From d5b8ee8070ced23a44315bcf0cb73298f4eb08a8 Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Thu, 27 Jun 2024 09:06:31 +0100 Subject: Simplify package structure cps-ncmp-rest Issue-ID: CPS-2294 Change-Id: Idc3605c1b877be13a8d344875612da6bef791fc7 Signed-off-by: ToineSiebelink --- .../ncmp/rest/controller/NcmpRestInputMapper.java | 74 ------------ .../rest/controller/NetworkCmProxyController.java | 5 +- .../NetworkCmProxyInventoryController.java | 1 + .../NetworkCmProxyRestExceptionHandler.java | 131 ++++++++++++++++++++ .../NetworkCmProxyRestExceptionHandler.java | 133 --------------------- .../cps/ncmp/rest/mapper/CmHandleStateMapper.java | 89 -------------- .../rest/mapper/DataOperationRequestMapper.java | 41 ------- .../cps/ncmp/rest/util/CmHandleStateMapper.java | 89 ++++++++++++++ .../ncmp/rest/util/DataOperationRequestMapper.java | 41 +++++++ .../cps/ncmp/rest/util/NcmpRestInputMapper.java | 74 ++++++++++++ 10 files changed, 339 insertions(+), 339 deletions(-) delete mode 100644 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java create mode 100644 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandler.java delete mode 100755 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java delete mode 100644 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java delete mode 100644 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/DataOperationRequestMapper.java create mode 100644 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/CmHandleStateMapper.java create mode 100644 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DataOperationRequestMapper.java create mode 100644 cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/NcmpRestInputMapper.java (limited to 'cps-ncmp-rest/src/main/java') 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 deleted file mode 100644 index 7f46c92ec7..0000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 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.InheritConfiguration; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.NullValueCheckStrategy; -import org.mapstruct.NullValuePropertyMappingStrategy; -import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters; -import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration; -import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; -import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; -import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration; -import org.onap.cps.ncmp.rest.model.RestInputCmHandle; -import org.onap.cps.ncmp.rest.model.RestModuleDefinition; -import org.onap.cps.ncmp.rest.model.RestModuleReference; -import org.onap.cps.spi.model.ModuleDefinition; -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) - @Mapping(source = "upgradedCmHandles", target = "upgradedCmHandles", - 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") - @Mapping(source = "trustLevel", target = "registrationTrustLevel") - NcmpServiceCmHandle toNcmpServiceCmHandle(final RestInputCmHandle restInputCmHandle); - - RestModuleReference toRestModuleReference( - final ModuleReference moduleReference); - - @InheritConfiguration(name = "toRestModuleReference") - RestModuleDefinition toRestModuleDefinition( - final ModuleDefinition moduleDefinition); - - @Mapping(source = "cmHandleQueryParameters", target = "cmHandleQueryParameters", - nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, - nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) - CmHandleQueryServiceParameters toCmHandleQueryServiceParameters( - final CmHandleQueryParameters cmHandleQueryParameters); -} 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 11252b7504..f09b9c67de 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 @@ -46,8 +46,6 @@ import org.onap.cps.ncmp.api.inventory.models.CompositeState; import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; import org.onap.cps.ncmp.api.models.CmResourceAddress; import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi; -import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper; -import org.onap.cps.ncmp.rest.mapper.DataOperationRequestMapper; import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties; import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; import org.onap.cps.ncmp.rest.model.DataOperationRequest; @@ -56,7 +54,10 @@ import org.onap.cps.ncmp.rest.model.RestModuleReference; import org.onap.cps.ncmp.rest.model.RestOutputCmHandle; import org.onap.cps.ncmp.rest.model.RestOutputCmHandleCompositeState; import org.onap.cps.ncmp.rest.model.RestOutputCmHandlePublicProperties; +import org.onap.cps.ncmp.rest.util.CmHandleStateMapper; +import org.onap.cps.ncmp.rest.util.DataOperationRequestMapper; import org.onap.cps.ncmp.rest.util.DeprecationHelper; +import org.onap.cps.ncmp.rest.util.NcmpRestInputMapper; import org.onap.cps.spi.model.DataNode; import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.utils.JsonObjectMapper; 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 113ee02aa1..8aa86ade36 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,6 +37,7 @@ import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; import org.onap.cps.ncmp.rest.model.CmHandlerRegistrationErrorResponse; import org.onap.cps.ncmp.rest.model.DmiPluginRegistrationErrorResponse; import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration; +import org.onap.cps.ncmp.rest.util.NcmpRestInputMapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandler.java new file mode 100644 index 0000000000..6d51f3c7f5 --- /dev/null +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyRestExceptionHandler.java @@ -0,0 +1,131 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2021-2024 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 lombok.AccessLevel; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException; +import org.onap.cps.ncmp.api.impl.exception.DmiRequestException; +import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException; +import org.onap.cps.ncmp.api.impl.exception.InvalidDmiResourceUrlException; +import org.onap.cps.ncmp.api.impl.exception.NcmpException; +import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException; +import org.onap.cps.ncmp.exceptions.InvalidTopicException; +import org.onap.cps.ncmp.exceptions.OperationNotSupportedException; +import org.onap.cps.ncmp.exceptions.PayloadTooLargeException; +import org.onap.cps.ncmp.rest.model.DmiErrorMessage; +import org.onap.cps.ncmp.rest.model.DmiErrorMessageDmiResponse; +import org.onap.cps.ncmp.rest.model.ErrorMessage; +import org.onap.cps.spi.exceptions.AlreadyDefinedException; +import org.onap.cps.spi.exceptions.CpsException; +import org.onap.cps.spi.exceptions.DataNodeNotFoundException; +import org.onap.cps.spi.exceptions.DataValidationException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +/** + * Exception handler with error message return. + */ +@Slf4j +@RestControllerAdvice(assignableTypes = {NetworkCmProxyController.class, NetworkCmProxyInventoryController.class}) +@NoArgsConstructor(access = AccessLevel.PACKAGE) +public class NetworkCmProxyRestExceptionHandler { + + private static final String CHECK_LOGS_FOR_DETAILS = "Check logs for details."; + + /** + * Default exception handler. + * + * @param exception the exception to handle + * @return response with response code 500. + */ + @ExceptionHandler + public static ResponseEntity handleInternalServerErrorExceptions(final Exception exception) { + return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception); + } + + @ExceptionHandler({CpsException.class, ServerNcmpException.class}) + public static ResponseEntity handleAnyOtherCpsExceptions(final Exception exception) { + return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception); + } + + @ExceptionHandler({DmiClientRequestException.class}) + public static ResponseEntity handleClientRequestExceptions( + final DmiClientRequestException dmiClientRequestException) { + return wrapDmiErrorResponse(dmiClientRequestException); + } + + @ExceptionHandler({DmiRequestException.class, DataValidationException.class, OperationNotSupportedException.class, + HttpMessageNotReadableException.class, InvalidTopicException.class, InvalidDatastoreException.class, + InvalidDmiResourceUrlException.class}) + public static ResponseEntity handleDmiRequestExceptions(final Exception exception) { + return buildErrorResponse(HttpStatus.BAD_REQUEST, exception); + } + + @ExceptionHandler({AlreadyDefinedException.class}) + public static ResponseEntity handleAlreadyDefinedExceptions(final Exception exception) { + return buildErrorResponse(HttpStatus.CONFLICT, exception); + } + + @ExceptionHandler({DataNodeNotFoundException.class}) + public static ResponseEntity handleNotFoundExceptions(final Exception exception) { + return buildErrorResponse(HttpStatus.NOT_FOUND, exception); + } + + @ExceptionHandler({PayloadTooLargeException.class}) + public static ResponseEntity handlePayloadTooLargeExceptions(final Exception exception) { + return buildErrorResponse(HttpStatus.PAYLOAD_TOO_LARGE, exception); + } + + private static ResponseEntity buildErrorResponse(final HttpStatus status, final Exception exception) { + if (exception.getCause() != null || !(exception instanceof CpsException)) { + log.error("Exception occurred", exception); + } + final var errorMessage = new ErrorMessage(); + errorMessage.setStatus(status.toString()); + errorMessage.setMessage(exception.getMessage()); + if (exception instanceof CpsException) { + errorMessage.setDetails(((CpsException) exception).getDetails()); + } else if (exception instanceof NcmpException) { + errorMessage.setDetails(((NcmpException) exception).getDetails()); + } else { + errorMessage.setDetails(CHECK_LOGS_FOR_DETAILS); + } + errorMessage.setDetails( + exception instanceof CpsException ? ((CpsException) exception).getDetails() : CHECK_LOGS_FOR_DETAILS); + return new ResponseEntity<>(errorMessage, status); + } + + private static ResponseEntity wrapDmiErrorResponse(final DmiClientRequestException + dmiClientRequestException) { + final var dmiErrorMessage = new DmiErrorMessage(); + final var dmiErrorResponse = new DmiErrorMessageDmiResponse(); + dmiErrorResponse.setHttpCode(dmiClientRequestException.getHttpStatusCode()); + dmiErrorResponse.setBody(dmiClientRequestException.getResponseBodyAsString()); + dmiErrorMessage.setMessage(dmiClientRequestException.getMessage()); + dmiErrorMessage.setDmiResponse(dmiErrorResponse); + return new ResponseEntity<>(dmiErrorMessage, HttpStatus.BAD_GATEWAY); + } +} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java deleted file mode 100755 index ba39178c7b..0000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Pantheon.tech - * Modifications Copyright (C) 2021-2024 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.exceptions; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.onap.cps.ncmp.api.impl.exception.DmiClientRequestException; -import org.onap.cps.ncmp.api.impl.exception.DmiRequestException; -import org.onap.cps.ncmp.api.impl.exception.InvalidDatastoreException; -import org.onap.cps.ncmp.api.impl.exception.InvalidDmiResourceUrlException; -import org.onap.cps.ncmp.api.impl.exception.NcmpException; -import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException; -import org.onap.cps.ncmp.exceptions.InvalidTopicException; -import org.onap.cps.ncmp.exceptions.OperationNotSupportedException; -import org.onap.cps.ncmp.exceptions.PayloadTooLargeException; -import org.onap.cps.ncmp.rest.controller.NetworkCmProxyController; -import org.onap.cps.ncmp.rest.controller.NetworkCmProxyInventoryController; -import org.onap.cps.ncmp.rest.model.DmiErrorMessage; -import org.onap.cps.ncmp.rest.model.DmiErrorMessageDmiResponse; -import org.onap.cps.ncmp.rest.model.ErrorMessage; -import org.onap.cps.spi.exceptions.AlreadyDefinedException; -import org.onap.cps.spi.exceptions.CpsException; -import org.onap.cps.spi.exceptions.DataNodeNotFoundException; -import org.onap.cps.spi.exceptions.DataValidationException; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; - -/** - * Exception handler with error message return. - */ -@Slf4j -@RestControllerAdvice(assignableTypes = {NetworkCmProxyController.class, NetworkCmProxyInventoryController.class}) -@NoArgsConstructor(access = AccessLevel.PACKAGE) -public class NetworkCmProxyRestExceptionHandler { - - private static final String CHECK_LOGS_FOR_DETAILS = "Check logs for details."; - - /** - * Default exception handler. - * - * @param exception the exception to handle - * @return response with response code 500. - */ - @ExceptionHandler - public static ResponseEntity handleInternalServerErrorExceptions(final Exception exception) { - return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception); - } - - @ExceptionHandler({CpsException.class, ServerNcmpException.class}) - public static ResponseEntity handleAnyOtherCpsExceptions(final Exception exception) { - return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception); - } - - @ExceptionHandler({DmiClientRequestException.class}) - public static ResponseEntity handleClientRequestExceptions( - final DmiClientRequestException dmiClientRequestException) { - return wrapDmiErrorResponse(dmiClientRequestException); - } - - @ExceptionHandler({DmiRequestException.class, DataValidationException.class, OperationNotSupportedException.class, - HttpMessageNotReadableException.class, InvalidTopicException.class, InvalidDatastoreException.class, - InvalidDmiResourceUrlException.class}) - public static ResponseEntity handleDmiRequestExceptions(final Exception exception) { - return buildErrorResponse(HttpStatus.BAD_REQUEST, exception); - } - - @ExceptionHandler({AlreadyDefinedException.class}) - public static ResponseEntity handleAlreadyDefinedExceptions(final Exception exception) { - return buildErrorResponse(HttpStatus.CONFLICT, exception); - } - - @ExceptionHandler({DataNodeNotFoundException.class}) - public static ResponseEntity handleNotFoundExceptions(final Exception exception) { - return buildErrorResponse(HttpStatus.NOT_FOUND, exception); - } - - @ExceptionHandler({PayloadTooLargeException.class}) - public static ResponseEntity handlePayloadTooLargeExceptions(final Exception exception) { - return buildErrorResponse(HttpStatus.PAYLOAD_TOO_LARGE, exception); - } - - private static ResponseEntity buildErrorResponse(final HttpStatus status, final Exception exception) { - if (exception.getCause() != null || !(exception instanceof CpsException)) { - log.error("Exception occurred", exception); - } - final var errorMessage = new ErrorMessage(); - errorMessage.setStatus(status.toString()); - errorMessage.setMessage(exception.getMessage()); - if (exception instanceof CpsException) { - errorMessage.setDetails(((CpsException) exception).getDetails()); - } else if (exception instanceof NcmpException) { - errorMessage.setDetails(((NcmpException) exception).getDetails()); - } else { - errorMessage.setDetails(CHECK_LOGS_FOR_DETAILS); - } - errorMessage.setDetails( - exception instanceof CpsException ? ((CpsException) exception).getDetails() : CHECK_LOGS_FOR_DETAILS); - return new ResponseEntity<>(errorMessage, status); - } - - private static ResponseEntity wrapDmiErrorResponse(final DmiClientRequestException - dmiClientRequestException) { - final var dmiErrorMessage = new DmiErrorMessage(); - final var dmiErrorResponse = new DmiErrorMessageDmiResponse(); - dmiErrorResponse.setHttpCode(dmiClientRequestException.getHttpStatusCode()); - dmiErrorResponse.setBody(dmiClientRequestException.getResponseBodyAsString()); - dmiErrorMessage.setMessage(dmiClientRequestException.getMessage()); - dmiErrorMessage.setDmiResponse(dmiErrorResponse); - return new ResponseEntity<>(dmiErrorMessage, HttpStatus.BAD_GATEWAY); - } -} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java deleted file mode 100644 index 3f44ee8528..0000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/CmHandleStateMapper.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 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.mapper; - -import static org.onap.cps.ncmp.impl.inventory.models.LockReasonCategory.LOCKED_MISBEHAVING; - -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Named; -import org.mapstruct.NullValueCheckStrategy; -import org.mapstruct.NullValuePropertyMappingStrategy; -import org.onap.cps.ncmp.api.inventory.models.CompositeState; -import org.onap.cps.ncmp.rest.model.CmHandleCompositeState; -import org.onap.cps.ncmp.rest.model.DataStores; -import org.onap.cps.ncmp.rest.model.LockReason; -import org.onap.cps.ncmp.rest.model.SyncState; - -@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, - nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) -public interface CmHandleStateMapper { - - @Mapping(target = "dataSyncState", source = "dataStores", qualifiedByName = "dataStoreToDataSyncState") - @Mapping(target = "lockReason", source = "lockReason", qualifiedByName = "toExternalLockReason") - CmHandleCompositeState toCmHandleCompositeStateExternalLockReason(CompositeState compositeState); - - /** - * Convert from CompositeState datastore to RestOutput Datastores. - * - * @param compositeStateDataStore Composite State data stores - * @return DataStores - */ - @Named("dataStoreToDataSyncState") - static DataStores toDataStores(CompositeState.DataStores compositeStateDataStore) { - - if (compositeStateDataStore == null) { - return null; - } - - final DataStores dataStores = new DataStores(); - - if (compositeStateDataStore.getOperationalDataStore() != null) { - final SyncState operationalSyncState = new SyncState(); - operationalSyncState.setSyncState(compositeStateDataStore.getOperationalDataStore() - .getDataStoreSyncState().name()); - operationalSyncState.setLastSyncTime(compositeStateDataStore.getOperationalDataStore().getLastSyncTime()); - dataStores.setOperational(operationalSyncState); - } - - return dataStores; - } - - /** - * Convert Internal Lock Reason to External Lock Reason. - * - * @param internalLockReason Internal Lock Reason - * - * @return externalLockReason - */ - @Named("toExternalLockReason") - static LockReason toExternalLockReason(CompositeState.LockReason internalLockReason) { - final LockReason externalLockReason = new LockReason(); - if (internalLockReason.getLockReasonCategory() == null) { - externalLockReason.setReason(LOCKED_MISBEHAVING.name()); - } else { - externalLockReason.setReason(internalLockReason.getLockReasonCategory().name()); - } - externalLockReason.setDetails(internalLockReason.getDetails()); - return externalLockReason; - } - -} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/DataOperationRequestMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/DataOperationRequestMapper.java deleted file mode 100644 index 51ee8ca174..0000000000 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/mapper/DataOperationRequestMapper.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2023 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.mapper; - -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.NullValueCheckStrategy; -import org.mapstruct.NullValuePropertyMappingStrategy; -import org.onap.cps.ncmp.api.models.DataOperationDefinition; -import org.onap.cps.ncmp.api.models.DataOperationRequest; - -@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, - nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) -public interface DataOperationRequestMapper { - - @Mapping(source = "operations", target = "dataOperationDefinitions") - DataOperationRequest toDataOperationRequest( - org.onap.cps.ncmp.rest.model.DataOperationRequest dataOperationRequest); - - @Mapping(source = "targetIds", target = "cmHandleIds") - DataOperationDefinition toDataOperationDefinition( - org.onap.cps.ncmp.rest.model.DataOperationDefinition dataOperationDefinition); -} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/CmHandleStateMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/CmHandleStateMapper.java new file mode 100644 index 0000000000..4abcb72308 --- /dev/null +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/CmHandleStateMapper.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022-2023 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.util; + +import static org.onap.cps.ncmp.impl.inventory.models.LockReasonCategory.LOCKED_MISBEHAVING; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.onap.cps.ncmp.api.inventory.models.CompositeState; +import org.onap.cps.ncmp.rest.model.CmHandleCompositeState; +import org.onap.cps.ncmp.rest.model.DataStores; +import org.onap.cps.ncmp.rest.model.LockReason; +import org.onap.cps.ncmp.rest.model.SyncState; + +@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) +public interface CmHandleStateMapper { + + @Mapping(target = "dataSyncState", source = "dataStores", qualifiedByName = "dataStoreToDataSyncState") + @Mapping(target = "lockReason", source = "lockReason", qualifiedByName = "toExternalLockReason") + CmHandleCompositeState toCmHandleCompositeStateExternalLockReason(CompositeState compositeState); + + /** + * Convert from CompositeState datastore to RestOutput Datastores. + * + * @param compositeStateDataStore Composite State data stores + * @return DataStores + */ + @Named("dataStoreToDataSyncState") + static DataStores toDataStores(CompositeState.DataStores compositeStateDataStore) { + + if (compositeStateDataStore == null) { + return null; + } + + final DataStores dataStores = new DataStores(); + + if (compositeStateDataStore.getOperationalDataStore() != null) { + final SyncState operationalSyncState = new SyncState(); + operationalSyncState.setSyncState(compositeStateDataStore.getOperationalDataStore() + .getDataStoreSyncState().name()); + operationalSyncState.setLastSyncTime(compositeStateDataStore.getOperationalDataStore().getLastSyncTime()); + dataStores.setOperational(operationalSyncState); + } + + return dataStores; + } + + /** + * Convert Internal Lock Reason to External Lock Reason. + * + * @param internalLockReason Internal Lock Reason + * + * @return externalLockReason + */ + @Named("toExternalLockReason") + static LockReason toExternalLockReason(CompositeState.LockReason internalLockReason) { + final LockReason externalLockReason = new LockReason(); + if (internalLockReason.getLockReasonCategory() == null) { + externalLockReason.setReason(LOCKED_MISBEHAVING.name()); + } else { + externalLockReason.setReason(internalLockReason.getLockReasonCategory().name()); + } + externalLockReason.setDetails(internalLockReason.getDetails()); + return externalLockReason; + } + +} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DataOperationRequestMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DataOperationRequestMapper.java new file mode 100644 index 0000000000..b84660a095 --- /dev/null +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/DataOperationRequestMapper.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.util; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.onap.cps.ncmp.api.models.DataOperationDefinition; +import org.onap.cps.ncmp.api.models.DataOperationRequest; + +@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) +public interface DataOperationRequestMapper { + + @Mapping(source = "operations", target = "dataOperationDefinitions") + DataOperationRequest toDataOperationRequest( + org.onap.cps.ncmp.rest.model.DataOperationRequest dataOperationRequest); + + @Mapping(source = "targetIds", target = "cmHandleIds") + DataOperationDefinition toDataOperationDefinition( + org.onap.cps.ncmp.rest.model.DataOperationDefinition dataOperationDefinition); +} diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/NcmpRestInputMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/NcmpRestInputMapper.java new file mode 100644 index 0000000000..b9a814dce4 --- /dev/null +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/NcmpRestInputMapper.java @@ -0,0 +1,74 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022-2023 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.util; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.onap.cps.ncmp.api.inventory.models.CmHandleQueryServiceParameters; +import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration; +import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; +import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; +import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration; +import org.onap.cps.ncmp.rest.model.RestInputCmHandle; +import org.onap.cps.ncmp.rest.model.RestModuleDefinition; +import org.onap.cps.ncmp.rest.model.RestModuleReference; +import org.onap.cps.spi.model.ModuleDefinition; +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) + @Mapping(source = "upgradedCmHandles", target = "upgradedCmHandles", + 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") + @Mapping(source = "trustLevel", target = "registrationTrustLevel") + NcmpServiceCmHandle toNcmpServiceCmHandle(final RestInputCmHandle restInputCmHandle); + + RestModuleReference toRestModuleReference( + final ModuleReference moduleReference); + + @InheritConfiguration(name = "toRestModuleReference") + RestModuleDefinition toRestModuleDefinition( + final ModuleDefinition moduleDefinition); + + @Mapping(source = "cmHandleQueryParameters", target = "cmHandleQueryParameters", + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) + CmHandleQueryServiceParameters toCmHandleQueryServiceParameters( + final CmHandleQueryParameters cmHandleQueryParameters); +} -- cgit 1.2.3-korg