Search in sources :

Example 11 with TableRecordReference

use of org.adempiere.util.lang.impl.TableRecordReference in project metasfresh-webui-api by metasfresh.

the class ViewAsPreconditionsContext method getSingleSelectedRecordId.

@Override
public int getSingleSelectedRecordId() {
    final DocumentId rowId = getSelectedRowIds().getSingleDocumentId();
    final TableRecordReference recordRef = view.getTableRecordReferenceOrNull(rowId);
    if (recordRef == null) {
        throw new AdempiereException("Cannot extract Record_ID from single selected rowId: " + rowId);
    }
    return recordRef.getRecord_ID();
}
Also used : TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 12 with TableRecordReference

use of org.adempiere.util.lang.impl.TableRecordReference in project metasfresh-webui-api by metasfresh.

the class ADProcessInstancesRepository method createProcessInfo.

private ProcessInfo createProcessInfo(@NonNull final CreateProcessInstanceRequest request) {
    final DocumentPath singleDocumentPath = request.getSingleDocumentPath();
    final String tableName;
    final int recordId;
    final String sqlWhereClause;
    final int adWindowId;
    // View
    if (request.getViewRowIdsSelection() != null) {
        final ViewRowIdsSelection viewRowIdsSelection = request.getViewRowIdsSelection();
        final ViewId viewId = viewRowIdsSelection.getViewId();
        final IView view = viewsRepo.getView(viewId);
        final DocumentIdsSelection viewDocumentIds = viewRowIdsSelection.getRowIds();
        adWindowId = viewId.getWindowId().toIntOr(-1);
        if (viewDocumentIds.isSingleDocumentId()) {
            final DocumentId viewSingleDocumentId = viewDocumentIds.getSingleDocumentId();
            final TableRecordReference recordRef = view.getTableRecordReferenceOrNull(viewSingleDocumentId);
            if (recordRef != null) {
                tableName = recordRef.getTableName();
                recordId = recordRef.getRecord_ID();
            } else {
                tableName = view.getTableNameOrNull(viewSingleDocumentId);
                recordId = -1;
            }
        } else {
            tableName = view.getTableNameOrNull(null);
            recordId = -1;
        }
        final boolean emptyTableName = Check.isEmpty(tableName);
        if (viewDocumentIds.isEmpty() || emptyTableName) {
            // Note: in the case of material cockpit, there is no single tableName to be returned by view.getTableNameOrNull,
            // so we do have selected rows, but no table name, which is OK
            sqlWhereClause = null;
        } else {
            sqlWhereClause = view.getSqlWhereClause(viewDocumentIds, SqlOptions.usingTableName(tableName));
        }
    } else // Single document call
    if (singleDocumentPath != null) {
        final DocumentEntityDescriptor entityDescriptor = documentDescriptorFactory.getDocumentEntityDescriptor(singleDocumentPath);
        adWindowId = singleDocumentPath.getWindowId().toIntOr(-1);
        tableName = entityDescriptor.getTableNameOrNull();
        if (singleDocumentPath.isRootDocument()) {
            recordId = singleDocumentPath.getDocumentId().toInt();
        } else {
            recordId = singleDocumentPath.getSingleRowId().toInt();
        }
        sqlWhereClause = entityDescriptor.getDataBinding(SqlDocumentEntityDataBindingDescriptor.class).getSqlWhereClauseById(recordId);
    } else // 
    // From menu
    {
        tableName = null;
        recordId = -1;
        sqlWhereClause = null;
        adWindowId = -1;
    }
    // 
    final Set<TableRecordReference> selectedIncludedRecords = request.getSelectedIncludedDocumentPaths().stream().map(documentDescriptorFactory::getTableRecordReference).collect(ImmutableSet.toImmutableSet());
    final ProcessInfoBuilder processInfoBuilder = ProcessInfo.builder().setCtx(Env.getCtx()).setCreateTemporaryCtx().setAD_Process_ID(request.getProcessIdAsInt()).setAD_Window_ID(adWindowId).setRecord(tableName, recordId).setSelectedIncludedRecords(selectedIncludedRecords).setWhereClause(sqlWhereClause);
    // View related internal parameters
    if (request.getViewRowIdsSelection() != null) {
        final ViewRowIdsSelection viewRowIdsSelection = request.getViewRowIdsSelection();
        processInfoBuilder.setLoadParametersFromDB(// important: we need to load the existing parameters from database, besides the internal ones we are adding here
        true).addParameter(ViewBasedProcessTemplate.PARAM_ViewId, viewRowIdsSelection.getViewId().toJson()).addParameter(ViewBasedProcessTemplate.PARAM_ViewSelectedIds, viewRowIdsSelection.getRowIds().toCommaSeparatedString());
    }
    if (request.getParentViewRowIdsSelection() != null) {
        final ViewRowIdsSelection parentViewRowIdsSelection = request.getParentViewRowIdsSelection();
        processInfoBuilder.setLoadParametersFromDB(// important: we need to load the existing parameters from database, besides the internal ones we are adding here
        true).addParameter(ViewBasedProcessTemplate.PARAM_ParentViewId, parentViewRowIdsSelection.getViewId().toJson()).addParameter(ViewBasedProcessTemplate.PARAM_ParentViewSelectedIds, parentViewRowIdsSelection.getRowIds().toCommaSeparatedString());
    }
    if (request.getChildViewRowIdsSelection() != null) {
        final ViewRowIdsSelection childViewRowIdsSelection = request.getChildViewRowIdsSelection();
        processInfoBuilder.setLoadParametersFromDB(// important: we need to load the existing parameters from database, besides the internal ones we are adding here
        true).addParameter(ViewBasedProcessTemplate.PARAM_ChildViewId, childViewRowIdsSelection.getViewId().toJson()).addParameter(ViewBasedProcessTemplate.PARAM_ChildViewSelectedIds, childViewRowIdsSelection.getRowIds().toCommaSeparatedString());
    }
    return processInfoBuilder.build();
}
Also used : IView(de.metas.ui.web.view.IView) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ViewRowIdsSelection(de.metas.ui.web.view.ViewRowIdsSelection) ViewId(de.metas.ui.web.view.ViewId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) ProcessInfoBuilder(de.metas.process.ProcessInfo.ProcessInfoBuilder) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 13 with TableRecordReference

use of org.adempiere.util.lang.impl.TableRecordReference in project metasfresh-webui-api by metasfresh.

the class WEBUI_Picking_Launcher method doIt.

@Override
protected String doIt() throws Exception {
    // repeat the verification from checkPreconditionsApplicable() just to be sure.
    // We had cases where the selected rows of checkPreconditionsApplicable() were not the selected rows of doIt()
    final ProcessPreconditionsResolution verifySelectedDocuments = verifySelectedDocuments();
    if (verifySelectedDocuments.isRejected()) {
        throw new AdempiereException(verifySelectedDocuments().getRejectReason().translate(Env.getAD_Language(getCtx())));
    }
    final DocumentIdsSelection selectedRowIds = getSelectedRootDocumentIds();
    final List<TableRecordReference> records = getView().streamByIds(selectedRowIds).flatMap(selectedRow -> selectedRow.getIncludedRows().stream()).map(IViewRow::getId).map(DocumentId::removeDocumentPrefixAndConvertToInt).map(recordId -> TableRecordReference.of(I_M_Packageable_V.Table_Name, recordId)).collect(ImmutableList.toImmutableList());
    if (records.isEmpty()) {
        throw new AdempiereException("@NoSelection@");
    }
    getResult().setRecordsToOpen(records, PickingConstants.WINDOWID_PickingView.toInt());
    return MSG_OK;
}
Also used : ViewBasedProcessTemplate(de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate) NonNull(lombok.NonNull) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) PickingConstants(de.metas.ui.web.picking.PickingConstants) Set(java.util.Set) Env(org.compiere.util.Env) Collectors(java.util.stream.Collectors) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) MSG_WEBUI_PICKING_DIVERGING_LOCATIONS(de.metas.ui.web.picking.PickingConstants.MSG_WEBUI_PICKING_DIVERGING_LOCATIONS) I_M_Packageable_V(de.metas.inoutcandidate.model.I_M_Packageable_V) List(java.util.List) IViewRow(de.metas.ui.web.view.IViewRow) ImmutableList(com.google.common.collect.ImmutableList) AdempiereException(org.adempiere.exceptions.AdempiereException) MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P(de.metas.ui.web.picking.PickingConstants.MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) IProcessPrecondition(de.metas.process.IProcessPrecondition) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 14 with TableRecordReference

use of org.adempiere.util.lang.impl.TableRecordReference in project metasfresh-webui-api by metasfresh.

the class ADProcessPostProcessService method extractSingleDocumentPath.

private static final DocumentPath extractSingleDocumentPath(final RecordsToOpen recordsToOpen) {
    final TableRecordReference recordRef = recordsToOpen.getSingleRecord();
    final int documentId = recordRef.getRecord_ID();
    WindowId windowId = WindowId.fromNullableJson(recordsToOpen.getWindowIdString());
    if (windowId == null) {
        windowId = WindowId.ofIntOrNull(RecordZoomWindowFinder.findAD_Window_ID(recordRef));
    }
    return DocumentPath.rootDocumentPath(windowId, documentId);
}
Also used : TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) WindowId(de.metas.ui.web.window.datatypes.WindowId)

Example 15 with TableRecordReference

use of org.adempiere.util.lang.impl.TableRecordReference 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

TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)19 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)6 WindowId (de.metas.ui.web.window.datatypes.WindowId)5 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)4 IView (de.metas.ui.web.view.IView)3 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 ProcessExecutionResult (de.metas.process.ProcessExecutionResult)2 ViewId (de.metas.ui.web.view.ViewId)2 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 List (java.util.List)2 Set (java.util.Set)2 NonNull (lombok.NonNull)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Suppliers (com.google.common.base.Suppliers)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 I_C_Order (de.metas.adempiere.model.I_C_Order)1 Event (de.metas.event.Event)1