@Test public void testPreviewAssetsWithSingleGroupRepository() { Repository groupRepositoryLeafMember = mock(Repository.class); when(groupRepositoryLeafMember.getType()).thenReturn(new HostedType()); when(groupRepositoryLeafMember.getName()).thenReturn("group-repository-leaf-member"); when(groupRepositoryLeafMember.optionalFacet(GroupFacet.class)).thenReturn(Optional.empty()); Repository groupRepository = mock(Repository.class); when(groupRepository.getType()).thenReturn(new GroupType()); when(groupRepository.getName()).thenReturn("group-repository"); when(groupRepository.facet(StorageFacet.class)).thenReturn(storageFacet); when(groupRepository.facet(GroupFacet.class)).thenReturn(groupFacet); when(groupRepository.optionalFacet(GroupFacet.class)).thenReturn(Optional.of(groupFacet)); List<Repository> groupRepositoryLeafMembers = asList(groupRepositoryLeafMember); when(groupFacet.leafMembers()).thenReturn(groupRepositoryLeafMembers); List<Repository> repositories = asList(groupRepository); Map<String, List<String>> expectedRepoToContainedGroupMap = new HashMap<>(); expectedRepoToContainedGroupMap.put("group-repository", asList("group-repository")); Map<String, Object> expectedQueryParams = new HashMap<>(); expectedQueryParams.put("repositorySelector", "toSelectorResult"); expectedQueryParams.put("jexlExpression", "myExpression"); expectedQueryParams.put("repoToContainedGroupMap", expectedRepoToContainedGroupMap); String expectedCountQuerySuffix = "and (contentExpression(@this, :jexlExpression, :repositorySelector, :repoToContainedGroupMap) == true)"; String expectedFindQuerySuffix = "and (contentExpression(@this, :jexlExpression, :repositorySelector, :repoToContainedGroupMap) == true) " + "SKIP 0 LIMIT 0"; when(repositorySelector.toSelector()).thenReturn("toSelectorResult"); when(storageTx.countAssets(NO_WHERE, expectedQueryParams, groupRepositoryLeafMembers, expectedCountQuerySuffix)) .thenReturn(57L); when(storageTx.findAssets(NO_WHERE, expectedQueryParams, groupRepositoryLeafMembers, expectedFindQuerySuffix)) .thenReturn(results); PageResult<Asset> browseResult = underTest.previewAssets(repositorySelector, repositories, "myExpression", queryOptions); assertThat(browseResult.getTotal(), is(57L)); assertThat(browseResult.getResults(), is(results)); }
@Override public PageResult<Asset> previewAssets(final RepositorySelector repositorySelector, final List<Repository> repositories, final String jexlExpression, final QueryOptions queryOptions) { checkNotNull(repositories); checkNotNull(jexlExpression); final Repository repository = repositories.get(0); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<Repository> previewRepositories; if (repositories.size() == 1 && groupType.equals(repository.getType())) { previewRepositories = repository.facet(GroupFacet.class).leafMembers(); } else { previewRepositories = repositories; } PreviewAssetsSqlBuilder builder = new PreviewAssetsSqlBuilder( repositorySelector, jexlExpression, queryOptions, getRepoToContainedGroupMap(repositories)); String whereClause = String.format("and (%s)", builder.buildWhereClause()); return new PageResult<>( storageTx.countAssets(null, builder.buildSqlParams(), previewRepositories, whereClause), Lists.newArrayList(storageTx.findAssets(null, builder.buildSqlParams(), previewRepositories, whereClause + builder.buildQuerySuffix())) ); } }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @Override public PageResult<Asset> previewAssets(final RepositorySelector repositorySelector, final List<Repository> repositories, final String jexlExpression, final QueryOptions queryOptions) { checkNotNull(repositories); checkNotNull(jexlExpression); final Repository repository = repositories.get(0); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<Repository> previewRepositories; if (repositories.size() == 1 && groupType.equals(repository.getType())) { previewRepositories = repository.facet(GroupFacet.class).leafMembers(); } else { previewRepositories = repositories; } PreviewAssetsSqlBuilder builder = new PreviewAssetsSqlBuilder( repositorySelector, jexlExpression, queryOptions, getRepoToContainedGroupMap(repositories)); String whereClause = String.format("and (%s)", builder.buildWhereClause()); return new PageResult<>( storageTx.countAssets(null, builder.buildSqlParams(), previewRepositories, whereClause), Lists.newArrayList(storageTx.findAssets(null, builder.buildSqlParams(), previewRepositories, whereClause + builder.buildQuerySuffix())) ); } } }
BrowseServiceImpl extends ComponentSupport implements BrowseService { @Override public PageResult<Asset> previewAssets(final RepositorySelector repositorySelector, final List<Repository> repositories, final String jexlExpression, final QueryOptions queryOptions) { checkNotNull(repositories); checkNotNull(jexlExpression); final Repository repository = repositories.get(0); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<Repository> previewRepositories; if (repositories.size() == 1 && groupType.equals(repository.getType())) { previewRepositories = repository.facet(GroupFacet.class).leafMembers(); } else { previewRepositories = repositories; } PreviewAssetsSqlBuilder builder = new PreviewAssetsSqlBuilder( repositorySelector, jexlExpression, queryOptions, getRepoToContainedGroupMap(repositories)); String whereClause = String.format("and (%s)", builder.buildWhereClause()); return new PageResult<>( storageTx.countAssets(null, builder.buildSqlParams(), previewRepositories, whereClause), Lists.newArrayList(storageTx.findAssets(null, builder.buildSqlParams(), previewRepositories, whereClause + builder.buildQuerySuffix())) ); } } @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> previewAssets(final RepositorySelector repositorySelector, final List<Repository> repositories, final String jexlExpression, final QueryOptions queryOptions) { checkNotNull(repositories); checkNotNull(jexlExpression); final Repository repository = repositories.get(0); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<Repository> previewRepositories; if (repositories.size() == 1 && groupType.equals(repository.getType())) { previewRepositories = repository.facet(GroupFacet.class).leafMembers(); } else { previewRepositories = repositories; } PreviewAssetsSqlBuilder builder = new PreviewAssetsSqlBuilder( repositorySelector, jexlExpression, queryOptions, getRepoToContainedGroupMap(repositories)); String whereClause = String.format("and (%s)", builder.buildWhereClause()); return new PageResult<>( storageTx.countAssets(null, builder.buildSqlParams(), previewRepositories, whereClause), Lists.newArrayList(storageTx.findAssets(null, builder.buildSqlParams(), previewRepositories, whereClause + builder.buildQuerySuffix())) ); } } @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> previewAssets(final RepositorySelector repositorySelector, final List<Repository> repositories, final String jexlExpression, final QueryOptions queryOptions) { checkNotNull(repositories); checkNotNull(jexlExpression); final Repository repository = repositories.get(0); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<Repository> previewRepositories; if (repositories.size() == 1 && groupType.equals(repository.getType())) { previewRepositories = repository.facet(GroupFacet.class).leafMembers(); } else { previewRepositories = repositories; } PreviewAssetsSqlBuilder builder = new PreviewAssetsSqlBuilder( repositorySelector, jexlExpression, queryOptions, getRepoToContainedGroupMap(repositories)); String whereClause = String.format("and (%s)", builder.buildWhereClause()); return new PageResult<>( storageTx.countAssets(null, builder.buildSqlParams(), previewRepositories, whereClause), Lists.newArrayList(storageTx.findAssets(null, builder.buildSqlParams(), previewRepositories, whereClause + builder.buildQuerySuffix())) ); } } @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);  }