X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-service%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Fimpl%2FNetworkCmProxyCmHandlerQueryServiceImpl.java;h=a8fc6d7057041056f122b3fe050a61fcfb0035ba;hb=37d72855721caa646144ad323fe51ae78af15507;hp=1674c52fc9bf16598ae4273ff6fa04bf84af847e;hpb=94d77dd3430bf504b1fe1209760cfeedb47752a7;p=cps.git diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java index 1674c52fc..a8fc6d705 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java @@ -20,11 +20,11 @@ package org.onap.cps.ncmp.api.impl; +import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCpsPathConditionProperties; +import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateModuleNameConditionProperties; import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle; import static org.onap.cps.spi.FetchDescendantsOption.FETCH_DIRECT_CHILDREN_ONLY; import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS; -import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties; -import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateModuleNameConditionProperties; import java.util.ArrayList; import java.util.Collection; @@ -40,16 +40,18 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.cpspath.parser.PathParsingException; import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService; +import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions; +import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions; import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; import org.onap.cps.ncmp.api.inventory.CmHandleQueries; import org.onap.cps.ncmp.api.inventory.InventoryPersistence; +import org.onap.cps.ncmp.api.inventory.enums.PropertyType; +import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.spi.exceptions.DataValidationException; import org.onap.cps.spi.model.Anchor; -import org.onap.cps.spi.model.CmHandleQueryServiceParameters; import org.onap.cps.spi.model.ConditionProperties; import org.onap.cps.spi.model.DataNode; -import org.onap.cps.utils.ValidQueryProperties; import org.springframework.stereotype.Service; @Service @@ -113,6 +115,92 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm return moduleNameQueryResult; } + @Override + public Set queryCmHandleIdsForInventory( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + + if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) { + return getAllCmHandleIds(); + } + + final Map publicPropertiesQueryResult = queryCmHandlesByPublicProperties( + cmHandleQueryServiceParameters); + if (publicPropertiesQueryResult != null && publicPropertiesQueryResult.isEmpty()) { + return Collections.emptySet(); + } + + final Map privatePropertiesQueryResult = queryCmHandlesByPrivateProperties( + cmHandleQueryServiceParameters); + if (privatePropertiesQueryResult != null && privatePropertiesQueryResult.isEmpty()) { + return Collections.emptySet(); + } + + final Map dmiPropertiesQueryResult = queryCmHandlesByDmiPlugin( + cmHandleQueryServiceParameters); + if (dmiPropertiesQueryResult != null && dmiPropertiesQueryResult.isEmpty()) { + return Collections.emptySet(); + } + + final Map combinedResult = + combineQueryResults(publicPropertiesQueryResult, privatePropertiesQueryResult, dmiPropertiesQueryResult); + + return combinedResult.keySet(); + } + + private Map queryCmHandlesByDmiPlugin( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + final Map dmiPropertyQueryPairs = + getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), + InventoryQueryConditions.CM_HANDLE_WITH_DMI_PLUGIN.getName()); + if (dmiPropertyQueryPairs.isEmpty()) { + return NO_QUERY_TO_EXECUTE; + } + + final String dmiPluginIdentifierValue = dmiPropertyQueryPairs.get( + PropertyType.DMI_PLUGIN.getYangContainerName()); + + final Set cmHandlesByDmiPluginIdentifier = cmHandleQueries + .getCmHandlesByDmiPluginIdentifier(dmiPluginIdentifierValue); + + return cmHandlesByDmiPluginIdentifier.stream() + .collect(Collectors.toMap(NcmpServiceCmHandle::getCmHandleId, cmH -> cmH)); + } + + private Map queryCmHandlesByPrivateProperties( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + + final Map privatePropertyQueryPairs = + getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), + InventoryQueryConditions.HAS_ALL_ADDITIONAL_PROPERTIES.getName()); + + return privatePropertyQueryPairs.isEmpty() + ? NO_QUERY_TO_EXECUTE + : cmHandleQueries.queryCmHandleAdditionalProperties(privatePropertyQueryPairs); + } + + private Map queryCmHandlesByPublicProperties( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + + final Map publicPropertyQueryPairs = + getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), + CmHandleQueryConditions.HAS_ALL_PROPERTIES.getConditionName()); + + return publicPropertyQueryPairs.isEmpty() + ? NO_QUERY_TO_EXECUTE + : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs); + } + + private Map combineQueryResults( + final Map publicPropertiesQueryResult, + final Map privatePropertiesQueryResult, + final Map dmiPropertiesQueryResult) { + + final Map propertiesCombinedResult = cmHandleQueries + .combineCmHandleQueries(publicPropertiesQueryResult, privatePropertiesQueryResult); + return cmHandleQueries + .combineCmHandleQueries(propertiesCombinedResult, dmiPropertiesQueryResult); + } + private Map combineWithModuleNameQuery( final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final Map previousQueryResult) { @@ -164,7 +252,8 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm } final Map publicPropertyQueryPairs = - getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters()); + getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(), + CmHandleQueryConditions.HAS_ALL_PROPERTIES.getConditionName()); final Map propertiesQueryResult = publicPropertyQueryPairs.isEmpty() ? NO_QUERY_TO_EXECUTE : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs); @@ -178,7 +267,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm private Collection getModuleNamesForQuery(final List conditionProperties) { final List result = new ArrayList<>(); - getConditions(conditionProperties, ValidQueryProperties.HAS_ALL_MODULES.getQueryProperty()) + getConditions(conditionProperties, CmHandleQueryConditions.HAS_ALL_MODULES.getConditionName()) .parallelStream().forEach( conditionProperty -> { validateModuleNameConditionProperties(conditionProperty); @@ -190,15 +279,15 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm private Map getCpsPath(final List conditionProperties) { final Map result = new HashMap<>(); - getConditions(conditionProperties, ValidQueryProperties.WITH_CPS_PATH.getQueryProperty()).forEach( + getConditions(conditionProperties, CmHandleQueryConditions.WITH_CPS_PATH.getConditionName()).forEach( result::putAll); return result; } - private Map getPublicPropertyPairs(final List conditionProperties) { + private Map getPropertyPairs(final List conditionProperties, + final String queryProperty) { final Map result = new HashMap<>(); - getConditions(conditionProperties, - ValidQueryProperties.HAS_ALL_PROPERTIES.getQueryProperty()).forEach(result::putAll); + getConditions(conditionProperties, queryProperty).forEach(result::putAll); return result; }