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();
}
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;
}
Aggregations