diff options
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 49d3a70f9f..eb0c764cbc 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 @@ -30,7 +30,6 @@ import java.io.IOException; import java.io.StringReader; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -45,6 +44,8 @@ import javax.xml.stream.XMLStreamReader; 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; @@ -74,9 +75,6 @@ import org.xml.sax.SAXException; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class YangUtils { - private static final String XPATH_DELIMITER_REGEX = "\\/"; - private static final String XPATH_NODE_KEY_ATTRIBUTES_REGEX = "\\[.*?\\]"; - /** * Parses data into Collection of NormalizedNode according to given schema context. * @@ -257,15 +255,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 Map<String, Object> findDataSchemaNodeAndIdentifiersByXpathNodeIdSequence( |