Search in sources :

Example 76 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class StoreAdminHandler 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(@PathParam("packageType") final String packageType, @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) {
    final StoreType st = StoreType.get(type);
    final StoreKey key = new StoreKey(packageType, 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 = noContent().build();
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : 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)

Example 77 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class StoreAdminHandler method get.

@ApiOperation("Retrieve the definition of a specific artifact store")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "The store definition"), @ApiResponse(code = 404, message = "The store doesn't exist") })
@Path("/{name}")
@GET
@Produces(ApplicationContent.application_json)
public Response get(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name) {
    final StoreType st = StoreType.get(type);
    final StoreKey key = new StoreKey(packageType, st, name);
    Response response;
    try {
        final ArtifactStore store = adminController.get(key);
        logger.info("Returning repository: {}", store);
        if (store == null) {
            response = Response.status(Status.NOT_FOUND).build();
        } else {
            response = formatOkResponseWithJsonEntity(store, objectMapper);
        }
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : 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) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 78 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class StoreAdminHandler method getAll.

@ApiOperation("Retrieve the definitions of all artifact stores of a given type on the system")
@ApiResponses({ @ApiResponse(code = 200, response = StoreListingDTO.class, message = "The store definitions") })
@GET
@Produces(ApplicationContent.application_json)
public Response getAll(@ApiParam("Filter only stores that support the package type (eg. maven, npm). NOTE: '_all' returns all.") @PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
    final StoreType st = StoreType.get(type);
    Response response;
    try {
        final List<ArtifactStore> stores = adminController.getAllOfType(packageType, st);
        logger.info("Returning listing containing stores:\n\t{}", new JoinString("\n\t", stores));
        final StoreListingDTO<ArtifactStore> dto = new StoreListingDTO<>(stores);
        response = formatOkResponseWithJsonEntity(dto, objectMapper);
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : 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) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 79 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class ContentAccessHandler method doHead.

public Response doHead(final String packageType, final String type, final String name, final String path, final Boolean cacheOnly, final String baseUri, final HttpServletRequest request, EventMetadata eventMetadata, final Consumer<ResponseBuilder> builderModifier) {
    if (!PackageTypes.contains(packageType)) {
        ResponseBuilder builder = Response.status(400);
        if (builderModifier != null) {
            builderModifier.accept(builder);
        }
        return builder.build();
    }
    final StoreType st = StoreType.get(type);
    final StoreKey sk = new StoreKey(packageType, st, name);
    eventMetadata = eventMetadata.set(ContentManager.ENTRY_POINT_STORE, sk);
    final AcceptInfo acceptInfo = jaxRsRequestHelper.findAccept(request, ApplicationContent.text_html);
    Response response = null;
    if (path == null || path.equals("") || path.endsWith("/") || path.endsWith(LISTING_HTML_FILE)) {
        try {
            logger.info("Getting listing at: {}", path);
            final String content = contentController.renderListing(acceptInfo.getBaseAccept(), sk, path, baseUri, uriFormatter);
            ResponseBuilder builder = Response.ok().header(ApplicationHeader.content_type.key(), acceptInfo.getRawAccept()).header(ApplicationHeader.content_length.key(), Long.toString(content.length())).header(ApplicationHeader.last_modified.key(), HttpUtils.formatDateHeader(new Date()));
            if (builderModifier != null) {
                builderModifier.accept(builder);
            }
            response = builder.build();
        } catch (final IndyWorkflowException e) {
            logger.error(String.format("Failed to list content: %s from: %s. Reason: %s", path, name, e.getMessage()), e);
            response = formatResponse(e, builderModifier);
        }
    } else {
        try {
            Transfer item = null;
            logger.info("Checking existence of: {}:{} (cache only? {})", sk, path, cacheOnly);
            boolean exists = false;
            if (Boolean.TRUE.equals(cacheOnly)) {
                logger.debug("Calling getTransfer()");
                item = contentController.getTransfer(sk, path, TransferOperation.DOWNLOAD);
                exists = item != null && item.exists();
                logger.debug("Got transfer reference: {}", item);
            } else {
                // Use exists for remote repo to avoid downloading file. Use getTransfer for everything else (hosted, cache-only).
                // Response will be composed of metadata by getHttpMetadata which get metadata from .http-metadata.json (because HTTP transport always writes a .http-metadata.json
                // file when it makes a request). This file stores the HTTP response status code and headers regardless exist returning true or false.
                logger.debug("Calling exists()");
                exists = contentController.exists(sk, path);
                logger.debug("Got exists: {}", exists);
            }
            if (exists) {
                HttpExchangeMetadata httpMetadata = item != null ? contentController.getHttpMetadata(item) : contentController.getHttpMetadata(sk, path);
                // TODO: For hosted repo, artifacts do not have metadata generated. Fall to get(). But we need a better fix later on.
                if (httpMetadata == null) {
                    logger.info("Retrieving: {}:{} for existence test", sk, path);
                    item = contentController.get(sk, path, eventMetadata);
                    logger.debug("Got retrieved transfer reference: {}", item);
                }
                logger.debug("Building 200 response. Using HTTP metadata: {}", httpMetadata);
                final ResponseBuilder builder = Response.ok();
                setInfoHeaders(builder, item, sk, path, true, contentController.getContentType(path), httpMetadata);
                if (builderModifier != null) {
                    builderModifier.accept(builder);
                }
                response = builder.build();
            } else {
                logger.debug("Building 404 (or error) response...");
                if (StoreType.remote == st) {
                    final HttpExchangeMetadata metadata = contentController.getHttpMetadata(sk, path);
                    if (metadata != null) {
                        logger.debug("Using HTTP metadata to build negative response.");
                        response = formatResponseFromMetadata(metadata);
                    }
                }
                if (response == null) {
                    logger.debug("No HTTP metadata; building generic 404 response.");
                    ResponseBuilder builder = Response.status(Status.NOT_FOUND);
                    if (builderModifier != null) {
                        builderModifier.accept(builder);
                    }
                    response = builder.build();
                }
            }
        } catch (final IndyWorkflowException e) {
            logger.error(String.format("Failed to download artifact: %s from: %s. Reason: %s", path, name, e.getMessage()), e);
            response = formatResponse(e, builderModifier);
        }
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) AcceptInfo(org.commonjava.indy.util.AcceptInfo) StoreKey(org.commonjava.indy.model.core.StoreKey) HttpExchangeMetadata(org.commonjava.maven.galley.transport.htcli.model.HttpExchangeMetadata) Date(java.util.Date)

Example 80 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class ContentAccessHandler method doCreate.

public Response doCreate(final String packageType, final String type, final String name, final String path, final HttpServletRequest request, EventMetadata eventMetadata, final Supplier<URI> uriBuilder, final Consumer<ResponseBuilder> builderModifier) {
    final StoreType st = StoreType.get(type);
    StoreKey sk = new StoreKey(packageType, st, name);
    eventMetadata = eventMetadata.set(ContentManager.ENTRY_POINT_STORE, sk);
    Response response = null;
    final Transfer transfer;
    try {
        transfer = contentController.store(sk, path, request.getInputStream(), eventMetadata);
        final StoreKey storageKey = LocationUtils.getKey(transfer);
        logger.info("Key for storage location: {}", storageKey);
        final URI uri = uriBuilder.get();
        ResponseBuilder builder = Response.created(uri);
        if (builderModifier != null) {
            builderModifier.accept(builder);
        }
        response = builder.build();
    } catch (final IndyWorkflowException | IOException e) {
        logger.error(String.format("Failed to upload: %s to: %s. Reason: %s", path, name, e.getMessage()), e);
        response = formatResponse(e, builderModifier);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI)

Aggregations

IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)109 Response (javax.ws.rs.core.Response)40 Transfer (org.commonjava.maven.galley.model.Transfer)39 IOException (java.io.IOException)36 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)36 StoreKey (org.commonjava.indy.model.core.StoreKey)36 ApiOperation (io.swagger.annotations.ApiOperation)35 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)34 ApiResponse (io.swagger.annotations.ApiResponse)33 Path (javax.ws.rs.Path)32 StoreType (org.commonjava.indy.model.core.StoreType)26 IndyDataException (org.commonjava.indy.data.IndyDataException)25 GET (javax.ws.rs.GET)24 Logger (org.slf4j.Logger)22 ApiResponses (io.swagger.annotations.ApiResponses)21 ArrayList (java.util.ArrayList)19 Produces (javax.ws.rs.Produces)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)18 InputStream (java.io.InputStream)15 List (java.util.List)13