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=========================================================
21 package org.openecomp.sdc.be.servlets;
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.tags.Tag;
35 import io.swagger.v3.oas.annotations.tags.Tags;
36 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
37 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
38 import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic;
39 import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
40 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
41 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
42 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
43 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
44 import org.openecomp.sdc.be.config.BeEcompErrorManager;
45 import org.openecomp.sdc.be.dao.api.ActionStatus;
46 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
47 import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
48 import org.openecomp.sdc.be.impl.ComponentsUtils;
49 import org.openecomp.sdc.be.impl.ServletUtils;
50 import org.openecomp.sdc.be.model.ComponentInstListInput;
51 import org.openecomp.sdc.be.model.ComponentInstanceInput;
52 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
53 import org.openecomp.sdc.be.model.DataTypeDefinition;
54 import org.openecomp.sdc.be.model.InputDefinition;
55 import org.openecomp.sdc.be.model.Resource;
56 import org.openecomp.sdc.be.model.User;
57 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
58 import org.openecomp.sdc.be.resources.data.EntryData;
59 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
60 import org.openecomp.sdc.be.user.UserBusinessLogic;
61 import org.openecomp.sdc.common.api.Constants;
62 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
63 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
64 import org.openecomp.sdc.common.log.enums.StatusCode;
65 import org.openecomp.sdc.common.log.wrappers.Logger;
66 import org.openecomp.sdc.exception.ResponseFormat;
67 import org.springframework.stereotype.Controller;
69 import javax.inject.Inject;
70 import javax.servlet.http.HttpServletRequest;
71 import javax.ws.rs.Consumes;
72 import javax.ws.rs.DELETE;
73 import javax.ws.rs.GET;
74 import javax.ws.rs.HeaderParam;
75 import javax.ws.rs.POST;
76 import javax.ws.rs.Path;
77 import javax.ws.rs.PathParam;
78 import javax.ws.rs.Produces;
79 import javax.ws.rs.core.Context;
80 import javax.ws.rs.core.MediaType;
81 import javax.ws.rs.core.Response;
82 import java.io.IOException;
83 import java.util.Arrays;
84 import java.util.List;
87 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
88 @Tags({@Tag(name = "SDCE-2 APIs")})
89 @Server(url = "/sdc2/rest")
92 @Consumes(MediaType.APPLICATION_JSON)
93 @Produces(MediaType.APPLICATION_JSON)
94 public class InputsServlet extends AbstractValidationsServlet {
96 private static final Logger log = Logger.getLogger(InputsServlet.class);
97 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(InputsServlet.class.getName());
98 private static final String START_HANDLE_REQUEST_OF = "(get) Start handle request of {}";
99 private static final String CREATE_INPUT = "CreateInput";
101 private final DataTypeBusinessLogic businessLogic;
102 private final InputsBusinessLogic inputsBusinessLogic;
105 public InputsServlet(UserBusinessLogic userBusinessLogic,
106 InputsBusinessLogic inputsBusinessLogic,
107 ComponentInstanceBusinessLogic componentInstanceBL,
108 ComponentsUtils componentsUtils, ServletUtils servletUtils,
109 ResourceImportManager resourceImportManager,
110 DataTypeBusinessLogic dataTypeBusinessLogic) {
111 super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
112 this.inputsBusinessLogic = inputsBusinessLogic;
113 this.businessLogic = dataTypeBusinessLogic;
117 @Path("/{containerComponentType}/{componentId}/update/inputs")
118 @Operation(description = "Update resource inputs", method = "POST", summary = "Returns updated input",
119 responses = {@ApiResponse(
120 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
121 @ApiResponse(responseCode = "200", description = "Input updated"),
122 @ApiResponse(responseCode = "403", description = "Restricted operation"),
123 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
124 public Response updateComponentInputs(@Parameter(description = "valid values: resources / services",
125 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
126 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
127 @PathParam("componentId") final String componentId,
128 @Parameter(description = "json describe the input", required = true) String data,
129 @Context final HttpServletRequest request) throws JsonProcessingException {
131 String url = request.getMethod() + " " + request.getRequestURI();
132 log.debug("Start handle request of {}", url);
133 String userId = request.getHeader(Constants.USER_ID_HEADER);
136 User modifier = new User();
137 modifier.setUserId(userId);
138 log.debug("modifier id is {}", userId);
140 Either<InputDefinition[], ResponseFormat> inputsEither = getComponentsUtils()
141 .convertJsonToObjectUsingObjectMapper(data, modifier, InputDefinition[].class,
142 AuditingActionEnum.UPDATE_RESOURCE_METADATA, ComponentTypeEnum.SERVICE);
143 if(inputsEither.isRight()){
144 log.debug("Failed to convert data to input definition. Status is {}", inputsEither.right().value());
145 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
147 List<InputDefinition> inputsToUpdate = Arrays.asList(inputsEither.left().value());
149 log.debug("Start handle request of updateComponentInputs. Received inputs are {}", inputsToUpdate);
151 ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(containerComponentType);
153 if (businessLogic == null) {
154 log.debug("Unsupported component type {}", containerComponentType);
155 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR));
158 Either<List<InputDefinition>, ResponseFormat> actionResponse = inputsBusinessLogic.updateInputsValue(componentType, componentId, inputsToUpdate, userId, true, false);
160 if (actionResponse.isRight()) {
161 return buildErrorResponse(actionResponse.right().value());
164 List<InputDefinition> componentInputs = actionResponse.left().value();
165 ObjectMapper mapper = new ObjectMapper();
166 String result = mapper.writeValueAsString(componentInputs);
167 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
170 catch (Exception e) {
171 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
177 @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{originComponentUid}/inputs")
178 @Operation(description = "Get Inputs only", method = "GET", summary = "Returns Inputs list", responses = {
179 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
180 @ApiResponse(responseCode = "200", description = "Component found"),
181 @ApiResponse(responseCode = "403", description = "Restricted operation"),
182 @ApiResponse(responseCode = "404", description = "Component not found")})
183 public Response getComponentInstanceInputs(@PathParam("componentType") final String componentType,
184 @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
185 @PathParam("originComponentUid") final String originComponentUid, @Context final HttpServletRequest request,
186 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
188 String url = request.getMethod() + " " + request.getRequestURI();
189 log.debug(START_HANDLE_REQUEST_OF, url);
192 Either<List<ComponentInstanceInput>, ResponseFormat> inputsResponse = inputsBusinessLogic.getComponentInstanceInputs(userId, componentId, instanceId);
193 if (inputsResponse.isRight()) {
194 log.debug("failed to get component instance inputs {}", componentType);
195 return buildErrorResponse(inputsResponse.right().value());
197 Object inputs = RepresentationUtils.toRepresentation(inputsResponse.left().value());
198 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), inputs);
200 } catch (Exception e) {
201 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Inputs " + componentType);
202 log.debug("getInputs failed with exception", e);
208 @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{inputId}/properties")
209 @Operation(description = "Get properties", method = "GET", summary = "Returns properties list", responses = {
210 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
211 @ApiResponse(responseCode = "200", description = "Component found"),
212 @ApiResponse(responseCode = "403", description = "Restricted operation"),
213 @ApiResponse(responseCode = "404", description = "Component not found")})
214 public Response getInputPropertiesForComponentInstance(@PathParam("componentType") final String componentType,
215 @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
216 @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
217 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
219 String url = request.getMethod() + " " + request.getRequestURI();
220 log.debug(START_HANDLE_REQUEST_OF, url);
223 Either<List<ComponentInstanceProperty>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
224 .getComponentInstancePropertiesByInputId(userId, componentId, instanceId, inputId);
225 if (inputPropertiesRes.isRight()) {
226 log.debug("failed to get properties of input: {}, with instance id: {}", inputId, instanceId);
227 return buildErrorResponse(inputPropertiesRes.right().value());
229 Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
230 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
232 } catch (Exception e) {
233 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Properites by input id: " + inputId + " for instance with id: " + instanceId);
234 log.debug("getInputPropertiesForComponentInstance failed with exception", e);
240 @Path("/{componentType}/{componentId}/inputs/{inputId}/inputs")
241 @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = {
242 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
243 @ApiResponse(responseCode = "200", description = "Component found"),
244 @ApiResponse(responseCode = "403", description = "Restricted operation"),
245 @ApiResponse(responseCode = "404", description = "Component not found")})
246 public Response getInputsForComponentInput(@PathParam("componentType") final String componentType,
247 @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
248 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
250 String url = request.getMethod() + " " + request.getRequestURI();
251 log.debug(START_HANDLE_REQUEST_OF, url);
253 Either<List<ComponentInstanceInput>, ResponseFormat> inputsRes =
254 inputsBusinessLogic.getInputsForComponentInput(userId, componentId, inputId);
256 if (inputsRes.isRight()) {
257 log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
258 return buildErrorResponse(inputsRes.right().value());
260 Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
261 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
263 } catch (Exception e) {
264 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get inputs by input id: " + inputId + " for component with id: " + componentId);
265 log.debug("getInputsForComponentInput failed with exception", e);
271 @Path("/{componentType}/{componentId}/inputs/{inputId}")
272 @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = {
273 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
274 @ApiResponse(responseCode = "200", description = "Component found"),
275 @ApiResponse(responseCode = "403", description = "Restricted operation"),
276 @ApiResponse(responseCode = "404", description = "Component not found")})
277 public Response getInputsAndPropertiesForComponentInput(@PathParam("componentType") final String componentType,
278 @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
279 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
281 String url = request.getMethod() + " " + request.getRequestURI();
282 log.debug(START_HANDLE_REQUEST_OF, url);
285 Either<InputDefinition, ResponseFormat> inputsRes =
286 inputsBusinessLogic.getInputsAndPropertiesForComponentInput(userId, componentId, inputId, false);
288 if (inputsRes.isRight()) {
289 log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
290 return buildErrorResponse(inputsRes.right().value());
292 Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
293 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
295 } catch (Exception e) {
296 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get inputs by input id: " + inputId + " for component with id: " + componentId);
297 log.debug("getInputsForComponentInput failed with exception", e);
302 private Either<ComponentInstListInput, ResponseFormat> parseToComponentInstListInput(String json, User user) {
303 return getComponentsUtils().convertJsonToObjectUsingObjectMapper(json, user, ComponentInstListInput.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
307 @Path("/{componentType}/{componentId}/create/inputs")
308 @Operation(description = "Create inputs on service", method = "POST", summary = "Return inputs list", responses = {
309 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
310 @ApiResponse(responseCode = "200", description = "Component found"),
311 @ApiResponse(responseCode = "403", description = "Restricted operation"),
312 @ApiResponse(responseCode = "404", description = "Component not found")})
313 public Response createMultipleInputs(@PathParam("componentType") final String componentType,
314 @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
315 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
316 @Parameter(description = "ComponentIns Inputs Object to be created",
317 required = true) String componentInstInputsMapObj) {
319 return super.declareProperties(userId, componentId, componentType, componentInstInputsMapObj,
320 DeclarationTypeEnum.INPUT, request);
324 @Path("/{componentType}/{componentId}/create/input")
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 createInput(@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) {
336 return createInput(componentId, componentInstInputsMapObj, request, userId);
340 * Creates a "list input" and updates given list of properties to get value from the input.
341 * also a data type which has same properties is created.
342 * the data type will be the entry_schema of the list input.
343 * @param componentType the container type (service, resource, ...)
344 * @param componentId the container ID
345 * @param request HttpServletRequest object
346 * @param userId the User ID
347 * @param componentInstInputsMapObj the list of properties to be declared and the "list input" to be created.
348 * the type of the input must be "list".
349 * schema.type of the input will be the name of new data type.
350 * @return the created input
353 @Path("/{componentType}/{componentId}/create/listInput")
354 @Operation(description = "Create a list input on service", method = "POST", summary = "Return input", responses = {
355 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
356 @ApiResponse(responseCode = "200", description = "Component found"),
357 @ApiResponse(responseCode = "403", description = "Restricted operation"),
358 @ApiResponse(responseCode = "404", description = "Component not found")})
359 public Response createListInput(@PathParam("componentType") final String componentType,
360 @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
361 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
362 @Parameter(description = "ComponentIns Inputs Object to be created",
363 required = true) String componentInstInputsMapObj) {
365 String url = request.getMethod() + " " + request.getRequestURI();
366 log.debug("#createListInput: Start handle request of {}", url);
369 User modifier = new User();
370 modifier.setUserId(userId);
371 log.debug("modifier id is {}", userId);
373 Either<ComponentInstListInput, ResponseFormat> componentInstInputsMapRes =
374 parseToComponentInstListInput(componentInstInputsMapObj, modifier);
375 if (componentInstInputsMapRes.isRight()) {
376 log.debug("failed to parse componentInstInputsMap");
377 return buildErrorResponse(componentInstInputsMapRes.right().value());
380 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
381 ComponentInstListInput componentInstInputsMap = componentInstInputsMapRes.left().value();
382 if (log.isDebugEnabled()) {
383 // for inspection on debug
384 log.debug("parsed componentInstInputsMap={}",
385 ReflectionToStringBuilder.toString(componentInstInputsMap));
388 Either<List<InputDefinition>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
389 .createListInput(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
390 if (inputPropertiesRes.isRight()) {
391 log.debug("failed to create list input for service: {}", componentId);
392 return buildErrorResponse(inputPropertiesRes.right().value());
394 Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
395 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
397 } catch (Exception e) {
398 BeEcompErrorManager.getInstance()
399 .logBeRestApiGeneralError("Create list input for service with id: " + componentId);
400 log.debug("createListInput failed with exception", e);
401 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
407 @Path("/{componentType}/{componentId}/delete/{inputId}/input")
408 @Operation(description = "Delete input from service", method = "DELETE", summary = "Delete service input",
409 responses = {@ApiResponse(
410 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
411 @ApiResponse(responseCode = "200", description = "Input deleted"),
412 @ApiResponse(responseCode = "403", description = "Restricted operation"),
413 @ApiResponse(responseCode = "404", description = "Input not found")})
414 public Response deleteInput(@PathParam("componentType") final String componentType,
415 @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
416 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
417 @Parameter(description = "Service Input to be deleted", required = true) String componentInstInputsMapObj) {
419 String url = request.getMethod() + " " + request.getRequestURI();
420 log.debug(START_HANDLE_REQUEST_OF, url);
421 loggerSupportability.log(LoggerSupportabilityActions.DELETE_INPUTS, StatusCode.STARTED,"Starting to delete Inputs for component {} ",componentId + " by " + userId );
424 InputDefinition deleteInput = inputsBusinessLogic.deleteInput(componentId, userId, inputId);
425 loggerSupportability.log(LoggerSupportabilityActions.DELETE_INPUTS, StatusCode.COMPLETE,"Ended delete Inputs for component {} ",componentId + " by " + userId );
426 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteInput);
427 } catch (ComponentException e){
428 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete input for service + " + componentId + " + with id: " + inputId);
429 log.debug("Delete input failed with exception", e);
435 * Gets a specific data type associated with a component.
436 * @param componentType the container type (service, resource, ...)
437 * @param componentId the container ID
438 * @param dataTypeName the data type name
439 * @param request HttpServletRequest object
440 * @return the data type info
443 @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
444 @Operation(description = "Get data type in service", method = "GET", summary = "Get data type in service",
445 responses = {@ApiResponse(content = @Content(
446 array = @ArraySchema(schema = @Schema(implementation = DataTypeDefinition.class)))),
447 @ApiResponse(responseCode = "200", description = "Data type found"),
448 @ApiResponse(responseCode = "403", description = "Restricted operation"),
449 @ApiResponse(responseCode = "404", description = "Data type not found")})
450 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
451 public Response getDataType(
452 @PathParam("componentType") final String componentType,
453 @PathParam("componentId") final String componentId,
454 @PathParam("dataTypeName") final String dataTypeName,
455 @Context final HttpServletRequest request
457 String url = request.getMethod() + " " + request.getRequestURI();
458 log.debug("(getDataType) Start handle request of {}", url);
462 Either<DataTypeDefinition, StorageOperationStatus> getResult = businessLogic.getPrivateDataType(componentId, dataTypeName);
463 if (getResult.isRight()) {
464 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
465 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
467 Object json = RepresentationUtils.toRepresentation(getResult.left().value());
468 return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
469 } catch (Exception e) {
470 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId + " + with name: " + dataTypeName);
471 log.debug("Get data type failed with exception", e);
472 response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
478 * Gets a list of data types which a component has.
479 * @param componentType the container type (service, resource, ...)
480 * @param componentId the container ID
481 * @param request HttpServletRequest object
482 * @return the list of data types in the component
485 @Path("/{componentType}/{componentId}/dataTypes")
486 @Operation(description = "Get data types that service has", method = "GET", summary = "Get data types in service",
487 responses = {@ApiResponse(
488 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
489 @ApiResponse(responseCode = "200", description = "Data type found"),
490 @ApiResponse(responseCode = "403", description = "Restricted operation"),
491 @ApiResponse(responseCode = "404", description = "Component not found")})
492 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
493 public Response getDataTypes(
494 @PathParam("componentType") final String componentType,
495 @PathParam("componentId") final String componentId,
496 @Context final HttpServletRequest request
498 ComponentsUtils componentsUtils = getComponentsUtils();
499 String url = request.getMethod() + " " + request.getRequestURI();
500 log.debug("(getDataType) Start handle request of {}", url);
504 Either<List<DataTypeDefinition>, StorageOperationStatus> getResult = businessLogic.getPrivateDataTypes(componentId);
505 if (getResult.isRight()) {
506 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
507 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
509 Object json = RepresentationUtils.toRepresentation(getResult.left().value());
510 return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
511 } catch (Exception e) {
512 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId);
513 log.debug("Get data type failed with exception", e);
514 response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
520 * Deletes a data type from a component.
521 * @param componentType the container type (service, resource, ...)
522 * @param componentId the container ID
523 * @param dataTypeName the data type name to be deleted
524 * @param request HttpServletRequest object
525 * @return operation result
528 @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
529 @Operation(description = "Delete data type from service", method = "DELETE", summary = "Delete service input",
530 responses = {@ApiResponse(
531 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
532 @ApiResponse(responseCode = "200", description = "Data type deleted"),
533 @ApiResponse(responseCode = "403", description = "Restricted operation"),
534 @ApiResponse(responseCode = "404", description = "Data type not found")})
535 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
536 public Response deleteDataType(
537 @PathParam("componentType") final String componentType,
538 @PathParam("componentId") final String componentId,
539 @PathParam("dataTypeName") final String dataTypeName,
540 @Context final HttpServletRequest request
542 ComponentsUtils componentsUtils = getComponentsUtils();
543 String url = request.getMethod() + " " + request.getRequestURI();
544 log.debug(START_HANDLE_REQUEST_OF, url);
548 Either<DataTypeDefinition, StorageOperationStatus> deleteResult = businessLogic.deletePrivateDataType(componentId, dataTypeName);
549 if (deleteResult.isRight()) {
550 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteResult.right().value());
551 return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
553 Object json = RepresentationUtils.toRepresentation(deleteResult.left().value());
554 return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
555 } catch (Exception e) {
556 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete data type for service + " + componentId + " + with name: " + dataTypeName);
557 log.debug("Delete data type failed with exception", e);
558 response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
563 private Response createInput(String componentId, String data, HttpServletRequest request,String userId) {
564 String url = request.getMethod() + " " + request.getRequestURI();
565 log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
566 loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS, StatusCode.STARTED,"CREATE_INPUTS by user {} ", userId);
569 Either<Map<String, InputDefinition>, ActionStatus> inputDefinition =
570 getInputModel(componentId, data);
571 if (inputDefinition.isRight()) {
572 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(inputDefinition.right().value());
573 return buildErrorResponse(responseFormat);
576 Map<String, InputDefinition> inputs = inputDefinition.left().value();
577 if (inputs == null || inputs.size() != 1) {
578 log.info("Input content is invalid - {}", data);
579 ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
580 return buildErrorResponse(responseFormat);
583 Map.Entry<String, InputDefinition> entry = inputs.entrySet().iterator().next();
584 InputDefinition newInputDefinition = entry.getValue();
585 newInputDefinition.setParentUniqueId(componentId);
586 String inputName = newInputDefinition.getName();
588 Either<EntryData<String, InputDefinition>, ResponseFormat> addInputEither =
589 inputsBusinessLogic.addInputToComponent(componentId, inputName, newInputDefinition, userId);
591 if(addInputEither.isRight()) {
592 return buildErrorResponse(addInputEither.right().value());
595 loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS, StatusCode.COMPLETE,"CREATE_INPUTS by user {} ", userId);
596 return buildOkResponse(newInputDefinition);
598 } catch (Exception e) {
599 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_INPUT);
600 log.debug("create input failed with exception", e);
601 ResponseFormat responseFormat =
602 getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
603 return buildErrorResponse(responseFormat);