X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ri%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fspi%2Fquery%2FCpsPathQuery.java;h=e85414cdc90b043bcaed69c00d4d467cbe378602;hb=50130c04626e0c5b09b344b2e11bb99c62dbf926;hp=4fcf6e444b4c4479fbcc912200959fc13ebd6f20;hpb=333f2b5a7a54f325a8d7137e6b8c0502fc860441;p=cps.git diff --git a/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java b/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java index 4fcf6e444b..e85414cdc9 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java @@ -31,32 +31,43 @@ import org.onap.cps.spi.exceptions.CpsPathException; @Setter(AccessLevel.PRIVATE) public class CpsPathQuery { + private CpsPathQueryType cpsPathQueryType; private String xpathPrefix; private String leafName; private Object leafValue; + private String endsWith; public static final Pattern QUERY_CPS_PATH_WITH_SINGLE_LEAF_PATTERN = - Pattern.compile("(.*)\\[\\s*@(.*?)\\s*=\\s*(.*?)\\s*]"); + Pattern.compile("((?:\\/[^\\/]+)+?)\\[\\s*@(\\S+?)\\s*=\\s*(.*?)\\s*\\]"); - public static final Pattern LEAF_STRING_VALUE_PATTERN = Pattern.compile("['\"](.*)['\"]"); + public static final Pattern QUERY_CPS_PATH_ENDS_WITH_PATTERN = Pattern.compile("\\/\\/(.+)"); public static final Pattern LEAF_INTEGER_VALUE_PATTERN = Pattern.compile("[-+]?\\d+"); + public static final Pattern LEAF_STRING_VALUE_PATTERN = Pattern.compile("['\"](.*)['\"]"); + /** - * Returns a xpath prefix, leaf name and leaf value for the given cps path. + * Returns a cps path query. * * @param cpsPath cps path - * @return a CpsPath object containing the xpath prefix, leaf name and leaf value. + * @return a CpsPath object. */ public static CpsPathQuery createFrom(final String cpsPath) { - final Matcher matcher = QUERY_CPS_PATH_WITH_SINGLE_LEAF_PATTERN.matcher(cpsPath); + Matcher matcher = QUERY_CPS_PATH_WITH_SINGLE_LEAF_PATTERN.matcher(cpsPath); + final CpsPathQuery cpsPathQuery = new CpsPathQuery(); if (matcher.matches()) { - final CpsPathQuery cpsPathQuery = new CpsPathQuery(); + cpsPathQuery.setCpsPathQueryType(CpsPathQueryType.XPATH_LEAF_VALUE); cpsPathQuery.setXpathPrefix(matcher.group(1)); cpsPathQuery.setLeafName(matcher.group(2)); cpsPathQuery.setLeafValue(convertLeafValueToCorrectType(matcher.group(3))); return cpsPathQuery; } + matcher = QUERY_CPS_PATH_ENDS_WITH_PATTERN.matcher(cpsPath); + if (matcher.matches()) { + cpsPathQuery.setCpsPathQueryType(CpsPathQueryType.XPATH_ENDS_WITH); + cpsPathQuery.setEndsWith(matcher.group(1)); + return cpsPathQuery; + } throw new CpsPathException("Invalid cps path.", String.format("Cannot interpret or parse cps path %s.", cpsPath)); }