Search in sources :

Example 1 with PackageTypeDescriptor

use of org.commonjava.indy.model.core.PackageTypeDescriptor in project indy by Commonjava.

the class PromoteResource method promoteToGroup.

@ApiOperation("Promote a source repository into the membership of a target group (subject to validation).")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = GroupPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON request specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.GroupPromoteRequest")
@Path("/groups/promote")
@POST
@Consumes(ApplicationContent.application_json)
public GroupPromoteResult promoteToGroup(final GroupPromoteRequest request, @Context final HttpServletRequest servletRequest, @Context final SecurityContext securityContext, @Context final UriInfo uriInfo) {
    Response response = null;
    try {
        PackageTypeDescriptor packageTypeDescriptor = PackageTypes.getPackageTypeDescriptor(request.getSource().getPackageType());
        String user = securityManager.getUser(securityContext, servletRequest);
        final String baseUrl = uriInfo.getBaseUriBuilder().path(packageTypeDescriptor.getContentRestBasePath()).build(request.getSource().getType().singularEndpointName(), request.getSource().getName()).toString();
        return manager.promoteToGroup(request, user, baseUrl);
    } catch (PromotionException e) {
        logger.error(e.getMessage(), e);
        throwError(e);
    }
    return null;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) PackageTypeDescriptor(org.commonjava.indy.model.core.PackageTypeDescriptor) PromotionException(org.commonjava.indy.promote.data.PromotionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) ApiResponse(io.swagger.annotations.ApiResponse)

Example 2 with PackageTypeDescriptor

use of org.commonjava.indy.model.core.PackageTypeDescriptor in project indy by Commonjava.

the class PromoteResource method promotePaths.

@ApiOperation("Promote paths from a source repository into a target repository/group (subject to validation).")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON request specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteRequest")
@Path("/paths/promote")
@POST
@Consumes(ApplicationContent.application_json)
public Response promotePaths(@Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
    PathsPromoteRequest req = null;
    Response response = null;
    try {
        final String json = IOUtils.toString(request.getInputStream());
        logger.info("Got promotion request:\n{}", json);
        req = mapper.readValue(json, PathsPromoteRequest.class);
    } catch (final IOException e) {
        response = formatResponse(e, "Failed to read DTO from request body.");
    }
    if (response != null) {
        return response;
    }
    try {
        PackageTypeDescriptor packageTypeDescriptor = PackageTypes.getPackageTypeDescriptor(req.getSource().getPackageType());
        final String baseUrl = uriInfo.getBaseUriBuilder().path(packageTypeDescriptor.getContentRestBasePath()).build(req.getSource().getType().singularEndpointName(), req.getSource().getName()).toString();
        final PathsPromoteResult result = manager.promotePaths(req, baseUrl);
        // TODO: Amend response status code based on presence of error? This would have consequences for client API...
        response = formatOkResponseWithJsonEntity(result, mapper);
    } catch (PromotionException | IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) PackageTypeDescriptor(org.commonjava.indy.model.core.PackageTypeDescriptor) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) IOException(java.io.IOException) PromotionException(org.commonjava.indy.promote.data.PromotionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) ApiResponse(io.swagger.annotations.ApiResponse)

Aggregations

ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponse (io.swagger.annotations.ApiResponse)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Response (javax.ws.rs.core.Response)2 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)2 PackageTypeDescriptor (org.commonjava.indy.model.core.PackageTypeDescriptor)2 PromotionException (org.commonjava.indy.promote.data.PromotionException)2 IOException (java.io.IOException)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)1 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)1