Search in sources :

Example 1 with BpmnJsonConverter

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

the class ImportUploadReceiver method deployUploadedFile.

protected void deployUploadedFile() {
    try {
        try {
            if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
                validFile = true;
                XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
                InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray()), "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 {
                        String processName = null;
                        if (StringUtils.isNotEmpty(bpmnModel.getMainProcess().getName())) {
                            processName = bpmnModel.getMainProcess().getName();
                        } else {
                            processName = bpmnModel.getMainProcess().getId();
                        }
                        modelData = repositoryService.newModel();
                        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
                        modelObjectNode.put(MODEL_NAME, processName);
                        modelObjectNode.put(MODEL_REVISION, 1);
                        modelData.setMetaInfo(modelObjectNode.toString());
                        modelData.setName(processName);
                        repositoryService.saveModel(modelData);
                        BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
                        ObjectNode editorNode = jsonConverter.convertToJson(bpmnModel);
                        repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
                    }
                }
            } else {
                notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_FILE, i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_FILE_EXPLANATION));
            }
        } catch (Exception e) {
            String errorMsg = e.getMessage().replace(System.getProperty("line.separator"), "<br/>");
            notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED, errorMsg);
        }
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                notificationManager.showErrorNotification("Server-side error", e.getMessage());
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) XMLInputFactory(javax.xml.stream.XMLInputFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 2 with BpmnJsonConverter

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

the class EditorProcessDefinitionDetailPanel method deployModelerModel.

protected void deployModelerModel(final ObjectNode modelNode) {
    BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
    String processName = modelData.getName() + ".bpmn20.xml";
    Deployment deployment = repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes)).deploy();
    ExplorerApp.get().getViewManager().showDeploymentPage(deployment.getId());
}
Also used : Deployment(org.activiti.engine.repository.Deployment) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 3 with BpmnJsonConverter

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

the class AbstractConverterTest method readJsonFile.

protected BpmnModel readJsonFile() throws Exception {
    InputStream jsonStream = this.getClass().getClassLoader().getResourceAsStream(getResource());
    JsonNode modelNode = new ObjectMapper().readTree(jsonStream);
    BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    return bpmnModel;
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 4 with BpmnJsonConverter

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

the class EditModelClickListener method showSelectEditorPopupWindow.

protected void showSelectEditorPopupWindow() {
    final PopupWindow selectEditorPopupWindow = new PopupWindow();
    selectEditorPopupWindow.setModal(true);
    selectEditorPopupWindow.setResizable(false);
    selectEditorPopupWindow.setWidth("350px");
    selectEditorPopupWindow.setHeight("250px");
    selectEditorPopupWindow.addStyleName(Reindeer.PANEL_LIGHT);
    selectEditorPopupWindow.center();
    final SelectEditorComponent selectEditorComponent = new SelectEditorComponent(false);
    selectEditorComponent.getModelerDescriptionLabel().setValue(ExplorerApp.get().getI18nManager().getMessage(Messages.PROCESS_EDITOR_CONVERSION_WARNING_MODELER));
    selectEditorComponent.getModelerDescriptionLabel().addStyleName(ExplorerLayout.STYLE_LABEL_RED);
    selectEditorComponent.preferTableDrivenEditor();
    selectEditorPopupWindow.getContent().addComponent(selectEditorComponent);
    selectEditorComponent.setEditorSelectedListener(new EditorSelectedListener() {

        public void editorSelectionChanged() {
            try {
                WorkflowDefinition workflowDefinition = loadWorkflowDefinition();
                // When using the modeler, the format must first be converted to the modeler json format
                if (selectEditorComponent.isModelerPreferred()) {
                    WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
                    conversion.convert();
                    RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
                    model.setCategory(null);
                    ObjectMapper objectMapper = new ObjectMapper();
                    ObjectNode metaInfoJson = objectMapper.createObjectNode();
                    metaInfoJson.put("name", model.getName());
                    model.setMetaInfo(metaInfoJson.toString());
                    repositoryService.saveModel(model);
                    BpmnJsonConverter bpmnJsonConverter = new BpmnJsonConverter();
                    ObjectNode json = bpmnJsonConverter.convertToJson(conversion.getBpmnModel());
                    repositoryService.addModelEditorSource(model.getId(), json.toString().getBytes("utf-8"));
                    // Show modeler
                    showModeler();
                } else {
                    // Load and show table editor
                    ExplorerApp.get().getViewManager().showSimpleTableProcessEditor(model.getId(), workflowDefinition);
                }
            } catch (Exception e) {
                LOGGER.error("Error showing editor", e);
                ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_EDITOR_LOADING_ERROR, e);
            } finally {
                ExplorerApp.get().getMainWindow().removeWindow(selectEditorPopupWindow);
            }
        }
    });
    ExplorerApp.get().getViewManager().showPopupWindow(selectEditorPopupWindow);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PopupWindow(org.activiti.explorer.ui.custom.PopupWindow) SelectEditorComponent(org.activiti.editor.ui.SelectEditorComponent) EditorSelectedListener(org.activiti.editor.ui.SelectEditorComponent.EditorSelectedListener) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RepositoryService(org.activiti.engine.RepositoryService)

Example 5 with BpmnJsonConverter

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

the class AbstractConverterTest method convertToJsonAndBack.

protected BpmnModel convertToJsonAndBack(BpmnModel bpmnModel) {
    ObjectNode modelNode = new BpmnJsonConverter().convertToJson(bpmnModel);
    bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    return bpmnModel;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter)

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