re base code
[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.*;
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;
47
48 import javax.inject.Singleton;
49 import javax.servlet.ServletContext;
50 import javax.servlet.http.HttpServletRequest;
51 import javax.ws.rs.*;
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;
60 import java.util.Set;
61
62 /**
63  * Root resource (exposed at "/" path) .json
64  */
65 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
66 @Path("/v1/catalog")
67 @Api(value = "Resource Instance Servlet")
68 @Singleton
69 public class ComponentInstanceServlet extends AbstractValidationsServlet {
70
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();
86
87     @POST
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();
98
99         try {
100
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));
108             }
109             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
110
111             if (actionResponse.isRight()) {
112                 return buildErrorResponse(actionResponse.right().value());
113             }
114             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
115
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));
120         }
121     }
122
123     @POST
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();
134
135         String url = request.getMethod() + " " + request.getRequestURI();
136         log.debug(START_HANDLE_REQUEST_OF, url);
137         try {
138
139             log.debug(START_HANDLE_REQUEST_OF, url);
140
141             InputStream inputStream = request.getInputStream();
142
143             byte[] bytes = IOUtils.toByteArray(inputStream);
144
145             if (bytes == null || bytes.length == 0) {
146                 log.info(EMPTY_BODY_WAS_SENT);
147                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
148             }
149
150             String userId = request.getHeader(Constants.USER_ID_HEADER);
151
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));
158             }
159             Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
160
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());
165             }
166
167             ComponentInstance resourceInstance = convertResponse.left().value();
168             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstanceMetadata(containerComponentType, componentId, componentInstanceId, userId, resourceInstance);
169
170             if (actionResponse.isRight()) {
171                 return buildErrorResponse(actionResponse.right().value());
172             }
173             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
174
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));
179         }
180
181     }
182
183     @POST
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) {
193
194         ServletContext context = request.getSession().getServletContext();
195         String url = request.getMethod() + " " + request.getRequestURI();
196         log.debug(START_HANDLE_REQUEST_OF, url);
197
198         try {
199             log.debug(START_HANDLE_REQUEST_OF, url);
200
201             if (componentInstanceJsonArray == null || componentInstanceJsonArray.length() == 0) {
202                 log.info("Empty JSON list was sent.");
203                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
204             }
205
206             String userId = request.getHeader(Constants.USER_ID_HEADER);
207
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));
213             }
214
215             Either<List<ComponentInstance>, ResponseFormat> convertResponse = convertToMultipleResourceInstance(componentInstanceJsonArray);
216
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());
222             }
223
224             List<ComponentInstance> componentInstanceList = convertResponse.left().value();
225
226             Either<List<ComponentInstance>, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstance(containerComponentType, componentId, userId, componentInstanceList, true);
227
228             if (actionResponse.isRight()) {
229                 return buildErrorResponse(actionResponse.right().value());
230             }
231
232             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
233
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));
238         }
239
240     }
241
242     @DELETE
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;
255         try {
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));
262             }
263             String userId = request.getHeader(Constants.USER_ID_HEADER);
264             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId);
265
266             if (actionResponse.isRight()) {
267                 response = buildErrorResponse(actionResponse.right().value());
268             } else {
269                 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
270             }
271             return response;
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));
276         }
277     }
278
279     @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + "," + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true)
280     @POST
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();
292
293         String url = request.getMethod() + " " + request.getRequestURI();
294         log.debug(START_HANDLE_REQUEST_OF, url);
295         Response response = null;
296
297         try {
298
299             log.debug(START_HANDLE_REQUEST_OF, url);
300
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));
306             }
307
308             Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
309
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());
315             } else {
316                 RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
317                 requirementDef.setOriginUI(true);
318                 resultOp = componentInstanceLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum);
319             }
320
321             Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = resultOp;
322
323             if (actionResponse.isRight()) {
324                 response = buildErrorResponse(actionResponse.right().value());
325             } else {
326                 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
327             }
328             return response;
329
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));
334         }
335     }
336
337     @PUT
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();
349
350         String url = request.getMethod() + " " + request.getRequestURI();
351         log.debug(START_HANDLE_REQUEST_OF, url);
352
353         try {
354
355             log.debug(START_HANDLE_REQUEST_OF, url);
356
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));
362             }
363
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());
369             }
370
371             RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
372             Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum);
373
374             if (actionResponse.isRight()) {
375                 return buildErrorResponse(actionResponse.right().value());
376             }
377             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
378
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));
383         }
384     }
385
386     @POST
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();
397
398         String url = request.getMethod() + " " + request.getRequestURI();
399         log.debug(START_HANDLE_REQUEST_OF, url);
400         try {
401
402             log.debug(START_HANDLE_REQUEST_OF, url);
403
404             InputStream inputStream = request.getInputStream();
405
406             byte[] bytes = IOUtils.toByteArray(inputStream);
407
408             if (bytes == null || bytes.length == 0) {
409                 log.info(EMPTY_BODY_WAS_SENT);
410                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
411             }
412
413             String userId = request.getHeader(Constants.USER_ID_HEADER);
414
415             String data = new String(bytes);
416
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));
422             }
423
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());
430             }
431
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);
436
437             if (actionResponse.isRight()) {
438                 return buildErrorResponse(actionResponse.right().value());
439             }
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));
445         }
446     }
447
448     @POST
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) {
458
459         String url = request.getMethod() + " " + request.getRequestURI();
460         log.debug(START_HANDLE_REQUEST_OF, url);
461
462         try {
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());
469                 } else {
470                     propertiesToUpdate = propertiesToUpdateEither.left().value();
471                 }
472             }
473
474             if (!errorWrapper.isEmpty()) {
475                 return buildErrorResponse(errorWrapper.getInnerElement());
476             }
477
478             log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, propertiesToUpdate);
479
480             ServletContext context = request.getSession().getServletContext();
481
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));
487             }
488
489             Either<List<ComponentInstanceProperty>, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdatePropertiesValues(componentTypeEnum, componentId, componentInstanceId, propertiesToUpdate, userId);
490
491             if (actionResponse.isRight()) {
492                 return buildErrorResponse(actionResponse.right().value());
493             }
494
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);
499
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));
503         }
504
505     }
506
507     @POST
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) {
517
518         String url = request.getMethod() + " " + request.getRequestURI();
519         log.debug(START_HANDLE_REQUEST_OF, url);
520
521         try {
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());
528                 } else {
529                     inputsToUpdate = inputsToUpdateEither.left().value();
530                 }
531             }
532             if (!errorWrapper.isEmpty()) {
533                 return buildErrorResponse(errorWrapper.getInnerElement());
534             }
535
536             log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, inputsToUpdate);
537
538             ServletContext context = request.getSession().getServletContext();
539
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));
545             }
546
547             Either<List<ComponentInstanceInput>, ResponseFormat> actionResponse =
548                     componentInstanceLogic.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, componentInstanceId, inputsToUpdate, userId);
549
550             if (actionResponse.isRight()) {
551                 return buildErrorResponse(actionResponse.right().value());
552             }
553
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);
558
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));
562         }
563
564     }
565
566     /**
567      * Updates ResourceInstance Attribute
568      *
569      * @param componentId
570      * @param containerComponentType
571      * @param componentInstanceId
572      * @param userId
573      * @param request
574      * @return
575      */
576     @POST
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) {
586
587         String url = request.getMethod() + " " + request.getRequestURI();
588         log.debug(START_HANDLE_REQUEST_OF, url);
589
590         try {
591
592             Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
593             Wrapper<String> dataWrapper = new Wrapper<>();
594             Wrapper<ComponentInstanceProperty> attributeWrapper = new Wrapper<>();
595             Wrapper<ComponentInstanceBusinessLogic> blWrapper = new Wrapper<>();
596
597             validateInputStream(request, dataWrapper, errorWrapper);
598
599             if (errorWrapper.isEmpty()) {
600                 validateClassParse(dataWrapper.getInnerElement(), attributeWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
601             }
602
603             if (errorWrapper.isEmpty()) {
604                 validateComponentInstanceBusinessLogic(request, containerComponentType, blWrapper, errorWrapper);
605             }
606
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());
614                 } else {
615                     attributeWrapper.setInnerElement(eitherAttribute.left().value());
616                 }
617             }
618
619             return buildResponseFromElement(errorWrapper, attributeWrapper);
620
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));
624         }
625
626     }
627
628     @DELETE
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) {
638
639         ServletContext context = request.getSession().getServletContext();
640
641         String url = request.getMethod() + " " + request.getRequestURI();
642         log.debug(START_HANDLE_REQUEST_OF, url);
643         try {
644
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));
650             }
651
652             Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId);
653             if (actionResponse.isRight()) {
654                 return buildErrorResponse(actionResponse.right().value());
655             }
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));
660         }
661
662     }
663
664     @POST
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();
674
675         String url = request.getMethod() + " " + request.getRequestURI();
676         log.debug(START_HANDLE_REQUEST_OF, url);
677         try (    InputStream inputStream = request.getInputStream()) {
678
679             byte[] bytes = IOUtils.toByteArray(inputStream);
680
681             if (bytes == null || bytes.length == 0) {
682                 log.info(EMPTY_BODY_WAS_SENT);
683                 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
684             }
685
686             String userId = request.getHeader(Constants.USER_ID_HEADER);
687
688             String data = new String(bytes);
689
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));
695             }
696
697             Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
698
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());
703             }
704
705             ComponentInstance newResourceInstance = convertResponse.left().value();
706             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance);
707
708             if (actionResponse.isRight()) {
709                 return buildErrorResponse(actionResponse.right().value());
710             }
711             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
712
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));
717         }
718
719     }
720
721     @POST
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) {
731
732         String url = request.getMethod() + " " + request.getRequestURI();
733         log.debug(START_HANDLE_REQUEST_OF, url);
734
735         try {
736             Wrapper<String> dataWrapper = new Wrapper<>();
737             Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
738             Wrapper<ComponentInstanceProperty> propertyWrapper = new Wrapper<>();
739
740             validateInputStream(request, dataWrapper, errorWrapper);
741
742             if (errorWrapper.isEmpty()) {
743                 validateClassParse(dataWrapper.getInnerElement(), propertyWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
744             }
745
746             if (!errorWrapper.isEmpty()) {
747                 return buildErrorResponse(errorWrapper.getInnerElement());
748             }
749
750             ComponentInstanceProperty property = propertyWrapper.getInnerElement();
751
752             log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, property);
753
754             ServletContext context = request.getSession().getServletContext();
755
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));
761             }
762
763             Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, componentInstanceId, groupInstanceId, property, userId);
764
765             if (actionResponse.isRight()) {
766                 return buildErrorResponse(actionResponse.right().value());
767             }
768
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);
773
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));
777         }
778
779     }
780
781     @GET
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);
792
793         try {
794
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);
798
799             if (actionResponse.isRight()) {
800                 log.debug("failed to get all non abstract {}", containerComponentType);
801                 return buildErrorResponse(actionResponse.right().value());
802             }
803
804             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
805
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));
810         }
811
812     }
813
814     // US831698
815     @GET
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) {
823
824         ServletContext context = request.getSession().getServletContext();
825         String url = request.getMethod() + " " + request.getRequestURI();
826         log.debug(GET_START_HANDLE_REQUEST_OF, url);
827
828         try {
829             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
830             ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context);
831
832             Either<List<ComponentInstanceProperty>, ResponseFormat> componentInstancePropertiesById = componentInstanceBL.getComponentInstancePropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, userId);
833
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());
837             }
838
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));
844         }
845
846     }
847
848     // US330353
849     @GET
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) {
858
859         ServletContext context = request.getSession().getServletContext();
860         String url = request.getMethod() + " " + request.getRequestURI();
861         log.debug(GET_START_HANDLE_REQUEST_OF, url);
862
863         try {
864             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
865             ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context);
866
867             Either<List<ComponentInstanceProperty>, ResponseFormat> componentInstancePropertiesById = componentInstanceBL.getComponentInstanceCapabilityPropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId,
868                     capabilityType, capabilityName, ownerId, userId);
869
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());
873             }
874
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));
880         }
881
882     }
883
884     //US 331281
885     @PUT
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);
898         try {
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());
905                 } else {
906                     propertiesToUpdate = propertiesToUpdateEither.left().value();
907                 }
908             }
909
910             if (!errorWrapper.isEmpty()) {
911                 return buildErrorResponse(errorWrapper.getInnerElement());
912             }
913
914             ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
915             ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context);
916
917             Either<List<ComponentInstanceProperty>, ResponseFormat> updateCICapProperty = componentInstanceBL.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, propertiesToUpdate, userId);
918
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());
922             }
923
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));
929         }
930     }
931
932     @POST
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();
943
944         try {
945
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));
952             }
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));
957             }
958             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.createServiceProxy();
959
960             if (actionResponse.isRight()) {
961                 return buildErrorResponse(actionResponse.right().value());
962             }
963             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
964
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));
969         }
970     }
971
972     @DELETE
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;
985         try {
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));
992             }
993             String userId = request.getHeader(Constants.USER_ID_HEADER);
994             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.deleteServiceProxy();
995
996             if (actionResponse.isRight()) {
997                 response = buildErrorResponse(actionResponse.right().value());
998             } else {
999                 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
1000             }
1001             return response;
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));
1006         }
1007     }
1008
1009     @POST
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();
1019
1020         String url = request.getMethod() + " " + request.getRequestURI();
1021         log.debug(START_HANDLE_REQUEST_OF, url);
1022         try {
1023
1024             String userId = request.getHeader(Constants.USER_ID_HEADER);
1025
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));
1031             }
1032             Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.changeServiceProxyVersion();
1033
1034             if (actionResponse.isRight()) {
1035                 return buildErrorResponse(actionResponse.right().value());
1036             }
1037             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
1038
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));
1043         }
1044     }
1045     /**
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
1050      * @param relationId
1051      * @param request
1052      * @param userId
1053      * @return Response
1054      */
1055     @GET
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) {
1063
1064         ServletContext context = request.getSession().getServletContext();
1065         String url = request.getMethod() + " " + request.getRequestURI();
1066         log.debug(GET_START_HANDLE_REQUEST_OF, url);
1067         try {
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));
1072             }
1073             ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
1074
1075             Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceLogic.getRelationById(componentId, relationId, userId, componentTypeEnum);
1076             if (actionResponse.isRight()) {
1077                 return buildErrorResponse(actionResponse.right().value());
1078             }
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));
1084         }
1085     }
1086
1087     private Either<ComponentInstance, ResponseFormat> convertToResourceInstance(String data) {
1088
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());
1092         }
1093         ComponentInstance resourceInstanceInfo = convertStatus.left().value();
1094
1095         return Either.left(resourceInstanceInfo);
1096     }
1097
1098     private Either<List<ComponentInstance>, ResponseFormat> convertToMultipleResourceInstance(String dataList) {
1099
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());
1103         }
1104
1105         return Either.left(Arrays.asList(convertStatus.left().value()));
1106     }
1107
1108     private Either<List<ComponentInstanceProperty>, ResponseFormat> convertMultipleProperties(String dataList) {
1109         if (StringUtils.isEmpty(dataList)) {
1110             return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
1111         }
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());
1115         }
1116         return Either.left(Arrays.asList(convertStatus.left().value()));
1117     }
1118
1119     private Either<List<ComponentInstanceInput>, ResponseFormat> convertMultipleInputs(String dataList) {
1120         if (StringUtils.isEmpty(dataList)) {
1121             return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
1122         }
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());
1126         }
1127         return Either.left(Arrays.asList(convertStatus.left().value()));
1128     }
1129
1130
1131     private Either<RequirementCapabilityRelDef, ResponseFormat> convertToRequirementCapabilityRelDef(String data) {
1132
1133         Either<RequirementCapabilityRelDef, ActionStatus> convertStatus = convertJsonToObject(data, RequirementCapabilityRelDef.class);
1134         if (convertStatus.isRight()) {
1135             return Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
1136         }
1137         RequirementCapabilityRelDef requirementCapabilityRelDef = convertStatus.left().value();
1138         return Either.left(requirementCapabilityRelDef);
1139     }
1140
1141     private <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
1142         try {
1143             log.trace("convert json to object. json=\n {}", data);
1144             T t;
1145             t = gsonDeserializer.fromJson(data, clazz);
1146             if (t == null) {
1147                 BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
1148                 log.debug("object is null after converting from json");
1149                 return Either.right(ActionStatus.INVALID_CONTENT);
1150             }
1151             return Either.left(t);
1152         } catch (Exception e) {
1153             // INVALID JSON
1154             BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
1155             log.debug("failed to convert from json", e);
1156             return Either.right(ActionStatus.INVALID_CONTENT);
1157         }
1158     }
1159
1160
1161     @GET
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));
1175         }
1176         if (newComponentInstanceId == null){
1177             return  buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_NEW_COMPONENT_INSTANCE));
1178         }
1179         ServletContext context = request.getSession().getServletContext();
1180
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));
1188         }
1189         ComponentInstance newComponentInstance;
1190         if(StringUtils.isNotEmpty(newComponentInstanceId)){
1191             newComponentInstance=new ComponentInstance();
1192             newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,newComponentInstanceId);
1193         }else{
1194             log.error("missing component id");
1195             return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_DATA));
1196         }
1197         Either<Set<String>,ResponseFormat> actionResponse= componentInstanceLogic.forwardingPathOnVersionChange(
1198             containerComponentType,componentId,oldComponentInstanceId,newComponentInstance);
1199         if (actionResponse.isRight()) {
1200             return buildErrorResponse(actionResponse.right().value());
1201         }
1202         ForwardingPaths forwardingPaths=new ForwardingPaths();
1203         forwardingPaths.setForwardingPathToDelete(actionResponse.left().value());
1204         return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), forwardingPaths);
1205
1206     }
1207
1208 }