Search in sources :

Example 1 with Context

use of org.sonatype.nexus.repository.view.Context in project nexus-repository-r by sonatype-nexus-community.

the class PackagesGroupHandler method doGet.

@Override
protected Response doGet(@Nonnull final Context context, @Nonnull final GroupHandler.DispatchedRepositories dispatched) throws Exception {
    GroupFacet groupFacet = context.getRepository().facet(GroupFacet.class);
    Map<Repository, Response> responses = getAll(context, groupFacet.members(), dispatched);
    List<Response> successfulResponses = responses.values().stream().filter(response -> response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null).collect(Collectors.toList());
    if (successfulResponses.isEmpty()) {
        return notFoundResponse(context);
    }
    if (successfulResponses.size() == 1) {
        return successfulResponses.get(0);
    }
    List<List<Map<String, String>>> parts = successfulResponses.stream().map(this::parseResponse).collect(Collectors.toList());
    List<Map<String, String>> merged = RPackagesUtils.merge(parts);
    return HttpResponses.ok(RPackagesUtils.buildPackages(merged));
}
Also used : Response(org.sonatype.nexus.repository.view.Response) CompressorException(org.apache.commons.compress.compressors.CompressorException) GroupFacet(org.sonatype.nexus.repository.group.GroupFacet) Context(org.sonatype.nexus.repository.view.Context) HttpStatus(org.sonatype.nexus.repository.http.HttpStatus) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) HttpResponses(org.sonatype.nexus.repository.http.HttpResponses) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) GZIP(org.apache.commons.compress.compressors.CompressorStreamFactory.GZIP) List(java.util.List) Repository(org.sonatype.nexus.repository.Repository) GroupHandler(org.sonatype.nexus.repository.group.GroupHandler) Map(java.util.Map) Payload(org.sonatype.nexus.repository.view.Payload) Named(javax.inject.Named) Response(org.sonatype.nexus.repository.view.Response) Nonnull(javax.annotation.Nonnull) InputStream(java.io.InputStream) GroupFacet(org.sonatype.nexus.repository.group.GroupFacet) Repository(org.sonatype.nexus.repository.Repository) List(java.util.List) Map(java.util.Map)

Example 2 with Context

use of org.sonatype.nexus.repository.view.Context in project nexus-repository-r by sonatype-nexus-community.

the class PackagesGroupHandler method doGet.

@Override
protected Response doGet(@Nonnull final Context context, @Nonnull final GroupHandler.DispatchedRepositories dispatched) throws Exception {
    GroupFacet groupFacet = context.getRepository().facet(GroupFacet.class);
    Map<Repository, Response> responses = getAll(context, groupFacet.members(), dispatched);
    List<Response> successfulResponses = responses.values().stream().filter(response -> response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null).collect(Collectors.toList());
    if (successfulResponses.isEmpty()) {
        return notFoundResponse(context);
    }
    if (successfulResponses.size() == 1) {
        return successfulResponses.get(0);
    }
    List<List<Map<String, String>>> parts = successfulResponses.stream().map(this::parseResponse).collect(Collectors.toList());
    List<Map<String, String>> merged = RPackagesUtils.merge(parts);
    return HttpResponses.ok(RPackagesUtils.buildPackages(merged));
}
Also used : Response(org.sonatype.nexus.repository.view.Response) RPackagesUtils(org.sonatype.nexus.repository.r.internal.util.RPackagesUtils) CompressorException(org.apache.commons.compress.compressors.CompressorException) GroupFacet(org.sonatype.nexus.repository.group.GroupFacet) Context(org.sonatype.nexus.repository.view.Context) RException(org.sonatype.nexus.repository.r.internal.RException) HttpStatus(org.sonatype.nexus.repository.http.HttpStatus) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) HttpResponses(org.sonatype.nexus.repository.http.HttpResponses) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) GZIP(org.apache.commons.compress.compressors.CompressorStreamFactory.GZIP) List(java.util.List) Repository(org.sonatype.nexus.repository.Repository) GroupHandler(org.sonatype.nexus.repository.group.GroupHandler) Map(java.util.Map) Payload(org.sonatype.nexus.repository.view.Payload) Named(javax.inject.Named) Response(org.sonatype.nexus.repository.view.Response) Nonnull(javax.annotation.Nonnull) InputStream(java.io.InputStream) GroupFacet(org.sonatype.nexus.repository.group.GroupFacet) Repository(org.sonatype.nexus.repository.Repository) List(java.util.List) Map(java.util.Map)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Nonnull (javax.annotation.Nonnull)2 Named (javax.inject.Named)2 Singleton (javax.inject.Singleton)2 CompressorException (org.apache.commons.compress.compressors.CompressorException)2 CompressorStreamFactory (org.apache.commons.compress.compressors.CompressorStreamFactory)2 GZIP (org.apache.commons.compress.compressors.CompressorStreamFactory.GZIP)2 Repository (org.sonatype.nexus.repository.Repository)2 GroupFacet (org.sonatype.nexus.repository.group.GroupFacet)2 GroupHandler (org.sonatype.nexus.repository.group.GroupHandler)2 HttpResponses (org.sonatype.nexus.repository.http.HttpResponses)2 HttpStatus (org.sonatype.nexus.repository.http.HttpStatus)2 Context (org.sonatype.nexus.repository.view.Context)2 Payload (org.sonatype.nexus.repository.view.Payload)2 Response (org.sonatype.nexus.repository.view.Response)2