Search in sources :

Example 1 with ProcessPreconditionsResolution

use of de.metas.process.ProcessPreconditionsResolution in project metasfresh-webui-api by metasfresh.

the class WEBUI_M_HU_Receipt_Base method checkPreconditionsApplicable.

@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable() {
    if (!isViewClass(HUEditorView.class)) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("The current view is not an HUEditorView");
    }
    final DocumentIdsSelection selectedRowIds = getSelectedRowIds();
    if (selectedRowIds.isEmpty()) {
        return ProcessPreconditionsResolution.rejectBecauseNoSelection();
    }
    final MutableInt checkedDocumentsCount = new MutableInt(0);
    final ProcessPreconditionsResolution firstRejection = getView(HUEditorView.class).streamByIds(selectedRowIds).filter(document -> document.isPureHU()).peek(// count checked documents
    document -> checkedDocumentsCount.incrementAndGet()).map(// create reject resolution if any
    document -> rejectResolutionOrNull(document)).filter(// filter out those which are not errors
    resolution -> resolution != null).findFirst().orElse(null);
    if (firstRejection != null) {
        // found a record which is not eligible => don't run the process
        return firstRejection;
    }
    if (checkedDocumentsCount.getValue() <= 0) {
        return ProcessPreconditionsResolution.rejectWithInternalReason("no eligible rows");
    }
    return ProcessPreconditionsResolution.accept();
}
Also used : MutableInt(org.adempiere.util.lang.MutableInt) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow) ViewBasedProcessTemplate(de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView) IProcessPrecondition(de.metas.process.IProcessPrecondition) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) MutableInt(org.adempiere.util.lang.MutableInt) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView)

Example 2 with ProcessPreconditionsResolution

use of de.metas.process.ProcessPreconditionsResolution 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)

Aggregations

IProcessPrecondition (de.metas.process.IProcessPrecondition)2 ProcessPreconditionsResolution (de.metas.process.ProcessPreconditionsResolution)2 ViewBasedProcessTemplate (de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate)2 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)2 ImmutableList (com.google.common.collect.ImmutableList)1 I_M_Packageable_V (de.metas.inoutcandidate.model.I_M_Packageable_V)1 HUEditorRow (de.metas.ui.web.handlingunits.HUEditorRow)1 HUEditorView (de.metas.ui.web.handlingunits.HUEditorView)1 PickingConstants (de.metas.ui.web.picking.PickingConstants)1 MSG_WEBUI_PICKING_DIVERGING_LOCATIONS (de.metas.ui.web.picking.PickingConstants.MSG_WEBUI_PICKING_DIVERGING_LOCATIONS)1 MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P (de.metas.ui.web.picking.PickingConstants.MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P)1 IViewRow (de.metas.ui.web.view.IViewRow)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 JSONLookupValue (de.metas.ui.web.window.datatypes.json.JSONLookupValue)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 NonNull (lombok.NonNull)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 MutableInt (org.adempiere.util.lang.MutableInt)1