Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Linary committed Aug 26, 2019
1 parent bba8303 commit ead533f
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ public final class Constant {
"com.baidu.hugegraph.controller";

public static final String COOKIE_USER = "user";

public static final Set<String> LIKE_WILDCARDS = ImmutableSet.of(
"%", "_", "^", "[", "]"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -63,9 +62,6 @@ public class GraphConnectionController extends BaseController {
public IPage<GraphConnection> list(@RequestParam(name = "content",
required = false)
String content,
@RequestParam(name = "graph_order",
required = false)
String graphOrder,
@RequestParam(name = "page_no",
required = false,
defaultValue = "1")
Expand All @@ -74,14 +70,7 @@ public IPage<GraphConnection> list(@RequestParam(name = "content",
required = false,
defaultValue = "10")
long pageSize) {
Boolean graphOrderAsc = null;
if (!StringUtils.isEmpty(graphOrder)) {
Ex.check(ORDER_ASC.equals(graphOrder) ||
ORDER_DESC.equals(graphOrder),
"graph-connection.graph-order.invalid", graphOrder);
graphOrderAsc = ORDER_ASC.equals(graphOrder);
}
return this.connService.list(content, graphOrderAsc, pageNo, pageSize);
return this.connService.list(content, pageNo, pageSize);
}

@GetMapping("{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@
package com.baidu.hugegraph.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

import com.baidu.hugegraph.entity.GraphConnection;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

@Mapper
@Component
public interface GraphConnectionMapper extends BaseMapper<GraphConnection> {

/**
* NOTE: Page must be the first param, otherwise throw exception
*/
IPage<GraphConnection> selectByContentInPage(IPage<GraphConnection> page,
@Param("content")
String content);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import com.baidu.hugegraph.common.Constant;
import com.baidu.hugegraph.entity.GraphConnection;
import com.baidu.hugegraph.mapper.GraphConnectionMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
Expand All @@ -44,25 +45,20 @@ public List<GraphConnection> listAll() {
return this.mapper.selectList(null);
}

public IPage<GraphConnection> list(String content, Boolean graphOrderAsc,
long current, long pageSize) {
QueryWrapper<GraphConnection> query = Wrappers.query();
public IPage<GraphConnection> list(String content, long current,
long pageSize) {
IPage<GraphConnection> page = new Page<>(current, pageSize);
if (!StringUtils.isEmpty(content)) {
query.like("name", content).or().like("graph", content);
}
/*
* The results will order by create_time when graph_order is null,
* otherwise order by graph firstly then by create_time.
*/
if (graphOrderAsc != null) {
if (graphOrderAsc) {
query.orderByAsc("graph");
} else {
query.orderByDesc("graph");
String value = content;
if (Constant.LIKE_WILDCARDS.contains(content)) {
value = "\\" + content;
}
return this.mapper.selectByContentInPage(page, value);
} else {
QueryWrapper<GraphConnection> query = Wrappers.query();
query.orderByDesc("create_time");
return this.mapper.selectPage(page, query);
}
query.orderByDesc("create_time");
return this.mapper.selectPage(new Page<>(current, pageSize), query);
}

public GraphConnection get(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.baidu.hugegraph.common.Constant;
import com.baidu.hugegraph.entity.GremlinCollection;
import com.baidu.hugegraph.mapper.GremlinCollectionMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
Expand All @@ -42,7 +43,11 @@ public IPage<GremlinCollection> list(String content, Boolean nameOrderAsc,
long current, long pageSize) {
QueryWrapper<GremlinCollection> query = Wrappers.query();
if (!StringUtils.isEmpty(content)) {
query.like("name", content).or().like("content", content);
String value = content;
if (Constant.LIKE_WILDCARDS.contains(content)) {
value = "\\" + content;
}
query.like("name", value).or().like("content", value);
}
if (nameOrderAsc != null) {
if (nameOrderAsc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static HugeClient tryConnect(GraphConnection connection) {
String message = cause.getMessage();
if (message.contains("Connection refused")) {
throw new ExternalException("service.unavailable", host, port);
} else if (message.contains("java.net.UnknownHostException")) {
} else if (message.contains("java.net.UnknownHostException") ||
message.contains("Host name may not be null")) {
throw new ExternalException("service.unknown-host", host);
}
throw e;
Expand Down
1 change: 1 addition & 0 deletions hubble-be/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

mybatis.type-aliases-package=com.baidu.hugegraph.entity
mybatis-plus.mapper-locations=classpath*:/mapper/**/*.xml
mybatis-plus.type-enums-package=com.baidu.hugegraph.entity.enums
mybatis.configuration.cache-enabled=false
mybatis.configuration.map-underscore-to-camel-case=true
Expand Down
1 change: 0 additions & 1 deletion hubble-be/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ client-server.version.unmatched=The version of hugegraph-client and hugegraph-se
service.unavailable=The service {0}:{1} is unavailable
service.unknown-host=The host {0} is unknown

graph-connection.graph-order.invalid=The param graph_order either not set or set to [asc, desc], but got {0}
graph-connection.name.unmatch-regex=Invalid connection name {0}, valid name is up to 48 alpha-numeric characters and underscores and only letters are supported as first letter. Note: letter is case insensitive
graph-connection.graph.unmatch-regex=Invalid connection graph {0}, valid graph is up to 48 alpha-numeric characters and underscores and only letters are supported as first letter. Note: letter is case insensitive
graph-connection.graph.unexist=There is no graph with the name {0} on service {1}:{2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ client-server.version.unmatched=The version of hugegraph-client and hugegraph-se
service.unavailable=The service {0}:{1} is unavailable
service.unknown-host=The host {0} is unknown

graph-connection.graph-order.invalid=The param graph_order either not set or set to [asc, desc], but got {0}
graph-connection.name.unmatch-regex=Invalid connection name {0}, valid name is up to 48 alpha-numeric characters and underscores and only letters are supported as first letter. Note: letter is case insensitive
graph-connection.graph.unmatch-regex=Invalid connection graph {0}, valid graph is up to 48 alpha-numeric characters and underscores and only letters are supported as first letter. Note: letter is case insensitive
graph-connection.graph.unexist=There is no graph with the name {0} on service {1}:{2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ client-server.version.unmatched=客户端 hugegraph-client 和服务端 hugegrap
service.unavailable=服务 {0}:{1} 不可用
service.unknown-host=未知的主机名 {0}

graph-connection.graph-order.invalid=参数 graph_order 要么不设置,要么设置为 asc 或 desc,但实际为 {0}
graph-connection.name.unmatch-regex=连接名 {0} 不合法,连接名应该由字母,数字以及下划线组成,第一个字符必须是字母,且最多48个字符。注意:字母不区分大小写
graph-connection.graph.unmatch-regex=连接的图名 {0} 不合法,图名应该由字母,数字以及下划线组成,第一个字符必须是字母,且最多48个字符。注意:字母不区分大小写
graph-connection.graph.unexist=不存在名字为 {0} 的图在服务 {1}:{2} 上
Expand Down
21 changes: 21 additions & 0 deletions hubble-be/src/main/resources/mapper/graph-connection-mapper.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.baidu.hugegraph.mapper.GraphConnectionMapper">

<select id="selectByContentInPage"
resultType="com.baidu.hugegraph.entity.GraphConnection">
SELECT *
FROM `graph_connection`
WHERE `name` LIKE '%${content}%' OR `graph` LIKE '%${content}%'
ORDER BY
CASE
WHEN `name` LIKE '%${content}%' AND
`graph` LIKE '%${content}%' THEN 0
WHEN `name` LIKE '%${content}%' THEN 1
WHEN `graph` LIKE '%${content}%' THEN 2
END ASC,
`create_time` DESC
</select>

</mapper>

0 comments on commit ead533f

Please sign in to comment.