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.google.gson.Gson;
25 import com.google.gson.GsonBuilder;
26 import com.google.gson.reflect.TypeToken;
27 import com.jcabi.aspects.Loggable;
28 import fj.data.Either;
29 import io.swagger.annotations.*;
30 import org.apache.commons.io.IOUtils;
31 import org.apache.commons.lang.StringUtils;
32 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
33 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
34 import org.openecomp.sdc.be.config.BeEcompErrorManager;
35 import org.openecomp.sdc.be.dao.api.ActionStatus;
36 import org.openecomp.sdc.be.datamodel.ForwardingPaths;
37 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
38 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
39 import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
40 import org.openecomp.sdc.be.info.GroupDefinitionInfo;
41 import org.openecomp.sdc.be.model.*;
42 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
43 import org.openecomp.sdc.common.api.Constants;
44 import org.openecomp.sdc.common.datastructure.Wrapper;
45 import org.openecomp.sdc.common.log.wrappers.Logger;
46 import org.openecomp.sdc.exception.ResponseFormat;
48 import javax.inject.Singleton;
49 import javax.servlet.ServletContext;
50 import javax.servlet.http.HttpServletRequest;
52 import javax.ws.rs.core.Context;
53 import javax.ws.rs.core.MediaType;
54 import javax.ws.rs.core.Response;
55 import java.io.InputStream;
56 import java.lang.reflect.Type;
57 import java.util.ArrayList;
58 import java.util.Arrays;
59 import java.util.List;
63 * Root resource (exposed at "/" path) .json
65 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
67 @Api(value = "Resource Instance Servlet")
69 public class ComponentInstanceServlet extends AbstractValidationsServlet {
71 private static final String FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID = "Failed to get properties of component instance ID: {} in {} with ID: {}";
72 private static final String GET_GROUP_ARTIFACT_BY_ID = "getGroupArtifactById";
73 private static final String GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION = "getGroupArtifactById unexpected exception";
74 private static final String GET_START_HANDLE_REQUEST_OF = "(GET) Start handle request of {}";
75 private static final String START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS = "Start handle request of updateResourceInstanceProperty. Received property is {}";
76 private static final String UPDATE_RESOURCE_INSTANCE = "Update Resource Instance";
77 private static final String RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE = "Resource Instance - updateResourceInstance";
78 private static final String UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION = "update resource instance with exception";
79 private static final String FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT = "Failed to convert received data to BE format.";
80 private static final String EMPTY_BODY_WAS_SENT = "Empty body was sent.";
81 private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
82 private static final String UNSUPPORTED_COMPONENT_TYPE = "Unsupported component type {}";
83 private static final Logger log = Logger.getLogger(ComponentInstanceServlet.class);
84 private static final Type PROPERTY_CONSTRAINT_TYPE = new TypeToken<PropertyConstraint>() {}.getType();
85 private static final Gson gsonDeserializer = new GsonBuilder().registerTypeAdapter(PROPERTY_CONSTRAINT_TYPE, new PropertyConstraintDeserialiser()).create();
88 @Path("/{containerComponentType}/{componentId}/resourceInstance")
89 @Consumes(MediaType.APPLICATION_JSON)
90 @Produces(MediaType.APPLICATION_JSON)
91 @ApiOperation(value = "Create ComponentInstance", httpMethod = "POST", notes = "Returns created ComponentInstance", response = Response.class)
92 @ApiResponses(value = { @ApiResponse(code = 201, message = "Component created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
93 @ApiResponse(code = 409, message = "Component instance already exist") })
94 public Response createComponentInstance(@ApiParam(value = "RI object to be created", required = true) String data, @PathParam("componentId") final String containerComponentId,
95 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
96 @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId, @Context final HttpServletRequest request) {
97 ServletContext context = request.getSession().getServletContext();
101 ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
102 componentInstance.setInvariantName(null);
103 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
104 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
105 if (componentInstanceLogic == null) {
106 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
107 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
109 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
111 if (actionResponse.isRight()) {
112 return buildErrorResponse(actionResponse.right().value());
114 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
116 } catch (Exception e) {
117 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Component Instance");
118 log.debug("create component instance failed with exception", e);
119 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
124 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}")
125 @Consumes(MediaType.APPLICATION_JSON)
126 @Produces(MediaType.APPLICATION_JSON)
127 @ApiOperation(value = "Update resource instance", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
128 @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource instance updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
129 public Response updateComponentInstanceMetadata(@PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId,
130 @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
131 + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
132 @Context final HttpServletRequest request) {
133 ServletContext context = request.getSession().getServletContext();
135 String url = request.getMethod() + " " + request.getRequestURI();
136 log.debug(START_HANDLE_REQUEST_OF, url);
139 log.debug(START_HANDLE_REQUEST_OF, url);
141 InputStream inputStream = request.getInputStream();
143 byte[] bytes = IOUtils.toByteArray(inputStream);
145 if (bytes == null || bytes.length == 0) {
146 log.info(EMPTY_BODY_WAS_SENT);
147 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
150 String userId = request.getHeader(Constants.USER_ID_HEADER);
152 String data = new String(bytes);
153 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
154 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
155 if (componentInstanceLogic == null) {
156 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
157 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
159 Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
161 if (convertResponse.isRight()) {
162 BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
163 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
164 return buildErrorResponse(convertResponse.right().value());
167 ComponentInstance resourceInstance = convertResponse.left().value();
168 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstanceMetadata(containerComponentType, componentId, componentInstanceId, userId, resourceInstance);
170 if (actionResponse.isRight()) {
171 return buildErrorResponse(actionResponse.right().value());
173 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
175 } catch (Exception e) {
176 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
177 log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
178 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
184 @Path("/{containerComponentType}/{componentId}/resourceInstance/multipleComponentInstance")
185 @Consumes(MediaType.APPLICATION_JSON)
186 @Produces(MediaType.APPLICATION_JSON)
187 @ApiOperation(value = "Update resource instance multiple component", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
188 @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource instance updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
189 public Response updateMultipleComponentInstance(@PathParam("componentId") final String componentId,
190 @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
191 + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
192 @Context final HttpServletRequest request, @ApiParam(value = "Component Instance JSON Array", required = true) final String componentInstanceJsonArray) {
194 ServletContext context = request.getSession().getServletContext();
195 String url = request.getMethod() + " " + request.getRequestURI();
196 log.debug(START_HANDLE_REQUEST_OF, url);
199 log.debug(START_HANDLE_REQUEST_OF, url);
201 if (componentInstanceJsonArray == null || componentInstanceJsonArray.length() == 0) {
202 log.info("Empty JSON list was sent.");
203 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
206 String userId = request.getHeader(Constants.USER_ID_HEADER);
208 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
209 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
210 if (componentInstanceLogic == null) {
211 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
212 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
215 Either<List<ComponentInstance>, ResponseFormat> convertResponse = convertToMultipleResourceInstance(componentInstanceJsonArray);
217 if (convertResponse.isRight()) {
218 // Using both ECOMP error methods, show to Sofer
219 BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
220 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
221 return buildErrorResponse(convertResponse.right().value());
224 List<ComponentInstance> componentInstanceList = convertResponse.left().value();
226 Either<List<ComponentInstance>, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstance(containerComponentType, componentId, userId, componentInstanceList, true);
228 if (actionResponse.isRight()) {
229 return buildErrorResponse(actionResponse.right().value());
232 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
234 } catch (Exception e) {
235 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
236 log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
237 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
243 @Path("/{containerComponentType}/{componentId}/resourceInstance/{resourceInstanceId}")
244 @Consumes(MediaType.APPLICATION_JSON)
245 @Produces(MediaType.APPLICATION_JSON)
246 @ApiOperation(value = "Delete ResourceInstance", httpMethod = "DELETE", notes = "Returns delete resourceInstance", response = Response.class)
247 @ApiResponses(value = { @ApiResponse(code = 201, message = "ResourceInstance deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
248 public Response deleteResourceInstance(@PathParam("componentId") final String componentId, @PathParam("resourceInstanceId") final String resourceInstanceId,
249 @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
250 + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
251 @Context final HttpServletRequest request) {
252 ServletContext context = request.getSession().getServletContext();
253 String url = request.getMethod() + " " + request.getRequestURI();
254 Response response = null;
256 log.debug(START_HANDLE_REQUEST_OF, url);
257 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
258 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
259 if (componentInstanceLogic == null) {
260 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
261 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
263 String userId = request.getHeader(Constants.USER_ID_HEADER);
264 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId);
266 if (actionResponse.isRight()) {
267 response = buildErrorResponse(actionResponse.right().value());
269 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
272 } catch (Exception e) {
273 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource Instance");
274 log.debug("delete resource instance with exception", e);
275 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
279 @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + "," + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true)
281 @Path("/{containerComponentType}/{componentId}/resourceInstance/associate")
282 @Consumes(MediaType.APPLICATION_JSON)
283 @Produces(MediaType.APPLICATION_JSON)
284 @ApiOperation(value = "Associate RI to RI", httpMethod = "POST", notes = "Returns created RelationshipInfo", response = Response.class)
285 @ApiResponses(value = { @ApiResponse(code = 201, message = "Relationship created"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
286 @ApiResponse(code = 409, message = "Relationship already exist") })
287 public Response associateRIToRI(@ApiParam(value = "unique id of the container component") @PathParam("componentId") final String componentId,
288 @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
289 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam("containerComponentType") final String containerComponentType,
290 @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "RelationshipInfo", required = true) String data, @Context final HttpServletRequest request) {
291 ServletContext context = request.getSession().getServletContext();
293 String url = request.getMethod() + " " + request.getRequestURI();
294 log.debug(START_HANDLE_REQUEST_OF, url);
295 Response response = null;
299 log.debug(START_HANDLE_REQUEST_OF, url);
301 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
302 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
303 if (componentInstanceLogic == null) {
304 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
305 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
308 Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
310 Either<RequirementCapabilityRelDef, ResponseFormat> resultOp;
311 if (regInfoW.isRight()) {
312 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - associateRIToRI");
313 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
314 resultOp = Either.right(regInfoW.right().value());
316 RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
317 requirementDef.setOriginUI(true);
318 resultOp = componentInstanceLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum);
321 Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = resultOp;
323 if (actionResponse.isRight()) {
324 response = buildErrorResponse(actionResponse.right().value());
326 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
330 } catch (Exception e) {
331 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Associate Resource Instance");
332 log.debug("associate resource instance to another RI with exception", e);
333 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
338 @Path("/{containerComponentType}/{componentId}/resourceInstance/dissociate")
339 @Consumes(MediaType.APPLICATION_JSON)
340 @Produces(MediaType.APPLICATION_JSON)
341 @ApiOperation(value = "Dissociate RI from RI", httpMethod = "PUT", notes = "Returns deleted RelationshipInfo", response = Response.class)
342 @ApiResponses(value = { @ApiResponse(code = 201, message = "Relationship deleted"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
343 public Response dissociateRIFromRI(
344 @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
345 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam("containerComponentType") final String containerComponentType,
346 @ApiParam(value = "unique id of the container component") @PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
347 @ApiParam(value = "RelationshipInfo", required = true) String data, @Context final HttpServletRequest request) {
348 ServletContext context = request.getSession().getServletContext();
350 String url = request.getMethod() + " " + request.getRequestURI();
351 log.debug(START_HANDLE_REQUEST_OF, url);
355 log.debug(START_HANDLE_REQUEST_OF, url);
357 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
358 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
359 if (componentInstanceLogic == null) {
360 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
361 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
364 Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
365 if (regInfoW.isRight()) {
366 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - dissociateRIFromRI");
367 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
368 return buildErrorResponse(regInfoW.right().value());
371 RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
372 Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum);
374 if (actionResponse.isRight()) {
375 return buildErrorResponse(actionResponse.right().value());
377 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
379 } catch (Exception e) {
380 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Dissociate Resource Instance");
381 log.debug("dissociate resource instance from service failed with exception", e);
382 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
387 @Path("/{containerComponentType}/{componentId}/resourceInstance/createAndAssociate")
388 @Consumes(MediaType.APPLICATION_JSON)
389 @Produces(MediaType.APPLICATION_JSON)
390 @ApiOperation(value = "Create RI and associate RI to RI", httpMethod = "POST", notes = "Returns created RI and RelationshipInfo", response = Response.class)
391 @ApiResponses(value = { @ApiResponse(code = 201, message = "RI created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
392 @ApiResponse(code = 409, message = "Relationship already exist") })
393 public Response createAndAssociateRIToRI(@PathParam("componentId") final String componentId,
394 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
395 @Context final HttpServletRequest request) {
396 ServletContext context = request.getSession().getServletContext();
398 String url = request.getMethod() + " " + request.getRequestURI();
399 log.debug(START_HANDLE_REQUEST_OF, url);
402 log.debug(START_HANDLE_REQUEST_OF, url);
404 InputStream inputStream = request.getInputStream();
406 byte[] bytes = IOUtils.toByteArray(inputStream);
408 if (bytes == null || bytes.length == 0) {
409 log.info(EMPTY_BODY_WAS_SENT);
410 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
413 String userId = request.getHeader(Constants.USER_ID_HEADER);
415 String data = new String(bytes);
417 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
418 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
419 if (componentInstanceLogic == null) {
420 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
421 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
424 Either<CreateAndAssotiateInfo, ActionStatus> convertStatus = convertJsonToObject(data, CreateAndAssotiateInfo.class);
425 if (convertStatus.isRight()) {
426 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - createAndAssociateRIToRI");
427 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
428 Either<Object, ResponseFormat> formattedResponse = Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
429 return buildErrorResponse(formattedResponse.right().value());
432 CreateAndAssotiateInfo createAndAssotiateInfo = convertStatus.left().value();
433 RequirementCapabilityRelDef requirementDef = createAndAssotiateInfo.getAssociate();
434 requirementDef.setOriginUI(true);
435 Either<CreateAndAssotiateInfo, ResponseFormat> actionResponse = componentInstanceLogic.createAndAssociateRIToRI(containerComponentType, componentId, userId, createAndAssotiateInfo);
437 if (actionResponse.isRight()) {
438 return buildErrorResponse(actionResponse.right().value());
440 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
441 } catch (Exception e) {
442 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create and Associate Resource Instance");
443 log.debug("create and associate RI failed with exception", e);
444 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
449 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/properties")
450 @Consumes(MediaType.APPLICATION_JSON)
451 @Produces(MediaType.APPLICATION_JSON)
452 @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
453 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
454 public Response updateResourceInstanceProperties(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
455 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
456 @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
457 @Context final HttpServletRequest request, @ApiParam(value = "Component Instance Properties JSON Array", required = true) final String componentInstancePropertiesJsonArray) {
459 String url = request.getMethod() + " " + request.getRequestURI();
460 log.debug(START_HANDLE_REQUEST_OF, url);
463 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
464 List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
465 if (errorWrapper.isEmpty()) {
466 Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties(componentInstancePropertiesJsonArray);
467 if (propertiesToUpdateEither.isRight()) {
468 errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
470 propertiesToUpdate = propertiesToUpdateEither.left().value();
474 if (!errorWrapper.isEmpty()) {
475 return buildErrorResponse(errorWrapper.getInnerElement());
478 log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, propertiesToUpdate);
480 ServletContext context = request.getSession().getServletContext();
482 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
483 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
484 if (componentInstanceLogic == null) {
485 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
486 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
489 Either<List<ComponentInstanceProperty>, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdatePropertiesValues(componentTypeEnum, componentId, componentInstanceId, propertiesToUpdate, userId);
491 if (actionResponse.isRight()) {
492 return buildErrorResponse(actionResponse.right().value());
495 List<ComponentInstanceProperty> resourceInstanceProperties = actionResponse.left().value();
496 ObjectMapper mapper = new ObjectMapper();
497 String result = mapper.writeValueAsString(resourceInstanceProperties);
498 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
500 } catch (Exception e) {
501 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
502 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
508 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/inputs")
509 @Consumes(MediaType.APPLICATION_JSON)
510 @Produces(MediaType.APPLICATION_JSON)
511 @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
512 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
513 public Response updateResourceInstanceInput(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
514 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
515 @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
516 @Context final HttpServletRequest request, @ApiParam(value = "Component Instance Properties JSON Array", required = true) final String componentInstanceInputsJsonArray) {
518 String url = request.getMethod() + " " + request.getRequestURI();
519 log.debug(START_HANDLE_REQUEST_OF, url);
522 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
523 List<ComponentInstanceInput> inputsToUpdate = new ArrayList<>();
524 if (errorWrapper.isEmpty()) {
525 Either<List<ComponentInstanceInput>, ResponseFormat> inputsToUpdateEither = convertMultipleInputs(componentInstanceInputsJsonArray);
526 if (inputsToUpdateEither.isRight()) {
527 errorWrapper.setInnerElement(inputsToUpdateEither.right().value());
529 inputsToUpdate = inputsToUpdateEither.left().value();
532 if (!errorWrapper.isEmpty()) {
533 return buildErrorResponse(errorWrapper.getInnerElement());
536 log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, inputsToUpdate);
538 ServletContext context = request.getSession().getServletContext();
540 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
541 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
542 if (componentInstanceLogic == null) {
543 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
544 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
547 Either<List<ComponentInstanceInput>, ResponseFormat> actionResponse =
548 componentInstanceLogic.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, componentInstanceId, inputsToUpdate, userId);
550 if (actionResponse.isRight()) {
551 return buildErrorResponse(actionResponse.right().value());
554 List<ComponentInstanceInput> resourceInstanceInput = actionResponse.left().value();
555 ObjectMapper mapper = new ObjectMapper();
556 String result = mapper.writeValueAsString(resourceInstanceInput);
557 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
559 } catch (Exception e) {
560 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
561 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
567 * Updates ResourceInstance Attribute
570 * @param containerComponentType
571 * @param componentInstanceId
577 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/attribute")
578 @Consumes(MediaType.APPLICATION_JSON)
579 @Produces(MediaType.APPLICATION_JSON)
580 @ApiOperation(value = "Update resource instance attribute", httpMethod = "POST", notes = "Returns updated resource instance attribute", response = Response.class)
581 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
582 public Response updateResourceInstanceAttribute(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
583 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
584 @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
585 @Context final HttpServletRequest request) {
587 String url = request.getMethod() + " " + request.getRequestURI();
588 log.debug(START_HANDLE_REQUEST_OF, url);
592 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
593 Wrapper<String> dataWrapper = new Wrapper<>();
594 Wrapper<ComponentInstanceProperty> attributeWrapper = new Wrapper<>();
595 Wrapper<ComponentInstanceBusinessLogic> blWrapper = new Wrapper<>();
597 validateInputStream(request, dataWrapper, errorWrapper);
599 if (errorWrapper.isEmpty()) {
600 validateClassParse(dataWrapper.getInnerElement(), attributeWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
603 if (errorWrapper.isEmpty()) {
604 validateComponentInstanceBusinessLogic(request, containerComponentType, blWrapper, errorWrapper);
607 if (errorWrapper.isEmpty()) {
608 ComponentInstanceBusinessLogic componentInstanceLogic = blWrapper.getInnerElement();
609 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
610 log.debug("Start handle request of ComponentInstanceAttribute. Received attribute is {}", attributeWrapper.getInnerElement());
611 Either<ComponentInstanceProperty, ResponseFormat> eitherAttribute = componentInstanceLogic.createOrUpdateAttributeValue(componentTypeEnum, componentId, componentInstanceId, attributeWrapper.getInnerElement(), userId);
612 if (eitherAttribute.isRight()) {
613 errorWrapper.setInnerElement(eitherAttribute.right().value());
615 attributeWrapper.setInnerElement(eitherAttribute.left().value());
619 return buildResponseFromElement(errorWrapper, attributeWrapper);
621 } catch (Exception e) {
622 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
623 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
629 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/property/{propertyId}")
630 @Consumes(MediaType.APPLICATION_JSON)
631 @Produces(MediaType.APPLICATION_JSON)
632 @ApiOperation(value = "Update resource instance", httpMethod = "DELETE", notes = "Returns deleted resource instance property", response = Response.class)
633 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
634 public Response deleteResourceInstanceProperty(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
635 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
636 @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "property id") @PathParam("propertyId") final String propertyId,
637 @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
639 ServletContext context = request.getSession().getServletContext();
641 String url = request.getMethod() + " " + request.getRequestURI();
642 log.debug(START_HANDLE_REQUEST_OF, url);
645 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
646 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
647 if (componentInstanceLogic == null) {
648 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
649 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
652 Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId);
653 if (actionResponse.isRight()) {
654 return buildErrorResponse(actionResponse.right().value());
656 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
657 } catch (Exception e) {
658 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
659 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
665 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/changeVersion")
666 @Consumes(MediaType.APPLICATION_JSON)
667 @Produces(MediaType.APPLICATION_JSON)
668 @ApiOperation(value = "Update resource instance", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
669 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
670 public Response changeResourceInstanceVersion(@PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId,
671 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
672 @Context final HttpServletRequest request) {
673 ServletContext context = request.getSession().getServletContext();
675 String url = request.getMethod() + " " + request.getRequestURI();
676 log.debug(START_HANDLE_REQUEST_OF, url);
677 try ( InputStream inputStream = request.getInputStream()) {
679 byte[] bytes = IOUtils.toByteArray(inputStream);
681 if (bytes == null || bytes.length == 0) {
682 log.info(EMPTY_BODY_WAS_SENT);
683 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
686 String userId = request.getHeader(Constants.USER_ID_HEADER);
688 String data = new String(bytes);
690 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
691 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
692 if (componentInstanceLogic == null) {
693 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
694 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
697 Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
699 if (convertResponse.isRight()) {
700 BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
701 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
702 return buildErrorResponse(convertResponse.right().value());
705 ComponentInstance newResourceInstance = convertResponse.left().value();
706 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance);
708 if (actionResponse.isRight()) {
709 return buildErrorResponse(actionResponse.right().value());
711 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
713 } catch (Exception e) {
714 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
715 log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
716 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
722 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}/property")
723 @Consumes(MediaType.APPLICATION_JSON)
724 @Produces(MediaType.APPLICATION_JSON)
725 @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
726 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
727 public Response updateGroupInstanceProperty(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
728 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
729 @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "group instance id") @PathParam("groupInstanceId") final String groupInstanceId,
730 @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
732 String url = request.getMethod() + " " + request.getRequestURI();
733 log.debug(START_HANDLE_REQUEST_OF, url);
736 Wrapper<String> dataWrapper = new Wrapper<>();
737 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
738 Wrapper<ComponentInstanceProperty> propertyWrapper = new Wrapper<>();
740 validateInputStream(request, dataWrapper, errorWrapper);
742 if (errorWrapper.isEmpty()) {
743 validateClassParse(dataWrapper.getInnerElement(), propertyWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
746 if (!errorWrapper.isEmpty()) {
747 return buildErrorResponse(errorWrapper.getInnerElement());
750 ComponentInstanceProperty property = propertyWrapper.getInnerElement();
752 log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, property);
754 ServletContext context = request.getSession().getServletContext();
756 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
757 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
758 if (componentInstanceLogic == null) {
759 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
760 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
763 Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, componentInstanceId, groupInstanceId, property, userId);
765 if (actionResponse.isRight()) {
766 return buildErrorResponse(actionResponse.right().value());
769 ComponentInstanceProperty resourceInstanceProperty = actionResponse.left().value();
770 ObjectMapper mapper = new ObjectMapper();
771 String result = mapper.writeValueAsString(resourceInstanceProperty);
772 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
774 } catch (Exception e) {
775 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
776 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
782 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstId}")
783 @Consumes(MediaType.APPLICATION_JSON)
784 @Produces(MediaType.APPLICATION_JSON)
785 @ApiOperation(value = "Get group artifacts ", httpMethod = "GET", notes = "Returns artifacts metadata according to groupInstId", response = Resource.class)
786 @ApiResponses(value = { @ApiResponse(code = 200, message = "group found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Group not found") })
787 public Response getGroupArtifactById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId,
788 @PathParam("groupInstId") final String groupInstId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
789 ServletContext context = request.getSession().getServletContext();
790 String url = request.getMethod() + " " + request.getRequestURI();
791 log.debug(GET_START_HANDLE_REQUEST_OF, url);
795 GroupBusinessLogic businessLogic = this.getGroupBL(context);
796 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
797 Either<GroupDefinitionInfo, ResponseFormat> actionResponse = businessLogic.getGroupInstWithArtifactsById(componentTypeEnum, componentId, componentInstanceId, groupInstId, userId, false);
799 if (actionResponse.isRight()) {
800 log.debug("failed to get all non abstract {}", containerComponentType);
801 return buildErrorResponse(actionResponse.right().value());
804 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
806 } catch (Exception e) {
807 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
808 log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
809 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
816 @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/properties")
817 @Consumes(MediaType.APPLICATION_JSON)
818 @Produces(MediaType.APPLICATION_JSON)
819 @ApiOperation(value = "Get component instance properties", httpMethod = "GET", notes = "Returns component instance properties", response = Response.class)
820 @ApiResponses(value = { @ApiResponse(code = 200, message = "Properties found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component/Component Instance - not found") })
821 public Response getInstancePropertiesById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("containerComponentId") final String containerComponentId,
822 @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
824 ServletContext context = request.getSession().getServletContext();
825 String url = request.getMethod() + " " + request.getRequestURI();
826 log.debug(GET_START_HANDLE_REQUEST_OF, url);
829 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
830 ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context);
832 Either<List<ComponentInstanceProperty>, ResponseFormat> componentInstancePropertiesById = componentInstanceBL.getComponentInstancePropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, userId);
834 if (componentInstancePropertiesById.isRight()) {
835 log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId);
836 return buildErrorResponse(componentInstancePropertiesById.right().value());
839 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById.left().value());
840 } catch (Exception e) {
841 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
842 log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
843 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
850 @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
851 @Consumes(MediaType.APPLICATION_JSON)
852 @Produces(MediaType.APPLICATION_JSON)
853 @ApiOperation(value = "Get component instance capability properties", httpMethod = "GET", notes = "Returns component instance capability properties", response = Response.class)
854 @ApiResponses(value = { @ApiResponse(code = 200, message = "Properties found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component/Component Instance/Capability - not found") })
855 public Response getInstanceCapabilityPropertiesById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("containerComponentId") final String containerComponentId,
856 @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId, @PathParam("capabilityType") final String capabilityType, @PathParam("capabilityName") final String capabilityName, @PathParam("ownerId") final String ownerId, @Context final HttpServletRequest request,
857 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
859 ServletContext context = request.getSession().getServletContext();
860 String url = request.getMethod() + " " + request.getRequestURI();
861 log.debug(GET_START_HANDLE_REQUEST_OF, url);
864 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
865 ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context);
867 Either<List<ComponentInstanceProperty>, ResponseFormat> componentInstancePropertiesById = componentInstanceBL.getComponentInstanceCapabilityPropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId,
868 capabilityType, capabilityName, ownerId, userId);
870 if (componentInstancePropertiesById.isRight()) {
871 log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId);
872 return buildErrorResponse(componentInstancePropertiesById.right().value());
875 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById.left().value());
876 } catch (Exception e) {
877 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
878 log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
879 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
886 @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
887 @Consumes(MediaType.APPLICATION_JSON)
888 @Produces(MediaType.APPLICATION_JSON)
889 @ApiOperation(value = "Update Instance Capabilty Property", httpMethod = "PUT", notes = "Returns updated property", response = Response.class)
890 @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource instance capabilty property updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
891 @ApiResponse(code = 404, message = "Component/Component Instance/Capability - not found") })
892 public Response updateInstanceCapabilityProperty(@PathParam("containerComponentType") final String containerComponentType, @PathParam("containerComponentId") final String containerComponentId,
893 @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId, @PathParam("capabilityType") final String capabilityType, @PathParam("capabilityName") final String capabilityName, @PathParam("ownerId") final String ownerId,
894 @ApiParam(value = "Instance capabilty property to update", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
895 ServletContext context = request.getSession().getServletContext();
896 String url = request.getMethod() + " " + request.getRequestURI();
897 log.debug("(PUT) Start handle request of {}", url);
899 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
900 List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
901 if (errorWrapper.isEmpty()) {
902 Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties(data);
903 if (propertiesToUpdateEither.isRight()) {
904 errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
906 propertiesToUpdate = propertiesToUpdateEither.left().value();
910 if (!errorWrapper.isEmpty()) {
911 return buildErrorResponse(errorWrapper.getInnerElement());
914 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
915 ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context);
917 Either<List<ComponentInstanceProperty>, ResponseFormat> updateCICapProperty = componentInstanceBL.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, propertiesToUpdate, userId);
919 if (updateCICapProperty.isRight()) {
920 log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId);
921 return buildErrorResponse(updateCICapProperty.right().value());
924 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updateCICapProperty.left().value());
925 } catch (Exception e) {
926 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
927 log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
928 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
933 @Path("/{containerComponentType}/{containerComponentId}/serviceProxy")
934 @Consumes(MediaType.APPLICATION_JSON)
935 @Produces(MediaType.APPLICATION_JSON)
936 @ApiOperation(value = "Create service proxy", httpMethod = "POST", notes = "Returns created service proxy", response = Response.class)
937 @ApiResponses(value = { @ApiResponse(code = 201, message = "Service proxy created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
938 @ApiResponse(code = 409, message = "Service proxy already exist") })
939 public Response createServiceProxy(@ApiParam(value = "RI object to be created", required = true) String data, @PathParam("containerComponentId") final String containerComponentId,
940 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
941 @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId, @Context final HttpServletRequest request) {
942 ServletContext context = request.getSession().getServletContext();
946 ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
947 componentInstance.setInvariantName(null);
948 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
949 if (componentTypeEnum != ComponentTypeEnum.SERVICE) {
950 log.debug("Unsupported container component type {}", containerComponentType);
951 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
953 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
954 if (componentInstanceLogic == null) {
955 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
956 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
958 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.createServiceProxy();
960 if (actionResponse.isRight()) {
961 return buildErrorResponse(actionResponse.right().value());
963 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
965 } catch (Exception e) {
966 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create service proxy");
967 log.debug("Create service proxy failed with exception", e);
968 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
973 @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}")
974 @Consumes(MediaType.APPLICATION_JSON)
975 @Produces(MediaType.APPLICATION_JSON)
976 @ApiOperation(value = "Delete service proxy", httpMethod = "DELETE", notes = "Returns delete service proxy", response = Response.class)
977 @ApiResponses(value = { @ApiResponse(code = 201, message = "Service proxy deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
978 public Response deleteServiceProxy(@PathParam("containerComponentId") final String containerComponentId, @PathParam("serviceProxyId") final String serviceProxyId,
979 @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
980 + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
981 @Context final HttpServletRequest request) {
982 ServletContext context = request.getSession().getServletContext();
983 String url = request.getMethod() + " " + request.getRequestURI();
984 Response response = null;
986 log.debug(START_HANDLE_REQUEST_OF, url);
987 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
988 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
989 if (componentInstanceLogic == null) {
990 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
991 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
993 String userId = request.getHeader(Constants.USER_ID_HEADER);
994 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.deleteServiceProxy();
996 if (actionResponse.isRight()) {
997 response = buildErrorResponse(actionResponse.right().value());
999 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
1002 } catch (Exception e) {
1003 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete service proxy");
1004 log.debug("Delete service proxy failed with exception", e);
1005 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
1010 @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}/changeVersion/{newServiceId}")
1011 @Consumes(MediaType.APPLICATION_JSON)
1012 @Produces(MediaType.APPLICATION_JSON)
1013 @ApiOperation(value = "Update service proxy with new version", httpMethod = "POST", notes = "Returns updated service proxy", response = Response.class)
1014 @ApiResponses(value = { @ApiResponse(code = 201, message = "Service proxy created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
1015 public Response changeServiceProxyVersion(@PathParam("containerComponentId") final String containerComponentId, @PathParam("serviceProxyId") final String serviceProxyId,
1016 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
1017 @Context final HttpServletRequest request) {
1018 ServletContext context = request.getSession().getServletContext();
1020 String url = request.getMethod() + " " + request.getRequestURI();
1021 log.debug(START_HANDLE_REQUEST_OF, url);
1024 String userId = request.getHeader(Constants.USER_ID_HEADER);
1026 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1027 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
1028 if (componentInstanceLogic == null) {
1029 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
1030 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1032 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.changeServiceProxyVersion();
1034 if (actionResponse.isRight()) {
1035 return buildErrorResponse(actionResponse.right().value());
1037 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
1039 } catch (Exception e) {
1040 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update service proxy with new version");
1041 log.debug("Update service proxy with new version failed with exception", e);
1042 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
1046 * REST API GET relation by Id
1047 * Allows to get relation contained in specified component according to received Id
1048 * @param containerComponentType
1049 * @param componentId
1056 @Path("/{containerComponentType}/{componentId}/relationId/{relationId}")
1057 @Consumes(MediaType.APPLICATION_JSON)
1058 @Produces(MediaType.APPLICATION_JSON)
1059 @ApiOperation(value = "Get relation", httpMethod = "GET", notes = "Returns relation metadata according to relationId", response = Resource.class)
1060 @ApiResponses(value = { @ApiResponse(code = 200, message = "relation found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Relation not found") })
1061 public Response getRelationById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("componentId") final String componentId,
1062 @PathParam("relationId") final String relationId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
1064 ServletContext context = request.getSession().getServletContext();
1065 String url = request.getMethod() + " " + request.getRequestURI();
1066 log.debug(GET_START_HANDLE_REQUEST_OF, url);
1068 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1069 if (componentTypeEnum == null) {
1070 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
1071 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1073 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
1075 Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceLogic.getRelationById(componentId, relationId, userId, componentTypeEnum);
1076 if (actionResponse.isRight()) {
1077 return buildErrorResponse(actionResponse.right().value());
1079 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
1080 } catch (Exception e) {
1081 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getRelationById");
1082 log.debug("getRelationById unexpected exception", e);
1083 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
1087 private Either<ComponentInstance, ResponseFormat> convertToResourceInstance(String data) {
1089 Either<ComponentInstance, ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), ComponentInstance.class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1090 if (convertStatus.isRight()) {
1091 return Either.right(convertStatus.right().value());
1093 ComponentInstance resourceInstanceInfo = convertStatus.left().value();
1095 return Either.left(resourceInstanceInfo);
1098 private Either<List<ComponentInstance>, ResponseFormat> convertToMultipleResourceInstance(String dataList) {
1100 Either<ComponentInstance[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstance[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1101 if (convertStatus.isRight()) {
1102 return Either.right(convertStatus.right().value());
1105 return Either.left(Arrays.asList(convertStatus.left().value()));
1108 private Either<List<ComponentInstanceProperty>, ResponseFormat> convertMultipleProperties(String dataList) {
1109 if (StringUtils.isEmpty(dataList)) {
1110 return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
1112 Either<ComponentInstanceProperty[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceProperty[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1113 if (convertStatus.isRight()) {
1114 return Either.right(convertStatus.right().value());
1116 return Either.left(Arrays.asList(convertStatus.left().value()));
1119 private Either<List<ComponentInstanceInput>, ResponseFormat> convertMultipleInputs(String dataList) {
1120 if (StringUtils.isEmpty(dataList)) {
1121 return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
1123 Either<ComponentInstanceInput[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceInput[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1124 if (convertStatus.isRight()) {
1125 return Either.right(convertStatus.right().value());
1127 return Either.left(Arrays.asList(convertStatus.left().value()));
1131 private Either<RequirementCapabilityRelDef, ResponseFormat> convertToRequirementCapabilityRelDef(String data) {
1133 Either<RequirementCapabilityRelDef, ActionStatus> convertStatus = convertJsonToObject(data, RequirementCapabilityRelDef.class);
1134 if (convertStatus.isRight()) {
1135 return Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
1137 RequirementCapabilityRelDef requirementCapabilityRelDef = convertStatus.left().value();
1138 return Either.left(requirementCapabilityRelDef);
1141 private <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
1143 log.trace("convert json to object. json=\n {}", data);
1145 t = gsonDeserializer.fromJson(data, clazz);
1147 BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
1148 log.debug("object is null after converting from json");
1149 return Either.right(ActionStatus.INVALID_CONTENT);
1151 return Either.left(t);
1152 } catch (Exception e) {
1154 BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
1155 log.debug("failed to convert from json", e);
1156 return Either.right(ActionStatus.INVALID_CONTENT);
1162 @Path("/{containerComponentType}/{componentId}/paths-to-delete")
1163 @Produces(MediaType.APPLICATION_JSON)
1164 @ApiOperation(value = "Check if forwarding path to delete on version change", httpMethod = "GET", notes = "Returns forwarding paths to delete",
1165 response = Response.class)
1166 public Response changeResourceInstanceVersion( @PathParam("componentId") String componentId,
1167 @QueryParam("componentInstanceId") final String oldComponentInstanceId,
1168 @QueryParam("newComponentInstanceId") final String newComponentInstanceId,
1169 @ApiParam(value = "valid values: resources / services",
1170 allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME)
1171 @PathParam("containerComponentType") final String containerComponentType,
1172 @Context final HttpServletRequest request) {
1173 if (oldComponentInstanceId == null){
1174 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_OLD_COMPONENT_INSTANCE));
1176 if (newComponentInstanceId == null){
1177 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_NEW_COMPONENT_INSTANCE));
1179 ServletContext context = request.getSession().getServletContext();
1181 String url = request.getMethod() + " " + request.getRequestURI();
1182 log.debug(START_HANDLE_REQUEST_OF, url);
1183 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1184 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
1185 if (componentInstanceLogic == null) {
1186 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
1187 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1189 ComponentInstance newComponentInstance;
1190 if(StringUtils.isNotEmpty(newComponentInstanceId)){
1191 newComponentInstance=new ComponentInstance();
1192 newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,newComponentInstanceId);
1194 log.error("missing component id");
1195 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_DATA));
1197 Either<Set<String>,ResponseFormat> actionResponse= componentInstanceLogic.forwardingPathOnVersionChange(
1198 containerComponentType,componentId,oldComponentInstanceId,newComponentInstance);
1199 if (actionResponse.isRight()) {
1200 return buildErrorResponse(actionResponse.right().value());
1202 ForwardingPaths forwardingPaths=new ForwardingPaths();
1203 forwardingPaths.setForwardingPathToDelete(actionResponse.left().value());
1204 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), forwardingPaths);