Search in sources :

Example 1 with ProcessInstanceResult

use of de.metas.ui.web.process.ProcessInstanceResult in project metasfresh-webui-api by metasfresh.

the class ViewActionInstance method startProcess.

@Override
public ProcessInstanceResult startProcess(@NonNull final ProcessExecutionContext context) {
    assertNotExecuted();
    // Validate parameters, if any
    if (parametersDocument != null) {
        final DocumentValidStatus validStatus = parametersDocument.checkAndGetValidStatus();
        if (!validStatus.isValid()) {
            throw new AdempiereException(validStatus.getReason());
        }
    }
    // 
    // Execute view action's method
    final IView view = getView();
    final Method viewActionMethod = viewActionDescriptor.getViewActionMethod();
    final Object[] viewActionParams = viewActionDescriptor.extractMethodArguments(view, parametersDocument, selectedDocumentIds);
    try {
        final Object targetObject = Modifier.isStatic(viewActionMethod.getModifiers()) ? null : view;
        final Object resultActionObj = viewActionMethod.invoke(targetObject, viewActionParams);
        final ResultAction resultAction = viewActionDescriptor.convertReturnType(resultActionObj);
        final ResultAction resultActionProcessed = processResultAction(resultAction, context.getViewsRepo());
        final ProcessInstanceResult result = ProcessInstanceResult.builder(pinstanceId).action(resultActionProcessed).build();
        this.result = result;
        return result;
    } catch (final Throwable ex) {
        throw AdempiereException.wrapIfNeeded(ex);
    }
}
Also used : IView(de.metas.ui.web.view.IView) AdempiereException(org.adempiere.exceptions.AdempiereException) ProcessInstanceResult(de.metas.ui.web.process.ProcessInstanceResult) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) Method(java.lang.reflect.Method) ResultAction(de.metas.ui.web.process.ProcessInstanceResult.ResultAction)

Example 2 with ProcessInstanceResult

use of de.metas.ui.web.process.ProcessInstanceResult in project metasfresh-webui-api by metasfresh.

the class HUReportProcessInstance method startProcess.

@Override
public synchronized ProcessInstanceResult startProcess(@NonNull final ProcessExecutionContext context) {
    final int numberOfCopies = getCopies();
    if (numberOfCopies <= 0) {
        throw new AdempiereException("@" + PARAM_Copies + "@ > 0");
    }
    final IViewsRepository viewsRepo = context.getViewsRepo();
    final DocumentCollection documentsCollection = context.getDocumentsCollection();
    final ViewId viewId = viewRowIdsSelection.getViewId();
    final HUEditorView view = HUEditorView.cast(viewsRepo.getView(viewId));
    final HUReportExecutorResult reportExecutorResult = HUReportExecutor.newInstance(context.getCtx()).numberOfCopies(numberOfCopies).printPreview(true).executeNow(reportADProcessId, extractHUsToReport(view));
    final ADProcessPostProcessService postProcessService = ADProcessPostProcessService.builder().viewsRepo(viewsRepo).documentsCollection(documentsCollection).build();
    final ProcessInstanceResult result = postProcessService.postProcess(ADProcessPostProcessRequest.builder().viewId(viewId).processInfo(reportExecutorResult.getProcessInfo()).processExecutionResult(reportExecutorResult.getProcessExecutionResult()).instanceIdOverride(instanceId).build());
    return lastExecutionResult = result;
}
Also used : ADProcessPostProcessService(de.metas.ui.web.process.adprocess.ADProcessPostProcessService) AdempiereException(org.adempiere.exceptions.AdempiereException) ProcessInstanceResult(de.metas.ui.web.process.ProcessInstanceResult) ViewId(de.metas.ui.web.view.ViewId) HUReportExecutorResult(de.metas.handlingunits.report.HUReportExecutorResult) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) IViewsRepository(de.metas.ui.web.view.IViewsRepository)

Aggregations

ProcessInstanceResult (de.metas.ui.web.process.ProcessInstanceResult)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 HUReportExecutorResult (de.metas.handlingunits.report.HUReportExecutorResult)1 HUEditorView (de.metas.ui.web.handlingunits.HUEditorView)1 ResultAction (de.metas.ui.web.process.ProcessInstanceResult.ResultAction)1 ADProcessPostProcessService (de.metas.ui.web.process.adprocess.ADProcessPostProcessService)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 DocumentCollection (de.metas.ui.web.window.model.DocumentCollection)1 DocumentValidStatus (de.metas.ui.web.window.model.DocumentValidStatus)1 Method (java.lang.reflect.Method)1