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.OpenAPIDefinition;
26 import io.swagger.v3.oas.annotations.Operation;
27 import io.swagger.v3.oas.annotations.Parameter;
28 import io.swagger.v3.oas.annotations.info.Info;
29 import io.swagger.v3.oas.annotations.media.ArraySchema;
30 import io.swagger.v3.oas.annotations.media.Content;
31 import io.swagger.v3.oas.annotations.media.Schema;
32 import io.swagger.v3.oas.annotations.responses.ApiResponse;
33 import io.swagger.v3.oas.annotations.responses.ApiResponses;
34 import org.apache.commons.codec.binary.Base64;
35 import org.apache.commons.lang3.tuple.ImmutablePair;
36 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
37 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
38 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
39 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
40 import org.openecomp.sdc.be.config.BeEcompErrorManager;
41 import org.openecomp.sdc.be.dao.api.ActionStatus;
42 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
43 import org.openecomp.sdc.be.impl.ComponentsUtils;
44 import org.openecomp.sdc.be.model.ArtifactDefinition;
45 import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
46 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
47 import org.openecomp.sdc.be.user.UserBusinessLogic;
48 import org.openecomp.sdc.common.api.Constants;
49 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
50 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
51 import org.openecomp.sdc.common.log.enums.StatusCode;
52 import org.openecomp.sdc.common.log.wrappers.Logger;
53 import org.openecomp.sdc.exception.ResponseFormat;
54 import org.springframework.stereotype.Controller;
56 import javax.inject.Inject;
57 import javax.servlet.http.HttpServletRequest;
58 import javax.ws.rs.Consumes;
59 import javax.ws.rs.DELETE;
60 import javax.ws.rs.GET;
61 import javax.ws.rs.HeaderParam;
62 import javax.ws.rs.POST;
63 import javax.ws.rs.Path;
64 import javax.ws.rs.PathParam;
65 import javax.ws.rs.Produces;
66 import javax.ws.rs.core.Context;
67 import javax.ws.rs.core.MediaType;
68 import javax.ws.rs.core.Response;
72 * Root resource (exposed at "/" path)
74 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
76 @OpenAPIDefinition(info = @Info(title = "Resource Artifact Servlet", description = "Resource Artifact Servlet"))
78 public class ArtifactServlet extends BeGenericServlet {
80 private final ArtifactsBusinessLogic artifactsBusinessLogic;
83 public ArtifactServlet(UserBusinessLogic userBusinessLogic,
84 ComponentsUtils componentsUtils, ArtifactsBusinessLogic artifactsBusinessLogic) {
85 super(userBusinessLogic, componentsUtils);
86 this.artifactsBusinessLogic = artifactsBusinessLogic;
89 private static final Logger log = Logger.getLogger(ArtifactServlet.class);
90 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ArtifactServlet.class.getName());
92 private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
93 private static final String DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64 = "downloadResourceInstanceArtifactBase64";
94 private static final String DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION = "downloadResourceInstanceArtifactBase64 unexpected exception";
96 // *************** Resources
98 @Path("/resources/{resourceId}/artifacts")
99 @Consumes(MediaType.APPLICATION_JSON)
100 @Produces(MediaType.APPLICATION_JSON)
101 @Operation(description = "Create Artifact", method = "POST", summary = "Returns created ArtifactDefinition",
102 responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
103 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
104 @ApiResponse(responseCode = "403", description = "Restricted operation"),
105 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
106 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
107 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
108 public Response loadArtifact(@PathParam("resourceId") final String resourceId,
109 @Parameter(description = "json describe the artifact", required = true) String data,
110 @Context final HttpServletRequest request) {
112 String url = request.getMethod() + " " + request.getRequestURI();
113 log.debug(START_HANDLE_REQUEST_OF, url);
114 return handleUploadRequest(data, request, resourceId, ComponentTypeEnum.RESOURCE);
118 @Path("/resources/{resourceId}/artifacts/{artifactId}")
119 @Consumes(MediaType.APPLICATION_JSON)
120 @Produces(MediaType.APPLICATION_JSON)
121 @Operation(description = "Update Artifact", method = "POST", summary = "Returns updated artifact",
122 responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
123 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
124 @ApiResponse(responseCode = "403", description = "Restricted operation"),
125 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
126 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
127 public Response updateArtifact(@PathParam("resourceId") final String resourceId,
128 @PathParam("artifactId") final String artifactId,
129 @Parameter(description = "json describe the artifact", required = true) String data,
130 @Context final HttpServletRequest request) {
132 String url = request.getMethod() + " " + request.getRequestURI();
133 log.debug(START_HANDLE_REQUEST_OF, url);
135 return handleUpdateRequest(data, request, resourceId, artifactId, ComponentTypeEnum.RESOURCE);
136 } catch (Exception e) {
137 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifact");
138 log.debug("updateArtifact unexpected exception", e);
144 @Path("/resources/{resourceId}/artifacts/{artifactId}")
145 @Consumes(MediaType.APPLICATION_JSON)
146 @Produces(MediaType.APPLICATION_JSON)
147 @Operation(description = "Delete Artifact", method = "DELETE",
148 summary = "Returns delete artifact", responses = @ApiResponse(
149 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
150 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
151 @ApiResponse(responseCode = "403", description = "Restricted operation"),
152 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
153 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
154 public Response deleteArtifact(@PathParam("resourceId") final String resourceId,
155 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
157 String url = request.getMethod() + " " + request.getRequestURI();
158 log.debug(START_HANDLE_REQUEST_OF, url);
160 return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, null, null);
161 } catch (Exception e) {
162 log.debug("deleteArtifact unexpected exception", e);
167 // *************** Services
169 @Path("/services/{serviceId}/artifacts")
170 @Consumes(MediaType.APPLICATION_JSON)
171 @Produces(MediaType.APPLICATION_JSON)
172 @Operation(description = "Create Artifact", method = "POST",
173 summary = "Returns created ArtifactDefinition", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
174 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
175 @ApiResponse(responseCode = "403", description = "Restricted operation"),
176 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
177 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
178 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
179 public Response loadInformationArtifact(@PathParam("serviceId") final String serviceId,
180 @Parameter(description = "json describe the artifact", required = true) String data,
181 @Context final HttpServletRequest request) {
183 String url = request.getMethod() + " " + request.getRequestURI();
184 log.debug(START_HANDLE_REQUEST_OF, url);
186 return handleUploadRequest(data, request, serviceId, ComponentTypeEnum.SERVICE);
187 } catch (Exception e) {
188 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadInformationArtifact");
189 log.debug("loadInformationArtifact unexpected exception", e);
195 @Path("/services/{serviceId}/artifacts/{artifactId}")
196 @Consumes(MediaType.APPLICATION_JSON)
197 @Produces(MediaType.APPLICATION_JSON)
198 @Operation(description = "Update Artifact", method = "POST",
199 summary = "Returns updated artifact", responses = @ApiResponse(
200 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
201 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service artifact created"),
202 @ApiResponse(responseCode = "403", description = "Restricted operation"),
203 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
204 public Response updateInformationArtifact(@PathParam("serviceId") final String serviceId,
205 @PathParam("artifactId") final String artifactId,
206 @Parameter(description = "json describe the artifact", required = true) String data,
207 @Context final HttpServletRequest request) {
209 String url = request.getMethod() + " " + request.getRequestURI();
210 log.debug(START_HANDLE_REQUEST_OF, url);
212 return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
213 } catch (Exception e) {
214 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateInformationArtifact");
215 log.debug("updateInformationArtifact unexpected exception", e);
220 // *************** Services api artifacts
222 @Path("/services/{serviceId}/artifacts/api/{artifactId}")
223 @Consumes(MediaType.APPLICATION_JSON)
224 @Produces(MediaType.APPLICATION_JSON)
225 @Operation(description = "Update Api Artifact", method = "POST",
226 summary = "Returns created ArtifactDefinition", responses = @ApiResponse(
227 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
228 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Api Artifact Updated"),
229 @ApiResponse(responseCode = "403", description = "Restricted operation"),
230 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
231 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
232 public Response updateApiArtifact(@PathParam("serviceId") final String serviceId,
233 @PathParam("artifactId") final String artifactId,
234 @Parameter(description = "json describe the artifact", required = true) String data,
235 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
236 @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
238 String url = request.getMethod() + " " + request.getRequestURI();
239 log.debug(START_HANDLE_REQUEST_OF, url);
241 return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
242 } catch (Exception e) {
243 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateApiArtifact");
244 log.debug("updateApiArtifact unexpected exception", e);
250 @Path("/services/{serviceId}/artifacts/api/{artifactId}")
251 @Consumes(MediaType.APPLICATION_JSON)
252 @Produces(MediaType.APPLICATION_JSON)
253 @Operation(description = "Delete Api Artifact", method = "DELETE",
254 summary = "Returns Deleted ArtifactDefinition", responses = @ApiResponse(
255 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
256 @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Api Artifact deleted"),
257 @ApiResponse(responseCode = "403", description = "Restricted operation")})
258 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
259 public Response deleteApiArtifact(@PathParam("serviceId") final String serviceId,
260 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request,
261 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
262 @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
264 String url = request.getMethod() + " " + request.getRequestURI();
265 log.debug(START_HANDLE_REQUEST_OF, url);
267 return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
268 } catch (Exception e) {
269 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteApiArtifact");
270 log.debug("deleteApiArtifact unexpected exception", e);
276 @Path("/services/{serviceId}/artifacts/{artifactId}")
277 @Consumes(MediaType.APPLICATION_JSON)
278 @Produces(MediaType.APPLICATION_JSON)
279 @Operation(description = "Delete Artifact", method = "DELETE",
280 summary = "Returns delete artifact", responses = @ApiResponse(
281 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
282 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service artifact deleted"),
283 @ApiResponse(responseCode = "403", description = "Restricted operation"),
284 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
285 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
286 public Response deleteInformationalArtifact(@PathParam("serviceId") final String serviceId,
287 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
289 String url = request.getMethod() + " " + request.getRequestURI();
290 log.debug(START_HANDLE_REQUEST_OF, url);
292 return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
293 } catch (Exception e) {
294 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteInformationalArtifact");
295 log.debug("deleteInformationalArtifact unexpected exception", e);
301 * DOWNLOAD Artifacts by json body in base 64 (because of userId problem with href)
305 @Path("/services/{serviceId}/artifacts/{artifactId}")
306 @Consumes(MediaType.APPLICATION_JSON)
307 @Produces(MediaType.APPLICATION_JSON)
308 @Operation(description = "Download service Artifact in Base64", method = "GET",
309 summary = "Returns downloaded artifact", responses = @ApiResponse(
310 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
311 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service artifact downloaded"),
312 @ApiResponse(responseCode = "404", description = "Service/Artifact not found")})
313 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
314 public Response downloadServiceArtifactBase64(@PathParam("serviceId") final String serviceId,
315 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
317 String url = request.getMethod() + " " + request.getRequestURI();
319 log.debug(START_HANDLE_REQUEST_OF, url);
321 response = handleDownloadRequest(request, serviceId, artifactId, null, ComponentTypeEnum.SERVICE, null);
322 } catch (Exception e) {
323 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadServiceArtifactBase64");
324 log.debug("downloadServiceArtifactBase64 unexpected exception", e);
328 loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS,StatusCode.COMPLETE,"Ended download Service Artifact ");
334 @Path("/resources/{resourceId}/artifacts/{artifactId}")
335 @Consumes(MediaType.APPLICATION_JSON)
336 @Produces(MediaType.APPLICATION_JSON)
337 @Operation(description = "Download resource Artifact in Base64", method = "GET",
338 summary = "Returns downloaded artifact", responses = @ApiResponse(
339 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
340 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource artifact downloaded"),
341 @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
342 public Response downloadResourceArtifactBase64(@PathParam("resourceId") final String resourceId,
343 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
345 String url = request.getMethod() + " " + request.getRequestURI();
346 log.debug(START_HANDLE_REQUEST_OF, url);
349 response = handleDownloadRequest(request, resourceId, artifactId, null, ComponentTypeEnum.RESOURCE, null);
350 } catch (Exception e) {
351 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceArtifactBase64");
352 log.debug("downloadResourceArtifactBase64 unexpected exception", e);
356 loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS,null, StatusCode.COMPLETE,"Ended download artifact {}", artifactId);
363 @Path("/{containerComponentType}/{componentId}/resourceInstances/{componentInstanceId}/artifacts/{artifactId}")
364 @Consumes(MediaType.APPLICATION_JSON)
365 @Produces(MediaType.APPLICATION_JSON)
366 @Operation(description = "Download component Artifact in Base64", method = "GET",
367 summary = "Returns downloaded artifact", responses = @ApiResponse(
368 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
369 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "ResourceInstance artifact downloaded"),
370 @ApiResponse(responseCode = "404", description = "ResourceInstance/Artifact not found")})
371 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
372 public Response downloadResourceInstanceArtifactBase64(@Parameter(
373 description = "valid values: resources / services",
374 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
375 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
376 @PathParam("componentId") final String componentId,
377 @PathParam("componentInstanceId") final String componentInstanceId,
378 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
381 String url = request.getMethod() + " " + request.getRequestURI();
382 log.debug(START_HANDLE_REQUEST_OF, url);
383 loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS, StatusCode.STARTED," Starting to download Resource Instance Artifact for component {} ", componentId);
385 response = handleDownloadRequest(request, componentInstanceId, artifactId, componentId, ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentType);
386 } catch (Exception e) {
387 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64);
388 log.debug(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION, e);
392 loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS, StatusCode.COMPLETE,"Ended download Resource Instance Artifact for component {} ", componentId);
397 // *************** Resource lifecycle ( interfces )
400 @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts")
401 @Consumes(MediaType.APPLICATION_JSON)
402 @Produces(MediaType.APPLICATION_JSON)
403 @Operation(description = "Create Artifact and Attach to interface", method = "POST",
404 summary = "Returns created resource", responses = @ApiResponse(
405 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
406 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
407 @ApiResponse(responseCode = "403", description = "Restricted operation"),
408 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
409 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
410 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
411 public Response loadArtifactToInterface(@PathParam("resourceId") final String resourceId,
412 @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
413 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
414 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
415 @Parameter(description = "json describe the artifact", required = true) String data,
416 @Context final HttpServletRequest request) {
418 String url = request.getMethod() + " " + request.getRequestURI();
419 log.debug(START_HANDLE_REQUEST_OF, url);
421 return handleArtifactRequest(data, request, resourceId, interfaceType, operation, null, ComponentTypeEnum.RESOURCE, ArtifactOperationEnum.CREATE, null, null, false);
422 } catch (Exception e) {
423 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadArtifactToInterface");
424 log.debug("loadArtifactToInterface unexpected exception", e);
431 @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
432 @Consumes(MediaType.APPLICATION_JSON)
433 @Produces(MediaType.APPLICATION_JSON)
434 @Operation(description = "delete Artifact from interface", method = "delete",
435 summary = "delete matching artifact from interface", responses = @ApiResponse(
436 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
437 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "delete artifact under interface deleted"),
438 @ApiResponse(responseCode = "403", description = "Restricted operation"),
439 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
440 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
441 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
442 public Response deleteArtifactToInterface(@PathParam("resourceId") final String resourceId,
443 @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
444 @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
446 String url = request.getMethod() + " " + request.getRequestURI();
447 log.debug(START_HANDLE_REQUEST_OF, url);
449 return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, interfaceType, operation);
450 } catch (Exception e) {
451 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteArtifactToInterface");
452 log.debug("deleteArtifactToInterface unexpected exception", e);
458 @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
459 @Consumes(MediaType.APPLICATION_JSON)
460 @Produces(MediaType.APPLICATION_JSON)
461 @Operation(description = "update Artifact Attach to interface", method = "post",
462 summary = "updates artifact by interface", responses = @ApiResponse(
463 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
464 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "delete artifact under interface deleted"),
465 @ApiResponse(responseCode = "403", description = "Restricted operation"),
466 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
467 @ApiResponse(responseCode = "409", description = "Artifact already exist")})
468 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
469 public Response updateArtifactToInterface(@PathParam("resourceId") final String resourceId,
470 @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
471 @PathParam("artifactId") final String artifactId,
472 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
473 @HeaderParam(value = Constants.MD5_HEADER) String origMd5, @Context final HttpServletRequest request,
474 @Parameter(description = "json describe the artifact", required = true) String data) {
476 String url = request.getMethod() + " " + request.getRequestURI();
477 log.debug(START_HANDLE_REQUEST_OF, url);
479 return handleArtifactRequest(data, request, resourceId, interfaceType, operation, artifactId, ComponentTypeEnum.RESOURCE, ArtifactOperationEnum.UPDATE, null, null, false);
480 } catch (Exception e) {
481 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifactToInterface");
482 log.debug("updateArtifactToInterface unexpected exception", e);
488 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}/heatParams")
489 @Consumes(MediaType.APPLICATION_JSON)
490 @Produces(MediaType.APPLICATION_JSON)
491 @Operation(description = "Update Resource Instance HEAT_ENV parameters",
492 method = "POST", summary = "Returns updated artifact", responses = @ApiResponse(
493 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
494 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
495 @ApiResponse(responseCode = "403", description = "Restricted operation"),
496 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
497 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
498 public Response updateRIArtifact(@Parameter(description = "valid values: resources / services",
499 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
500 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
501 @PathParam("componentId") final String componentId,
502 @PathParam("componentInstanceId") final String componentInstanceId,
503 @PathParam("artifactId") final String artifactId,
504 @Parameter(description = "json describe the artifact", required = true) String data,
505 @Context final HttpServletRequest request) {
507 String url = request.getMethod() + " " + request.getRequestURI();
508 log.debug(START_HANDLE_REQUEST_OF, url);
509 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_HEAT, StatusCode.STARTED,"Starting update RI Artifact {}" ,artifactId);
512 response = handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.UPDATE, componentId, containerComponentType, false);
513 } catch (Exception e) {
514 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateRIArtifact");
515 log.debug("updateRIArtifact unexpected exception", e);
519 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_HEAT, StatusCode.COMPLETE,"Ending update RI Artifact {}" , artifactId);
525 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
526 @Consumes(MediaType.APPLICATION_JSON)
527 @Produces(MediaType.APPLICATION_JSON)
528 @Operation(description = "Update Resource Instance artifact payload", method = "POST",
529 summary = "Returns updated artifact", responses = @ApiResponse(
530 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
531 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
532 @ApiResponse(responseCode = "403", description = "Restricted operation"),
533 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
534 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
535 public Response updateComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
536 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
537 @Parameter(description = "valid values: resources / services",
538 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
539 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
540 @PathParam("componentId") final String componentId,
541 @PathParam("componentInstanceId") final String componentInstanceId,
542 @PathParam("artifactId") final String artifactId,
543 @Parameter(description = "json describe the artifact", required = true) String data,
544 @Context final HttpServletRequest request) {
546 String url = request.getMethod() + " " + request.getRequestURI();
547 log.debug(START_HANDLE_REQUEST_OF, url);
549 return handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.UPDATE, componentId, containerComponentType, true);
550 } catch (Exception e) {
551 log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
557 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts")
558 @Consumes(MediaType.APPLICATION_JSON)
559 @Produces(MediaType.APPLICATION_JSON)
560 @Operation(description = "Load Resource Instance artifact payload", method = "POST",
561 summary = "Returns updated artifact", responses = @ApiResponse(
562 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
563 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
564 @ApiResponse(responseCode = "403", description = "Restricted operation"),
565 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
566 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
567 public Response loadComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
568 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
569 @Parameter(description = "valid values: resources / services",
570 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
571 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
572 @PathParam("componentId") final String componentId,
573 @PathParam("componentInstanceId") final String componentInstanceId,
574 @Parameter(description = "json describe the artifact", required = true) String data,
575 @Context final HttpServletRequest request) {
577 String url = request.getMethod() + " " + request.getRequestURI();
578 log.debug(START_HANDLE_REQUEST_OF, url);
580 return handleArtifactRequest(data, request, componentInstanceId, null, null, null, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.CREATE, componentId, containerComponentType, false);
581 } catch (Exception e) {
582 log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
588 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
589 @Consumes(MediaType.APPLICATION_JSON)
590 @Produces(MediaType.APPLICATION_JSON)
591 @Operation(description = "Delete Resource Instance artifact", method = "POST",
592 summary = "Returns deleted artifact", responses = @ApiResponse(
593 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
594 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
595 @ApiResponse(responseCode = "403", description = "Restricted operation"),
596 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
597 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
598 public Response deleteComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
599 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
600 @Parameter(description = "valid values: resources / services",
601 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
602 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
603 @PathParam("componentId") final String componentId,
604 @PathParam("componentInstanceId") final String componentInstanceId,
605 @PathParam("artifactId") final String artifactId,
606 @Parameter(description = "json describe the artifact", required = true) String data,
607 @Context final HttpServletRequest request) {
609 String url = request.getMethod() + " " + request.getRequestURI();
610 log.debug(START_HANDLE_REQUEST_OF, url);
611 loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE_ARTIFACT,null, StatusCode.STARTED,"Starting delete component instance artifact {}" ,artifactId);
614 response = handleDeleteRequest(request, componentInstanceId, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, null, null, componentId);
615 } catch (Exception e) {
616 log.debug("deleteArtifact unexpected exception", e);
620 loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE_ARTIFACT,null, StatusCode.COMPLETE,"Ending delete component instance artifact {}" ,artifactId);
628 @Path("/{containerComponentType}/{componentId}/artifactsByType/{artifactGroupType}")
629 @Consumes(MediaType.APPLICATION_JSON)
630 @Produces(MediaType.APPLICATION_JSON)
631 @Operation(description = "Get component Artifacts", method = "GET",
632 summary = "Returns artifacts", responses = @ApiResponse(
633 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
634 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component artifacts"),
635 @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
636 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
637 public Response getComponentArtifacts(@Parameter(description = "valid values: resources / services",
638 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
639 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
640 @PathParam("componentId") final String componentId,
641 @PathParam("artifactGroupType") final String artifactGroupType, @Context final HttpServletRequest request) {
643 String url = request.getMethod() + " " + request.getRequestURI();
644 log.debug(START_HANDLE_REQUEST_OF, url);
646 return handleGetArtifactsRequest(request, componentId, null, artifactGroupType, containerComponentType);
647 } catch (Exception e) {
648 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64);
649 log.debug(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION, e);
655 @Path("/{containerComponentType}/{componentId}/resourceInstances/{componentInstanceId}/artifactsByType/{artifactGroupType}")
656 @Consumes(MediaType.APPLICATION_JSON)
657 @Produces(MediaType.APPLICATION_JSON)
658 @Operation(description = "Get component Artifacts", method = "GET",
659 summary = "Returns artifacts", responses = @ApiResponse(
660 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
661 @ApiResponses(value = {@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", summary = "uploads of artifact to component operation workflow")
688 @ApiResponses(value = {
689 @ApiResponse(responseCode = "200", description = "Artifact uploaded",content = @Content(array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
690 @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
691 @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
692 @ApiResponse(responseCode = "400", description = "Artifact type (mandatory field) is missing in request - SVC4124"),
693 @ApiResponse(responseCode = "400", description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
694 @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
695 @ApiResponse(responseCode = "400", 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"),
696 @ApiResponse(responseCode = "400", description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
697 //@ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the artifact")})
698 public Response uploadInterfaceOperationArtifact(
699 @Parameter(description = "Asset type") @PathParam("assetType") String assetType,
700 @Parameter(description = "The uuid of the asset as published in the metadata", required = true)@PathParam("uuid") final String uuid,
701 @Parameter(description = "The uuid of the interface", required = true)@PathParam("interfaceUUID") final String interfaceUUID,
702 @Parameter(description = "The uuid of the operation", required = true)@PathParam("operationUUID") final String operationUUID,
703 @Parameter(description = "The uuid of the artifact", required = true)@PathParam("artifactUUID") final String artifactUUID,
704 @Parameter( hidden = true) String data,
705 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
706 @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
707 @Context final HttpServletRequest request) {
709 String url = request.getMethod() + " " + request.getRequestURI();
710 log.debug("Start handle request of {}" , url);
713 Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
714 artifactsBusinessLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request,
715 ComponentTypeEnum.findByParamName(assetType), uuid, interfaceUUID, operationUUID, artifactUUID,
716 new ResourceCommonInfo(assetType), artifactsBusinessLogic.new ArtifactOperationInfo(true,
717 false, ArtifactOperationEnum.UPDATE));
718 if (uploadArtifactEither.isRight()) {
719 log.debug("failed to update artifact");
720 return buildErrorResponse(uploadArtifactEither.right().value());
722 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), uploadArtifactEither.left().value());
724 catch (Exception e) {
725 final String message = "failed to update artifact on a resource or service";
726 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
727 log.debug(message, e);
728 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
732 // ////////// API END ///////////////////////////
734 // ************ private *********************
736 private Response handleUploadRequest(String data, HttpServletRequest request, String componentId, ComponentTypeEnum componentType) {
737 return handleArtifactRequest(data, componentId, null, componentType, ArtifactOperationEnum.CREATE);
740 private Response handleUpdateRequest(String data, HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType) {
741 return handleArtifactRequest(data, componentId, artifactId, componentType, ArtifactOperationEnum.UPDATE);
744 private Response handleDownloadRequest(HttpServletRequest request, String componentId, String artifactId, String parentId, ComponentTypeEnum componentType, String containerComponentType) {
745 String userId = request.getHeader(Constants.USER_ID_HEADER);
746 ImmutablePair<String, byte[]> actionResult = artifactsBusinessLogic.handleDownloadRequestById(componentId, artifactId, userId, componentType, parentId, containerComponentType);
749 byte[] file = actionResult.getRight();
750 String base64Contents = new String(Base64.encodeBase64(file));
751 String artifactName = actionResult.getLeft();
752 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
753 ArtifactUiDownloadData artifactUiDownloadData = new ArtifactUiDownloadData();
754 artifactUiDownloadData.setArtifactName(artifactName);
755 artifactUiDownloadData.setBase64Contents(base64Contents);
756 response = buildOkResponse(responseFormat, artifactUiDownloadData);
760 private Response handleGetArtifactsRequest(HttpServletRequest request, String componentId, String parentId, String artifactGroupType, String containerComponentType) {
761 String userId = request.getHeader(Constants.USER_ID_HEADER);
762 ComponentTypeEnum componentTypeEnum = parentId == null || parentId.isEmpty() ? ComponentTypeEnum.findByParamName(containerComponentType) : ComponentTypeEnum.RESOURCE_INSTANCE;
763 Map<String, ArtifactDefinition> actionResult = artifactsBusinessLogic.handleGetArtifactsByType(containerComponentType, parentId, componentTypeEnum, componentId, artifactGroupType, userId);
765 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResult);
769 private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName) {
770 return handleDeleteRequest(request, componentId, artifactId, componentType, interfaceType, operationName, null);
773 private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName, String parentId) {
774 String userId = request.getHeader(Constants.USER_ID_HEADER);
775 Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> actionResult = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.DELETE), artifactId, null, null, null, interfaceType, operationName,
779 Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> result = actionResult;
780 if (result.isLeft()) {
781 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
783 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
789 private Response handleArtifactRequest(String data, HttpServletRequest request, String componentId, String interfaceName, String operationName, String artifactId, ComponentTypeEnum componentType, ArtifactOperationEnum operationEnum, String parentId,
790 String containerComponentType, boolean validateTimeout) {
791 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_ARTIFACT, StatusCode.STARTED,"Starting to update artifact {} " ,artifactId + " for component " + componentId);
792 ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class, validateTimeout);
793 String origMd5 = request.getHeader(Constants.MD5_HEADER);
795 String userId = request.getHeader(Constants.USER_ID_HEADER);
797 Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> result = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType,
798 artifactsBusinessLogic.new ArtifactOperationInfo(false, false, operationEnum), artifactId, artifactInfo, origMd5, data, interfaceName, operationName, parentId,
799 containerComponentType);
801 if (result.isLeft()) {
802 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
804 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
807 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_ARTIFACT, StatusCode.COMPLETE,"Ended update artifact {} " ,artifactId + " for component " + componentId);
812 private Response handleArtifactRequest(String data, String componentId, String artifactId, ComponentTypeEnum componentType, ArtifactOperationEnum operation) {
813 return handleArtifactRequest(data, servletRequest, componentId, null, null, artifactId, componentType, operation, null, null, false);