2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.be.servlets;
22 import com.fasterxml.jackson.core.JsonProcessingException;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import com.jcabi.aspects.Loggable;
25 import fj.data.Either;
26 import io.swagger.v3.oas.annotations.Operation;
27 import io.swagger.v3.oas.annotations.Parameter;
28 import io.swagger.v3.oas.annotations.media.ArraySchema;
29 import io.swagger.v3.oas.annotations.media.Content;
30 import io.swagger.v3.oas.annotations.media.Schema;
31 import io.swagger.v3.oas.annotations.responses.ApiResponse;
32 import io.swagger.v3.oas.annotations.servers.Server;
33 import io.swagger.v3.oas.annotations.tags.Tag;
34 import io.swagger.v3.oas.annotations.tags.Tags;
35 import java.io.IOException;
36 import java.util.Arrays;
37 import java.util.List;
39 import javax.inject.Inject;
40 import javax.servlet.http.HttpServletRequest;
41 import javax.ws.rs.Consumes;
42 import javax.ws.rs.DELETE;
43 import javax.ws.rs.GET;
44 import javax.ws.rs.HeaderParam;
45 import javax.ws.rs.POST;
46 import javax.ws.rs.Path;
47 import javax.ws.rs.PathParam;
48 import javax.ws.rs.Produces;
49 import javax.ws.rs.core.Context;
50 import javax.ws.rs.core.MediaType;
51 import javax.ws.rs.core.Response;
52 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
53 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
54 import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic;
55 import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
56 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
57 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
58 import org.openecomp.sdc.be.config.BeEcompErrorManager;
59 import org.openecomp.sdc.be.dao.api.ActionStatus;
60 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
61 import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
62 import org.openecomp.sdc.be.impl.ComponentsUtils;
63 import org.openecomp.sdc.be.impl.ServletUtils;
64 import org.openecomp.sdc.be.model.ComponentInstListInput;
65 import org.openecomp.sdc.be.model.ComponentInstanceInput;
66 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
67 import org.openecomp.sdc.be.model.DataTypeDefinition;
68 import org.openecomp.sdc.be.model.InputDefinition;
69 import org.openecomp.sdc.be.model.Resource;
70 import org.openecomp.sdc.be.model.User;
71 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
72 import org.openecomp.sdc.be.resources.data.EntryData;
73 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
74 import org.openecomp.sdc.common.api.Constants;
75 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
76 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
77 import org.openecomp.sdc.common.log.enums.StatusCode;
78 import org.openecomp.sdc.common.log.wrappers.Logger;
79 import org.openecomp.sdc.exception.ResponseFormat;
80 import org.springframework.stereotype.Controller;
82 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
83 @Tags({@Tag(name = "SDCE-2 APIs")})
84 @Server(url = "/sdc2/rest")
87 @Consumes(MediaType.APPLICATION_JSON)
88 @Produces(MediaType.APPLICATION_JSON)
89 public class InputsServlet extends AbstractValidationsServlet {
91 private static final Logger log = Logger.getLogger(InputsServlet.class);
92 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(InputsServlet.class.getName());
93 private static final String START_HANDLE_REQUEST_OF = "(get) Start handle request of {}";
94 private static final String CREATE_INPUT = "CreateInput";
95 private final DataTypeBusinessLogic businessLogic;
96 private final InputsBusinessLogic inputsBusinessLogic;
99 public InputsServlet(InputsBusinessLogic inputsBusinessLogic,
100 ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils, ServletUtils servletUtils,
101 ResourceImportManager resourceImportManager, DataTypeBusinessLogic dataTypeBusinessLogic) {
102 super(componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
103 this.inputsBusinessLogic = inputsBusinessLogic;
104 this.businessLogic = dataTypeBusinessLogic;
108 @Path("/{containerComponentType}/{componentId}/update/inputs")
109 @Operation(description = "Update resource inputs", method = "POST", summary = "Returns updated input", responses = {
110 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
111 @ApiResponse(responseCode = "200", description = "Input updated"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
112 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
113 public Response updateComponentInputs(
114 @Parameter(description = "valid values: resources / services", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
115 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
116 @PathParam("componentId") final String componentId, @Parameter(description = "json describe the input", required = true) String data,
117 @Context final HttpServletRequest request) throws JsonProcessingException {
118 String url = request.getMethod() + " " + request.getRequestURI();
119 log.debug("Start handle request of {}", url);
120 String userId = request.getHeader(Constants.USER_ID_HEADER);
122 User modifier = new User();
123 modifier.setUserId(userId);
124 log.debug("modifier id is {}", userId);
125 Either<InputDefinition[], ResponseFormat> inputsEither = getComponentsUtils()
126 .convertJsonToObjectUsingObjectMapper(data, modifier, InputDefinition[].class, AuditingActionEnum.UPDATE_RESOURCE_METADATA,
127 ComponentTypeEnum.SERVICE);
128 if (inputsEither.isRight()) {
129 log.debug("Failed to convert data to input definition. Status is {}", inputsEither.right().value());
130 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
132 List<InputDefinition> inputsToUpdate = Arrays.asList(inputsEither.left().value());
133 log.debug("Start handle request of updateComponentInputs. Received inputs are {}", inputsToUpdate);
134 ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(containerComponentType);
135 if (businessLogic == null) {
136 log.debug("Unsupported component type {}", containerComponentType);
137 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR));
139 Either<List<InputDefinition>, ResponseFormat> actionResponse = inputsBusinessLogic
140 .updateInputsValue(componentType, componentId, inputsToUpdate, userId, true);
141 if (actionResponse.isRight()) {
142 return buildErrorResponse(actionResponse.right().value());
144 List<InputDefinition> componentInputs = actionResponse.left().value();
145 ObjectMapper mapper = new ObjectMapper();
146 String result = mapper.writeValueAsString(componentInputs);
147 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
148 } catch (Exception e) {
149 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
155 @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{originComponentUid}/inputs")
156 @Operation(description = "Get Inputs only", method = "GET", summary = "Returns Inputs list", responses = {
157 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
158 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
159 @ApiResponse(responseCode = "404", description = "Component not found")})
160 public Response getComponentInstanceInputs(@PathParam("componentType") final String componentType,
161 @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
162 @PathParam("originComponentUid") final String originComponentUid,
163 @Context final HttpServletRequest request,
164 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
165 String url = request.getMethod() + " " + request.getRequestURI();
166 log.debug(START_HANDLE_REQUEST_OF, url);
168 Either<List<ComponentInstanceInput>, ResponseFormat> inputsResponse = inputsBusinessLogic
169 .getComponentInstanceInputs(userId, componentId, instanceId);
170 if (inputsResponse.isRight()) {
171 log.debug("failed to get component instance inputs {}", componentType);
172 return buildErrorResponse(inputsResponse.right().value());
174 Object inputs = RepresentationUtils.toRepresentation(inputsResponse.left().value());
175 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), inputs);
176 } catch (Exception e) {
177 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Inputs " + componentType);
178 log.debug("getInputs failed with exception", e);
184 @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{inputId}/properties")
185 @Operation(description = "Get properties", method = "GET", summary = "Returns properties list", responses = {
186 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
187 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
188 @ApiResponse(responseCode = "404", description = "Component not found")})
189 public Response getInputPropertiesForComponentInstance(@PathParam("componentType") final String componentType,
190 @PathParam("componentId") final String componentId,
191 @PathParam("instanceId") final String instanceId,
192 @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
193 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
194 String url = request.getMethod() + " " + request.getRequestURI();
195 log.debug(START_HANDLE_REQUEST_OF, url);
197 Either<List<ComponentInstanceProperty>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
198 .getComponentInstancePropertiesByInputId(userId, componentId, instanceId, inputId);
199 if (inputPropertiesRes.isRight()) {
200 log.debug("failed to get properties of input: {}, with instance id: {}", inputId, instanceId);
201 return buildErrorResponse(inputPropertiesRes.right().value());
203 Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
204 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
205 } catch (Exception e) {
206 BeEcompErrorManager.getInstance()
207 .logBeRestApiGeneralError("Get Properites by input id: " + inputId + " for instance with id: " + instanceId);
208 log.debug("getInputPropertiesForComponentInstance failed with exception", e);
214 @Path("/{componentType}/{componentId}/inputs/{inputId}/inputs")
215 @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = {
216 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
217 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
218 @ApiResponse(responseCode = "404", description = "Component not found")})
219 public Response getInputsForComponentInput(@PathParam("componentType") final String componentType,
220 @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
221 @Context final HttpServletRequest request,
222 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
223 String url = request.getMethod() + " " + request.getRequestURI();
224 log.debug(START_HANDLE_REQUEST_OF, url);
226 Either<List<ComponentInstanceInput>, ResponseFormat> inputsRes = inputsBusinessLogic
227 .getInputsForComponentInput(userId, componentId, inputId);
228 if (inputsRes.isRight()) {
229 log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
230 return buildErrorResponse(inputsRes.right().value());
232 Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
233 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
234 } catch (Exception e) {
235 BeEcompErrorManager.getInstance()
236 .logBeRestApiGeneralError("Get inputs by input id: " + inputId + " for component with id: " + componentId);
237 log.debug("getInputsForComponentInput failed with exception", e);
243 @Path("/{componentType}/{componentId}/inputs/{inputId}")
244 @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = {
245 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
246 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
247 @ApiResponse(responseCode = "404", description = "Component not found")})
248 public Response getInputsAndPropertiesForComponentInput(@PathParam("componentType") final String componentType,
249 @PathParam("componentId") final String componentId,
250 @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
251 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
252 String url = request.getMethod() + " " + request.getRequestURI();
253 log.debug(START_HANDLE_REQUEST_OF, url);
255 Either<InputDefinition, ResponseFormat> inputsRes = inputsBusinessLogic
256 .getInputsAndPropertiesForComponentInput(userId, componentId, inputId, false);
257 if (inputsRes.isRight()) {
258 log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
259 return buildErrorResponse(inputsRes.right().value());
261 Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
262 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
263 } catch (Exception e) {
264 BeEcompErrorManager.getInstance()
265 .logBeRestApiGeneralError("Get inputs by input id: " + inputId + " for component with id: " + componentId);
266 log.debug("getInputsForComponentInput failed with exception", e);
271 private Either<ComponentInstListInput, ResponseFormat> parseToComponentInstListInput(String json, User user) {
272 return getComponentsUtils().convertJsonToObjectUsingObjectMapper(json, user, ComponentInstListInput.class, AuditingActionEnum.CREATE_RESOURCE,
273 ComponentTypeEnum.SERVICE);
277 @Path("/{componentType}/{componentId}/create/inputs")
278 @Operation(description = "Create inputs on service", method = "POST", summary = "Return inputs list", responses = {
279 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
280 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
281 @ApiResponse(responseCode = "404", description = "Component not found")})
282 public Response createMultipleInputs(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
283 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
284 @Parameter(description = "ComponentIns Inputs Object to be created", required = true) String componentInstInputsMapObj) {
285 return super.declareProperties(userId, componentId, componentType, componentInstInputsMapObj, DeclarationTypeEnum.INPUT, request);
289 @Path("/{componentType}/{componentId}/create/input")
290 @Operation(description = "Create inputs on service", method = "POST", summary = "Return inputs list", responses = {
291 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
292 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
293 @ApiResponse(responseCode = "404", description = "Component not found")})
294 public Response createInput(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
295 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
296 @Parameter(description = "ComponentIns Inputs Object to be created", required = true) String componentInstInputsMapObj) {
297 return createInput(componentId, componentInstInputsMapObj, request, userId);
301 * Creates a "list input" and updates given list of properties to get value from the input. also a data type which has same properties is created.
302 * the data type will be the entry_schema of the list input.
304 * @param componentType the container type (service, resource, ...)
305 * @param componentId the container ID
306 * @param request HttpServletRequest object
307 * @param userId the User ID
308 * @param componentInstInputsMapObj the list of properties to be declared and the "list input" to be created. the type of the input must be
309 * "list". schema.type of the input will be the name of new data type.
310 * @return the created input
313 @Path("/{componentType}/{componentId}/create/listInput")
314 @Operation(description = "Create a list input on service", method = "POST", summary = "Return input", responses = {
315 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
316 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
317 @ApiResponse(responseCode = "404", description = "Component not found")})
318 public Response createListInput(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
319 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
320 @Parameter(description = "ComponentIns Inputs Object to be created", required = true) String componentInstInputsMapObj) {
321 String url = request.getMethod() + " " + request.getRequestURI();
322 log.debug("#createListInput: Start handle request of {}", url);
325 User modifier = new User();
326 modifier.setUserId(userId);
327 log.debug("modifier id is {}", userId);
328 Either<ComponentInstListInput, ResponseFormat> componentInstInputsMapRes = parseToComponentInstListInput(componentInstInputsMapObj,
330 if (componentInstInputsMapRes.isRight()) {
331 log.debug("failed to parse componentInstInputsMap");
332 return buildErrorResponse(componentInstInputsMapRes.right().value());
334 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
335 ComponentInstListInput componentInstInputsMap = componentInstInputsMapRes.left().value();
336 if (log.isDebugEnabled()) {
337 // for inspection on debug
338 log.debug("parsed componentInstInputsMap={}", ReflectionToStringBuilder.toString(componentInstInputsMap));
340 Either<List<InputDefinition>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
341 .createListInput(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
342 if (inputPropertiesRes.isRight()) {
343 log.debug("failed to create list input for service: {}", componentId);
344 return buildErrorResponse(inputPropertiesRes.right().value());
346 Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
347 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
348 } catch (Exception e) {
349 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create list input for service with id: " + componentId);
350 log.debug("createListInput failed with exception", e);
351 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
356 @Path("/{componentType}/{componentId}/delete/{inputId}/input")
357 @Operation(description = "Delete input from service", method = "DELETE", summary = "Delete service input", responses = {
358 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
359 @ApiResponse(responseCode = "200", description = "Input deleted"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
360 @ApiResponse(responseCode = "404", description = "Input not found")})
361 public Response deleteInput(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
362 @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
363 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
364 @Parameter(description = "Service Input to be deleted", required = true) String componentInstInputsMapObj) {
365 String url = request.getMethod() + " " + request.getRequestURI();
366 log.debug(START_HANDLE_REQUEST_OF, url);
367 loggerSupportability.log(LoggerSupportabilityActions.DELETE_INPUTS, StatusCode.STARTED, "Starting to delete Inputs for component {} ",
368 componentId + " by " + userId);
370 InputDefinition deleteInput = inputsBusinessLogic.deleteInput(componentId, userId, inputId);
371 loggerSupportability.log(LoggerSupportabilityActions.DELETE_INPUTS, StatusCode.COMPLETE, "Ended delete Inputs for component {} ",
372 componentId + " by " + userId);
373 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteInput);
374 } catch (ComponentException e) {
375 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete input for service + " + componentId + " + with id: " + inputId);
376 log.debug("Delete input failed with exception", e);
382 * Gets a specific data type associated with a component.
384 * @param componentType the container type (service, resource, ...)
385 * @param componentId the container ID
386 * @param dataTypeName the data type name
387 * @param request HttpServletRequest object
388 * @return the data type info
391 @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
392 @Operation(description = "Get data type in service", method = "GET", summary = "Get data type in service", responses = {
393 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = DataTypeDefinition.class)))),
394 @ApiResponse(responseCode = "200", description = "Data type found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
395 @ApiResponse(responseCode = "404", description = "Data type not found")})
396 public Response getDataType(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
397 @PathParam("dataTypeName") final String dataTypeName, @Context final HttpServletRequest request) {
398 String url = request.getMethod() + " " + request.getRequestURI();
399 log.debug("(getDataType) Start handle request of {}", url);
402 Either<DataTypeDefinition, StorageOperationStatus> getResult = businessLogic.getPrivateDataType(componentId, dataTypeName);
403 if (getResult.isRight()) {
404 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
405 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
407 Object json = RepresentationUtils.toRepresentation(getResult.left().value());
408 return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
409 } catch (Exception e) {
410 BeEcompErrorManager.getInstance()
411 .logBeRestApiGeneralError("Get data type from service + " + componentId + " + with name: " + dataTypeName);
412 log.debug("Get data type failed with exception", e);
413 response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
419 * Gets a list of data types which a component has.
421 * @param componentType the container type (service, resource, ...)
422 * @param componentId the container ID
423 * @param request HttpServletRequest object
424 * @return the list of data types in the component
427 @Path("/{componentType}/{componentId}/dataTypes")
428 @Operation(description = "Get data types that service has", method = "GET", summary = "Get data types in service", responses = {
429 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
430 @ApiResponse(responseCode = "200", description = "Data type found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
431 @ApiResponse(responseCode = "404", description = "Component not found")})
432 public Response getDataTypes(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
433 @Context final HttpServletRequest request) {
434 ComponentsUtils componentsUtils = getComponentsUtils();
435 String url = request.getMethod() + " " + request.getRequestURI();
436 log.debug("(getDataType) Start handle request of {}", url);
439 Either<List<DataTypeDefinition>, StorageOperationStatus> getResult = businessLogic.getPrivateDataTypes(componentId);
440 if (getResult.isRight()) {
441 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
442 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
444 Object json = RepresentationUtils.toRepresentation(getResult.left().value());
445 return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
446 } catch (Exception e) {
447 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId);
448 log.debug("Get data type failed with exception", e);
449 response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
455 * Deletes a data type from a component.
457 * @param componentType the container type (service, resource, ...)
458 * @param componentId the container ID
459 * @param dataTypeName the data type name to be deleted
460 * @param request HttpServletRequest object
461 * @return operation result
464 @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
465 @Operation(description = "Delete data type from service", method = "DELETE", summary = "Delete service input", responses = {
466 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
467 @ApiResponse(responseCode = "200", description = "Data type deleted"),
468 @ApiResponse(responseCode = "403", description = "Restricted operation"),
469 @ApiResponse(responseCode = "404", description = "Data type not found")})
470 public Response deleteDataType(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
471 @PathParam("dataTypeName") final String dataTypeName, @Context final HttpServletRequest request) {
472 ComponentsUtils componentsUtils = getComponentsUtils();
473 String url = request.getMethod() + " " + request.getRequestURI();
474 log.debug(START_HANDLE_REQUEST_OF, url);
477 Either<DataTypeDefinition, StorageOperationStatus> deleteResult = businessLogic.deletePrivateDataType(componentId, dataTypeName);
478 if (deleteResult.isRight()) {
479 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteResult.right().value());
480 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
482 Object json = RepresentationUtils.toRepresentation(deleteResult.left().value());
483 return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
484 } catch (Exception e) {
485 BeEcompErrorManager.getInstance()
486 .logBeRestApiGeneralError("Delete data type for service + " + componentId + " + with name: " + dataTypeName);
487 log.debug("Delete data type failed with exception", e);
488 response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
493 private Response createInput(String componentId, String data, HttpServletRequest request, String userId) {
494 String url = request.getMethod() + " " + request.getRequestURI();
495 log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
496 loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS, StatusCode.STARTED, "CREATE_INPUTS by user {} ", userId);
498 Either<Map<String, InputDefinition>, ActionStatus> inputDefinition = getInputModel(componentId, data);
499 if (inputDefinition.isRight()) {
500 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(inputDefinition.right().value());
501 return buildErrorResponse(responseFormat);
503 Map<String, InputDefinition> inputs = inputDefinition.left().value();
504 if (inputs == null || inputs.size() != 1) {
505 log.info("Input content is invalid - {}", data);
506 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
507 return buildErrorResponse(responseFormat);
509 Map.Entry<String, InputDefinition> entry = inputs.entrySet().iterator().next();
510 InputDefinition newInputDefinition = entry.getValue();
511 newInputDefinition.setParentUniqueId(componentId);
512 String inputName = newInputDefinition.getName();
513 Either<EntryData<String, InputDefinition>, ResponseFormat> addInputEither = inputsBusinessLogic
514 .addInputToComponent(componentId, inputName, newInputDefinition, userId);
515 if (addInputEither.isRight()) {
516 return buildErrorResponse(addInputEither.right().value());
518 loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS, StatusCode.COMPLETE, "CREATE_INPUTS by user {} ", userId);
519 return buildOkResponse(newInputDefinition);
520 } catch (Exception e) {
521 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_INPUT);
522 log.debug("create input failed with exception", e);
523 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
524 return buildErrorResponse(responseFormat);