Upgrade swagger
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / PolicyServlet.java
index 38f3878..1ab061f 100644 (file)
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 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.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.StringUtils;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
-import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.PolicyDefinition;
-import org.openecomp.sdc.be.model.PolicyTargetDTO;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.stereotype.Controller;
-
-/**
- * Provides REST API to create, retrieve, update, delete a policy
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@Api(value = "Policy Servlet")
-@Controller
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class PolicyServlet extends AbstractValidationsServlet {
-
-    private static final Logger log = Logger.getLogger(PolicyServlet.class);
-    private final PolicyBusinessLogic policyBusinessLogic;
-
-    @Inject
-    public PolicyServlet(UserBusinessLogic userBusinessLogic,
-        ComponentInstanceBusinessLogic componentInstanceBL,
-        ComponentsUtils componentsUtils, ServletUtils servletUtils,
-        ResourceImportManager resourceImportManager,
-        PolicyBusinessLogic policyBusinessLogic) {
-        super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
-        this.policyBusinessLogic = policyBusinessLogic;
-    }
-
-    @POST
-    @Path("/{containerComponentType}/{componentId}/policies/{policyTypeName}")
-    @ApiOperation(value = "Create Policy", httpMethod = "POST", notes = "Returns created Policy", response = Response.class)
-    @ApiResponses(value = {@ApiResponse(code = 201, message = "Policy created"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
-            @ApiResponse(code = 409, message = "Policy already exist"),  @ApiResponse(code = 404, message = "Component not found")})
-    public Response createPolicy(@PathParam("componentId") final String containerComponentId,
-                                 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
-                                 @PathParam("policyTypeName") final String policyTypeName,
-                                 @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId,
-                                 @Context final HttpServletRequest request) {
-        init();
-
-        Wrapper<Response> responseWrapper = new Wrapper<>();
-        try {
-            Wrapper<ComponentTypeEnum> componentTypeWrapper = validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
-            if (responseWrapper.isEmpty()) {
-                responseWrapper.setInnerElement(policyBusinessLogic.createPolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyTypeName, userId, true)
-                        .either(l -> buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), l),
-                                this::buildErrorResponse));
-            }
-        } catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Policy");
-            log.error("Failed to create policy. The exception {} occurred. ", e);
-            responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
-        }
-        return responseWrapper.getInnerElement();
-    }
-
-    @PUT
-    @Path("/{containerComponentType}/{componentId}/policies/{policyId}")
-    @ApiOperation(value = "Update Policy metadata", httpMethod = "PUT", notes = "Returns updated Policy", response = Response.class)
-    @ApiResponses(value = {@ApiResponse(code = 200, message = "Policy updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
-            @ApiResponse(code = 404, message = "component / policy Not found")})
-    public Response updatePolicy(@PathParam("componentId") final String containerComponentId,
-                                 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
-                                 @PathParam("policyId") final String policyId, @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId,
-                                 @ApiParam(value = "PolicyDefinition", required = true) String policyData, @Context final HttpServletRequest request) {
-        init();
-
-        Wrapper<Response> responseWrapper = new Wrapper<>();
-        try {
-            Wrapper<ComponentTypeEnum> componentTypeWrapper = validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
-            Wrapper<PolicyDefinition> policyWrapper = new Wrapper<>();
-            if (responseWrapper.isEmpty()) {
-                convertJsonToObjectOfClass(policyData, policyWrapper, PolicyDefinition.class, responseWrapper);
-                if (policyWrapper.isEmpty()) {
-                    responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)));
-                }
-            }
-            if (!policyWrapper.isEmpty()) {
-                policyWrapper.getInnerElement().setUniqueId(policyId);
-                responseWrapper.setInnerElement(policyBusinessLogic.updatePolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyWrapper.getInnerElement(), userId, true)
-                        .either(this::buildOkResponse,
-                                this::buildErrorResponse));
-            }
-
-        } catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Policy");
-            log.error("Failed to update policy. The exception {} occurred. ", e);
-            responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
-        }
-        return responseWrapper.getInnerElement();
-    }
-
-    @GET
-    @Path("/{containerComponentType}/{componentId}/policies/{policyId}")
-    @ApiOperation(value = "Get Policy", httpMethod = "GET", notes = "Returns Policy", response = Response.class)
-    @ApiResponses(value = {@ApiResponse(code = 200, message = "Policy was found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
-            @ApiResponse(code = 404, message = "component / policy Not found")})
-    public Response getPolicy(@PathParam("componentId") final String containerComponentId,
-                              @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
-                              @PathParam("policyId") final String policyId, @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId,
-                              @Context final HttpServletRequest request) {
-        init();
-
-        Wrapper<Response> responseWrapper = new Wrapper<>();
-        try {
-            Wrapper<ComponentTypeEnum> componentTypeWrapper = validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
-            if (responseWrapper.isEmpty()) {
-                responseWrapper.setInnerElement(policyBusinessLogic.getPolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyId, userId)
-                        .either(this::buildOkResponse,
-                                this::buildErrorResponse));
-            }
-
-        } catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Policy");
-            log.error("Failed to retrieve policy. The exception {} occurred. ", e);
-            responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
-        }
-        return responseWrapper.getInnerElement();
-    }
-
-    @DELETE
-    @Path("/{containerComponentType}/{componentId}/policies/{policyId}")
-    @ApiOperation(value = "Delete Policy", httpMethod = "DELETE", notes = "No body", response = Response.class)
-    @ApiResponses(value = {@ApiResponse(code = 204, message = "Policy was deleted"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
-            @ApiResponse(code = 404, message = "component / policy Not found")})
-    public Response deletePolicy(@PathParam("componentId") final String containerComponentId,
-                                 @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
-                                 @PathParam("policyId") final String policyId, @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId,
-                                 @Context final HttpServletRequest request) {
-        init();
-
-        Wrapper<Response> responseWrapper = new Wrapper<>();
-        try {
-            Wrapper<ComponentTypeEnum> componentTypeWrapper = validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
-            if (responseWrapper.isEmpty()) {
-                responseWrapper.setInnerElement(policyBusinessLogic.deletePolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyId, userId, true)
-                        .either(this::buildOkResponse,
-                                this::buildErrorResponse));
-            }
-
-        } catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Policy");
-            log.error("Failed to delete policy. The exception {} occurred. ", e);
-            responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
-        }
-        return responseWrapper.getInnerElement();
-    }
-
-    @PUT
-    @Path("/{containerComponentType}/{componentId}/policies/{policyId}/undeclare")
-    @ApiOperation(value = "undeclare Policy", httpMethod = "PUT", notes = "No body", response = Response.class)
-    @ApiResponses(value = {@ApiResponse(code = 204, message = "Policy was undeclared"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
-            @ApiResponse(code = 404, message = "component / policy Not found")})
-    public Response undeclarePolicy(@PathParam("componentId") final String containerComponentId,
-            @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
-            @PathParam("policyId") final String policyId, @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId,
-            @Context final HttpServletRequest request) {
-        init();
-
-        Wrapper<Response> responseWrapper = new Wrapper<>();
-        try {
-            Wrapper<ComponentTypeEnum> componentTypeWrapper = validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
-            if (responseWrapper.isEmpty()) {
-                responseWrapper.setInnerElement(policyBusinessLogic.undeclarePolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyId, userId, true)
-                                                        .either(this::buildOkResponse,
-                                                                this::buildErrorResponse));
-            }
-
-        } catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Undeclare Policy");
-            log.error("Failed to undeclare policy. The exception {} occurred. ", e);
-            responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
-        }
-        return responseWrapper.getInnerElement();
-    }
-
-    @GET
-    @Path("/{containerComponentType}/{componentId}/policies/{policyId}/properties")
-    @ApiOperation(value = "Get component policy properties", httpMethod = "GET", notes = "Returns component policy properties", response = PropertyDataDefinition.class, responseContainer="List")
-    @ApiResponses(value = {@ApiResponse(code = 200, message = "Properties found"),@ApiResponse(code = 400, message = "invalid content - Error: containerComponentType is invalid"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Componentorpolicy  not found"),
-    @ApiResponse(code = 500, message = "The GET request failed due to internal SDC problem.") })public Response getPolicyProperties(@ApiParam(value = "the id of the component which is the container of the policy") @PathParam("componentId") final String containerComponentId,
-                                        @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
-                                        @ApiParam(value = "the id of the policy which its properties are to return") @PathParam("policyId") final String policyId,
-                                        @ApiParam(value = "the userid", required = true)@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
-                                        @Context final HttpServletRequest request) {
-        init();
-        try {
-            return convertToComponentType(containerComponentType)
-                    .left()
-                    .bind(cmptType -> policyBusinessLogic.getPolicyProperties(cmptType, containerComponentId, policyId, userId))
-                    .either(this::buildOkResponse,
-                            this::buildErrorResponse);
-        } catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("get Policy properties");
-            log.debug("#getPolicyProperties - get Policy properties has failed.", e);
-            return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-        }
-
-
-    }
-
-    @PUT
-    @Path("/{containerComponentType}/{componentId}/policies/{policyId}/properties")
-    @ApiOperation(value = "Update Policy properties", httpMethod = "PUT", notes = "Returns updated Policy", response = Response.class)
-    @ApiResponses(value = {@ApiResponse(code = 200, message = "Policy properties updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content"),
-            @ApiResponse(code = 404, message = "component / policy Not found")})
-    public Response updatePolicyProperties(@PathParam("componentId") final String containerComponentId,
-                                           @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
-                                           @PathParam("policyId") final String policyId, @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId,
-                                           @ApiParam(value = "PolicyDefinition", required = true) String policyData, @Context final HttpServletRequest request) {
-        init();
-        Wrapper<Response> responseWrapper = new Wrapper<>();
-        try {
-            Wrapper<ComponentTypeEnum> componentTypeWrapper = validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
-            Wrapper<PropertyDataDefinition[]> propertiesWrapper = new Wrapper<>();
-            if (responseWrapper.isEmpty()) {
-                convertJsonToObjectOfClass(policyData, propertiesWrapper, PropertyDataDefinition[].class, responseWrapper);
-                if (propertiesWrapper.isEmpty()) {
-                    responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)));
-                }
-            }
-            if (!propertiesWrapper.isEmpty()) {
-                responseWrapper.setInnerElement(
-                        policyBusinessLogic.updatePolicyProperties(componentTypeWrapper.getInnerElement(), containerComponentId, policyId, propertiesWrapper.getInnerElement(), userId, true)
-                                .either(this::buildOkResponse, this::buildErrorResponse));
-            }
-        } catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Policy");
-            log.error("Failed to update policy. The exception {} occurred. ", e);
-            responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
-        }
-        return responseWrapper.getInnerElement();
-    }
-
-    private Wrapper<ComponentTypeEnum> validateComponentTypeAndUserId(final String containerComponentType, String userId, Wrapper<Response> responseWrapper) {
-        Wrapper<ComponentTypeEnum> componentTypeWrapper = new Wrapper<>();
-        if (StringUtils.isEmpty(userId)) {
-            log.error("Missing userId HTTP header. ");
-            responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID)));
-        }
-        if (responseWrapper.isEmpty()) {
-            validateComponentType(responseWrapper, componentTypeWrapper, containerComponentType);
-        }
-        return componentTypeWrapper;
-    }
-
-       @POST
-       @Path("/{containerComponentType}/{componentId}/policies/{policyId}/targets")
-       @Consumes(MediaType.APPLICATION_JSON)
-       @Produces(MediaType.APPLICATION_JSON)
-       @ApiOperation(value = "update policy targets", httpMethod = "POST", notes = "Returns updated Policy", response = Response.class)
-       @ApiResponses(value = {@ApiResponse(code = 201, message = "Policy target updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content")})
-       public Response updatePolicyTargets(@PathParam("componentId") final String containerComponentId,
-                                                                               @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
-                                                                               @PathParam("policyId") final String policyId,
-                                                                               @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId,
-                                                                               @Context final HttpServletRequest request,
-                                                                               List<PolicyTargetDTO> requestJson) {
-               try {
-
-                   return updatePolicyTargetsFromDTO(requestJson)
-                    .left()
-                    .bind(policyTarget -> updatePolicyTargetsFromMap(policyTarget, containerComponentType, containerComponentId, policyId, userId))
-                    .either(this::buildOkResponse, this::buildErrorResponse);
-
-        } catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Policy");
-            log.debug("Policy target update has been failed with the exception{}. ", e);
-            return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-        }
-    }
-
-    @POST
-    @Path("/{componentType}/{componentId}/create/policies")
-    @ApiOperation(value = "Create policies on service", httpMethod = "POST", notes = "Return policies list", response = Resource.class)
-    @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
-    public Response declareProperties(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
-            @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @ApiParam(value = "ComponentIns policies Object to be created", required = true) String componentInstPoliciesMapObj) {
-
-        return super.declareProperties(userId, componentId, componentType, componentInstPoliciesMapObj,
-                DeclarationTypeEnum.POLICY, request);
-    }
-
-    private Either<PolicyDefinition, ResponseFormat> updatePolicyTargetsFromMap(Map<PolicyTargetType, List<String>> policyTarget, String containerComponentType, String containerComponentId, String policyId, String userId) {
-        return convertToComponentType(containerComponentType)
-                .left()
-                .bind(cmptType -> policyBusinessLogic.updatePolicyTargets(cmptType, containerComponentId, policyId, policyTarget, userId));
-    }
-
-    private Either<Map<PolicyTargetType, List<String>>, ResponseFormat> updatePolicyTargetsFromDTO(List<PolicyTargetDTO> targetDTOList) {
-        Map<PolicyTargetType, List<String>> policyTarget = new HashMap<>();
-        for (PolicyTargetDTO currentTarget : targetDTOList) {
-            if(!addTargetsByType(policyTarget, currentTarget.getType(), currentTarget.getUniqueIds())){
-                return Either.right(componentsUtils.getResponseFormat(ActionStatus.POLICY_TARGET_TYPE_DOES_NOT_EXIST, currentTarget.getType()));
-            }
-        }
-        return Either.left(policyTarget);
-    }
-
-
-    public boolean addTargetsByType(Map<PolicyTargetType, List<String>> policyTarget, String type, List<String> uniqueIds) {
-        PolicyTargetType targetTypeEnum = PolicyTargetType.getByNameIgnoreCase(type);
-        if(targetTypeEnum != null){
-            policyTarget.put(targetTypeEnum, validateUniquenessOfIds(uniqueIds));
-            return true;
-        }
-        else{
-            return false;
-        }
-    }
-
-    private List<String> validateUniquenessOfIds(List<String> uniqueIds) {
-        return uniqueIds.stream().distinct().collect(Collectors.toList());
-    }
-}
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * SDC\r
+ * ================================================================================\r
+ * Copyright (C) 2019 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.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.stream.Collectors;\r
+import javax.inject.Inject;\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.ws.rs.Consumes;\r
+import javax.ws.rs.DELETE;\r
+import javax.ws.rs.GET;\r
+import javax.ws.rs.HeaderParam;\r
+import javax.ws.rs.POST;\r
+import javax.ws.rs.PUT;\r
+import javax.ws.rs.Path;\r
+import javax.ws.rs.PathParam;\r
+import javax.ws.rs.Produces;\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.lang3.StringUtils;\r
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;\r
+import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;\r
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;\r
+import org.openecomp.sdc.be.config.BeEcompErrorManager;\r
+import org.openecomp.sdc.be.dao.api.ActionStatus;\r
+import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;\r
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;\r
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;\r
+import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;\r
+import org.openecomp.sdc.be.impl.ComponentsUtils;\r
+import org.openecomp.sdc.be.impl.ServletUtils;\r
+import org.openecomp.sdc.be.model.PolicyDefinition;\r
+import org.openecomp.sdc.be.model.PolicyTargetDTO;\r
+import org.openecomp.sdc.be.model.Resource;\r
+import org.openecomp.sdc.be.user.UserBusinessLogic;\r
+import org.openecomp.sdc.common.api.Constants;\r
+import org.openecomp.sdc.common.datastructure.Wrapper;\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
+ * Provides REST API to create, retrieve, update, delete a policy\r
+ */\r
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)\r
+@Path("/v1/catalog")\r
+@OpenAPIDefinition(info = @Info(title = "Policy Servlet"))\r
+@Controller\r
+@Consumes(MediaType.APPLICATION_JSON)\r
+@Produces(MediaType.APPLICATION_JSON)\r
+public class PolicyServlet extends AbstractValidationsServlet {\r
+\r
+    private static final Logger log = Logger.getLogger(PolicyServlet.class);\r
+    private final PolicyBusinessLogic policyBusinessLogic;\r
+\r
+    @Inject\r
+    public PolicyServlet(UserBusinessLogic userBusinessLogic,\r
+        ComponentInstanceBusinessLogic componentInstanceBL,\r
+        ComponentsUtils componentsUtils, ServletUtils servletUtils,\r
+        ResourceImportManager resourceImportManager,\r
+        PolicyBusinessLogic policyBusinessLogic) {\r
+        super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);\r
+        this.policyBusinessLogic = policyBusinessLogic;\r
+    }\r
+\r
+    @POST\r
+    @Path("/{containerComponentType}/{componentId}/policies/{policyTypeName}")\r
+    @Operation(description = "Create Policy", method = "POST", summary = "Returns created Policy",\r
+            responses = @ApiResponse(\r
+                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
+    @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Policy created"),\r
+            @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
+            @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),\r
+            @ApiResponse(responseCode = "409", description = "Policy already exist"),\r
+            @ApiResponse(responseCode = "404", description = "Component not found")})\r
+    public Response createPolicy(@PathParam("componentId") final String containerComponentId, @Parameter(description = "valid values: resources / services",\r
+            schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,\r
+                    ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,\r
+            @PathParam("policyTypeName") final String policyTypeName,\r
+            @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",\r
+                    required = true) String userId,\r
+            @Context final HttpServletRequest request) {\r
+        init();\r
+\r
+        Wrapper<Response> responseWrapper = new Wrapper<>();\r
+        try {\r
+            Wrapper<ComponentTypeEnum> componentTypeWrapper =\r
+                    validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);\r
+            if (responseWrapper.isEmpty()) {\r
+                responseWrapper.setInnerElement(policyBusinessLogic\r
+                        .createPolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyTypeName,\r
+                                userId, true)\r
+                        .either(l -> buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), l),\r
+                                this::buildErrorResponse));\r
+            }\r
+        } catch (Exception e) {\r
+            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Policy");\r
+            log.error("Failed to create policy. The exception {} occurred. ", e);\r
+            responseWrapper.setInnerElement(\r
+                    buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));\r
+        }\r
+        return responseWrapper.getInnerElement();\r
+    }\r
+\r
+    @PUT\r
+    @Path("/{containerComponentType}/{componentId}/policies/{policyId}")\r
+    @Operation(description = "Update Policy metadata", method = "PUT", summary = "Returns updated Policy",\r
+            responses = @ApiResponse(\r
+                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
+    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Policy updated"),\r
+            @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
+            @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),\r
+            @ApiResponse(responseCode = "404", description = "component / policy Not found")})\r
+    public Response updatePolicy(@PathParam("componentId") final String containerComponentId, @Parameter(\r
+            description = "valid values: resources / services",\r
+                    schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,\r
+                            ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,\r
+            @PathParam("policyId") final String policyId,\r
+            @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",\r
+                    required = true) String userId,\r
+            @Parameter(description = "PolicyDefinition", required = true) String policyData,\r
+            @Context final HttpServletRequest request) {\r
+        init();\r
+\r
+        Wrapper<Response> responseWrapper = new Wrapper<>();\r
+        try {\r
+            Wrapper<ComponentTypeEnum> componentTypeWrapper =\r
+                    validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);\r
+            Wrapper<PolicyDefinition> policyWrapper = new Wrapper<>();\r
+            if (responseWrapper.isEmpty()) {\r
+                convertJsonToObjectOfClass(policyData, policyWrapper, PolicyDefinition.class, responseWrapper);\r
+                if (policyWrapper.isEmpty()) {\r
+                    responseWrapper.setInnerElement(\r
+                            buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)));\r
+                }\r
+            }\r
+            if (!policyWrapper.isEmpty()) {\r
+                policyWrapper.getInnerElement().setUniqueId(policyId);\r
+                responseWrapper.setInnerElement(policyBusinessLogic\r
+                        .updatePolicy(componentTypeWrapper.getInnerElement(), containerComponentId,\r
+                                policyWrapper.getInnerElement(), userId, true)\r
+                        .either(this::buildOkResponse, this::buildErrorResponse));\r
+            }\r
+\r
+        } catch (Exception e) {\r
+            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Policy");\r
+            log.error("Failed to update policy. The exception {} occurred. ", e);\r
+            responseWrapper.setInnerElement(\r
+                    buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));\r
+        }\r
+        return responseWrapper.getInnerElement();\r
+    }\r
+\r
+    @GET\r
+    @Path("/{containerComponentType}/{componentId}/policies/{policyId}")\r
+    @Operation(description = "Get Policy", method = "GET", summary = "Returns Policy", responses = @ApiResponse(\r
+            content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
+    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Policy was found"),\r
+            @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
+            @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),\r
+            @ApiResponse(responseCode = "404", description = "component / policy Not found")})\r
+    public Response getPolicy(@PathParam("componentId") final String containerComponentId, @Parameter(\r
+            description = "valid values: resources / services",\r
+                    schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,\r
+                            ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,\r
+            @PathParam("policyId") final String policyId,\r
+            @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",\r
+                    required = true) String userId,\r
+            @Context final HttpServletRequest request) {\r
+        init();\r
+\r
+        Wrapper<Response> responseWrapper = new Wrapper<>();\r
+        try {\r
+            Wrapper<ComponentTypeEnum> componentTypeWrapper =\r
+                    validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);\r
+            if (responseWrapper.isEmpty()) {\r
+                responseWrapper.setInnerElement(policyBusinessLogic\r
+                        .getPolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyId, userId)\r
+                        .either(this::buildOkResponse, this::buildErrorResponse));\r
+            }\r
+\r
+        } catch (Exception e) {\r
+            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Policy");\r
+            log.error("Failed to retrieve policy. The exception {} occurred. ", e);\r
+            responseWrapper.setInnerElement(\r
+                    buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));\r
+        }\r
+        return responseWrapper.getInnerElement();\r
+    }\r
+\r
+    @DELETE\r
+    @Path("/{containerComponentType}/{componentId}/policies/{policyId}")\r
+    @Operation(description = "Delete Policy", method = "DELETE", summary = "No body", responses = @ApiResponse(\r
+            content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
+    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Policy was deleted"),\r
+            @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
+            @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),\r
+            @ApiResponse(responseCode = "404", description = "component / policy Not found")})\r
+    public Response deletePolicy(@PathParam("componentId") final String containerComponentId, @Parameter(\r
+            description = "valid values: resources / services",\r
+                    schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,\r
+                            ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,\r
+            @PathParam("policyId") final String policyId,\r
+            @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",\r
+                    required = true) String userId,\r
+            @Context final HttpServletRequest request) {\r
+        init();\r
+\r
+        Wrapper<Response> responseWrapper = new Wrapper<>();\r
+        try {\r
+            Wrapper<ComponentTypeEnum> componentTypeWrapper =\r
+                    validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);\r
+            if (responseWrapper.isEmpty()) {\r
+                responseWrapper\r
+                        .setInnerElement(\r
+                                policyBusinessLogic\r
+                                        .deletePolicy(componentTypeWrapper.getInnerElement(), containerComponentId,\r
+                                                policyId, userId, true)\r
+                                        .either(this::buildOkResponse, this::buildErrorResponse));\r
+            }\r
+\r
+        } catch (Exception e) {\r
+            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Policy");\r
+            log.error("Failed to delete policy. The exception {} occurred. ", e);\r
+            responseWrapper.setInnerElement(\r
+                    buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));\r
+        }\r
+        return responseWrapper.getInnerElement();\r
+    }\r
+\r
+    @PUT\r
+    @Path("/{containerComponentType}/{componentId}/policies/{policyId}/undeclare")\r
+    @Operation(description = "undeclare Policy", method = "PUT", summary = "No body",responses = @ApiResponse(\r
+            content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
+    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Policy was undeclared"),\r
+            @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
+            @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),\r
+            @ApiResponse(responseCode = "404", description = "component / policy Not found")})\r
+    public Response undeclarePolicy(@PathParam("componentId") final String containerComponentId, @Parameter(\r
+            description = "valid values: resources / services",\r
+                    schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,\r
+                            ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,\r
+            @PathParam("policyId") final String policyId,\r
+            @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",\r
+                    required = true) String userId,\r
+            @Context final HttpServletRequest request) {\r
+        init();\r
+\r
+        Wrapper<Response> responseWrapper = new Wrapper<>();\r
+        try {\r
+            Wrapper<ComponentTypeEnum> componentTypeWrapper =\r
+                    validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);\r
+            if (responseWrapper.isEmpty()) {\r
+                responseWrapper\r
+                        .setInnerElement(\r
+                                policyBusinessLogic\r
+                                        .undeclarePolicy(componentTypeWrapper.getInnerElement(), containerComponentId,\r
+                                                policyId, userId, true)\r
+                                        .either(this::buildOkResponse, this::buildErrorResponse));\r
+            }\r
+\r
+        } catch (Exception e) {\r
+            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Undeclare Policy");\r
+            log.error("Failed to undeclare policy. The exception {} occurred. ", e);\r
+            responseWrapper.setInnerElement(\r
+                    buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));\r
+        }\r
+        return responseWrapper.getInnerElement();\r
+    }\r
+\r
+    @GET\r
+    @Path("/{containerComponentType}/{componentId}/policies/{policyId}/properties")\r
+    @Operation(description = "Get component policy properties", method = "GET",\r
+            summary = "Returns component policy properties",responses = @ApiResponse(\r
+                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = PropertyDataDefinition.class)))))\r
+    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Properties found"),\r
+            @ApiResponse(responseCode = "400",\r
+                    description = "invalid content - Error: containerComponentType is invalid"),\r
+            @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
+            @ApiResponse(responseCode = "404", description = "Componentorpolicy  not found"),\r
+            @ApiResponse(responseCode = "500", description = "The GET request failed due to internal SDC problem.")})\r
+    public Response getPolicyProperties(@Parameter(\r
+            description = "the id of the component which is the container of the policy") @PathParam("componentId") final String containerComponentId,\r
+            @Parameter(description = "valid values: resources / services",\r
+                    schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,\r
+                            ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,\r
+            @Parameter(\r
+                    description = "the id of the policy which its properties are to return") @PathParam("policyId") final String policyId,\r
+            @Parameter(description = "the userid",\r
+                    required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId,\r
+            @Context final HttpServletRequest request) {\r
+        init();\r
+        try {\r
+            return convertToComponentType(containerComponentType).left().bind(cmptType -> policyBusinessLogic\r
+                    .getPolicyProperties(cmptType, containerComponentId, policyId, userId))\r
+                    .either(this::buildOkResponse, this::buildErrorResponse);\r
+        } catch (Exception e) {\r
+            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("get Policy properties");\r
+            log.debug("#getPolicyProperties - get Policy properties has failed.", e);\r
+            return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
+        }\r
+\r
+\r
+    }\r
+\r
+    @PUT\r
+    @Path("/{containerComponentType}/{componentId}/policies/{policyId}/properties")\r
+    @Operation(description = "Update Policy properties", method = "PUT", summary = "Returns updated Policy",\r
+            responses = @ApiResponse(\r
+                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
+    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Policy properties updated"),\r
+            @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
+            @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),\r
+            @ApiResponse(responseCode = "404", description = "component / policy Not found")})\r
+    public Response updatePolicyProperties(@PathParam("componentId") final String containerComponentId, @Parameter(\r
+            description = "valid values: resources / services",\r
+                    schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,\r
+                            ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,\r
+            @PathParam("policyId") final String policyId,\r
+            @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",\r
+                    required = true) String userId,\r
+            @Parameter(description = "PolicyDefinition", required = true) String policyData,\r
+            @Context final HttpServletRequest request) {\r
+        init();\r
+        Wrapper<Response> responseWrapper = new Wrapper<>();\r
+        try {\r
+            Wrapper<ComponentTypeEnum> componentTypeWrapper =\r
+                    validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);\r
+            Wrapper<PropertyDataDefinition[]> propertiesWrapper = new Wrapper<>();\r
+            if (responseWrapper.isEmpty()) {\r
+                convertJsonToObjectOfClass(policyData, propertiesWrapper, PropertyDataDefinition[].class,\r
+                        responseWrapper);\r
+                if (propertiesWrapper.isEmpty()) {\r
+                    responseWrapper.setInnerElement(\r
+                            buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)));\r
+                }\r
+            }\r
+            if (!propertiesWrapper.isEmpty()) {\r
+                responseWrapper.setInnerElement(policyBusinessLogic\r
+                        .updatePolicyProperties(componentTypeWrapper.getInnerElement(), containerComponentId, policyId,\r
+                                propertiesWrapper.getInnerElement(), userId, true)\r
+                        .either(this::buildOkResponse, this::buildErrorResponse));\r
+            }\r
+        } catch (Exception e) {\r
+            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Policy");\r
+            log.error("Failed to update policy. The exception {} occurred. ", e);\r
+            responseWrapper.setInnerElement(\r
+                    buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));\r
+        }\r
+        return responseWrapper.getInnerElement();\r
+    }\r
+\r
+    private Wrapper<ComponentTypeEnum> validateComponentTypeAndUserId(final String containerComponentType, String userId, Wrapper<Response> responseWrapper) {\r
+        Wrapper<ComponentTypeEnum> componentTypeWrapper = new Wrapper<>();\r
+        if (StringUtils.isEmpty(userId)) {\r
+            log.error("Missing userId HTTP header. ");\r
+            responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID)));\r
+        }\r
+        if (responseWrapper.isEmpty()) {\r
+            validateComponentType(responseWrapper, componentTypeWrapper, containerComponentType);\r
+        }\r
+        return componentTypeWrapper;\r
+    }\r
+\r
+    @POST\r
+    @Path("/{containerComponentType}/{componentId}/policies/{policyId}/targets")\r
+    @Consumes(MediaType.APPLICATION_JSON)\r
+    @Produces(MediaType.APPLICATION_JSON)\r
+    @Operation(description = "update policy targets", method = "POST", summary = "Returns updated Policy",\r
+            responses = @ApiResponse(\r
+                    content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))\r
+    @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Policy target updated"),\r
+            @ApiResponse(responseCode = "403", description = "Restricted operation"),\r
+            @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})\r
+    public Response updatePolicyTargets(@PathParam("componentId") final String containerComponentId, @Parameter(\r
+            description = "valid values: resources / services",\r
+                    schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,\r
+                            ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,\r
+            @PathParam("policyId") final String policyId,\r
+            @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",\r
+                    required = true) String userId,\r
+            @Context final HttpServletRequest request, List<PolicyTargetDTO> requestJson) {\r
+        try {\r
+\r
+            return updatePolicyTargetsFromDTO(requestJson).left()\r
+                    .bind(policyTarget -> updatePolicyTargetsFromMap(policyTarget, containerComponentType,\r
+                            containerComponentId, policyId, userId))\r
+                    .either(this::buildOkResponse, this::buildErrorResponse);\r
+\r
+        } catch (Exception e) {\r
+            BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Policy");\r
+            log.debug("Policy target update has been failed with the exception{}. ", e);\r
+            return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));\r
+        }\r
+    }\r
+\r
+    @POST\r
+    @Path("/{componentType}/{componentId}/create/policies")\r
+    @Operation(description = "Create policies on service", method = "POST", summary = "Return policies list",\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 declareProperties(@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
+            @Parameter(description = "ComponentIns policies Object to be created",\r
+                    required = true) String componentInstPoliciesMapObj) {\r
+\r
+        return super.declareProperties(userId, componentId, componentType, componentInstPoliciesMapObj,\r
+                DeclarationTypeEnum.POLICY, request);\r
+    }\r
+\r
+    private Either<PolicyDefinition, ResponseFormat> updatePolicyTargetsFromMap(\r
+            Map<PolicyTargetType, List<String>> policyTarget, String containerComponentType,\r
+            String containerComponentId, String policyId, String userId) {\r
+        return convertToComponentType(containerComponentType).left().bind(cmptType -> policyBusinessLogic\r
+                .updatePolicyTargets(cmptType, containerComponentId, policyId, policyTarget, userId));\r
+    }\r
+\r
+    private Either<Map<PolicyTargetType, List<String>>, ResponseFormat> updatePolicyTargetsFromDTO(\r
+            List<PolicyTargetDTO> targetDTOList) {\r
+        Map<PolicyTargetType, List<String>> policyTarget = new HashMap<>();\r
+        for (PolicyTargetDTO currentTarget : targetDTOList) {\r
+            if (!addTargetsByType(policyTarget, currentTarget.getType(), currentTarget.getUniqueIds())) {\r
+                return Either.right(componentsUtils.getResponseFormat(ActionStatus.POLICY_TARGET_TYPE_DOES_NOT_EXIST,\r
+                        currentTarget.getType()));\r
+            }\r
+        }\r
+        return Either.left(policyTarget);\r
+    }\r
+\r
+\r
+    public boolean addTargetsByType(Map<PolicyTargetType, List<String>> policyTarget, String type, List<String> uniqueIds) {\r
+        PolicyTargetType targetTypeEnum = PolicyTargetType.getByNameIgnoreCase(type);\r
+        if(targetTypeEnum != null){\r
+            policyTarget.put(targetTypeEnum, validateUniquenessOfIds(uniqueIds));\r
+            return true;\r
+        }\r
+        else{\r
+            return false;\r
+        }\r
+    }\r
+\r
+    private List<String> validateUniquenessOfIds(List<String> uniqueIds) {\r
+        return uniqueIds.stream().distinct().collect(Collectors.toList());\r
+    }\r
+}\r