aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorChris André <chris.andre@yoppworks.com>2020-06-03 13:23:40 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-11 14:27:33 +0000
commit8d72481341ac6be40c380352a2a7ef5cc536692d (patch)
tree4daeb823c434e21e4724bce6ff3611b9e46b74c0 /catalog-be/src/main
parentc8a11265085b1342c4efa03a9985d9fd9ca203a3 (diff)
Rewrite of `updateArtifactOnInterfaceOperationByResourceUUID` to remove NPE
Issue-ID: SDC-2978 Signed-off-by: Chris Andre <chris.andre@yoppworks.com> Change-Id: I60942ab1767bf65c806ce796ca62365396b20d93
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java49
1 files changed, 25 insertions, 24 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 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<ResponseFormat> errorWrapper = new Wrapper<>();
Either<ArtifactDefinition, ResponseFormat> updateArtifactResult;
- Either<Either<ArtifactDefinition, Operation>, 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<ComponentMetadataData, ActionStatus> 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<ArtifactDefinition, ResponseFormat> 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<ComponentMetadataData, ActionStatus> fetchLatestComponentMetadataOrThrow(
ComponentTypeEnum componentType, String componentUuid