summaryrefslogtreecommitdiffstats
path: root/cps-path-parser/src/main/java
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2022-12-19 14:19:29 +0000
committerToineSiebelink <toine.siebelink@est.tech>2022-12-19 16:12:32 +0000
commite52d0cbf970f1de982fb64f1a052646457b81f52 (patch)
tree86452d641b55bd3c365470d5ff21f32a6ce9c8ec /cps-path-parser/src/main/java
parentb344f764a93e03545dc8984a4974329d6811b859 (diff)
Fix Delete uses case with '/' in path
-Extend and use cpsPath parser (util) classes instead of regex Issue-ID: CPS-1409 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech> Change-Id: I230c9eb71cc34264983830b39149511b95c4b4a6
Diffstat (limited to 'cps-path-parser/src/main/java')
-rw-r--r--cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java5
-rw-r--r--cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java1
-rw-r--r--cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathUtil.java30
3 files changed, 32 insertions, 4 deletions
diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
index 21f5173a98..7183120120 100644
--- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
+++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
@@ -61,6 +61,11 @@ public class CpsPathBuilder extends CpsPathBaseListener {
}
@Override
+ public void exitParent(final CpsPathParser.ParentContext ctx) {
+ cpsPathQuery.setNormalizedParentPath(normalizedXpathBuilder.toString());
+ }
+
+ @Override
public void exitIncorrectPrefix(final IncorrectPrefixContext ctx) {
throw new PathParsingException("CPS path can only start with one or two slashes (/)");
}
diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java
index 53490f3a2d..a9bd5d81c3 100644
--- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java
+++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathQuery.java
@@ -32,6 +32,7 @@ import lombok.Setter;
public class CpsPathQuery {
private String xpathPrefix;
+ private String normalizedParentPath;
private String normalizedXpath;
private CpsPathPrefixType cpsPathPrefixType = ABSOLUTE;
private String descendantName;
diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathUtil.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathUtil.java
index 97d7d1d760..283463b512 100644
--- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathUtil.java
+++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathUtil.java
@@ -20,6 +20,8 @@
package org.onap.cps.cpspath.parser;
+import static org.onap.cps.cpspath.parser.CpsPathPrefixType.ABSOLUTE;
+
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -45,8 +47,29 @@ public class CpsPathUtil {
* @return a normalized xpath String.
*/
public static String getNormalizedXpath(final String xpathSource) {
- final CpsPathBuilder cpsPathBuilder = getCpsPathBuilder(xpathSource);
- return cpsPathBuilder.build().getNormalizedXpath();
+ return getCpsPathBuilder(xpathSource).build().getNormalizedXpath();
+ }
+
+ /**
+ * Returns the parent xpath.
+ *
+ * @param xpathSource xpath
+ * @return the parent xpath String.
+ */
+ public static String getNormalizedParentXpath(final String xpathSource) {
+ return getCpsPathBuilder(xpathSource).build().getNormalizedParentPath();
+ }
+
+
+ /**
+ * Returns boolean indicating xpath is an absolute path to a list element.
+ *
+ * @param xpathSource xpath
+ * @return true if xpath is an absolute path to a list element
+ */
+ public static boolean isPathToListElement(final String xpathSource) {
+ final CpsPathQuery cpsPathQuery = getCpsPathBuilder(xpathSource).build();
+ return cpsPathQuery.getCpsPathPrefixType() == ABSOLUTE && cpsPathQuery.hasLeafConditions();
}
/**
@@ -57,8 +80,7 @@ public class CpsPathUtil {
*/
public static CpsPathQuery getCpsPathQuery(final String cpsPathSource) {
- final CpsPathBuilder cpsPathBuilder = getCpsPathBuilder(cpsPathSource);
- return cpsPathBuilder.build();
+ return getCpsPathBuilder(cpsPathSource).build();
}
private static CpsPathBuilder getCpsPathBuilder(final String cpsPathSource) {