Search in sources :

Example 1 with StoreListingDTO

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

the class DeprecatedStoreAdminHandler 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(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
    String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type).toString();
    Consumer<Response.ResponseBuilder> modifier = (rb) -> markDeprecated(rb, altPath);
    final StoreType st = StoreType.get(type);
    Response response;
    try {
        final List<ArtifactStore> stores = adminController.getAllOfType(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, modifier);
    } 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) 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) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with StoreListingDTO

use of org.commonjava.indy.model.core.dto.StoreListingDTO 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 3 with StoreListingDTO

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

the class ReplicationController method addStoresFrom.

private <T extends ArtifactStore> void addStoresFrom(final List<ArtifactStore> result, final String remotesUrl, final ReplicationDTO dto, final Class<T> type) throws IndyWorkflowException {
    final HttpGet req = newGet(remotesUrl, dto);
    CloseableHttpClient client = null;
    try {
        String siteId = new URL(remotesUrl).getHost();
        client = http.createClient(siteId);
        CloseableHttpResponse response = client.execute(req, http.createContext(siteId));
        final StatusLine statusLine = response.getStatusLine();
        final int status = statusLine.getStatusCode();
        if (status == HttpStatus.SC_OK) {
            final String json = HttpResources.entityToString(response);
            final StoreListingDTO<T> listing = serializer.readValue(json, serializer.getTypeFactory().constructParametricType(StoreListingDTO.class, type));
            if (listing != null) {
                result.addAll(listing.getItems());
            }
        } else {
            throw new IndyWorkflowException(status, "Request: %s failed: %s", remotesUrl, statusLine);
        }
    } catch (final IOException | IndyHttpException e) {
        throw new IndyWorkflowException("Failed to retrieve endpoints from: %s. Reason: %s", e, remotesUrl, e.getMessage());
    } finally {
        IOUtils.closeQuietly(client);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) IndyHttpException(org.commonjava.indy.subsys.http.IndyHttpException) IOException(java.io.IOException) URL(java.net.URL) StatusLine(org.apache.http.StatusLine) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Aggregations

IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponse (io.swagger.annotations.ApiResponse)2 ApiResponses (io.swagger.annotations.ApiResponses)2 IOException (java.io.IOException)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 StoreListingDTO (org.commonjava.indy.model.core.dto.StoreListingDTO)2 Api (io.swagger.annotations.Api)1 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)1 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)1 ApiParam (io.swagger.annotations.ApiParam)1 URI (java.net.URI)1 URL (java.net.URL)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