Search in sources :

Example 1 with ViewOpenTarget

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

the class ADProcessPostProcessService method createResultAction.

private ResultAction createResultAction(final ProcessInfo processInfo, final ProcessExecutionResult processExecutionResult) {
    final File reportTempFile = saveReportToDiskIfAny(processExecutionResult);
    final RecordsToOpen recordsToOpen = processExecutionResult.getRecordsToOpen();
    // Open report
    if (reportTempFile != null) {
        logger.debug("The processExecutionResult specifies reportTempFile={}", reportTempFile);
        return OpenReportAction.builder().filename(processExecutionResult.getReportFilename()).contentType(processExecutionResult.getReportContentType()).tempFile(reportTempFile).build();
    } else // Create & open view from Records
    if (recordsToOpen != null && recordsToOpen.getTarget() == OpenTarget.GridView) {
        logger.debug("The processExecutionResult specifies recordsToOpen={}", recordsToOpen);
        final Set<DocumentPath> referencingDocumentPaths = recordsToOpen.isAutomaticallySetReferencingDocumentPaths() ? extractReferencingDocumentPaths(processInfo) : null;
        final String parentViewIdStr = processExecutionResult.getWebuiViewId();
        final ViewId parentViewId = parentViewIdStr != null ? ViewId.ofViewIdString(parentViewIdStr) : null;
        final CreateViewRequest viewRequest = createViewRequest(recordsToOpen, referencingDocumentPaths, parentViewId);
        final IView view = viewsRepo.createView(viewRequest);
        return OpenViewAction.builder().viewId(view.getViewId()).build();
    } else // Open existing view
    if (processExecutionResult.getWebuiViewToOpen() != null) {
        final WebuiViewToOpen viewToOpen = processExecutionResult.getWebuiViewToOpen();
        logger.debug("The processExecutionResult specifies viewToOpen={}", viewToOpen);
        final ViewOpenTarget target = viewToOpen.getTarget();
        if (ViewOpenTarget.IncludedView.equals(target)) {
            return OpenIncludedViewAction.builder().viewId(ViewId.ofViewIdString(viewToOpen.getViewId())).profileId(ViewProfileId.fromJson(viewToOpen.getProfileId())).build();
        } else if (ViewOpenTarget.ModalOverlay.equals(target)) {
            return OpenViewAction.builder().viewId(ViewId.ofViewIdString(viewToOpen.getViewId())).profileId(ViewProfileId.fromJson(viewToOpen.getProfileId())).modalOverlay(true).build();
        } else if (ViewOpenTarget.NewBrowserTab.equals(target)) {
            return OpenViewAction.builder().viewId(ViewId.ofViewIdString(viewToOpen.getViewId())).profileId(ViewProfileId.fromJson(viewToOpen.getProfileId())).modalOverlay(false).build();
        } else {
            throw new AdempiereException("Unknown target: " + target);
        }
    } else // Open single document
    if (recordsToOpen != null && recordsToOpen.getTarget() == OpenTarget.SingleDocument) {
        final DocumentPath documentPath = extractSingleDocumentPath(recordsToOpen);
        return OpenSingleDocument.builder().documentPath(documentPath).modal(false).build();
    } else // Open single document
    if (recordsToOpen != null && recordsToOpen.getTarget() == OpenTarget.SingleDocumentModal) {
        final DocumentPath documentPath = extractSingleDocumentPath(recordsToOpen);
        return OpenSingleDocument.builder().documentPath(documentPath).modal(true).build();
    } else // Display QRCode to user
    if (processExecutionResult.getDisplayQRCode() != null) {
        return DisplayQRCodeAction.builder().code(processExecutionResult.getDisplayQRCode().getCode()).build();
    } else // 
    // No action
    {
        return null;
    }
}
Also used : TableRecordReferenceSet(org.adempiere.util.lang.impl.TableRecordReferenceSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) IView(de.metas.ui.web.view.IView) ViewOpenTarget(de.metas.process.ProcessExecutionResult.ViewOpenTarget) AdempiereException(org.adempiere.exceptions.AdempiereException) ViewId(de.metas.ui.web.view.ViewId) WebuiViewToOpen(de.metas.process.ProcessExecutionResult.WebuiViewToOpen) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) RecordsToOpen(de.metas.process.ProcessExecutionResult.RecordsToOpen) File(java.io.File) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 RecordsToOpen (de.metas.process.ProcessExecutionResult.RecordsToOpen)1 ViewOpenTarget (de.metas.process.ProcessExecutionResult.ViewOpenTarget)1 WebuiViewToOpen (de.metas.process.ProcessExecutionResult.WebuiViewToOpen)1 CreateViewRequest (de.metas.ui.web.view.CreateViewRequest)1 IView (de.metas.ui.web.view.IView)1 ViewId (de.metas.ui.web.view.ViewId)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 File (java.io.File)1 Set (java.util.Set)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 TableRecordReferenceSet (org.adempiere.util.lang.impl.TableRecordReferenceSet)1