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%2FNetworkCmProxyDataServiceImpl.java;h=8b80a0341a76390545e4cf98e13bb039841bd1e5;hb=c3928f8614d007384969f7f24a7ef31c73647992;hp=09838898024b9a14e2ab8abecd3dac463ec42639;hpb=8ebc0ab268b9e474e42078336f3e50258c1bbf21;p=cps.git diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java index 098388980..8b80a0341 100755 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java @@ -25,7 +25,7 @@ package org.onap.cps.ncmp.api.impl; import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME; import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum; -import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters; +import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters; import com.hazelcast.map.IMap; import java.time.OffsetDateTime; @@ -45,6 +45,8 @@ import org.onap.cps.ncmp.api.NetworkCmProxyDataService; import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler; import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations; import org.onap.cps.ncmp.api.impl.operations.DmiOperations; +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.impl.yangmodels.YangModelCmHandle; import org.onap.cps.ncmp.api.inventory.CmHandleQueries; @@ -54,6 +56,7 @@ import org.onap.cps.ncmp.api.inventory.CompositeStateUtils; import org.onap.cps.ncmp.api.inventory.DataStoreSyncState; import org.onap.cps.ncmp.api.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters; +import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters; import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError; import org.onap.cps.ncmp.api.models.DmiPluginRegistration; @@ -64,10 +67,8 @@ import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch; import org.onap.cps.spi.exceptions.CpsException; import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.onap.cps.spi.exceptions.DataValidationException; -import org.onap.cps.spi.model.CmHandleQueryServiceParameters; import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; -import org.onap.cps.utils.CpsValidator; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -92,8 +93,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final DmiPluginRegistration dmiPluginRegistration) { dmiPluginRegistration.validateDmiPluginRegistration(); final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse(); - dmiPluginRegistrationResponse.setRemovedCmHandles( - parseAndRemoveCmHandlesInDmiRegistration(dmiPluginRegistration.getRemovedCmHandles())); + + if (!dmiPluginRegistration.getRemovedCmHandles().isEmpty()) { + dmiPluginRegistrationResponse.setRemovedCmHandles( + parseAndRemoveCmHandlesInDmiRegistration(dmiPluginRegistration.getRemovedCmHandles())); + } + if (!dmiPluginRegistration.getCreatedCmHandles().isEmpty()) { dmiPluginRegistrationResponse.setCreatedCmHandles( parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(dmiPluginRegistration)); @@ -148,20 +153,17 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final OperationEnum operation, final String requestData, final String dataType) { - CpsValidator.validateNameCharacters(cmHandleId); return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier, operation, requestData, dataType); } @Override public Collection getYangResourcesModuleReferences(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId); } @Override public Collection getModuleDefinitionsByCmHandleId(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId); } @@ -175,9 +177,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService public Set executeCmHandleSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) { final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); - - validateCmHandleQueryParameters(cmHandleQueryServiceParameters); - + validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); return networkCmProxyCmHandlerQueryService.queryCmHandles(cmHandleQueryServiceParameters); } @@ -191,9 +191,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService public Set executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) { final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType( cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class); - - validateCmHandleQueryParameters(cmHandleQueryServiceParameters); - + validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES); return networkCmProxyCmHandlerQueryService.queryCmHandleIds(cmHandleQueryServiceParameters); } @@ -206,7 +204,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService */ @Override public void setDataSyncEnabled(final String cmHandleId, final boolean dataSyncEnabled) { - CpsValidator.validateNameCharacters(cmHandleId); final CompositeState compositeState = inventoryPersistence .getCmHandleState(cmHandleId); if (compositeState.getDataSyncEnabled().equals(dataSyncEnabled)) { @@ -242,6 +239,19 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService return cmHandleIds; } + /** + * Get all cm handle IDs by various properties. + * + * @param cmHandleQueryServiceParameters cm handle query parameters + * @return set of cm handle IDs + */ + @Override + public Set executeCmHandleIdSearchForInventory( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES); + return networkCmProxyCmHandlerQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters); + } + /** * Retrieve cm handle details for a given cm handle. * @@ -250,7 +260,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService */ @Override public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle( inventoryPersistence.getYangModelCmHandle(cmHandleId)); } @@ -263,7 +272,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService */ @Override public Map getCmHandlePublicProperties(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); final List yangModelPublicProperties = yangModelCmHandle.getPublicProperties(); @@ -280,7 +288,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService */ @Override public CompositeState getCmHandleCompositeState(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState(); } @@ -318,16 +325,15 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final List tobeRemovedCmHandles) { final List cmHandleRegistrationResponses = new ArrayList<>(tobeRemovedCmHandles.size()); + final List yangModelCmHandles = + tobeRemovedCmHandles.stream().map(inventoryPersistence::getYangModelCmHandle) + .collect(Collectors.toList()); + updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING); + for (final String cmHandleId : tobeRemovedCmHandles) { try { - CpsValidator.validateNameCharacters(cmHandleId); - final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); - lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle, - CmHandleState.DELETING); deleteCmHandleFromDbAndModuleSyncMap(cmHandleId); cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)); - lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle, - CmHandleState.DELETED); } catch (final DataNodeNotFoundException dataNodeNotFoundException) { log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandleId, dataNodeNotFoundException.getMessage()); @@ -345,9 +351,19 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception)); } } + + updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETED); return cmHandleRegistrationResponses; } + private void updateCmHandleStateBatch(final List yangModelCmHandles, + final CmHandleState cmHandleState) { + final Map cmHandleIdsToBeRemoved = new HashMap<>(); + yangModelCmHandles.stream().forEach(yangModelCmHandle -> + cmHandleIdsToBeRemoved.put(yangModelCmHandle, cmHandleState)); + lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleIdsToBeRemoved); + } + private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) { inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId); inventoryPersistence.deleteListOrListElement("/dmi-registry/cm-handles[@id='" + cmHandleId + "']");