Search in sources :

Example 1 with IQueryFilter

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();
    }
}
Also used : MimeType(org.compiere.util.MimeType) LogManager(de.metas.logging.LogManager) ProcessInfo(de.metas.process.ProcessInfo) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) OpenViewAction(de.metas.ui.web.process.ProcessInstanceResult.OpenViewAction) ProcessExecutionResult(de.metas.process.ProcessExecutionResult) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HashMap(java.util.HashMap) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) OpenReportAction(de.metas.ui.web.process.ProcessInstanceResult.OpenReportAction) Supplier(java.util.function.Supplier) IQueryFilter(org.adempiere.ad.dao.IQueryFilter) PlainContextAware(org.adempiere.model.PlainContextAware) OpenIncludedViewAction(de.metas.ui.web.process.ProcessInstanceResult.OpenIncludedViewAction) IView(de.metas.ui.web.view.IView) RecordsToOpen(de.metas.process.ProcessExecutionResult.RecordsToOpen) Map(java.util.Map) ResultAction(de.metas.ui.web.process.ProcessInstanceResult.ResultAction) Suppliers(com.google.common.base.Suppliers) ProcessInstanceResult(de.metas.ui.web.process.ProcessInstanceResult) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) Util(org.compiere.util.Util) RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) OpenTarget(de.metas.process.ProcessExecutionResult.RecordsToOpen.OpenTarget) OpenSingleDocument(de.metas.ui.web.process.ProcessInstanceResult.OpenSingleDocument) NonNull(lombok.NonNull) ViewProfileId(de.metas.ui.web.view.ViewProfileId) Set(java.util.Set) IOException(java.io.IOException) JavaProcess(de.metas.process.JavaProcess) WindowId(de.metas.ui.web.window.datatypes.WindowId) IQueryBL(org.adempiere.ad.dao.IQueryBL) File(java.io.File) Services(org.adempiere.util.Services) List(java.util.List) Builder(lombok.Builder) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(de.metas.printing.esb.base.util.Check) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest) IViewsRepository(de.metas.ui.web.view.IViewsRepository) ViewId(de.metas.ui.web.view.ViewId) IQueryBL(org.adempiere.ad.dao.IQueryBL) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) WindowId(de.metas.ui.web.window.datatypes.WindowId) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Aggregations

Suppliers (com.google.common.base.Suppliers)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 LogManager (de.metas.logging.LogManager)1 Check (de.metas.printing.esb.base.util.Check)1 JavaProcess (de.metas.process.JavaProcess)1 ProcessExecutionResult (de.metas.process.ProcessExecutionResult)1 RecordsToOpen (de.metas.process.ProcessExecutionResult.RecordsToOpen)1 OpenTarget (de.metas.process.ProcessExecutionResult.RecordsToOpen.OpenTarget)1 ProcessInfo (de.metas.process.ProcessInfo)1 ProcessInstanceResult (de.metas.ui.web.process.ProcessInstanceResult)1 OpenIncludedViewAction (de.metas.ui.web.process.ProcessInstanceResult.OpenIncludedViewAction)1 OpenReportAction (de.metas.ui.web.process.ProcessInstanceResult.OpenReportAction)1 OpenSingleDocument (de.metas.ui.web.process.ProcessInstanceResult.OpenSingleDocument)1 OpenViewAction (de.metas.ui.web.process.ProcessInstanceResult.OpenViewAction)1 ResultAction (de.metas.ui.web.process.ProcessInstanceResult.ResultAction)1 CreateViewRequest (de.metas.ui.web.view.CreateViewRequest)1 IView (de.metas.ui.web.view.IView)1 IViewsRepository (de.metas.ui.web.view.IViewsRepository)1 ViewId (de.metas.ui.web.view.ViewId)1 ViewProfileId (de.metas.ui.web.view.ViewProfileId)1