@Test public void testGetAssetsLastPage() throws Exception { when(browseResult.getTotal()).thenReturn(2l); when(browseResult.getResults()).thenReturn(Arrays.asList(assetOne, assetTwo)); when(browseService.browseAssets(eq(mavenReleases), queryOptionsCaptor.capture())).thenReturn(browseResult); Page<AssetXO> assetXOPage = underTest.getAssets(null, "maven-releases"); assertThat(assetXOPage.getContinuationToken(), isEmptyOrNullString()); assertThat(assetXOPage.getItems(), hasSize(2)); }
@GET public Page<AssetXO> getAssets(@QueryParam("continuationToken") final String continuationToken, @QueryParam("repository") final String repositoryId) { Repository repository = repositoryManagerRESTAdapter.getRepository(repositoryId); PageResult<Asset> assetBrowseResult = browseService.browseAssets( repository, new QueryOptions(null, "id", "asc", 0, 10, lastIdFromContinuationToken(continuationToken))); List<AssetXO> assetXOs = assetBrowseResult.getResults().stream() .map(asset -> fromAsset(asset, repository)) .collect(toList()); return new Page<>(assetXOs, assetBrowseResult.getTotal() > assetBrowseResult.getResults().size() ? continuationTokenHelper.getTokenFromId(getLast(assetBrowseResult.getResults())) : null); }
AssetsResource extends ComponentSupport implements Resource, AssetsResourceDoc { @GET public Page<AssetXO> getAssets(@QueryParam("continuationToken") final String continuationToken, @QueryParam("repository") final String repositoryId) { Repository repository = repositoryManagerRESTAdapter.getRepository(repositoryId); PageResult<Asset> assetBrowseResult = browseService.browseAssets( repository, new QueryOptions(null, "id", "asc", 0, 10, lastIdFromContinuationToken(continuationToken))); List<AssetXO> assetXOs = assetBrowseResult.getResults().stream() .map(asset -> fromAsset(asset, repository)) .collect(toList()); return new Page<>(assetXOs, assetBrowseResult.getTotal() > assetBrowseResult.getResults().size() ? continuationTokenHelper.getTokenFromId(getLast(assetBrowseResult.getResults())) : null); } }
AssetsResource extends ComponentSupport implements Resource, AssetsResourceDoc { @GET public Page<AssetXO> getAssets(@QueryParam("continuationToken") final String continuationToken, @QueryParam("repository") final String repositoryId) { Repository repository = repositoryManagerRESTAdapter.getRepository(repositoryId); PageResult<Asset> assetBrowseResult = browseService.browseAssets( repository, new QueryOptions(null, "id", "asc", 0, 10, lastIdFromContinuationToken(continuationToken))); List<AssetXO> assetXOs = assetBrowseResult.getResults().stream() .map(asset -> fromAsset(asset, repository)) .collect(toList()); return new Page<>(assetXOs, assetBrowseResult.getTotal() > assetBrowseResult.getResults().size() ? continuationTokenHelper.getTokenFromId(getLast(assetBrowseResult.getResults())) : null); } @Inject  AssetsResource(final BrowseService browseService,
                        final RepositoryManagerRESTAdapter repositoryManagerRESTAdapter,
                        final AssetEntityAdapter assetEntityAdapter,
                        final MaintenanceService maintenanceService,
                        @Named("asset") final ContinuationTokenHelper continuationTokenHelper); }
AssetsResource extends ComponentSupport implements Resource, AssetsResourceDoc { @GET public Page<AssetXO> getAssets(@QueryParam("continuationToken") final String continuationToken, @QueryParam("repository") final String repositoryId) { Repository repository = repositoryManagerRESTAdapter.getRepository(repositoryId); PageResult<Asset> assetBrowseResult = browseService.browseAssets( repository, new QueryOptions(null, "id", "asc", 0, 10, lastIdFromContinuationToken(continuationToken))); List<AssetXO> assetXOs = assetBrowseResult.getResults().stream() .map(asset -> fromAsset(asset, repository)) .collect(toList()); return new Page<>(assetXOs, assetBrowseResult.getTotal() > assetBrowseResult.getResults().size() ? continuationTokenHelper.getTokenFromId(getLast(assetBrowseResult.getResults())) : null); } @Inject  AssetsResource(final BrowseService browseService,
                        final RepositoryManagerRESTAdapter repositoryManagerRESTAdapter,
                        final AssetEntityAdapter assetEntityAdapter,
                        final MaintenanceService maintenanceService,
                        @Named("asset") final ContinuationTokenHelper continuationTokenHelper); @GET Page<AssetXO> getAssets(@QueryParam("continuationToken") final String continuationToken,
      @QueryParam("repository") final String repositoryId); @GET @Path("/{id}") AssetXO getAssetById(@PathParam("id") final String id); @DELETE @Path("/{id}") void deleteAsset(@PathParam("id")
                          final String id); }
AssetsResource extends ComponentSupport implements Resource, AssetsResourceDoc { @GET public Page<AssetXO> getAssets(@QueryParam("continuationToken") final String continuationToken, @QueryParam("repository") final String repositoryId) { Repository repository = repositoryManagerRESTAdapter.getRepository(repositoryId); PageResult<Asset> assetBrowseResult = browseService.browseAssets( repository, new QueryOptions(null, "id", "asc", 0, 10, lastIdFromContinuationToken(continuationToken))); List<AssetXO> assetXOs = assetBrowseResult.getResults().stream() .map(asset -> fromAsset(asset, repository)) .collect(toList()); return new Page<>(assetXOs, assetBrowseResult.getTotal() > assetBrowseResult.getResults().size() ? continuationTokenHelper.getTokenFromId(getLast(assetBrowseResult.getResults())) : null); } @Inject  AssetsResource(final BrowseService browseService,
                        final RepositoryManagerRESTAdapter repositoryManagerRESTAdapter,
                        final AssetEntityAdapter assetEntityAdapter,
                        final MaintenanceService maintenanceService,
                        @Named("asset") final ContinuationTokenHelper continuationTokenHelper); @GET Page<AssetXO> getAssets(@QueryParam("continuationToken") final String continuationToken,
      @QueryParam("repository") final String repositoryId); @GET @Path("/{id}") AssetXO getAssetById(@PathParam("id") final String id); @DELETE @Path("/{id}") void deleteAsset(@PathParam("id")
                          final String id); static final String RESOURCE_URI; }