From 8d72481341ac6be40c380352a2a7ef5cc536692d Mon Sep 17 00:00:00 2001 From: Chris André Date: Wed, 3 Jun 2020 13:23:40 -0400 Subject: Rewrite of `updateArtifactOnInterfaceOperationByResourceUUID` to remove NPE Issue-ID: SDC-2978 Signed-off-by: Chris Andre Change-Id: I60942ab1767bf65c806ce796ca62365396b20d93 --- .../be/components/impl/ArtifactsBusinessLogic.java | 49 +++++++++++----------- 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'catalog-be/src/main/java/org') 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 eba749fcba..60b88cf5cb 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 @@ -4115,25 +4115,21 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { ResourceCommonInfo resourceCommonInfo,ArtifactOperationInfo operation) { Wrapper errorWrapper = new Wrapper<>(); Either updateArtifactResult; - Either, ResponseFormat> actionResult = null; - ArtifactDefinition updateArtifact = null; String componentId = null; + ArtifactDefinition existingArtifactInfo = null; + String interfaceName = null; + ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinitionForUpdate(data, ArtifactDefinition.class); String origMd5 = request.getHeader(Constants.MD5_HEADER); String userId = request.getHeader(Constants.USER_ID_HEADER); - ArtifactDefinition existingArtifactInfo = null; - String interfaceName = null; Either getComponentRes = - fetchLatestComponentMetadata(componentType, componentUuid).right().map(as -> { + 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()) { componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId(); String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName(); @@ -4187,26 +4183,31 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } if (errorWrapper.isEmpty()) { - try { - actionResult = Either.left(handleArtifactRequest(componentId, userId, componentType, operation, - artifactUUID, artifactInfo, origMd5, data, interfaceName, - operationUUID, null, null)); - }catch (ComponentException e){ - errorWrapper.setInnerElement(e.getResponseFormat()); - } - } - - if (errorWrapper.isEmpty()) { - updateArtifact = actionResult.left().value().left().value(); - updateArtifactResult = Either.left(updateArtifact); - - } - else { + updateArtifactResult = handleArtifactRequestAndFlatten(componentId, userId, componentType, operation, + artifactUUID, artifactInfo, origMd5, data, interfaceName, operationUUID); + } else { updateArtifactResult = Either.right(errorWrapper.getInnerElement()); } + return updateArtifactResult; } + private Either handleArtifactRequestAndFlatten( + String componentId, String userId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, + String artifactId, ArtifactDefinition artifactInfo, String origMd5, String originData, String interfaceName, + String operationName) { + try { + return handleArtifactRequest(componentId, userId, componentType, operation, + artifactId, artifactInfo, origMd5, originData, interfaceName, + operationName, null, null) + .right().map(op -> { + log.debug("Unexpected value returned while calling handleArtifactRequest: {}", op); + return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR); + }); + } catch (ComponentException e) { + return Either.right(e.getResponseFormat()); + } + } private Either fetchLatestComponentMetadataOrThrow( ComponentTypeEnum componentType, String componentUuid -- cgit 1.2.3-korg