private List<Repository> getRepositories(final Repository repository) { checkNotNull(repository); if (groupType.equals(repository.getType())) { return repository.facet(GroupFacet.class).leafMembers(); } return ImmutableList.of(repository); }
@Override public BrowseResult<Component> browseComponents( final Repository repository, @Nullable final String filter, @Nullable final String sortProperty, @Nullable final String sortDirection, @Nullable final Integer start, @Nullable final Integer limit) { checkNotNull(repository); final List<Repository> repositories = getRepositories(repository); try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) { storageTx.begin(); List<Bucket> buckets = getBuckets(storageTx, repositories); QueryOptions options = new QueryOptions(filter, sortProperty, sortDirection, start, limit, repository.getName()); BrowseComponentsSqlBuilder builder = new BrowseComponentsSqlBuilder(groupType.equals(repository.getType()), buckets, options); return new BrowseResult<>( getCount(storageTx.browse(builder.buildCountSql(), builder.buildSqlParams())), getComponents(storageTx.browse(builder.buildBrowseSql(), builder.buildSqlParams()))); } }
@Override public BrowseResult<Asset> previewAssets( final List<Repository> repositories, final String jexlExpression, @Nullable final String filter, @Nullable final String sortProperty, @Nullable final String sortDirection, @Nullable final Integer start, @Nullable final Integer limit) { 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; } QueryOptions options = new QueryOptions(filter, sortProperty, sortDirection, start, limit, repository.getName()); PreviewAssetsSqlBuilder builder = new PreviewAssetsSqlBuilder( repository.getName(), jexlExpression, previewRepositories.stream().map(Repository::getName).collect(Collectors.toList()), options); return new BrowseResult<>( storageTx.countAssets( builder.buildWhereClause(), builder.buildSqlParams(), repositories, null), Lists.newArrayList( storageTx.findAssets( builder.buildWhereClause(), builder.buildSqlParams(), previewRepositories, builder.buildQuerySuffix()))); } }