/*
* ============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.CpsAnchorService;
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 static final String CACHE_ENTRY_PROPERTY_NAME = "prefixPerContainerName";
- private final CpsAdminService cpsAdminService;
+ private final CpsAnchorService cpsAnchorService;
private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
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.
*
* @return the prefix of the module the top level element of given xpath
*/
public String getPrefix(final String dataspaceName, final String anchorName, final String xpath) {
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
return getPrefix(anchor, xpath);
}
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);
}