-/*-\r
- * ============LICENSE_START=======================================================\r
- * SDC\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.openecomp.sdc.be.servlets;\r
-\r
-import java.util.ArrayList;\r
-import java.util.EnumMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-import javax.inject.Inject;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.ws.rs.Consumes;\r
-import javax.ws.rs.GET;\r
-import javax.ws.rs.HeaderParam;\r
-import javax.ws.rs.POST;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.PathParam;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.QueryParam;\r
-import javax.ws.rs.core.Context;\r
-import javax.ws.rs.core.MediaType;\r
-import javax.ws.rs.core.Response;\r
-import org.apache.commons.collections.CollectionUtils;\r
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;\r
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider;\r
-import org.openecomp.sdc.be.config.BeEcompErrorManager;\r
-import org.openecomp.sdc.be.dao.api.ActionStatus;\r
-import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;\r
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;\r
-import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;\r
-import org.openecomp.sdc.be.impl.ComponentsUtils;\r
-import org.openecomp.sdc.be.mixin.GroupCompositionMixin;\r
-import org.openecomp.sdc.be.mixin.PolicyCompositionMixin;\r
-import org.openecomp.sdc.be.model.CapReqDef;\r
-import org.openecomp.sdc.be.model.Component;\r
-import org.openecomp.sdc.be.model.ComponentInstance;\r
-import org.openecomp.sdc.be.model.IComponentInstanceConnectedElement;\r
-import org.openecomp.sdc.be.model.Resource;\r
-import org.openecomp.sdc.be.model.User;\r
-import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;\r
-import org.openecomp.sdc.be.user.UserBusinessLogic;\r
-import org.openecomp.sdc.be.view.ResponseView;\r
-import org.openecomp.sdc.common.api.Constants;\r
-import org.openecomp.sdc.common.log.wrappers.Logger;\r
-import org.openecomp.sdc.exception.ResponseFormat;\r
-import org.springframework.stereotype.Controller;\r
-import com.jcabi.aspects.Loggable;\r
-import fj.data.Either;\r
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;\r
-import io.swagger.v3.oas.annotations.Operation;\r
-import io.swagger.v3.oas.annotations.Parameter;\r
-import io.swagger.v3.oas.annotations.info.Info;\r
-import io.swagger.v3.oas.annotations.media.ArraySchema;\r
-import io.swagger.v3.oas.annotations.media.Content;\r
-import io.swagger.v3.oas.annotations.media.Schema;\r
-import io.swagger.v3.oas.annotations.responses.ApiResponse;\r
-import io.swagger.v3.oas.annotations.responses.ApiResponses;\r
-\r
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)\r
-@Path("/v1/catalog")\r
-@OpenAPIDefinition(info = @Info(title = "Component Servlet",description = "Component Servlet"))\r
-@Controller\r
-public class ComponentServlet extends BeGenericServlet {\r
- private static final String GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION = "getCertifiedNotAbstractComponents failed with exception";\r
-\r
- private static final String GET_CERTIFIED_NON_ABSTRACT = "Get Certified Non Abstract";\r
-\r
- private static final String FAILED_TO_GET_ALL_NON_ABSTRACT = "failed to get all non abstract {}";\r
-\r
- private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";\r
-\r
- private static final Logger log = Logger.getLogger(ComponentServlet.class);\r
-\r
- private final ComponentBusinessLogicProvider componentBusinessLogicProvider;\r
-\r
- @Inject\r
- public ComponentServlet(UserBusinessLogic userBusinessLogic,\r
- ComponentsUtils componentsUtils,\r
- ComponentBusinessLogicProvider componentBusinessLogicProvider) {\r
- super(userBusinessLogic, componentsUtils);\r
- this.componentBusinessLogicProvider = componentBusinessLogicProvider;\r
- }\r
-\r
- @GET\r
- @Path("/{componentType}/{componentUuid}/conformanceLevelValidation")\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- @Operation(description = "Validate Component Conformance Level", method = "GET",\r
- summary = "Returns the result according to conformance level in BE config", responses = @ApiResponse(\r
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
- @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
- @ApiResponse(responseCode = "404", description = "Component not found")})\r
- public Response conformanceLevelValidation(@PathParam("componentType") final String componentType,\r
- @PathParam("componentUuid") final String componentUuid, @Context final HttpServletRequest request,\r
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {\r
- Response response;\r
-\r
- String url = request.getMethod() + " " + request.getRequestURI();\r
- log.debug(START_HANDLE_REQUEST_OF, url);\r
-\r
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);\r
- if (componentTypeEnum != null) {\r
- ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum);\r
- Either<Boolean, ResponseFormat> eitherConformanceLevel = compBL.validateConformanceLevel(componentUuid, componentTypeEnum, userId);\r
- if (eitherConformanceLevel.isRight()) {\r
- response = buildErrorResponse(eitherConformanceLevel.right().value());\r
- } else {\r
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), gson.toJson(eitherConformanceLevel.left().value()));\r
- }\r
- } else {\r
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));\r
- }\r
-\r
- return response;\r
- }\r
-\r
- @GET\r
- @Path("/{componentType}/{componentId}/requirmentsCapabilities")\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- @Operation(description = "Get Component Requirments And Capabilities", method = "GET",\r
- summary = "Returns Requirements And Capabilities according to componentId", responses = @ApiResponse(\r
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
- @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
- @ApiResponse(responseCode = "404", description = "Component not found")})\r
- public Response getRequirementAndCapabilities(@PathParam("componentType") final String componentType,\r
- @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,\r
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {\r
- Response response;\r
-\r
- String url = request.getMethod() + " " + request.getRequestURI();\r
- log.debug(START_HANDLE_REQUEST_OF, url);\r
-\r
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);\r
- if (componentTypeEnum != null) {\r
- try {\r
- ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum);\r
- Either<CapReqDef, ResponseFormat> eitherRequirementsAndCapabilities = compBL.getRequirementsAndCapabilities(componentId, componentTypeEnum, userId);\r
- if (eitherRequirementsAndCapabilities.isRight()) {\r
- response = buildErrorResponse(eitherRequirementsAndCapabilities.right().value());\r
- } else {\r
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), RepresentationUtils.toRepresentation(eitherRequirementsAndCapabilities.left().value()));\r
- }\r
- } catch (Exception e) {\r
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Capabilities and requirements for " + componentId);\r
- log.debug("getRequirementAndCapabilities failed with exception", e);\r
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
- }\r
- } else {\r
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));\r
- }\r
-\r
- return response;\r
- }\r
-\r
- @GET\r
- @Path("/{componentType}/latestversion/notabstract")\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- @Operation(description = "Get Component Requirments And Capabilities", method = "GET",\r
- summary = "Returns Requirments And Capabilities according to componentId", responses = @ApiResponse(\r
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
- @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
- @ApiResponse(responseCode = "404", description = "Component not found")})\r
- public Response getLatestVersionNotAbstractCheckoutComponents(\r
- @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,\r
- @QueryParam("internalComponentType") String internalComponentType,\r
- @QueryParam("componentUids") List<String> componentUids,\r
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {\r
-\r
- String url = request.getMethod() + " " + request.getRequestURI();\r
- log.debug("(get) Start handle request of {}", url);\r
- Response response = null;\r
-\r
- try {\r
-\r
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);\r
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);\r
-\r
- log.debug("Received componentUids size is {}", componentUids == null ? 0 : componentUids.size());\r
-\r
- Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, componentTypeEnum, internalComponentType, componentUids, userId);\r
-\r
- if (actionResponse.isRight()) {\r
- log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);\r
- return buildErrorResponse(actionResponse.right().value());\r
- }\r
- Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());\r
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);\r
-\r
- } catch (Exception e) {\r
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);\r
- log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);\r
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
- return response;\r
-\r
- }\r
-\r
- }\r
-\r
- @POST\r
- @Path("/{componentType}/latestversion/notabstract")\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- @Operation(description = "Get Component Requirments And Capabilities", method = "GET",\r
- summary = "Returns Requirments And Capabilities according to componentId", responses = @ApiResponse(\r
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
- @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
- @ApiResponse(responseCode = "404", description = "Component not found")})\r
- public Response getLatestVersionNotAbstractCheckoutComponentsByBody(\r
- @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,\r
- @QueryParam("internalComponentType") String internalComponentType,\r
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,\r
- @Parameter(description = "Consumer Object to be created", required = true) List<String> data) {\r
-\r
- String url = request.getMethod() + " " + request.getRequestURI();\r
- log.debug("(GET) Start handle request of {}", url);\r
- Response response = null;\r
-\r
- try {\r
-\r
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);\r
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);\r
- if (log.isDebugEnabled()) {\r
- log.debug("Received componentUids size is {}", data == null ? 0 : data.size());\r
- }\r
-\r
- Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, componentTypeEnum, internalComponentType, data, userId);\r
-\r
- if (actionResponse.isRight()) {\r
- log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);\r
- return buildErrorResponse(actionResponse.right().value());\r
-\r
- }\r
- Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());\r
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);\r
-\r
-\r
-\r
- } catch (Exception e) {\r
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);\r
- log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);\r
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
- return response;\r
-\r
- }\r
-\r
- }\r
-\r
- @GET\r
- @Path("/{componentType}/latestversion/notabstract/metadata")\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- @Operation(description = "Get Component uid only", method = "GET", summary = "Returns componentId",\r
- responses = @ApiResponse(\r
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
- @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
- @ApiResponse(responseCode = "404", description = "Component not found")})\r
- public Response getLatestVersionNotAbstractCheckoutComponentsIdesOnly(\r
- @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,\r
- @QueryParam("internalComponentType") String internalComponentType,\r
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,\r
- @Parameter(description = "uid list", required = true) String data) {\r
-\r
- String url = request.getMethod() + " " + request.getRequestURI();\r
- log.debug("(get) Start handle request of {}", url);\r
- Response response = null;\r
- try {\r
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);\r
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);\r
-\r
- Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponentsMetadata(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, internalComponentType, userId);\r
- if (actionResponse.isRight()) {\r
- log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);\r
- return buildErrorResponse(actionResponse.right().value());\r
- }\r
- Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());\r
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);\r
-\r
- } catch (Exception e) {\r
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);\r
- log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);\r
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
- return response;\r
-\r
- }\r
-\r
- }\r
-\r
- @GET\r
- @Path("/{componentType}/{componentId}/componentInstances")\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- @Operation(description = "Get Component instances", method = "GET", summary = "Returns component instances",\r
- responses = @ApiResponse(\r
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
- @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
- @ApiResponse(responseCode = "404", description = "Component not found")})\r
- public Response getComponentInstancesFilteredByPropertiesAndInputs(\r
- @PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,\r
- @Context final HttpServletRequest request, @QueryParam("searchText") String searchText,\r
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,\r
- @Parameter(description = "uid" + " " + "list", required = true) String data) {\r
-\r
- String url = request.getMethod() + " " + request.getRequestURI();\r
- log.debug("(GET) Start handle request of {}", url);\r
- Response response = null;\r
- try {\r
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);\r
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);\r
-\r
- Either<List<ComponentInstance>, ResponseFormat> actionResponse = businessLogic.getComponentInstancesFilteredByPropertiesAndInputs(componentId, userId);\r
- if (actionResponse.isRight()) {\r
- log.debug("failed to get all component instances filtered by properties and inputs", componentType);\r
- return buildErrorResponse(actionResponse.right().value());\r
- }\r
- Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());\r
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);\r
-\r
- } catch (Exception e) {\r
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Instances filtered by properties & inputs" + componentType);\r
- log.debug("getComponentInstancesFilteredByPropertiesAndInputs failed with exception", e);\r
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
- return response;\r
- }\r
- }\r
-\r
-\r
-\r
- /**\r
- * This API is a generic api for ui - the api get a list of strings and return the data on the component according to to list.\r
- * for example: list of the string "properties, inputs" will return component with the list of properties and inputs.\r
- *\r
- * @param componentType\r
- * @param componentId\r
- * @param dataParamsToReturn\r
- * @param request\r
- * @param userId\r
- * @return\r
- */\r
-\r
- @GET\r
- @Path("/{componentType}/{componentId}/filteredDataByParams")\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- @Operation(description = "Retrieve Resource", method = "GET", summary = "Returns resource according to resourceId",\r
- responses = @ApiResponse(\r
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))\r
- @ResponseView(mixin = {GroupCompositionMixin.class, PolicyCompositionMixin.class})\r
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource found"),\r
- @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
- @ApiResponse(responseCode = "404", description = "Resource not found")})\r
- public Response getComponentDataFilteredByParams(@PathParam("componentType") final String componentType,\r
- @PathParam("componentId") final String componentId,\r
- @QueryParam("include") final List<String> dataParamsToReturn, @Context final HttpServletRequest request,\r
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {\r
-\r
- String url = request.getMethod() + " " + request.getRequestURI();\r
- log.debug(START_HANDLE_REQUEST_OF , url);\r
-\r
- // get modifier id\r
- User modifier = new User();\r
- modifier.setUserId(userId);\r
- log.debug("modifier id is {}" , userId);\r
-\r
- Response response;\r
-\r
- try {\r
- String resourceIdLower = componentId.toLowerCase();\r
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);\r
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);\r
-\r
- log.trace("get component with id {} filtered by ui params", componentId);\r
- Either<UiComponentDataTransfer, ResponseFormat> actionResponse = businessLogic.getComponentDataFilteredByParams(resourceIdLower, modifier, dataParamsToReturn);\r
-\r
- if (actionResponse.isRight()) {\r
- log.debug("failed to get component data filtered by ui params");\r
- response = buildErrorResponse(actionResponse.right().value());\r
- return response;\r
- }\r
- RepresentationUtils.toRepresentation(actionResponse.left().value());\r
- return buildOkResponse(actionResponse.left().value());\r
-\r
- } catch (Exception e) {\r
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get component filtered by ui params");\r
- log.debug("get resource failed with exception", e);\r
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
-\r
- }\r
- }\r
-\r
-\r
- @GET\r
- @Path("/{componentType}/{componentId}/filteredproperties/{propertyNameFragment}")\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- @Operation(\r
- description = "Retrieve properties belonging to component instances of specific component by name and optionally resource type",\r
- method = "GET",\r
- summary = "Returns properties belonging to component instances of specific component by name and optionally resource type",\r
- responses = @ApiResponse(\r
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Map.class)))))\r
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),\r
- @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
- @ApiResponse(responseCode = "404", description = "Component not found")})\r
- public Response getFilteredComponentInstanceProperties(\r
- @PathParam("componentType") final String componentType,\r
- @PathParam("componentId") final String componentId,\r
- @PathParam("propertyNameFragment") final String propertyNameFragment,\r
- @QueryParam("resourceType") List<String> resourceTypes,\r
- @Context final HttpServletRequest request,\r
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {\r
-\r
- User user = new User();\r
- user.setUserId(userId);\r
- log.debug("User Id is {}" , userId);\r
- Response response;\r
- try {\r
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);\r
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);\r
- Map<FilterKeyEnum, List<String>> filters = new EnumMap<>(FilterKeyEnum.class);\r
- List<String> propertyNameFragments = new ArrayList<>();\r
- propertyNameFragments.add(propertyNameFragment);\r
- filters.put(FilterKeyEnum.NAME_FRAGMENT, propertyNameFragments);\r
- if(CollectionUtils.isNotEmpty(resourceTypes)){\r
- filters.put(FilterKeyEnum.RESOURCE_TYPE, resourceTypes);\r
- }\r
- Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> actionResponse = businessLogic.getFilteredComponentInstanceProperties(componentId, filters, userId);\r
- if (actionResponse.isRight()) {\r
- response = buildErrorResponse(actionResponse.right().value());\r
- return response;\r
- }\r
- Object resource = RepresentationUtils.toRepresentation(actionResponse.left().value());\r
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resource);\r
-\r
- } catch (Exception e) {\r
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Filtered Component Instance Properties");\r
- log.debug("Getting of filtered component instance properties failed with exception", e);\r
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
-\r
- }\r
- }\r
-}\r
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.mixin.GroupCompositionMixin;
+import org.openecomp.sdc.be.mixin.PolicyCompositionMixin;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.IComponentInstanceConnectedElement;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
+import org.openecomp.sdc.be.ui.model.UiLeftPaletteComponent;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.be.view.ResponseView;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.openecomp.sdc.common.util.GeneralUtility.getCategorizedComponents;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Component Servlet",description = "Component Servlet"))
+@Controller
+public class ComponentServlet extends BeGenericServlet {
+ private static final String GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION = "getCertifiedNotAbstractComponents failed with exception";
+
+ private static final String GET_CERTIFIED_NON_ABSTRACT = "Get Certified Non Abstract";
+
+ private static final String FAILED_TO_GET_ALL_NON_ABSTRACT = "failed to get all non abstract {}";
+
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+
+ private static final Logger log = Logger.getLogger(ComponentServlet.class);
+
+ private final ComponentBusinessLogicProvider componentBusinessLogicProvider;
+
+ @Inject
+ public ComponentServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ ComponentBusinessLogicProvider componentBusinessLogicProvider) {
+ super(userBusinessLogic, componentsUtils);
+ this.componentBusinessLogicProvider = componentBusinessLogicProvider;
+ }
+
+ @GET
+ @Path("/{componentType}/{componentUuid}/conformanceLevelValidation")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Validate Component Conformance Level", method = "GET",
+ summary = "Returns the result according to conformance level in BE config", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response conformanceLevelValidation(@PathParam("componentType") final String componentType,
+ @PathParam("componentUuid") final String componentUuid, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ Response response;
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ if (componentTypeEnum != null) {
+ ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+ Either<Boolean, ResponseFormat> eitherConformanceLevel = compBL.validateConformanceLevel(componentUuid, componentTypeEnum, userId);
+ if (eitherConformanceLevel.isRight()) {
+ response = buildErrorResponse(eitherConformanceLevel.right().value());
+ } else {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), gson.toJson(eitherConformanceLevel.left().value()));
+ }
+ } else {
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ return response;
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/requirmentsCapabilities")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component Requirments And Capabilities", method = "GET",
+ summary = "Returns Requirements And Capabilities according to componentId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getRequirementAndCapabilities(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+ Response response;
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ if (componentTypeEnum != null) {
+ try {
+ ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ RepresentationUtils.toRepresentation(compBL.getRequirementsAndCapabilities(componentId, componentTypeEnum, userId)));
+ } catch (IOException e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Capabilities and requirements for " + componentId);
+ log.debug("getRequirementAndCapabilities failed with exception", e);
+ throw e;
+ }
+ } else {
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ return response;
+ }
+
+ @GET
+ @Path("/{componentType}/latestversion/notabstract")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component Requirments And Capabilities", method = "GET",
+ summary = "Returns Requirments And Capabilities according to componentId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getLatestVersionNotAbstractCheckoutComponents(
+ @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
+ @QueryParam("internalComponentType") String internalComponentType,
+ @QueryParam("componentUids") List<String> componentUids,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+
+ log.debug("Received componentUids size is {}", componentUids == null ? 0 : componentUids.size());
+
+ Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, componentTypeEnum, internalComponentType, componentUids, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);
+ log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);
+ throw e;
+
+ }
+ }
+
+ @POST
+ @Path("/{componentType}/latestversion/notabstract")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component Requirments And Capabilities", method = "GET",
+ summary = "Returns Requirments And Capabilities according to componentId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getLatestVersionNotAbstractCheckoutComponentsByBody(
+ @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
+ @QueryParam("internalComponentType") String internalComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "Consumer Object to be created", required = true) List<String> data) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(GET) Start handle request of {}", url);
+ Response response;
+
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+ if (log.isDebugEnabled()) {
+ log.debug("Received componentUids size is {}", data == null ? 0 : data.size());
+ }
+
+ Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, componentTypeEnum, internalComponentType, data, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);
+ return buildErrorResponse(actionResponse.right().value());
+
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);
+ log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);
+ throw e;
+ }
+
+ }
+
+ @GET
+ @Path("/{componentType}/latestversion/notabstract/metadata")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component uid only", method = "GET", summary = "Returns componentId",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getLatestVersionNotAbstractCheckoutComponentsIdesOnly(
+ @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
+ @QueryParam("internalComponentType") String internalComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "uid list", required = true) String data) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+
+ Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponentsMetadata(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, internalComponentType, userId);
+ if (actionResponse.isRight()) {
+ log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ List<UiLeftPaletteComponent> uiLeftPaletteComponents = getComponentsUtils().convertComponentToUiLeftPaletteComponentObject(actionResponse.left().value());
+ Map<String, Map<String, List<UiLeftPaletteComponent>>> categorizedComponents = getCategorizedComponents(uiLeftPaletteComponents);
+ Object components = RepresentationUtils.toRepresentation(categorizedComponents);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);
+ log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);
+ throw e;
+ }
+
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/componentInstances")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component instances", method = "GET", summary = "Returns component instances",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getComponentInstancesFilteredByPropertiesAndInputs(
+ @PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
+ @Context final HttpServletRequest request, @QueryParam("searchText") String searchText,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "uid" + " " + "list", required = true) String data) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(GET) Start handle request of {}", url);
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+
+ Either<List<ComponentInstance>, ResponseFormat> actionResponse = businessLogic.getComponentInstancesFilteredByPropertiesAndInputs(componentId, userId);
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all component instances filtered by properties and inputs", componentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Instances filtered by properties & inputs" + componentType);
+ log.debug("getComponentInstancesFilteredByPropertiesAndInputs failed with exception", e);
+ throw e;
+ }
+ }
+
+
+
+ /**
+ * This API is a generic api for ui - the api get a list of strings and return the data on the component according to to list.
+ * for example: list of the string "properties, inputs" will return component with the list of properties and inputs.
+ *
+ * @param componentType
+ * @param componentId
+ * @param dataParamsToReturn
+ * @param request
+ * @param userId
+ * @return
+ */
+
+
+ @GET
+ @Path("/{componentType}/{componentId}/filteredDataByParams")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve Resource", method = "GET", summary = "Returns resource according to resourceId",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ResponseView(mixin = {GroupCompositionMixin.class, PolicyCompositionMixin.class})
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Resource not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getComponentDataFilteredByParams(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId,
+ @QueryParam("include") final List<String> dataParamsToReturn, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF , url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}" , userId);
+
+ try {
+ String resourceIdLower = componentId.toLowerCase();
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+
+ log.trace("get component with id {} filtered by ui params", componentId);
+ Either<UiComponentDataTransfer, ResponseFormat> actionResponse = businessLogic.getComponentDataFilteredByParams(resourceIdLower, modifier, dataParamsToReturn);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get component data filtered by ui params");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get component filtered by ui params");
+ log.debug("get resource failed with exception", e);
+ throw e;
+ }
+ }
+
+
+ @GET
+ @Path("/{componentType}/{componentId}/filteredproperties/{propertyNameFragment}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(
+ description = "Retrieve properties belonging to component instances of specific component by name and optionally resource type",
+ method = "GET",
+ summary = "Returns properties belonging to component instances of specific component by name and optionally resource type",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Map.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getFilteredComponentInstanceProperties(
+ @PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("propertyNameFragment") final String propertyNameFragment,
+ @QueryParam("resourceType") List<String> resourceTypes,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ User user = new User();
+ user.setUserId(userId);
+ log.debug("User Id is {}" , userId);
+ Response response;
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+ Map<FilterKeyEnum, List<String>> filters = new EnumMap<>(FilterKeyEnum.class);
+ List<String> propertyNameFragments = new ArrayList<>();
+ propertyNameFragments.add(propertyNameFragment);
+ filters.put(FilterKeyEnum.NAME_FRAGMENT, propertyNameFragments);
+ if(CollectionUtils.isNotEmpty(resourceTypes)){
+ filters.put(FilterKeyEnum.RESOURCE_TYPE, resourceTypes);
+ }
+ Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> actionResponse = businessLogic.getFilteredComponentInstanceProperties(componentId, filters, userId);
+ if (actionResponse.isRight()) {
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ Object resource = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resource);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Filtered Component Instance Properties");
+ log.debug("Getting of filtered component instance properties failed with exception", e);
+ throw e;
+ }
+ }
+}