diff options
author | 2022-09-02 11:01:31 +0530 | |
---|---|---|
committer | 2022-09-06 11:45:41 +0530 | |
commit | ce559bf358caf180ba3b61d43a2cf86dd3f3e111 (patch) | |
tree | 86507cf4a6468450cbae9ecc6aa7c1365f4e40f1 /cps-service/src/main | |
parent | 61c5b06dcaa4e8902b946fb86e773b75ddb10a8f (diff) |
Xpath to NodeId invalid
Issue-ID: CPS-1244
Signed-off-by: Gandhapu, Yashwanth <gandhapu.yashwanth@wipro.com>
Change-Id: Ib091de1247cb0bb48d3157bf2c5becfc9189b773
Diffstat (limited to 'cps-service/src/main')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/utils/YangUtils.java | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java index 8c32010d7..5e1b486aa 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java +++ b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java @@ -52,7 +52,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class YangUtils { private static final String XPATH_DELIMITER_REGEX = "\\/"; - private static final String XPATH_NODE_KEY_ATTRIBUTES_REGEX = "\\[.+"; + private static final String XPATH_NODE_KEY_ATTRIBUTES_REGEX = "\\[.*?\\]"; + //Might cause an issue with [] inside [] in key-values /** * Parses jsonData into NormalizedNode according to given schema context. @@ -149,10 +150,11 @@ public class YangUtils { } private static String[] xpathToNodeIdSequence(final String xpath) { - final String[] xpathNodeIdSequence = Arrays.stream(xpath.split(XPATH_DELIMITER_REGEX)) - .map(identifier -> identifier.replaceFirst(XPATH_NODE_KEY_ATTRIBUTES_REGEX, "")) - .filter(identifier -> !identifier.isEmpty()) - .toArray(String[]::new); + final String[] xpathNodeIdSequence = Arrays.stream(xpath + .replaceAll(XPATH_NODE_KEY_ATTRIBUTES_REGEX, "") + .split(XPATH_DELIMITER_REGEX)) + .filter(identifier -> !identifier.isEmpty()) + .toArray(String[]::new); if (xpathNodeIdSequence.length < 1) { throw new DataValidationException("Invalid xpath.", "Xpath contains no node identifiers."); } |