Search in sources :

Example 6 with BpmnJsonConverter

use of org.activiti.editor.language.json.converter.BpmnJsonConverter in project Activiti by Activiti.

the class ConvertProcessDefinitionPopupWindow method addButtons.

protected void addButtons() {
    // Cancel
    Button cancelButton = new Button(i18nManager.getMessage(Messages.BUTTON_CANCEL));
    cancelButton.addStyleName(Reindeer.BUTTON_SMALL);
    cancelButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            close();
        }
    });
    // Convert
    Button convertButton = new Button(i18nManager.getMessage(Messages.PROCESS_CONVERT_POPUP_CONVERT_BUTTON));
    convertButton.addStyleName(Reindeer.BUTTON_SMALL);
    convertButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            try {
                InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
                XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
                InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
                XMLStreamReader xtr = xif.createXMLStreamReader(in);
                BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
                if (bpmnModel.getMainProcess() == null || bpmnModel.getMainProcess().getId() == null) {
                    notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMN_EXPLANATION));
                } else {
                    if (bpmnModel.getLocationMap().isEmpty()) {
                        notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_BPMNDI, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMNDI_EXPLANATION));
                    } else {
                        BpmnJsonConverter converter = new BpmnJsonConverter();
                        ObjectNode modelNode = converter.convertToJson(bpmnModel);
                        Model modelData = repositoryService.newModel();
                        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
                        modelObjectNode.put(MODEL_NAME, processDefinition.getName());
                        modelObjectNode.put(MODEL_REVISION, 1);
                        modelObjectNode.put(MODEL_DESCRIPTION, processDefinition.getDescription());
                        modelData.setMetaInfo(modelObjectNode.toString());
                        modelData.setName(processDefinition.getName());
                        repositoryService.saveModel(modelData);
                        repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
                        close();
                        ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(modelData.getId());
                        URL explorerURL = ExplorerApp.get().getURL();
                        URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "modeler.html?modelId=" + modelData.getId());
                        ExplorerApp.get().getMainWindow().open(new ExternalResource(url));
                    }
                }
            } catch (Exception e) {
                notificationManager.showErrorNotification("error", e);
            }
        }
    });
    // Alignment
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(cancelButton);
    buttonLayout.addComponent(convertButton);
    addComponent(buttonLayout);
    windowLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) ClickEvent(com.vaadin.ui.Button.ClickEvent) ExternalResource(com.vaadin.terminal.ExternalResource) URL(java.net.URL) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) BpmnModel(org.activiti.bpmn.model.BpmnModel) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Button(com.vaadin.ui.Button) Model(org.activiti.engine.repository.Model) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ClickListener(com.vaadin.ui.Button.ClickListener) XMLInputFactory(javax.xml.stream.XMLInputFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with BpmnJsonConverter

use of org.activiti.editor.language.json.converter.BpmnJsonConverter 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

BpmnJsonConverter (org.activiti.editor.language.json.converter.BpmnJsonConverter)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 BpmnModel (org.activiti.bpmn.model.BpmnModel)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 XMLInputFactory (javax.xml.stream.XMLInputFactory)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)2 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DownloadStream (com.vaadin.terminal.DownloadStream)1 ExternalResource (com.vaadin.terminal.ExternalResource)1 FileResource (com.vaadin.terminal.FileResource)1 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1