Upgrade swagger
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / externalapi / servlet / ArtifactExternalServlet.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * SDC\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.sdc.be.externalapi.servlet;\r
22 \r
23 import java.io.ByteArrayInputStream;\r
24 import java.io.IOException;\r
25 import java.io.InputStream;\r
26 import java.util.HashMap;\r
27 import java.util.Map;\r
28 import javax.inject.Inject;\r
29 import javax.inject.Singleton;\r
30 import javax.servlet.http.HttpServletRequest;\r
31 import javax.ws.rs.DELETE;\r
32 import javax.ws.rs.GET;\r
33 import javax.ws.rs.HeaderParam;\r
34 import javax.ws.rs.POST;\r
35 import javax.ws.rs.Path;\r
36 import javax.ws.rs.PathParam;\r
37 import javax.ws.rs.Produces;\r
38 import javax.ws.rs.core.Context;\r
39 import javax.ws.rs.core.HttpHeaders;\r
40 import javax.ws.rs.core.MediaType;\r
41 import javax.ws.rs.core.Response;\r
42 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;\r
43 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;\r
44 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;\r
45 import org.openecomp.sdc.be.components.impl.ResourceImportManager;\r
46 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;\r
47 import org.openecomp.sdc.be.config.BeEcompErrorManager;\r
48 import org.openecomp.sdc.be.dao.api.ActionStatus;\r
49 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;\r
50 import org.openecomp.sdc.be.impl.ComponentsUtils;\r
51 import org.openecomp.sdc.be.impl.ServletUtils;\r
52 import org.openecomp.sdc.be.model.ArtifactDefinition;\r
53 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;\r
54 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;\r
55 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;\r
56 import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;\r
57 import org.openecomp.sdc.be.servlets.RepresentationUtils;\r
58 import org.openecomp.sdc.be.user.UserBusinessLogic;\r
59 import org.openecomp.sdc.common.api.Constants;\r
60 import org.openecomp.sdc.common.datastructure.Wrapper;\r
61 import org.openecomp.sdc.common.util.GeneralUtility;\r
62 import org.openecomp.sdc.exception.ResponseFormat;\r
63 import org.slf4j.Logger;\r
64 import org.slf4j.LoggerFactory;\r
65 import com.jcabi.aspects.Loggable;\r
66 import fj.data.Either;\r
67 import io.swagger.v3.oas.annotations.OpenAPIDefinition;\r
68 import io.swagger.v3.oas.annotations.Operation;\r
69 import io.swagger.v3.oas.annotations.Parameter;\r
70 import io.swagger.v3.oas.annotations.info.Info;\r
71 import io.swagger.v3.oas.annotations.media.ArraySchema;\r
72 import io.swagger.v3.oas.annotations.media.Content;\r
73 import io.swagger.v3.oas.annotations.media.Schema;\r
74 import io.swagger.v3.oas.annotations.responses.ApiResponse;\r
75 import io.swagger.v3.oas.annotations.responses.ApiResponses;\r
76 \r
77 /**\r
78  * This Servlet serves external users operations on artifacts.\r
79  *\r
80  * @author mshitrit\r
81  *\r
82  */\r
83 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)\r
84 @Path("/v1/catalog")\r
85 \r
86 @OpenAPIDefinition(info = @Info(title = "Artifact External Servlet",\r
87         description = "Servlet serves external users operations on artifacts."))\r
88 @Singleton\r
89 public class ArtifactExternalServlet extends AbstractValidationsServlet {\r
90 \r
91     private static final String FAILED_TO_UPDATE_ARTIFACT = "failed to update artifact";\r
92 \r
93     @Context\r
94     private HttpServletRequest request;\r
95 \r
96     private final ArtifactsBusinessLogic artifactsBusinessLogic;\r
97 \r
98     private static final Logger log = LoggerFactory.getLogger(ArtifactExternalServlet.class);\r
99 \r
100     private static String startLog = "Start handle request of ";\r
101 \r
102     @Inject\r
103     public ArtifactExternalServlet(UserBusinessLogic userBusinessLogic,\r
104             ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils,\r
105             ServletUtils servletUtils, ResourceImportManager resourceImportManager,\r
106             ArtifactsBusinessLogic artifactsBusinessLogic) {\r
107         super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);\r
108         this.artifactsBusinessLogic = artifactsBusinessLogic;\r
109     }\r
110 \r
111 \r
112     @POST\r
113     @Path("/{assetType}/{uuid}/interfaces/{interfaceUUID}/operations/{operationUUID}/artifacts/{artifactUUID}")\r
114     @Produces(MediaType.APPLICATION_JSON)\r
115     @Operation(parameters = @Parameter(required = true ),description = "uploads of artifact to VF operation workflow", method = "POST",\r
116             summary = "uploads of artifact to VF operation workflow")\r
117     @ApiResponses(value = {\r
118             @ApiResponse(responseCode = "200", description = "Artifact uploaded",\r
119                     content = @Content(\r
120                             array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),\r
121             @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),\r
122             @ApiResponse(responseCode = "401",\r
123                     description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),\r
124             @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),\r
125             @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),\r
126             @ApiResponse(responseCode = "405",\r
127                     description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),\r
128             @ApiResponse(responseCode = "500",\r
129                     description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),\r
130             @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),\r
131             @ApiResponse(responseCode = "400",\r
132                     description = "Artifact type (mandatory field) is missing in request - SVC4124"),\r
133             @ApiResponse(responseCode = "400",\r
134                     description = "Artifact name given in input already exists in the context of the asset - SVC4125"),\r
135             @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),\r
136             @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),\r
137             @ApiResponse(responseCode = "400",\r
138                     description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),\r
139             @ApiResponse(responseCode = "400",\r
140                     description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})\r
141     // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =\r
142     // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the\r
143     // artifact")})\r
144     public Response uploadInterfaceOperationArtifact(\r
145             @Parameter(description = "Determines the format of the body of the request",\r
146                     required = true) @HeaderParam(value = HttpHeaders.CONTENT_TYPE) String contentType,\r
147             @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",\r
148                     required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,\r
149             @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",\r
150                     required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,\r
151             @Parameter(description = "X-ECOMP-RequestID header",\r
152                     required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,\r
153             @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(\r
154                     value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,\r
155             @Parameter(description = "Determines the format of the body of the response",\r
156                     required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,\r
157             @Parameter(description = "The username and password",\r
158                     required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,\r
159             @Parameter(description = "Asset type") @PathParam("assetType") String assetType,\r
160             @Parameter(description = "The uuid of the asset as published in the metadata",\r
161                     required = true) @PathParam("uuid") final String uuid,\r
162             @Parameter(description = "The uuid of the interface",\r
163                     required = true) @PathParam("interfaceUUID") final String interfaceUUID,\r
164             @Parameter(description = "The uuid of the operation",\r
165                     required = true) @PathParam("operationUUID") final String operationUUID,\r
166             @Parameter(description = "The uuid of the artifact",\r
167                     required = true) @PathParam("artifactUUID") final String artifactUUID,\r
168             @Parameter(hidden = true) String data) {\r
169         Wrapper<Response> responseWrapper = new Wrapper<>();\r
170         ResponseFormat responseFormat = null;\r
171         String requestURI = request.getRequestURI();\r
172         String url = request.getMethod() + " " + requestURI;\r
173         log.debug("{} {}", startLog, url);\r
174         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(assetType);\r
175         ArtifactDefinition artifactDefinition = null;\r
176 \r
177         if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {\r
178             log.debug("updateArtifact: Missing X-ECOMP-InstanceID header");\r
179             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);\r
180             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
181         }\r
182         if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {\r
183             log.debug("updateArtifact: Missing USER_ID");\r
184             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);\r
185             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
186         }\r
187         try {\r
188             if (responseWrapper.isEmpty()) {\r
189                 Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =\r
190                         artifactsBusinessLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request,\r
191                                 ComponentTypeEnum.findByParamName(assetType), uuid, interfaceUUID, operationUUID,\r
192                                 artifactUUID, resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true,\r
193                                         false, ArtifactOperationEnum.UPDATE));\r
194                 if (uploadArtifactEither.isRight()) {\r
195                     log.debug(FAILED_TO_UPDATE_ARTIFACT);\r
196                     responseFormat = uploadArtifactEither.right().value();\r
197                     responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
198                 } else {\r
199                     artifactDefinition = uploadArtifactEither.left().value();\r
200                     Object representation = RepresentationUtils.toRepresentation(artifactDefinition);\r
201                     Map<String, String> headers = new HashMap<>();\r
202                     headers.put(Constants.MD5_HEADER,\r
203                             GeneralUtility.calculateMD5Base64EncodedByString((String) representation));\r
204                     responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);\r
205                     responseWrapper.setInnerElement(buildOkResponse(\r
206                             getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));\r
207                 }\r
208             }\r
209         } catch (Exception e) {\r
210             final String message = "failed to update artifact on a resource or service";\r
211             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);\r
212             log.debug(message, e);\r
213             responseWrapper.setInnerElement(\r
214                     buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));\r
215         } finally {\r
216             getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPLOAD_BY_API,\r
217                     resourceCommonInfo, request, artifactDefinition, null);\r
218         }\r
219         return responseWrapper.getInnerElement();\r
220     }\r
221 \r
222     /**\r
223      * Uploads an artifact to resource or service\r
224      *\r
225      * @param contentType\r
226      * @param checksum\r
227      * @param userId\r
228      * @param requestId\r
229      * @param instanceIdHeader\r
230      * @param accept\r
231      * @param authorization\r
232      * @param assetType\r
233      * @param uuid\r
234      * @param data\r
235      * @return\r
236      */\r
237     @POST\r
238     @Path("/{assetType}/{uuid}/artifacts")\r
239     @Produces(MediaType.APPLICATION_JSON)\r
240     @Operation(description = "uploads of artifact to a resource or service", method = "POST",\r
241             summary = "uploads of artifact to a resource or service")\r
242     @ApiResponses(value = {\r
243             @ApiResponse(responseCode = "200", description = "Artifact uploaded",\r
244                     content = @Content(\r
245                             array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),\r
246             @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),\r
247             @ApiResponse(responseCode = "401",\r
248                     description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),\r
249             @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),\r
250             @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),\r
251             @ApiResponse(responseCode = "405",\r
252                     description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),\r
253             @ApiResponse(responseCode = "500",\r
254                     description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),\r
255             @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),\r
256             @ApiResponse(responseCode = "400",\r
257                     description = "Artifact type (mandatory field) is missing in request - SVC4124"),\r
258             @ApiResponse(responseCode = "400",\r
259                     description = "Artifact name given in input already exists in the context of the asset - SVC4125"),\r
260             @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),\r
261             @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),\r
262             @ApiResponse(responseCode = "400",\r
263                     description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),\r
264             @ApiResponse(responseCode = "400",\r
265                     description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})\r
266     // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =\r
267     // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the\r
268     // artifact")})\r
269     public Response uploadArtifact(\r
270             @Parameter(description = "Determines the format of the body of the request",\r
271                     required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,\r
272             @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",\r
273                     required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,\r
274             @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",\r
275                     required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,\r
276             @Parameter(description = "X-ECOMP-RequestID header",\r
277                     required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,\r
278             @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(\r
279                     value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,\r
280             @Parameter(description = "Determines the format of the body of the response",\r
281                     required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,\r
282             @Parameter(description = "The username and password",\r
283                     required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,\r
284             @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",\r
285                     required = true) @PathParam("assetType") final String assetType,\r
286             @Parameter(description = "The uuid of the asset as published in the metadata",\r
287                     required = true) @PathParam("uuid") final String uuid,\r
288             @Parameter(hidden = true) String data) {\r
289 \r
290         init();\r
291 \r
292         Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();\r
293         String requestURI = request.getRequestURI();\r
294         String url = request.getMethod() + " " + requestURI;\r
295         log.debug("{} {}", startLog, url);\r
296         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);\r
297         String componentTypeValue = componentType == null ? null : componentType.getValue();\r
298         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);\r
299 \r
300         if (componentType == null) {\r
301             log.debug("uploadArtifact: assetType parameter {} is not valid", assetType);\r
302             responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));\r
303         }\r
304         if (responseWrapper.isEmpty()) {\r
305             validateXECOMPInstanceIDHeader(instanceIdHeader, responseWrapper);\r
306         }\r
307         if (responseWrapper.isEmpty()) {\r
308             validateHttpCspUserIdHeader(userId, responseWrapper);\r
309         }\r
310         Response response = null;\r
311         ArtifactDefinition artifactDefinition = null;\r
312         try {\r
313             if (responseWrapper.isEmpty()) {\r
314                 Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =\r
315                         artifactsBusinessLogic.uploadArtifactToComponentByUUID(data, request, componentType, uuid,\r
316                                 resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false,\r
317                                         ArtifactOperationEnum.CREATE));\r
318                 if (uploadArtifactEither.isRight()) {\r
319                     log.debug("failed to upload artifact");\r
320                     responseWrapper.setInnerElement(uploadArtifactEither.right().value());\r
321                 } else {\r
322                     artifactDefinition = uploadArtifactEither.left().value();\r
323                     Object representation = RepresentationUtils.toRepresentation(artifactDefinition);\r
324                     Map<String, String> headers = new HashMap<>();\r
325                     headers.put(Constants.MD5_HEADER,\r
326                             GeneralUtility.calculateMD5Base64EncodedByString((String) representation));\r
327                     responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.OK));\r
328                     response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation,\r
329                             headers);\r
330                 }\r
331             }\r
332         } catch (IOException e) {\r
333             final String message = "failed to upload artifact to a resource or service";\r
334             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);\r
335             log.debug(message, e);\r
336             responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
337             response = buildErrorResponse(responseWrapper.getInnerElement());\r
338         } catch (ComponentException e) {\r
339             responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(e));\r
340         } finally {\r
341             if (response == null) {\r
342                 response = buildErrorResponse(responseWrapper.getInnerElement());\r
343             }\r
344             getComponentsUtils().auditExternalCrudApi(responseWrapper.getInnerElement(),\r
345                     AuditingActionEnum.ARTIFACT_UPLOAD_BY_API, resourceCommonInfo, request, artifactDefinition, null);\r
346         }\r
347         return response;\r
348     }\r
349 \r
350     /**\r
351      * Uploads an artifact to resource instance\r
352      *\r
353      * @param assetType\r
354      * @param uuid\r
355      * @param resourceInstanceName\r
356      * @return\r
357      */\r
358     @POST\r
359     @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts")\r
360     @Produces(MediaType.APPLICATION_JSON)\r
361     @Operation(description = "uploads an artifact to a resource instance", method = "POST",\r
362             summary = "uploads an artifact to a resource instance")\r
363     @ApiResponses(value = {\r
364             @ApiResponse(responseCode = "200", description = "Artifact uploaded",\r
365                     content = @Content(\r
366                             array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),\r
367             @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),\r
368             @ApiResponse(responseCode = "401",\r
369                     description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),\r
370             @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),\r
371             @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),\r
372             @ApiResponse(responseCode = "405",\r
373                     description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),\r
374             @ApiResponse(responseCode = "500",\r
375                     description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),\r
376             @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),\r
377             @ApiResponse(responseCode = "400",\r
378                     description = "Artifact type (mandatory field) is missing in request - SVC4124"),\r
379             @ApiResponse(responseCode = "400",\r
380                     description = "Artifact name given in input already exists in the context of the asset - SVC4125"),\r
381             @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),\r
382             @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),\r
383             @ApiResponse(responseCode = "400",\r
384                     description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),\r
385             @ApiResponse(responseCode = "400",\r
386                     description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})\r
387     // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =\r
388     // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the\r
389     // artifact")})\r
390     public Response uploadArtifactToInstance(\r
391             @Parameter(description = "Determines the format of the body of the request",\r
392                     required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,\r
393             @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",\r
394                     required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,\r
395             @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",\r
396                     required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,\r
397             @Parameter(description = "X-ECOMP-RequestID header",\r
398                     required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,\r
399             @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(\r
400                     value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,\r
401             @Parameter(description = "Determines the format of the body of the response",\r
402                     required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,\r
403             @Parameter(description = "The username and password",\r
404                     required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,\r
405             @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",\r
406                     required = true) @PathParam("assetType") final String assetType,\r
407             @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The uuid of the asset as published in the metadata",\r
408                     required = true) @PathParam("uuid") final String uuid,\r
409             @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",\r
410                     required = true) @PathParam("resourceInstanceName") final String resourceInstanceName,\r
411             @Parameter(hidden = true) String data) {\r
412 \r
413         Wrapper<Response> responseWrapper = new Wrapper<>();\r
414         ResponseFormat responseFormat = null;\r
415         String requestURI = request.getRequestURI();\r
416         String url = request.getMethod() + " " + requestURI;\r
417         log.debug("{} {}", startLog, url);\r
418         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);\r
419         String componentTypeValue = componentType == null ? null : componentType.getValue();\r
420         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(resourceInstanceName, componentTypeValue);\r
421         ArtifactDefinition artifactDefinition = null;\r
422 \r
423         if (componentType == null) {\r
424             log.debug("uploadArtifact: assetType parameter {} is not valid", assetType);\r
425             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);\r
426             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
427         }\r
428         if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {\r
429             log.debug("uploadArtifact: Missing X-ECOMP-InstanceID header");\r
430             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);\r
431             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
432         }\r
433         if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {\r
434             log.debug("uploadArtifact: Missing USER_ID header");\r
435             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);\r
436             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
437         }\r
438         try {\r
439             if (responseWrapper.isEmpty()) {\r
440                 Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =\r
441                         artifactsBusinessLogic.uploadArtifactToRiByUUID(data, request, componentType, uuid,\r
442                                 resourceInstanceName, artifactsBusinessLogic.new ArtifactOperationInfo(true, false,\r
443                                         ArtifactOperationEnum.CREATE));\r
444                 if (uploadArtifactEither.isRight()) {\r
445                     log.debug("failed to upload artifact");\r
446                     responseFormat = uploadArtifactEither.right().value();\r
447                     responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
448                 } else {\r
449                     Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());\r
450                     Map<String, String> headers = new HashMap<>();\r
451                     headers.put(Constants.MD5_HEADER,\r
452                             GeneralUtility.calculateMD5Base64EncodedByString((String) representation));\r
453                     responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);\r
454                     responseWrapper.setInnerElement(buildOkResponse(\r
455                             getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));\r
456                 }\r
457             }\r
458         } catch (IOException e) {\r
459             final String message = "failed to upload artifact to a resource instance";\r
460             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);\r
461             log.debug(message, e);\r
462             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);\r
463             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
464         } catch (ComponentException e) {\r
465             responseFormat = getComponentsUtils().getResponseFormat(e);\r
466         } finally {\r
467             getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPLOAD_BY_API,\r
468                     resourceCommonInfo, request, artifactDefinition, null);\r
469         }\r
470         return responseWrapper.getInnerElement();\r
471     }\r
472 \r
473     /**\r
474      *\r
475      * @param contentType\r
476      * @param checksum\r
477      * @param userId\r
478      * @param requestId\r
479      * @param instanceIdHeader\r
480      * @param accept\r
481      * @param authorization\r
482      * @param assetType\r
483      * @param uuid\r
484      * @param artifactUUID\r
485      * @param data\r
486      * @return\r
487      */\r
488     @POST\r
489     @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")\r
490     @Produces(MediaType.APPLICATION_JSON)\r
491     @Operation(description = "updates an artifact on a resource or service", method = "POST",\r
492             summary = "uploads of artifact to a resource or service")\r
493     @ApiResponses(value = {\r
494             @ApiResponse(responseCode = "200", description = "Artifact updated",\r
495                     content = @Content(\r
496                             array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),\r
497             @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),\r
498             @ApiResponse(responseCode = "401",\r
499                     description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),\r
500             @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),\r
501             @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),\r
502             @ApiResponse(responseCode = "405",\r
503                     description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),\r
504             @ApiResponse(responseCode = "500",\r
505                     description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),\r
506             @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),\r
507             @ApiResponse(responseCode = "400",\r
508                     description = "Artifact type (mandatory field) is missing in request - SVC4124"),\r
509             @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),\r
510             @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),\r
511             @ApiResponse(responseCode = "403",\r
512                     description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),\r
513             @ApiResponse(responseCode = "409",\r
514                     description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})\r
515     // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =\r
516     // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the\r
517     // artifact")})\r
518     public Response updateArtifact(\r
519             @Parameter(description = "Determines the format of the body of the request",\r
520                     required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,\r
521             @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",\r
522                     required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,\r
523             @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",\r
524                     required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,\r
525             @Parameter(description = "X-ECOMP-RequestID header",\r
526                     required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,\r
527             @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(\r
528                     value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,\r
529             @Parameter(description = "Determines the format of the body of the response",\r
530                     required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,\r
531             @Parameter(description = "The username and password",\r
532                     required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,\r
533             @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",\r
534                     required = true) @PathParam("assetType") final String assetType,\r
535             @Parameter(description = "The uuid of the asset as published in the metadata",\r
536                     required = true) @PathParam("uuid") final String uuid,\r
537             @Parameter(\r
538                     description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",\r
539                     required = true) @PathParam("artifactUUID") final String artifactUUID,\r
540             @Parameter(hidden = true) String data) {\r
541 \r
542         Wrapper<Response> responseWrapper = new Wrapper<>();\r
543         ResponseFormat responseFormat = null;\r
544         String requestURI = request.getRequestURI();\r
545         String url = request.getMethod() + " " + requestURI;\r
546         log.debug("{} {}", startLog, url);\r
547         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);\r
548         String componentTypeValue = componentType == null ? null : componentType.getValue();\r
549         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);\r
550         if (componentType == null) {\r
551             log.debug("updateArtifact: assetType parameter {} is not valid", assetType);\r
552             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);\r
553             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
554         }\r
555         if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {\r
556             log.debug("updateArtifact: Missing X-ECOMP-InstanceID header");\r
557             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);\r
558             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
559         }\r
560         if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {\r
561             log.debug("updateArtifact: Missing USER_ID");\r
562             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);\r
563             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
564         }\r
565         ArtifactDefinition artifactDefinition = null;\r
566         try {\r
567             if (responseWrapper.isEmpty()) {\r
568                 Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =\r
569                         artifactsBusinessLogic.updateArtifactOnComponentByUUID(data, request, componentType, uuid,\r
570                                 artifactUUID, resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true,\r
571                                         false, ArtifactOperationEnum.UPDATE));\r
572                 if (uploadArtifactEither.isRight()) {\r
573                     log.debug(FAILED_TO_UPDATE_ARTIFACT);\r
574                     responseFormat = uploadArtifactEither.right().value();\r
575                     responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
576                 } else {\r
577                     Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());\r
578                     Map<String, String> headers = new HashMap<>();\r
579                     headers.put(Constants.MD5_HEADER,\r
580                             GeneralUtility.calculateMD5Base64EncodedByString((String) representation));\r
581                     responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);\r
582                     responseWrapper.setInnerElement(buildOkResponse(\r
583                             getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));\r
584                 }\r
585             }\r
586         } catch (IOException e) {\r
587             final String message = "failed to update artifact on a resource or service";\r
588             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);\r
589             log.debug(message, e);\r
590             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);\r
591             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
592         } catch (ComponentException e) {\r
593             responseFormat = getComponentsUtils().getResponseFormat(e);\r
594         } finally {\r
595             getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPDATE_BY_API,\r
596                     resourceCommonInfo, request, artifactDefinition, artifactUUID);\r
597         }\r
598         return responseWrapper.getInnerElement();\r
599     }\r
600 \r
601     /**\r
602      * updates an artifact on a resource instance\r
603      *\r
604      * @param assetType\r
605      * @param uuid\r
606      * @param resourceInstanceName\r
607      * @param artifactUUID\r
608      * @return\r
609      */\r
610     @POST\r
611     @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")\r
612     @Produces(MediaType.APPLICATION_JSON)\r
613     @Operation(description = "updates an artifact on a resource instance", method = "POST",\r
614             summary = "uploads of artifact to a resource or service")\r
615     @ApiResponses(value = {\r
616             @ApiResponse(responseCode = "200", description = "Artifact updated",\r
617                     content = @Content(\r
618                             array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),\r
619             @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),\r
620             @ApiResponse(responseCode = "401",\r
621                     description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),\r
622             @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),\r
623             @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),\r
624             @ApiResponse(responseCode = "405",\r
625                     description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),\r
626             @ApiResponse(responseCode = "500",\r
627                     description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),\r
628             @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),\r
629             @ApiResponse(responseCode = "400",\r
630                     description = "Artifact type (mandatory field) is missing in request - SVC4124"),\r
631             @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),\r
632             @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),\r
633             @ApiResponse(responseCode = "403",\r
634                     description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),\r
635             @ApiResponse(responseCode = "409",\r
636                     description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})\r
637     // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =\r
638     // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the\r
639     // artifact")})\r
640     public Response updateArtifactOnResourceInstance(\r
641             @Parameter(description = "Determines the format of the body of the request",\r
642                     required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,\r
643             @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",\r
644                     required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,\r
645             @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",\r
646                     required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,\r
647             @Parameter(description = "X-ECOMP-RequestID header",\r
648                     required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,\r
649             @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(\r
650                     value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,\r
651             @Parameter(description = "Determines the format of the body of the response",\r
652                     required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,\r
653             @Parameter(description = "The username and password",\r
654                     required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,\r
655             @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",\r
656                     required = true) @PathParam("assetType") final String assetType,\r
657             @Parameter(description = "The uuid of the asset as published in the metadata",\r
658                     required = true) @PathParam("uuid") final String uuid,\r
659             @Parameter(\r
660                     description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",\r
661                     required = true) @PathParam("artifactUUID") final String artifactUUID,\r
662             @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",\r
663                     required = true) @PathParam("resourceInstanceName") final String resourceInstanceName,\r
664             @Parameter(hidden = true) String data) {\r
665 \r
666         Wrapper<Response> responseWrapper = new Wrapper<>();\r
667         ResponseFormat responseFormat = null;\r
668         String requestURI = request.getRequestURI();\r
669         String url = request.getMethod() + " " + requestURI;\r
670         log.debug("{} {}", startLog, url);\r
671         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);\r
672         String componentTypeValue = componentType == null ? null : componentType.getValue();\r
673         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(resourceInstanceName, componentTypeValue);\r
674         if (componentType == null) {\r
675             log.debug("updateArtifactOnResourceInstance: assetType parameter {} is not valid", assetType);\r
676             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);\r
677             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
678         }\r
679         if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {\r
680             log.debug("updateArtifactOnResourceInstance: Missing X-ECOMP-InstanceID header");\r
681             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);\r
682             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
683         }\r
684         if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {\r
685             log.debug("updateArtifactOnResourceInstance: Missing USER_ID header");\r
686             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);\r
687             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
688         }\r
689         ArtifactDefinition artifactDefinition = null;\r
690         try {\r
691             if (responseWrapper.isEmpty()) {\r
692                 Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =\r
693                         artifactsBusinessLogic.updateArtifactOnRiByUUID(data, request, componentType, uuid,\r
694                                 resourceInstanceName, artifactUUID, artifactsBusinessLogic.new ArtifactOperationInfo(\r
695                                         true, false, ArtifactOperationEnum.UPDATE));\r
696                 if (uploadArtifactEither.isRight()) {\r
697                     log.debug(FAILED_TO_UPDATE_ARTIFACT);\r
698                     responseFormat = uploadArtifactEither.right().value();\r
699                     responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
700                 } else {\r
701                     Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());\r
702                     Map<String, String> headers = new HashMap<>();\r
703                     headers.put(Constants.MD5_HEADER,\r
704                             GeneralUtility.calculateMD5Base64EncodedByString((String) representation));\r
705                     responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);\r
706                     responseWrapper.setInnerElement(buildOkResponse(\r
707                             getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));\r
708                 }\r
709             }\r
710         } catch (IOException e) {\r
711             final String message = "failed to update artifact on resource instance";\r
712             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);\r
713             log.debug(message, e);\r
714             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);\r
715             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
716         } catch (ComponentException e) {\r
717             responseFormat = getComponentsUtils().getResponseFormat(e);\r
718         } finally {\r
719             getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPDATE_BY_API,\r
720                     resourceCommonInfo, request, artifactDefinition, artifactUUID);\r
721         }\r
722         return responseWrapper.getInnerElement();\r
723     }\r
724 \r
725     /**\r
726      * deletes an artifact of a resource or service\r
727      *\r
728      * @param assetType\r
729      * @param uuid\r
730      * @param artifactUUID\r
731      * @return\r
732      */\r
733     @DELETE\r
734     @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")\r
735     @Produces(MediaType.APPLICATION_JSON)\r
736     @Operation(description = "deletes an artifact of a resource or service", method = "DELETE",\r
737             summary = "deletes an artifact of a resource or service", responses = @ApiResponse(\r
738                     content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
739     @ApiResponses(value = {\r
740             @ApiResponse(responseCode = "200", description = "Artifact deleted",\r
741                     content = @Content(\r
742                             array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),\r
743             @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),\r
744             @ApiResponse(responseCode = "401",\r
745                     description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),\r
746             @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),\r
747             @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),\r
748             @ApiResponse(responseCode = "405",\r
749                     description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),\r
750             @ApiResponse(responseCode = "500",\r
751                     description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),\r
752             @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),\r
753             @ApiResponse(responseCode = "400",\r
754                     description = "Artifact type (mandatory field) is missing in request - SVC4124"),\r
755             @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),\r
756             @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),\r
757             @ApiResponse(responseCode = "403",\r
758                     description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),\r
759             @ApiResponse(responseCode = "409",\r
760                     description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})\r
761     public Response deleteArtifact(\r
762             @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",\r
763                     required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,\r
764             @Parameter(description = "X-ECOMP-RequestID header",\r
765                     required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,\r
766             @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(\r
767                     value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,\r
768             @Parameter(description = "Determines the format of the body of the response",\r
769                     required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,\r
770             @Parameter(description = "The username and password",\r
771                     required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,\r
772             @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",\r
773                     required = true) @PathParam("assetType") final String assetType,\r
774             @Parameter(description = "The uuid of the asset as published in the metadata",\r
775                     required = true) @PathParam("uuid") final String uuid,\r
776             @Parameter(\r
777                     description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",\r
778                     required = true) @PathParam("artifactUUID") final String artifactUUID) {\r
779 \r
780         Wrapper<Response> responseWrapper = new Wrapper<>();\r
781         ResponseFormat responseFormat = null;\r
782         String requestURI = request.getRequestURI();\r
783         String url = request.getMethod() + " " + requestURI;\r
784         log.debug("{} {}", startLog, url);\r
785         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);\r
786         String componentTypeValue = componentType == null ? null : componentType.getValue();\r
787         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);\r
788         ArtifactDefinition artifactDefinition = null;\r
789         if (componentType == null) {\r
790             log.debug("deleteArtifact: assetType parameter {} is not valid", assetType);\r
791             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);\r
792             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
793         }\r
794         if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {\r
795             log.debug("deleteArtifact: Missing X-ECOMP-InstanceID header");\r
796             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);\r
797             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
798         }\r
799         if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {\r
800             log.debug("deleteArtifact: Missing USER_ID header");\r
801             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);\r
802             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
803         }\r
804         try {\r
805             if (responseWrapper.isEmpty()) {\r
806                 Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =\r
807                         artifactsBusinessLogic.deleteArtifactOnComponentByUUID(request, componentType, uuid,\r
808                                 artifactUUID, resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true,\r
809                                         false, ArtifactOperationEnum.DELETE));\r
810                 if (uploadArtifactEither.isRight()) {\r
811                     log.debug("failed to delete artifact");\r
812                     responseFormat = uploadArtifactEither.right().value();\r
813                     responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
814                 } else {\r
815                     Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());\r
816                     Map<String, String> headers = new HashMap<>();\r
817                     headers.put(Constants.MD5_HEADER,\r
818                             GeneralUtility.calculateMD5Base64EncodedByString((String) representation));\r
819                     responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);\r
820                     responseWrapper.setInnerElement(buildOkResponse(\r
821                             getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));\r
822                 }\r
823             }\r
824         } catch (IOException e) {\r
825             final String message = "failed to delete an artifact of a resource or service";\r
826             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);\r
827             log.debug(message, e);\r
828             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);\r
829             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
830         } catch (ComponentException e) {\r
831             responseFormat = getComponentsUtils().getResponseFormat(e);\r
832         } finally {\r
833             getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_DELETE_BY_API,\r
834                     resourceCommonInfo, request, artifactDefinition, artifactUUID);\r
835         }\r
836         return responseWrapper.getInnerElement();\r
837     }\r
838 \r
839     /**\r
840      * deletes an artifact of a resource instance\r
841      *\r
842      * @param assetType\r
843      * @param uuid\r
844      * @param resourceInstanceName\r
845      * @return\r
846      */\r
847     @DELETE\r
848     @Path("{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")\r
849     @Produces(MediaType.APPLICATION_JSON)\r
850     @Operation(description = "deletes an artifact of a resource insatnce", method = "DELETE",\r
851             summary = "deletes an artifact of a resource insatnce", responses = @ApiResponse(\r
852                     content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
853     @ApiResponses(value = {\r
854             @ApiResponse(responseCode = "200", description = "Artifact deleted",\r
855                     content = @Content(\r
856                             array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),\r
857             @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),\r
858             @ApiResponse(responseCode = "401",\r
859                     description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),\r
860             @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),\r
861             @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),\r
862             @ApiResponse(responseCode = "405",\r
863                     description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),\r
864             @ApiResponse(responseCode = "500",\r
865                     description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),\r
866             @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),\r
867             @ApiResponse(responseCode = "400",\r
868                     description = "Artifact type (mandatory field) is missing in request - SVC4124"),\r
869             @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),\r
870             @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),\r
871             @ApiResponse(responseCode = "403",\r
872                     description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),\r
873             @ApiResponse(responseCode = "409",\r
874                     description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})\r
875     public Response deleteArtifactOnResourceInstance(\r
876             @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",\r
877                     required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,\r
878             @Parameter(description = "X-ECOMP-RequestID header",\r
879                     required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,\r
880             @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(\r
881                     value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,\r
882             @Parameter(description = "Determines the format of the body of the response",\r
883                     required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,\r
884             @Parameter(description = "The username and password",\r
885                     required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,\r
886             @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",\r
887                     required = true) @PathParam("assetType") final String assetType,\r
888             @Parameter(description = "The uuid of the asset as published in the metadata",\r
889                     required = true) @PathParam("uuid") final String uuid,\r
890             @Parameter(\r
891                     description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",\r
892                     required = true) @PathParam("artifactUUID") final String artifactUUID,\r
893             @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",\r
894                     required = true) @PathParam("resourceInstanceName") final String resourceInstanceName) {\r
895 \r
896         Wrapper<Response> responseWrapper = new Wrapper<>();\r
897         ResponseFormat responseFormat = null;\r
898         String requestURI = request.getRequestURI();\r
899         String url = request.getMethod() + " " + requestURI;\r
900         log.debug("{} {}", startLog, url);\r
901         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);\r
902         String componentTypeValue = componentType == null ? null : componentType.getValue();\r
903         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(resourceInstanceName, componentTypeValue);\r
904         if (componentType == null) {\r
905             log.debug("deleteArtifactOnResourceInsatnce: assetType parameter {} is not valid", assetType);\r
906             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);\r
907             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
908         }\r
909         if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {\r
910             log.debug("deleteArtifactOnResourceInsatnce: Missing X-ECOMP-InstanceID header");\r
911             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);\r
912             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
913         }\r
914         if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {\r
915             log.debug("deleteArtifactOnResourceInsatnce: Missing USER_ID header");\r
916             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);\r
917             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
918         }\r
919         ArtifactDefinition artifactDefinition = null;\r
920         try {\r
921             if (responseWrapper.isEmpty()) {\r
922                 Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =\r
923                         artifactsBusinessLogic.deleteArtifactOnRiByUUID(request, componentType, uuid,\r
924                                 resourceInstanceName, artifactUUID, artifactsBusinessLogic.new ArtifactOperationInfo(\r
925                                         true, false, ArtifactOperationEnum.DELETE));\r
926                 if (uploadArtifactEither.isRight()) {\r
927                     log.debug("failed to delete artifact");\r
928                     responseFormat = uploadArtifactEither.right().value();\r
929                     responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
930                 } else {\r
931                     Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());\r
932                     Map<String, String> headers = new HashMap<>();\r
933                     headers.put(Constants.MD5_HEADER,\r
934                             GeneralUtility.calculateMD5Base64EncodedByString((String) representation));\r
935                     responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);\r
936                     responseWrapper.setInnerElement(buildOkResponse(\r
937                             getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));\r
938                 }\r
939             }\r
940         } catch (IOException e) {\r
941             final String message = "failed to delete an artifact of a resource instance";\r
942             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);\r
943             log.debug(message, e);\r
944             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);\r
945             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
946         } catch (ComponentException e) {\r
947             responseFormat = getComponentsUtils().getResponseFormat(e);\r
948         } finally {\r
949             getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_DELETE_BY_API,\r
950                     resourceCommonInfo, request, artifactDefinition, artifactUUID);\r
951         }\r
952         return responseWrapper.getInnerElement();\r
953     }\r
954 \r
955     /**\r
956      * downloads an artifact of a component (either a service or a resource) by artifactUUID\r
957      *\r
958      * @param assetType\r
959      * @param uuid\r
960      * @param artifactUUID\r
961      * @return\r
962      */\r
963     @GET\r
964     @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")\r
965     @Produces(MediaType.APPLICATION_OCTET_STREAM)\r
966     @Operation(description = "Download component artifact", method = "GET", summary = "Returns downloaded artifact")\r
967     @ApiResponses(value = {\r
968             @ApiResponse(responseCode = "200", description = "Artifact downloaded",\r
969                     content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),\r
970             @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),\r
971             @ApiResponse(responseCode = "401",\r
972                     description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),\r
973             @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),\r
974             @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),\r
975             @ApiResponse(responseCode = "405",\r
976                     description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),\r
977             @ApiResponse(responseCode = "500",\r
978                     description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),\r
979             @ApiResponse(responseCode = "404", description = "Artifact was not found - SVC4505")})\r
980     public Response downloadComponentArtifact(\r
981             @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",\r
982                     required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,\r
983             @Parameter(description = "X-ECOMP-RequestID header",\r
984                     required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,\r
985             @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(\r
986                     value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,\r
987             @Parameter(description = "Determines the format of the body of the response",\r
988                     required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,\r
989             @Parameter(description = "The username and password",\r
990                     required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,\r
991             @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",\r
992                     required = true) @PathParam("assetType") final String assetType,\r
993             @Parameter(description = "The uuid of the asset as published in the metadata",\r
994                     required = true) @PathParam("uuid") final String uuid,\r
995             @Parameter(\r
996                     description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",\r
997                     required = true) @PathParam("artifactUUID") final String artifactUUID) {\r
998 \r
999         Wrapper<Response> responseWrapper = new Wrapper<>();\r
1000         ResponseFormat responseFormat = null;\r
1001         String requestURI = request.getRequestURI();\r
1002         String url = request.getMethod() + " " + requestURI;\r
1003         log.debug("{} {}", startLog, url);\r
1004         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);\r
1005         String componentTypeValue = componentType == null ? null : componentType.getValue();\r
1006         if (componentType == null) {\r
1007             log.debug("downloadComponentArtifact: assetType parameter {} is not valid", assetType);\r
1008             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);\r
1009             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
1010         }\r
1011         if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {\r
1012             log.debug("downloadComponentArtifact: Missing X-ECOMP-InstanceID header");\r
1013             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);\r
1014             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
1015         }\r
1016         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);\r
1017         try {\r
1018             if (responseWrapper.isEmpty()) {\r
1019                 Either<byte[], ResponseFormat> downloadComponentArtifactEither = artifactsBusinessLogic\r
1020                         .downloadComponentArtifactByUUIDs(componentType, uuid, artifactUUID, resourceCommonInfo);\r
1021                 if (downloadComponentArtifactEither.isRight()) {\r
1022                     responseFormat = downloadComponentArtifactEither.right().value();\r
1023                     responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
1024                 } else {\r
1025                     byte[] value = downloadComponentArtifactEither.left().value();\r
1026                     InputStream is = new ByteArrayInputStream(value);\r
1027                     Map<String, String> headers = new HashMap<>();\r
1028                     headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));\r
1029                     responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);\r
1030                     responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));\r
1031                 }\r
1032             }\r
1033         } catch (ComponentException e) {\r
1034             responseFormat = getComponentsUtils().getResponseFormat(e);\r
1035         } finally {\r
1036             getComponentsUtils().auditExternalDownloadArtifact(responseFormat, resourceCommonInfo,\r
1037                     new DistributionData(instanceIdHeader, requestURI), requestId, artifactUUID, userId);\r
1038         }\r
1039         return responseWrapper.getInnerElement();\r
1040     }\r
1041 \r
1042     /**\r
1043      * downloads an artifact of a resource instance of a component (either a service or a resource) by\r
1044      * artifactUUID\r
1045      *\r
1046      * @param assetType\r
1047      * @param uuid\r
1048      * @param resourceInstanceName\r
1049      * @param artifactUUID\r
1050      * @return\r
1051      */\r
1052     @GET\r
1053     @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")\r
1054     @Produces(MediaType.APPLICATION_OCTET_STREAM)\r
1055     @Operation(description = "Download resource instance artifact", method = "GET",\r
1056             summary = "Returns downloaded artifact", responses = @ApiResponse(\r
1057                     content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
1058     @ApiResponses(value = {\r
1059             @ApiResponse(responseCode = "200", description = "Artifact downloaded",\r
1060                     content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),\r
1061             @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),\r
1062             @ApiResponse(responseCode = "401",\r
1063                     description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),\r
1064             @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),\r
1065             @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),\r
1066             @ApiResponse(responseCode = "405",\r
1067                     description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),\r
1068             @ApiResponse(responseCode = "500",\r
1069                     description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),\r
1070             @ApiResponse(responseCode = "404", description = "Artifact was not found - SVC4505")})\r
1071     public Response downloadResourceInstanceArtifact(\r
1072             @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",\r
1073                     required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,\r
1074             @Parameter(description = "X-ECOMP-RequestID header",\r
1075                     required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,\r
1076             @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(\r
1077                     value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,\r
1078             @Parameter(description = "Determines the format of the body of the response",\r
1079                     required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,\r
1080             @Parameter(description = "The username and password",\r
1081                     required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,\r
1082             @Parameter(description = "The requested asset type",\r
1083                     required = true) @PathParam("assetType") final String assetType,\r
1084             @Parameter(description = "The uuid of the asset as published in the metadata",\r
1085                     required = true) @PathParam("uuid") final String uuid,\r
1086             @Parameter(\r
1087                     description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",\r
1088                     required = true) @PathParam("artifactUUID") final String artifactUUID,\r
1089             @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",\r
1090                     required = true) @PathParam("resourceInstanceName") final String resourceInstanceName) {\r
1091 \r
1092         Wrapper<Response> responseWrapper = new Wrapper<>();\r
1093         ResponseFormat responseFormat = null;\r
1094         String requestURI = request.getRequestURI();\r
1095         String url = request.getMethod() + " " + requestURI;\r
1096         log.debug("{} {}", startLog, url);\r
1097         ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);\r
1098         String componentTypeValue = componentType == null ? null : componentType.getValue();\r
1099         if (componentType == null) {\r
1100             log.debug("downloadResourceInstanceArtifact: assetType parameter {} is not valid", assetType);\r
1101             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);\r
1102             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
1103         }\r
1104         if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {\r
1105             log.debug("downloadResourceInstanceArtifact: Missing X-ECOMP-InstanceID header");\r
1106             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);\r
1107             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
1108         }\r
1109         try {\r
1110             if (responseWrapper.isEmpty()) {\r
1111                 Either<byte[], ResponseFormat> downloadResourceArtifactEither =\r
1112                         artifactsBusinessLogic.downloadResourceInstanceArtifactByUUIDs(componentType, uuid,\r
1113                                 resourceInstanceName, artifactUUID);\r
1114                 if (downloadResourceArtifactEither.isRight()) {\r
1115                     responseFormat = downloadResourceArtifactEither.right().value();\r
1116                     responseWrapper.setInnerElement(buildErrorResponse(responseFormat));\r
1117                 } else {\r
1118                     byte[] value = downloadResourceArtifactEither.left().value();\r
1119                     InputStream is = new ByteArrayInputStream(value);\r
1120                     Map<String, String> headers = new HashMap<>();\r
1121                     headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));\r
1122                     responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);\r
1123                     responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));\r
1124                 }\r
1125             }\r
1126         } catch (ComponentException e) {\r
1127             responseFormat = getComponentsUtils().getResponseFormat(e);\r
1128         } finally {\r
1129             getComponentsUtils().auditExternalDownloadArtifact(responseFormat,\r
1130                     new ResourceCommonInfo(resourceInstanceName, componentTypeValue),\r
1131                     new DistributionData(instanceIdHeader, requestURI), requestId, artifactUUID, userId);\r
1132         }\r
1133         return responseWrapper.getInnerElement();\r
1134     }\r
1135 }\r