eddac103c33d5eda8bb4a8c7602b5a52ab2a37ef
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / action-library-rest / action-library-rest-services / src / main / java / org / openecomp / sdcrests / action / rest / Actions.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdcrests.action.rest;
22
23 import io.swagger.v3.oas.annotations.OpenAPIDefinition;
24 import io.swagger.v3.oas.annotations.Operation;
25 import io.swagger.v3.oas.annotations.info.Info;
26 import io.swagger.v3.oas.annotations.media.Content;
27 import io.swagger.v3.oas.annotations.media.Schema;
28 import io.swagger.v3.oas.annotations.responses.ApiResponse;
29 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
30 import org.apache.cxf.jaxrs.ext.multipart.Multipart;
31 import org.openecomp.sdcrests.action.types.ActionResponseDto;
32 import org.openecomp.sdcrests.action.types.ListResponseWrapper;
33 import org.springframework.validation.annotation.Validated;
34
35 import javax.servlet.http.HttpServletRequest;
36 import javax.ws.rs.*;
37 import javax.ws.rs.core.Context;
38 import javax.ws.rs.core.MediaType;
39 import javax.ws.rs.core.Response;
40
41 /**
42  * Defines various CRUD API that can be performed on Action.
43  */
44 @Path("/workflow/v1.0/actions")
45 @Produces(MediaType.APPLICATION_JSON)
46 @Consumes(MediaType.APPLICATION_JSON)
47 @OpenAPIDefinition(info =  @Info(title = "Actions"))
48 @Validated
49 public interface Actions {
50
51   /**
52    * List All Major, Last Minor and Candidate version if any for Given Action Invariant UuId
53    *
54    * @return List of All Major, Last Minor and Candidate version if any Of Action with given
55     actionInvariantUuId. If actionUuId is provided then only action with given actionInvariantUuId
56     and actionUuId
57    */
58   @GET
59   @Path("/{actionInvariantUuId}")
60   @Operation(description = "List Actions For Given Action Invariant UuId", responses = @ApiResponse(content = @Content(schema = @Schema(implementation = ListResponseWrapper.class))))
61   Response getActionsByActionInvariantUuId(
62       @PathParam("actionInvariantUuId") String actionInvariantUuId,
63       @QueryParam("version") String actionUuId, @Context HttpServletRequest servletRequest);
64
65   /**
66    * Get list of actions based on a filter criteria. If no filter is sent all actions will be
67    * returned
68    *
69    * @return List Of Last Major and Last Minor of All Actions based on filter criteria
70    */
71   @GET
72   @Operation(description = "List Filtered Actions ",
73       summary = "Get list of actions based on a filter criteria | If no filter is sent all actions "
74           + "will be returned",
75           responses = @ApiResponse(content = @Content(schema = @Schema(implementation = ListResponseWrapper.class))))
76   Response getFilteredActions(@QueryParam("vendor") String vendor,
77                               @QueryParam("category") String category,
78                               @QueryParam("name") String name,
79                               @QueryParam("modelId") String modelId,
80                               @QueryParam("componentId") String componentId,
81                               @Context HttpServletRequest servletRequest);
82
83   /**
84    * List OPENECOMP Components supported by Action Library.
85    *
86    * @return List of OPENECOMP Components supported by Action Library
87    */
88   @GET
89   @Path("/components")
90   @Operation(description = "List OPENECOMP Components supported by Action Library", responses = @ApiResponse(content = @Content(schema = @Schema(implementation = ListResponseWrapper.class))))
91   Response getOpenEcompComponents(@Context HttpServletRequest servletRequest);
92
93   /**
94    * Create a new Action based on request JSON.
95    *
96    * @return Metadata object {@link ActionResponseDto ActionResponseDto} object for created Action
97    */
98   @POST
99   @Operation(description = "Create a new Action")
100   Response createAction(String requestJson, @Context HttpServletRequest servletRequest);
101
102   /**
103    * Update an existing action with parameters provided in requestJson.
104    *
105    * @return Metadata object {@link ActionResponseDto ActionResponseDto} object for created Action
106    */
107   @PUT
108   @Path("/{actionInvariantUuId}")
109   @Operation(description = "Update an existing action")
110   Response updateAction(@PathParam("actionInvariantUuId") String actionInvariantUuId,
111                         String requestJson, @Context HttpServletRequest servletRequest);
112
113   /**
114    * Delete an action.
115    *
116    * @param actionInvariantUuId Invariant UuId of the action to be deleted
117    * @param servletRequest      Servlet request object
118    * @return Empty response object
119    */
120   @DELETE
121   @Path("/{actionInvariantUuId}")
122   @Operation(description = "Delete Action")
123   Response deleteAction(@PathParam("actionInvariantUuId") String actionInvariantUuId,
124                         @Context HttpServletRequest servletRequest);
125
126   /**
127    * Performs Checkout/Undo_Checkout/Checkin/Submit Operation on Action.
128    *
129    * @return Metadata object {@link ActionResponseDto ActionResponseDto} object for created Action
130    */
131   @POST
132   @Path("/{actionInvariantUuId}")
133   @Operation(description = "Actions on a action",
134       summary = "Performs one of the following actions on a action: |"
135           + "Checkout: Locks it for edits by other users. Only the locking user sees the edited "
136           + "version.|"
137           + "Undo_Checkout: Unlocks it and deletes the edits that were done.|"
138           + "Checkin: Unlocks it and activates the edited version to all users.| "
139           + "Submit: Finalize its active version.|")
140   Response actOnAction(@PathParam("actionInvariantUuId") String actionInvariantUuId,
141                        String requestJson, @Context HttpServletRequest servletRequest);
142
143   /**
144    * Upload an artifact to an action.
145    *
146    * @param actionInvariantUuId Invariant UuId of the action to which the artifact is uploaded
147    * @param artifactName        Name of the artifact
148    * @param artifactLabel       Label of the artifact
149    * @param artifactCategory    Category of the artifact
150    * @param artifactDescription Description  of the artifact
151    * @param artifactProtection  Artifact protection mode
152    * @param checksum            Checksum of the artifact
153    * @param artifactToUpload    Artifact content object
154    * @param servletRequest      Servlet request object
155    * @return Generated UuId of the uploaded artifact
156    */
157   @POST
158   @Path("/{actionInvariantUuId}/artifacts")
159   @Consumes(MediaType.MULTIPART_FORM_DATA)
160   Response uploadArtifact(@PathParam("actionInvariantUuId") String actionInvariantUuId,
161        @Multipart(value = "artifactName", required = false) String artifactName,
162        @Multipart(value = "artifactLabel", required = false) String artifactLabel,
163        @Multipart(value = "artifactCategory", required = false) String artifactCategory,
164        @Multipart(value = "artifactDescription", required = false) String artifactDescription,
165        @Multipart(value = "artifactProtection", required = false) String artifactProtection,
166        @HeaderParam("Content-MD5") String checksum,
167        @Multipart(value = "uploadArtifact", required = false) Attachment artifactToUpload,
168        @Context HttpServletRequest servletRequest);
169
170   @GET
171   @Path("/{actionUuId}/artifacts/{artifactUuId}")
172   @Produces(MediaType.APPLICATION_OCTET_STREAM)
173   @Operation(description = "Downloads artifact for action")
174   Response downloadArtifact(@PathParam("actionUuId") String actionUuId,
175                             @PathParam("artifactUuId") String artifactUuId,
176                             @Context HttpServletRequest servletRequest);
177
178   @DELETE
179   @Path("/{actionInvariantUuId}/artifacts/{artifactUuId}")
180   @Operation(description = "Delete Artifact")
181   Response deleteArtifact(@PathParam("actionInvariantUuId") String actionInvariantUuId,
182                           @PathParam("artifactUuId") String artifactUuId,
183                           @Context HttpServletRequest servletRequest);
184
185   @PUT
186   @Path("/{actionInvariantUuId}/artifacts/{artifactUuId}")
187   @Consumes(MediaType.MULTIPART_FORM_DATA)
188   Response updateArtifact(@PathParam("actionInvariantUuId") String actionInvariantUuId,
189        @PathParam("artifactUuId") String artifactUuId,
190        @Multipart(value = "artifactName", required = false) String artifactName,
191        @Multipart(value = "artifactLabel", required = false) String artifactLabel,
192        @Multipart(value = "artifactCategory", required = false) String artifactCategory,
193        @Multipart(value = "artifactDescription", required = false) String artifactDescription,
194        @Multipart(value = "artifactProtection", required = false) String artifactProtection,
195        @HeaderParam("Content-MD5") String checksum,
196        @Multipart(value = "updateArtifact", required = false) Attachment artifactToUpdate,
197        @Context HttpServletRequest servletRequest);
198
199 }