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.aaf.AafPermission;
58 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
59 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
60 import org.openecomp.sdc.be.config.BeEcompErrorManager;
61 import org.openecomp.sdc.be.dao.api.ActionStatus;
62 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
63 import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
64 import org.openecomp.sdc.be.impl.ComponentsUtils;
65 import org.openecomp.sdc.be.impl.ServletUtils;
66 import org.openecomp.sdc.be.model.ComponentInstListInput;
67 import org.openecomp.sdc.be.model.ComponentInstanceInput;
68 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
69 import org.openecomp.sdc.be.model.DataTypeDefinition;
70 import org.openecomp.sdc.be.model.InputDefinition;
71 import org.openecomp.sdc.be.model.Resource;
72 import org.openecomp.sdc.be.model.User;
73 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
74 import org.openecomp.sdc.be.resources.data.EntryData;
75 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
76 import org.openecomp.sdc.common.api.Constants;
77 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
78 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
79 import org.openecomp.sdc.common.log.enums.StatusCode;
80 import org.openecomp.sdc.common.log.wrappers.Logger;
81 import org.openecomp.sdc.exception.ResponseFormat;
82 import org.springframework.stereotype.Controller;
84 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
85 @Tags({@Tag(name = "SDCE-2 APIs")})
86 @Server(url = "/sdc2/rest")
89 @Consumes(MediaType.APPLICATION_JSON)
90 @Produces(MediaType.APPLICATION_JSON)
91 public class InputsServlet extends AbstractValidationsServlet {
93 private static final Logger log = Logger.getLogger(InputsServlet.class);
94 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(InputsServlet.class.getName());
95 private static final String START_HANDLE_REQUEST_OF = "(get) Start handle request of {}";
96 private static final String CREATE_INPUT = "CreateInput";
97 private final DataTypeBusinessLogic businessLogic;
98 private final InputsBusinessLogic inputsBusinessLogic;
101 public InputsServlet(InputsBusinessLogic inputsBusinessLogic,
102 ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils, ServletUtils servletUtils,
103 ResourceImportManager resourceImportManager, DataTypeBusinessLogic dataTypeBusinessLogic) {
104 super(componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
105 this.inputsBusinessLogic = inputsBusinessLogic;
106 this.businessLogic = dataTypeBusinessLogic;
110 @Path("/{containerComponentType}/{componentId}/update/inputs")
111 @Operation(description = "Update resource inputs", method = "POST", summary = "Returns updated input", responses = {
112 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
113 @ApiResponse(responseCode = "200", description = "Input updated"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
114 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
115 public Response updateComponentInputs(
116 @Parameter(description = "valid values: resources / services", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
117 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
118 @PathParam("componentId") final String componentId, @Parameter(description = "json describe the input", required = true) String data,
119 @Context final HttpServletRequest request) throws JsonProcessingException {
120 String url = request.getMethod() + " " + request.getRequestURI();
121 log.debug("Start handle request of {}", url);
122 String userId = request.getHeader(Constants.USER_ID_HEADER);
124 User modifier = new User();
125 modifier.setUserId(userId);
126 log.debug("modifier id is {}", userId);
127 Either<InputDefinition[], ResponseFormat> inputsEither = getComponentsUtils()
128 .convertJsonToObjectUsingObjectMapper(data, modifier, InputDefinition[].class, AuditingActionEnum.UPDATE_RESOURCE_METADATA,
129 ComponentTypeEnum.SERVICE);
130 if (inputsEither.isRight()) {
131 log.debug("Failed to convert data to input definition. Status is {}", inputsEither.right().value());
132 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
134 List<InputDefinition> inputsToUpdate = Arrays.asList(inputsEither.left().value());
135 log.debug("Start handle request of updateComponentInputs. Received inputs are {}", inputsToUpdate);
136 ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(containerComponentType);
137 if (businessLogic == null) {
138 log.debug("Unsupported component type {}", containerComponentType);
139 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR));
141 Either<List<InputDefinition>, ResponseFormat> actionResponse = inputsBusinessLogic
142 .updateInputsValue(componentType, componentId, inputsToUpdate, userId, true);
143 if (actionResponse.isRight()) {
144 return buildErrorResponse(actionResponse.right().value());
146 List<InputDefinition> componentInputs = actionResponse.left().value();
147 ObjectMapper mapper = new ObjectMapper();
148 String result = mapper.writeValueAsString(componentInputs);
149 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
150 } catch (Exception e) {
151 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
157 @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{originComponentUid}/inputs")
158 @Operation(description = "Get Inputs only", method = "GET", summary = "Returns Inputs list", responses = {
159 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
160 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
161 @ApiResponse(responseCode = "404", description = "Component not found")})
162 public Response getComponentInstanceInputs(@PathParam("componentType") final String componentType,
163 @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
164 @PathParam("originComponentUid") final String originComponentUid,
165 @Context final HttpServletRequest request,
166 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
167 String url = request.getMethod() + " " + request.getRequestURI();
168 log.debug(START_HANDLE_REQUEST_OF, url);
170 Either<List<ComponentInstanceInput>, ResponseFormat> inputsResponse = inputsBusinessLogic
171 .getComponentInstanceInputs(userId, componentId, instanceId);
172 if (inputsResponse.isRight()) {
173 log.debug("failed to get component instance inputs {}", componentType);
174 return buildErrorResponse(inputsResponse.right().value());
176 Object inputs = RepresentationUtils.toRepresentation(inputsResponse.left().value());
177 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), inputs);
178 } catch (Exception e) {
179 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Inputs " + componentType);
180 log.debug("getInputs failed with exception", e);
186 @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{inputId}/properties")
187 @Operation(description = "Get properties", method = "GET", summary = "Returns properties list", responses = {
188 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
189 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
190 @ApiResponse(responseCode = "404", description = "Component not found")})
191 public Response getInputPropertiesForComponentInstance(@PathParam("componentType") final String componentType,
192 @PathParam("componentId") final String componentId,
193 @PathParam("instanceId") final String instanceId,
194 @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
195 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
196 String url = request.getMethod() + " " + request.getRequestURI();
197 log.debug(START_HANDLE_REQUEST_OF, url);
199 Either<List<ComponentInstanceProperty>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
200 .getComponentInstancePropertiesByInputId(userId, componentId, instanceId, inputId);
201 if (inputPropertiesRes.isRight()) {
202 log.debug("failed to get properties of input: {}, with instance id: {}", inputId, instanceId);
203 return buildErrorResponse(inputPropertiesRes.right().value());
205 Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
206 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
207 } catch (Exception e) {
208 BeEcompErrorManager.getInstance()
209 .logBeRestApiGeneralError("Get Properites by input id: " + inputId + " for instance with id: " + instanceId);
210 log.debug("getInputPropertiesForComponentInstance failed with exception", e);
216 @Path("/{componentType}/{componentId}/inputs/{inputId}/inputs")
217 @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = {
218 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
219 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
220 @ApiResponse(responseCode = "404", description = "Component not found")})
221 public Response getInputsForComponentInput(@PathParam("componentType") final String componentType,
222 @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
223 @Context final HttpServletRequest request,
224 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
225 String url = request.getMethod() + " " + request.getRequestURI();
226 log.debug(START_HANDLE_REQUEST_OF, url);
228 Either<List<ComponentInstanceInput>, ResponseFormat> inputsRes = inputsBusinessLogic
229 .getInputsForComponentInput(userId, componentId, inputId);
230 if (inputsRes.isRight()) {
231 log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
232 return buildErrorResponse(inputsRes.right().value());
234 Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
235 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
236 } catch (Exception e) {
237 BeEcompErrorManager.getInstance()
238 .logBeRestApiGeneralError("Get inputs by input id: " + inputId + " for component with id: " + componentId);
239 log.debug("getInputsForComponentInput failed with exception", e);
245 @Path("/{componentType}/{componentId}/inputs/{inputId}")
246 @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = {
247 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
248 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
249 @ApiResponse(responseCode = "404", description = "Component not found")})
250 public Response getInputsAndPropertiesForComponentInput(@PathParam("componentType") final String componentType,
251 @PathParam("componentId") final String componentId,
252 @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
253 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
254 String url = request.getMethod() + " " + request.getRequestURI();
255 log.debug(START_HANDLE_REQUEST_OF, url);
257 Either<InputDefinition, ResponseFormat> inputsRes = inputsBusinessLogic
258 .getInputsAndPropertiesForComponentInput(userId, componentId, inputId, false);
259 if (inputsRes.isRight()) {
260 log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
261 return buildErrorResponse(inputsRes.right().value());
263 Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
264 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
265 } catch (Exception e) {
266 BeEcompErrorManager.getInstance()
267 .logBeRestApiGeneralError("Get inputs by input id: " + inputId + " for component with id: " + componentId);
268 log.debug("getInputsForComponentInput failed with exception", e);
273 private Either<ComponentInstListInput, ResponseFormat> parseToComponentInstListInput(String json, User user) {
274 return getComponentsUtils().convertJsonToObjectUsingObjectMapper(json, user, ComponentInstListInput.class, AuditingActionEnum.CREATE_RESOURCE,
275 ComponentTypeEnum.SERVICE);
279 @Path("/{componentType}/{componentId}/create/inputs")
280 @Operation(description = "Create inputs on service", method = "POST", summary = "Return inputs list", responses = {
281 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
282 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
283 @ApiResponse(responseCode = "404", description = "Component not found")})
284 public Response createMultipleInputs(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
285 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
286 @Parameter(description = "ComponentIns Inputs Object to be created", required = true) String componentInstInputsMapObj) {
287 return super.declareProperties(userId, componentId, componentType, componentInstInputsMapObj, DeclarationTypeEnum.INPUT, request);
291 @Path("/{componentType}/{componentId}/create/input")
292 @Operation(description = "Create inputs on service", method = "POST", summary = "Return inputs list", responses = {
293 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
294 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
295 @ApiResponse(responseCode = "404", description = "Component not found")})
296 public Response createInput(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
297 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
298 @Parameter(description = "ComponentIns Inputs Object to be created", required = true) String componentInstInputsMapObj) {
299 return createInput(componentId, componentInstInputsMapObj, request, userId);
303 * 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.
304 * the data type will be the entry_schema of the list input.
306 * @param componentType the container type (service, resource, ...)
307 * @param componentId the container ID
308 * @param request HttpServletRequest object
309 * @param userId the User ID
310 * @param componentInstInputsMapObj the list of properties to be declared and the "list input" to be created. the type of the input must be
311 * "list". schema.type of the input will be the name of new data type.
312 * @return the created input
315 @Path("/{componentType}/{componentId}/create/listInput")
316 @Operation(description = "Create a list input on service", method = "POST", summary = "Return input", responses = {
317 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
318 @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
319 @ApiResponse(responseCode = "404", description = "Component not found")})
320 public Response createListInput(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
321 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
322 @Parameter(description = "ComponentIns Inputs Object to be created", required = true) String componentInstInputsMapObj) {
323 String url = request.getMethod() + " " + request.getRequestURI();
324 log.debug("#createListInput: Start handle request of {}", url);
327 User modifier = new User();
328 modifier.setUserId(userId);
329 log.debug("modifier id is {}", userId);
330 Either<ComponentInstListInput, ResponseFormat> componentInstInputsMapRes = parseToComponentInstListInput(componentInstInputsMapObj,
332 if (componentInstInputsMapRes.isRight()) {
333 log.debug("failed to parse componentInstInputsMap");
334 return buildErrorResponse(componentInstInputsMapRes.right().value());
336 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
337 ComponentInstListInput componentInstInputsMap = componentInstInputsMapRes.left().value();
338 if (log.isDebugEnabled()) {
339 // for inspection on debug
340 log.debug("parsed componentInstInputsMap={}", ReflectionToStringBuilder.toString(componentInstInputsMap));
342 Either<List<InputDefinition>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
343 .createListInput(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
344 if (inputPropertiesRes.isRight()) {
345 log.debug("failed to create list input for service: {}", componentId);
346 return buildErrorResponse(inputPropertiesRes.right().value());
348 Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
349 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
350 } catch (Exception e) {
351 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create list input for service with id: " + componentId);
352 log.debug("createListInput failed with exception", e);
353 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
358 @Path("/{componentType}/{componentId}/delete/{inputId}/input")
359 @Operation(description = "Delete input from service", method = "DELETE", summary = "Delete service input", responses = {
360 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
361 @ApiResponse(responseCode = "200", description = "Input deleted"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
362 @ApiResponse(responseCode = "404", description = "Input not found")})
363 public Response deleteInput(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
364 @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
365 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
366 @Parameter(description = "Service Input to be deleted", required = true) String componentInstInputsMapObj) {
367 String url = request.getMethod() + " " + request.getRequestURI();
368 log.debug(START_HANDLE_REQUEST_OF, url);
369 loggerSupportability.log(LoggerSupportabilityActions.DELETE_INPUTS, StatusCode.STARTED, "Starting to delete Inputs for component {} ",
370 componentId + " by " + userId);
372 InputDefinition deleteInput = inputsBusinessLogic.deleteInput(componentId, userId, inputId);
373 loggerSupportability.log(LoggerSupportabilityActions.DELETE_INPUTS, StatusCode.COMPLETE, "Ended delete Inputs for component {} ",
374 componentId + " by " + userId);
375 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteInput);
376 } catch (ComponentException e) {
377 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete input for service + " + componentId + " + with id: " + inputId);
378 log.debug("Delete input failed with exception", e);
384 * Gets a specific data type associated with a component.
386 * @param componentType the container type (service, resource, ...)
387 * @param componentId the container ID
388 * @param dataTypeName the data type name
389 * @param request HttpServletRequest object
390 * @return the data type info
393 @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
394 @Operation(description = "Get data type in service", method = "GET", summary = "Get data type in service", responses = {
395 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = DataTypeDefinition.class)))),
396 @ApiResponse(responseCode = "200", description = "Data type found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
397 @ApiResponse(responseCode = "404", description = "Data type not found")})
398 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
399 public Response getDataType(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
400 @PathParam("dataTypeName") final String dataTypeName, @Context final HttpServletRequest request) {
401 String url = request.getMethod() + " " + request.getRequestURI();
402 log.debug("(getDataType) Start handle request of {}", url);
405 Either<DataTypeDefinition, StorageOperationStatus> getResult = businessLogic.getPrivateDataType(componentId, dataTypeName);
406 if (getResult.isRight()) {
407 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
408 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
410 Object json = RepresentationUtils.toRepresentation(getResult.left().value());
411 return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
412 } catch (Exception e) {
413 BeEcompErrorManager.getInstance()
414 .logBeRestApiGeneralError("Get data type from service + " + componentId + " + with name: " + dataTypeName);
415 log.debug("Get data type failed with exception", e);
416 response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
422 * Gets a list of data types which a component has.
424 * @param componentType the container type (service, resource, ...)
425 * @param componentId the container ID
426 * @param request HttpServletRequest object
427 * @return the list of data types in the component
430 @Path("/{componentType}/{componentId}/dataTypes")
431 @Operation(description = "Get data types that service has", method = "GET", summary = "Get data types in service", responses = {
432 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
433 @ApiResponse(responseCode = "200", description = "Data type found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
434 @ApiResponse(responseCode = "404", description = "Component not found")})
435 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
436 public Response getDataTypes(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
437 @Context final HttpServletRequest request) {
438 ComponentsUtils componentsUtils = getComponentsUtils();
439 String url = request.getMethod() + " " + request.getRequestURI();
440 log.debug("(getDataType) Start handle request of {}", url);
443 Either<List<DataTypeDefinition>, StorageOperationStatus> getResult = businessLogic.getPrivateDataTypes(componentId);
444 if (getResult.isRight()) {
445 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
446 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
448 Object json = RepresentationUtils.toRepresentation(getResult.left().value());
449 return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
450 } catch (Exception e) {
451 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId);
452 log.debug("Get data type failed with exception", e);
453 response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
459 * Deletes a data type from a component.
461 * @param componentType the container type (service, resource, ...)
462 * @param componentId the container ID
463 * @param dataTypeName the data type name to be deleted
464 * @param request HttpServletRequest object
465 * @return operation result
468 @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
469 @Operation(description = "Delete data type from service", method = "DELETE", summary = "Delete service input", responses = {
470 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
471 @ApiResponse(responseCode = "200", description = "Data type deleted"),
472 @ApiResponse(responseCode = "403", description = "Restricted operation"),
473 @ApiResponse(responseCode = "404", description = "Data type not found")})
474 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
475 public Response deleteDataType(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
476 @PathParam("dataTypeName") final String dataTypeName, @Context final HttpServletRequest request) {
477 ComponentsUtils componentsUtils = getComponentsUtils();
478 String url = request.getMethod() + " " + request.getRequestURI();
479 log.debug(START_HANDLE_REQUEST_OF, url);
482 Either<DataTypeDefinition, StorageOperationStatus> deleteResult = businessLogic.deletePrivateDataType(componentId, dataTypeName);
483 if (deleteResult.isRight()) {
484 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteResult.right().value());
485 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
487 Object json = RepresentationUtils.toRepresentation(deleteResult.left().value());
488 return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
489 } catch (Exception e) {
490 BeEcompErrorManager.getInstance()
491 .logBeRestApiGeneralError("Delete data type for service + " + componentId + " + with name: " + dataTypeName);
492 log.debug("Delete data type failed with exception", e);
493 response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
498 private Response createInput(String componentId, String data, HttpServletRequest request, String userId) {
499 String url = request.getMethod() + " " + request.getRequestURI();
500 log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
501 loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS, StatusCode.STARTED, "CREATE_INPUTS by user {} ", userId);
503 Either<Map<String, InputDefinition>, ActionStatus> inputDefinition = getInputModel(componentId, data);
504 if (inputDefinition.isRight()) {
505 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(inputDefinition.right().value());
506 return buildErrorResponse(responseFormat);
508 Map<String, InputDefinition> inputs = inputDefinition.left().value();
509 if (inputs == null || inputs.size() != 1) {
510 log.info("Input content is invalid - {}", data);
511 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
512 return buildErrorResponse(responseFormat);
514 Map.Entry<String, InputDefinition> entry = inputs.entrySet().iterator().next();
515 InputDefinition newInputDefinition = entry.getValue();
516 newInputDefinition.setParentUniqueId(componentId);
517 String inputName = newInputDefinition.getName();
518 Either<EntryData<String, InputDefinition>, ResponseFormat> addInputEither = inputsBusinessLogic
519 .addInputToComponent(componentId, inputName, newInputDefinition, userId);
520 if (addInputEither.isRight()) {
521 return buildErrorResponse(addInputEither.right().value());
523 loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS, StatusCode.COMPLETE, "CREATE_INPUTS by user {} ", userId);
524 return buildOkResponse(newInputDefinition);
525 } catch (Exception e) {
526 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_INPUT);
527 log.debug("create input failed with exception", e);
528 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
529 return buildErrorResponse(responseFormat);