diff --git a/hubble-be/src/main/java/com/baidu/hugegraph/common/Constant.java b/hubble-be/src/main/java/com/baidu/hugegraph/common/Constant.java index b04ad05d..508cd792 100644 --- a/hubble-be/src/main/java/com/baidu/hugegraph/common/Constant.java +++ b/hubble-be/src/main/java/com/baidu/hugegraph/common/Constant.java @@ -42,4 +42,8 @@ public final class Constant { "com.baidu.hugegraph.controller"; public static final String COOKIE_USER = "user"; + + public static final Set LIKE_WILDCARDS = ImmutableSet.of( + "%", "_", "^", "[", "]" + ); } diff --git a/hubble-be/src/main/java/com/baidu/hugegraph/controller/GraphConnectionController.java b/hubble-be/src/main/java/com/baidu/hugegraph/controller/GraphConnectionController.java index c9b98b0f..1f6ac8d3 100644 --- a/hubble-be/src/main/java/com/baidu/hugegraph/controller/GraphConnectionController.java +++ b/hubble-be/src/main/java/com/baidu/hugegraph/controller/GraphConnectionController.java @@ -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; @@ -63,9 +62,6 @@ public class GraphConnectionController extends BaseController { public IPage list(@RequestParam(name = "content", required = false) String content, - @RequestParam(name = "graph_order", - required = false) - String graphOrder, @RequestParam(name = "page_no", required = false, defaultValue = "1") @@ -74,14 +70,7 @@ public IPage 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}") diff --git a/hubble-be/src/main/java/com/baidu/hugegraph/service/GraphConnectionService.java b/hubble-be/src/main/java/com/baidu/hugegraph/service/GraphConnectionService.java index 1e10a232..9637b780 100644 --- a/hubble-be/src/main/java/com/baidu/hugegraph/service/GraphConnectionService.java +++ b/hubble-be/src/main/java/com/baidu/hugegraph/service/GraphConnectionService.java @@ -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; @@ -44,22 +45,16 @@ public List listAll() { return this.mapper.selectList(null); } - public IPage list(String content, Boolean graphOrderAsc, - long current, long pageSize) { + public IPage list(String content, long current, + long pageSize) { QueryWrapper 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); diff --git a/hubble-be/src/main/java/com/baidu/hugegraph/service/GremlinCollectionService.java b/hubble-be/src/main/java/com/baidu/hugegraph/service/GremlinCollectionService.java index 213f1064..b45d232a 100644 --- a/hubble-be/src/main/java/com/baidu/hugegraph/service/GremlinCollectionService.java +++ b/hubble-be/src/main/java/com/baidu/hugegraph/service/GremlinCollectionService.java @@ -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; @@ -42,7 +43,11 @@ public IPage list(String content, Boolean nameOrderAsc, long current, long pageSize) { QueryWrapper 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) { diff --git a/hubble-be/src/main/java/com/baidu/hugegraph/util/HugeClientUtil.java b/hubble-be/src/main/java/com/baidu/hugegraph/util/HugeClientUtil.java index b4ad7943..179d6e68 100644 --- a/hubble-be/src/main/java/com/baidu/hugegraph/util/HugeClientUtil.java +++ b/hubble-be/src/main/java/com/baidu/hugegraph/util/HugeClientUtil.java @@ -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; diff --git a/hubble-be/src/main/resources/i18n/messages.properties b/hubble-be/src/main/resources/i18n/messages.properties index ba9b5007..6e3bb5ab 100644 --- a/hubble-be/src/main/resources/i18n/messages.properties +++ b/hubble-be/src/main/resources/i18n/messages.properties @@ -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} diff --git a/hubble-be/src/main/resources/i18n/messages_en_US.properties b/hubble-be/src/main/resources/i18n/messages_en_US.properties index ba9b5007..6e3bb5ab 100644 --- a/hubble-be/src/main/resources/i18n/messages_en_US.properties +++ b/hubble-be/src/main/resources/i18n/messages_en_US.properties @@ -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} diff --git a/hubble-be/src/main/resources/i18n/messages_zh_CN.properties b/hubble-be/src/main/resources/i18n/messages_zh_CN.properties index daf8a973..f8525b7f 100644 --- a/hubble-be/src/main/resources/i18n/messages_zh_CN.properties +++ b/hubble-be/src/main/resources/i18n/messages_zh_CN.properties @@ -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} 上