Search in sources :

Example 1 with METADATA_CHANGELOG

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

the class DeprecatedStoreAdminHandler method delete.

@ApiOperation("Delete an artifact store")
@ApiResponses({ @ApiResponse(code = 204, response = ArtifactStore.class, message = "The store was deleted (or didn't exist in the first place)") })
@Path("/{name}")
@DELETE
public Response delete(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
    String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type, name).toString();
    Consumer<Response.ResponseBuilder> modifier = (rb) -> markDeprecated(rb, altPath);
    final StoreType st = StoreType.get(type);
    final StoreKey key = new StoreKey(st, name);
    logger.info("Deleting: {}", key);
    Response response;
    try {
        String summary = null;
        try {
            summary = IOUtils.toString(request.getInputStream());
        } catch (final IOException e) {
            // no problem, try to get the summary from a header instead.
            logger.info("store-deletion change summary not in request body, checking headers.");
        }
        if (isEmpty(summary)) {
            summary = request.getHeader(METADATA_CHANGELOG);
        }
        if (isEmpty(summary)) {
            summary = "Changelog not provided";
        }
        String user = securityManager.getUser(securityContext, request);
        adminController.delete(key, user, summary);
        response = markDeprecated(noContent(), altPath).build();
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e, modifier);
    }
    return response;
}
Also used : Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) ApiOperation(io.swagger.annotations.ApiOperation) Consumes(javax.ws.rs.Consumes) Response.noContent(javax.ws.rs.core.Response.noContent) Response.status(javax.ws.rs.core.Response.status) URI(java.net.URI) StoreKey(org.commonjava.indy.model.core.StoreKey) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) StringUtils.isEmpty(org.apache.commons.lang.StringUtils.isEmpty) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) Response.notModified(javax.ws.rs.core.Response.notModified) IOUtils(org.apache.commons.io.IOUtils) ApplicationContent(org.commonjava.indy.util.ApplicationContent) List(java.util.List) Response(javax.ws.rs.core.Response) Response.ok(javax.ws.rs.core.Response.ok) ApplicationScoped(javax.enterprise.context.ApplicationScoped) UriInfo(javax.ws.rs.core.UriInfo) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) HEAD(javax.ws.rs.HEAD) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) ApplicationContent.application_json(org.commonjava.indy.util.ApplicationContent.application_json) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) MavenPackageTypeDescriptor(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor) ResponseUtils.formatOkResponseWithJsonEntity(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatOkResponseWithJsonEntity) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) SecurityManager(org.commonjava.indy.bind.jaxrs.SecurityManager) ResponseUtils.formatCreatedResponseWithJsonEntity(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatCreatedResponseWithJsonEntity) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) METADATA_CHANGELOG(org.commonjava.indy.model.core.ArtifactStore.METADATA_CHANGELOG) IOException(java.io.IOException) Consumer(java.util.function.Consumer) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) AdminController(org.commonjava.indy.core.ctl.AdminController) PUT(javax.ws.rs.PUT) StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Api (io.swagger.annotations.Api)1 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)1 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 HEAD (javax.ws.rs.HEAD)1 POST (javax.ws.rs.POST)1