From: vasraz Date: Tue, 17 Jan 2023 18:59:55 +0000 (+0000) Subject: Fix 'SDC be API returns HTTP 200 response code on error'-bug X-Git-Tag: 1.12.1~18 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F34%2F132934%2F6;p=sdc.git Fix 'SDC be API returns HTTP 200 response code on error'-bug Signed-off-by: Vasyl Razinkov Change-Id: I7c314a8d3aa7978d60bee8256e5a83958f2328db Issue-ID: SDC-3505 --- diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java index acbb0cdd03..bf674d5dcd 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java @@ -50,6 +50,7 @@ import java.util.UUID; import javax.activation.DataHandler; import javax.inject.Named; import javax.ws.rs.core.Response; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.openecomp.sdc.activitylog.ActivityLogManager; @@ -176,12 +177,18 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate vspUploadStatus = orchestrationTemplateCandidateUploadManager.putUploadInProcessing(vspId, versionId, user); response = processOnboardPackage(onboardPackageInfo, vspDetails, errorMessages); final UploadFileResponseDto entity = (UploadFileResponseDto) response.getEntity(); - if (artifactStorageManager.isEnabled()) { - if (entity.getErrors().isEmpty()) { - artifactStorageManager.put(vspId, versionId + ".reduced", new ByteArrayInputStream(fileToUploadBytes)); - } else { + final Map> errors = entity.getErrors(); + if (MapUtils.isNotEmpty(errors)) { + if (artifactStorageManager.isEnabled()) { artifactStorageManager.delete(artifactInfo); } + orchestrationTemplateCandidateUploadManager + .putUploadAsFinished(vspId, versionId, vspUploadStatus.getLockId(), VspUploadStatus.ERROR, user); + return Response.status(NOT_ACCEPTABLE) + .entity(buildUploadResponseWithError(errors.values().stream().flatMap(List::stream).toArray(ErrorMessage[]::new))).build(); + } + if (artifactStorageManager.isEnabled()) { + artifactStorageManager.put(vspId, versionId + ".reduced", new ByteArrayInputStream(fileToUploadBytes)); } orchestrationTemplateCandidateUploadManager .putUploadAsFinished(vspId, versionId, vspUploadStatus.getLockId(), VspUploadStatus.SUCCESS, user);