diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2022-12-22 15:12:50 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-12-22 15:12:50 +0000 |
commit | cd02dc580f1a83d4ce05c7b1eedea88593fac5df (patch) | |
tree | cc04e4da6c4be4699e6d4adf2dc1db49aec050d1 /cps-service/src/main/java | |
parent | acc63c2a2b5974d3346cbb763ec963104a393a18 (diff) | |
parent | 5452b5ea786a3e7def19c1f328c43ec264da38d5 (diff) |
Merge "Add fix for posting nodes with xPath with '/'"
Diffstat (limited to 'cps-service/src/main/java')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/utils/YangUtils.java | 19 |
1 files changed, 7 insertions, 12 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 9a61579b12..3ef6c6fcf7 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 @@ -28,7 +28,6 @@ import com.google.gson.stream.JsonReader; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -37,6 +36,8 @@ import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.onap.cps.cpspath.parser.CpsPathUtil; +import org.onap.cps.cpspath.parser.PathParsingException; import org.onap.cps.spi.exceptions.DataValidationException; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -60,9 +61,6 @@ import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class YangUtils { - private static final String XPATH_DELIMITER_REGEX = "\\/"; - private static final String XPATH_NODE_KEY_ATTRIBUTES_REGEX = "\\[.*?\\]"; - /** * Parses jsonData into Collection of NormalizedNode according to given schema context. * @@ -170,15 +168,12 @@ public class YangUtils { } private static String[] xpathToNodeIdSequence(final String xpath) { - 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."); + try { + return CpsPathUtil.getXpathNodeIdSequence(xpath); + } catch (final PathParsingException pathParsingException) { + throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(), + pathParsingException); } - return xpathNodeIdSequence; } private static Collection<QName> findDataSchemaNodeIdentifiersByXpathNodeIdSequence( |