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