Sync Integ to Master
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / ComponentInstanceServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.servlets;
22
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.Api;
30 import io.swagger.annotations.ApiOperation;
31 import io.swagger.annotations.ApiParam;
32 import io.swagger.annotations.ApiResponse;
33 import io.swagger.annotations.ApiResponses;
34 import org.apache.commons.io.IOUtils;
35 import org.apache.commons.lang.StringUtils;
36 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
37 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
38 import org.openecomp.sdc.be.config.BeEcompErrorManager;
39 import org.openecomp.sdc.be.dao.api.ActionStatus;
40 import org.openecomp.sdc.be.datamodel.ForwardingPaths;
41 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
42 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
43 import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
44 import org.openecomp.sdc.be.info.GroupDefinitionInfo;
45 import org.openecomp.sdc.be.model.ComponentInstance;
46 import org.openecomp.sdc.be.model.ComponentInstanceInput;
47 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
48 import org.openecomp.sdc.be.model.PropertyConstraint;
49 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
50 import org.openecomp.sdc.be.model.Resource;
51 import org.openecomp.sdc.be.model.User;
52 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
53 import org.openecomp.sdc.common.api.Constants;
54 import org.openecomp.sdc.common.datastructure.Wrapper;
55 import org.openecomp.sdc.exception.ResponseFormat;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58
59 import javax.inject.Singleton;
60 import javax.servlet.ServletContext;
61 import javax.servlet.http.HttpServletRequest;
62 import javax.ws.rs.Consumes;
63 import javax.ws.rs.DELETE;
64 import javax.ws.rs.GET;
65 import javax.ws.rs.HeaderParam;
66 import javax.ws.rs.POST;
67 import javax.ws.rs.PUT;
68 import javax.ws.rs.Path;
69 import javax.ws.rs.PathParam;
70 import javax.ws.rs.Produces;
71 import javax.ws.rs.QueryParam;
72 import javax.ws.rs.core.Context;
73 import javax.ws.rs.core.MediaType;
74 import javax.ws.rs.core.Response;
75 import java.io.InputStream;
76 import java.lang.reflect.Type;
77 import java.util.ArrayList;
78 import java.util.Arrays;
79 import java.util.List;
80 import java.util.Set;
81
82 /**
83  * Root resource (exposed at "/" path) .json
84  */
85 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
86 @Path("/v1/catalog")
87 @Api(value = "Resource Instance Servlet")
88 @Singleton
89 public class ComponentInstanceServlet extends AbstractValidationsServlet {
90
91     private static final Logger log = LoggerFactory.getLogger(ComponentInstanceServlet.class);
92
93     Type constraintType = new TypeToken<PropertyConstraint>() {
94     }.getType();
95
96     Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
97
98     @POST
99     @Path("/{containerComponentType}/{componentId}/resourceInstance")
100     @Consumes(MediaType.APPLICATION_JSON)
101     @Produces(MediaType.APPLICATION_JSON)
102     @ApiOperation(value = "Create ComponentInstance", httpMethod = "POST", notes = "Returns created ComponentInstance", response = Response.class)
103     @ApiResponses(value = { @ApiResponse(code = 201, message = "Component created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
104             @ApiResponse(code = 409, message = "Component instance already exist") })
105     public Response createComponentInstance(@ApiParam(value = "RI object to be created", required = true) String data, @PathParam("componentId") final String containerComponentId,
106             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
107             @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId, @Context final HttpServletRequest request) {
108         ServletContext context = request.getSession().getServletContext();
109
110         try {
111
112             ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
113             componentInstance.setInvariantName(null);
114             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
115             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
116             if (componentInstanceLogic == null) {
117                 log.debug("Unsupported component type {}", containerComponentType);
118                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
119             }
120             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
121
122             if (actionResponse.isRight()) {
123                 return buildErrorResponse(actionResponse.right().value());
124             }
125             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
126
127         } catch (Exception e) {
128             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Component Instance");
129             log.debug("create component instance failed with exception", e);
130             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
131         }
132     }
133
134     @POST
135     @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}")
136     @Consumes(MediaType.APPLICATION_JSON)
137     @Produces(MediaType.APPLICATION_JSON)
138     @ApiOperation(value = "Update resource instance", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
139     @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource instance updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
140     public Response updateComponentInstanceMetadata(@PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId,
141             @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
142                     + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
143             @Context final HttpServletRequest request) {
144         ServletContext context = request.getSession().getServletContext();
145
146         String url = request.getMethod() + " " + request.getRequestURI();
147         log.debug("Start handle request of {}", url);
148         try {
149
150             log.debug("Start handle request of {}", url);
151
152             InputStream inputStream = request.getInputStream();
153
154             byte[] bytes = IOUtils.toByteArray(inputStream);
155
156             if (bytes == null || bytes.length == 0) {
157                 log.info("Empty body was sent.");
158                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
159             }
160
161             String userId = request.getHeader(Constants.USER_ID_HEADER);
162
163             String data = new String(bytes);
164             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
165             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
166             if (componentInstanceLogic == null) {
167                 log.debug("Unsupported component type {}", containerComponentType);
168                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
169             }
170             Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
171
172             if (convertResponse.isRight()) {
173                 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance");
174                 log.debug("Failed to convert received data to BE format.");
175                 return buildErrorResponse(convertResponse.right().value());
176             }
177
178             ComponentInstance resourceInstance = convertResponse.left().value();
179             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstanceMetadata(containerComponentType, componentId, componentInstanceId, userId, resourceInstance);
180
181             if (actionResponse.isRight()) {
182                 return buildErrorResponse(actionResponse.right().value());
183             }
184             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
185
186         } catch (Exception e) {
187             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Instance");
188             log.debug("update resource instance with exception", e);
189             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
190         }
191
192     }
193
194     @POST
195     @Path("/{containerComponentType}/{componentId}/resourceInstance/multipleComponentInstance")
196     @Consumes(MediaType.APPLICATION_JSON)
197     @Produces(MediaType.APPLICATION_JSON)
198     @ApiOperation(value = "Update resource instance multiple component", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
199     @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource instance updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
200     public Response updateMultipleComponentInstance(@PathParam("componentId") final String componentId,
201             @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
202                     + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
203             @Context final HttpServletRequest request, @ApiParam(value = "Component Instance JSON Array", required = true) final String componentInstanceJsonArray) {
204
205         ServletContext context = request.getSession().getServletContext();
206         String url = request.getMethod() + " " + request.getRequestURI();
207         log.debug("Start handle request of {}", url);
208
209         try {
210             log.debug("Start handle request of {}", url);
211
212             if (componentInstanceJsonArray == null || componentInstanceJsonArray.length() == 0) {
213                 log.info("Empty JSON list was sent.");
214                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
215             }
216
217             String userId = request.getHeader(Constants.USER_ID_HEADER);
218
219             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
220             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
221             if (componentInstanceLogic == null) {
222                 log.debug("Unsupported component type {}", containerComponentType);
223                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
224             }
225
226             Either<List<ComponentInstance>, ResponseFormat> convertResponse = convertToMultipleResourceInstance(componentInstanceJsonArray);
227
228             if (convertResponse.isRight()) {
229                 // Using both ECOMP error methods, show to Sofer
230                 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance");
231                 log.debug("Failed to convert received data to BE format.");
232                 return buildErrorResponse(convertResponse.right().value());
233             }
234
235             List<ComponentInstance> componentInstanceList = convertResponse.left().value();
236
237             Either<List<ComponentInstance>, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstance(containerComponentType, componentId, userId, componentInstanceList, true, true);
238
239             if (actionResponse.isRight()) {
240                 return buildErrorResponse(actionResponse.right().value());
241             }
242
243             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
244
245         } catch (Exception e) {
246             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Instance");
247             log.debug("update resource instance with exception", e);
248             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
249         }
250
251     }
252
253     @DELETE
254     @Path("/{containerComponentType}/{componentId}/resourceInstance/{resourceInstanceId}")
255     @Consumes(MediaType.APPLICATION_JSON)
256     @Produces(MediaType.APPLICATION_JSON)
257     @ApiOperation(value = "Delete ResourceInstance", httpMethod = "DELETE", notes = "Returns delete resourceInstance", response = Response.class)
258     @ApiResponses(value = { @ApiResponse(code = 201, message = "ResourceInstance deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
259     public Response deleteResourceInstance(@PathParam("componentId") final String componentId, @PathParam("resourceInstanceId") final String resourceInstanceId,
260             @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
261                     + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
262             @Context final HttpServletRequest request) {
263         ServletContext context = request.getSession().getServletContext();
264         String url = request.getMethod() + " " + request.getRequestURI();
265         Response response = null;
266         try {
267             log.debug("Start handle request of {}", url);
268             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
269             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
270             if (componentInstanceLogic == null) {
271                 log.debug("Unsupported component type {}", containerComponentType);
272                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
273             }
274             String userId = request.getHeader(Constants.USER_ID_HEADER);
275             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId);
276
277             if (actionResponse.isRight()) {
278                 response = buildErrorResponse(actionResponse.right().value());
279             } else {
280                 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
281             }
282             return response;
283         } catch (Exception e) {
284             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource Instance");
285             log.debug("delete resource instance with exception", e);
286             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
287         }
288     }
289
290     @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + "," + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true)
291     @POST
292     @Path("/{containerComponentType}/{componentId}/resourceInstance/associate")
293     @Consumes(MediaType.APPLICATION_JSON)
294     @Produces(MediaType.APPLICATION_JSON)
295     @ApiOperation(value = "Associate RI to RI", httpMethod = "POST", notes = "Returns created RelationshipInfo", response = Response.class)
296     @ApiResponses(value = { @ApiResponse(code = 201, message = "Relationship created"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
297             @ApiResponse(code = 409, message = "Relationship already exist") })
298     public Response associateRIToRI(@ApiParam(value = "unique id of the container component") @PathParam("componentId") final String componentId,
299             @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
300                     + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam("containerComponentType") final String containerComponentType,
301             @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "RelationshipInfo", required = true) String data, @Context final HttpServletRequest request) {
302         ServletContext context = request.getSession().getServletContext();
303
304         String url = request.getMethod() + " " + request.getRequestURI();
305         log.debug("Start handle request of {}", url);
306         Response response = null;
307
308         try {
309
310             log.debug("Start handle request of {}", url);
311
312             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
313             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
314             if (componentInstanceLogic == null) {
315                 log.debug("Unsupported component type {}", containerComponentType);
316                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
317             }
318
319             Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
320
321             Either<RequirementCapabilityRelDef, ResponseFormat> resultOp;
322             if (regInfoW.isRight()) {
323                 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - associateRIToRI");
324                 log.debug("Failed to convert received data to BE format.");
325                 resultOp = Either.right(regInfoW.right().value());
326             } else {
327                 RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
328                 resultOp = componentInstanceLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum);
329             }
330
331             Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = resultOp;
332
333             if (actionResponse.isRight()) {
334                 response = buildErrorResponse(actionResponse.right().value());
335             } else {
336                 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
337             }
338             return response;
339
340         } catch (Exception e) {
341             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Associate Resource Instance");
342             log.debug("associate resource instance to another RI with exception", e);
343             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
344         }
345     }
346
347     @PUT
348     @Path("/{containerComponentType}/{componentId}/resourceInstance/dissociate")
349     @Consumes(MediaType.APPLICATION_JSON)
350     @Produces(MediaType.APPLICATION_JSON)
351     @ApiOperation(value = "Dissociate RI from RI", httpMethod = "PUT", notes = "Returns deleted RelationshipInfo", response = Response.class)
352     @ApiResponses(value = { @ApiResponse(code = 201, message = "Relationship deleted"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
353     public Response dissociateRIFromRI(
354             @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
355                     + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam("containerComponentType") final String containerComponentType,
356             @ApiParam(value = "unique id of the container component") @PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
357             @ApiParam(value = "RelationshipInfo", required = true) String data, @Context final HttpServletRequest request) {
358         ServletContext context = request.getSession().getServletContext();
359
360         String url = request.getMethod() + " " + request.getRequestURI();
361         log.debug("Start handle request of {}", url);
362
363         try {
364
365             log.debug("Start handle request of {}", url);
366
367             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
368             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
369             if (componentInstanceLogic == null) {
370                 log.debug("Unsupported component type {}", containerComponentType);
371                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
372             }
373
374             Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
375             if (regInfoW.isRight()) {
376                 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - dissociateRIFromRI");
377                 log.debug("Failed to convert received data to BE format.");
378                 return buildErrorResponse(regInfoW.right().value());
379             }
380
381             RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
382             Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum);
383
384             if (actionResponse.isRight()) {
385                 return buildErrorResponse(actionResponse.right().value());
386             }
387             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
388
389         } catch (Exception e) {
390             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Dissociate Resource Instance");
391             log.debug("dissociate resource instance from service failed with exception", e);
392             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
393         }
394     }
395
396     @POST
397     @Path("/{containerComponentType}/{componentId}/resourceInstance/createAndAssociate")
398     @Consumes(MediaType.APPLICATION_JSON)
399     @Produces(MediaType.APPLICATION_JSON)
400     @ApiOperation(value = "Create RI and associate RI to RI", httpMethod = "POST", notes = "Returns created RI and RelationshipInfo", response = Response.class)
401     @ApiResponses(value = { @ApiResponse(code = 201, message = "RI created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
402             @ApiResponse(code = 409, message = "Relationship already exist") })
403     public Response createAndAssociateRIToRI(@PathParam("componentId") final String componentId,
404             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
405             @Context final HttpServletRequest request) {
406         ServletContext context = request.getSession().getServletContext();
407
408         String url = request.getMethod() + " " + request.getRequestURI();
409         log.debug("Start handle request of {}", url);
410         try {
411
412             log.debug("Start handle request of {}", url);
413
414             InputStream inputStream = request.getInputStream();
415
416             byte[] bytes = IOUtils.toByteArray(inputStream);
417
418             if (bytes == null || bytes.length == 0) {
419                 log.info("Empty body was sent.");
420                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
421             }
422
423             String userId = request.getHeader(Constants.USER_ID_HEADER);
424
425             String data = new String(bytes);
426
427             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
428             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
429             if (componentInstanceLogic == null) {
430                 log.debug("Unsupported component type {}", containerComponentType);
431                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
432             }
433
434             Either<CreateAndAssotiateInfo, ActionStatus> convertStatus = convertJsonToObject(data, CreateAndAssotiateInfo.class);
435             if (convertStatus.isRight()) {
436                 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - createAndAssociateRIToRI");
437                 log.debug("Failed to convert received data to BE format.");
438                 Either<Object, ResponseFormat> formattedResponse = Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
439                 return buildErrorResponse(formattedResponse.right().value());
440             }
441
442             CreateAndAssotiateInfo createAndAssotiateInfo = convertStatus.left().value();
443             Either<CreateAndAssotiateInfo, ResponseFormat> actionResponse = componentInstanceLogic.createAndAssociateRIToRI(containerComponentType, componentId, userId, createAndAssotiateInfo);
444
445             if (actionResponse.isRight()) {
446                 return buildErrorResponse(actionResponse.right().value());
447             }
448             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
449         } catch (Exception e) {
450             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create and Associate Resource Instance");
451             log.debug("create and associate RI failed with exception", e);
452             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
453         }
454     }
455
456     @POST
457     @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/properties")
458     @Consumes(MediaType.APPLICATION_JSON)
459     @Produces(MediaType.APPLICATION_JSON)
460     @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
461     @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
462     public Response updateResourceInstanceProperties(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
463             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
464             @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,
465             @Context final HttpServletRequest request, @ApiParam(value = "Component Instance Properties JSON Array", required = true) final String componentInstancePropertiesJsonArray) {
466
467         String url = request.getMethod() + " " + request.getRequestURI();
468         log.debug("Start handle request of {}", url);
469
470         try {
471             Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
472             List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
473             if (errorWrapper.isEmpty()) {
474                 Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties(componentInstancePropertiesJsonArray);
475                 if (propertiesToUpdateEither.isRight()) {
476                     errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
477                 } else {
478                     propertiesToUpdate = propertiesToUpdateEither.left().value();
479                 }
480             }
481
482             if (!errorWrapper.isEmpty()) {
483                 return buildErrorResponse(errorWrapper.getInnerElement());
484             }
485
486             log.debug("Start handle request of updateResourceInstanceProperty. Received property is {}", propertiesToUpdate);
487
488             ServletContext context = request.getSession().getServletContext();
489
490             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
491             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
492             if (componentInstanceLogic == null) {
493                 log.debug("Unsupported component type {}", containerComponentType);
494                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
495             }
496
497             Either<List<ComponentInstanceProperty>, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdatePropertiesValues(componentTypeEnum, componentId, componentInstanceId, propertiesToUpdate, userId);
498
499             if (actionResponse.isRight()) {
500                 return buildErrorResponse(actionResponse.right().value());
501             }
502
503             List<ComponentInstanceProperty> resourceInstanceProperties = actionResponse.left().value();
504             ObjectMapper mapper = new ObjectMapper();
505             String result = mapper.writeValueAsString(resourceInstanceProperties);
506             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
507
508         } catch (Exception e) {
509             log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
510             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
511         }
512
513     }
514
515     @POST
516     @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/inputs")
517     @Consumes(MediaType.APPLICATION_JSON)
518     @Produces(MediaType.APPLICATION_JSON)
519     @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
520     @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
521     public Response updateResourceInstanceInput(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
522             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
523             @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,
524             @Context final HttpServletRequest request, @ApiParam(value = "Component Instance Properties JSON Array", required = true) final String componentInstanceInputsJsonArray) {
525
526         String url = request.getMethod() + " " + request.getRequestURI();
527         log.debug("Start handle request of {}", url);
528
529         try {
530             Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
531             List<ComponentInstanceInput> inputsToUpdate = new ArrayList<>();
532             if (errorWrapper.isEmpty()) {
533                 Either<List<ComponentInstanceInput>, ResponseFormat> inputsToUpdateEither = convertMultipleInputs(componentInstanceInputsJsonArray);
534                 if (inputsToUpdateEither.isRight()) {
535                     errorWrapper.setInnerElement(inputsToUpdateEither.right().value());
536                 } else {
537                     inputsToUpdate = inputsToUpdateEither.left().value();
538                 }
539             }
540             if (!errorWrapper.isEmpty()) {
541                 return buildErrorResponse(errorWrapper.getInnerElement());
542             }
543
544             log.debug("Start handle request of updateResourceInstanceProperty. Received property is {}", inputsToUpdate);
545
546             ServletContext context = request.getSession().getServletContext();
547
548             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
549             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
550             if (componentInstanceLogic == null) {
551                 log.debug("Unsupported component type {}", containerComponentType);
552                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
553             }
554
555             Either<List<ComponentInstanceInput>, ResponseFormat> actionResponse =
556                     componentInstanceLogic.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, componentInstanceId, inputsToUpdate, userId);
557
558             if (actionResponse.isRight()) {
559                 return buildErrorResponse(actionResponse.right().value());
560             }
561
562             List<ComponentInstanceInput> resourceInstanceInput = actionResponse.left().value();
563             ObjectMapper mapper = new ObjectMapper();
564             String result = mapper.writeValueAsString(resourceInstanceInput);
565             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
566
567         } catch (Exception e) {
568             log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
569             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
570         }
571
572     }
573
574     /**
575      * Updates ResourceInstance Attribute
576      *
577      * @param componentId
578      * @param containerComponentType
579      * @param componentInstanceId
580      * @param userId
581      * @param request
582      * @return
583      */
584     @POST
585     @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/attribute")
586     @Consumes(MediaType.APPLICATION_JSON)
587     @Produces(MediaType.APPLICATION_JSON)
588     @ApiOperation(value = "Update resource instance attribute", httpMethod = "POST", notes = "Returns updated resource instance attribute", response = Response.class)
589     @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
590     public Response updateResourceInstanceAttribute(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
591             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
592             @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,
593             @Context final HttpServletRequest request) {
594
595         String url = request.getMethod() + " " + request.getRequestURI();
596         log.debug("Start handle request of {}", url);
597
598         try {
599
600             Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
601             Wrapper<String> dataWrapper = new Wrapper<>();
602             Wrapper<ComponentInstanceProperty> attributeWrapper = new Wrapper<>();
603             Wrapper<ComponentInstanceBusinessLogic> blWrapper = new Wrapper<>();
604
605             validateInputStream(request, dataWrapper, errorWrapper);
606
607             if (errorWrapper.isEmpty()) {
608                 validateClassParse(dataWrapper.getInnerElement(), attributeWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
609             }
610
611             if (errorWrapper.isEmpty()) {
612                 validateComponentInstanceBusinessLogic(request, containerComponentType, blWrapper, errorWrapper);
613             }
614
615             if (errorWrapper.isEmpty()) {
616                 ComponentInstanceBusinessLogic componentInstanceLogic = blWrapper.getInnerElement();
617                 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
618                 log.debug("Start handle request of ComponentInstanceAttribute. Received attribute is {}", attributeWrapper.getInnerElement());
619                 Either<ComponentInstanceProperty, ResponseFormat> eitherAttribute = componentInstanceLogic.createOrUpdateAttributeValue(componentTypeEnum, componentId, componentInstanceId, attributeWrapper.getInnerElement(), userId);
620                 if (eitherAttribute.isRight()) {
621                     errorWrapper.setInnerElement(eitherAttribute.right().value());
622                 } else {
623                     attributeWrapper.setInnerElement(eitherAttribute.left().value());
624                 }
625             }
626
627             return buildResponseFromElement(errorWrapper, attributeWrapper);
628
629         } catch (Exception e) {
630             log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
631             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
632         }
633
634     }
635
636     @DELETE
637     @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/property/{propertyId}")
638     @Consumes(MediaType.APPLICATION_JSON)
639     @Produces(MediaType.APPLICATION_JSON)
640     @ApiOperation(value = "Update resource instance", httpMethod = "DELETE", notes = "Returns deleted resource instance property", response = Response.class)
641     @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
642     public Response deleteResourceInstanceProperty(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
643             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
644             @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "property id") @PathParam("propertyId") final String propertyId,
645             @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
646
647         ServletContext context = request.getSession().getServletContext();
648
649         String url = request.getMethod() + " " + request.getRequestURI();
650         log.debug("Start handle request of {}", url);
651         try {
652
653             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
654             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
655             if (componentInstanceLogic == null) {
656                 log.debug("Unsupported component type {}", containerComponentType);
657                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
658             }
659
660             Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId);
661             if (actionResponse.isRight()) {
662                 return buildErrorResponse(actionResponse.right().value());
663             }
664             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
665         } catch (Exception e) {
666             log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
667             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
668         }
669
670     }
671
672     @POST
673     @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/changeVersion")
674     @Consumes(MediaType.APPLICATION_JSON)
675     @Produces(MediaType.APPLICATION_JSON)
676     @ApiOperation(value = "Update resource instance", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
677     @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
678     public Response changeResourceInstanceVersion(@PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId,
679             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
680             @Context final HttpServletRequest request) {
681         ServletContext context = request.getSession().getServletContext();
682
683         String url = request.getMethod() + " " + request.getRequestURI();
684         log.debug("Start handle request of {}", url);
685         try (    InputStream inputStream = request.getInputStream()) {
686
687             byte[] bytes = IOUtils.toByteArray(inputStream);
688
689             if (bytes == null || bytes.length == 0) {
690                 log.info("Empty body was sent.");
691                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
692             }
693
694             String userId = request.getHeader(Constants.USER_ID_HEADER);
695
696             String data = new String(bytes);
697
698             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
699             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
700             if (componentInstanceLogic == null) {
701                 log.debug("Unsupported component type {}", containerComponentType);
702                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
703             }
704
705             Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
706
707             if (convertResponse.isRight()) {
708                 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance");
709                 log.debug("Failed to convert received data to BE format.");
710                 return buildErrorResponse(convertResponse.right().value());
711             }
712
713             ComponentInstance newResourceInstance = convertResponse.left().value();
714             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance);
715
716             if (actionResponse.isRight()) {
717                 return buildErrorResponse(actionResponse.right().value());
718             }
719             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
720
721         } catch (Exception e) {
722             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Instance");
723             log.debug("update resource instance with exception", e);
724             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
725         }
726
727     }
728
729     @POST
730     @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}/property")
731     @Consumes(MediaType.APPLICATION_JSON)
732     @Produces(MediaType.APPLICATION_JSON)
733     @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
734     @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
735     public Response updateGroupInstanceProperty(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
736             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
737             @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "group instance id") @PathParam("groupInstanceId") final String groupInstanceId,
738             @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
739
740         String url = request.getMethod() + " " + request.getRequestURI();
741         log.debug("Start handle request of {}", url);
742
743         try {
744             Wrapper<String> dataWrapper = new Wrapper<>();
745             Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
746             Wrapper<ComponentInstanceProperty> propertyWrapper = new Wrapper<>();
747
748             validateInputStream(request, dataWrapper, errorWrapper);
749
750             if (errorWrapper.isEmpty()) {
751                 validateClassParse(dataWrapper.getInnerElement(), propertyWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
752             }
753
754             if (!errorWrapper.isEmpty()) {
755                 return buildErrorResponse(errorWrapper.getInnerElement());
756             }
757
758             ComponentInstanceProperty property = propertyWrapper.getInnerElement();
759
760             log.debug("Start handle request of updateResourceInstanceProperty. Received property is {}", property);
761
762             ServletContext context = request.getSession().getServletContext();
763
764             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
765             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
766             if (componentInstanceLogic == null) {
767                 log.debug("Unsupported component type {}", containerComponentType);
768                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
769             }
770
771             Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, componentInstanceId, groupInstanceId, property, userId);
772
773             if (actionResponse.isRight()) {
774                 return buildErrorResponse(actionResponse.right().value());
775             }
776
777             ComponentInstanceProperty resourceInstanceProperty = actionResponse.left().value();
778             ObjectMapper mapper = new ObjectMapper();
779             String result = mapper.writeValueAsString(resourceInstanceProperty);
780             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
781
782         } catch (Exception e) {
783             log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
784             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
785         }
786
787     }
788
789     @GET
790     @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstId}")
791     @Consumes(MediaType.APPLICATION_JSON)
792     @Produces(MediaType.APPLICATION_JSON)
793     @ApiOperation(value = "Get group artifacts ", httpMethod = "GET", notes = "Returns artifacts metadata according to groupInstId", response = Resource.class)
794     @ApiResponses(value = { @ApiResponse(code = 200, message = "group found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Group not found") })
795     public Response getGroupArtifactById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId,
796             @PathParam("groupInstId") final String groupInstId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
797         ServletContext context = request.getSession().getServletContext();
798         String url = request.getMethod() + " " + request.getRequestURI();
799         log.debug("(GET) Start handle request of {}", url);
800
801         try {
802
803             GroupBusinessLogic businessLogic = this.getGroupBL(context);
804             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
805             Either<GroupDefinitionInfo, ResponseFormat> actionResponse = businessLogic.getGroupInstWithArtifactsById(componentTypeEnum, componentId, componentInstanceId, groupInstId, userId, false);
806
807             if (actionResponse.isRight()) {
808                 log.debug("failed to get all non abstract {}", containerComponentType);
809                 return buildErrorResponse(actionResponse.right().value());
810             }
811
812             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
813
814         } catch (Exception e) {
815             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getGroupArtifactById");
816             log.debug("getGroupArtifactById unexpected exception", e);
817             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
818         }
819
820     }
821
822     // US831698
823     @GET
824     @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/properties")
825     @Consumes(MediaType.APPLICATION_JSON)
826     @Produces(MediaType.APPLICATION_JSON)
827     @ApiOperation(value = "Get component instance properties", httpMethod = "GET", notes = "Returns component instance properties", response = Response.class)
828     @ApiResponses(value = { @ApiResponse(code = 200, message = "Properties found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component/Component Instance - not found") })
829     public Response getInstancePropertiesById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("containerComponentId") final String containerComponentId,
830             @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
831
832         ServletContext context = request.getSession().getServletContext();
833         String url = request.getMethod() + " " + request.getRequestURI();
834         log.debug("(GET) Start handle request of {}", url);
835
836         try {
837             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
838             ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context, componentTypeEnum);
839
840             Either<List<ComponentInstanceProperty>, ResponseFormat> componentInstancePropertiesById = componentInstanceBL.getComponentInstancePropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, userId);
841
842             if (componentInstancePropertiesById.isRight()) {
843                 log.debug("Failed to get properties of component instance ID: {} in {} with ID: {}", componentInstanceUniqueId, containerComponentType, containerComponentId);
844                 return buildErrorResponse(componentInstancePropertiesById.right().value());
845             }
846
847             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById.left().value());
848         } catch (Exception e) {
849             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getGroupArtifactById");
850             log.debug("getGroupArtifactById unexpected exception", e);
851             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
852         }
853
854     }
855
856     // US330353
857     @GET
858     @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
859     @Consumes(MediaType.APPLICATION_JSON)
860     @Produces(MediaType.APPLICATION_JSON)
861     @ApiOperation(value = "Get component instance capability properties", httpMethod = "GET", notes = "Returns component instance capability properties", response = Response.class)
862     @ApiResponses(value = { @ApiResponse(code = 200, message = "Properties found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component/Component Instance/Capability - not found") })
863     public Response getInstanceCapabilityPropertiesById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("containerComponentId") final String containerComponentId,
864             @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId, @PathParam("capabilityType") final String capabilityType, @PathParam("capabilityName") final String capabilityName,  @PathParam("ownerId") final String ownerId, @Context final HttpServletRequest request,
865             @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
866
867         ServletContext context = request.getSession().getServletContext();
868         String url = request.getMethod() + " " + request.getRequestURI();
869         log.debug("(GET) Start handle request of {}", url);
870
871         try {
872             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
873             ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context, componentTypeEnum);
874
875             Either<List<ComponentInstanceProperty>, ResponseFormat> componentInstancePropertiesById = componentInstanceBL.getComponentInstanceCapabilityPropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId,
876                     capabilityType, capabilityName, ownerId, userId);
877
878             if (componentInstancePropertiesById.isRight()) {
879                 log.debug("Failed to get properties of component instance ID: {} in {} with ID: {}", componentInstanceUniqueId, containerComponentType, containerComponentId);
880                 return buildErrorResponse(componentInstancePropertiesById.right().value());
881             }
882
883             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById.left().value());
884         } catch (Exception e) {
885             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getGroupArtifactById");
886             log.debug("getGroupArtifactById unexpected exception", e);
887             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
888         }
889
890     }
891
892     //US 331281
893     @PUT
894     @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
895     @Consumes(MediaType.APPLICATION_JSON)
896     @Produces(MediaType.APPLICATION_JSON)
897     @ApiOperation(value = "Update Instance Capabilty  Property", httpMethod = "PUT", notes = "Returns updated property", response = Response.class)
898     @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"),
899             @ApiResponse(code = 404, message = "Component/Component Instance/Capability - not found") })
900     public Response updateInstanceCapabilityProperty(@PathParam("containerComponentType") final String containerComponentType, @PathParam("containerComponentId") final String containerComponentId,
901             @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId, @PathParam("capabilityType") final String capabilityType, @PathParam("capabilityName") final String capabilityName, @PathParam("ownerId") final String ownerId,
902             @ApiParam(value = "Instance capabilty property to update", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
903         ServletContext context = request.getSession().getServletContext();
904         String url = request.getMethod() + " " + request.getRequestURI();
905         log.debug("(PUT) Start handle request of {}", url);
906         try {
907             Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
908             List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
909             if (errorWrapper.isEmpty()) {
910                 Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties(data);
911                 if (propertiesToUpdateEither.isRight()) {
912                     errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
913                 } else {
914                     propertiesToUpdate = propertiesToUpdateEither.left().value();
915                 }
916             }
917
918             if (!errorWrapper.isEmpty()) {
919                 return buildErrorResponse(errorWrapper.getInnerElement());
920             }
921
922             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
923             ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context, componentTypeEnum);
924
925             Either<List<ComponentInstanceProperty>, ResponseFormat> updateCICapProperty = componentInstanceBL.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, propertiesToUpdate, userId);
926
927             if (updateCICapProperty.isRight()) {
928                 log.debug("Failed to get properties of component instance ID: {} in {} with ID: {}", componentInstanceUniqueId, containerComponentType, containerComponentId);
929                 return buildErrorResponse(updateCICapProperty.right().value());
930             }
931
932             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updateCICapProperty.left().value());
933         } catch (Exception e) {
934             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getGroupArtifactById");
935             log.debug("getGroupArtifactById unexpected exception", e);
936             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
937         }
938     }
939
940     @POST
941     @Path("/{containerComponentType}/{containerComponentId}/serviceProxy")
942     @Consumes(MediaType.APPLICATION_JSON)
943     @Produces(MediaType.APPLICATION_JSON)
944     @ApiOperation(value = "Create service proxy", httpMethod = "POST", notes = "Returns created service proxy", response = Response.class)
945     @ApiResponses(value = { @ApiResponse(code = 201, message = "Service proxy created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
946             @ApiResponse(code = 409, message = "Service proxy already exist") })
947     public Response createServiceProxy(@ApiParam(value = "RI object to be created", required = true) String data, @PathParam("containerComponentId") final String containerComponentId,
948             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
949             @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId, @Context final HttpServletRequest request) {
950         ServletContext context = request.getSession().getServletContext();
951
952         try {
953
954             ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
955             componentInstance.setInvariantName(null);
956             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
957             if (componentTypeEnum != ComponentTypeEnum.SERVICE) {
958                 log.debug("Unsupported container component type {}", containerComponentType);
959                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
960             }
961             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
962             if (componentInstanceLogic == null) {
963                 log.debug("Unsupported component type {}", containerComponentType);
964                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
965             }
966             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.createServiceProxy(containerComponentType, containerComponentId, userId, componentInstance);
967
968             if (actionResponse.isRight()) {
969                 return buildErrorResponse(actionResponse.right().value());
970             }
971             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
972
973         } catch (Exception e) {
974             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create service proxy");
975             log.debug("Create service proxy failed with exception", e);
976             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
977         }
978     }
979
980     @DELETE
981     @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}")
982     @Consumes(MediaType.APPLICATION_JSON)
983     @Produces(MediaType.APPLICATION_JSON)
984     @ApiOperation(value = "Delete service proxy", httpMethod = "DELETE", notes = "Returns delete service proxy", response = Response.class)
985     @ApiResponses(value = { @ApiResponse(code = 201, message = "Service proxy deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
986     public Response deleteServiceProxy(@PathParam("containerComponentId") final String containerComponentId, @PathParam("serviceProxyId") final String serviceProxyId,
987             @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
988                     + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
989             @Context final HttpServletRequest request) {
990         ServletContext context = request.getSession().getServletContext();
991         String url = request.getMethod() + " " + request.getRequestURI();
992         Response response = null;
993         try {
994             log.debug("Start handle request of {}", url);
995             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
996             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
997             if (componentInstanceLogic == null) {
998                 log.debug("Unsupported component type {}", containerComponentType);
999                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1000             }
1001             String userId = request.getHeader(Constants.USER_ID_HEADER);
1002             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.deleteServiceProxy(containerComponentType, containerComponentId, serviceProxyId, userId);
1003
1004             if (actionResponse.isRight()) {
1005                 response = buildErrorResponse(actionResponse.right().value());
1006             } else {
1007                 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
1008             }
1009             return response;
1010         } catch (Exception e) {
1011             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete service proxy");
1012             log.debug("Delete service proxy failed with exception", e);
1013             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
1014         }
1015     }
1016
1017     @POST
1018     @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}/changeVersion/{newServiceId}")
1019     @Consumes(MediaType.APPLICATION_JSON)
1020     @Produces(MediaType.APPLICATION_JSON)
1021     @ApiOperation(value = "Update service proxy with new version", httpMethod = "POST", notes = "Returns updated service proxy", response = Response.class)
1022     @ApiResponses(value = { @ApiResponse(code = 201, message = "Service proxy created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
1023     public Response changeServiceProxyVersion(@PathParam("containerComponentId") final String containerComponentId, @PathParam("serviceProxyId") final String serviceProxyId,
1024             @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
1025             @Context final HttpServletRequest request) {
1026         ServletContext context = request.getSession().getServletContext();
1027
1028         String url = request.getMethod() + " " + request.getRequestURI();
1029         log.debug("Start handle request of {}", url);
1030         try {
1031
1032             String userId = request.getHeader(Constants.USER_ID_HEADER);
1033
1034             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1035             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
1036             if (componentInstanceLogic == null) {
1037                 log.debug("Unsupported component type {}", containerComponentType);
1038                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1039             }
1040             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.changeServiceProxyVersion(containerComponentType, containerComponentId, serviceProxyId, userId);
1041
1042             if (actionResponse.isRight()) {
1043                 return buildErrorResponse(actionResponse.right().value());
1044             }
1045             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
1046
1047         } catch (Exception e) {
1048             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update service proxy with new version");
1049             log.debug("Update service proxy with new version failed with exception", e);
1050             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
1051         }
1052     }
1053     /**
1054      * REST API GET relation by Id
1055      * Allows to get relation contained in specified component according to received Id
1056      * @param containerComponentType
1057      * @param componentId
1058      * @param relationId
1059      * @param request
1060      * @param userId
1061      * @return Response
1062      */
1063     @GET
1064     @Path("/{containerComponentType}/{componentId}/relationId/{relationId}")
1065     @Consumes(MediaType.APPLICATION_JSON)
1066     @Produces(MediaType.APPLICATION_JSON)
1067     @ApiOperation(value = "Get relation", httpMethod = "GET", notes = "Returns relation metadata according to relationId", response = Resource.class)
1068     @ApiResponses(value = { @ApiResponse(code = 200, message = "relation found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Relation not found") })
1069     public Response getRelationById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("componentId") final String componentId,
1070             @PathParam("relationId") final String relationId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
1071
1072         ServletContext context = request.getSession().getServletContext();
1073         String url = request.getMethod() + " " + request.getRequestURI();
1074         log.debug("(GET) Start handle request of {}", url);
1075         try {
1076             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1077             if (componentTypeEnum == null) {
1078                 log.debug("Unsupported component type {}", containerComponentType);
1079                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1080             }
1081             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
1082
1083             Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceLogic.getRelationById(componentId, relationId, userId, componentTypeEnum);
1084             if (actionResponse.isRight()) {
1085                 return buildErrorResponse(actionResponse.right().value());
1086             }
1087             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
1088         } catch (Exception e) {
1089             BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getRelationById");
1090             log.debug("getRelationById unexpected exception", e);
1091             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
1092         }
1093     }
1094
1095     private Either<ComponentInstance, ResponseFormat> convertToResourceInstance(String data) {
1096
1097         // Either<ComponentInstance, ActionStatus> convertStatus =
1098         // convertJsonToObject(data, ComponentInstance.class);
1099         Either<ComponentInstance, ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), ComponentInstance.class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1100         if (convertStatus.isRight()) {
1101             return Either.right(convertStatus.right().value());
1102         }
1103         ComponentInstance resourceInstanceInfo = convertStatus.left().value();
1104
1105         return Either.left(resourceInstanceInfo);
1106     }
1107
1108     private Either<List<ComponentInstance>, ResponseFormat> convertToMultipleResourceInstance(String dataList) {
1109
1110         Either<ComponentInstance[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstance[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1111         if (convertStatus.isRight()) {
1112             return Either.right(convertStatus.right().value());
1113         }
1114
1115         return Either.left(Arrays.asList(convertStatus.left().value()));
1116     }
1117
1118     private Either<List<ComponentInstanceProperty>, ResponseFormat> convertMultipleProperties(String dataList) {
1119         if (StringUtils.isEmpty(dataList)) {
1120             return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
1121         }
1122         Either<ComponentInstanceProperty[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceProperty[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1123         if (convertStatus.isRight()) {
1124             return Either.right(convertStatus.right().value());
1125         }
1126         return Either.left(Arrays.asList(convertStatus.left().value()));
1127     }
1128
1129     private Either<List<ComponentInstanceInput>, ResponseFormat> convertMultipleInputs(String dataList) {
1130         if (StringUtils.isEmpty(dataList)) {
1131             return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
1132         }
1133         Either<ComponentInstanceInput[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceInput[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1134         if (convertStatus.isRight()) {
1135             return Either.right(convertStatus.right().value());
1136         }
1137         return Either.left(Arrays.asList(convertStatus.left().value()));
1138     }
1139
1140
1141     private Either<RequirementCapabilityRelDef, ResponseFormat> convertToRequirementCapabilityRelDef(String data) {
1142
1143         Either<RequirementCapabilityRelDef, ActionStatus> convertStatus = convertJsonToObject(data, RequirementCapabilityRelDef.class);
1144         if (convertStatus.isRight()) {
1145             return Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
1146         }
1147         RequirementCapabilityRelDef requirementCapabilityRelDef = convertStatus.left().value();
1148         return Either.left(requirementCapabilityRelDef);
1149     }
1150
1151     private <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
1152         try {
1153             log.trace("convert json to object. json=\n {}", data);
1154             T t;
1155             t = gson.fromJson(data, clazz);
1156             if (t == null) {
1157                 BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
1158                 log.debug("object is null after converting from json");
1159                 return Either.right(ActionStatus.INVALID_CONTENT);
1160             }
1161             return Either.left(t);
1162         } catch (Exception e) {
1163             // INVALID JSON
1164             BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
1165             log.debug("failed to convert from json", e);
1166             return Either.right(ActionStatus.INVALID_CONTENT);
1167         }
1168     }
1169
1170
1171     @GET
1172     @Path("/{containerComponentType}/{componentId}/paths-to-delete")
1173     @Produces(MediaType.APPLICATION_JSON)
1174     @ApiOperation(value = "Check if forwarding path to delete on version change", httpMethod = "GET", notes = "Returns forwarding paths to delete",
1175         response = Response.class)
1176     public Response changeResourceInstanceVersion( @PathParam("componentId") String componentId,
1177         @QueryParam("componentInstanceId") final String oldComponentInstanceId,
1178         @QueryParam("newComponentInstanceId") final String newComponentInstanceId,
1179         @ApiParam(value = "valid values: resources / services",
1180             allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME)
1181         @PathParam("containerComponentType") final String containerComponentType,
1182         @Context final HttpServletRequest request) {
1183         if (oldComponentInstanceId == null){
1184             return  buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_OLD_COMPONENT_INSTANCE));
1185         }
1186         if (newComponentInstanceId == null){
1187             return  buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_NEW_COMPONENT_INSTANCE));
1188         }
1189         ServletContext context = request.getSession().getServletContext();
1190
1191         String url = request.getMethod() + " " + request.getRequestURI();
1192         log.debug("Start handle request of {}", url);
1193         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1194         ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
1195         if (componentInstanceLogic == null) {
1196             log.debug("Unsupported component type {}", containerComponentType);
1197             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1198         }
1199         ComponentInstance newComponentInstance;
1200         if(StringUtils.isNotEmpty(newComponentInstanceId)){
1201             newComponentInstance=new ComponentInstance();
1202             newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,newComponentInstanceId);
1203         }else{
1204             log.error("missing component id");
1205             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_DATA));
1206         }
1207         Either<Set<String>,ResponseFormat> actionResponse= componentInstanceLogic.forwardingPathOnVersionChange(
1208             containerComponentType,componentId,oldComponentInstanceId,newComponentInstance);
1209         if (actionResponse.isRight()) {
1210             return buildErrorResponse(actionResponse.right().value());
1211         }
1212         ForwardingPaths forwardingPaths=new ForwardingPaths();
1213         forwardingPaths.setForwardingPathToDelete(actionResponse.left().value());
1214         return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), forwardingPaths);
1215
1216     }
1217
1218 }