Search in sources :

Example 51 with ApiResponse

use of io.swagger.annotations.ApiResponse in project indy by Commonjava.

the class StoreAdminHandler method create.

@ApiOperation("Create a new store")
@ApiResponses({ @ApiResponse(code = 201, response = ArtifactStore.class, message = "The store was created"), @ApiResponse(code = 409, message = "A store with the specified type and name already exists") })
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.model.core.ArtifactStore", value = "The artifact store definition JSON") })
@POST
@Consumes(ApplicationContent.application_json)
@Produces(ApplicationContent.application_json)
public Response create(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @Context final UriInfo uriInfo, @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());
        // logger.warn("=> JSON: " + json);
        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 = responseHelper.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 = responseHelper.formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    logger.info("\n\nGot artifact store: {}\n\n", store);
    try {
        String user = securityManager.getUser(securityContext, request);
        if (adminController.store(store, user, false)) {
            final URI uri = uriInfo.getBaseUriBuilder().path("/api/admin/stores").path(store.getPackageType()).path(store.getType().singularEndpointName()).build(store.getName());
            response = responseHelper.formatCreatedResponseWithJsonEntity(uri, store);
        } else {
            response = status(CONFLICT).entity("{\"error\": \"Store already exists.\"}").type(application_json).build();
        }
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) IOException(java.io.IOException) URI(java.net.URI) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 52 with ApiResponse

use of io.swagger.annotations.ApiResponse in project indy by Commonjava.

the class StoreAdminHandler method revalidateArtifactStores.

@ApiOperation("Revalidation of Artifacts Stored on demand")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "Revalidation for Remote Repositories was successfull"), @ApiResponse(code = 404, message = "Revalidation is not successfull") })
@Path("/revalidate/all/")
@POST
public Response revalidateArtifactStores(@PathParam("packageType") String packageType, @PathParam("type") String type) {
    ArtifactStoreValidateData result = null;
    Map<String, ArtifactStoreValidateData> results = new HashMap<>();
    Response response;
    try {
        StoreType storeType = StoreType.get(type);
        List<ArtifactStore> allArtifactStores = adminController.getAllOfType(packageType, storeType);
        for (ArtifactStore artifactStore : allArtifactStores) {
            // Validate this Store
            result = adminController.validateStore(artifactStore);
            results.put(artifactStore.getKey().toString(), result);
        }
        response = responseHelper.formatOkResponseWithJsonEntity(results);
    } catch (IndyDataException ide) {
        logger.warn("=> [IndyDataException] exception message: " + ide.getMessage());
        response = responseHelper.formatResponse(ide);
    } catch (MalformedURLException mue) {
        logger.warn("=> [MalformedURLException] Invalid URL exception message: " + mue.getMessage());
        response = responseHelper.formatResponse(mue);
    } catch (IndyWorkflowException iwe) {
        logger.warn("=> [IndyWorkflowException] exception message: " + iwe.getMessage());
        response = responseHelper.formatResponse(iwe);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 53 with ApiResponse

use of io.swagger.annotations.ApiResponse 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, @QueryParam("deleteContent") final boolean deleteContent, @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: {}, deleteContent: {}", key, deleteContent);
    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";
        }
        summary += (", deleteContent:" + deleteContent);
        String user = securityManager.getUser(securityContext, request);
        adminController.delete(key, user, summary, deleteContent);
        response = noContent().build();
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) JoinString(org.commonjava.atlas.maven.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 54 with ApiResponse

use of io.swagger.annotations.ApiResponse in project indy by Commonjava.

the class StoreAdminHandler method revalidateArtifactStore.

@ApiOperation("Revalidation of Artifact Stored on demand based on package, type and name")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "Revalidation for Remote Repository was successfull"), @ApiResponse(code = 404, message = "Revalidation is not successfull") })
@Path("/{name}/revalidate")
@POST
public Response revalidateArtifactStore(@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) {
    ArtifactStoreValidateData result = null;
    Response response;
    try {
        final StoreType st = StoreType.get(type);
        final StoreKey key = new StoreKey(packageType, st, name);
        final ArtifactStore store = adminController.get(key);
        logger.info("=> Returning repository: {}", store);
        // Validate this Store
        result = adminController.validateStore(store);
        logger.warn("=> Result from Validating Store: " + result);
        if (result == null) {
            response = Response.status(Status.NOT_FOUND).build();
        } else {
            response = responseHelper.formatOkResponseWithJsonEntity(result);
        }
    } catch (IndyDataException ide) {
        logger.warn("=> [IndyDataException] exception message: " + ide.getMessage());
        response = responseHelper.formatResponse(ide);
    } catch (MalformedURLException mue) {
        logger.warn("=> [MalformedURLException] Invalid URL exception message: " + mue.getMessage());
        response = responseHelper.formatResponse(mue);
    } catch (IndyWorkflowException iwe) {
        logger.warn("=> [IndyWorkflowException] exception message: " + iwe.getMessage());
        response = responseHelper.formatResponse(iwe);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) MalformedURLException(java.net.MalformedURLException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArtifactStoreValidateData(org.commonjava.indy.data.ArtifactStoreValidateData) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 55 with ApiResponse

use of io.swagger.annotations.ApiResponse in project indy by Commonjava.

the class StatsHandler method getAllEndpoints.

@ApiOperation("Retrieve a listing of the artifact stores available on the system. This is especially useful for setting up a network of Indy instances that reference one another")
@ApiResponse(code = 200, response = EndpointViewListing.class, message = "The artifact store listing")
@Path("/all-endpoints")
@GET
@Produces(ApplicationContent.application_json)
public Response getAllEndpoints(@Context final UriInfo uriInfo) {
    Response response;
    try {
        final String baseUri = uriInfo.getBaseUriBuilder().path(IndyDeployment.API_PREFIX).build().toString();
        final EndpointViewListing listing = statsController.getEndpointsListing(baseUri, uriFormatter);
        response = responseHelper.formatOkResponseWithJsonEntity(listing);
        logger.info("\n\n\n\n\n\n{} Sent all-endpoints:\n\n{}\n\n\n\n\n\n\n", new Date(), listing);
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to retrieve endpoint listing: %s", responseHelper.formatEntity(e)), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Aggregations

ApiResponse (io.swagger.annotations.ApiResponse)156 ApiOperation (io.swagger.annotations.ApiOperation)130 Path (javax.ws.rs.Path)124 Response (javax.ws.rs.core.Response)120 ApiResponses (io.swagger.annotations.ApiResponses)116 GET (javax.ws.rs.GET)93 Produces (javax.ws.rs.Produces)83 Api (io.swagger.annotations.Api)64 Consumes (javax.ws.rs.Consumes)60 POST (javax.ws.rs.POST)58 PathParam (javax.ws.rs.PathParam)58 DELETE (javax.ws.rs.DELETE)55 QueryParam (javax.ws.rs.QueryParam)46 List (java.util.List)45 Inject (javax.inject.Inject)45 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)45 ApiParam (io.swagger.annotations.ApiParam)44 Collectors (java.util.stream.Collectors)42 Logger (org.slf4j.Logger)42 LoggerFactory (org.slf4j.LoggerFactory)42