use of org.adempiere.ad.dao.IQueryFilter in project metasfresh-webui-api by metasfresh.
the class ADProcessPostProcessService method extractReferencingDocumentPaths.
private static final Set<DocumentPath> extractReferencingDocumentPaths(final ProcessInfo processInfo) {
final String tableName = processInfo.getTableNameOrNull();
if (tableName == null) {
return ImmutableSet.of();
}
final TableRecordReference sourceRecordRef = processInfo.getRecordRefOrNull();
final IQueryFilter<Object> selectionQueryFilter = processInfo.getQueryFilterOrElse(null);
if (selectionQueryFilter != null) {
final List<Integer> recordIds = Services.get(IQueryBL.class).createQueryBuilder(tableName, PlainContextAware.newWithThreadInheritedTrx()).filter(selectionQueryFilter).setLimit(MAX_REFERENCED_DOCUMENTPATHS_ALLOWED + 1).create().listIds();
if (recordIds.isEmpty()) {
return ImmutableSet.of();
} else if (recordIds.size() > MAX_REFERENCED_DOCUMENTPATHS_ALLOWED) {
throw new AdempiereException("Selecting more than " + MAX_REFERENCED_DOCUMENTPATHS_ALLOWED + " records is not allowed");
}
final TableRecordReference firstRecordRef = TableRecordReference.of(tableName, recordIds.get(0));
// assume all records are from same window
final WindowId windowId = WindowId.of(RecordZoomWindowFinder.findAD_Window_ID(firstRecordRef));
return recordIds.stream().map(recordId -> DocumentPath.rootDocumentPath(windowId, recordId)).collect(ImmutableSet.toImmutableSet());
} else if (sourceRecordRef != null) {
final WindowId windowId = WindowId.of(RecordZoomWindowFinder.findAD_Window_ID(sourceRecordRef));
final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, sourceRecordRef.getRecord_ID());
return ImmutableSet.of(documentPath);
} else {
return ImmutableSet.of();
}
}
Aggregations