From d5bda8848a661465f214b0bf11211e63b272cfd6 Mon Sep 17 00:00:00 2001 From: lukegleeson Date: Wed, 2 Mar 2022 14:32:47 +0000 Subject: Replacing ModelMapper with MapStruct - Removed Model Mapper from pom files - Replaced ModelMapper with MapStruct - Added Tests for MapStruct - Changed mapstruct annotations for individual variables to be null safe rather than all variables - Excluded generated code from code coverage - Set ModuleReferences input to required for SchemaSet so that ModuleReferences list set to empty list rather than null Issue-ID: CPS-127 Signed-off-by: lukegleeson Change-Id: I43f874aea79f58dda5526c6fdead27d8474d90af --- .../ncmp/rest/controller/NcmpRestInputMapper.java | 55 ++++++++++++++++++++++ .../rest/controller/NetworkCmProxyController.java | 13 +++-- .../NetworkCmProxyInventoryController.java | 4 +- .../cps/ncmp/rest/controller/RestInputMapper.java | 43 ----------------- 4 files changed, 63 insertions(+), 52 deletions(-) create mode 100644 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java delete mode 100644 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/RestInputMapper.java (limited to 'cps-ncmp-rest/src/main') diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java new file mode 100644 index 000000000..4c8fafea5 --- /dev/null +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.rest.controller; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.onap.cps.ncmp.api.models.DmiPluginRegistration; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; +import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration; +import org.onap.cps.ncmp.rest.model.RestInputCmHandle; +import org.onap.cps.ncmp.rest.model.RestModuleReference; +import org.onap.cps.spi.model.ModuleReference; + +@Mapper(componentModel = "spring") +public interface NcmpRestInputMapper { + + @Mapping(source = "createdCmHandles", target = "createdCmHandles", + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) + @Mapping(source = "updatedCmHandles", target = "updatedCmHandles", + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) + @Mapping(source = "removedCmHandles", target = "removedCmHandles", + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) + DmiPluginRegistration toDmiPluginRegistration(final RestDmiPluginRegistration restDmiPluginRegistration); + + @Mapping(source = "cmHandle", target = "cmHandleID") + @Mapping(source = "cmHandleProperties", target = "dmiProperties") + @Mapping(source = "publicCmHandleProperties", target = "publicProperties") + NcmpServiceCmHandle toNcmpServiceCmHandle(final RestInputCmHandle restInputCmHandle); + + RestModuleReference toRestModuleReference( + final ModuleReference moduleReference); +} \ No newline at end of file diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java index 2a336d52b..01b892218 100755 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java @@ -37,7 +37,6 @@ import javax.validation.Valid; import javax.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.modelmapper.ModelMapper; import org.onap.cps.ncmp.api.NetworkCmProxyDataService; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi; @@ -49,7 +48,7 @@ import org.onap.cps.ncmp.rest.model.ConditionProperties; import org.onap.cps.ncmp.rest.model.Conditions; import org.onap.cps.ncmp.rest.model.ModuleNameAsJsonObject; import org.onap.cps.ncmp.rest.model.ModuleNamesAsJsonArray; -import org.onap.cps.ncmp.rest.model.ModuleReference; +import org.onap.cps.ncmp.rest.model.RestModuleReference; import org.onap.cps.ncmp.rest.model.RestOutputCmHandle; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.HttpStatus; @@ -65,9 +64,9 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { private static final String NO_BODY = null; - private final ModelMapper modelMapper; private final NetworkCmProxyDataService networkCmProxyDataService; private final JsonObjectMapper jsonObjectMapper; + private final NcmpRestInputMapper ncmpRestInputMapper; /** * Get resource data from operational datastore. @@ -207,12 +206,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * @param cmHandle the cm handle * @return module references for cm handle. Namespace will be always blank because restConf does not include this. */ - public ResponseEntity> getModuleReferencesByCmHandle(final String cmHandle) { - final List moduleReferences = + public ResponseEntity> getModuleReferencesByCmHandle(final String cmHandle) { + final List restModuleReferences = networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle).stream() - .map(moduleReference -> modelMapper.map(moduleReference, ModuleReference.class)) + .map(ncmpRestInputMapper::toRestModuleReference) .collect(Collectors.toList()); - return new ResponseEntity<>(moduleReferences, HttpStatus.OK); + return new ResponseEntity<>(restModuleReferences, HttpStatus.OK); } private Collection processConditions(final List conditionProperties) { diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java index 36991952c..c9d26f2a5 100755 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java @@ -37,7 +37,7 @@ import org.springframework.web.bind.annotation.RestController; public class NetworkCmProxyInventoryController implements NetworkCmProxyInventoryApi { private final NetworkCmProxyDataService networkCmProxyDataService; - private final RestInputMapper restInputMapper; + private final NcmpRestInputMapper ncmpRestInputMapper; /** * Update DMI Plugin Registration (used for first registration also). @@ -47,7 +47,7 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor public ResponseEntity updateDmiPluginRegistration( final @Valid RestDmiPluginRegistration restDmiPluginRegistration) { networkCmProxyDataService.updateDmiRegistrationAndSyncModule( - restInputMapper.toDmiPluginRegistration(restDmiPluginRegistration)); + ncmpRestInputMapper.toDmiPluginRegistration(restDmiPluginRegistration)); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/RestInputMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/RestInputMapper.java deleted file mode 100644 index a1d046ece..000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/RestInputMapper.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.ncmp.rest.controller; - -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.NullValueMappingStrategy; -import org.mapstruct.NullValuePropertyMappingStrategy; -import org.onap.cps.ncmp.api.models.DmiPluginRegistration; -import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; -import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration; -import org.onap.cps.ncmp.rest.model.RestInputCmHandle; - -@Mapper(componentModel = "spring", nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT, - nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) -public interface RestInputMapper { - - DmiPluginRegistration toDmiPluginRegistration(final RestDmiPluginRegistration restDmiPluginRegistration); - - @Mapping(source = "cmHandle", target = "cmHandleID") - @Mapping(source = "cmHandleProperties", target = "dmiProperties") - @Mapping(source = "publicCmHandleProperties", target = "publicProperties") - NcmpServiceCmHandle toNcmpServiceCmHandle(final RestInputCmHandle restInputCmHandle); - -} -- cgit 1.2.3-korg