Search in sources :

Example 46 with IndyWorkflowException

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

the class SecurityResource method getKeycloakJs.

@ApiOperation("Retrieve the keycloak Javascript adapter (for use by the UI)")
@ApiResponses({ @ApiResponse(code = 200, message = "Keycloak is disabled, return a Javascript comment to this effect."), @ApiResponse(code = 307, message = "Redirect to keycloak server to load Javascript adapter.") })
@Path("/keycloak.js")
@Produces("text/javascript")
@GET
public Response getKeycloakJs() {
    logger.debug("Retrieving Keycloak Javascript adapter...");
    Response response = null;
    try {
        final String url = controller.getKeycloakJs();
        if (url == null) {
            response = Response.ok("/* " + DISABLED_MESSAGE + "; loading of keycloak.js blocked. */").header(ApplicationHeader.cache_control.key(), NO_CACHE).build();
        } else {
            response = Response.temporaryRedirect(new URI(url)).build();
        }
    } catch (final IndyWorkflowException | URISyntaxException e) {
        logger.error(String.format("Failed to load keycloak.js. Reason: %s", 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) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) 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 47 with IndyWorkflowException

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

the class ValidationRequest method getSourcePaths.

public synchronized Set<String> getSourcePaths(boolean includeMetadata, boolean includeChecksums) throws PromotionValidationException {
    if (requestPaths == null) {
        Set<String> paths = null;
        if (promoteRequest instanceof PathsPromoteRequest) {
            paths = ((PathsPromoteRequest) promoteRequest).getPaths();
        }
        if (paths == null) {
            ArtifactStore store = null;
            try {
                store = tools.getArtifactStore(promoteRequest.getSource());
            } catch (IndyDataException e) {
                throw new PromotionValidationException("Failed to retrieve source ArtifactStore: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
            }
            if (store != null) {
                try {
                    paths = new HashSet<>();
                    listRecursively(store, "/", paths);
                } catch (IndyWorkflowException e) {
                    throw new PromotionValidationException("Failed to list paths in source: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
                }
            }
        }
        requestPaths = paths;
    }
    if (!includeMetadata || !includeChecksums) {
        Predicate<String> filter = (path) -> (includeMetadata || !path.matches(".+/maven-metadata\\.xml(\\.(md5|sha[0-9]+))?")) && (includeChecksums || !path.matches(".+\\.(md5|sha[0-9]+)"));
        return requestPaths.stream().filter(filter).collect(Collectors.toSet());
    }
    return requestPaths;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Predicate(java.util.function.Predicate) Set(java.util.Set) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) ValidationRuleSet(org.commonjava.indy.promote.model.ValidationRuleSet) List(java.util.List) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreResource(org.commonjava.indy.content.StoreResource) PromotionValidationTools(org.commonjava.indy.promote.validate.PromotionValidationTools) PromoteRequest(org.commonjava.indy.promote.model.PromoteRequest) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreKey(org.commonjava.indy.model.core.StoreKey) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException)

Example 48 with IndyWorkflowException

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

the class SetBackSettingsResource method get.

@ApiOperation("Return settings.xml that approximates the behavior of the specified Indy group/repository (CAUTION: Indy-hosted content will be unavailable!)")
@ApiResponses({ @ApiResponse(code = 400, message = "Requested repository is hosted on Indy and cannot be simulated via settings.xml"), @ApiResponse(code = 404, message = "No such repository or group, or the settings.xml has not been generated."), @ApiResponse(code = 200, message = "Maven settings.xml content") })
@Path("/{type: (remote|group)}/{name}")
@GET
@Produces(ApplicationContent.application_xml)
public Response get(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String t, @PathParam("name") final String n) {
    final StoreType type = StoreType.get(t);
    if (StoreType.hosted == type) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Response response;
    final StoreKey key = new StoreKey(type, n);
    DataFile settingsXml = null;
    try {
        settingsXml = controller.getSetBackSettings(key);
    } catch (final IndyWorkflowException e) {
        response = ResponseUtils.formatResponse(e);
    }
    if (settingsXml != null && settingsXml.exists()) {
        response = Response.ok(settingsXml).type(ApplicationContent.application_xml).build();
    } else {
        response = Response.status(Status.NOT_FOUND).build();
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) DataFile(org.commonjava.indy.subsys.datafile.DataFile) 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 49 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException 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)

Example 50 with IndyWorkflowException

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

the class PromoteResource method resumePaths.

@ApiOperation("RESUME promotion of paths from a source repository into a target repository/group (subject to validation), presumably after a previous failure condition has been corrected.")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON result from previous attempt, specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteResult")
@Path("/paths/resume")
@POST
@Consumes(ApplicationContent.application_json)
public Response resumePaths(@Context final HttpServletRequest request) {
    PathsPromoteResult result = null;
    Response response = null;
    try {
        result = mapper.readValue(request.getInputStream(), PathsPromoteResult.class);
    } catch (final IOException e) {
        response = formatResponse(e, "Failed to read DTO from request body.");
    }
    if (response != null) {
        return response;
    }
    try {
        result = manager.resumePathsPromote(result);
        // 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) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) 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

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