From 3ef8252b29317f8fec99fd93c38e9f306639e6bb Mon Sep 17 00:00:00 2001 From: vasraz Date: Tue, 17 Jan 2023 18:59:55 +0000 Subject: Fix 'SDC be API returns HTTP 200 response code on error'-bug Signed-off-by: Vasyl Razinkov Change-Id: I7c314a8d3aa7978d60bee8256e5a83958f2328db Issue-ID: SDC-3505 --- .../rest/services/OrchestrationTemplateCandidateImpl.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'openecomp-be') 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); -- cgit 1.2.3-korg