Fix 'SDC be API returns HTTP 200 response code on error'-bug 34/132934/6
authorvasraz <vasyl.razinkov@est.tech>
Tue, 17 Jan 2023 18:59:55 +0000 (18:59 +0000)
committerMichael Morris <michael.morris@est.tech>
Thu, 19 Jan 2023 21:59:49 +0000 (21:59 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I7c314a8d3aa7978d60bee8256e5a83958f2328db
Issue-ID: SDC-3505

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 acbb0cd..bf674d5 100644 (file)
@@ -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<String, List<ErrorMessage>> 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);