diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java | 464 |
1 files changed, 178 insertions, 286 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java index f0ef7074ea..1affe7592c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.servlets; import com.fasterxml.jackson.core.JsonProcessingException; @@ -37,6 +36,26 @@ import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tags; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import javax.inject.Inject; +import javax.servlet.ServletContext; +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.http.HttpStatus; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; @@ -77,27 +96,6 @@ import org.openecomp.sdc.common.zip.exception.ZipException; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.stereotype.Controller; -import javax.inject.Inject; -import javax.servlet.ServletContext; -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 java.io.IOException; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - @Loggable(prepend = true, value = Loggable.DEBUG, trim = false) @Path("/v1/catalog") @Tags({@Tag(name = "SDC Internal APIs")}) @@ -105,22 +103,17 @@ import java.util.Map; @Controller public class ServiceServlet extends AbstractValidationsServlet { - private final ElementBusinessLogic elementBusinessLogic; private static final Logger log = Logger.getLogger(ServiceServlet.class); private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ServiceServlet.class.getName()); - private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}"; private static final String MODIFIER_ID_IS = "modifier id is {}"; - + private final ElementBusinessLogic elementBusinessLogic; private final ServiceBusinessLogic serviceBusinessLogic; @Inject - public ServiceServlet(UserBusinessLogic userBusinessLogic, - ComponentInstanceBusinessLogic componentInstanceBL, - ComponentsUtils componentsUtils, ServletUtils servletUtils, - ResourceImportManager resourceImportManager, - ServiceBusinessLogic serviceBusinessLogic, - ResourceBusinessLogic resourceBusinessLogic, ElementBusinessLogic elementBusinessLogic) { + public ServiceServlet(UserBusinessLogic userBusinessLogic, ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils, + ServletUtils servletUtils, ResourceImportManager resourceImportManager, ServiceBusinessLogic serviceBusinessLogic, + ResourceBusinessLogic resourceBusinessLogic, ElementBusinessLogic elementBusinessLogic) { super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager); this.serviceBusinessLogic = serviceBusinessLogic; this.elementBusinessLogic = elementBusinessLogic; @@ -131,68 +124,58 @@ public class ServiceServlet extends AbstractValidationsServlet { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Create Service", method = "POST", summary = "Returns created service", responses = { - @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), - @ApiResponse(responseCode = "201", description = "Service created"), - @ApiResponse(responseCode = "403", description = "Restricted operation"), - @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), - @ApiResponse(responseCode = "409", description = "Service already exist")}) + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), + @ApiResponse(responseCode = "201", description = "Service created"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), + @ApiResponse(responseCode = "409", description = "Service already exist")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response createService(@Parameter(description = "Service object to be created", required = true) String data, - @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - + @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); User modifier = new User(); modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - loggerSupportability.log(LoggerSupportabilityActions.CREATE_SERVICE,StatusCode.STARTED,"Starting to create a service by user {} ",userId); - + loggerSupportability.log(LoggerSupportabilityActions.CREATE_SERVICE, StatusCode.STARTED, "Starting to create a service by user {} ", userId); validateNotEmptyBody(data); Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier); if (convertResponse.isRight()) { throw new ByResponseFormatComponentException(convertResponse.right().value()); } - Service service = convertResponse.left().value(); Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.createService(service, modifier); - if (actionResponse.isRight()) { log.debug("Failed to create service"); throw new ByResponseFormatComponentException(actionResponse.right().value()); } - - loggerSupportability.log(LoggerSupportabilityActions.CREATE_SERVICE,service.getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"Service {} has been created by user {} ",service.getName(), userId ); - + loggerSupportability.log(LoggerSupportabilityActions.CREATE_SERVICE, service.getComponentMetadataForSupportLog(), StatusCode.COMPLETE, + "Service {} has been created by user {} ", service.getName(), userId); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value()); } public Either<Service, ResponseFormat> parseToService(String serviceJson, User user) { - return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, Service.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE); + return getComponentsUtils() + .convertJsonToObjectUsingObjectMapper(serviceJson, user, Service.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE); } @GET @Path("/services/validate-name/{serviceName}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "validate service name", method = "GET", - summary = "checks if the chosen service name is available ", responses = { - @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))), - @ApiResponse(responseCode = "200", description = "Service found"), - @ApiResponse(responseCode = "403", description = "Restricted operation")}) + @Operation(description = "validate service name", method = "GET", summary = "checks if the chosen service name is available ", responses = { + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))), + @ApiResponse(responseCode = "200", description = "Service found"), @ApiResponse(responseCode = "403", description = "Restricted operation")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) - public Response validateServiceName(@PathParam("serviceName") final String serviceName, - @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + public Response validateServiceName(@PathParam("serviceName") final String serviceName, @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { 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 { - Either<Map<String, Boolean>, ResponseFormat> actionResponse = - serviceBusinessLogic.validateServiceNameExists(serviceName, userId); - + Either<Map<String, Boolean>, ResponseFormat> actionResponse = serviceBusinessLogic.validateServiceNameExists(serviceName, userId); if (actionResponse.isRight()) { log.debug("failed to get validate service name"); return buildErrorResponse(actionResponse.right().value()); @@ -209,20 +192,18 @@ public class ServiceServlet extends AbstractValidationsServlet { @Path("/audit-records/{componentType}/{componentUniqueId}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "get component audit records", method = "GET", - summary = "get audit records for a service or a resource", responses = { - @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))), - @ApiResponse(responseCode = "200", description = "Service found"), - @ApiResponse(responseCode = "403", description = "Restricted operation")}) + @Operation(description = "get component audit records", method = "GET", summary = "get audit records for a service or a resource", responses = { + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))), + @ApiResponse(responseCode = "200", description = "Service found"), @ApiResponse(responseCode = "403", description = "Restricted operation")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response getComponentAuditRecords(@PathParam("componentType") final String componentType, - @PathParam("componentUniqueId") final String componentUniqueId, @Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + @PathParam("componentUniqueId") final String componentUniqueId, + @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { init(); ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); - User modifier = new User(); modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); @@ -232,14 +213,13 @@ public class ServiceServlet extends AbstractValidationsServlet { Wrapper<User> userWrapper = new Wrapper<>(); try { validateUserExist(responseWrapper, userWrapper, userId); - if (responseWrapper.isEmpty()) { - fillUUIDAndVersion(responseWrapper, uuidWrapper, versionWrapper, userWrapper.getInnerElement(), validateComponentType(componentType), componentUniqueId, context); + fillUUIDAndVersion(responseWrapper, uuidWrapper, versionWrapper, userWrapper.getInnerElement(), validateComponentType(componentType), + componentUniqueId, context); } - if (responseWrapper.isEmpty()) { - Either<List<Map<String, Object>>, ResponseFormat> eitherServiceAudit = serviceBusinessLogic.getComponentAuditRecords(versionWrapper.getInnerElement(), uuidWrapper.getInnerElement(), userId); - + Either<List<Map<String, Object>>, ResponseFormat> eitherServiceAudit = serviceBusinessLogic + .getComponentAuditRecords(versionWrapper.getInnerElement(), uuidWrapper.getInnerElement(), userId); if (eitherServiceAudit.isRight()) { Response errorResponse = buildErrorResponse(eitherServiceAudit.right().value()); responseWrapper.setInnerElement(errorResponse); @@ -247,10 +227,8 @@ public class ServiceServlet extends AbstractValidationsServlet { List<Map<String, Object>> auditRecords = eitherServiceAudit.left().value(); Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), auditRecords); responseWrapper.setInnerElement(okResponse); - } } - } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Service Name"); log.debug("get Service Audit Records failed with exception", e); @@ -259,8 +237,8 @@ public class ServiceServlet extends AbstractValidationsServlet { return responseWrapper.getInnerElement(); } - private void fillUUIDAndVersion(Wrapper<Response> responseWrapper, Wrapper<String> uuidWrapper, Wrapper<String> versionWrapper, User user, final ComponentTypeEnum componentTypeEnum, final String componentUniqueId, ServletContext context) { - + private void fillUUIDAndVersion(Wrapper<Response> responseWrapper, Wrapper<String> uuidWrapper, Wrapper<String> versionWrapper, User user, + final ComponentTypeEnum componentTypeEnum, final String componentUniqueId, ServletContext context) { if (componentTypeEnum == ComponentTypeEnum.RESOURCE) { Either<Resource, ResponseFormat> eitherResource = getResourceBL(context).getResource(componentUniqueId, user); if (eitherResource.isLeft()) { @@ -269,7 +247,6 @@ public class ServiceServlet extends AbstractValidationsServlet { } else { responseWrapper.setInnerElement(buildErrorResponse(eitherResource.right().value())); } - } else { Either<Service, ResponseFormat> eitherService = getServiceBL(context).getService(componentUniqueId, user); if (eitherService.isLeft()) { @@ -277,7 +254,6 @@ public class ServiceServlet extends AbstractValidationsServlet { versionWrapper.setInnerElement(eitherService.left().value().getVersion()); } else { responseWrapper.setInnerElement(buildErrorResponse(eitherService.right().value())); - } } } @@ -285,17 +261,15 @@ public class ServiceServlet extends AbstractValidationsServlet { @DELETE @Path("/services/{serviceId}") @Operation(description = "Delete Service", method = "DELETE", summary = "Return no content", responses = { - @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), - @ApiResponse(responseCode = "204", description = "Service deleted"), - @ApiResponse(responseCode = "403", description = "Restricted operation"), - @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), - @ApiResponse(responseCode = "404", description = "Service not found")}) + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), + @ApiResponse(responseCode = "204", description = "Service deleted"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), + @ApiResponse(responseCode = "404", description = "Service not found")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response deleteService(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request) { ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); - // get modifier id String userId = request.getHeader(Constants.USER_ID_HEADER); User modifier = new User(); @@ -303,16 +277,18 @@ public class ServiceServlet extends AbstractValidationsServlet { log.debug(MODIFIER_ID_IS, userId); try { String serviceIdLower = serviceId.toLowerCase(); - loggerSupportability.log(LoggerSupportabilityActions.DELETE_SERVICE, StatusCode.STARTED,"Starting to delete service {} by user {} ",serviceIdLower, userId); + loggerSupportability + .log(LoggerSupportabilityActions.DELETE_SERVICE, StatusCode.STARTED, "Starting to delete service {} by user {} ", serviceIdLower, + userId); ServiceBusinessLogic businessLogic = getServiceBL(context); ResponseFormat actionResponse = businessLogic.deleteService(serviceIdLower, modifier); if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) { log.debug("failed to delete service"); return buildErrorResponse(actionResponse); } - loggerSupportability.log(LoggerSupportabilityActions.DELETE_SERVICE,StatusCode.COMPLETE,"Ended deleting service {} by user {}",serviceIdLower, userId); + loggerSupportability + .log(LoggerSupportabilityActions.DELETE_SERVICE, StatusCode.COMPLETE, "Ended deleting service {} by user {}", serviceIdLower, userId); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null); - } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service"); log.debug("delete service failed with exception", e); @@ -322,22 +298,17 @@ public class ServiceServlet extends AbstractValidationsServlet { @DELETE @Path("/services/{serviceName}/{version}") - @Operation(description = "Delete Service By Name And Version", method = "DELETE", summary = "Returns no content", - responses = {@ApiResponse( - content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))), - @ApiResponse(responseCode = "204", description = "Service deleted"), - @ApiResponse(responseCode = "403", description = "Restricted operation"), - @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), - @ApiResponse(responseCode = "404", description = "Service not found")}) + @Operation(description = "Delete Service By Name And Version", method = "DELETE", summary = "Returns no content", responses = { + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))), + @ApiResponse(responseCode = "204", description = "Service deleted"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), + @ApiResponse(responseCode = "404", description = "Service not found")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) - public Response deleteServiceByNameAndVersion(@PathParam("serviceName") final String serviceName, - @PathParam("version") final String version, + public Response deleteServiceByNameAndVersion(@PathParam("serviceName") final String serviceName, @PathParam("version") final String version, @Context final HttpServletRequest request) { User modifier = getUser(request); - try { ResponseFormat actionResponse = serviceBusinessLogic.deleteServiceByNameAndVersion(serviceName, version, modifier); - if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) { log.debug("failed to delete service"); return buildErrorResponse(actionResponse); @@ -353,7 +324,6 @@ public class ServiceServlet extends AbstractValidationsServlet { private User getUser(HttpServletRequest request) { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); - // get modifier id String userId = request.getHeader(Constants.USER_ID_HEADER); User modifier = new User(); @@ -366,27 +336,22 @@ public class ServiceServlet extends AbstractValidationsServlet { @Path("/services/{serviceId}/metadata") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Update Service Metadata", method = "PUT", summary = "Returns updated service", - responses = {@ApiResponse( - content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), - @ApiResponse(responseCode = "200", description = "Service Updated"), - @ApiResponse(responseCode = "403", description = "Restricted operation"), - @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")}) + @Operation(description = "Update Service Metadata", method = "PUT", summary = "Returns updated service", responses = { + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), + @ApiResponse(responseCode = "200", description = "Service Updated"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response updateServiceMetadata(@PathParam("serviceId") final String serviceId, - @Parameter(description = "Service object to be Updated", required = true) String data, - @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException { - + @Parameter(description = "Service object to be Updated", required = true) String data, + @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); - User modifier = new User(); modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - try { String serviceIdLower = serviceId.toLowerCase(); - Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier); if (convertResponse.isRight()) { log.debug("failed to parse service"); @@ -394,25 +359,24 @@ public class ServiceServlet extends AbstractValidationsServlet { } Service updatedService = convertResponse.left().value(); Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.updateServiceMetadata(serviceIdLower, updatedService, modifier); - if (actionResponse.isRight()) { log.debug("failed to update service"); return buildErrorResponse(actionResponse.right().value()); } - Service service = actionResponse.left().value(); Object result = RepresentationUtils.toRepresentation(service); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Service Metadata"); log.debug("update service metadata failed with exception", e); throw e; } } + /** - * updates group instance property values - * Note, than in case of group instance updated successfully, related resourceInstance and containing component modification time will be updated + * updates group instance property values Note, than in case of group instance updated successfully, related resourceInstance and containing + * component modification time will be updated + * * @param serviceId * @param componentInstanceId * @param groupInstanceId @@ -425,48 +389,46 @@ public class ServiceServlet extends AbstractValidationsServlet { @Path("/{containerComponentType}/{serviceId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Update Group Instance Property Values", method = "PUT", - summary = "Returns updated group instance", responses = { - @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), - @ApiResponse(responseCode = "200", description = "Group Instance Property Values Updated"), - @ApiResponse(responseCode = "403", description = "Restricted operation"), - @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")}) + @Operation(description = "Update Group Instance Property Values", method = "PUT", summary = "Returns updated group instance", responses = { + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), + @ApiResponse(responseCode = "200", description = "Group Instance Property Values Updated"), + @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response updateGroupInstancePropertyValues(@PathParam("serviceId") final String serviceId, - @PathParam("componentInstanceId") final String componentInstanceId, - @PathParam("groupInstanceId") final String groupInstanceId, - @Parameter(description = "Group instance object to be Updated", required = true) String data, - @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws JsonProcessingException { - + @PathParam("componentInstanceId") final String componentInstanceId, + @PathParam("groupInstanceId") final String groupInstanceId, + @Parameter(description = "Group instance object to be Updated", required = true) String data, + @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws JsonProcessingException { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); - User modifier = new User(); modifier.setUserId(userId); - log.debug(MODIFIER_ID_IS,userId); - + log.debug(MODIFIER_ID_IS, userId); Either<List<GroupInstanceProperty>, ResponseFormat> actionResponse = null; try { List<GroupInstanceProperty> updatedProperties; - Type listType = new TypeToken<ArrayList<GroupInstanceProperty>>(){}.getType(); + Type listType = new TypeToken<ArrayList<GroupInstanceProperty>>() { + }.getType(); ArrayList<GroupInstanceProperty> newProperties = gson.fromJson(data, listType); if (newProperties == null) { actionResponse = Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)); } - if(actionResponse == null){ + if (actionResponse == null) { log.debug("Start handle update group instance property values request. Received group instance is {}", groupInstanceId); - actionResponse = serviceBusinessLogic.updateGroupInstancePropertyValues(modifier, serviceId, componentInstanceId, groupInstanceId, newProperties); - if(actionResponse.isRight()){ + actionResponse = serviceBusinessLogic + .updateGroupInstancePropertyValues(modifier, serviceId, componentInstanceId, groupInstanceId, newProperties); + if (actionResponse.isRight()) { actionResponse = Either.right(actionResponse.right().value()); } } - if(actionResponse.isLeft()){ + if (actionResponse.isLeft()) { updatedProperties = actionResponse.left().value(); ObjectMapper mapper = new ObjectMapper(); String result = mapper.writeValueAsString(updatedProperties); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - } - else{ + } else { return buildErrorResponse(actionResponse.right().value()); } } catch (Exception e) { @@ -479,39 +441,30 @@ public class ServiceServlet extends AbstractValidationsServlet { @Path("/services/{serviceId}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Retrieve Service", method = "GET", summary = "Returns service according to serviceId", - responses = {@ApiResponse( - content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), - @ApiResponse(responseCode = "200", description = "Service found"), - @ApiResponse(responseCode = "403", description = "Restricted operation"), - @ApiResponse(responseCode = "404", description = "Service not found")}) + @Operation(description = "Retrieve Service", method = "GET", summary = "Returns service according to serviceId", responses = { + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), + @ApiResponse(responseCode = "200", description = "Service found"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "404", description = "Service not found")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) - public Response getServiceById(@PathParam("serviceId") final String serviceId, - @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException { - + public Response getServiceById(@PathParam("serviceId") final String serviceId, @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 serviceIdLower = serviceId.toLowerCase(); log.debug("get service with id {}", serviceId); Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getService(serviceIdLower, modifier); - if (actionResponse.isRight()) { log.debug("failed to get service"); return buildErrorResponse(actionResponse.right().value()); } - Service service = actionResponse.left().value(); Object result = RepresentationUtils.toRepresentation(service); - return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service"); log.debug("get service failed with exception", e); @@ -523,34 +476,26 @@ public class ServiceServlet extends AbstractValidationsServlet { @Path("/services/serviceName/{serviceName}/serviceVersion/{serviceVersion}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Retrieve Service", method = "GET", - summary = "Returns service according to name and version", responses = { - @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), - @ApiResponse(responseCode = "200", description = "Service found"), - @ApiResponse(responseCode = "403", description = "Restricted operation"), - @ApiResponse(responseCode = "404", description = "Service not found")}) + @Operation(description = "Retrieve Service", method = "GET", summary = "Returns service according to name and version", responses = { + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))), + @ApiResponse(responseCode = "200", description = "Service found"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "404", description = "Service not found")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response getServiceByNameAndVersion(@PathParam("serviceName") final String serviceName, - @PathParam("serviceVersion") final String serviceVersion, @Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException { - + @PathParam("serviceVersion") final String serviceVersion, @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException { // get modifier id User modifier = new User(); modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - try { Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceByNameAndVersion(serviceName, serviceVersion, userId); - if (actionResponse.isRight()) { return buildErrorResponse(actionResponse.right().value()); } - Service service = actionResponse.left().value(); Object result = RepresentationUtils.toRepresentation(service); - return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service by name and version"); log.debug("get service failed with exception", e); @@ -562,25 +507,21 @@ public class ServiceServlet extends AbstractValidationsServlet { @Path("/services/{serviceId}/distribution/{env}/activate") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Activate distribution", method = "POST", summary = "activate distribution", - responses = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "409", - description = "Service cannot be distributed due to missing deployment artifacts"), - @ApiResponse(responseCode = "404", description = "Requested service was not found"), - @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")}) + @Operation(description = "Activate distribution", method = "POST", summary = "activate distribution", responses = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "409", description = "Service cannot be distributed due to missing deployment artifacts"), + @ApiResponse(responseCode = "404", description = "Requested service was not found"), + @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) - public Response activateDistribution(@PathParam("serviceId") final String serviceId, - @PathParam("env") final String env, @Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException { - + public Response activateDistribution(@PathParam("serviceId") final String serviceId, @PathParam("env") final String env, + @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); - User modifier = new User(); modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.activateDistribution(serviceId, env, modifier, request); - if (distResponse.isRight()) { log.debug("failed to activate service distribution"); return buildErrorResponse(distResponse.right().value()); @@ -601,29 +542,24 @@ public class ServiceServlet extends AbstractValidationsServlet { @Path("/services/{serviceId}/distribution/{did}/markDeployed") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Mark distribution as deployed", method = "POST", - summary = "relevant audit record will be created", - responses = {@ApiResponse(responseCode = "200", description = "Service was marked as deployed"), - @ApiResponse(responseCode = "409", description = "Restricted operation"), - @ApiResponse(responseCode = "403", description = "Service is not available"), - @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), - @ApiResponse(responseCode = "404", description = "Requested service was not found"), - @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")}) + @Operation(description = "Mark distribution as deployed", method = "POST", summary = "relevant audit record will be created", responses = { + @ApiResponse(responseCode = "200", description = "Service was marked as deployed"), + @ApiResponse(responseCode = "409", description = "Restricted operation"), + @ApiResponse(responseCode = "403", description = "Service is not available"), + @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), + @ApiResponse(responseCode = "404", description = "Requested service was not found"), + @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) - public Response markDistributionAsDeployed(@PathParam("serviceId") final String serviceId, - @PathParam("did") final String did, @Context final HttpServletRequest request, - @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException { - + public Response markDistributionAsDeployed(@PathParam("serviceId") final String serviceId, @PathParam("did") final String did, + @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); - User modifier = new User(); modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - try { Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.markDistributionAsDeployed(serviceId, did, modifier); - if (distResponse.isRight()) { log.debug("failed to mark distribution as deployed"); return buildErrorResponse(distResponse.right().value()); @@ -643,22 +579,20 @@ public class ServiceServlet extends AbstractValidationsServlet { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Operation(responses = {@ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")}) + @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) - public Response tempUrlToBeDeleted(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - + public Response tempUrlToBeDeleted(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); - User modifier = new User(); modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - try { Service service = (serviceBusinessLogic.getService(serviceId, modifier)).left().value(); - Either<Service, ResponseFormat> res = serviceBusinessLogic.updateDistributionStatusForActivation(service, modifier, DistributionStatusEnum.DISTRIBUTED); - + Either<Service, ResponseFormat> res = serviceBusinessLogic + .updateDistributionStatusForActivation(service, modifier, DistributionStatusEnum.DISTRIBUTED); if (res.isRight()) { buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } @@ -670,45 +604,34 @@ public class ServiceServlet extends AbstractValidationsServlet { } } - @GET @Path("/services/{serviceId}/linksMap") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Operation(description = "Retrieve Service component relations map", method = "GET", - summary = "Returns service components relations", responses = {@ApiResponse( - content = @Content(array = @ArraySchema(schema = @Schema(implementation = ServiceRelations.class)))), - @ApiResponse(responseCode = "200", description = "Service found"), - @ApiResponse(responseCode = "403", description = "Restricted operation"), - @ApiResponse(responseCode = "404", description = "Service not found")}) + @Operation(description = "Retrieve Service component relations map", method = "GET", summary = "Returns service components relations", responses = { + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = ServiceRelations.class)))), + @ApiResponse(responseCode = "200", description = "Service found"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "404", description = "Service not found")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) - public Response getServiceComponentRelationMap(@PathParam("serviceId") final String serviceId, - @Context final HttpServletRequest request, + public Response getServiceComponentRelationMap(@PathParam("serviceId") final String serviceId, @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 serviceIdLower = serviceId.toLowerCase(); log.debug("get service components relations with id {}", serviceId); Either<ServiceRelations, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceComponentsRelations(serviceIdLower, modifier); - if (actionResponse.isRight()) { log.debug("failed to get service relations data"); return buildErrorResponse(actionResponse.right().value()); } - ServiceRelations serviceRelations = actionResponse.left().value(); Object result = RepresentationUtils.toRepresentation(serviceRelations); - return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); - } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service"); log.debug("get service relations data failed with exception", e); @@ -721,23 +644,21 @@ public class ServiceServlet extends AbstractValidationsServlet { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Import Service", method = "POST", summary = "Returns imported service", responses = { - @ApiResponse(responseCode = "201", description = "Service created"), @ApiResponse(responseCode = "403", description = "Restricted operation"), @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), @ApiResponse(responseCode = "409", description = "Service already exist")}) - public Response importNsService(@Parameter(description = "Service object to be imported", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - + @ApiResponse(responseCode = "201", description = "Service created"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), + @ApiResponse(responseCode = "409", description = "Service already exist")}) + public Response importNsService(@Parameter(description = "Service object to be imported", required = true) String data, + @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER); initSpringFromContext(); - String url = request.getMethod() + " " + request.getRequestURI(); - log.debug("Start handle request of {}" , url); - + log.debug("Start handle request of {}", url); // get modifier id User modifier = new User(); modifier.setUserId(userId); log.debug("modifier id is {}", userId); - Response response; try { - Wrapper<Response> responseWrapper = new Wrapper<>(); performUIImport(responseWrapper, data, request, userId, null); return responseWrapper.getInnerElement(); @@ -749,25 +670,23 @@ public class ServiceServlet extends AbstractValidationsServlet { } } - private void performUIImport(Wrapper<Response> responseWrapper, String data, final HttpServletRequest request, String userId, String ServiceUniqueId) - throws FileNotFoundException, ZipException { - + private void performUIImport(Wrapper<Response> responseWrapper, String data, final HttpServletRequest request, String userId, + String ServiceUniqueId) throws FileNotFoundException, ZipException { Wrapper<User> userWrapper = new Wrapper<>(); Wrapper<UploadServiceInfo> uploadServiceInfoWrapper = new Wrapper<>(); Wrapper<String> yamlStringWrapper = new Wrapper<>(); - ServiceAuthorityTypeEnum ServiceAuthorityEnum = ServiceAuthorityTypeEnum.USER_TYPE_UI; - commonServiceGeneralValidations(responseWrapper, userWrapper, uploadServiceInfoWrapper, ServiceAuthorityEnum, userId, data); - - specificServiceAuthorityValidations(responseWrapper, uploadServiceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), request, data, ServiceAuthorityEnum); - + specificServiceAuthorityValidations(responseWrapper, uploadServiceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), request, + data, ServiceAuthorityEnum); if (responseWrapper.isEmpty()) { - handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), yamlStringWrapper.getInnerElement(), ServiceAuthorityEnum, true, ServiceUniqueId); + handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), + yamlStringWrapper.getInnerElement(), ServiceAuthorityEnum, true, ServiceUniqueId); } } - /**import ReplaceService + /** + * import ReplaceService * * @param userId * @param requestId @@ -785,61 +704,41 @@ public class ServiceServlet extends AbstractValidationsServlet { @Path("/services/serviceUUID/{uuid}/importReplaceService") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Import Service", method = "POST", summary = "Returns imported service", responses = { - @ApiResponse(responseCode = "201", description = "Service created"), - @ApiResponse(responseCode = "403", description = "Restricted operation"), - @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), - @ApiResponse(responseCode = "409", description = "Service already exist")}) + @ApiResponse(responseCode = "201", description = "Service created"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), + @ApiResponse(responseCode = "409", description = "Service already exist")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response importReplaceService( - @Parameter(description = "The user id", - required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId, - @Parameter(description = "X-ECOMP-RequestID header", - required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, - @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam( - value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader, - @Parameter(description = "Determines the format of the body of the response", - required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept, - @Parameter(description = "The username and password", - required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, - @Context final HttpServletRequest request, - @Parameter(description = "FileInputStream") - @FormDataParam("serviceZip") File file, - @Parameter(description = "ContentDisposition") - @FormDataParam("serviceZip") FormDataContentDisposition contentDispositionHeader, - @Parameter(description = "serviceMetadata") - @FormDataParam("serviceZipMetadata") String serviceInfoJsonString, - @Parameter(description = "The requested asset uuid", - required = true) @PathParam("uuid") final String uuid) { - + @Parameter(description = "The user id", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId, + @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId, + @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader, + @Parameter(description = "Determines the format of the body of the response", required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept, + @Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization, + @Context final HttpServletRequest request, @Parameter(description = "FileInputStream") @FormDataParam("serviceZip") File file, + @Parameter(description = "ContentDisposition") @FormDataParam("serviceZip") FormDataContentDisposition contentDispositionHeader, + @Parameter(description = "serviceMetadata") @FormDataParam("serviceZipMetadata") String serviceInfoJsonString, + @Parameter(description = "The requested asset uuid", required = true) @PathParam("uuid") final String uuid) { initSpringFromContext(); - String requestURI = request.getRequestURI(); String url = request.getMethod() + " " + requestURI; log.debug("importReplaceService,Start handle request of {}", url); - // get modifier id User modifier = new User(); modifier.setUserId(userId); log.debug("importReplaceService,modifier id is {}", userId); - - log.debug("importReplaceService,get file:{},fileName:{}",file,file.getName()); - + log.debug("importReplaceService,get file:{},fileName:{}", file, file.getName()); Response response; - ResponseFormat responseFormat =null; + ResponseFormat responseFormat = null; AuditingActionEnum auditingActionEnum = AuditingActionEnum.Import_Replace_Service; String assetType = "services"; - - Either<List<? extends Component>, ResponseFormat> assetTypeData = elementBusinessLogic.getCatalogComponentsByUuidAndAssetType(assetType, uuid); - + Either<List<? extends Component>, ResponseFormat> assetTypeData = elementBusinessLogic + .getCatalogComponentsByUuidAndAssetType(assetType, uuid); if (assetTypeData.isRight() || assetTypeData.left().value().size() != 1) { log.debug("getServiceAbstractStatus: Service Fetching Failed"); throw new ByResponseFormatComponentException(assetTypeData.right().value()); } - log.debug("getServiceAbstractStatus: Service Fetching Success"); - Service oldService = (Service) assetTypeData.left().value().get(0); - ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue()); DistributionData distributionData = new DistributionData(instanceIdHeader, requestURI); @@ -847,43 +746,36 @@ public class ServiceServlet extends AbstractValidationsServlet { if (instanceIdHeader == null || instanceIdHeader.isEmpty()) { log.debug("importReplaceService: Missing X-ECOMP-InstanceID header"); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID); - getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, - resourceCommonInfo, requestId, null); + getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, null); return buildErrorResponse(responseFormat); } - try { Wrapper<Response> responseWrapper = new Wrapper<>(); // file import Wrapper<User> userWrapper = new Wrapper<>(); Wrapper<UploadServiceInfo> uploadServiceInfoWrapper = new Wrapper<>(); Wrapper<String> yamlStringWrapper = new Wrapper<>(); - ServiceUploadServlet.ServiceAuthorityTypeEnum serviceAuthorityEnum = ServiceUploadServlet.ServiceAuthorityTypeEnum.CSAR_TYPE_BE; - // PayLoad Validations - commonServiceGeneralValidations(responseWrapper, userWrapper, uploadServiceInfoWrapper, serviceAuthorityEnum, userId, serviceInfoJsonString); - - fillServicePayload(responseWrapper, uploadServiceInfoWrapper, yamlStringWrapper, modifier, serviceInfoJsonString, serviceAuthorityEnum, file); - - specificServiceAuthorityValidations(responseWrapper, uploadServiceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), request, serviceInfoJsonString, serviceAuthorityEnum); - + commonServiceGeneralValidations(responseWrapper, userWrapper, uploadServiceInfoWrapper, serviceAuthorityEnum, userId, + serviceInfoJsonString); + fillServicePayload(responseWrapper, uploadServiceInfoWrapper, yamlStringWrapper, modifier, serviceInfoJsonString, serviceAuthorityEnum, + file); + specificServiceAuthorityValidations(responseWrapper, uploadServiceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), request, + serviceInfoJsonString, serviceAuthorityEnum); log.debug("importReplaceService:get payload:{}", uploadServiceInfoWrapper.getInnerElement().getPayloadData()); - - ServiceMetadataDataDefinition serviceMetadataDataDefinition = (ServiceMetadataDataDefinition)oldService.getComponentMetadataDefinition().getMetadataDataDefinition(); - + ServiceMetadataDataDefinition serviceMetadataDataDefinition = (ServiceMetadataDataDefinition) oldService.getComponentMetadataDefinition() + .getMetadataDataDefinition(); uploadServiceInfoWrapper.getInnerElement().setServiceVendorModelNumber(serviceMetadataDataDefinition.getServiceVendorModelNumber()); uploadServiceInfoWrapper.getInnerElement().setDescription(oldService.getDescription()); uploadServiceInfoWrapper.getInnerElement().setCategories(oldService.getCategories()); uploadServiceInfoWrapper.getInnerElement().setIcon(oldService.getIcon()); uploadServiceInfoWrapper.getInnerElement().setProjectCode(oldService.getProjectCode()); - - if (responseWrapper.isEmpty()) { log.debug("importReplaceService:start handleImportService"); - handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), yamlStringWrapper.getInnerElement(), serviceAuthorityEnum, true, null); + handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(), + yamlStringWrapper.getInnerElement(), serviceAuthorityEnum, true, null); } - return responseWrapper.getInnerElement(); } catch (IOException | ZipException e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Import Service"); |