use of org.springframework.data.domain.Pageable in project kylo by Teradata.
the class CommonFilterTranslations method resolveSortFilters.
/**
* Update the Pageable sort filter and resolve any filter strings if needed
*/
public static Pageable resolveSortFilters(EntityPathBase base, Pageable pageable) {
if (pageable != null && pageable.getSort() != null) {
List<Sort.Order> sortList = Lists.newArrayList(pageable.getSort().iterator());
boolean anyMatch = sortList.stream().anyMatch(order -> containsFilterMappings(base, order.getProperty()));
// if there is a match reconstruct pageable
if (anyMatch) {
List<Sort.Order> updatedSortOrder = sortList.stream().map(order -> new Sort.Order(order.getDirection(), resolvedFilter(base, order.getProperty()))).collect(Collectors.toList());
Sort sort = new Sort(updatedSortOrder);
Pageable updatedPageable = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), sort);
return updatedPageable;
}
}
return pageable;
}
use of org.springframework.data.domain.Pageable in project kylo by Teradata.
the class JpaBatchJobExecutionProviderTest method findAll_NoMatchingGroupAclEntry.
@WithMockJaasUser(username = "dladmin", password = "secret", authorities = { "admin", "user" })
@Test
public void findAll_NoMatchingGroupAclEntry() throws Exception {
Pageable pageable = new PageRequest(0, 5);
Page<? extends BatchJobExecution> all = repo.findAll(null, pageable);
}
use of org.springframework.data.domain.Pageable in project kylo by Teradata.
the class HiveMetastoreService method listTables.
@Nonnull
public List<JdbcTable> listTables(@Nullable final String catalog, @Nullable final String schema, @Nullable final String pattern, @Nullable final Pageable pageable) {
String query = "SELECT d.NAME as \"DATABASE_NAME\", t.TBL_NAME, t.TBL_TYPE, p.PARAM_VALUE" + " FROM TBLS t" + " JOIN DBS d on d.DB_ID = t.DB_ID" + " LEFT JOIN TABLE_PARAMS p on p.TBL_ID = t.TBL_ID AND p.PARAM_KEY = \"comment\"" + " WHERE d.NAME LIKE ? " + " AND t.TBL_NAME LIKE ? " + " ORDER BY \"DATABASE_NAME\", t.TBL_NAME";
if (DatabaseType.POSTGRES.equals(getMetastoreDatabaseType())) {
query = "SELECT d.\"NAME\" as \"DATABASE_NAME\", t.\"TBL_NAME\", t.\"TBL_TYPE\", p.\"PARAM_VALUE\"" + " FROM \"TBLS\" t" + " JOIN \"DBS\" d on d.\"DB_ID\" = t.\"DB_ID\" " + " LEFT JOIN \"TABLE_PARAMS\" p ON p.\"TBL_ID\" = t.\"TBL_ID\" and p.\"PARAM_KEY\" = 'comment'" + " WHERE d.\"NAME\" LIKE ? " + " AND t.\"TBL_NAME\" LIKE ? " + " ORDER BY d.\"NAME\", t.\"TBL_NAME\"";
}
final List<JdbcTable> tables = hiveMetatoreJdbcTemplate.query(query, ps -> {
ps.setString(1, schema == null ? "%" : schema);
ps.setString(2, pattern == null ? "%" : "%" + pattern + "%");
}, (rs, i) -> {
final DefaultJdbcTable jdbcTable = new DefaultJdbcTable(rs.getString("TBL_NAME"), rs.getString("TBL_TYPE"));
jdbcTable.setIdentifierQuoteString("`");
jdbcTable.setRemarks(rs.getString("PARAM_VALUE"));
jdbcTable.setSchema(rs.getString("DATABASE_NAME"));
return jdbcTable;
});
if (userImpersonationEnabled) {
return tables.stream().filter(jdbcTable -> hiveService.isTableAccessibleByImpersonatedUser(jdbcTable.getSchema() + "." + jdbcTable.getName())).collect(Collectors.toList());
} else {
return tables;
}
}
use of org.springframework.data.domain.Pageable in project kylo by Teradata.
the class DataSourceProvider method findAllDataSources.
/**
* Gets the list of available connectors.
*/
@Nonnull
public Page<DataSource> findAllDataSources(@Nonnull final Pageable pageable, @Nullable final String filter) {
// Filter catalog data sources
final Supplier<Stream<DataSource>> catalogDataSources = () -> metadataService.read(() -> metadataProvider.findAll().stream().map(modelTransform.dataSourceToRestModel()));
// Filter feed data sources
final DatasourceCriteria feedDataSourcesCriteria = feedDataSourceProvider.datasetCriteria().type(UserDatasource.class);
final Supplier<Stream<DataSource>> feedDataSources = () -> feedDataSourceProvider.getDatasources(feedDataSourcesCriteria).stream().filter(containsIgnoreCase(Datasource::getName, filter)).map(datasource -> toDataSource(datasource, DatasourceModelTransform.Level.BASIC)).filter(Objects::nonNull);
// Sort and paginate
final List<DataSource> filteredDataSources = Stream.concat(catalogDataSources.get(), feedDataSources.get()).sorted(Comparator.comparing(DataSource::getTitle)).skip(pageable.getOffset()).limit(pageable.getPageSize()).peek(findConnector()).collect(Collectors.toList());
return new PageImpl<>(filteredDataSources, pageable, catalogDataSources.get().count() + feedDataSources.get().count());
}
use of org.springframework.data.domain.Pageable in project mica2 by obiba.
the class FileIndexer method reIndexAll.
@Async
@Subscribe
public void reIndexAll(IndexFilesEvent event) {
if (indexer.hasIndex(Indexer.ATTACHMENT_DRAFT_INDEX))
indexer.dropIndex(Indexer.ATTACHMENT_DRAFT_INDEX);
if (indexer.hasIndex(Indexer.ATTACHMENT_PUBLISHED_INDEX))
indexer.dropIndex(Indexer.ATTACHMENT_PUBLISHED_INDEX);
Pageable pageRequest = new PageRequest(0, 100);
Page<AttachmentState> attachments;
do {
attachments = attachmentStateRepository.findAll(pageRequest);
attachments.forEach(a -> {
if (FileUtils.isDirectory(a))
return;
indexer.index(Indexer.ATTACHMENT_DRAFT_INDEX, a);
if (a.getPublishedAttachment() != null) {
indexer.index(Indexer.ATTACHMENT_PUBLISHED_INDEX, a);
}
});
} while ((pageRequest = attachments.nextPageable()) != null);
}
Aggregations