diff options
author | seanbeirne <sean.beirne@est.tech> | 2024-11-05 10:21:30 +0000 |
---|---|---|
committer | seanbeirne <sean.beirne@est.tech> | 2024-11-13 10:52:19 +0000 |
commit | c37dee4816f51f750a9c92946dc9d4a558f3b812 (patch) | |
tree | d54dba7ce7c024c6be1a347190b14c8a2aecb092 /cps-ncmp-service/src | |
parent | 38cea5882ab71f23eddd3ffc9fd56c5d6540f28e (diff) |
Support alternate Id interface for ncmp inventory /ch/cmhandles endpoint
Issue-ID: CPS-2481
Change-Id: I8a200495be1afb9a4f256127f886bed78c77f653
Signed-off-by: seanbeirne <sean.beirne@est.tech>
Diffstat (limited to 'cps-ncmp-service/src')
13 files changed, 108 insertions, 80 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 e9e5f5499f..a8996874ff 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 @@ -75,13 +75,16 @@ public class NetworkCmProxyInventoryFacade { } /** - * Get all cm handle IDs by DMI plugin identifier. + * Get all cm handle references by DMI plugin identifier. * * @param dmiPluginIdentifier DMI plugin identifier - * @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 references */ - public Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) { - return cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier); + public Collection<String> getAllCmHandleReferencesByDmiPluginIdentifier(final String dmiPluginIdentifier, + final boolean outputAlternateId) { + return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifier, outputAlternateId); } /** @@ -90,10 +93,10 @@ public class NetworkCmProxyInventoryFacade { * @param cmHandleQueryServiceParameters cm handle query parameters * @param outputAlternateId Boolean for cm handle reference type either * cm handle id (false) or alternate id (true) - * @return collection of cm handle IDs + * @return collection of cm handle references */ public Collection<String> executeParameterizedCmHandleIdSearch( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) { validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES); return parameterizedCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters, @@ -159,11 +162,11 @@ 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) + * @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, - final Boolean outputAlternateId) { + final boolean outputAlternateId) { final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); @@ -224,4 +227,4 @@ public class NetworkCmProxyInventoryFacade { .getEffectiveTrustLevel(ncmpServiceCmHandle.getCmHandleId())); } -} +}
\ No newline at end of file diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java index f1dc9af09d..a0d89644e4 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/utils/DmiDataOperationsHelper.java @@ -71,8 +71,8 @@ public class DmiDataOperationsHelper { final Map<String, List<DmiDataOperation>> dmiDataOperationsOutPerDmiServiceName = new HashMap<>(); final MultiValueMap<DmiDataOperation, Map<NcmpResponseStatus, List<String>>> cmHandleReferencesPerResponseCodesPerOperation = new LinkedMultiValueMap<>(); - final Map<String, String> nonReadyCmHandleReferencesLookup = - filterAndGetNonReadyCmHandleReferences(yangModelCmHandles); + final Map<String, String> nonReadyAlternateIdPerCmHandleId = + filterAndGetNonReadyAlternateIdPerCmHandleId(yangModelCmHandles); final Map<String, Map<String, Map<String, String>>> dmiPropertiesPerCmHandleIdPerServiceName = DmiServiceNameOrganizer.getDmiPropertiesPerCmHandleIdPerServiceName(yangModelCmHandles); @@ -87,8 +87,8 @@ public class DmiDataOperationsHelper { final List<String> nonExistingCmHandleReferences = new ArrayList<>(); final List<String> nonReadyCmHandleReferences = new ArrayList<>(); for (final String cmHandleReference : dataOperationDefinitionIn.getCmHandleReferences()) { - if (nonReadyCmHandleReferencesLookup.containsKey(cmHandleReference) - || nonReadyCmHandleReferencesLookup.containsValue(cmHandleReference)) { + if (nonReadyAlternateIdPerCmHandleId.containsKey(cmHandleReference) + || nonReadyAlternateIdPerCmHandleId.containsValue(cmHandleReference)) { nonReadyCmHandleReferences.add(cmHandleReference); } else { final String cmHandleId = getCmHandleId(cmHandleReference, yangModelCmHandles); @@ -184,7 +184,7 @@ public class DmiDataOperationsHelper { return dmiBatchOperationsOut.get(dmiBatchOperationsOut.size() - 1); } - private static Map<String, String> filterAndGetNonReadyCmHandleReferences( + private static Map<String, String> filterAndGetNonReadyAlternateIdPerCmHandleId( final Collection<YangModelCmHandle> yangModelCmHandles) { final Map<String, String> cmHandleReferenceMap = new HashMap<>(yangModelCmHandles.size()); for (final YangModelCmHandle yangModelCmHandle: yangModelCmHandles) { 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 86e9c934ce..74c04928ed 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 @@ -36,7 +36,7 @@ public interface CmHandleQueryService { * @return Ids of Cm Handles which have these private properties */ Collection<String> queryCmHandleAdditionalProperties(Map<String, String> additionalPropertyQueryPairs, - Boolean outputAlternateId); + boolean outputAlternateId); /** * Query Cm Handles based on public properties. @@ -46,7 +46,7 @@ public interface CmHandleQueryService { * @return CmHandles which have these public properties */ Collection<String> queryCmHandlePublicProperties(Map<String, String> publicPropertyQueryPairs, - Boolean outputAlternateId); + boolean outputAlternateId); /** * Query Cm Handles based on Trust Level. @@ -56,7 +56,7 @@ public interface CmHandleQueryService { * @return Ids of Cm Handles which have desired trust level */ Collection<String> queryCmHandlesByTrustLevel(Map<String, String> trustLevelPropertyQueryPairs, - Boolean outputAlternateId); + boolean outputAlternateId); /** * Method which returns cm handles by the cm handles state. @@ -100,19 +100,21 @@ public interface CmHandleQueryService { Collection<DataNode> queryCmHandlesByOperationalSyncState(DataStoreSyncState dataStoreSyncState); /** - * Get all cm handles ids by DMI plugin identifier. + * Get collection of all cm handles references by DMI plugin identifier and alternate id output option. * * @param dmiPluginIdentifier DMI plugin identifier + * @param outputAlternateId Boolean for cm handle reference type either cmHandleId (false) or AlternateId (true) * @return collection of cm handle ids */ - Collection<String> getCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier); + Collection<String> getCmHandleReferencesByDmiPluginIdentifier(String dmiPluginIdentifier, + boolean outputAlternateId); /** - * Get map of cmHandle ids and alternate ids by DMI plugin identifier. + * Get map of cmHandle references by DMI plugin identifier. * * @param dmiPluginIdentifier DMI plugin identifier * @return map of cmHandle references key:CmHandleId Value:AlternateId */ - Map<String, String> getCmHandleReferencesByDmiPluginIdentifier(String dmiPluginIdentifier); + Map<String, String> getCmHandleReferencesMapByDmiPluginIdentifier(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 4249b452c3..1490d69881 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 @@ -68,19 +68,19 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { @Override public Collection<String> queryCmHandleAdditionalProperties(final Map<String, String> privatePropertyQueryPairs, - final Boolean outputAlternateId) { + final boolean outputAlternateId) { return queryCmHandleAnyProperties(privatePropertyQueryPairs, PropertyType.ADDITIONAL, outputAlternateId); } @Override public Collection<String> queryCmHandlePublicProperties(final Map<String, String> publicPropertyQueryPairs, - final Boolean outputAlternateId) { + final boolean outputAlternateId) { return queryCmHandleAnyProperties(publicPropertyQueryPairs, PropertyType.PUBLIC, outputAlternateId); } @Override public Collection<String> queryCmHandlesByTrustLevel(final Map<String, String> trustLevelPropertyQueryPairs, - final Boolean outputAlternateId) { + final boolean outputAlternateId) { final String trustLevelProperty = trustLevelPropertyQueryPairs.values().iterator().next(); final TrustLevel targetTrustLevel = TrustLevel.valueOf(trustLevelProperty); return getCmHandleReferencesByTrustLevel(targetTrustLevel, outputAlternateId); @@ -122,20 +122,25 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { } @Override - public Collection<String> getCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) { - final Collection<String> cmHandleIds = new HashSet<>(); + public Collection<String> getCmHandleReferencesByDmiPluginIdentifier(final String dmiPluginIdentifier, + final boolean outputAlternateId) { + final Collection<String> cmHandleReferences = new HashSet<>(); for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) { for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty( dmiPluginIdentifier, modelledDmiServiceLeaf.getLeafName())) { - cmHandleIds.add(cmHandleAsDataNode.getLeaves().get("id").toString()); + if (outputAlternateId) { + cmHandleReferences.add(cmHandleAsDataNode.getLeaves().get(ALTERNATE_ID).toString()); + } else { + cmHandleReferences.add(cmHandleAsDataNode.getLeaves().get("id").toString()); + } } } - return cmHandleIds; + return cmHandleReferences; } @Override - public Map<String, String> getCmHandleReferencesByDmiPluginIdentifier(final String dmiPluginIdentifier) { + public Map<String, String> getCmHandleReferencesMapByDmiPluginIdentifier(final String dmiPluginIdentifier) { final Map<String, String> cmHandleReferencesMap = new HashMap<>(); for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) { for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty( @@ -149,21 +154,21 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { } private Collection<String> getCmHandleReferencesByTrustLevel(final TrustLevel targetTrustLevel, - final Boolean outputAlternateId) { + 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 Map<String, String> candidateCmHandleReferences = - getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifier); + getCmHandleReferencesMapByDmiPluginIdentifier(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)) { - if (Boolean.TRUE.equals(outputAlternateId)) { + if (outputAlternateId) { selectedCmHandleReferences.add(candidateCmHandleReference.getValue()); } else { selectedCmHandleReferences.add(candidateCmHandleReference.getKey()); @@ -175,8 +180,8 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { } private Collection<String> collectCmHandleReferencesFromDataNodes(final Collection<DataNode> dataNodes, - final Boolean outputAlternateId) { - if (Boolean.TRUE.equals(outputAlternateId)) { + final boolean outputAlternateId) { + if (outputAlternateId) { return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get(ALTERNATE_ID)).collect(Collectors.toSet()); } else { @@ -187,7 +192,7 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { private Collection<String> queryCmHandleAnyProperties( final Map<String, String> propertyQueryPairs, - final PropertyType propertyType, final Boolean outputAlternateId) { + final PropertyType propertyType, final boolean outputAlternateId) { if (propertyQueryPairs.isEmpty()) { return Collections.emptySet(); } 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 de8e8e80a7..61d7df923e 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 @@ -162,7 +162,7 @@ public interface InventoryPersistence extends NcmpPersistence { * @return Collection of CM handle Ids */ Collection<String> getCmHandleReferencesWithGivenModules(Collection<String> moduleNamesForQuery, - Boolean outputAlternateIds); + boolean outputAlternateIds); /** * Check database if cm handle id exists if not return false. 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 d73fae9fbc..c4765ff53d 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 @@ -218,8 +218,8 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv @Override public Collection<String> getCmHandleReferencesWithGivenModules(final Collection<String> moduleNamesForQuery, - final Boolean outputAlternateIds) { - if (Boolean.TRUE.equals(outputAlternateIds)) { + final boolean outputAlternateIds) { + if (outputAlternateIds) { final Collection<String> cmHandleIds = cpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery); return getAlternateIdsFromDataNodes(getCmHandleDataNodes(cmHandleIds)); 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 8301579b42..3db4920d3e 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 @@ -38,7 +38,7 @@ public interface ParameterizedCmHandleQueryService { * @return collection of cm handle ids or alternate ids */ Collection<String> queryCmHandleReferenceIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters, - Boolean outputAlternateId); + boolean outputAlternateId); /** * Query and return cm handle ids or alternate ids that match the given query parameters. @@ -54,7 +54,7 @@ public interface ParameterizedCmHandleQueryService { * @return collection of cm handle ids */ Collection<String> queryCmHandleIdsForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters, - Boolean outputAlternateId); + 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 bacbbe0c95..c0d4b08f3c 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 @@ -63,7 +63,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan @Override public Collection<String> queryCmHandleReferenceIds( final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, - final Boolean outputAlternateId) { + final boolean outputAlternateId) { return executeQueries(cmHandleQueryServiceParameters, outputAlternateId, this::executeCpsPathQuery, this::queryCmHandlesByPublicProperties, @@ -74,7 +74,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan @Override public Collection<String> queryCmHandleIdsForInventory( final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, - final Boolean outputAlternateId) { + final boolean outputAlternateId) { return executeQueries(cmHandleQueryServiceParameters, outputAlternateId, this::executeCpsPathQuery, this::queryCmHandlesByPublicProperties, @@ -102,7 +102,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan } private Collection<String> queryCmHandlesByDmiPlugin( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) { final Map<String, String> dmiPropertyQueryPairs = getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), InventoryQueryConditions.CM_HANDLE_WITH_DMI_PLUGIN.getName()); @@ -113,15 +113,17 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan final String dmiPluginIdentifierValue = dmiPropertyQueryPairs .get(PropertyType.DMI_PLUGIN.getYangContainerName()); - if (Boolean.TRUE.equals(outputAlternateId)) { - return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifierValue).values(); + if (outputAlternateId) { + return + cmHandleQueryService.getCmHandleReferencesMapByDmiPluginIdentifier(dmiPluginIdentifierValue).values(); } else { - return cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifierValue); + return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifierValue, + outputAlternateId); } } private Collection<String> queryCmHandlesByPrivateProperties( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) { final Map<String, String> privatePropertyQueryPairs = getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), @@ -134,7 +136,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan } private Collection<String> queryCmHandlesByPublicProperties( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) { final Map<String, String> publicPropertyQueryPairs = getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), @@ -148,7 +150,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan private Collection<String> queryCmHandlesByTrustLevel(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, - final Boolean outputAlternateId) { + final boolean outputAlternateId) { final Map<String, String> trustLevelPropertyQueryPairs = getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), @@ -161,7 +163,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan } private Collection<String> executeModuleNameQuery( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) { final Collection<String> moduleNamesForQuery = getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); if (moduleNamesForQuery.isEmpty()) { @@ -171,7 +173,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan } private Collection<String> executeCpsPathQuery( - final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Boolean outputAlternateId) { + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) { final Map<String, String> cpsPathCondition = getCpsPathCondition(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); if (!validateCpsPathConditionProperties(cpsPathCondition)) { @@ -225,7 +227,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan return Collections.emptyList(); } - private Collection<String> getAllCmHandleReferences(final Boolean outputAlternateId) { + private Collection<String> getAllCmHandleReferences(final boolean outputAlternateId) { final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT, DIRECT_CHILDREN_ONLY) .iterator().next(); return collectCmHandleReferencesFromDataNodes(dataNode.getChildDataNodes(), outputAlternateId); @@ -248,7 +250,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan } private Collection<String> executeQueries(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, - final Boolean outputAlternateId, + final boolean outputAlternateId, final BiFunction<CmHandleQueryServiceParameters, Boolean, Collection<String>>... queryFunctions) { if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) { @@ -286,8 +288,8 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan } private Collection<String> collectCmHandleReferencesFromDataNodes(final Collection<DataNode> dataNodes, - final Boolean outputAlternateId) { - if (Boolean.TRUE.equals(outputAlternateId)) { + final boolean outputAlternateId) { + if (outputAlternateId) { return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("alternate-id")).collect(Collectors.toSet()); } else { diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java index 7581c4af7a..aca485f53d 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/trustlevel/DmiPluginTrustLevelWatchDog.java @@ -66,7 +66,7 @@ public class DmiPluginTrustLevelWatchDog { log.debug("The Dmi Plugin: {} has already the same trust level: {}", dmiServiceName, newDmiTrustLevel); } else { final Collection<String> cmHandleIds = - cmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier(dmiServiceName); + cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(dmiServiceName, false); trustLevelManager.updateDmi(dmiServiceName, cmHandleIds, newDmiTrustLevel); } }); diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy index 0c50e3d4ee..ce08156fec 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy @@ -199,22 +199,26 @@ class CmHandleQueryServiceImplSpec extends Specification { assert result.contains(cmHandleDataNode) } - def 'Get all cm handles by dmi plugin identifier'() { + def 'Get all cm handles by dmi plugin identifier and alternate id output option where #scenario'() { given: 'the DataNodes queried for a given cpsPath are returned from the persistence service.' mockResponses() - when: 'cm Handles are fetched for a given dmi plugin identifier' - def result = objectUnderTest.getCmHandleIdsByDmiPluginIdentifier('my-dmi-plugin-identifier') + when: 'cm Handles are fetched for a given dmi plugin identifier and alternate id output option' + def result = objectUnderTest.getCmHandleReferencesByDmiPluginIdentifier('my-dmi-plugin-identifier', outputAlternateId) then: 'result is the correct size' assert result.size() == 3 and: 'result contains the correct cm handles' - assert result.containsAll('PNFDemo', 'PNFDemo2', 'PNFDemo4') + assert result.containsAll(expectedResult) + where: + scenario | outputAlternateId || expectedResult + 'output is for alternate ids' | true || ['alt-PNFDemo', 'alt-PNFDemo2', 'alt-PNFDemo4'] + 'output is for cm handle ids' | false || ['PNFDemo', 'PNFDemo2', 'PNFDemo4'] } def 'Get all alternateIds by dmi plugin identifier'() { given: 'the DataNodes queried for a given cpsPath are returned from the persistence service.' mockResponses() when: 'cm Handles are fetched for a given dmi plugin identifier' - def result = objectUnderTest.getCmHandleReferencesByDmiPluginIdentifier('my-dmi-plugin-identifier').values() + def result = objectUnderTest.getCmHandleReferencesMapByDmiPluginIdentifier('my-dmi-plugin-identifier').values() then: 'result is the correct size' assert result.size() == 3 and: 'result contains the correct alternate Ids' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy index 34d9374f78..00f092ff75 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy @@ -381,9 +381,7 @@ class InventoryPersistenceImplSpec extends Specification { def 'Check if cm handle exists for a given cm handle id'() { given: 'data service returns a datanode with correct cm handle id' mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, xpath, INCLUDE_ALL_DESCENDANTS) >> [dataNode] - when: 'method is called to check if cm handle exists from cm handle id' - def result = objectUnderTest.isExistingCmHandleId('some-cm-handle') - then: 'check if cm handle id in datanode is equal to given cm handle id' - assert result == true + expect: 'cm handle exists for given cm handle id' + assert true == objectUnderTest.isExistingCmHandleId('some-cm-handle') } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy index 4c554c6af5..282bd9e89b 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy @@ -78,15 +78,20 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification { assert result.contains('cmHandle2') } - def 'Get all cm handle IDs by DMI plugin identifier.' () { - given: 'cm handle queries service returns cm handles' - 1 * mockCmHandleQueryService.getCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier') >> ['cm-handle-1','cm-handle-2'] - when: 'cm handle Ids are requested with dmi plugin identifier' - def result = objectUnderTest.getAllCmHandleIdsByDmiPluginIdentifier('some-dmi-plugin-identifier') + def 'Get all cm handle references by DMI plugin identifier and alternate id output option where #scenario.' () { + given: 'cm handle queries service returns cm handle references' + mockCmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier('some-dmi-plugin-identifier', false) >> ['cm-handle-1','cm-handle-2'] + mockCmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier('some-dmi-plugin-identifier', true) >> ['alternate-id-1','alternate-id-2'] + when: 'cm handle references are requested with dmi plugin identifier and alternate id output option' + def result = objectUnderTest.getAllCmHandleReferencesByDmiPluginIdentifier('some-dmi-plugin-identifier', outputAlternateId) then: 'the result size is correct' assert result.size() == 2 and: 'the result returns the correct details' - assert result.containsAll('cm-handle-1','cm-handle-2') + assert result.containsAll(expectedResult) + where: + scenario | outputAlternateId || expectedResult + 'output is for alternate ids' | true || ['alternate-id-1', 'alternate-id-2'] + 'output is for cm handle ids' | false || ['cm-handle-1','cm-handle-2'] } def 'Getting Yang Resources for a given #scenario'() { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy index 9a81807ef9..0c44196348 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy @@ -200,22 +200,31 @@ class ParameterizedCmHandleQueryServiceSpec extends Specification { 'additional properties, no matching cm handles' | 'hasAllAdditionalProperties' | null | [] || 0 } - def 'Retrieve CMHandleIds by different DMI properties with #scenario.' () { + def 'Retrieve alternate ids by different DMI properties.' () { given: 'a query object created with dmi plugin as condition' def cmHandleQueryParameters = new CmHandleQueryServiceParameters() def conditionProperties = createConditionProperties('cmHandleWithDmiPlugin', [['some-key': 'some-value']]) cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties]) and: 'the inventoryPersistence returns different CmHandleIds' - partiallyMockedCmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(*_) >> cmHandleQueryResult - partiallyMockedCmHandleQueries.getCmHandleReferencesByDmiPluginIdentifier(*_) >> cmHandleQueryResult + partiallyMockedCmHandleQueries.getCmHandleReferencesMapByDmiPluginIdentifier(*_) >> [:] when: 'the query executed' - def result = objectUnderTestWithPartiallyMockedQueries.queryCmHandleIdsForInventory(cmHandleQueryParameters, outputAlternateId) + def result = objectUnderTestWithPartiallyMockedQueries.queryCmHandleIdsForInventory(cmHandleQueryParameters, true) then: 'the expected number of results are returned.' - assert result.size() == expectedCmHandleIdsSize - where: 'the following data is used' - scenario | cmHandleQueryResult | outputAlternateId || expectedCmHandleIdsSize - 'some matches' | ['h1','h2'] | false || 2 - 'no matches' | [:] | true || 0 + assert result.size() == 0 + } + + def 'Retrieve cm handle ids by different DMI properties.' () { + given: 'a query object created with dmi plugin as condition' + def cmHandleQueryParameters = new CmHandleQueryServiceParameters() + def conditionProperties = createConditionProperties('cmHandleWithDmiPlugin', [['some-key': 'some-value']]) + cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties]) + and: 'the inventoryPersistence returns different CmHandleIds' + partiallyMockedCmHandleQueries.getCmHandleReferencesByDmiPluginIdentifier(_, _) >> ['h1','h2'] + when: 'the query executed' + def result = objectUnderTestWithPartiallyMockedQueries.queryCmHandleIdsForInventory(cmHandleQueryParameters, false) + then: 'the expected number of results are returned.' + assert result.size() == 2 + } def 'Combine two query results where #scenario.'() { |