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