2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.servlets;
23 import java.io.InputStream;
24 import java.lang.reflect.Type;
25 import java.util.Arrays;
26 import java.util.List;
28 import javax.inject.Singleton;
29 import javax.servlet.ServletContext;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.ws.rs.Consumes;
32 import javax.ws.rs.DELETE;
33 import javax.ws.rs.GET;
34 import javax.ws.rs.HeaderParam;
35 import javax.ws.rs.POST;
36 import javax.ws.rs.PUT;
37 import javax.ws.rs.Path;
38 import javax.ws.rs.PathParam;
39 import javax.ws.rs.Produces;
40 import javax.ws.rs.core.Context;
41 import javax.ws.rs.core.MediaType;
42 import javax.ws.rs.core.Response;
44 import org.apache.commons.io.IOUtils;
45 import org.codehaus.jackson.map.ObjectMapper;
46 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
47 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
48 import org.openecomp.sdc.be.config.BeEcompErrorManager;
49 import org.openecomp.sdc.be.dao.api.ActionStatus;
50 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
51 import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
52 import org.openecomp.sdc.be.info.GroupDefinitionInfo;
53 import org.openecomp.sdc.be.model.ComponentInstance;
54 import org.openecomp.sdc.be.model.ComponentInstanceInput;
55 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
56 import org.openecomp.sdc.be.model.InputDefinition;
57 import org.openecomp.sdc.be.model.PropertyConstraint;
58 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
59 import org.openecomp.sdc.be.model.Resource;
60 import org.openecomp.sdc.be.model.User;
61 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
62 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
63 import org.openecomp.sdc.common.api.Constants;
64 import org.openecomp.sdc.common.datastructure.Wrapper;
65 import org.openecomp.sdc.exception.ResponseFormat;
66 import org.slf4j.Logger;
67 import org.slf4j.LoggerFactory;
69 import com.google.gson.Gson;
70 import com.google.gson.GsonBuilder;
71 import com.google.gson.reflect.TypeToken;
72 import com.jcabi.aspects.Loggable;
73 import io.swagger.annotations.Api;
74 import io.swagger.annotations.ApiOperation;
75 import io.swagger.annotations.ApiParam;
76 import io.swagger.annotations.ApiResponse;
77 import io.swagger.annotations.ApiResponses;
79 import fj.data.Either;
82 * Root resource (exposed at "/" path)
85 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
87 @Api(value = "Resource Instance Servlet", description = "Resource Instance Servlet")
89 public class ComponentInstanceServlet extends AbstractValidationsServlet {
91 private static Logger log = LoggerFactory.getLogger(ComponentInstanceServlet.class.getName());
93 Type constraintType = new TypeToken<PropertyConstraint>() {
96 Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
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();
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));
120 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
122 if (actionResponse.isRight()) {
123 return buildErrorResponse(actionResponse.right().value());
125 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
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));
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();
146 String url = request.getMethod() + " " + request.getRequestURI();
147 log.debug("Start handle request of {}", url);
150 log.debug("Start handle request of {}", url);
152 InputStream inputStream = request.getInputStream();
154 byte[] bytes = IOUtils.toByteArray(inputStream);
156 if (bytes == null || bytes.length == 0) {
157 log.info("Empty body was sent.");
158 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
161 String userId = request.getHeader(Constants.USER_ID_HEADER);
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));
170 Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
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());
178 ComponentInstance resourceInstance = convertResponse.left().value();
179 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstanceMetadata(containerComponentType, componentId, componentInstanceId, userId, resourceInstance);
181 if (actionResponse.isRight()) {
182 return buildErrorResponse(actionResponse.right().value());
184 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
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));
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) {
205 ServletContext context = request.getSession().getServletContext();
206 String url = request.getMethod() + " " + request.getRequestURI();
207 log.debug("Start handle request of {}", url);
210 log.debug("Start handle request of {}", url);
212 if (componentInstanceJsonArray == null || componentInstanceJsonArray.length() == 0) {
213 log.info("Empty JSON list was sent.");
214 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
217 String userId = request.getHeader(Constants.USER_ID_HEADER);
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));
226 Either<List<ComponentInstance>, ResponseFormat> convertResponse = convertToMultipleResourceInstance(componentInstanceJsonArray);
228 if (convertResponse.isRight()) {
229 // Using both ECOMP error methods, show to Sofer
230 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance");
232 * BeEcompErrorManager.getInstance().processEcompError( EcompErrorName.BeSystemError, "Resource Instance - updateResourceInstance");
234 log.debug("Failed to convert received data to BE format.");
235 return buildErrorResponse(convertResponse.right().value());
238 List<ComponentInstance> componentInstanceList = convertResponse.left().value();
240 Either<List<ComponentInstance>, ResponseFormat> actionResponse = componentInstanceLogic.updateComponentInstance(containerComponentType, componentId, userId, componentInstanceList, true, true);
242 if (actionResponse.isRight()) {
243 return buildErrorResponse(actionResponse.right().value());
246 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
248 } catch (Exception e) {
250 * BeEcompErrorManager.getInstance().processEcompError( EcompErrorName.BeRestApiGeneralError, "Update Resource Instance" );
252 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Instance");
253 log.debug("update resource instance with exception", e);
254 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
260 @Path("/{containerComponentType}/{componentId}/resourceInstance/{resourceInstanceId}")
261 @Consumes(MediaType.APPLICATION_JSON)
262 @Produces(MediaType.APPLICATION_JSON)
263 @ApiOperation(value = "Delete ResourceInstance", httpMethod = "DELETE", notes = "Returns delete resourceInstance", response = Response.class)
264 @ApiResponses(value = { @ApiResponse(code = 201, message = "ResourceInstance deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
265 public Response deleteResourceInstance(@PathParam("componentId") final String componentId, @PathParam("resourceInstanceId") final String resourceInstanceId,
266 @ApiParam(value = "valid values: resources / services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
267 + ComponentTypeEnum.PRODUCT_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
268 @Context final HttpServletRequest request) {
269 ServletContext context = request.getSession().getServletContext();
270 String url = request.getMethod() + " " + request.getRequestURI();
271 Response response = null;
273 log.debug("Start handle request of {}", url);
274 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
275 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
276 if (componentInstanceLogic == null) {
277 log.debug("Unsupported component type {}", containerComponentType);
278 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
280 String userId = request.getHeader(Constants.USER_ID_HEADER);
281 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId);
283 if (actionResponse.isRight()) {
284 response = buildErrorResponse(actionResponse.right().value());
286 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
289 } catch (Exception e) {
290 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource Instance");
291 log.debug("delete resource instance with exception", e);
292 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
296 @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + "," + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true)
298 @Path("/{containerComponentType}/{componentId}/resourceInstance/associate")
299 @Consumes(MediaType.APPLICATION_JSON)
300 @Produces(MediaType.APPLICATION_JSON)
301 @ApiOperation(value = "Associate RI to RI", httpMethod = "POST", notes = "Returns created RelationshipInfo", response = Response.class)
302 @ApiResponses(value = { @ApiResponse(code = 201, message = "Relationship created"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
303 @ApiResponse(code = 409, message = "Relationship already exist") })
304 public Response associateRIToRI(@ApiParam(value = "unique id of the container component") @PathParam("componentId") final String componentId,
305 @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
306 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam("containerComponentType") final String containerComponentType,
307 @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "RelationshipInfo", required = true) String data, @Context final HttpServletRequest request) {
308 ServletContext context = request.getSession().getServletContext();
310 String url = request.getMethod() + " " + request.getRequestURI();
311 log.debug("Start handle request of {}", url);
312 Response response = null;
316 log.debug("Start handle request of {}", url);
318 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
319 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
320 if (componentInstanceLogic == null) {
321 log.debug("Unsupported component type {}", containerComponentType);
322 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
325 Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
327 Either<RequirementCapabilityRelDef, ResponseFormat> resultOp;
328 if (regInfoW.isRight()) {
329 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - associateRIToRI");
330 log.debug("Failed to convert received data to BE format.");
331 resultOp = Either.right(regInfoW.right().value());
333 RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
334 resultOp = componentInstanceLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum);
337 Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = resultOp;
339 if (actionResponse.isRight()) {
340 response = buildErrorResponse(actionResponse.right().value());
342 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
346 } catch (Exception e) {
347 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Associate Resource Instance");
348 log.debug("associate resource instance to another RI with exception", e);
349 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
354 @Path("/{containerComponentType}/{componentId}/resourceInstance/dissociate")
355 @Consumes(MediaType.APPLICATION_JSON)
356 @Produces(MediaType.APPLICATION_JSON)
357 @ApiOperation(value = "Dissociate RI from RI", httpMethod = "PUT", notes = "Returns deleted RelationshipInfo", response = Response.class)
358 @ApiResponses(value = { @ApiResponse(code = 201, message = "Relationship deleted"), @ApiResponse(code = 403, message = "Missing information"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
359 public Response dissociateRIFromRI(
360 @ApiParam(value = "allowed values are resources /services / products", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME + ","
361 + ComponentTypeEnum.PRODUCT_PARAM_NAME, required = true) @PathParam("containerComponentType") final String containerComponentType,
362 @ApiParam(value = "unique id of the container component") @PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "RelationshipInfo", required = true) String data,
363 @Context final HttpServletRequest request) {
364 ServletContext context = request.getSession().getServletContext();
366 String url = request.getMethod() + " " + request.getRequestURI();
367 log.debug("Start handle request of {}", url);
371 log.debug("Start handle request of {}", url);
373 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
374 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
375 if (componentInstanceLogic == null) {
376 log.debug("Unsupported component type {}", containerComponentType);
377 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
380 Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
381 if (regInfoW.isRight()) {
382 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - dissociateRIFromRI");
383 log.debug("Failed to convert received data to BE format.");
384 return buildErrorResponse(regInfoW.right().value());
387 RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
388 Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum);
390 if (actionResponse.isRight()) {
391 return buildErrorResponse(actionResponse.right().value());
393 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
395 } catch (Exception e) {
396 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Dissociate Resource Instance");
397 log.debug("dissociate resource instance from service failed with exception", e);
398 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
403 @Path("/{containerComponentType}/{componentId}/resourceInstance/createAndAssociate")
404 @Consumes(MediaType.APPLICATION_JSON)
405 @Produces(MediaType.APPLICATION_JSON)
406 @ApiOperation(value = "Create RI and associate RI to RI", httpMethod = "POST", notes = "Returns created RI and RelationshipInfo", response = Response.class)
407 @ApiResponses(value = { @ApiResponse(code = 201, message = "RI created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
408 @ApiResponse(code = 409, message = "Relationship already exist") })
409 public Response createAndAssociateRIToRI(@PathParam("componentId") final String componentId,
410 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
411 @Context final HttpServletRequest request) {
412 ServletContext context = request.getSession().getServletContext();
414 String url = request.getMethod() + " " + request.getRequestURI();
415 log.debug("Start handle request of {}", url);
418 log.debug("Start handle request of {}", url);
420 InputStream inputStream = request.getInputStream();
422 byte[] bytes = IOUtils.toByteArray(inputStream);
424 if (bytes == null || bytes.length == 0) {
425 log.info("Empty body was sent.");
426 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
429 String userId = request.getHeader(Constants.USER_ID_HEADER);
431 String data = new String(bytes);
433 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
434 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
435 if (componentInstanceLogic == null) {
436 log.debug("Unsupported component type {}", containerComponentType);
437 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
440 Either<CreateAndAssotiateInfo, ActionStatus> convertStatus = convertJsonToObject(data, CreateAndAssotiateInfo.class);
441 if (convertStatus.isRight()) {
442 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - createAndAssociateRIToRI");
443 log.debug("Failed to convert received data to BE format.");
444 Either<Object, ResponseFormat> formattedResponse = Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
445 return buildErrorResponse(formattedResponse.right().value());
448 CreateAndAssotiateInfo createAndAssotiateInfo = convertStatus.left().value();
449 Either<CreateAndAssotiateInfo, ResponseFormat> actionResponse = componentInstanceLogic.createAndAssociateRIToRI(containerComponentType, componentId, userId, createAndAssotiateInfo);
451 if (actionResponse.isRight()) {
452 return buildErrorResponse(actionResponse.right().value());
454 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
455 } catch (Exception e) {
456 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create and Associate Resource Instance");
457 log.debug("create and associate RI failed with exception", e);
458 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
463 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/property")
464 @Consumes(MediaType.APPLICATION_JSON)
465 @Produces(MediaType.APPLICATION_JSON)
466 @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
467 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
468 public Response updateResourceInstanceProperty(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
469 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
470 @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,
471 @Context final HttpServletRequest request) {
473 String url = request.getMethod() + " " + request.getRequestURI();
474 log.debug("Start handle request of {}", url);
477 Wrapper<String> dataWrapper = new Wrapper<>();
478 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
479 Wrapper<ComponentInstanceProperty> propertyWrapper = new Wrapper<>();
481 validateInputStream(request, dataWrapper, errorWrapper);
483 if (errorWrapper.isEmpty()) {
484 validateClassParse(dataWrapper.getInnerElement(), propertyWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
487 if (!errorWrapper.isEmpty()) {
488 return buildErrorResponse(errorWrapper.getInnerElement());
491 ComponentInstanceProperty property = propertyWrapper.getInnerElement();
493 log.debug("Start handle request of updateResourceInstanceProperty. Received property is {}", property);
495 ServletContext context = request.getSession().getServletContext();
497 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
498 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
499 if (componentInstanceLogic == null) {
500 log.debug("Unsupported component type {}", containerComponentType);
501 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
504 Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdatePropertyValue(componentTypeEnum, componentId, componentInstanceId, property, userId);
506 if (actionResponse.isRight()) {
507 return buildErrorResponse(actionResponse.right().value());
510 ComponentInstanceProperty resourceInstanceProperty = actionResponse.left().value();
511 ObjectMapper mapper = new ObjectMapper();
512 String result = mapper.writeValueAsString(resourceInstanceProperty);
513 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
515 } catch (Exception e) {
516 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
517 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
523 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/input")
524 @Consumes(MediaType.APPLICATION_JSON)
525 @Produces(MediaType.APPLICATION_JSON)
526 @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
527 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
528 public Response updateResourceInstanceInput(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
529 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
530 @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,
531 @Context final HttpServletRequest request) {
533 String url = request.getMethod() + " " + request.getRequestURI();
534 log.debug("Start handle request of {}", url);
537 Wrapper<String> dataWrapper = new Wrapper<>();
538 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
539 Wrapper<ComponentInstanceInput> propertyWrapper = new Wrapper<>();
541 validateInputStream(request, dataWrapper, errorWrapper);
542 ComponentInstanceInput property = null;
544 if (errorWrapper.isEmpty()) {
545 User modifier = new User();
546 modifier.setUserId(userId);
547 log.debug("modifier id is {}", userId);
549 Either<ComponentInstanceInput, ResponseFormat> inputEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataWrapper.getInnerElement(), modifier, ComponentInstanceInput.class, AuditingActionEnum.UPDATE_RESOURCE_METADATA, ComponentTypeEnum.SERVICE);;
550 if(inputEither.isRight()){
551 log.debug("Failed to convert data to input definition. Status is {}", inputEither.right().value());
552 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
554 property = inputEither.left().value();
558 if (property == null) {
559 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
563 log.debug("Start handle request of updateResourceInstanceProperty. Received property is {}", property);
565 ServletContext context = request.getSession().getServletContext();
567 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
568 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
569 if (componentInstanceLogic == null) {
570 log.debug("Unsupported component type {}", containerComponentType);
571 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
574 Either<ComponentInstanceInput, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdateInstanceInputValue(componentTypeEnum, componentId, componentInstanceId, property, userId);
576 if (actionResponse.isRight()) {
577 return buildErrorResponse(actionResponse.right().value());
580 ComponentInstanceInput resourceInstanceProperty = actionResponse.left().value();
581 ObjectMapper mapper = new ObjectMapper();
582 String result = mapper.writeValueAsString(resourceInstanceProperty);
583 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
585 } catch (Exception e) {
586 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
587 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
593 * Updates ResourceInstance Attribute
596 * @param containerComponentType
597 * @param componentInstanceId
603 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/attribute")
604 @Consumes(MediaType.APPLICATION_JSON)
605 @Produces(MediaType.APPLICATION_JSON)
606 @ApiOperation(value = "Update resource instance attribute", httpMethod = "POST", notes = "Returns updated resource instance attribute", response = Response.class)
607 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
608 public Response updateResourceInstanceAttribute(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
609 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
610 @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,
611 @Context final HttpServletRequest request) {
613 String url = request.getMethod() + " " + request.getRequestURI();
614 log.debug("Start handle request of {}", url);
618 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
619 Wrapper<String> dataWrapper = new Wrapper<>();
620 Wrapper<ComponentInstanceProperty> attributeWrapper = new Wrapper<>();
621 Wrapper<ComponentInstanceBusinessLogic> blWrapper = new Wrapper<>();
623 validateInputStream(request, dataWrapper, errorWrapper);
625 if (errorWrapper.isEmpty()) {
626 validateClassParse(dataWrapper.getInnerElement(), attributeWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
629 if (errorWrapper.isEmpty()) {
630 validateComponentInstanceBusinessLogic(request, containerComponentType, blWrapper, errorWrapper);
633 if (errorWrapper.isEmpty()) {
634 ComponentInstanceBusinessLogic componentInstanceLogic = blWrapper.getInnerElement();
635 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
636 log.debug("Start handle request of ComponentInstanceAttribute. Received attribute is {}", attributeWrapper.getInnerElement());
637 Either<ComponentInstanceProperty, ResponseFormat> eitherAttribute = componentInstanceLogic.createOrUpdateAttributeValue(componentTypeEnum, componentId, componentInstanceId, attributeWrapper.getInnerElement(), userId);
638 if (eitherAttribute.isRight()) {
639 errorWrapper.setInnerElement(eitherAttribute.right().value());
641 attributeWrapper.setInnerElement(eitherAttribute.left().value());
645 return buildResponseFromElement(errorWrapper, attributeWrapper);
647 } catch (Exception e) {
648 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
649 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
655 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/property/{propertyId}")
656 @Consumes(MediaType.APPLICATION_JSON)
657 @Produces(MediaType.APPLICATION_JSON)
658 @ApiOperation(value = "Update resource instance", httpMethod = "DELETE", notes = "Returns deleted resource instance property", response = Response.class)
659 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
660 public Response deleteResourceInstanceProperty(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
661 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
662 @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "property id") @PathParam("propertyId") final String propertyId,
663 @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
665 ServletContext context = request.getSession().getServletContext();
667 String url = request.getMethod() + " " + request.getRequestURI();
668 log.debug("Start handle request of {}", url);
671 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
672 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
673 if (componentInstanceLogic == null) {
674 log.debug("Unsupported component type {}", containerComponentType);
675 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
678 Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId);
679 if (actionResponse.isRight()) {
680 return buildErrorResponse(actionResponse.right().value());
682 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
683 } catch (Exception e) {
684 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
685 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
691 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/changeVersion")
692 @Consumes(MediaType.APPLICATION_JSON)
693 @Produces(MediaType.APPLICATION_JSON)
694 @ApiOperation(value = "Update resource instance", httpMethod = "POST", notes = "Returns updated resource instance", response = Response.class)
695 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
696 public Response changeResourceInstanceVersion(@PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId,
697 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
698 @Context final HttpServletRequest request) {
699 ServletContext context = request.getSession().getServletContext();
701 String url = request.getMethod() + " " + request.getRequestURI();
702 log.debug("Start handle request of {}", url);
704 InputStream inputStream = request.getInputStream();
706 byte[] bytes = IOUtils.toByteArray(inputStream);
708 if (bytes == null || bytes.length == 0) {
709 log.info("Empty body was sent.");
710 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
713 String userId = request.getHeader(Constants.USER_ID_HEADER);
715 String data = new String(bytes);
717 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
718 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
719 if (componentInstanceLogic == null) {
720 log.debug("Unsupported component type {}", containerComponentType);
721 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
724 Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
726 if (convertResponse.isRight()) {
727 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance");
728 log.debug("Failed to convert received data to BE format.");
729 return buildErrorResponse(convertResponse.right().value());
732 ComponentInstance newResourceInstance = convertResponse.left().value();
733 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance);
735 if (actionResponse.isRight()) {
736 return buildErrorResponse(actionResponse.right().value());
738 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
740 } catch (Exception e) {
741 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Instance");
742 log.debug("update resource instance with exception", e);
743 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
749 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}/property")
750 @Consumes(MediaType.APPLICATION_JSON)
751 @Produces(MediaType.APPLICATION_JSON)
752 @ApiOperation(value = "Update resource instance property", httpMethod = "POST", notes = "Returns updated resource instance property", response = Response.class)
753 @ApiResponses(value = { @ApiResponse(code = 201, message = "Resource instance created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
754 public Response updateGroupInstanceProperty(@ApiParam(value = "service id") @PathParam("componentId") final String componentId,
755 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
756 @ApiParam(value = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId, @ApiParam(value = "group instance id") @PathParam("groupInstanceId") final String groupInstanceId, @ApiParam(value = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
757 @Context final HttpServletRequest request) {
759 String url = request.getMethod() + " " + request.getRequestURI();
760 log.debug("Start handle request of {}", url);
763 Wrapper<String> dataWrapper = new Wrapper<>();
764 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
765 Wrapper<ComponentInstanceProperty> propertyWrapper = new Wrapper<>();
767 validateInputStream(request, dataWrapper, errorWrapper);
769 if (errorWrapper.isEmpty()) {
770 validateClassParse(dataWrapper.getInnerElement(), propertyWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
773 if (!errorWrapper.isEmpty()) {
774 return buildErrorResponse(errorWrapper.getInnerElement());
777 ComponentInstanceProperty property = propertyWrapper.getInnerElement();
779 log.debug("Start handle request of updateResourceInstanceProperty. Received property is {}", property);
781 ServletContext context = request.getSession().getServletContext();
783 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
784 ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context, componentTypeEnum);
785 if (componentInstanceLogic == null) {
786 log.debug("Unsupported component type {}", containerComponentType);
787 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
790 Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceLogic.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, componentInstanceId, groupInstanceId, property, userId);
792 if (actionResponse.isRight()) {
793 return buildErrorResponse(actionResponse.right().value());
796 ComponentInstanceProperty resourceInstanceProperty = actionResponse.left().value();
797 ObjectMapper mapper = new ObjectMapper();
798 String result = mapper.writeValueAsString(resourceInstanceProperty);
799 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
801 } catch (Exception e) {
802 log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
803 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
809 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstId}")
810 @Consumes(MediaType.APPLICATION_JSON)
811 @Produces(MediaType.APPLICATION_JSON)
812 @ApiOperation(value = "Get group artifacts ", httpMethod = "GET", notes = "Returns artifacts metadata according to groupInstId", response = Resource.class)
813 @ApiResponses(value = { @ApiResponse(code = 200, message = "group found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Group not found") })
814 public Response getGroupArtifactById(@PathParam("containerComponentType") final String containerComponentType, @PathParam("componentId") final String componentId, @PathParam("componentInstanceId") final String componentInstanceId, @PathParam("groupInstId") final String groupInstId,
815 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
816 ServletContext context = request.getSession().getServletContext();
817 String url = request.getMethod() + " " + request.getRequestURI();
818 log.debug("(GET) Start handle request of {}", url);
822 GroupBusinessLogic businessLogic = this.getGroupBL(context);
823 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
824 Either<GroupDefinitionInfo, ResponseFormat> actionResponse = businessLogic.getGroupInstWithArtifactsById(componentTypeEnum, componentId, componentInstanceId, groupInstId, userId, false);
826 if (actionResponse.isRight()) {
827 log.debug("failed to get all non abstract {}", containerComponentType);
828 return buildErrorResponse(actionResponse.right().value());
831 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
833 } catch (Exception e) {
834 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getGroupArtifactById");
835 log.debug("getGroupArtifactById unexpected exception", e);
836 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
843 @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/properties")
844 @Consumes(MediaType.APPLICATION_JSON)
845 @Produces(MediaType.APPLICATION_JSON)
846 @ApiOperation(value = "Get component instance properties", httpMethod = "GET",
847 notes = "Returns component instance properties", response = Response.class)
848 @ApiResponses(value = { @ApiResponse(code = 200, message = "Properties found"),
849 @ApiResponse(code = 403, message = "Restricted operation"),
850 @ApiResponse(code = 404, message = "Component/Component Instance - not found") })
851 public Response getInstancePropertiesById(@PathParam("containerComponentType") final String containerComponentType,
852 @PathParam("containerComponentId") final String containerComponentId,
853 @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
854 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
856 ServletContext context = request.getSession().getServletContext();
857 String url = request.getMethod() + " " + request.getRequestURI();
858 log.debug("(GET) Start handle request of {}", url);
861 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
862 ComponentInstanceBusinessLogic componentInstanceBL = getComponentInstanceBL(context, componentTypeEnum);
864 Either<List<ComponentInstanceProperty>, ResponseFormat> componentInstancePropertiesById = componentInstanceBL
865 .getComponentInstancePropertiesById(containerComponentType, containerComponentId,
866 componentInstanceUniqueId, userId);
868 if (componentInstancePropertiesById.isRight()) {
869 log.debug("Failed to get properties of component instance ID: {} in {} with ID: {}",
870 componentInstanceUniqueId, containerComponentType, containerComponentId);
871 return buildErrorResponse(componentInstancePropertiesById.right().value());
874 return buildOkResponse(getComponentsUtils().
875 getResponseFormat(ActionStatus.OK), componentInstancePropertiesById.left().value());
876 } catch (Exception e) {
877 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getGroupArtifactById");
878 log.debug("getGroupArtifactById unexpected exception", e);
879 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
884 private Either<ComponentInstance, ResponseFormat> convertToResourceInstance(String data) {
886 // Either<ComponentInstance, ActionStatus> convertStatus =
887 // convertJsonToObject(data, ComponentInstance.class);
888 Either<ComponentInstance, ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), ComponentInstance.class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
889 if (convertStatus.isRight()) {
890 return Either.right(convertStatus.right().value());
892 ComponentInstance resourceInstanceInfo = convertStatus.left().value();
894 return Either.left(resourceInstanceInfo);
897 private Either<List<ComponentInstance>, ResponseFormat> convertToMultipleResourceInstance(String dataList) {
899 Either<ComponentInstance[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstance[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
900 if (convertStatus.isRight()) {
901 return Either.right(convertStatus.right().value());
904 return Either.left(Arrays.asList(convertStatus.left().value()));
907 private Either<RequirementCapabilityRelDef, ResponseFormat> convertToRequirementCapabilityRelDef(String data) {
909 Either<RequirementCapabilityRelDef, ActionStatus> convertStatus = convertJsonToObject(data, RequirementCapabilityRelDef.class);
910 if (convertStatus.isRight()) {
911 return Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
913 RequirementCapabilityRelDef requirementCapabilityRelDef = convertStatus.left().value();
914 return Either.left(requirementCapabilityRelDef);
917 private <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
919 log.trace("convert json to object. json=\n {}", data);
921 t = gson.fromJson(data, clazz);
923 BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
924 log.debug("object is null after converting from json");
925 return Either.right(ActionStatus.INVALID_CONTENT);
927 return Either.left(t);
928 } catch (Exception e) {
930 BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
931 log.debug("failed to convert from json", e);
932 return Either.right(ActionStatus.INVALID_CONTENT);