Skip to content

Commit

Permalink
#2378 tuned dme parser
Browse files Browse the repository at this point in the history
  • Loading branch information
gavin2lee committed Jun 15, 2023
1 parent 4f1da5d commit 4d943d9
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<EntityDto> getAllEntities(String dataModelExpression) {
log.info("Get all entities with expression:{}", dataModelExpression);
}

List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(dataModelExpression);
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(dataModelExpression).getExprNodeInfos();
List<EntityDto> entityDtos = new ArrayList<EntityDto>();

for (EntityQueryExprNodeInfo exprNodeInfo : exprNodeInfos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<Object> fetchDataWithFilter(DmeFilterDto dmeFilterDto) {
log.info("start to fetch data with filter:{}", dmeFilterDto);
}
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser
.parse(dmeFilterDto.getDataModelExpression());
.parse(dmeFilterDto.getDataModelExpression()).getExprNodeInfos();

enrichEntityQueryExprNodeInfos(exprNodeInfos, dmeFilterDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public List<StandardEntityDataNode> generatePreviewTree(EntityOperationRootCondi

protected EntityOperationContext buildEntityOperationContext(EntityOperationRootCondition condition,
RestTemplate restTemplate, Map<Object, Object> externalCacheMap) {
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(condition.getEntityLinkExpr());
EntityQueryExpr entityQueryExpr = entityQueryExpressionParser.parse(condition.getEntityLinkExpr());
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpr.getExprNodeInfos();

EntityOperationContext ctx = new EntityOperationContext();
ctx.setEntityQueryExprNodeInfos(exprNodeInfos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ private void calculateInputParamValueFromObject(ExecutionJobs executionJob, Exec

String entityAttrName = null;
List<EntityQueryExprNodeInfo> currExprNodeInfos = this.entityQueryExpressionParser
.parse(parameter.getMappingEntityExpression());
.parse(parameter.getMappingEntityExpression()).getExprNodeInfos();
if (currExprNodeInfos == null || currExprNodeInfos.isEmpty()) {
// nothing
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ private void handleObjectMapping(String mappingType, PluginConfigInterfaceParame

String entityAttrName = null;
List<EntityQueryExprNodeInfo> currExprNodeInfos = this.entityQueryExpressionParser
.parse(param.getMappingEntityExpression());
.parse(param.getMappingEntityExpression()).getExprNodeInfos();
if (currExprNodeInfos == null || currExprNodeInfos.isEmpty()) {
// nothing
} else {
Expand Down Expand Up @@ -3021,9 +3021,9 @@ private boolean checkIfNeedPickoutFromContext(String currTaskNodeRoutineExp, Str
}

List<EntityQueryExprNodeInfo> currExprNodeInfos = this.entityQueryExpressionParser
.parse(currTaskNodeRoutineExp);
.parse(currTaskNodeRoutineExp).getExprNodeInfos();
List<EntityQueryExprNodeInfo> lastExprNodeInfos = this.entityQueryExpressionParser
.parse(bindTaskNodeRoutineExp);
.parse(bindTaskNodeRoutineExp).getExprNodeInfos();

if (currExprNodeInfos == null || currExprNodeInfos.isEmpty()) {
return true;
Expand Down Expand Up @@ -3779,7 +3779,7 @@ private void tryHandleSingleOutputMapOnceEntityCreation(PluginInterfaceInvocatio
// continue;
}

List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(paramExpr);
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(paramExpr).getExprNodeInfos();

if (exprNodeInfos == null || exprNodeInfos.isEmpty()) {
String errMsg = String.format("Unknown how to update entity attribute due to invalid expression:%s",
Expand Down Expand Up @@ -3927,7 +3927,7 @@ private void tryHandleSingleOutputMapOnceEntityUpdate(PluginInterfaceInvocationR
// }
// }

List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(paramExpr);
List<EntityQueryExprNodeInfo> exprNodeInfos = entityQueryExpressionParser.parse(paramExpr).getExprNodeInfos();
if (exprNodeInfos == null || exprNodeInfos.isEmpty()) {
String errMsg = String.format("Unknown how to update entity attribute due to invalid expression:%s",
paramExpr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ private List<RegisteredEntityDefDto> buildTaskNodeBoundEntities(TaskNodeDefInfoE
}

String nodeExpr = exprPart.trim();
List<EntityQueryExprNodeInfo> exprNodeInfos = this.entityQueryExpressionParser.parse(nodeExpr);
List<EntityQueryExprNodeInfo> exprNodeInfos = this.entityQueryExpressionParser.parse(nodeExpr).getExprNodeInfos();
if (exprNodeInfos == null || exprNodeInfos.isEmpty()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class EntityQueryExpressionParserTests {
@Test
public void testParseSingleRootExpr() {
String inputExpr = "wecmdb:host_resource_instance{ip_address eq 'localhost'}";
List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr);
List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr).getExprNodeInfos();
Assert.assertNotNull(queryNodeInfos);
Assert.assertEquals(1, queryNodeInfos.size());
EntityQueryExprNodeInfo nodeInfo = queryNodeInfos.get(0);
Expand All @@ -27,7 +27,7 @@ public void testParseRefToWithConditionShouldSucceed() {
String inputExpr = "wecmdb:subsys{att1 eq '@@0008_123456789@@eee'}{attr2 like 'AAA'}.subsys_design"
+ ">wecmdb:subsys_design.system_design" + ">wecmdb:system_design{attr2 like 'AAA'}.key_name";

List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr);
List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr).getExprNodeInfos();
Assert.assertNotNull(queryNodeInfos);
Assert.assertEquals(3, queryNodeInfos.size());
EntityQueryExprNodeInfo nodeInfo = queryNodeInfos.get(0);
Expand Down Expand Up @@ -69,7 +69,7 @@ public void testParseRefToWithConditionShouldSucceed() {
public void testParseSingleExprNodeWithoutFilterExprShouldSucceed() {
String inputExpr = "we-cmdb:system_design";

List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr);
List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr).getExprNodeInfos();
Assert.assertNotNull(queryNodeInfos);
Assert.assertEquals(1, queryNodeInfos.size());
Assert.assertEquals("we-cmdb:system_design", queryNodeInfos.get(0).getEntityInfoExpr());
Expand All @@ -82,7 +82,7 @@ public void testParseMultiExprNodeWithoutFilterExprShouldSucceed() {
String inputExpr = "wecmdb:zone_design" + "~(zone_design2)wecmdb:zone_link_design"
+ "~(zone_link_design)wecmdb:zone_link.zone1" + ">wecmdb:zone";

List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr);
List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr).getExprNodeInfos();
Assert.assertNotNull(queryNodeInfos);
Assert.assertEquals(4, queryNodeInfos.size());
// 0
Expand All @@ -107,7 +107,7 @@ public void testParseMultiExprNodeWithoutFilterExprShouldSucceed() {
public void testParseSingleExprNodeWithFilterExprShouldSucceed() {
String inputExpr = "we-cmdb:system_design{att1 eq '@@0008_123456789@@eee'}";

List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr);
List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr).getExprNodeInfos();
Assert.assertNotNull(queryNodeInfos);
Assert.assertEquals(1, queryNodeInfos.size());

Expand All @@ -127,7 +127,7 @@ public void testParseMultiExprNodeWithFilterExprShouldSucceed() {
+ "~(zone_design2)wecmdb:zone_link_design{att1 like 'A'}" + "~(zone_link_design)wecmdb:zone_link.zone1"
+ ">wecmdb:zone";

List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr);
List<EntityQueryExprNodeInfo> queryNodeInfos = parser.parse(inputExpr).getExprNodeInfos();
Assert.assertNotNull(queryNodeInfos);
Assert.assertEquals(4, queryNodeInfos.size());
// 0
Expand Down

0 comments on commit 4d943d9

Please sign in to comment.