From 9373e4f17236dc7496cd7dcfbbd159675e839e55 Mon Sep 17 00:00:00 2001 From: Francis Toth Date: Fri, 8 May 2020 18:45:14 -0400 Subject: Add ArtifactsBusinessLogic::fetchLatestComponentMetadata Signed-off-by: Francis Toth Change-Id: Ibb8621a91551a2e4ffcac1145f85ed7983063d02 Issue-ID: SDC-2812 --- .../be/components/impl/ArtifactsBusinessLogic.java | 90 +++++++++++----------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index c56517c0af..17f8bdef48 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -3958,13 +3958,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { String origMd5 = request.getHeader(Constants.MD5_HEADER); String userId = request.getHeader(Constants.USER_ID_HEADER); - Either getComponentRes = - toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true); - if (getComponentRes.isRight()) { - StorageOperationStatus status = getComponentRes.right().value(); - log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status); - throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status, componentType), componentUuid); - } + Either getComponentRes = + fetchLatestComponentMetadataOrThrow(componentType, componentUuid); ComponentMetadataDataDefinition componentMetadataDataDefinition = getComponentRes.left().value().getMetadataDataDefinition(); componentId = componentMetadataDataDefinition.getUniqueId(); @@ -4007,12 +4002,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { String userId = request.getHeader(Constants.USER_ID_HEADER); ImmutablePair componentRiPair = null; - Either getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true); - if (getComponentRes.isRight()) { - StorageOperationStatus status = getComponentRes.right().value(); - log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status); - throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status, componentType), resourceInstanceName); - } + + Either getComponentRes = + fetchLatestComponentMetadataOrThrow(componentType, componentUuid, resourceInstanceName); if (!getComponentRes.left() .value() .getMetadataDataDefinition() @@ -4062,12 +4054,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { String origMd5 = request.getHeader(Constants.MD5_HEADER); String userId = request.getHeader(Constants.USER_ID_HEADER); - Either getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true); - if (getComponentRes.isRight()) { - StorageOperationStatus status = getComponentRes.right().value(); - log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status); - throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status)); - } + Either getComponentRes = + fetchLatestComponentMetadataOrThrow(componentType, componentUuid); componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(); String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName(); @@ -4119,12 +4107,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { String userId = request.getHeader(Constants.USER_ID_HEADER); ImmutablePair componentRiPair = null; - Either getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true); - if (getComponentRes.isRight()) { - StorageOperationStatus status = getComponentRes.right().value(); - log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status); - throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status)); - } + Either getComponentRes = + fetchLatestComponentMetadataOrThrow(componentType, componentUuid); if (!getComponentRes.left() .value() .getMetadataDataDefinition() @@ -4229,11 +4213,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { ArtifactDefinition existingArtifactInfo = null; String interfaceName = null; - Either getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true); - if (getComponentRes.isRight()) { - StorageOperationStatus status = getComponentRes.right().value(); - log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status); - errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status))); + Either getComponentRes = + fetchLatestComponentMetadata(componentType, componentUuid).right().map(as -> { + errorWrapper.setInnerElement(componentsUtils.getResponseFormat(as)); + return as; + }); + + if(getComponentRes.isRight()) { + errorWrapper.setInnerElement(componentsUtils.getResponseFormat(getComponentRes.right().value())); } if (errorWrapper.isEmpty()) { @@ -4309,6 +4296,32 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { return updateArtifactResult; } + + private Either fetchLatestComponentMetadataOrThrow( + ComponentTypeEnum componentType, String componentUuid + ) { + return fetchLatestComponentMetadataOrThrow(componentType, componentUuid, componentUuid); + } + + private Either fetchLatestComponentMetadataOrThrow( + ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName + ) { + return fetchLatestComponentMetadata(componentType, componentUuid).right().map(as -> { + throw new ByActionStatusComponentException(as, resourceInstanceName); + }); + } + + private Either fetchLatestComponentMetadata( + ComponentTypeEnum componentType, String componentUuid + ) { + return toscaOperationFacade + .getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true) + .right().map(sos -> { + log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, sos); + return componentsUtils.convertFromStorageResponse(sos, componentType); + }); + } + private Either fetchInterfaceName(String componentId, String interfaceUUID) { Either componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId); if (componentStorageOperationStatusEither.isRight()) { @@ -4347,12 +4360,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { String origMd5 = request.getHeader(Constants.MD5_HEADER); String userId = request.getHeader(Constants.USER_ID_HEADER); - Either getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true); - if (getComponentRes.isRight()) { - StorageOperationStatus status = getComponentRes.right().value(); - log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status); - throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status, componentType), componentUuid); - } + Either getComponentRes = + fetchLatestComponentMetadataOrThrow(componentType, componentUuid); componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(); String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName(); if (!getComponentRes.left() @@ -4395,13 +4404,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { String origMd5 = request.getHeader(Constants.MD5_HEADER); String userId = request.getHeader(Constants.USER_ID_HEADER); ImmutablePair componentRiPair = null; - Either getComponentRes = - toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true); - if (getComponentRes.isRight()) { - StorageOperationStatus status = getComponentRes.right().value(); - log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status); - throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status)); - } + Either getComponentRes = + fetchLatestComponentMetadataOrThrow(componentType, componentUuid); if (!getComponentRes.left() .value() .getMetadataDataDefinition() -- cgit 1.2.3-korg