Search in sources :

Example 16 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.

the class HUEditorViewBuffer_FullyCached method getSqlWhereClause.

@Override
public String getSqlWhereClause(final DocumentIdsSelection rowIds) {
    final DocumentIdsSelection rowIdsEffective = getRows().streamByIdsExcludingIncludedRows(HUEditorRowFilter.onlyRowIds(rowIds)).map(HUEditorRow::getId).collect(DocumentIdsSelection.toDocumentIdsSelection());
    final Set<Integer> huIds = huEditorRepo.getRowIdsConverter().convertToRecordIds(rowIdsEffective);
    // NOTE: accept it even if is empty. In case it's empty, we will return something like M_HU_ID in (-1)
    // same this is happening for the others HUEditorViewBuffer implementation
    // see https://github.com/metasfresh/metasfresh-webui-api/issues/764
    final String sqlKeyColumnNameFK = I_M_HU.Table_Name + "." + I_M_HU.COLUMNNAME_M_HU_ID;
    return sqlKeyColumnNameFK + " IN " + DB.buildSqlList(huIds);
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection)

Example 17 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.

the class HUEditorViewBuffer_HighVolume method removeHUIds.

@Override
public boolean removeHUIds(final Collection<Integer> huIdsToRemove) {
    if (huIdsToRemove == null || huIdsToRemove.isEmpty()) {
        return false;
    }
    final DocumentIdsSelection rowIdsToRemove = HUEditorRowId.rowIdsFromTopLevelM_HU_IDs(huIdsToRemove);
    rowIdsToRemove.forEach(rowId -> cache_huRowsById.remove(rowId));
    return changeSelection(defaultSelection -> huEditorRepo.removeRowIdsFromSelection(defaultSelection, rowIdsToRemove));
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection)

Example 18 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection 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 19 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection 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 20 with DocumentIdsSelection

use of de.metas.ui.web.window.datatypes.DocumentIdsSelection in project metasfresh-webui-api by metasfresh.

the class ViewBasedProcessTemplate method getSingleSelectedRow.

@OverridingMethodsMustInvokeSuper
protected IViewRow getSingleSelectedRow() {
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    final DocumentId documentId = selectedRowIds.getSingleDocumentId();
    return getView().getById(documentId);
}
Also used : DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper)

Aggregations

DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)25 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)8 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)6 IProcessPrecondition (de.metas.process.IProcessPrecondition)5 ProcessPreconditionsResolution (de.metas.process.ProcessPreconditionsResolution)5 List (java.util.List)5 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)5 ImmutableList (com.google.common.collect.ImmutableList)4 HUEditorView (de.metas.ui.web.handlingunits.HUEditorView)4 IView (de.metas.ui.web.view.IView)4 AdempiereException (org.adempiere.exceptions.AdempiereException)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ViewBasedProcessTemplate (de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate)3 Collection (java.util.Collection)3 Set (java.util.Set)3 NonNull (lombok.NonNull)3 Services (org.adempiere.util.Services)3 IHandlingUnitsBL (de.metas.handlingunits.IHandlingUnitsBL)2 I_M_HU (de.metas.handlingunits.model.I_M_HU)2 Param (de.metas.process.Param)2