Search in sources :

Example 1 with GroupFacet

use of org.sonatype.nexus.repository.group.GroupFacet in project nexus-repository-r by sonatype-nexus-community.

the class PackagesGroupHandlerTest method setupRepository.

// Commented out until GroupHandler.DispactchedRepositories is made public
/*  @Test
  public void okWhenGetPackagesWithSingleResponse() throws Exception {
    Response response = underTest.doGet(context, dispatchedRepositories);
    assertThat(response.getStatus().getCode(), is(equalTo(200)));
  }

  @Test
  public void okWhenGetPackagesWithMultipleResponses() throws Exception {
    members.add(repository2);
    Response response = underTest.doGet(context, dispatchedRepositories);
    assertThat(response.getStatus().getCode(), is(equalTo(200)));
  }

  @Test
  public void notFoundWhenNoResponses() throws Exception {
    members.clear();
    Response response = underTest.doGet(context, dispatchedRepositories);
    assertThat(response.getStatus().getCode(), is(equalTo(404)));
  }*/
private void setupRepository(final Repository repository) throws Exception {
    ViewFacet viewFacet = mock(ViewFacet.class);
    Response response = mock(Response.class);
    Payload payload = mock(Payload.class);
    GroupFacet groupFacet = mock(GroupFacet.class);
    when(groupFacet.members()).thenReturn(members);
    when(repository.facet(GroupFacet.class)).thenReturn(groupFacet);
    when(repository.facet(ViewFacet.class)).thenReturn(viewFacet);
    when(viewFacet.dispatch(any(), any())).thenReturn(response);
    when(response.getPayload()).thenReturn(payload);
    when(payload.openInputStream()).thenReturn(new FileInputStream(packages));
    when(response.getStatus()).thenReturn(new Status(true, 200));
}
Also used : Response(org.sonatype.nexus.repository.view.Response) Status(org.sonatype.nexus.repository.view.Status) GroupFacet(org.sonatype.nexus.repository.group.GroupFacet) ViewFacet(org.sonatype.nexus.repository.view.ViewFacet) Payload(org.sonatype.nexus.repository.view.Payload) FileInputStream(java.io.FileInputStream)

Example 2 with GroupFacet

use of org.sonatype.nexus.repository.group.GroupFacet 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 3 with GroupFacet

use of org.sonatype.nexus.repository.group.GroupFacet in project nexus-repository-r by sonatype-nexus-community.

the class PackagesGroupHandlerTest method setupRepository.

// Commented out until GroupHandler.DispactchedRepositories is made public
/*  @Test
  public void okWhenGetPackagesWithSingleResponse() throws Exception {
    Response response = underTest.doGet(context, dispatchedRepositories);
    assertThat(response.getStatus().getCode(), is(equalTo(200)));
  }

  @Test
  public void okWhenGetPackagesWithMultipleResponses() throws Exception {
    members.add(repository2);
    Response response = underTest.doGet(context, dispatchedRepositories);
    assertThat(response.getStatus().getCode(), is(equalTo(200)));
  }

  @Test
  public void notFoundWhenNoResponses() throws Exception {
    members.clear();
    Response response = underTest.doGet(context, dispatchedRepositories);
    assertThat(response.getStatus().getCode(), is(equalTo(404)));
  }*/
private void setupRepository(final Repository repository) throws Exception {
    ViewFacet viewFacet = mock(ViewFacet.class);
    Response response = mock(Response.class);
    Payload payload = mock(Payload.class);
    GroupFacet groupFacet = mock(GroupFacet.class);
    when(groupFacet.members()).thenReturn(members);
    when(repository.facet(GroupFacet.class)).thenReturn(groupFacet);
    when(repository.facet(ViewFacet.class)).thenReturn(viewFacet);
    when(viewFacet.dispatch(any(), any())).thenReturn(response);
    when(response.getPayload()).thenReturn(payload);
    when(payload.openInputStream()).thenReturn(new FileInputStream(packages));
    when(response.getStatus()).thenReturn(new Status(true, 200));
}
Also used : Response(org.sonatype.nexus.repository.view.Response) Status(org.sonatype.nexus.repository.view.Status) GroupFacet(org.sonatype.nexus.repository.group.GroupFacet) ViewFacet(org.sonatype.nexus.repository.view.ViewFacet) Payload(org.sonatype.nexus.repository.view.Payload) FileInputStream(java.io.FileInputStream)

Example 4 with GroupFacet

use of org.sonatype.nexus.repository.group.GroupFacet 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

GroupFacet (org.sonatype.nexus.repository.group.GroupFacet)4 Payload (org.sonatype.nexus.repository.view.Payload)4 Response (org.sonatype.nexus.repository.view.Response)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 FileInputStream (java.io.FileInputStream)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 GroupHandler (org.sonatype.nexus.repository.group.GroupHandler)2 HttpResponses (org.sonatype.nexus.repository.http.HttpResponses)2 HttpStatus (org.sonatype.nexus.repository.http.HttpStatus)2