diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2023-10-11 08:54:57 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2023-10-11 08:54:57 +0000 |
commit | 4bc19fe118ca7d81891c12d40719a569bc528a21 (patch) | |
tree | aafde6495f3e5a5f53ea07f92db6a31f13f2d4ad /cps-ncmp-service/src/main/java | |
parent | d27dc5428a8bb256b901736f483c795266a68528 (diff) | |
parent | 6c338a5655f569adff88d9317e7482f1482b455d (diff) |
Merge "Conflicting Error code"
Diffstat (limited to 'cps-ncmp-service/src/main/java')
8 files changed, 87 insertions, 95 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpEventResponseCode.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java index 3b11249838..b9c834c559 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpEventResponseCode.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NcmpResponseStatus.java @@ -23,7 +23,7 @@ package org.onap.cps.ncmp.api; import lombok.Getter; @Getter -public enum NcmpEventResponseCode { +public enum NcmpResponseStatus { SUCCESS("0", "Successfully applied changes"), SUCCESSFULLY_APPLIED_SUBSCRIPTION("1", "successfully applied subscription"), @@ -33,13 +33,16 @@ public enum NcmpEventResponseCode { UNABLE_TO_READ_RESOURCE_DATA("103", "dmi plugin service is not able to read resource data"), PARTIALLY_APPLIED_SUBSCRIPTION("104", "partially applied subscription"), SUBSCRIPTION_NOT_APPLICABLE("105", "subscription not applicable for all cm handles"), - SUBSCRIPTION_PENDING("106", "subscription pending for all cm handles"); + SUBSCRIPTION_PENDING("106", "subscription pending for all cm handles"), + UNKNOWN_ERROR("108", "Unknown error"), + CM_HANDLE_ALREADY_EXIST("109", "cm-handle already exists"), + CM_HANDLE_INVALID_ID("110", "cm-handle has an invalid character(s) in id"); - private final String statusCode; - private final String statusMessage; + private final String code; + private final String message; - NcmpEventResponseCode(final String statusCode, final String statusMessage) { - this.statusCode = statusCode; - this.statusMessage = statusMessage; + NcmpResponseStatus(final String code, final String message) { + this.code = code; + this.message = message; } } 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 f8adde85ff..d34e2a3141 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 @@ -24,6 +24,9 @@ package org.onap.cps.ncmp.api.impl; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID; import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME; import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters; @@ -61,7 +64,6 @@ import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; 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.DataOperationRequest; import org.onap.cps.ncmp.api.models.DmiPluginRegistration; import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse; @@ -356,13 +358,11 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } catch (final DataNodeNotFoundException dataNodeNotFoundException) { log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandleId, dataNodeNotFoundException.getMessage()); - return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, - RegistrationError.CM_HANDLE_DOES_NOT_EXIST); + return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND); } catch (final DataValidationException dataValidationException) { log.error("Unable to de-register cm-handle id: {}, caused by: {}", cmHandleId, dataValidationException.getMessage()); - return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, - RegistrationError.CM_HANDLE_INVALID_ID); + return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID); } catch (final Exception exception) { log.error("Unable to de-register cm-handle id : {} , caused by : {}", cmHandleId, exception.getMessage()); return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception); @@ -405,14 +405,14 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private List<CmHandleRegistrationResponse> registerNewCmHandles(final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle) { final List<String> cmHandleIds = cmHandleStatePerCmHandle.keySet().stream().map(YangModelCmHandle::getId) - .collect(Collectors.toList()); + .toList(); try { lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle); return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds); } catch (final AlreadyDefinedException alreadyDefinedException) { return CmHandleRegistrationResponse.createFailureResponses( alreadyDefinedException.getAlreadyDefinedObjectNames(), - RegistrationError.CM_HANDLE_ALREADY_EXIST); + CM_HANDLE_ALREADY_EXIST); } catch (final Exception exception) { return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception); } 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 2f61b228b3..401b190360 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 @@ -22,6 +22,8 @@ package org.onap.cps.ncmp.api.impl; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID; import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.DMI_PROPERTY; import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.PUBLIC_PROPERTY; @@ -38,7 +40,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; -import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.onap.cps.spi.exceptions.DataValidationException; @@ -75,13 +76,12 @@ public class NetworkCmProxyDataServicePropertyHandler { log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", cmHandleId, e.getMessage()); cmHandleRegistrationResponses.add(CmHandleRegistrationResponse - .createFailureResponse(cmHandleId, RegistrationError.CM_HANDLE_DOES_NOT_EXIST)); + .createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND)); } catch (final DataValidationException e) { log.error("Unable to update cm handle : {}, caused by : {}", cmHandleId, e.getMessage()); cmHandleRegistrationResponses.add( - CmHandleRegistrationResponse.createFailureResponse(cmHandleId, - RegistrationError.CM_HANDLE_INVALID_ID)); + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID)); } catch (final Exception exception) { log.error("Unable to update cmHandle : {} , caused by : {}", cmHandleId, exception.getMessage()); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpOutEventPublisher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpOutEventPublisher.java index 473538c93e..a0fd81c12a 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpOutEventPublisher.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpOutEventPublisher.java @@ -20,13 +20,20 @@ package org.onap.cps.ncmp.api.impl.events.cmsubscription; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.PARTIALLY_APPLIED_SUBSCRIPTION; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.SUBSCRIPTION_NOT_APPLICABLE; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.SUBSCRIPTION_PENDING; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.SUCCESSFULLY_APPLIED_SUBSCRIPTION; +import static org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus.ACCEPTED; +import static org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus.PENDING; +import static org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus.REJECTED; + import io.cloudevents.CloudEvent; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.onap.cps.ncmp.api.NcmpEventResponseCode; +import org.onap.cps.ncmp.api.NcmpResponseStatus; import org.onap.cps.ncmp.api.impl.events.EventsPublisher; import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence; import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus; @@ -100,48 +107,39 @@ public class CmSubscriptionNcmpOutEventPublisher { cmSubscriptionStatus.setStatus(SubscriptionStatus.fromString(status)); cmSubscriptionStatus.setDetails(details); return cmSubscriptionStatus; - }).collect(Collectors.toList()); + }).toList(); } - private NcmpEventResponseCode decideOnNcmpEventResponseCodeForSubscription( + private NcmpResponseStatus decideOnNcmpEventResponseCodeForSubscription( final Map<String, Map<String, String>> cmHandleIdToStatusAndDetailsAsMap) { - final boolean isAllTargetsPending = isAllTargetCmHandleStatusMatch(cmHandleIdToStatusAndDetailsAsMap, - SubscriptionStatus.PENDING); - - final boolean isAllTargetsRejected = isAllTargetCmHandleStatusMatch(cmHandleIdToStatusAndDetailsAsMap, - SubscriptionStatus.REJECTED); - - final boolean isAllTargetsAccepted = isAllTargetCmHandleStatusMatch(cmHandleIdToStatusAndDetailsAsMap, - SubscriptionStatus.ACCEPTED); - - if (isAllTargetsAccepted) { - return NcmpEventResponseCode.SUCCESSFULLY_APPLIED_SUBSCRIPTION; - } else if (isAllTargetsRejected) { - return NcmpEventResponseCode.SUBSCRIPTION_NOT_APPLICABLE; - } else if (isAllTargetsPending) { - return NcmpEventResponseCode.SUBSCRIPTION_PENDING; - } else { - return NcmpEventResponseCode.PARTIALLY_APPLIED_SUBSCRIPTION; + if (allTargetsHaveStatus(cmHandleIdToStatusAndDetailsAsMap, ACCEPTED)) { + return SUCCESSFULLY_APPLIED_SUBSCRIPTION; + } + if (allTargetsHaveStatus(cmHandleIdToStatusAndDetailsAsMap, REJECTED)) { + return SUBSCRIPTION_NOT_APPLICABLE; + } + if (allTargetsHaveStatus(cmHandleIdToStatusAndDetailsAsMap, PENDING)) { + return SUBSCRIPTION_PENDING; } + return PARTIALLY_APPLIED_SUBSCRIPTION; } - private boolean isAllTargetCmHandleStatusMatch( - final Map<String, Map<String, String>> cmHandleIdToStatusAndDetailsAsMap, - final SubscriptionStatus subscriptionStatus) { + private boolean allTargetsHaveStatus(final Map<String, Map<String, String>> cmHandleIdToStatusAndDetailsAsMap, + final SubscriptionStatus subscriptionStatus) { return cmHandleIdToStatusAndDetailsAsMap.values().stream() .allMatch(entryset -> entryset.containsValue(subscriptionStatus.toString())); } private CmSubscriptionNcmpOutEvent fromCmSubscriptionEvent( final CmSubscriptionEvent cmSubscriptionEvent, - final NcmpEventResponseCode ncmpEventResponseCode) { + final NcmpResponseStatus ncmpResponseStatus) { final CmSubscriptionNcmpOutEvent cmSubscriptionNcmpOutEvent = cmSubscriptionEventToCmSubscriptionNcmpOutEventMapper.toCmSubscriptionNcmpOutEvent( cmSubscriptionEvent); - cmSubscriptionNcmpOutEvent.getData().setStatusCode(Integer.parseInt(ncmpEventResponseCode.getStatusCode())); - cmSubscriptionNcmpOutEvent.getData().setStatusMessage(ncmpEventResponseCode.getStatusMessage()); + cmSubscriptionNcmpOutEvent.getData().setStatusCode(Integer.parseInt(ncmpResponseStatus.getCode())); + cmSubscriptionNcmpOutEvent.getData().setStatusMessage(ncmpResponseStatus.getMessage()); return cmSubscriptionNcmpOutEvent; } 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 8f76a45e0e..b8edeccf2e 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 @@ -21,6 +21,8 @@ package org.onap.cps.ncmp.api.impl.operations; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.DMI_SERVICE_NOT_RESPONDING; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNABLE_TO_READ_RESOURCE_DATA; import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING; import static org.onap.cps.ncmp.api.impl.operations.OperationType.READ; @@ -30,7 +32,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; -import org.onap.cps.ncmp.api.NcmpEventResponseCode; +import org.onap.cps.ncmp.api.NcmpResponseStatus; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration; import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException; @@ -230,9 +232,7 @@ public class DmiDataOperations extends DmiOperations { final Map<String, List<DmiDataOperation>> groupsOutPerDmiServiceName) { - groupsOutPerDmiServiceName.entrySet().forEach(groupsOutPerDmiServiceNameEntry -> { - final String dmiServiceName = groupsOutPerDmiServiceNameEntry.getKey(); - final List<DmiDataOperation> dmiDataOperationRequestBodies = groupsOutPerDmiServiceNameEntry.getValue(); + groupsOutPerDmiServiceName.forEach((dmiServiceName, dmiDataOperationRequestBodies) -> { final String dmiDataOperationResourceUrl = getDmiServiceDataOperationRequestUrl(dmiServiceName, topicParamInQuery, requestId); sendDataOperationRequestToDmiService(dmiDataOperationResourceUrl, dmiDataOperationRequestBodies); @@ -261,18 +261,18 @@ public class DmiDataOperations extends DmiOperations { final String topicName = dataOperationResourceUrlParameters.get("topic").get(0); final String requestId = dataOperationResourceUrlParameters.get("requestId").get(0); - final MultiValueMap<DmiDataOperation, Map<NcmpEventResponseCode, List<String>>> + final MultiValueMap<DmiDataOperation, Map<NcmpResponseStatus, List<String>>> cmHandleIdsPerResponseCodesPerOperation = new LinkedMultiValueMap<>(); dmiDataOperationRequestBodies.forEach(dmiDataOperationRequestBody -> { final List<String> cmHandleIds = dmiDataOperationRequestBody.getCmHandles().stream() - .map(CmHandle::getId).collect(Collectors.toList()); + .map(CmHandle::getId).toList(); if (throwable.getCause() instanceof HttpClientRequestException) { cmHandleIdsPerResponseCodesPerOperation.add(dmiDataOperationRequestBody, - Map.of(NcmpEventResponseCode.UNABLE_TO_READ_RESOURCE_DATA, cmHandleIds)); + Map.of(UNABLE_TO_READ_RESOURCE_DATA, cmHandleIds)); } else { cmHandleIdsPerResponseCodesPerOperation.add(dmiDataOperationRequestBody, - Map.of(NcmpEventResponseCode.DMI_SERVICE_NOT_RESPONDING, cmHandleIds)); + Map.of(DMI_SERVICE_NOT_RESPONDING, cmHandleIds)); } }); ResourceDataOperationRequestUtils.publishErrorMessageToClientTopic(topicName, requestId, diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/DataOperationEventCreator.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/DataOperationEventCreator.java index 65cda94787..61da706c59 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/DataOperationEventCreator.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/DataOperationEventCreator.java @@ -28,7 +28,7 @@ import java.util.Map; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.onap.cps.ncmp.api.NcmpEventResponseCode; +import org.onap.cps.ncmp.api.NcmpResponseStatus; import org.onap.cps.ncmp.api.impl.events.NcmpCloudEventBuilder; import org.onap.cps.ncmp.api.impl.operations.DmiDataOperation; import org.onap.cps.ncmp.events.async1_0_0.Data; @@ -51,7 +51,7 @@ public class DataOperationEventCreator { public static CloudEvent createDataOperationEvent(final String clientTopic, final String requestId, final MultiValueMap<DmiDataOperation, - Map<NcmpEventResponseCode, List<String>>> + Map<NcmpResponseStatus, List<String>>> cmHandleIdsPerResponseCodesPerOperation) { final DataOperationEvent dataOperationEvent = new DataOperationEvent(); final Data data = createPayloadFromDataOperationResponses(cmHandleIdsPerResponseCodesPerOperation); @@ -62,7 +62,7 @@ public class DataOperationEventCreator { } private static Data createPayloadFromDataOperationResponses(final MultiValueMap<DmiDataOperation, - Map<NcmpEventResponseCode, List<String>>> cmHandleIdsPerResponseCodesPerOperation) { + Map<NcmpResponseStatus, List<String>>> cmHandleIdsPerResponseCodesPerOperation) { final Data data = new Data(); final List<org.onap.cps.ncmp.events.async1_0_0.Response> responses = new ArrayList<>(); cmHandleIdsPerResponseCodesPerOperation.forEach((dmiDataOperation, cmHandleIdsPerResponseCodes) -> @@ -75,13 +75,13 @@ public class DataOperationEventCreator { private static List<Response> createResponseFromDataOperationResponses( final DmiDataOperation dmiDataOperation, - final Map<NcmpEventResponseCode, List<String>> cmHandleIdsPerResponseCodeEntries) { + final Map<NcmpResponseStatus, List<String>> cmHandleIdsPerResponseCodeEntries) { final List<org.onap.cps.ncmp.events.async1_0_0.Response> responses = new ArrayList<>(); cmHandleIdsPerResponseCodeEntries.forEach((ncmpEventResponseCode, cmHandleIds) -> { final Response response = new Response(); response.setOperationId(dmiDataOperation.getOperationId()); - response.setStatusCode(ncmpEventResponseCode.getStatusCode()); - response.setStatusMessage(ncmpEventResponseCode.getStatusMessage()); + response.setStatusCode(ncmpEventResponseCode.getCode()); + response.setStatusMessage(ncmpEventResponseCode.getMessage()); response.setIds(cmHandleIds); response.setResourceIdentifier(dmiDataOperation.getResourceIdentifier()); response.setOptions(dmiDataOperation.getOptions()); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/ResourceDataOperationRequestUtils.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/ResourceDataOperationRequestUtils.java index e95d4f4c78..e78f0901fe 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/ResourceDataOperationRequestUtils.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/ResourceDataOperationRequestUtils.java @@ -20,6 +20,9 @@ package org.onap.cps.ncmp.api.impl.utils.data.operation; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_READY; + import io.cloudevents.CloudEvent; import java.util.ArrayList; import java.util.Collection; @@ -32,7 +35,7 @@ import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.onap.cps.ncmp.api.NcmpEventResponseCode; +import org.onap.cps.ncmp.api.NcmpResponseStatus; import org.onap.cps.ncmp.api.impl.events.EventsPublisher; import org.onap.cps.ncmp.api.impl.inventory.CmHandleState; import org.onap.cps.ncmp.api.impl.operations.CmHandle; @@ -68,7 +71,7 @@ public class ResourceDataOperationRequestUtils { final Collection<YangModelCmHandle> yangModelCmHandles) { final Map<String, List<DmiDataOperation>> dmiDataOperationsOutPerDmiServiceName = new HashMap<>(); - final MultiValueMap<DmiDataOperation, Map<NcmpEventResponseCode, + final MultiValueMap<DmiDataOperation, Map<NcmpResponseStatus, List<String>>> cmHandleIdsPerResponseCodesPerOperation = new LinkedMultiValueMap<>(); final Set<String> nonReadyCmHandleIdsLookup = filterAndGetNonReadyCmHandleIds(yangModelCmHandles); @@ -102,10 +105,10 @@ public class ResourceDataOperationRequestUtils { } populateCmHandleIdsPerOperationIdPerResponseCode(cmHandleIdsPerResponseCodesPerOperation, DmiDataOperation.buildDmiDataOperationRequestBodyWithoutCmHandles(dataOperationDefinitionIn), - NcmpEventResponseCode.CM_HANDLES_NOT_FOUND, nonExistingCmHandleIds); + CM_HANDLES_NOT_FOUND, nonExistingCmHandleIds); populateCmHandleIdsPerOperationIdPerResponseCode(cmHandleIdsPerResponseCodesPerOperation, DmiDataOperation.buildDmiDataOperationRequestBodyWithoutCmHandles(dataOperationDefinitionIn), - NcmpEventResponseCode.CM_HANDLES_NOT_READY, nonReadyCmHandleIds); + CM_HANDLES_NOT_READY, nonReadyCmHandleIds); } if (!cmHandleIdsPerResponseCodesPerOperation.isEmpty()) { publishErrorMessageToClientTopic(topicParamInQuery, requestId, cmHandleIdsPerResponseCodesPerOperation); @@ -124,7 +127,7 @@ public class ResourceDataOperationRequestUtils { public static void publishErrorMessageToClientTopic(final String clientTopic, final String requestId, final MultiValueMap<DmiDataOperation, - Map<NcmpEventResponseCode, List<String>>> + Map<NcmpResponseStatus, List<String>>> cmHandleIdsPerResponseCodesPerOperation) { final CloudEvent dataOperationCloudEvent = DataOperationEventCreator.createDataOperationEvent(clientTopic, requestId, cmHandleIdsPerResponseCodesPerOperation); @@ -175,13 +178,13 @@ public class ResourceDataOperationRequestUtils { } private static void populateCmHandleIdsPerOperationIdPerResponseCode(final MultiValueMap<DmiDataOperation, - Map<NcmpEventResponseCode, List<String>>> cmHandleIdsPerResponseCodesPerOperation, + Map<NcmpResponseStatus, List<String>>> cmHandleIdsPerResponseCodesPerOperation, final DmiDataOperation dmiDataOperation, - final NcmpEventResponseCode - ncmpEventResponseCode, + final NcmpResponseStatus + ncmpResponseStatus, final List<String> cmHandleIds) { if (!cmHandleIds.isEmpty()) { - cmHandleIdsPerResponseCodesPerOperation.add(dmiDataOperation, Map.of(ncmpEventResponseCode, cmHandleIds)); + cmHandleIdsPerResponseCodesPerOperation.add(dmiDataOperation, Map.of(ncmpResponseStatus, cmHandleIds)); } } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java index d5b27b61f6..5bab51bc27 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleRegistrationResponse.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada - * Modifications Copyright (C) 2022 Nordix Foundation + * Modifications 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. @@ -21,16 +21,17 @@ package org.onap.cps.ncmp.api.models; +import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR; + import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import lombok.Builder; import lombok.Data; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.NcmpResponseStatus; @Data @Builder @@ -39,7 +40,7 @@ public class CmHandleRegistrationResponse { private final String cmHandle; private final Status status; - private RegistrationError registrationError; + private NcmpResponseStatus ncmpResponseStatus; private String errorText; private static final Pattern cmHandleIdInXpathPattern = Pattern.compile("\\[@id='(.*?)']"); @@ -56,7 +57,7 @@ public class CmHandleRegistrationResponse { return CmHandleRegistrationResponse.builder() .cmHandle(cmHandleId) .status(Status.FAILURE) - .registrationError(RegistrationError.UNKNOWN_ERROR) + .ncmpResponseStatus(UNKNOWN_ERROR) .errorText(exception.getMessage()).build(); } @@ -64,15 +65,15 @@ public class CmHandleRegistrationResponse { * Creates a failure response based on registration error. * * @param cmHandleId cmHandleId - * @param registrationError registrationError + * @param ncmpResponseStatus registration error code and status * @return CmHandleRegistrationResponse */ public static CmHandleRegistrationResponse createFailureResponse(final String cmHandleId, - final RegistrationError registrationError) { + final NcmpResponseStatus ncmpResponseStatus) { return CmHandleRegistrationResponse.builder().cmHandle(cmHandleId) .status(Status.FAILURE) - .registrationError(registrationError) - .errorText(registrationError.errorText) + .ncmpResponseStatus(ncmpResponseStatus) + .errorText(ncmpResponseStatus.getMessage()) .build(); } @@ -80,17 +81,17 @@ public class CmHandleRegistrationResponse { * Creates a failure response based on registration error. * * @param failedXpaths list of failed Xpaths - * @param registrationError enum describing the type of registration error + * @param ncmpResponseStatus enum describing the type of registration error * @return CmHandleRegistrationResponse */ public static List<CmHandleRegistrationResponse> createFailureResponses(final Collection<String> failedXpaths, - final RegistrationError registrationError) { + final NcmpResponseStatus ncmpResponseStatus) { final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses = new ArrayList<>(failedXpaths.size()); for (final String xpath : failedXpaths) { final Matcher matcher = cmHandleIdInXpathPattern.matcher(xpath); if (matcher.find()) { cmHandleRegistrationResponses.add( - CmHandleRegistrationResponse.createFailureResponse(matcher.group(1), registrationError)); + CmHandleRegistrationResponse.createFailureResponse(matcher.group(1), ncmpResponseStatus)); } else { log.warn("Unexpected xpath {}", xpath); } @@ -109,7 +110,7 @@ public class CmHandleRegistrationResponse { final Exception exception) { return cmHandleIds.stream() .map(cmHandleId -> CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception)) - .collect(Collectors.toList()); + .toList(); } public static CmHandleRegistrationResponse createSuccessResponse(final String cmHandle) { @@ -118,23 +119,10 @@ public class CmHandleRegistrationResponse { } public static List<CmHandleRegistrationResponse> createSuccessResponses(final List<String> cmHandleIds) { - return cmHandleIds.stream().map(CmHandleRegistrationResponse::createSuccessResponse) - .collect(Collectors.toList()); + return cmHandleIds.stream().map(CmHandleRegistrationResponse::createSuccessResponse).toList(); } public enum Status { SUCCESS, FAILURE; } - - @RequiredArgsConstructor - public enum RegistrationError { - UNKNOWN_ERROR("00", "Unknown error"), - CM_HANDLE_ALREADY_EXIST("01", "cm-handle already exists"), - CM_HANDLE_DOES_NOT_EXIST("02", "cm-handle does not exist"), - CM_HANDLE_INVALID_ID("03", "cm-handle has an invalid character(s) in id"); - - public final String errorCode; - public final String errorText; - - } } |