@Test public void testBrowseAssets() { List<Repository> expectedRepositories = asList(mavenReleases); String expectedQuery1 = "SELECT FROM INDEXVALUES:asset_name_ci_idx WHERE (bucket = b4) SKIP 0 LIMIT 1"; List<String> bucketIds = Collections.singletonList("b4"); Iterable<ODocument> resultDocs = asList(mock(ODocument.class), mock(ODocument.class)); doReturn(bucketIds).when(underTest).getBucketIds(any(), eq(expectedRepositories)); doReturn(results).when(underTest).getAssets(resultDocs); when(storageTx.browse(eq(expectedQuery1), any())).thenReturn(resultDocs); when(queryOptions.getLimit()).thenReturn(10); when(browseAssetIterableFactory.create(any(), any(), any(), any(), eq(10))).thenReturn(resultDocs); PageResult<Asset> browseResult = underTest.browseAssets(mavenReleases, queryOptions); assertThat(browseResult.getTotal(), is(2L)); assertThat(browseResult.getResults(), is(results)); }
@Override public PageResult<Asset> browseAssets(final Repository repository, final QueryOptions queryOptions) { checkNotNull(repository); final List<Repository> repositories = getRepositories(repository); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<String> bucketIds = getBucketIds(storageTx, repositories); List<Asset> assets = Collections.emptyList(); if (hasAssets(storageTx, repository, bucketIds, queryOptions)) { assets = getAssets(browseAssetIterableFactory.create( storageTx.getDb(), queryOptions.getLastId(), repository.getName(), bucketIds, queryOptions.getLimit())); } return new PageResult<>(queryOptions, assets); } }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @Override public PageResult<Asset> browseAssets(final Repository repository, final QueryOptions queryOptions) { checkNotNull(repository); final List<Repository> repositories = getRepositories(repository); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<String> bucketIds = getBucketIds(storageTx, repositories); List<Asset> assets = Collections.emptyList(); if (hasAssets(storageTx, repository, bucketIds, queryOptions)) { assets = getAssets(browseAssetIterableFactory.create( storageTx.getDb(), queryOptions.getLastId(), repository.getName(), bucketIds, queryOptions.getLimit())); } return new PageResult<>(queryOptions, assets); } } }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @Override public PageResult<Asset> browseAssets(final Repository repository, final QueryOptions queryOptions) { checkNotNull(repository); final List<Repository> repositories = getRepositories(repository); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<String> bucketIds = getBucketIds(storageTx, repositories); List<Asset> assets = Collections.emptyList(); if (hasAssets(storageTx, repository, bucketIds, queryOptions)) { assets = getAssets(browseAssetIterableFactory.create( storageTx.getDb(), queryOptions.getLastId(), repository.getName(), bucketIds, queryOptions.getLimit())); } return new PageResult<>(queryOptions, assets); } } @Inject  BrowseServiceImpl(@Named(GroupType.NAME) final Type groupType,
                           final ComponentEntityAdapter componentEntityAdapter,
                           final VariableResolverAdapterManager variableResolverAdapterManager,
                           final ContentPermissionChecker contentPermissionChecker,
                           final AssetEntityAdapter assetEntityAdapter,
                           final BrowseAssetIterableFactory browseAssetIterableFactory,
                           final BrowseAssetsSqlBuilder browseAssetsSqlBuilder,
                           final BrowseComponentsSqlBuilder browseComponentsSqlBuilder,
                           final BucketStore bucketStore,
                           final RepositoryManager repositoryManager); }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @Override public PageResult<Asset> browseAssets(final Repository repository, final QueryOptions queryOptions) { checkNotNull(repository); final List<Repository> repositories = getRepositories(repository); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<String> bucketIds = getBucketIds(storageTx, repositories); List<Asset> assets = Collections.emptyList(); if (hasAssets(storageTx, repository, bucketIds, queryOptions)) { assets = getAssets(browseAssetIterableFactory.create( storageTx.getDb(), queryOptions.getLastId(), repository.getName(), bucketIds, queryOptions.getLimit())); } return new PageResult<>(queryOptions, assets); } } @Inject  BrowseServiceImpl(@Named(GroupType.NAME) final Type groupType,
                           final ComponentEntityAdapter componentEntityAdapter,
                           final VariableResolverAdapterManager variableResolverAdapterManager,
                           final ContentPermissionChecker contentPermissionChecker,
                           final AssetEntityAdapter assetEntityAdapter,
                           final BrowseAssetIterableFactory browseAssetIterableFactory,
                           final BrowseAssetsSqlBuilder browseAssetsSqlBuilder,
                           final BrowseComponentsSqlBuilder browseComponentsSqlBuilder,
                           final BucketStore bucketStore,
                           final RepositoryManager repositoryManager); @Override PageResult<Component> browseComponents(final Repository repository,
                                                  final QueryOptions queryOptions); @Override PageResult<Asset> browseComponentAssets(final Repository repository, final String componentId); @Override PageResult<Asset> browseComponentAssets(final Repository repository, final Component component); @Override PageResult<Asset> browseAssets(final Repository repository,
                                          final QueryOptions queryOptions); @Override PageResult<Asset> previewAssets(final RepositorySelector repositorySelector,
                                           final List<Repository> repositories,
                                           final String jexlExpression,
                                           final QueryOptions queryOptions); @Override Asset getAssetById(final ORID assetId, final Repository repository); @Override Component getComponentById(final ORID componentId, final Repository repository); @Override Map<EntityId, String> getRepositoryBucketNames(final Repository repository); @Override Asset getAssetById(final EntityId assetId, final Repository repository); }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @Override public PageResult<Asset> browseAssets(final Repository repository, final QueryOptions queryOptions) { checkNotNull(repository); final List<Repository> repositories = getRepositories(repository); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<String> bucketIds = getBucketIds(storageTx, repositories); List<Asset> assets = Collections.emptyList(); if (hasAssets(storageTx, repository, bucketIds, queryOptions)) { assets = getAssets(browseAssetIterableFactory.create( storageTx.getDb(), queryOptions.getLastId(), repository.getName(), bucketIds, queryOptions.getLimit())); } return new PageResult<>(queryOptions, assets); } } @Inject  BrowseServiceImpl(@Named(GroupType.NAME) final Type groupType,
                           final ComponentEntityAdapter componentEntityAdapter,
                           final VariableResolverAdapterManager variableResolverAdapterManager,
                           final ContentPermissionChecker contentPermissionChecker,
                           final AssetEntityAdapter assetEntityAdapter,
                           final BrowseAssetIterableFactory browseAssetIterableFactory,
                           final BrowseAssetsSqlBuilder browseAssetsSqlBuilder,
                           final BrowseComponentsSqlBuilder browseComponentsSqlBuilder,
                           final BucketStore bucketStore,
                           final RepositoryManager repositoryManager); @Override PageResult<Component> browseComponents(final Repository repository,
                                                  final QueryOptions queryOptions); @Override PageResult<Asset> browseComponentAssets(final Repository repository, final String componentId); @Override PageResult<Asset> browseComponentAssets(final Repository repository, final Component component); @Override PageResult<Asset> browseAssets(final Repository repository,
                                          final QueryOptions queryOptions); @Override PageResult<Asset> previewAssets(final RepositorySelector repositorySelector,
                                           final List<Repository> repositories,
                                           final String jexlExpression,
                                           final QueryOptions queryOptions); @Override Asset getAssetById(final ORID assetId, final Repository repository); @Override Component getComponentById(final ORID componentId, final Repository repository); @Override Map<EntityId, String> getRepositoryBucketNames(final Repository repository); @Override Asset getAssetById(final EntityId assetId, final Repository repository);  }