diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java | 86 |
1 files changed, 28 insertions, 58 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java index a459e3d7e0..cede761386 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java @@ -1,45 +1,29 @@ package org.openecomp.sdc.be.externalapi.servlet; -import java.util.List; -import java.util.Map; - -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.WebApplicationException; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - +import fj.data.Either; import org.openecomp.sdc.be.components.impl.ExternalRefsBusinessLogic; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.dto.ExternalRefDTO; import org.openecomp.sdc.be.impl.ComponentsUtils; -import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.servlets.AbstractValidationsServlet; -import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.be.servlets.BeGenericServlet; import org.openecomp.sdc.common.datastructure.Wrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.stereotype.Controller; -import fj.data.Either; - +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; +import java.util.Map; @Path("/v1/catalog") @Controller -public class ExternalRefsServlet extends AbstractValidationsServlet { +public class ExternalRefsServlet extends BeGenericServlet { - private static final Logger log = LoggerFactory.getLogger(ExternalRefsServlet.class); - - private ExternalRefsBusinessLogic businessLogic; + private static final Logger log = Logger.getLogger(ExternalRefsServlet.class); + private final ComponentsUtils componentsUtils; + private final ExternalRefsBusinessLogic businessLogic; public ExternalRefsServlet(ExternalRefsBusinessLogic businessLogic, ComponentsUtils componentsUtils){ this.businessLogic = businessLogic; @@ -50,16 +34,15 @@ public class ExternalRefsServlet extends AbstractValidationsServlet { @Path("/{assetType}/{uuid}/version/{version}/resourceInstances/{componentInstanceName}/externalReferences/{objectType}") @Produces(MediaType.APPLICATION_JSON) public Response getComponentInstanceExternalRef( - @Context final HttpServletRequest request, @PathParam("assetType") String assetType, @PathParam("uuid") String uuid, @PathParam("version") String version, @PathParam("componentInstanceName") String componentInstanceName, - @PathParam("objectType") String objectType, @HeaderParam("USER_ID") String userId) { + @PathParam("objectType") String objectType, @HeaderParam("USER_ID") String userId, @HeaderParam("X-ECOMP-InstanceID") String xEcompInstanceId) { log.debug("GET component instance external interfaces {} {} {} {}", assetType, uuid, componentInstanceName, objectType); - Response r = authorizeAndValidateRequest(request, userId); + Response r = validateRequest(xEcompInstanceId); if (r != null){ return r; } @@ -76,15 +59,14 @@ public class ExternalRefsServlet extends AbstractValidationsServlet { @Path("/{assetType}/{uuid}/version/{version}/externalReferences/{objectType}") @Produces(MediaType.APPLICATION_JSON) public Map<String, List<String>> getAssetExternalRefByObjectType( - @Context final HttpServletRequest request, @PathParam("assetType") String assetType, @PathParam("uuid") String uuid, @PathParam("version") String version, - @PathParam("objectType") String objectType, @HeaderParam("USER_ID") String userId) { + @PathParam("objectType") String objectType, @HeaderParam("USER_ID") String userId, @HeaderParam("X-ECOMP-InstanceID") String xEcompInstanceId) { log.debug("GET asset external references {} {} {}", assetType, uuid, objectType); - Response r = authorizeAndValidateRequest(request, userId); + Response r = validateRequest(xEcompInstanceId); if (r != null){ throw new WebApplicationException(r); } @@ -102,20 +84,19 @@ public class ExternalRefsServlet extends AbstractValidationsServlet { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response addComponentInstanceExternalRef( - @Context final HttpServletRequest request, @PathParam("assetType") String assetType, @PathParam("uuid") String uuid, @PathParam("componentInstanceName") String componentInstanceName, - @PathParam("objectType") String objectType, ExternalRefDTO ref, @HeaderParam("USER_ID") String userId) { + @PathParam("objectType") String objectType, ExternalRefDTO ref, @HeaderParam("USER_ID") String userId, @HeaderParam("X-ECOMP-InstanceID") String xEcompInstanceId) { log.debug("POST component instance external interfaces {} {} {} {} {}", assetType, uuid, componentInstanceName, objectType, ref); - Response r = authorizeAndValidateRequest(request, userId); + Response r = validateRequest(xEcompInstanceId); if (r != null){ return r; } - Either<String, ActionStatus> addResult = this.businessLogic.addExternalReference(uuid, componentInstanceName, objectType, ref); + Either<String, ActionStatus> addResult = this.businessLogic.addExternalReference(ComponentTypeEnum.findByParamName(assetType), userId, uuid, componentInstanceName, objectType, ref); if (addResult.isLeft()) { return Response.status(Response.Status.CREATED) .entity(ref) @@ -130,21 +111,20 @@ public class ExternalRefsServlet extends AbstractValidationsServlet { @Path("/{assetType}/{uuid}/resourceInstances/{componentInstanceName}/externalReferences/{objectType}/{reference}") @Produces(MediaType.APPLICATION_JSON) public Response deleteComponentInstanceReference( - @Context final HttpServletRequest request, @PathParam("assetType") String assetType, @PathParam("uuid") String uuid, @PathParam("componentInstanceName") String componentInstanceName, @PathParam("objectType") String objectType, - @PathParam("reference") String reference, @HeaderParam("USER_ID") String userId) { + @PathParam("reference") String reference, @HeaderParam("USER_ID") String userId, @HeaderParam("X-ECOMP-InstanceID") String xEcompInstanceId) { log.debug("DELETE component instance external interfaces {} {} {} {}", assetType, uuid, componentInstanceName, objectType); - Response r = authorizeAndValidateRequest(request, userId); + Response r = validateRequest(xEcompInstanceId); if (r != null){ return r; } - Either<String, ActionStatus> deleteStatus = this.businessLogic.deleteExternalReference(uuid, componentInstanceName, objectType, reference); + Either<String, ActionStatus> deleteStatus = this.businessLogic.deleteExternalReference(ComponentTypeEnum.findByParamName(assetType), userId, uuid, componentInstanceName, objectType, reference); if (deleteStatus.isLeft()){ return this.buildOkResponse(new ExternalRefDTO(reference)); } else { @@ -157,23 +137,22 @@ public class ExternalRefsServlet extends AbstractValidationsServlet { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response updateComponentInstanceReference( - @Context final HttpServletRequest request, @PathParam("assetType") String assetType, @PathParam("uuid") String uuid, @PathParam("componentInstanceName") String componentInstanceName, @PathParam("objectType") String objectType, @PathParam("oldRefValue") String oldRefValue, - ExternalRefDTO newRefValueDTO, @HeaderParam("USER_ID") String userId) { + ExternalRefDTO newRefValueDTO, @HeaderParam("USER_ID") String userId, @HeaderParam("X-ECOMP-InstanceID") String xEcompInstanceId) { log.debug("PUT component instance external interfaces {} {} {} {}", assetType, uuid, componentInstanceName, objectType); - Response r = authorizeAndValidateRequest(request, userId); + Response r = validateRequest(xEcompInstanceId); if (r != null){ return r; } String newRefValue = newRefValueDTO.getReferenceUUID(); - Either<String, ActionStatus> updateResult = this.businessLogic.updateExternalReference(uuid, componentInstanceName, objectType, oldRefValue, newRefValue); + Either<String, ActionStatus> updateResult = this.businessLogic.updateExternalReference(ComponentTypeEnum.findByParamName(assetType), userId, uuid, componentInstanceName, objectType, oldRefValue, newRefValue); if (updateResult.isLeft()){ return this.buildOkResponse(new ExternalRefDTO(newRefValue)); } else { @@ -182,23 +161,14 @@ public class ExternalRefsServlet extends AbstractValidationsServlet { } - private Response authorizeAndValidateRequest(final HttpServletRequest request, String userId) { - init(log); - + private Response validateRequest(String xEcompInstanceIdHeader) { Wrapper<Response> responseWrapper = new Wrapper<>(); - Wrapper<User> userWrapper = new Wrapper<>(); //Validate X-ECOMP_INSTANCE_ID_HEADER - if (request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER) == null || request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER).isEmpty()){ + if (xEcompInstanceIdHeader == null || xEcompInstanceIdHeader.isEmpty()){ return this.buildExtRefErrorResponse(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID, "", "", "", "", ""); } - String method = request.getMethod(); - if (responseWrapper.isEmpty() && !"GET".equals(method)) { - validateUserExist(responseWrapper, userWrapper, userId); - validateUserRole(responseWrapper, userWrapper.getInnerElement()); - } - return responseWrapper.getInnerElement(); } |