Search in sources :

Example 1 with DownloadStream

use of com.vaadin.terminal.DownloadStream in project Activiti by Activiti.

the class EditorProcessDefinitionDetailPanel method exportModel.

protected void exportModel() {
    final FileResource stream = new FileResource(new File(""), ExplorerApp.get()) {

        private static final long serialVersionUID = 1L;

        @Override
        public DownloadStream getStream() {
            DownloadStream ds = null;
            try {
                byte[] bpmnBytes = null;
                String filename = null;
                if (SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY.equals(modelData.getCategory())) {
                    WorkflowDefinition workflowDefinition = ExplorerApp.get().getSimpleWorkflowJsonConverter().readWorkflowDefinition(repositoryService.getModelEditorSource(modelData.getId()));
                    filename = workflowDefinition.getName();
                    WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
                    bpmnBytes = conversion.getBpmn20Xml().getBytes("utf-8");
                } else {
                    JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
                    BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
                    BpmnModel model = jsonConverter.convertToBpmnModel(editorNode);
                    filename = model.getMainProcess().getId() + ".bpmn20.xml";
                    bpmnBytes = new BpmnXMLConverter().convertToXML(model);
                }
                ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
                ds = new DownloadStream(in, "application/xml", filename);
                // Need a file download POPUP
                ds.setParameter("Content-Disposition", "attachment; filename=" + filename);
            } catch (Exception e) {
                LOGGER.error("failed to export model to BPMN XML", e);
                ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_TOXML_FAILED, e);
            }
            return ds;
        }
    };
    stream.setCacheTime(0);
    ExplorerApp.get().getMainWindow().open(stream);
}
Also used : FileResource(com.vaadin.terminal.FileResource) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) DownloadStream(com.vaadin.terminal.DownloadStream) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DownloadStream (com.vaadin.terminal.DownloadStream)1 FileResource (com.vaadin.terminal.FileResource)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 BpmnJsonConverter (org.activiti.editor.language.json.converter.BpmnJsonConverter)1 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)1 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)1