Search in sources :

Example 21 with BpmnXMLConverter

use of org.activiti.bpmn.converter.BpmnXMLConverter in project Activiti by Activiti.

the class DefaultProcessValidatorTest method testWarningError.

@Test
public void testWarningError() throws UnsupportedEncodingException, XMLStreamException {
    String flowWithoutConditionNoDefaultFlow = "<?xml version='1.0' encoding='UTF-8'?>" + "<definitions id='definitions' xmlns='http://www.omg.org/spec/BPMN/20100524/MODEL' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:activiti='http://activiti.org/bpmn' targetNamespace='Examples'>" + "  <process id='exclusiveGwDefaultSequenceFlow'> " + "    <startEvent id='theStart' /> " + "    <sequenceFlow id='flow1' sourceRef='theStart' targetRef='exclusiveGw' /> " + // no default = "flow3" !!
    "    <exclusiveGateway id='exclusiveGw' name='Exclusive Gateway' /> " + "    <sequenceFlow id='flow2' sourceRef='exclusiveGw' targetRef='theTask1'> " + "      <conditionExpression xsi:type='tFormalExpression'>${input == 1}</conditionExpression> " + "    </sequenceFlow> " + // one would be OK
    "    <sequenceFlow id='flow3' sourceRef='exclusiveGw' targetRef='theTask2'/> " + // but two unconditional not!
    "    <sequenceFlow id='flow4' sourceRef='exclusiveGw' targetRef='theTask2'/> " + "    <userTask id='theTask1' name='Input is one' /> " + "    <userTask id='theTask2' name='Default input' /> " + "  </process>" + "</definitions>";
    XMLInputFactory xif = XMLInputFactory.newInstance();
    InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(flowWithoutConditionNoDefaultFlow.getBytes()), "UTF-8");
    XMLStreamReader xtr = xif.createXMLStreamReader(in);
    BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
    Assert.assertNotNull(bpmnModel);
    List<ValidationError> allErrors = processValidator.validate(bpmnModel);
    Assert.assertEquals(1, allErrors.size());
    Assert.assertTrue(allErrors.get(0).isWarning());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ValidationError(org.activiti.validation.ValidationError) XMLInputFactory(javax.xml.stream.XMLInputFactory) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) Test(org.junit.Test)

Example 22 with BpmnXMLConverter

use of org.activiti.bpmn.converter.BpmnXMLConverter 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 23 with BpmnXMLConverter

use of org.activiti.bpmn.converter.BpmnXMLConverter 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

BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)23 BpmnModel (org.activiti.bpmn.model.BpmnModel)15 ByteArrayInputStream (java.io.ByteArrayInputStream)12 InputStream (java.io.InputStream)9 XMLInputFactory (javax.xml.stream.XMLInputFactory)8 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 InputStreamReader (java.io.InputStreamReader)6 InputStreamSource (org.activiti.engine.impl.util.io.InputStreamSource)6 StreamSource (org.activiti.engine.impl.util.io.StreamSource)5 BpmnJsonConverter (org.activiti.editor.language.json.converter.BpmnJsonConverter)4 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ExternalResource (com.vaadin.terminal.ExternalResource)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 URL (java.net.URL)3 Deployment (org.activiti.engine.repository.Deployment)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 StreamResource (com.vaadin.terminal.StreamResource)2 Embedded (com.vaadin.ui.Embedded)2 Label (com.vaadin.ui.Label)2