/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Pantheon.tech
- * Modifications (C) 2021-2022 Nordix Foundation
+ * Modifications (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
* ================================================================================
import java.util.Map;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.onap.cps.cpspath.parser.CpsPathQuery;
+import org.onap.cps.cpspath.parser.CpsPathUtil;
import org.onap.cps.spi.model.DataNode;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
}
private static String getNodeIdentifier(String xpath) {
- if (xpath.endsWith("]")) {
- xpath = xpath.substring(0, xpath.lastIndexOf('['));
+ final CpsPathQuery cpsPathQuery = CpsPathUtil.getCpsPathQuery(xpath);
+ if (cpsPathQuery.isPathToListElement()) {
+ xpath = cpsPathQuery.getXpathPrefix();
}
final int fromIndex = xpath.lastIndexOf('/') + 1;
return xpath.substring(fromIndex);
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import lombok.RequiredArgsConstructor;
import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.impl.YangTextSchemaSourceSetCache;
import org.onap.cps.cache.AnchorDataCacheEntry;
+import org.onap.cps.cpspath.parser.CpsPathPrefixType;
+import org.onap.cps.cpspath.parser.CpsPathQuery;
+import org.onap.cps.cpspath.parser.CpsPathUtil;
import org.onap.cps.spi.model.Anchor;
import org.onap.cps.yang.YangTextSchemaSourceSet;
import org.opendaylight.yangtools.yang.common.QNameModule;
private final IMap<String, AnchorDataCacheEntry> anchorDataCache;
- private static final Pattern TOP_LEVEL_NODE_NAME_FINDER
- = Pattern.compile("\\/([\\w-]*)(\\[@(?!.*\\[).*?])?(\\/.*)?"); //NOSONAR
-
/**
* Get the module prefix for the given xpath for a dataspace and anchor name.
*
private String getPrefixForTopContainer(final Map<String, String> prefixPerContainerName,
final String xpath) {
- final Matcher matcher = TOP_LEVEL_NODE_NAME_FINDER.matcher(xpath);
- if (matcher.matches()) {
- final String topLevelContainerName = matcher.group(1);
+ final CpsPathQuery cpsPathQuery = CpsPathUtil.getCpsPathQuery(xpath);
+ if (cpsPathQuery.getCpsPathPrefixType() == CpsPathPrefixType.ABSOLUTE) {
+ final String topLevelContainerName = cpsPathQuery.getContainerNames().get(0);
if (prefixPerContainerName.containsKey(topLevelContainerName)) {
return prefixPerContainerName.get(topLevelContainerName);
}
scenario | xPath | expectedNodeIdentifier
'container xpath' | '/bookstore' | 'sampleModuleName:bookstore'
'xpath contains list attribute' | '/bookstore/categories[@code=1]' | 'sampleModuleName:categories'
- 'xpath contains list attributes with /' | '/bookstore/categories[@code=1/2]' | 'sampleModuleName:categories'
-
+ 'xpath contains list attributes with /' | '/bookstore/categories[@code="1/2"]' | 'sampleModuleName:categories'
+ 'xpath contains list attributes with [' | '/bookstore/categories[@code="[1]"]' | 'sampleModuleName:categories'
}
def 'Data node structure with anchor name conversion to map with root node identifier.'() {
def dataNode = buildDataNode(
"/parent",[parentLeaf:'parentLeafValue', parentLeafList:['parentLeafListEntry1','parentLeafListEntry2']],[
- buildDataNode('/parent/child-list[@id=1/2]',[listElementLeaf:'listElement1leafValue'],noChildren),
+ buildDataNode('/parent/child-list[@id="1/2"]',[listElementLeaf:'listElement1leafValue'],noChildren),
buildDataNode('/parent/child-list[@id=2]',[listElementLeaf:'listElement2leafValue'],noChildren),
buildDataNode('/parent/child-object',[childLeaf:'childLeafValue'],
[buildDataNode('/parent/child-object/grand-child-object',[grandChildLeaf:'grandChildLeafValue'],noChildren)]
def dataNodeWithAnchor = buildDataNodeWithAnchor(
"/parent", 'anchor01',[parentLeaf:'parentLeafValue', parentLeafList:['parentLeafListEntry1','parentLeafListEntry2']],[
- buildDataNode('/parent/child-list[@id=1/2]',[listElementLeaf:'listElement1leafValue'],noChildren),
+ buildDataNode('/parent/child-list[@id="1/2"]',[listElementLeaf:'listElement1leafValue'],noChildren),
buildDataNode('/parent/child-list[@id=2]',[listElementLeaf:'listElement2leafValue'],noChildren),
buildDataNode('/parent/child-object',[childLeaf:'childLeafValue'],
[buildDataNode('/parent/child-object/grand-child-object',[grandChildLeaf:'grandChildLeafValue'],noChildren)]
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation
+ * Copyright (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2021-2022 Bell Canada.
* ================================================================================
'/test-tree/with/descendants' || 'tree'
'/test-tree[@id=1]' || 'tree'
'/test-tree[@id=1]/child' || 'tree'
+ '/test-tree[@id="[1]"]/child' || 'tree'
+ '//test-tree' || ''
'/not-defined' || ''
- 'invalid-xpath' || ''
}
def 'get prefix with populated anchor data cache with #scenario cache entry'() {