diff options
author | lukegleeson <luke.gleeson@est.tech> | 2022-08-26 10:55:04 +0100 |
---|---|---|
committer | lukegleeson <luke.gleeson@est.tech> | 2022-10-20 16:52:21 +0100 |
commit | e5254a7b007e4a0dc59003d94f43e688c25cf7d1 (patch) | |
tree | 96c40dfc8ab48834c9520b875cf4bb4042609aed /cps-ncmp-service/src/main/java | |
parent | 1377bf984e9d3ae97b1dc58c7d62ff1cafe60bb9 (diff) |
CPS Validator Changes
Changed CPS Validator from static to non-static
Moved CPSValidator implementation to rest interface layer to prevent duplicated usage
Created CPSValidator interface in persistence layer
Removed unnecessary tests
Refactored misplaced tests
Copyright fixes
Copyright Check Script output formatting fix
Issue-ID: CPS-1228
Signed-off-by: lukegleeson <luke.gleeson@est.tech>
Change-Id: I4c99a51870e7d3b8e416bc1f909aeed5dc3baa42
Diffstat (limited to 'cps-ncmp-service/src/main/java')
6 files changed, 14 insertions, 25 deletions
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 0983889802..27c3646a5e 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 @@ -67,7 +67,6 @@ 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; @@ -148,20 +147,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<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId); } @Override public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId); } @@ -206,7 +202,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)) { @@ -250,7 +245,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService */ @Override public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle( inventoryPersistence.getYangModelCmHandle(cmHandleId)); } @@ -263,7 +257,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService */ @Override public Map<String, String> getCmHandlePublicProperties(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); final List<YangModelCmHandle.Property> yangModelPublicProperties = yangModelCmHandle.getPublicProperties(); @@ -280,7 +273,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService */ @Override public CompositeState getCmHandleCompositeState(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState(); } @@ -320,7 +312,6 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService new ArrayList<>(tobeRemovedCmHandles.size()); for (final String cmHandleId : tobeRemovedCmHandles) { try { - CpsValidator.validateNameCharacters(cmHandleId); final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId); lcmEventsCmHandleStateHandler.updateCmHandleState(yangModelCmHandle, CmHandleState.DELETING); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java index d9aeaf2589..f39c2f9b60 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java @@ -43,7 +43,6 @@ import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.onap.cps.spi.exceptions.DataValidationException; import org.onap.cps.spi.model.DataNode; import org.onap.cps.spi.model.DataNodeBuilder; -import org.onap.cps.utils.CpsValidator; import org.springframework.stereotype.Service; @Slf4j @@ -67,7 +66,6 @@ public class NetworkCmProxyDataServicePropertyHandler { for (final NcmpServiceCmHandle ncmpServiceCmHandle : ncmpServiceCmHandles) { final String cmHandleId = ncmpServiceCmHandle.getCmHandleId(); try { - CpsValidator.validateNameCharacters(cmHandleId); final DataNode existingCmHandleDataNode = inventoryPersistence.getCmHandleDataNode(cmHandleId); processUpdates(existingCmHandleDataNode, ncmpServiceCmHandle); cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java index d46d634104..83faa005f0 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java @@ -16,7 +16,7 @@ * limitations under the License. * * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= + * ============LICENSE_END========================================================= */ package org.onap.cps.ncmp.api.impl.operations; @@ -33,7 +33,6 @@ import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; import org.onap.cps.ncmp.api.inventory.CmHandleState; import org.onap.cps.ncmp.api.inventory.InventoryPersistence; import org.onap.cps.spi.exceptions.CpsException; -import org.onap.cps.utils.CpsValidator; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; @@ -131,7 +130,6 @@ public class DmiDataOperations extends DmiOperations { } private YangModelCmHandle getYangModelCmHandle(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); return inventoryPersistence.getYangModelCmHandle(cmHandleId); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilder.java index b679107251..5f4a6540c2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilder.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. * * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= + * ============LICENSE_END========================================================= */ package org.onap.cps.ncmp.api.impl.utils; @@ -30,7 +30,7 @@ import org.apache.logging.log4j.util.TriConsumer; import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration; import org.onap.cps.ncmp.api.impl.operations.DmiOperations; import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; -import org.onap.cps.utils.CpsValidator; +import org.onap.cps.spi.utils.CpsValidator; import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -41,6 +41,7 @@ import org.springframework.web.util.UriComponentsBuilder; public class DmiServiceUrlBuilder { private final NcmpConfiguration.DmiProperties dmiProperties; + private final CpsValidator cpsValidator; /** * This method creates the dmi service url. @@ -84,7 +85,7 @@ public class DmiServiceUrlBuilder { public Map<String, Object> populateUriVariables(final YangModelCmHandle yangModelCmHandle, final String cmHandleId, final DmiOperations.DataStoreEnum dataStore) { - CpsValidator.validateNameCharacters(cmHandleId); + cpsValidator.validateNameCharacters(cmHandleId); final Map<String, Object> uriVariables = new HashMap<>(); final String dmiBasePath = dmiProperties.getDmiBasePath(); uriVariables.put("dmiServiceName", diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java index f842ddbc1a..aabc52c592 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java @@ -37,7 +37,6 @@ import lombok.Setter; import org.onap.cps.ncmp.api.impl.operations.RequiredDmiService; import org.onap.cps.ncmp.api.inventory.CompositeState; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; -import org.onap.cps.utils.CpsValidator; /** * Cm Handle which follows the Yang resource dmi registry model when persisting data to DMI or the DB. @@ -104,7 +103,6 @@ public class YangModelCmHandle { final String dmiDataServiceName, final String dmiModelServiceName, final NcmpServiceCmHandle ncmpServiceCmHandle) { - CpsValidator.validateNameCharacters(ncmpServiceCmHandle.getCmHandleId()); final YangModelCmHandle yangModelCmHandle = new YangModelCmHandle(); yangModelCmHandle.setId(ncmpServiceCmHandle.getCmHandleId()); yangModelCmHandle.setDmiServiceName(dmiServiceName); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java index eed47eddab..adba198408 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java @@ -46,7 +46,7 @@ import org.onap.cps.spi.model.Anchor; import org.onap.cps.spi.model.DataNode; import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; -import org.onap.cps.utils.CpsValidator; +import org.onap.cps.spi.utils.CpsValidator; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.stereotype.Component; @@ -73,11 +73,14 @@ public class InventoryPersistenceImpl implements InventoryPersistence { private final CpsAdminPersistenceService cpsAdminPersistenceService; + private final CpsValidator cpsValidator; + @Override public CompositeState getCmHandleState(final String cmHandleId) { final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId) + "/state", - FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); + String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId) + "/state", + FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); + cpsValidator.validateNameCharacters(cmHandleId); return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build(); } @@ -102,7 +105,7 @@ public class InventoryPersistenceImpl implements InventoryPersistence { @Override public YangModelCmHandle getYangModelCmHandle(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); + cpsValidator.validateNameCharacters(cmHandleId); return YangDataConverter.convertCmHandleToYangModel(getCmHandleDataNode(cmHandleId), cmHandleId); } @@ -113,7 +116,7 @@ public class InventoryPersistenceImpl implements InventoryPersistence { @Override public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) { - CpsValidator.validateNameCharacters(cmHandleId); + cpsValidator.validateNameCharacters(cmHandleId); return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId); } @@ -143,7 +146,7 @@ public class InventoryPersistenceImpl implements InventoryPersistence { @Override public void deleteSchemaSetWithCascade(final String schemaSetName) { try { - CpsValidator.validateNameCharacters(schemaSetName); + cpsValidator.validateNameCharacters(schemaSetName); cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, schemaSetName, CASCADE_DELETE_ALLOWED); } catch (final SchemaSetNotFoundException schemaSetNotFoundException) { |