Search in sources :

Example 1 with OpenReportAction

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

the class JSONProcessInstanceResult method toJSONResultAction.

/**
 * Converts {@link ResultAction} to JSON
 */
private static final JSONResultAction toJSONResultAction(final ResultAction resultAction) {
    if (resultAction == null) {
        return null;
    } else if (resultAction instanceof OpenReportAction) {
        final OpenReportAction openReportAction = (OpenReportAction) resultAction;
        return new JSONOpenReportAction(openReportAction.getFilename(), openReportAction.getContentType());
    } else if (resultAction instanceof OpenViewAction) {
        final OpenViewAction openViewAction = (OpenViewAction) resultAction;
        return new JSONOpenViewAction(openViewAction.getViewId());
    } else if (resultAction instanceof OpenIncludedViewAction) {
        final OpenIncludedViewAction openIncludedViewAction = (OpenIncludedViewAction) resultAction;
        return new JSONOpenIncludedViewAction(openIncludedViewAction.getViewId(), openIncludedViewAction.getProfileId());
    } else if (resultAction instanceof OpenSingleDocument) {
        final OpenSingleDocument openDocumentAction = (OpenSingleDocument) resultAction;
        final DocumentPath documentPath = openDocumentAction.getDocumentPath();
        return new JSONOpenSingleDocumentAction(documentPath.getWindowId(), documentPath.getDocumentId().toJson(), openDocumentAction.isModal());
    } else if (resultAction instanceof SelectViewRowsAction) {
        final SelectViewRowsAction selectViewRowsAction = (SelectViewRowsAction) resultAction;
        return new JSONSelectViewRowsAction(selectViewRowsAction.getViewId(), selectViewRowsAction.getRowIds());
    } else {
        logger.warn("Unknown result action: {}. Ignoring it.", resultAction);
        return null;
    }
}
Also used : OpenSingleDocument(de.metas.ui.web.process.ProcessInstanceResult.OpenSingleDocument) OpenIncludedViewAction(de.metas.ui.web.process.ProcessInstanceResult.OpenIncludedViewAction) OpenViewAction(de.metas.ui.web.process.ProcessInstanceResult.OpenViewAction) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) SelectViewRowsAction(de.metas.ui.web.process.ProcessInstanceResult.SelectViewRowsAction) OpenReportAction(de.metas.ui.web.process.ProcessInstanceResult.OpenReportAction)

Example 2 with OpenReportAction

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

the class ProcessRestController method getReport.

@RequestMapping(value = "/{processId}/{pinstanceId}/print/{filename:.*}", method = RequestMethod.GET)
public ResponseEntity<byte[]> getReport(// 
@PathVariable("processId") final String processIdStr, // 
@PathVariable("pinstanceId") final String pinstanceIdStr, // 
@PathVariable("filename") final String filename) {
    userSession.assertLoggedIn();
    final ProcessId processId = ProcessId.fromJson(processIdStr);
    final DocumentId pinstanceId = DocumentId.of(pinstanceIdStr);
    final IProcessInstancesRepository instancesRepository = getRepository(processId);
    final ProcessInstanceResult executionResult = instancesRepository.forProcessInstanceReadonly(pinstanceId, processInstance -> processInstance.getExecutionResult());
    final OpenReportAction action = executionResult.getAction(OpenReportAction.class);
    final String reportFilename = action.getFilename();
    final String reportContentType = action.getContentType();
    final byte[] reportData = action.getReportData();
    final String reportFilenameEffective = Util.coalesce(filename, reportFilename, "");
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType(reportContentType));
    headers.set(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + reportFilenameEffective + "\"");
    headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
    final ResponseEntity<byte[]> response = new ResponseEntity<>(reportData, headers, HttpStatus.OK);
    return response;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) JSONProcessInstanceResult(de.metas.ui.web.process.json.JSONProcessInstanceResult) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) OpenReportAction(de.metas.ui.web.process.ProcessInstanceResult.OpenReportAction) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OpenReportAction (de.metas.ui.web.process.ProcessInstanceResult.OpenReportAction)2 OpenIncludedViewAction (de.metas.ui.web.process.ProcessInstanceResult.OpenIncludedViewAction)1 OpenSingleDocument (de.metas.ui.web.process.ProcessInstanceResult.OpenSingleDocument)1 OpenViewAction (de.metas.ui.web.process.ProcessInstanceResult.OpenViewAction)1 SelectViewRowsAction (de.metas.ui.web.process.ProcessInstanceResult.SelectViewRowsAction)1 JSONProcessInstanceResult (de.metas.ui.web.process.json.JSONProcessInstanceResult)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1