summaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
authoremaclee <lee.anjella.macabuhay@est.tech>2022-12-21 09:29:24 +0000
committeremaclee <lee.anjella.macabuhay@est.tech>2022-12-22 09:44:40 +0000
commit5452b5ea786a3e7def19c1f328c43ec264da38d5 (patch)
treeb7988ce69ee08cc3121c50785b7baac887dcf9ad /cps-service
parente52d0cbf970f1de982fb64f1a052646457b81f52 (diff)
Add fix for posting nodes with xPath with '/'
- YangUtils method changed from using REGEX to cps path parser - unit test added for cps path util Issue-ID: CPS-1433 Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech> Change-Id: Ibb9efdd09423f9bade4a4a557d7d9ed49aa44ef4
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/pom.xml4
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/YangUtils.java19
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy2
-rw-r--r--cps-service/src/test/resources/bookstore.json8
4 files changed, 16 insertions, 17 deletions
diff --git a/cps-service/pom.xml b/cps-service/pom.xml
index 77f262c32e..0cefb8fcc2 100644
--- a/cps-service/pom.xml
+++ b/cps-service/pom.xml
@@ -111,6 +111,10 @@
<artifactId>janino</artifactId>
</dependency>
<dependency>
+ <groupId>org.onap.cps</groupId>
+ <artifactId>cps-path-parser</artifactId>
+ </dependency>
+ <dependency>
<!-- Hazelcast provide Distributed Caches -->
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
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(
diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy
index e205a19eed..b70c437953 100644
--- a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy
@@ -41,7 +41,7 @@ class JsonObjectMapperSpec extends Specification {
then: 'the result is a valid json string (can be parsed)'
def contentMap = new JsonSlurper().parseText(content)
and: 'the parsed content is as expected'
- assert contentMap.'test:bookstore'.'bookstore-name' == 'Chapters'
+ assert contentMap.'test:bookstore'.'bookstore-name' == 'Chapters/Easons'
}
def 'Map a structured object to json String error.'() {
diff --git a/cps-service/src/test/resources/bookstore.json b/cps-service/src/test/resources/bookstore.json
index d1b8d6882d..459908bd63 100644
--- a/cps-service/src/test/resources/bookstore.json
+++ b/cps-service/src/test/resources/bookstore.json
@@ -1,19 +1,19 @@
{
"test:bookstore":{
- "bookstore-name": "Chapters",
+ "bookstore-name": "Chapters/Easons",
"categories": [
{
- "code": "01",
+ "code": "01/1",
"name": "SciFi",
"books": [
{
"authors": [
"Iain M. Banks"
],
- "lang": "en",
+ "lang": "en/it",
"price": "895",
"pub_year": "1994",
- "title": "Feersum Endjinn"
+ "title": "Feersum Endjinn/Endjinn Feersum"
},
{
"authors": [