aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
authorseanbeirne <sean.beirne@est.tech>2024-09-03 15:27:28 +0100
committerseanbeirne <sean.beirne@est.tech>2024-10-25 15:46:44 +0100
commitccf48efa15fa6cce9d2e245601105043f939bcce (patch)
tree77a1a6a13f8de8a1e1d4d745e3becf1898ca0a31 /cps-ncmp-service/src/main
parentde910dce42459035b24f3b1ff2f843152312518a (diff)
Support Alternate-Id for CPS-E05 id-searches and searchCmHandleIds
Issue-ID: CPS-2402 Issue-ID: CPS-2383 Change-Id: I5dd3132b70b401bf2f50f77c2c131d5d34aa0c0a Signed-off-by: seanbeirne <sean.beirne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java19
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java20
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java82
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java7
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java18
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java16
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java90
8 files changed, 169 insertions, 87 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java
index 1fa801c3c5..5331c13bd1 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java
@@ -29,7 +29,6 @@ import static org.onap.cps.ncmp.impl.inventory.CmHandleQueryParametersValidator.
import java.util.Collection;
import java.util.Map;
import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters;
import org.onap.cps.ncmp.api.inventory.models.CompositeState;
@@ -51,7 +50,6 @@ import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.stereotype.Service;
-@Slf4j
@Service
@RequiredArgsConstructor
public class NetworkCmProxyInventoryFacade {
@@ -89,12 +87,16 @@ public class NetworkCmProxyInventoryFacade {
* Get all cm handle IDs by various properties.
*
* @param cmHandleQueryServiceParameters cm handle query parameters
- * @return collection of cm handle IDs
+ * @param outputAlternateId Boolean for cm handle reference type either
+ * cm handle id (false) or alternate id (true)
+ * @return collection of cm handle IDs
*/
public Collection<String> executeParameterizedCmHandleIdSearch(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) {
validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
- return parameterizedCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
+
+ return parameterizedCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters,
+ outputAlternateId);
}
@@ -156,13 +158,16 @@ public class NetworkCmProxyInventoryFacade {
* Retrieve cm handle ids for the given query parameters.
*
* @param cmHandleQueryApiParameters cm handle query parameters
+ * @param outputAlternateId boolean for cm handle reference type either cmHandleId (false) or AlternateId (true)
* @return cm handle ids
*/
- public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
+ public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters,
+ final Boolean outputAlternateId) {
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
- return parameterizedCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
+ return parameterizedCmHandleQueryService.queryCmHandleReferenceIds(cmHandleQueryServiceParameters,
+ outputAlternateId);
}
/**
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java
index 5343a2e131..b9b295a8a0 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java
@@ -28,16 +28,13 @@ import static org.onap.cps.ncmp.api.data.models.DatastoreType.OPERATIONAL;
import java.util.Collection;
import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.data.models.CmResourceAddress;
import org.onap.cps.ncmp.api.data.models.DataOperationRequest;
import org.onap.cps.ncmp.api.data.models.DatastoreType;
import org.onap.cps.ncmp.api.data.models.OperationType;
-import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher;
import org.onap.cps.spi.model.DataNode;
import org.springframework.stereotype.Service;
-@Slf4j
@Service
@RequiredArgsConstructor
public class NetworkCmProxyFacade {
@@ -45,7 +42,6 @@ public class NetworkCmProxyFacade {
private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler;
private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler;
private final DmiDataOperations dmiDataOperations;
- private final AlternateIdMatcher alternateIdMatcher;
/**
* Fetches resource data for a given data store using DMI (Data Management Interface).
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
index 95c3c77b71..86e9c934ce 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
@@ -32,25 +32,31 @@ public interface CmHandleQueryService {
* Query Cm Handles based on additional (private) properties.
*
* @param additionalPropertyQueryPairs private properties for query
+ * @param outputAlternateId boolean for cm handle reference type either cmHandleId (false) or AlternateId (true)
* @return Ids of Cm Handles which have these private properties
*/
- Collection<String> queryCmHandleAdditionalProperties(Map<String, String> additionalPropertyQueryPairs);
+ Collection<String> queryCmHandleAdditionalProperties(Map<String, String> additionalPropertyQueryPairs,
+ Boolean outputAlternateId);
/**
* Query Cm Handles based on public properties.
*
* @param publicPropertyQueryPairs public properties for query
+ * @param outputAlternateId boolean for cm handle reference type either cmHandleId (false) or AlternateId (true)
* @return CmHandles which have these public properties
*/
- Collection<String> queryCmHandlePublicProperties(Map<String, String> publicPropertyQueryPairs);
+ Collection<String> queryCmHandlePublicProperties(Map<String, String> publicPropertyQueryPairs,
+ Boolean outputAlternateId);
/**
* Query Cm Handles based on Trust Level.
*
* @param trustLevelPropertyQueryPairs trust level properties for query
+ * @param outputAlternateId boolean for cm handle reference type either cmHandleId (false) or AlternateId (true)
* @return Ids of Cm Handles which have desired trust level
*/
- Collection<String> queryCmHandlesByTrustLevel(Map<String, String> trustLevelPropertyQueryPairs);
+ Collection<String> queryCmHandlesByTrustLevel(Map<String, String> trustLevelPropertyQueryPairs,
+ Boolean outputAlternateId);
/**
* Method which returns cm handles by the cm handles state.
@@ -101,4 +107,12 @@ public interface CmHandleQueryService {
*/
Collection<String> getCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier);
+ /**
+ * Get map of cmHandle ids and alternate ids by DMI plugin identifier.
+ *
+ * @param dmiPluginIdentifier DMI plugin identifier
+ * @return map of cmHandle references key:CmHandleId Value:AlternateId
+ */
+ Map<String, String> getCmHandleReferencesByDmiPluginIdentifier(String dmiPluginIdentifier);
+
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
index 71e7384208..4249b452c3 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
@@ -29,6 +29,7 @@ import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.stream.Collectors;
@@ -53,6 +54,7 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
private static final String DESCENDANT_PATH = "//";
private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
+ private static final String ALTERNATE_ID = "alternate-id";
private final CpsDataService cpsDataService;
private final CpsQueryService cpsQueryService;
@@ -65,21 +67,23 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
private final CpsValidator cpsValidator;
@Override
- public Collection<String> queryCmHandleAdditionalProperties(final Map<String, String> privatePropertyQueryPairs) {
- return queryCmHandleAnyProperties(privatePropertyQueryPairs, PropertyType.ADDITIONAL);
+ public Collection<String> queryCmHandleAdditionalProperties(final Map<String, String> privatePropertyQueryPairs,
+ final Boolean outputAlternateId) {
+ return queryCmHandleAnyProperties(privatePropertyQueryPairs, PropertyType.ADDITIONAL, outputAlternateId);
}
@Override
- public Collection<String> queryCmHandlePublicProperties(final Map<String, String> publicPropertyQueryPairs) {
- return queryCmHandleAnyProperties(publicPropertyQueryPairs, PropertyType.PUBLIC);
+ public Collection<String> queryCmHandlePublicProperties(final Map<String, String> publicPropertyQueryPairs,
+ final Boolean outputAlternateId) {
+ return queryCmHandleAnyProperties(publicPropertyQueryPairs, PropertyType.PUBLIC, outputAlternateId);
}
@Override
- public Collection<String> queryCmHandlesByTrustLevel(final Map<String, String> trustLevelPropertyQueryPairs) {
+ public Collection<String> queryCmHandlesByTrustLevel(final Map<String, String> trustLevelPropertyQueryPairs,
+ final Boolean outputAlternateId) {
final String trustLevelProperty = trustLevelPropertyQueryPairs.values().iterator().next();
final TrustLevel targetTrustLevel = TrustLevel.valueOf(trustLevelProperty);
-
- return getCmHandleIdsByTrustLevel(targetTrustLevel);
+ return getCmHandleReferencesByTrustLevel(targetTrustLevel, outputAlternateId);
}
@Override
@@ -130,37 +134,64 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
return cmHandleIds;
}
- private Collection<String> getCmHandleIdsByTrustLevel(final TrustLevel targetTrustLevel) {
- final Collection<String> selectedCmHandleIds = new HashSet<>();
+ @Override
+ public Map<String, String> getCmHandleReferencesByDmiPluginIdentifier(final String dmiPluginIdentifier) {
+ final Map<String, String> cmHandleReferencesMap = new HashMap<>();
+ for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) {
+ for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty(
+ dmiPluginIdentifier,
+ modelledDmiServiceLeaf.getLeafName())) {
+ cmHandleReferencesMap.put(cmHandleAsDataNode.getLeaves().get("id").toString(),
+ cmHandleAsDataNode.getLeaves().get(ALTERNATE_ID).toString());
+ }
+ }
+ return cmHandleReferencesMap;
+ }
+
+ private Collection<String> getCmHandleReferencesByTrustLevel(final TrustLevel targetTrustLevel,
+ final Boolean outputAlternateId) {
+ final Collection<String> selectedCmHandleReferences = new HashSet<>();
for (final Map.Entry<String, TrustLevel> mapEntry : trustLevelPerDmiPlugin.entrySet()) {
final String dmiPluginIdentifier = mapEntry.getKey();
final TrustLevel dmiTrustLevel = mapEntry.getValue();
- final Collection<String> candidateCmHandleIds = getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
- for (final String candidateCmHandleId : candidateCmHandleIds) {
- final TrustLevel candidateCmHandleTrustLevel = trustLevelPerCmHandle.get(candidateCmHandleId);
+ final Map<String, String> candidateCmHandleReferences =
+ getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifier);
+ for (final Map.Entry<String, String> candidateCmHandleReference : candidateCmHandleReferences.entrySet()) {
+ final TrustLevel candidateCmHandleTrustLevel =
+ trustLevelPerCmHandle.get(candidateCmHandleReference.getKey());
final TrustLevel effectiveTrustlevel =
candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel);
if (targetTrustLevel.equals(effectiveTrustlevel)) {
- selectedCmHandleIds.add(candidateCmHandleId);
+ if (Boolean.TRUE.equals(outputAlternateId)) {
+ selectedCmHandleReferences.add(candidateCmHandleReference.getValue());
+ } else {
+ selectedCmHandleReferences.add(candidateCmHandleReference.getKey());
+ }
}
}
}
-
- return selectedCmHandleIds;
+ return selectedCmHandleReferences;
}
- private Collection<String> collectCmHandleIdsFromDataNodes(final Collection<DataNode> dataNodes) {
- return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+ private Collection<String> collectCmHandleReferencesFromDataNodes(final Collection<DataNode> dataNodes,
+ final Boolean outputAlternateId) {
+ if (Boolean.TRUE.equals(outputAlternateId)) {
+ return dataNodes.stream().map(dataNode ->
+ (String) dataNode.getLeaves().get(ALTERNATE_ID)).collect(Collectors.toSet());
+ } else {
+ return dataNodes.stream().map(dataNode ->
+ (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+ }
}
private Collection<String> queryCmHandleAnyProperties(
final Map<String, String> propertyQueryPairs,
- final PropertyType propertyType) {
+ final PropertyType propertyType, final Boolean outputAlternateId) {
if (propertyQueryPairs.isEmpty()) {
return Collections.emptySet();
}
- Collection<String> cmHandleIds = null;
+ Collection<String> cmHandleReferences = null;
for (final Map.Entry<String, String> publicPropertyQueryPair : propertyQueryPairs.entrySet()) {
final String cpsPath = DESCENDANT_PATH + propertyType.getYangContainerName() + "[@name=\""
+ publicPropertyQueryPair.getKey()
@@ -168,17 +199,18 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
final Collection<DataNode> dataNodes = queryCmHandleAncestorsByCpsPath(cpsPath,
OMIT_DESCENDANTS);
- if (cmHandleIds == null) {
- cmHandleIds = collectCmHandleIdsFromDataNodes(dataNodes);
+ if (cmHandleReferences == null) {
+ cmHandleReferences = collectCmHandleReferencesFromDataNodes(dataNodes, outputAlternateId);
} else {
- final Collection<String> cmHandleIdsToRetain = collectCmHandleIdsFromDataNodes(dataNodes);
- cmHandleIds.retainAll(cmHandleIdsToRetain);
+ final Collection<String> cmHandleReferencesToRetain;
+ cmHandleReferencesToRetain = collectCmHandleReferencesFromDataNodes(dataNodes, outputAlternateId);
+ cmHandleReferences.retainAll(cmHandleReferencesToRetain);
}
- if (cmHandleIds.isEmpty()) {
+ if (cmHandleReferences.isEmpty()) {
break;
}
}
- return cmHandleIds;
+ return cmHandleReferences;
}
private Collection<DataNode> getCmHandlesByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier,
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java
index a0d3a3eaee..850edf7d57 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java
@@ -149,9 +149,12 @@ public interface InventoryPersistence extends NcmpPersistence {
* get CM handles that has given module names.
*
* @param moduleNamesForQuery module names
+ * @param outputAlternateIds Boolean for cm handle reference type either
+ * cm handle id (false or null) or alternate id (true)
* @return Collection of CM handle Ids
*/
- Collection<String> getCmHandleIdsWithGivenModules(Collection<String> moduleNamesForQuery);
+ Collection<String> getCmHandleReferencesWithGivenModules(Collection<String> moduleNamesForQuery,
+ Boolean outputAlternateIds);
/**
* Check database if cm handle id exists if not return false.
@@ -159,5 +162,5 @@ public interface InventoryPersistence extends NcmpPersistence {
* @param cmHandleId cmHandle Id
* @return Boolean
*/
- boolean isExistingCmHandleId(String cmHandleId);
+ Boolean isExistingCmHandleId(String cmHandleId);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java
index 06c3f8d2f4..655d8437b1 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java
@@ -201,12 +201,19 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
}
@Override
- public Collection<String> getCmHandleIdsWithGivenModules(final Collection<String> moduleNamesForQuery) {
- return cpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
+ public Collection<String> getCmHandleReferencesWithGivenModules(final Collection<String> moduleNamesForQuery,
+ final Boolean outputAlternateIds) {
+ if (Boolean.TRUE.equals(outputAlternateIds)) {
+ final Collection<String> cmHandleIds =
+ cpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
+ return getAlternateIdsFromDataNodes(getCmHandleDataNodes(cmHandleIds));
+ } else {
+ return cpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
+ }
}
@Override
- public boolean isExistingCmHandleId(final String cmHandleId) {
+ public Boolean isExistingCmHandleId(final String cmHandleId) {
try {
return !getCmHandleDataNodeByCmHandleId(cmHandleId).isEmpty();
} catch (final DataNodeNotFoundException exception) {
@@ -234,4 +241,9 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
private String createCmHandlesJsonData(final List<YangModelCmHandle> yangModelCmHandles) {
return "{\"cm-handles\":" + jsonObjectMapper.asJsonString(yangModelCmHandles) + "}";
}
+
+ private Collection<String> getAlternateIdsFromDataNodes(final Collection<DataNode> dataNodes) {
+ return dataNodes.stream().map(dataNode ->
+ (String) dataNode.getLeaves().get("alternate-id")).collect(Collectors.toSet());
+ }
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java
index e5848c0dfa..8301579b42 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryService.java
@@ -26,19 +26,22 @@ import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
public interface ParameterizedCmHandleQueryService {
/**
- * Query and return cm handle ids that match the given query parameters.
+ * Query and return cm handle ids or alternate ids that match the given query parameters.
* Supported query types:
* public properties
* modules
* cps-path
*
* @param cmHandleQueryServiceParameters the cm handle query parameters
- * @return collection of cm handle ids
+ * @param outputAlternateId Boolean for cm handle reference type either
+ * cm handle id (false or null) or alternate id (true)
+ * @return collection of cm handle ids or alternate ids
*/
- Collection<String> queryCmHandleIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+ Collection<String> queryCmHandleReferenceIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+ Boolean outputAlternateId);
/**
- * Query and return cm handle ids that match the given query parameters.
+ * Query and return cm handle ids or alternate ids that match the given query parameters.
* Supported query types:
* public properties
* private (additional) properties
@@ -46,9 +49,12 @@ public interface ParameterizedCmHandleQueryService {
* The inventory interface also allows conditions on private (additional) properties and dmi names
*
* @param cmHandleQueryServiceParameters the cm handle query parameters
+ * @param outputAlternateId Boolean for cm handle reference type either
+ * cm handle id (false or null) or alternate id (true)
* @return collection of cm handle ids
*/
- Collection<String> queryCmHandleIdsForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+ Collection<String> queryCmHandleIdsForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+ Boolean outputAlternateId);
/**
* Query and return cm handle objects that match the given query parameters.
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java
index 34eeaccf8f..bacbbe0c95 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java
@@ -37,10 +37,9 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.function.Function;
+import java.util.function.BiFunction;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
import org.onap.cps.cpspath.parser.PathParsingException;
import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters;
import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
@@ -54,7 +53,6 @@ import org.onap.cps.spi.model.DataNode;
import org.springframework.stereotype.Service;
@Service
-@Slf4j
@RequiredArgsConstructor
public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHandleQueryService {
@@ -63,19 +61,21 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
private final InventoryPersistence inventoryPersistence;
@Override
- public Collection<String> queryCmHandleIds(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
- return executeQueries(cmHandleQueryServiceParameters,
- this::executeCpsPathQuery,
- this::queryCmHandlesByPublicProperties,
- this::executeModuleNameQuery,
- this::queryCmHandlesByTrustLevel);
+ public Collection<String> queryCmHandleReferenceIds(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+ final Boolean outputAlternateId) {
+ return executeQueries(cmHandleQueryServiceParameters, outputAlternateId,
+ this::executeCpsPathQuery,
+ this::queryCmHandlesByPublicProperties,
+ this::executeModuleNameQuery,
+ this::queryCmHandlesByTrustLevel);
}
@Override
public Collection<String> queryCmHandleIdsForInventory(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
- return executeQueries(cmHandleQueryServiceParameters,
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+ final Boolean outputAlternateId) {
+ return executeQueries(cmHandleQueryServiceParameters, outputAlternateId,
this::executeCpsPathQuery,
this::queryCmHandlesByPublicProperties,
this::queryCmHandlesByPrivateProperties,
@@ -90,7 +90,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
return getAllCmHandles();
}
- final Collection<String> cmHandleIds = queryCmHandleIds(cmHandleQueryServiceParameters);
+ final Collection<String> cmHandleIds = queryCmHandleReferenceIds(cmHandleQueryServiceParameters, false);
return getNcmpServiceCmHandles(cmHandleIds);
}
@@ -102,7 +102,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
}
private Collection<String> queryCmHandlesByDmiPlugin(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) {
final Map<String, String> dmiPropertyQueryPairs =
getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
InventoryQueryConditions.CM_HANDLE_WITH_DMI_PLUGIN.getName());
@@ -113,11 +113,15 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
final String dmiPluginIdentifierValue = dmiPropertyQueryPairs
.get(PropertyType.DMI_PLUGIN.getYangContainerName());
- return cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifierValue);
+ if (Boolean.TRUE.equals(outputAlternateId)) {
+ return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifierValue).values();
+ } else {
+ return cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifierValue);
+ }
}
private Collection<String> queryCmHandlesByPrivateProperties(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) {
final Map<String, String> privatePropertyQueryPairs =
getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
@@ -126,11 +130,11 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
if (privatePropertyQueryPairs.isEmpty()) {
return NO_QUERY_TO_EXECUTE;
}
- return cmHandleQueryService.queryCmHandleAdditionalProperties(privatePropertyQueryPairs);
+ return cmHandleQueryService.queryCmHandleAdditionalProperties(privatePropertyQueryPairs, outputAlternateId);
}
private Collection<String> queryCmHandlesByPublicProperties(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) {
final Map<String, String> publicPropertyQueryPairs =
getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
@@ -139,11 +143,12 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
if (publicPropertyQueryPairs.isEmpty()) {
return NO_QUERY_TO_EXECUTE;
}
- return cmHandleQueryService.queryCmHandlePublicProperties(publicPropertyQueryPairs);
+ return cmHandleQueryService.queryCmHandlePublicProperties(publicPropertyQueryPairs, outputAlternateId);
}
private Collection<String> queryCmHandlesByTrustLevel(final CmHandleQueryServiceParameters
- cmHandleQueryServiceParameters) {
+ cmHandleQueryServiceParameters,
+ final Boolean outputAlternateId) {
final Map<String, String> trustLevelPropertyQueryPairs =
getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
@@ -152,21 +157,21 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
if (trustLevelPropertyQueryPairs.isEmpty()) {
return NO_QUERY_TO_EXECUTE;
}
- return cmHandleQueryService.queryCmHandlesByTrustLevel(trustLevelPropertyQueryPairs);
+ return cmHandleQueryService.queryCmHandlesByTrustLevel(trustLevelPropertyQueryPairs, outputAlternateId);
}
private Collection<String> executeModuleNameQuery(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) {
final Collection<String> moduleNamesForQuery =
getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
if (moduleNamesForQuery.isEmpty()) {
return NO_QUERY_TO_EXECUTE;
}
- return inventoryPersistence.getCmHandleIdsWithGivenModules(moduleNamesForQuery);
+ return inventoryPersistence.getCmHandleReferencesWithGivenModules(moduleNamesForQuery, outputAlternateId);
}
private Collection<String> executeCpsPathQuery(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) {
final Map<String, String> cpsPathCondition
= getCpsPathCondition(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
if (!validateCpsPathConditionProperties(cpsPathCondition)) {
@@ -177,9 +182,9 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
return NO_QUERY_TO_EXECUTE;
}
try {
- cpsPathQueryResult = collectCmHandleIdsFromDataNodes(
- cmHandleQueryService.queryCmHandleAncestorsByCpsPath(
- cpsPathCondition.get("cpsPath"), OMIT_DESCENDANTS));
+ cpsPathQueryResult = collectCmHandleReferencesFromDataNodes(
+ cmHandleQueryService.queryCmHandleAncestorsByCpsPath(cpsPathCondition.get("cpsPath"), OMIT_DESCENDANTS),
+ outputAlternateId);
} catch (final PathParsingException pathParsingException) {
throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(),
pathParsingException);
@@ -220,10 +225,10 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
return Collections.emptyList();
}
- private Collection<String> getAllCmHandleIds() {
+ private Collection<String> getAllCmHandleReferences(final Boolean outputAlternateId) {
final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT, DIRECT_CHILDREN_ONLY)
- .iterator().next();
- return collectCmHandleIdsFromDataNodes(dataNode.getChildDataNodes());
+ .iterator().next();
+ return collectCmHandleReferencesFromDataNodes(dataNode.getChildDataNodes(), outputAlternateId);
}
private Collection<NcmpServiceCmHandle> getNcmpServiceCmHandles(final Collection<String> cmHandleIds) {
@@ -243,14 +248,17 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
}
private Collection<String> executeQueries(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
- final Function<CmHandleQueryServiceParameters, Collection<String>>...
- queryFunctions) {
+ final Boolean outputAlternateId,
+ final BiFunction<CmHandleQueryServiceParameters, Boolean,
+ Collection<String>>... queryFunctions) {
if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
- return getAllCmHandleIds();
+ return getAllCmHandleReferences(outputAlternateId);
}
Collection<String> combinedQueryResult = NO_QUERY_TO_EXECUTE;
- for (final Function<CmHandleQueryServiceParameters, Collection<String>> queryFunction : queryFunctions) {
- final Collection<String> queryResult = queryFunction.apply(cmHandleQueryServiceParameters);
+ for (final BiFunction<CmHandleQueryServiceParameters, Boolean,
+ Collection<String>> queryFunction : queryFunctions) {
+ final Collection<String> queryResult = queryFunction.apply(cmHandleQueryServiceParameters,
+ outputAlternateId);
if (noEntriesFoundCanStopQuerying(queryResult)) {
return Collections.emptySet();
}
@@ -277,8 +285,14 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
}
}
- private Collection<String> collectCmHandleIdsFromDataNodes(final Collection<DataNode> dataNodes) {
- return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+ private Collection<String> collectCmHandleReferencesFromDataNodes(final Collection<DataNode> dataNodes,
+ final Boolean outputAlternateId) {
+ if (Boolean.TRUE.equals(outputAlternateId)) {
+ return dataNodes.stream().map(dataNode ->
+ (String) dataNode.getLeaves().get("alternate-id")).collect(Collectors.toSet());
+ } else {
+ return dataNodes.stream().map(dataNode ->
+ (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+ }
}
-
}