You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
Version 1
Next »
References
CPS-1215
-
Getting issue details...
STATUS
Issues & Decisions
# | Issue | Notes | Decision |
---|
1 | Antlr changes to be made to recognize OR as input in cps-path | Adding OR operator to the antlr grammer file PATH : cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4 Solution : listElementRef : OB leafCondition ( ( KW_AND | KW_OR) leafCondition)* CB multipleLeafConditions : OB leafCondition ( ( KW_AND | KW_OR) leafCondition)* CB It is tested by antlr test | |
---|
2 | Code changes made to recognise the operatoe i.e., and ,or | PATH:cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java Solution: String parent = ctx.getParent().getText(); String payload = ctx.getPayload().getText(); payloads.add(payload); String operator = findOperator(parent, payloads); appendCondition(normalizedXpathBuilder, ctx.leafName().getText(), comparisonValue, operator); if (processingAncestorAxis) { appendCondition(normalizedAncestorPathBuilder, ctx.leafName().getText(), comparisonValue, operator); } } private String findOperator(String parent, List<String> payloads) { StringBuilder parentStringBuilder = new StringBuilder(parent); try { payloads.forEach(payload -> parentStringBuilder.delete(parentStringBuilder.indexOf(payload), parentStringBuilder.indexOf(payload) + payload.length())); parentStringBuilder.delete(0, parentStringBuilder.indexOf("[") + 1); return parentStringBuilder.toString().trim(); } catch (RuntimeException e) { return null; } } private void appendCondition(final StringBuilder currentNormalizedPathBuilder, final String name, final Object value, String operator) { final char lastCharacter = currentNormalizedPathBuilder.charAt(currentNormalizedPathBuilder.length() - 1); currentNormalizedPathBuilder.append(lastCharacter == '[' ? "" : " " + operator + " "); currentNormalizedPathBuilder.append("@"); currentNormalizedPathBuilder.append(name); currentNormalizedPathBuilder.append("='"); currentNormalizedPathBuilder.append(value); currentNormalizedPathBuilder.append("'"); } }
|
|
---|
3 | Test Case written to test code changes | PATH:cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy 1. def 'Parse cps path having OR operator containing #scenario.'() { when: 'the given cps path is parsed' def result = CpsPathUtil.getCpsPathQuery(cpsPath) then: 'the query has the right normalized xpath type' assert result.normalizedXpath == expectedNormalizedXPath where: 'the following data is used' scenario | cpsPath || expectedNormalizedXPath 'parent & child with more than one attribute' | '/parent/child[@key1=1 or @key2="abc"]/child2' || "/parent/child[@key1='1' or @key2='abc']/child2" } 2. def 'Parse cps path that ends with a yang list containing #scenario and having or operator '() { when: 'the given cps path is parsed' def result = CpsPathQuery.createFrom(cpsPath) then: 'the query has the right xpath type' result.cpsPathPrefixType == DESCENDANT and: 'the right parameters are set' result.descendantName == "child" result.leavesData.size() == expectedNumberOfLeaves where: 'the following data is used' scenario | cpsPath || expectedNumberOfLeaves 'more than one attribute' | '//child[@int-leaf=5 or @leaf-name="leaf value"]' || 2 }
|
|
---|