2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.servlets;
23 import com.jcabi.aspects.Loggable;
24 import fj.data.Either;
25 import io.swagger.v3.oas.annotations.Operation;
26 import io.swagger.v3.oas.annotations.Parameter;
27 import io.swagger.v3.oas.annotations.media.ArraySchema;
28 import io.swagger.v3.oas.annotations.media.Content;
29 import io.swagger.v3.oas.annotations.media.Schema;
30 import io.swagger.v3.oas.annotations.responses.ApiResponse;
31 import io.swagger.v3.oas.annotations.servers.Server;
32 import io.swagger.v3.oas.annotations.servers.Servers;
33 import io.swagger.v3.oas.annotations.tags.Tag;
34 import io.swagger.v3.oas.annotations.tags.Tags;
35 import org.apache.commons.codec.binary.Base64;
36 import org.apache.commons.lang3.tuple.ImmutablePair;
37 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
38 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
39 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
40 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
41 import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
42 import org.openecomp.sdc.be.config.BeEcompErrorManager;
43 import org.openecomp.sdc.be.dao.api.ActionStatus;
44 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
45 import org.openecomp.sdc.be.impl.ComponentsUtils;
46 import org.openecomp.sdc.be.model.ArtifactDefinition;
47 import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
48 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
49 import org.openecomp.sdc.be.user.UserBusinessLogic;
50 import org.openecomp.sdc.common.api.Constants;
51 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
52 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
53 import org.openecomp.sdc.common.log.enums.StatusCode;
54 import org.openecomp.sdc.common.log.wrappers.Logger;
55 import org.openecomp.sdc.exception.ResponseFormat;
56 import org.springframework.stereotype.Controller;
58 import javax.inject.Inject;
59 import javax.servlet.http.HttpServletRequest;
60 import javax.ws.rs.Consumes;
61 import javax.ws.rs.DELETE;
62 import javax.ws.rs.GET;
63 import javax.ws.rs.HeaderParam;
64 import javax.ws.rs.POST;
65 import javax.ws.rs.Path;
66 import javax.ws.rs.PathParam;
67 import javax.ws.rs.Produces;
68 import javax.ws.rs.core.Context;
69 import javax.ws.rs.core.MediaType;
70 import javax.ws.rs.core.Response;
74 * Root resource (exposed at "/" path)
76 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
78 @Tags({@Tag(name = "SDC Internal APIs")})
79 @Servers({@Server(url = "/sdc2/rest")})
81 public class ArtifactServlet extends BeGenericServlet {
83 private final ArtifactsBusinessLogic artifactsBusinessLogic;
86 public ArtifactServlet(UserBusinessLogic userBusinessLogic,
87 ComponentsUtils componentsUtils, ArtifactsBusinessLogic artifactsBusinessLogic) {
88 super(userBusinessLogic, componentsUtils);
89 this.artifactsBusinessLogic = artifactsBusinessLogic;
92 private static final Logger log = Logger.getLogger(ArtifactServlet.class);
93 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ArtifactServlet.class.getName());
95 private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
96 private static final String DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64 = "downloadResourceInstanceArtifactBase64";
97 private static final String DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION = "downloadResourceInstanceArtifactBase64 unexpected exception";
99 // *************** Resources
101 @Path("/resources/{resourceId}/artifacts")
102 @Consumes(MediaType.APPLICATION_JSON)
103 @Produces(MediaType.APPLICATION_JSON)
104 @Operation(description = "Create Artifact", method = "POST", summary = "Returns created ArtifactDefinition",
105 responses = {@ApiResponse(
106 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
107 @ApiResponse(responseCode = "201", description = "Resource created"),
108 @ApiResponse(responseCode = "403", description = "Restricted operation"),
109 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
110 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
111 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
112 public Response loadArtifact(@PathParam("resourceId") final String resourceId,
113 @Parameter(description = "json describe the artifact", required = true) String data,
114 @Context final HttpServletRequest request) {
116 String url = request.getMethod() + " " + request.getRequestURI();
117 log.debug(START_HANDLE_REQUEST_OF, url);
118 return handleUploadRequest(data, request, resourceId, ComponentTypeEnum.RESOURCE);
122 @Path("/resources/{resourceId}/artifacts/{artifactId}")
123 @Consumes(MediaType.APPLICATION_JSON)
124 @Produces(MediaType.APPLICATION_JSON)
125 @Operation(description = "Update Artifact", method = "POST", summary = "Returns updated artifact", responses = {
126 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
127 @ApiResponse(responseCode = "201", description = "Resource created"),
128 @ApiResponse(responseCode = "403", description = "Restricted operation"),
129 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
130 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
131 public Response updateArtifact(@PathParam("resourceId") final String resourceId,
132 @PathParam("artifactId") final String artifactId,
133 @Parameter(description = "json describe the artifact", required = true) String data,
134 @Context final HttpServletRequest request) {
136 String url = request.getMethod() + " " + request.getRequestURI();
137 log.debug(START_HANDLE_REQUEST_OF, url);
139 return handleUpdateRequest(data, request, resourceId, artifactId, ComponentTypeEnum.RESOURCE);
140 } catch (Exception e) {
141 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifact");
142 log.debug("updateArtifact unexpected exception", e);
148 @Path("/resources/{resourceId}/artifacts/{artifactId}")
149 @Consumes(MediaType.APPLICATION_JSON)
150 @Produces(MediaType.APPLICATION_JSON)
151 @Operation(description = "Delete Artifact", method = "DELETE", summary = "Returns delete artifact", responses = {
152 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
153 @ApiResponse(responseCode = "201", description = "Resource created"),
154 @ApiResponse(responseCode = "403", description = "Restricted operation"),
155 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
156 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
157 public Response deleteArtifact(@PathParam("resourceId") final String resourceId,
158 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
160 String url = request.getMethod() + " " + request.getRequestURI();
161 log.debug(START_HANDLE_REQUEST_OF, url);
163 return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, null, null);
164 } catch (Exception e) {
165 log.debug("deleteArtifact unexpected exception", e);
170 // *************** Services
172 @Path("/services/{serviceId}/artifacts")
173 @Consumes(MediaType.APPLICATION_JSON)
174 @Produces(MediaType.APPLICATION_JSON)
175 @Operation(description = "Create Artifact", method = "POST", summary = "Returns created ArtifactDefinition",
176 responses = {@ApiResponse(
177 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
178 @ApiResponse(responseCode = "201", description = "Resource created"),
179 @ApiResponse(responseCode = "403", description = "Restricted operation"),
180 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
181 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
182 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
183 public Response loadInformationArtifact(@PathParam("serviceId") final String serviceId,
184 @Parameter(description = "json describe the artifact", required = true) String data,
185 @Context final HttpServletRequest request) {
187 String url = request.getMethod() + " " + request.getRequestURI();
188 log.debug(START_HANDLE_REQUEST_OF, url);
190 return handleUploadRequest(data, request, serviceId, ComponentTypeEnum.SERVICE);
191 } catch (Exception e) {
192 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadInformationArtifact");
193 log.debug("loadInformationArtifact unexpected exception", e);
199 @Path("/services/{serviceId}/artifacts/{artifactId}")
200 @Consumes(MediaType.APPLICATION_JSON)
201 @Produces(MediaType.APPLICATION_JSON)
202 @Operation(description = "Update Artifact", method = "POST", summary = "Returns updated artifact", responses = {
203 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
204 @ApiResponse(responseCode = "201", description = "Service artifact created"),
205 @ApiResponse(responseCode = "403", description = "Restricted operation"),
206 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
207 public Response updateInformationArtifact(@PathParam("serviceId") final String serviceId,
208 @PathParam("artifactId") final String artifactId,
209 @Parameter(description = "json describe the artifact", required = true) String data,
210 @Context final HttpServletRequest request) {
212 String url = request.getMethod() + " " + request.getRequestURI();
213 log.debug(START_HANDLE_REQUEST_OF, url);
215 return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
216 } catch (Exception e) {
217 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateInformationArtifact");
218 log.debug("updateInformationArtifact unexpected exception", e);
223 // *************** Services api artifacts
225 @Path("/services/{serviceId}/artifacts/api/{artifactId}")
226 @Consumes(MediaType.APPLICATION_JSON)
227 @Produces(MediaType.APPLICATION_JSON)
228 @Operation(description = "Update Api Artifact", method = "POST", summary = "Returns created ArtifactDefinition",
229 responses = {@ApiResponse(
230 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
231 @ApiResponse(responseCode = "200", description = "Api Artifact Updated"),
232 @ApiResponse(responseCode = "403", description = "Restricted operation"),
233 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
234 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
235 public Response updateApiArtifact(@PathParam("serviceId") final String serviceId,
236 @PathParam("artifactId") final String artifactId,
237 @Parameter(description = "json describe the artifact", required = true) String data,
238 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
239 @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
241 String url = request.getMethod() + " " + request.getRequestURI();
242 log.debug(START_HANDLE_REQUEST_OF, url);
244 return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
245 } catch (Exception e) {
246 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateApiArtifact");
247 log.debug("updateApiArtifact unexpected exception", e);
253 @Path("/services/{serviceId}/artifacts/api/{artifactId}")
254 @Consumes(MediaType.APPLICATION_JSON)
255 @Produces(MediaType.APPLICATION_JSON)
256 @Operation(description = "Delete Api Artifact", method = "DELETE", summary = "Returns Deleted ArtifactDefinition",
257 responses = {@ApiResponse(
258 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
259 @ApiResponse(responseCode = "204", description = "Api Artifact deleted"),
260 @ApiResponse(responseCode = "403", description = "Restricted operation")})
261 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
262 public Response deleteApiArtifact(@PathParam("serviceId") final String serviceId,
263 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request,
264 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
265 @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
267 String url = request.getMethod() + " " + request.getRequestURI();
268 log.debug(START_HANDLE_REQUEST_OF, url);
270 return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
271 } catch (Exception e) {
272 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteApiArtifact");
273 log.debug("deleteApiArtifact unexpected exception", e);
279 @Path("/services/{serviceId}/artifacts/{artifactId}")
280 @Consumes(MediaType.APPLICATION_JSON)
281 @Produces(MediaType.APPLICATION_JSON)
282 @Operation(description = "Delete Artifact", method = "DELETE", summary = "Returns delete artifact", responses = {
283 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
284 @ApiResponse(responseCode = "201", description = "Service artifact deleted"),
285 @ApiResponse(responseCode = "403", description = "Restricted operation"),
286 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
287 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
288 public Response deleteInformationalArtifact(@PathParam("serviceId") final String serviceId,
289 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
291 String url = request.getMethod() + " " + request.getRequestURI();
292 log.debug(START_HANDLE_REQUEST_OF, url);
294 return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
295 } catch (Exception e) {
296 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteInformationalArtifact");
297 log.debug("deleteInformationalArtifact unexpected exception", e);
303 * DOWNLOAD Artifacts by json body in base 64 (because of userId problem with href)
307 @Path("/services/{serviceId}/artifacts/{artifactId}")
308 @Consumes(MediaType.APPLICATION_JSON)
309 @Produces(MediaType.APPLICATION_JSON)
310 @Operation(description = "Download service Artifact in Base64", method = "GET",
311 summary = "Returns downloaded artifact", responses = {
312 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
313 @ApiResponse(responseCode = "200", description = "Service artifact downloaded"),
314 @ApiResponse(responseCode = "404", description = "Service/Artifact not found")})
315 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
316 public Response downloadServiceArtifactBase64(@PathParam("serviceId") final String serviceId,
317 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
319 String url = request.getMethod() + " " + request.getRequestURI();
321 log.debug(START_HANDLE_REQUEST_OF, url);
323 response = handleDownloadRequest(request, serviceId, artifactId, null, ComponentTypeEnum.SERVICE, null);
324 } catch (Exception e) {
325 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadServiceArtifactBase64");
326 log.debug("downloadServiceArtifactBase64 unexpected exception", e);
330 loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS,StatusCode.COMPLETE,"Ended download Service Artifact ");
336 @Path("/resources/{resourceId}/artifacts/{artifactId}")
337 @Consumes(MediaType.APPLICATION_JSON)
338 @Produces(MediaType.APPLICATION_JSON)
339 @Operation(description = "Download resource Artifact in Base64", method = "GET",
340 summary = "Returns downloaded artifact", responses = {
341 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
342 @ApiResponse(responseCode = "200", description = "Resource artifact downloaded"),
343 @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
344 public Response downloadResourceArtifactBase64(@PathParam("resourceId") final String resourceId,
345 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
347 String url = request.getMethod() + " " + request.getRequestURI();
348 log.debug(START_HANDLE_REQUEST_OF, url);
351 response = handleDownloadRequest(request, resourceId, artifactId, null, ComponentTypeEnum.RESOURCE, null);
352 } catch (Exception e) {
353 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceArtifactBase64");
354 log.debug("downloadResourceArtifactBase64 unexpected exception", e);
358 loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS,null, StatusCode.COMPLETE,"Ended download artifact {}", artifactId);
365 @Path("/{containerComponentType}/{componentId}/resourceInstances/{componentInstanceId}/artifacts/{artifactId}")
366 @Consumes(MediaType.APPLICATION_JSON)
367 @Produces(MediaType.APPLICATION_JSON)
368 @Operation(description = "Download component Artifact in Base64", method = "GET",
369 summary = "Returns downloaded artifact", responses = {
370 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
371 @ApiResponse(responseCode = "200", description = "ResourceInstance artifact downloaded"),
372 @ApiResponse(responseCode = "404", description = "ResourceInstance/Artifact not found")})
373 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
374 public Response downloadResourceInstanceArtifactBase64(@Parameter(
375 description = "valid values: resources / services",
376 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
377 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
378 @PathParam("componentId") final String componentId,
379 @PathParam("componentInstanceId") final String componentInstanceId,
380 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
383 String url = request.getMethod() + " " + request.getRequestURI();
384 log.debug(START_HANDLE_REQUEST_OF, url);
385 loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS, StatusCode.STARTED," Starting to download Resource Instance Artifact for component {} ", componentId);
387 response = handleDownloadRequest(request, componentInstanceId, artifactId, componentId, ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentType);
388 } catch (Exception e) {
389 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64);
390 log.debug(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION, e);
394 loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS, StatusCode.COMPLETE,"Ended download Resource Instance Artifact for component {} ", componentId);
399 // *************** Resource lifecycle ( interfces )
402 @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts")
403 @Consumes(MediaType.APPLICATION_JSON)
404 @Produces(MediaType.APPLICATION_JSON)
405 @Operation(description = "Create Artifact and Attach to interface", method = "POST",
406 summary = "Returns created resource", responses = {
407 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
408 @ApiResponse(responseCode = "201", description = "Resource created"),
409 @ApiResponse(responseCode = "403", description = "Restricted operation"),
410 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
411 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
412 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
413 public Response loadArtifactToInterface(@PathParam("resourceId") final String resourceId,
414 @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
415 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
416 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
417 @Parameter(description = "json describe the artifact", required = true) String data,
418 @Context final HttpServletRequest request) {
420 String url = request.getMethod() + " " + request.getRequestURI();
421 log.debug(START_HANDLE_REQUEST_OF, url);
423 return handleArtifactRequest(data, request, resourceId, interfaceType, operation, null, ComponentTypeEnum.RESOURCE, ArtifactOperationEnum.CREATE, null, null, false);
424 } catch (Exception e) {
425 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadArtifactToInterface");
426 log.debug("loadArtifactToInterface unexpected exception", e);
433 @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
434 @Consumes(MediaType.APPLICATION_JSON)
435 @Produces(MediaType.APPLICATION_JSON)
436 @Operation(description = "delete Artifact from interface", method = "delete",
437 summary = "delete matching artifact from interface", responses = {
438 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
439 @ApiResponse(responseCode = "201", description = "delete artifact under interface deleted"),
440 @ApiResponse(responseCode = "403", description = "Restricted operation"),
441 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
442 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
443 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
444 public Response deleteArtifactToInterface(@PathParam("resourceId") final String resourceId,
445 @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
446 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
448 String url = request.getMethod() + " " + request.getRequestURI();
449 log.debug(START_HANDLE_REQUEST_OF, url);
451 return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, interfaceType, operation);
452 } catch (Exception e) {
453 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteArtifactToInterface");
454 log.debug("deleteArtifactToInterface unexpected exception", e);
460 @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
461 @Consumes(MediaType.APPLICATION_JSON)
462 @Produces(MediaType.APPLICATION_JSON)
463 @Operation(description = "update Artifact Attach to interface", method = "post",
464 summary = "updates artifact by interface", responses = {
465 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
466 @ApiResponse(responseCode = "201", description = "delete artifact under interface deleted"),
467 @ApiResponse(responseCode = "403", description = "Restricted operation"),
468 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
469 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
470 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
471 public Response updateArtifactToInterface(@PathParam("resourceId") final String resourceId,
472 @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
473 @PathParam("artifactId") final String artifactId,
474 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
475 @HeaderParam(value = Constants.MD5_HEADER) String origMd5, @Context final HttpServletRequest request,
476 @Parameter(description = "json describe the artifact", required = true) String data) {
478 String url = request.getMethod() + " " + request.getRequestURI();
479 log.debug(START_HANDLE_REQUEST_OF, url);
481 return handleArtifactRequest(data, request, resourceId, interfaceType, operation, artifactId, ComponentTypeEnum.RESOURCE, ArtifactOperationEnum.UPDATE, null, null, false);
482 } catch (Exception e) {
483 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifactToInterface");
484 log.debug("updateArtifactToInterface unexpected exception", e);
490 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}/heatParams")
491 @Consumes(MediaType.APPLICATION_JSON)
492 @Produces(MediaType.APPLICATION_JSON)
493 @Operation(description = "Update Resource Instance HEAT_ENV parameters", method = "POST",
494 summary = "Returns updated artifact", responses = {
495 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
496 @ApiResponse(responseCode = "200", description = "Artifact updated"),
497 @ApiResponse(responseCode = "403", description = "Restricted operation"),
498 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
499 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
500 public Response updateRIArtifact(@Parameter(description = "valid values: resources / services",
501 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
502 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
503 @PathParam("componentId") final String componentId,
504 @PathParam("componentInstanceId") final String componentInstanceId,
505 @PathParam("artifactId") final String artifactId,
506 @Parameter(description = "json describe the artifact", required = true) String data,
507 @Context final HttpServletRequest request) {
509 String url = request.getMethod() + " " + request.getRequestURI();
510 log.debug(START_HANDLE_REQUEST_OF, url);
511 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_HEAT, StatusCode.STARTED,"Starting update RI Artifact {}" ,artifactId);
514 response = handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.UPDATE, componentId, containerComponentType, false);
515 } catch (Exception e) {
516 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateRIArtifact");
517 log.debug("updateRIArtifact unexpected exception", e);
521 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_HEAT, StatusCode.COMPLETE,"Ending update RI Artifact {}" , artifactId);
527 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
528 @Consumes(MediaType.APPLICATION_JSON)
529 @Produces(MediaType.APPLICATION_JSON)
530 @Operation(description = "Update Resource Instance artifact payload", method = "POST",
531 summary = "Returns updated artifact", responses = {
532 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
533 @ApiResponse(responseCode = "200", description = "Artifact updated"),
534 @ApiResponse(responseCode = "403", description = "Restricted operation"),
535 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
536 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
537 public Response updateComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
538 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
539 @Parameter(description = "valid values: resources / services",
540 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
541 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
542 @PathParam("componentId") final String componentId,
543 @PathParam("componentInstanceId") final String componentInstanceId,
544 @PathParam("artifactId") final String artifactId,
545 @Parameter(description = "json describe the artifact", required = true) String data,
546 @Context final HttpServletRequest request) {
548 String url = request.getMethod() + " " + request.getRequestURI();
549 log.debug(START_HANDLE_REQUEST_OF, url);
551 return handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.UPDATE, componentId, containerComponentType, true);
552 } catch (Exception e) {
553 log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
559 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts")
560 @Consumes(MediaType.APPLICATION_JSON)
561 @Produces(MediaType.APPLICATION_JSON)
562 @Operation(description = "Load Resource Instance artifact payload", method = "POST",
563 summary = "Returns updated artifact", responses = {
564 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
565 @ApiResponse(responseCode = "200", description = "Artifact updated"),
566 @ApiResponse(responseCode = "403", description = "Restricted operation"),
567 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
568 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
569 public Response loadComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
570 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
571 @Parameter(description = "valid values: resources / services",
572 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
573 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
574 @PathParam("componentId") final String componentId,
575 @PathParam("componentInstanceId") final String componentInstanceId,
576 @Parameter(description = "json describe the artifact", required = true) String data,
577 @Context final HttpServletRequest request) {
579 String url = request.getMethod() + " " + request.getRequestURI();
580 log.debug(START_HANDLE_REQUEST_OF, url);
582 return handleArtifactRequest(data, request, componentInstanceId, null, null, null, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.CREATE, componentId, containerComponentType, false);
583 } catch (Exception e) {
584 log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
590 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
591 @Consumes(MediaType.APPLICATION_JSON)
592 @Produces(MediaType.APPLICATION_JSON)
593 @Operation(description = "Delete Resource Instance artifact", method = "POST", summary = "Returns deleted artifact",
594 responses = {@ApiResponse(
595 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
596 @ApiResponse(responseCode = "200", description = "Artifact updated"),
597 @ApiResponse(responseCode = "403", description = "Restricted operation"),
598 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
599 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
600 public Response deleteComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
601 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
602 @Parameter(description = "valid values: resources / services",
603 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
604 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
605 @PathParam("componentId") final String componentId,
606 @PathParam("componentInstanceId") final String componentInstanceId,
607 @PathParam("artifactId") final String artifactId,
608 @Parameter(description = "json describe the artifact", required = true) String data,
609 @Context final HttpServletRequest request) {
611 String url = request.getMethod() + " " + request.getRequestURI();
612 log.debug(START_HANDLE_REQUEST_OF, url);
613 loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE_ARTIFACT,null, StatusCode.STARTED,"Starting delete component instance artifact {}" ,artifactId);
616 response = handleDeleteRequest(request, componentInstanceId, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, null, null, componentId);
617 } catch (Exception e) {
618 log.debug("deleteArtifact unexpected exception", e);
622 loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE_ARTIFACT,null, StatusCode.COMPLETE,"Ending delete component instance artifact {}" ,artifactId);
630 @Path("/{containerComponentType}/{componentId}/artifactsByType/{artifactGroupType}")
631 @Consumes(MediaType.APPLICATION_JSON)
632 @Produces(MediaType.APPLICATION_JSON)
633 @Operation(description = "Get component Artifacts", method = "GET", summary = "Returns artifacts", responses = {
634 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
635 @ApiResponse(responseCode = "200", description = "Component artifacts"),
636 @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
637 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
638 public Response getComponentArtifacts(@Parameter(description = "valid values: resources / services",
639 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
640 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
641 @PathParam("componentId") final String componentId,
642 @PathParam("artifactGroupType") final String artifactGroupType, @Context final HttpServletRequest request) {
644 String url = request.getMethod() + " " + request.getRequestURI();
645 log.debug(START_HANDLE_REQUEST_OF, url);
647 return handleGetArtifactsRequest(request, componentId, null, artifactGroupType, containerComponentType);
648 } catch (Exception e) {
649 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64);
650 log.debug(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION, e);
656 @Path("/{containerComponentType}/{componentId}/resourceInstances/{componentInstanceId}/artifactsByType/{artifactGroupType}")
657 @Consumes(MediaType.APPLICATION_JSON)
658 @Produces(MediaType.APPLICATION_JSON)
659 @Operation(description = "Get component Artifacts", method = "GET", summary = "Returns artifacts", responses = {
660 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
661 @ApiResponse(responseCode = "200", description = "Component artifacts"),
662 @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
663 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
664 public Response getComponentInstanceArtifacts(@Parameter(description = "valid values: resources / services",
665 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
666 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
667 @PathParam("componentId") final String componentId,
668 @PathParam("componentInstanceId") final String componentInstanceId,
669 @PathParam("artifactGroupType") final String artifactGroupType, @Context final HttpServletRequest request) {
671 String url = request.getMethod() + " " + request.getRequestURI();
672 log.debug(START_HANDLE_REQUEST_OF, url);
674 return handleGetArtifactsRequest(request, componentInstanceId, componentId, artifactGroupType, containerComponentType);
675 } catch (Exception e) {
676 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64);
677 log.debug(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION, e);
684 @Path("/{assetType}/{uuid}/interfaces/{interfaceUUID}/operations/{operationUUID}/artifacts/{artifactUUID}")
685 @Consumes(MediaType.APPLICATION_JSON)
686 @Produces(MediaType.APPLICATION_JSON)
687 @Operation(description = "uploads of artifact to component operation workflow", method = "POST",
688 summary = "uploads of artifact to component operation workflow", responses = {
689 @ApiResponse(responseCode = "200", description = "Artifact uploaded", content = @Content(
690 array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
691 @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
692 @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
693 @ApiResponse(responseCode = "400",
694 description = "Artifact type (mandatory field) is missing in request - SVC4124"),
695 @ApiResponse(responseCode = "400",
696 description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
697 @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
698 @ApiResponse(responseCode = "400",
699 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"),
700 @ApiResponse(responseCode = "400",
701 description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
702 public Response uploadInterfaceOperationArtifact(
703 @Parameter(description = "Asset type") @PathParam("assetType") String assetType,
704 @Parameter(description = "The uuid of the asset as published in the metadata", required = true)@PathParam("uuid") final String uuid,
705 @Parameter(description = "The uuid of the interface", required = true)@PathParam("interfaceUUID") final String interfaceUUID,
706 @Parameter(description = "The uuid of the operation", required = true)@PathParam("operationUUID") final String operationUUID,
707 @Parameter(description = "The uuid of the artifact", required = true)@PathParam("artifactUUID") final String artifactUUID,
708 @Parameter( hidden = true) String data,
709 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
710 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
711 @Context final HttpServletRequest request) {
713 String url = request.getMethod() + " " + request.getRequestURI();
714 log.debug("Start handle request of {}" , url);
717 Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
718 artifactsBusinessLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request,
719 ComponentTypeEnum.findByParamName(assetType), uuid, interfaceUUID, operationUUID, artifactUUID,
720 new ResourceCommonInfo(assetType), new ArtifactOperationInfo(true,
721 false, ArtifactOperationEnum.UPDATE));
722 if (uploadArtifactEither.isRight()) {
723 log.debug("failed to update artifact");
724 return buildErrorResponse(uploadArtifactEither.right().value());
726 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), uploadArtifactEither.left().value());
728 catch (Exception e) {
729 final String message = "failed to update artifact on a resource or service";
730 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
731 log.debug(message, e);
732 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
736 // ////////// API END ///////////////////////////
738 // ************ private *********************
740 private Response handleUploadRequest(String data, HttpServletRequest request, String componentId, ComponentTypeEnum componentType) {
741 return handleArtifactRequest(data, componentId, null, componentType, ArtifactOperationEnum.CREATE);
744 private Response handleUpdateRequest(String data, HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType) {
745 return handleArtifactRequest(data, componentId, artifactId, componentType, ArtifactOperationEnum.UPDATE);
748 private Response handleDownloadRequest(HttpServletRequest request, String componentId, String artifactId, String parentId, ComponentTypeEnum componentType, String containerComponentType) {
749 String userId = request.getHeader(Constants.USER_ID_HEADER);
750 ImmutablePair<String, byte[]> actionResult = artifactsBusinessLogic.handleDownloadRequestById(componentId, artifactId, userId, componentType, parentId, containerComponentType);
753 byte[] file = actionResult.getRight();
754 String base64Contents = new String(Base64.encodeBase64(file));
755 String artifactName = actionResult.getLeft();
756 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
757 ArtifactUiDownloadData artifactUiDownloadData = new ArtifactUiDownloadData();
758 artifactUiDownloadData.setArtifactName(artifactName);
759 artifactUiDownloadData.setBase64Contents(base64Contents);
760 response = buildOkResponse(responseFormat, artifactUiDownloadData);
764 private Response handleGetArtifactsRequest(HttpServletRequest request, String componentId, String parentId, String artifactGroupType, String containerComponentType) {
765 String userId = request.getHeader(Constants.USER_ID_HEADER);
766 ComponentTypeEnum componentTypeEnum = parentId == null || parentId.isEmpty() ? ComponentTypeEnum.findByParamName(containerComponentType) : ComponentTypeEnum.RESOURCE_INSTANCE;
767 Map<String, ArtifactDefinition> actionResult = artifactsBusinessLogic.handleGetArtifactsByType(containerComponentType, parentId, componentTypeEnum, componentId, artifactGroupType, userId);
769 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResult);
773 private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName) {
774 return handleDeleteRequest(request, componentId, artifactId, componentType, interfaceType, operationName, null);
777 private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName, String parentId) {
778 String userId = request.getHeader(Constants.USER_ID_HEADER);
779 Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> actionResult = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType, new ArtifactOperationInfo(false, false, ArtifactOperationEnum.DELETE), artifactId, null, null, null, interfaceType, operationName,
783 Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> result = actionResult;
784 if (result.isLeft()) {
785 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
787 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
793 private Response handleArtifactRequest(String data, HttpServletRequest request, String componentId, String interfaceName, String operationName, String artifactId, ComponentTypeEnum componentType, ArtifactOperationEnum operationEnum, String parentId,
794 String containerComponentType, boolean validateTimeout) {
795 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_ARTIFACT, StatusCode.STARTED,"Starting to update artifact {} " ,artifactId + " for component " + componentId);
796 ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class, validateTimeout);
797 String origMd5 = request.getHeader(Constants.MD5_HEADER);
799 String userId = request.getHeader(Constants.USER_ID_HEADER);
801 Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> result = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType,
802 new ArtifactOperationInfo(false, false, operationEnum), artifactId, artifactInfo, origMd5, data, interfaceName, operationName, parentId,
803 containerComponentType);
805 if (result.isLeft()) {
806 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
808 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
811 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_ARTIFACT, StatusCode.COMPLETE,"Ended update artifact {} " ,artifactId + " for component " + componentId);
816 private Response handleArtifactRequest(String data, String componentId, String artifactId, ComponentTypeEnum componentType, ArtifactOperationEnum operation) {
817 return handleArtifactRequest(data, servletRequest, componentId, null, null, artifactId, componentType, operation, null, null, false);