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