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