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 21, 2019
1 parent bba8303 commit 00e00ba
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 30 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 @@ -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,22 +45,16 @@ public List<GraphConnection> listAll() {
return this.mapper.selectList(null);
}

public IPage<GraphConnection> list(String content, Boolean graphOrderAsc,
long current, long pageSize) {
public IPage<GraphConnection> list(String content, long current,
long pageSize) {
QueryWrapper<GraphConnection> query = Wrappers.query();
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;
}
query.like("name", value).or().like("graph", value);
query.orderByAsc("name").orderByAsc("graph");
}
query.orderByDesc("create_time");
return this.mapper.selectPage(new Page<>(current, pageSize), query);
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: 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

0 comments on commit 00e00ba

Please sign in to comment.