df061ad3b1d0aeda5f1e62a8b31cbb60475cedd2
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / InputsServlet.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * SDC\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.sdc.be.servlets;\r
22 \r
23 import java.util.Arrays;\r
24 import java.util.List;\r
25 import javax.inject.Inject;\r
26 import javax.inject.Singleton;\r
27 import javax.servlet.ServletContext;\r
28 import javax.servlet.http.HttpServletRequest;\r
29 import javax.ws.rs.Consumes;\r
30 import javax.ws.rs.DELETE;\r
31 import javax.ws.rs.GET;\r
32 import javax.ws.rs.HeaderParam;\r
33 import javax.ws.rs.POST;\r
34 import javax.ws.rs.Path;\r
35 import javax.ws.rs.PathParam;\r
36 import javax.ws.rs.Produces;\r
37 import javax.ws.rs.core.Context;\r
38 import javax.ws.rs.core.MediaType;\r
39 import javax.ws.rs.core.Response;\r
40 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;\r
41 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;\r
42 import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic;\r
43 import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;\r
44 import org.openecomp.sdc.be.components.impl.ResourceImportManager;\r
45 import org.openecomp.sdc.be.config.BeEcompErrorManager;\r
46 import org.openecomp.sdc.be.dao.api.ActionStatus;\r
47 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;\r
48 import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;\r
49 import org.openecomp.sdc.be.impl.ComponentsUtils;\r
50 import org.openecomp.sdc.be.impl.ServletUtils;\r
51 import org.openecomp.sdc.be.model.ComponentInstInputsMap;\r
52 import org.openecomp.sdc.be.model.ComponentInstListInput;\r
53 import org.openecomp.sdc.be.model.ComponentInstanceInput;\r
54 import org.openecomp.sdc.be.model.ComponentInstanceProperty;\r
55 import org.openecomp.sdc.be.model.DataTypeDefinition;\r
56 import org.openecomp.sdc.be.model.InputDefinition;\r
57 import org.openecomp.sdc.be.model.Resource;\r
58 import org.openecomp.sdc.be.model.User;\r
59 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;\r
60 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;\r
61 import org.openecomp.sdc.be.user.UserBusinessLogic;\r
62 import org.openecomp.sdc.common.api.Constants;\r
63 import org.openecomp.sdc.common.log.wrappers.Logger;\r
64 import org.openecomp.sdc.exception.ResponseFormat;\r
65 import com.fasterxml.jackson.databind.ObjectMapper;\r
66 import com.jcabi.aspects.Loggable;\r
67 import fj.data.Either;\r
68 import io.swagger.v3.oas.annotations.OpenAPIDefinition;\r
69 import io.swagger.v3.oas.annotations.Operation;\r
70 import io.swagger.v3.oas.annotations.Parameter;\r
71 import io.swagger.v3.oas.annotations.info.Info;\r
72 import io.swagger.v3.oas.annotations.media.ArraySchema;\r
73 import io.swagger.v3.oas.annotations.media.Content;\r
74 import io.swagger.v3.oas.annotations.media.Schema;\r
75 import io.swagger.v3.oas.annotations.responses.ApiResponse;\r
76 import io.swagger.v3.oas.annotations.responses.ApiResponses;\r
77 \r
78 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)\r
79 @OpenAPIDefinition(info = @Info(title = "Input Catalog", description = "Input Servlet"))\r
80 @Path("/v1/catalog")\r
81 @Singleton\r
82 @Consumes(MediaType.APPLICATION_JSON)\r
83 @Produces(MediaType.APPLICATION_JSON)\r
84 public class InputsServlet extends AbstractValidationsServlet {\r
85 \r
86     private static final Logger log = Logger.getLogger(InputsServlet.class);\r
87 \r
88     private final DataTypeBusinessLogic businessLogic;\r
89     private final InputsBusinessLogic inputsBusinessLogic;\r
90 \r
91     @Inject\r
92     public InputsServlet(UserBusinessLogic userBusinessLogic,\r
93         InputsBusinessLogic inputsBusinessLogic,\r
94         ComponentInstanceBusinessLogic componentInstanceBL,\r
95         ComponentsUtils componentsUtils, ServletUtils servletUtils,\r
96         ResourceImportManager resourceImportManager,\r
97         DataTypeBusinessLogic dataTypeBusinessLogic) {\r
98         super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);\r
99         this.inputsBusinessLogic = inputsBusinessLogic;\r
100         this.businessLogic = dataTypeBusinessLogic;\r
101     }\r
102 \r
103     @POST\r
104     @Path("/{containerComponentType}/{componentId}/update/inputs")\r
105     @Operation(description = "Update resource  inputs", method = "POST", summary = "Returns updated input",\r
106             responses = @ApiResponse(content = @Content(\r
107                     array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
108     @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Input updated"),\r
109             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
110             @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})\r
111     public Response updateComponentInputs(@Parameter(description = "valid values: resources / services",\r
112             schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,\r
113                     ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,\r
114             @PathParam("componentId") final String componentId,\r
115             @Parameter(description = "json describe the input", required = true) String data,\r
116             @Context final HttpServletRequest request) {\r
117 \r
118         String url = request.getMethod() + " " + request.getRequestURI();\r
119         log.debug("Start handle request of {}", url);\r
120         String userId = request.getHeader(Constants.USER_ID_HEADER);\r
121 \r
122         try {\r
123             User modifier = new User();\r
124             modifier.setUserId(userId);\r
125             log.debug("modifier id is {}", userId);\r
126 \r
127             Either<InputDefinition[], ResponseFormat> inputsEither = getComponentsUtils()\r
128                     .convertJsonToObjectUsingObjectMapper(data, modifier, InputDefinition[].class,\r
129                             AuditingActionEnum.UPDATE_RESOURCE_METADATA, ComponentTypeEnum.SERVICE);\r
130             if(inputsEither.isRight()){\r
131                 log.debug("Failed to convert data to input definition. Status is {}", inputsEither.right().value());\r
132                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));\r
133             }\r
134             List<InputDefinition> inputsToUpdate = Arrays.asList(inputsEither.left().value());\r
135 \r
136             log.debug("Start handle request of updateComponentInputs. Received inputs are {}", inputsToUpdate);\r
137 \r
138             ServletContext context = request.getSession().getServletContext();\r
139             ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(containerComponentType);\r
140 \r
141             if (businessLogic == null) {\r
142                 log.debug("Unsupported component type {}", containerComponentType);\r
143                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR));\r
144             }\r
145 \r
146             Either<List<InputDefinition>, ResponseFormat> actionResponse = inputsBusinessLogic.updateInputsValue(componentType, componentId, inputsToUpdate, userId, true, false);\r
147 \r
148             if (actionResponse.isRight()) {\r
149                 return buildErrorResponse(actionResponse.right().value());\r
150             }\r
151 \r
152             List<InputDefinition> componentInputs = actionResponse.left().value();\r
153             ObjectMapper mapper = new ObjectMapper();\r
154             String result = mapper.writeValueAsString(componentInputs);\r
155             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);\r
156 \r
157         }\r
158         catch (Exception e) {\r
159             log.error("create and associate RI failed with exception: {}", e.getMessage(), e);\r
160             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
161         }\r
162     }\r
163 \r
164 \r
165     @GET\r
166     @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{originComponentUid}/inputs")\r
167     @Operation(description = "Get Inputs only", method = "GET", summary = "Returns Inputs list",\r
168             responses = @ApiResponse(content = @Content(\r
169                     array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
170     @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
171             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
172             @ApiResponse(responseCode = "404", description = "Component not found")})\r
173     public Response getComponentInstanceInputs(@PathParam("componentType") final String componentType,\r
174             @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,\r
175             @PathParam("originComponentUid") final String originComponentUid, @Context final HttpServletRequest request,\r
176             @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {\r
177 \r
178         ServletContext context = request.getSession().getServletContext();\r
179         String url = request.getMethod() + " " + request.getRequestURI();\r
180         log.debug("(get) Start handle request of {}", url);\r
181         Response response;\r
182 \r
183         try {\r
184             Either<List<ComponentInstanceInput>, ResponseFormat> inputsResponse = inputsBusinessLogic.getComponentInstanceInputs(userId, componentId, instanceId);\r
185             if (inputsResponse.isRight()) {\r
186                 log.debug("failed to get component instance inputs {}", componentType);\r
187                 return buildErrorResponse(inputsResponse.right().value());\r
188             }\r
189             Object inputs = RepresentationUtils.toRepresentation(inputsResponse.left().value());\r
190             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), inputs);\r
191 \r
192         } catch (Exception e) {\r
193             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Inputs " + componentType);\r
194             log.debug("getInputs failed with exception", e);\r
195             response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
196             return response;\r
197 \r
198         }\r
199     }\r
200 \r
201     @GET\r
202     @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{inputId}/properties")\r
203     @Operation(description = "Get properties", method = "GET", summary = "Returns properties list",\r
204             responses = @ApiResponse(content = @Content(\r
205                     array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )\r
206     @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
207             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
208             @ApiResponse(responseCode = "404", description = "Component not found")})\r
209     public Response getInputPropertiesForComponentInstance(@PathParam("componentType") final String componentType,\r
210             @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,\r
211             @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,\r
212             @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {\r
213 \r
214         ServletContext context = request.getSession().getServletContext();\r
215         String url = request.getMethod() + " " + request.getRequestURI();\r
216         log.debug("(GET) Start handle request of {}", url);\r
217         Response response = null;\r
218 \r
219         try {\r
220             Either<List<ComponentInstanceProperty>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic\r
221                     .getComponentInstancePropertiesByInputId(userId, componentId, instanceId, inputId);\r
222             if (inputPropertiesRes.isRight()) {\r
223                 log.debug("failed to get properties of input: {}, with instance id: {}", inputId, instanceId);\r
224                 return buildErrorResponse(inputPropertiesRes.right().value());\r
225             }\r
226             Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());\r
227             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);\r
228 \r
229         } catch (Exception e) {\r
230             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(\r
231                     "Get Properites by input id: " + inputId + " for instance with id: " + instanceId);\r
232             log.debug("getInputPropertiesForComponentInstance failed with exception", e);\r
233             response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
234             return response;\r
235 \r
236         }\r
237     }\r
238 \r
239     @GET\r
240     @Path("/{componentType}/{componentId}/inputs/{inputId}/inputs")\r
241     @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = @ApiResponse(content = @Content(\r
242             array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )\r
243     @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
244             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
245             @ApiResponse(responseCode = "404", description = "Component not found")})\r
246     public Response getInputsForComponentInput(@PathParam("componentType") final String componentType,\r
247             @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,\r
248             @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {\r
249 \r
250         ServletContext context = request.getSession().getServletContext();\r
251         String url = request.getMethod() + " " + request.getRequestURI();\r
252         log.debug("(get) Start handle request of {}", url);\r
253         Response response;\r
254         try {\r
255             Either<List<ComponentInstanceInput>, ResponseFormat> inputsRes =\r
256                     inputsBusinessLogic.getInputsForComponentInput(userId, componentId, inputId);\r
257 \r
258             if (inputsRes.isRight()) {\r
259                 log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);\r
260                 return buildErrorResponse(inputsRes.right().value());\r
261             }\r
262             Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());\r
263             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);\r
264 \r
265         } catch (Exception e) {\r
266             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(\r
267                     "Get inputs by input id: " + inputId + " for component with id: " + componentId);\r
268             log.debug("getInputsForComponentInput failed with exception", e);\r
269             response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
270             return response;\r
271 \r
272         }\r
273     }\r
274 \r
275     @GET\r
276     @Path("/{componentType}/{componentId}/inputs/{inputId}")\r
277     @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = @ApiResponse(content = @Content(\r
278             array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )\r
279     @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
280             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
281             @ApiResponse(responseCode = "404", description = "Component not found")})\r
282     public Response getInputsAndPropertiesForComponentInput(@PathParam("componentType") final String componentType,\r
283             @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,\r
284             @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {\r
285 \r
286         ServletContext context = request.getSession().getServletContext();\r
287         String url = request.getMethod() + " " + request.getRequestURI();\r
288         log.debug("(get) Start handle request of {}", url);\r
289         Response response;\r
290 \r
291         try {\r
292             Either<InputDefinition, ResponseFormat> inputsRes =\r
293                     inputsBusinessLogic.getInputsAndPropertiesForComponentInput(userId, componentId, inputId, false);\r
294 \r
295             if (inputsRes.isRight()) {\r
296                 log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);\r
297                 return buildErrorResponse(inputsRes.right().value());\r
298             }\r
299             Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());\r
300             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);\r
301 \r
302         } catch (Exception e) {\r
303             BeEcompErrorManager.getInstance().logBeRestApiGeneralError(\r
304                     "Get inputs by input id: " + inputId + " for component with id: " + componentId);\r
305             log.debug("getInputsForComponentInput failed with exception", e);\r
306             response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
307             return response;\r
308 \r
309         }\r
310     }\r
311 \r
312     private Either<ComponentInstInputsMap, ResponseFormat> parseToComponentInstanceMap(String serviceJson, User user) {\r
313         return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, ComponentInstInputsMap.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);\r
314     }\r
315 \r
316     private Either<ComponentInstListInput, ResponseFormat> parseToComponentInstListInput(String json, User user) {\r
317         return getComponentsUtils().convertJsonToObjectUsingObjectMapper(json, user, ComponentInstListInput.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);\r
318     }\r
319 \r
320     @POST\r
321     @Path("/{componentType}/{componentId}/create/inputs")\r
322     @Operation(description = "Create inputs on service", method = "POST", summary = "Return inputs list",\r
323             responses = @ApiResponse(\r
324                     content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
325     @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
326             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
327             @ApiResponse(responseCode = "404", description = "Component not found")})\r
328     public Response createMultipleInputs(@PathParam("componentType") final String componentType,\r
329             @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,\r
330             @HeaderParam(value = Constants.USER_ID_HEADER) String userId,\r
331             @Parameter(description = "ComponentIns Inputs Object to be created",\r
332                     required = true) String componentInstInputsMapObj) {\r
333 \r
334         return super.declareProperties(userId, componentId, componentType, componentInstInputsMapObj,\r
335                 DeclarationTypeEnum.INPUT, request);\r
336     }\r
337 \r
338 \r
339     /**\r
340      * Creates a "list input" and updates given list of properties to get value from the input.\r
341      * also a data type which has same properties is created.\r
342      * the data type will be the entry_schema of the list input.\r
343      * @param componentType the container type (service, resource, ...)\r
344      * @param componentId the container ID\r
345      * @param request HttpServletRequest object\r
346      * @param userId the User ID\r
347      * @param componentInstInputsMapObj the list of properties to be declared and the "list input" to be created.\r
348      *                                  the type of the input must be "list".\r
349      *                                  schema.type of the input will be the name of new data type.\r
350      * @return the created input\r
351      */\r
352     @POST\r
353     @Path("/{componentType}/{componentId}/create/listInput")\r
354     @Operation(description = "Create a list input on service", method = "POST", summary = "Return input",\r
355             responses = @ApiResponse(content = @Content(\r
356                     array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )\r
357     @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
358             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
359             @ApiResponse(responseCode = "404", description = "Component not found")})\r
360     public Response createListInput(@PathParam("componentType") final String componentType,\r
361             @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,\r
362             @HeaderParam(value = Constants.USER_ID_HEADER) String userId,\r
363             @Parameter(description = "ComponentIns Inputs Object to be created",\r
364                     required = true) String componentInstInputsMapObj) {\r
365 \r
366         ServletContext context = request.getSession().getServletContext();\r
367         String url = request.getMethod() + " " + request.getRequestURI();\r
368         log.debug("#createListInput: Start handle request of {}", url);\r
369         Response response = null;\r
370 \r
371         try {\r
372             // get modifier id\r
373             User modifier = new User();\r
374             modifier.setUserId(userId);\r
375             log.debug("modifier id is {}", userId);\r
376 \r
377             Either<ComponentInstListInput, ResponseFormat> componentInstInputsMapRes =\r
378                     parseToComponentInstListInput(componentInstInputsMapObj, modifier);\r
379             if (componentInstInputsMapRes.isRight()) {\r
380                 log.debug("failed to parse componentInstInputsMap");\r
381                 response = buildErrorResponse(componentInstInputsMapRes.right().value());\r
382                 return response;\r
383             }\r
384 \r
385             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);\r
386             ComponentInstListInput componentInstInputsMap = componentInstInputsMapRes.left().value();\r
387             if (log.isDebugEnabled()) {\r
388                 // for inspection on debug\r
389                 log.debug("parsed componentInstInputsMap={}",\r
390                         ReflectionToStringBuilder.toString(componentInstInputsMap));\r
391             }\r
392 \r
393             Either<List<InputDefinition>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic\r
394                     .createListInput(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);\r
395             if (inputPropertiesRes.isRight()) {\r
396                 log.debug("failed to create list input for service: {}", componentId);\r
397                 return buildErrorResponse(inputPropertiesRes.right().value());\r
398             }\r
399             Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());\r
400             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);\r
401 \r
402         } catch (Exception e) {\r
403             BeEcompErrorManager.getInstance()\r
404                     .logBeRestApiGeneralError("Create list input for service with id: " + componentId);\r
405             log.debug("createListInput failed with exception", e);\r
406             response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
407             return response;\r
408         }\r
409     }\r
410 \r
411 \r
412     @DELETE\r
413     @Path("/{componentType}/{componentId}/delete/{inputId}/input")\r
414     @Operation(description = "Delete input from service", method = "DELETE", summary = "Delete service input",\r
415             responses = @ApiResponse(content = @Content(\r
416                     array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )\r
417     @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Input deleted"),\r
418             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
419             @ApiResponse(responseCode = "404", description = "Input not found")})\r
420     public Response deleteInput(@PathParam("componentType") final String componentType,\r
421             @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,\r
422             @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,\r
423             @Parameter(description = "Service Input to be deleted", required = true) String componentInstInputsMapObj) {\r
424 \r
425         ServletContext context = request.getSession().getServletContext();\r
426         String url = request.getMethod() + " " + request.getRequestURI();\r
427         log.debug("(get) Start handle request of {}", url);\r
428         Response response = null;\r
429 \r
430         try {\r
431             Either<InputDefinition, ResponseFormat> deleteInput =\r
432                     inputsBusinessLogic.deleteInput(componentId, userId, inputId);\r
433             if (deleteInput.isRight()) {\r
434                 ResponseFormat deleteResponseFormat = deleteInput.right().value();\r
435                 response = buildErrorResponse(deleteResponseFormat);\r
436                 return response;\r
437             }\r
438             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteInput.left().value());\r
439         } catch (Exception e) {\r
440             BeEcompErrorManager.getInstance()\r
441                     .logBeRestApiGeneralError("Delete input for service + " + componentId + " + with id: " + inputId);\r
442             log.debug("Delete input failed with exception", e);\r
443             response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
444             return response;\r
445 \r
446         }\r
447     }\r
448 \r
449     /**\r
450      * Gets a specific data type associated with a component.\r
451      * @param componentType the container type (service, resource, ...)\r
452      * @param componentId the container ID\r
453      * @param dataTypeName the data type name\r
454      * @param request HttpServletRequest object\r
455      * @return the data type info\r
456      */\r
457     @GET\r
458     @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")\r
459     @Operation(description = "Get data type in service", method = "GET", summary = "Get data type in service",\r
460             responses = @ApiResponse(content = @Content(\r
461                     array = @ArraySchema(schema = @Schema(implementation = DataTypeDefinition.class)))))\r
462     @ApiResponses(value = {\r
463             @ApiResponse(responseCode = "200", description = "Data type found"),\r
464             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
465             @ApiResponse(responseCode = "404", description = "Data type not found")})\r
466     public Response getDataType(\r
467             @PathParam("componentType") final String componentType,\r
468             @PathParam("componentId") final String componentId,\r
469             @PathParam("dataTypeName") final String dataTypeName,\r
470             @Context final HttpServletRequest request\r
471     ) {\r
472         ComponentsUtils componentsUtils = getComponentsUtils();\r
473         String url = request.getMethod() + " " + request.getRequestURI();\r
474         log.debug("(getDataType) Start handle request of {}", url);\r
475         Response response;\r
476 \r
477         try {\r
478             Either<DataTypeDefinition, StorageOperationStatus> getResult = businessLogic.getPrivateDataType(componentId, dataTypeName);\r
479             if (getResult.isRight()) {\r
480                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());\r
481                 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));\r
482             }\r
483             Object json = RepresentationUtils.toRepresentation(getResult.left().value());\r
484             return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);\r
485         } catch (Exception e) {\r
486             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId + " + with name: " + dataTypeName);\r
487             log.debug("Get data type failed with exception", e);\r
488             response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));\r
489             return response;\r
490         }\r
491     }\r
492 \r
493     /**\r
494      * Gets a list of data types which a component has.\r
495      * @param componentType the container type (service, resource, ...)\r
496      * @param componentId the container ID\r
497      * @param request HttpServletRequest object\r
498      * @return the list of data types in the component\r
499      */\r
500     @GET\r
501     @Path("/{componentType}/{componentId}/dataTypes")\r
502     @Operation(description = "Get data types that service has", method = "GET", summary = "Get data types in service",\r
503             responses = @ApiResponse(content = @Content(\r
504                     array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )\r
505     @ApiResponses(value = {\r
506             @ApiResponse(responseCode = "200", description = "Data type found"),\r
507             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
508             @ApiResponse(responseCode = "404", description = "Component not found")})\r
509     public Response getDataTypes(\r
510             @PathParam("componentType") final String componentType,\r
511             @PathParam("componentId") final String componentId,\r
512             @Context final HttpServletRequest request\r
513     ) {\r
514         ServletContext context = request.getSession().getServletContext();\r
515         ComponentsUtils componentsUtils = getComponentsUtils();\r
516         String url = request.getMethod() + " " + request.getRequestURI();\r
517         log.debug("(getDataType) Start handle request of {}", url);\r
518         Response response;\r
519 \r
520         try {\r
521             Either<List<DataTypeDefinition>, StorageOperationStatus> getResult = businessLogic.getPrivateDataTypes(componentId);\r
522             if (getResult.isRight()) {\r
523                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());\r
524                 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));\r
525             }\r
526             Object json = RepresentationUtils.toRepresentation(getResult.left().value());\r
527             return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);\r
528         } catch (Exception e) {\r
529             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId);\r
530             log.debug("Get data type failed with exception", e);\r
531             response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));\r
532             return response;\r
533         }\r
534     }\r
535 \r
536     /**\r
537      * Deletes a data type from a component.\r
538      * @param componentType the container type (service, resource, ...)\r
539      * @param componentId the container ID\r
540      * @param dataTypeName the data type name to be deleted\r
541      * @param request HttpServletRequest object\r
542      * @return operation result\r
543      */\r
544     @DELETE\r
545     @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")\r
546     @Operation(description = "Delete data type from service", method = "DELETE", summary = "Delete service input",\r
547             responses = @ApiResponse(content = @Content(\r
548                     array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
549     @ApiResponses(value = {\r
550             @ApiResponse(responseCode = "200", description = "Data type deleted"),\r
551             @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
552             @ApiResponse(responseCode = "404", description = "Data type not found")})\r
553     public Response deleteDataType(\r
554             @PathParam("componentType") final String componentType,\r
555             @PathParam("componentId") final String componentId,\r
556             @PathParam("dataTypeName") final String dataTypeName,\r
557             @Context final HttpServletRequest request\r
558     ) {\r
559         ServletContext context = request.getSession().getServletContext();\r
560         ComponentsUtils componentsUtils = getComponentsUtils();\r
561         String url = request.getMethod() + " " + request.getRequestURI();\r
562         log.debug("(get) Start handle request of {}", url);\r
563         Response response;\r
564 \r
565         try {\r
566             Either<DataTypeDefinition, StorageOperationStatus> deleteResult = businessLogic.deletePrivateDataType(componentId, dataTypeName);\r
567             if (deleteResult.isRight()) {\r
568                 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteResult.right().value());\r
569                 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));\r
570             }\r
571             Object json = RepresentationUtils.toRepresentation(deleteResult.left().value());\r
572             return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);\r
573         } catch (Exception e) {\r
574             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete data type for service + " + componentId + " + with name: " + dataTypeName);\r
575             log.debug("Delete data type failed with exception", e);\r
576             response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));\r
577             return response;\r
578         }\r
579     }\r
580 }\r