Search in sources :

Example 26 with StoreType

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

the class SchedulerHandler method deprecatedGetStoreDisableTimeout.

@ApiOperation("[Deprecated] Retrieve the expiration information related to re-enablement of a repository")
@ApiResponses({ @ApiResponse(code = 200, message = "Expiration information retrieved successfully.", response = Expiration.class), @ApiResponse(code = 400, message = "Store is manually disabled (doesn't automatically re-enable), or isn't disabled.") })
@Path("store/{type: (hosted|group|remote)}/{name}/disable-timeout")
@GET
@Deprecated
public Response deprecatedGetStoreDisableTimeout(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") String storeType, @ApiParam(required = true) @PathParam("name") String storeName) {
    StoreType type = StoreType.get(storeType);
    String altPath = Paths.get("/api/admin/schedule", MAVEN_PKG_KEY, type.singularEndpointName(), storeName).toString();
    StoreKey storeKey = new StoreKey(type, storeName);
    Expiration timeout = null;
    try {
        timeout = controller.getStoreDisableTimeout(storeKey);
        if (timeout == null) {
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        return formatOkResponseWithJsonEntity(timeout, objectMapper, rb -> markDeprecated(rb, altPath));
    } catch (IndyWorkflowException e) {
        throwError(e, rb -> markDeprecated(rb, altPath));
    }
    return null;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ResponseUtils.throwError(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.throwError) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ResponseUtils.formatOkResponseWithJsonEntity(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatOkResponseWithJsonEntity) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Api(io.swagger.annotations.Api) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) ExpirationSet(org.commonjava.indy.core.expire.ExpirationSet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Expiration(org.commonjava.indy.core.expire.Expiration) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) ApplicationContent(org.commonjava.indy.util.ApplicationContent) Response(javax.ws.rs.core.Response) SchedulerController(org.commonjava.indy.core.ctl.SchedulerController) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) ResponseUtils(org.commonjava.indy.bind.jaxrs.util.ResponseUtils) WebApplicationException(javax.ws.rs.WebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Expiration(org.commonjava.indy.core.expire.Expiration) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 27 with StoreType

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

the class StoreAdminHandler method store.

/*
     * (non-Javadoc)
     * @see org.commonjava.indy.core.rest.admin.DeployPointAdminResource#store(java.lang.String)
     */
@ApiOperation("Update an existing store")
@ApiResponses({ @ApiResponse(code = 200, message = "The store was updated"), @ApiResponse(code = 400, message = "The store specified in the body JSON didn't match the URL parameters") })
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.model.core.ArtifactStore", value = "The artifact store definition JSON") })
@Path("/{name}")
@PUT
@Consumes(ApplicationContent.application_json)
public Response store(@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);
    Response response = null;
    String json = null;
    try {
        json = IOUtils.toString(request.getInputStream());
        json = objectMapper.patchLegacyStoreJson(json);
    } catch (final IOException e) {
        final String message = "Failed to read " + st.getStoreClass().getSimpleName() + " from request body.";
        logger.error(message, e);
        response = formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    ArtifactStore store = null;
    try {
        store = objectMapper.readValue(json, st.getStoreClass());
    } catch (final IOException e) {
        final String message = "Failed to parse " + st.getStoreClass().getSimpleName() + " from request body.";
        logger.error(message, e);
        response = formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    if (!packageType.equals(store.getPackageType()) || st != store.getType() || !name.equals(store.getName())) {
        response = Response.status(Status.BAD_REQUEST).entity(String.format("Store in URL path is: '%s' but in JSON it is: '%s'", new StoreKey(packageType, st, name), store.getKey())).build();
    }
    try {
        String user = securityManager.getUser(securityContext, request);
        logger.info("Storing: {}", store);
        if (adminController.store(store, user, false)) {
            response = ok().build();
        } else {
            logger.warn("{} NOT modified!", store);
            response = notModified().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) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) 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) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 28 with StoreType

use of org.commonjava.indy.model.core.StoreType 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 29 with StoreType

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

the class StoreAdminHandler method exists.

//    @Context
//    private UriInfo uriInfo;
//
//    @Context
//    private HttpServletRequest request;
@ApiOperation("Check if a given store exists")
@ApiResponses({ @ApiResponse(code = 200, message = "The store exists"), @ApiResponse(code = 404, message = "The store doesn't exist") })
@Path("/{name}")
@HEAD
public Response exists(@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) {
    Response response;
    final StoreType st = StoreType.get(type);
    logger.info("Checking for existence of: {}:{}:{}", packageType, st, name);
    if (adminController.exists(new StoreKey(packageType, st, name))) {
        logger.info("returning OK");
        response = Response.ok().build();
    } else {
        logger.info("Returning NOT FOUND");
        response = Response.status(Status.NOT_FOUND).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 30 with StoreType

use of org.commonjava.indy.model.core.StoreType 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)

Aggregations

StoreType (org.commonjava.indy.model.core.StoreType)53 StoreKey (org.commonjava.indy.model.core.StoreKey)43 Response (javax.ws.rs.core.Response)25 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)25 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)22 ApiOperation (io.swagger.annotations.ApiOperation)21 ApiResponse (io.swagger.annotations.ApiResponse)21 Path (javax.ws.rs.Path)19 ApiResponses (io.swagger.annotations.ApiResponses)18 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)18 IOException (java.io.IOException)13 GET (javax.ws.rs.GET)12 Produces (javax.ws.rs.Produces)12 List (java.util.List)10 Inject (javax.inject.Inject)10 DELETE (javax.ws.rs.DELETE)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 ResponseUtils.markDeprecated (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated)9 IndyDataException (org.commonjava.indy.data.IndyDataException)8 Transfer (org.commonjava.maven.galley.model.Transfer)8