Search in sources :

Example 6 with BpmnXMLConverter

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

the class BpmnParse method execute.

public BpmnParse execute() {
    try {
        ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
        BpmnXMLConverter converter = new BpmnXMLConverter();
        boolean enableSafeBpmnXml = false;
        String encoding = null;
        if (processEngineConfiguration != null) {
            enableSafeBpmnXml = processEngineConfiguration.isEnableSafeBpmnXml();
            encoding = processEngineConfiguration.getXmlEncoding();
        }
        if (encoding != null) {
            bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding);
        } else {
            bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml);
        }
        // XSD validation goes first, then process/semantic validation
        if (validateProcess) {
            ProcessValidator processValidator = processEngineConfiguration.getProcessValidator();
            if (processValidator == null) {
                LOGGER.warn("Process should be validated, but no process validator is configured on the process engine configuration!");
            } else {
                List<ValidationError> validationErrors = processValidator.validate(bpmnModel);
                if (validationErrors != null && !validationErrors.isEmpty()) {
                    StringBuilder warningBuilder = new StringBuilder();
                    StringBuilder errorBuilder = new StringBuilder();
                    for (ValidationError error : validationErrors) {
                        if (error.isWarning()) {
                            warningBuilder.append(error.toString());
                            warningBuilder.append("\n");
                        } else {
                            errorBuilder.append(error.toString());
                            errorBuilder.append("\n");
                        }
                    }
                    // Throw exception if there is any error
                    if (errorBuilder.length() > 0) {
                        throw new ActivitiException("Errors while parsing:\n" + errorBuilder.toString());
                    }
                    // Write out warnings (if any)
                    if (warningBuilder.length() > 0) {
                        LOGGER.warn("Following warnings encountered during process validation: " + warningBuilder.toString());
                    }
                }
            }
        }
        // Validation successfull (or no validation)
        createImports();
        createItemDefinitions();
        createMessages();
        createOperations();
        transformProcessDefinitions();
    } catch (Exception e) {
        if (e instanceof ActivitiException) {
            throw (ActivitiException) e;
        } else if (e instanceof XMLException) {
            throw (XMLException) e;
        } else {
            throw new ActivitiException("Error parsing XML", e);
        }
    }
    return this;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) XMLException(org.activiti.bpmn.exceptions.XMLException) ValidationError(org.activiti.validation.ValidationError) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessValidator(org.activiti.validation.ProcessValidator) ActivitiException(org.activiti.engine.ActivitiException) XMLException(org.activiti.bpmn.exceptions.XMLException) MalformedURLException(java.net.MalformedURLException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 7 with BpmnXMLConverter

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

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

the class DefaultProcessValidatorTest method verifyValidation.

@Test
public void verifyValidation() throws Exception {
    InputStream xmlStream = this.getClass().getClassLoader().getResourceAsStream("org/activiti/engine/test/validation/invalidProcess.bpmn20.xml");
    XMLInputFactory xif = XMLInputFactory.newInstance();
    InputStreamReader in = new InputStreamReader(xmlStream, "UTF-8");
    XMLStreamReader xtr = xif.createXMLStreamReader(in);
    BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
    Assert.assertNotNull(bpmnModel);
    List<ValidationError> allErrors = processValidator.validate(bpmnModel);
    Assert.assertEquals(65, allErrors.size());
    // shortening it a bit
    String setName = ValidatorSetNames.ACTIVITI_EXECUTABLE_PROCESS;
    // isExecutable should be true
    List<ValidationError> problems = findErrors(allErrors, setName, Problems.ALL_PROCESS_DEFINITIONS_NOT_EXECUTABLE, 1);
    Assert.assertNotNull(problems.get(0).getValidatorSetName());
    Assert.assertNotNull(problems.get(0).getProblem());
    Assert.assertNotNull(problems.get(0).getDefaultDescription());
    // Event listeners
    problems = findErrors(allErrors, setName, Problems.EVENT_LISTENER_IMPLEMENTATION_MISSING, 1);
    assertProcessElementError(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.EVENT_LISTENER_INVALID_THROW_EVENT_TYPE, 1);
    assertProcessElementError(problems.get(0));
    // Execution listeners
    problems = findErrors(allErrors, setName, Problems.EXECUTION_LISTENER_IMPLEMENTATION_MISSING, 2);
    assertProcessElementError(problems.get(0));
    assertCommonProblemFieldForActivity(problems.get(1));
    // Association
    problems = findErrors(allErrors, setName, Problems.ASSOCIATION_INVALID_SOURCE_REFERENCE, 1);
    assertProcessElementError(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.ASSOCIATION_INVALID_TARGET_REFERENCE, 1);
    assertProcessElementError(problems.get(0));
    // Signals
    problems = findErrors(allErrors, setName, Problems.SIGNAL_MISSING_ID, 1);
    assertCommonErrorFields(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.SIGNAL_MISSING_NAME, 2);
    assertCommonErrorFields(problems.get(0));
    assertCommonErrorFields(problems.get(1));
    problems = findErrors(allErrors, setName, Problems.SIGNAL_DUPLICATE_NAME, 2);
    assertCommonErrorFields(problems.get(0));
    assertCommonErrorFields(problems.get(1));
    problems = findErrors(allErrors, setName, Problems.SIGNAL_INVALID_SCOPE, 1);
    assertCommonErrorFields(problems.get(0));
    // Start event
    problems = findErrors(allErrors, setName, Problems.START_EVENT_MULTIPLE_FOUND, 2);
    assertCommonProblemFieldForActivity(problems.get(0));
    assertCommonProblemFieldForActivity(problems.get(1));
    problems = findErrors(allErrors, setName, Problems.START_EVENT_INVALID_EVENT_DEFINITION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Sequence flow
    problems = findErrors(allErrors, setName, Problems.SEQ_FLOW_INVALID_SRC, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.SEQ_FLOW_INVALID_TARGET, 2);
    assertCommonProblemFieldForActivity(problems.get(0));
    // User task
    problems = findErrors(allErrors, setName, Problems.USER_TASK_LISTENER_IMPLEMENTATION_MISSING, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Service task 
    problems = findErrors(allErrors, setName, Problems.SERVICE_TASK_RESULT_VAR_NAME_WITH_DELEGATE, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.SERVICE_TASK_INVALID_TYPE, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.SERVICE_TASK_MISSING_IMPLEMENTATION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.SERVICE_TASK_WEBSERVICE_INVALID_OPERATION_REF, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Send task
    problems = findErrors(allErrors, setName, Problems.SEND_TASK_INVALID_IMPLEMENTATION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.SEND_TASK_INVALID_TYPE, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.SEND_TASK_WEBSERVICE_INVALID_OPERATION_REF, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Mail task
    problems = findErrors(allErrors, setName, Problems.MAIL_TASK_NO_RECIPIENT, 2);
    assertCommonProblemFieldForActivity(problems.get(0));
    assertCommonProblemFieldForActivity(problems.get(1));
    problems = findErrors(allErrors, setName, Problems.MAIL_TASK_NO_CONTENT, 4);
    assertCommonProblemFieldForActivity(problems.get(0));
    assertCommonProblemFieldForActivity(problems.get(1));
    // Shell task
    problems = findErrors(allErrors, setName, Problems.SHELL_TASK_NO_COMMAND, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Script task
    problems = findErrors(allErrors, setName, Problems.SCRIPT_TASK_MISSING_SCRIPT, 2);
    assertCommonProblemFieldForActivity(problems.get(0));
    assertCommonProblemFieldForActivity(problems.get(1));
    // Exclusive gateway
    problems = findErrors(allErrors, setName, Problems.EXCLUSIVE_GATEWAY_CONDITION_NOT_ALLOWED_ON_SINGLE_SEQ_FLOW, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.EXCLUSIVE_GATEWAY_CONDITION_ON_DEFAULT_SEQ_FLOW, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.EXCLUSIVE_GATEWAY_NO_OUTGOING_SEQ_FLOW, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.EXCLUSIVE_GATEWAY_SEQ_FLOW_WITHOUT_CONDITIONS, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Event gateway
    problems = findErrors(allErrors, setName, Problems.EVENT_GATEWAY_ONLY_CONNECTED_TO_INTERMEDIATE_EVENTS, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Subprocesses
    problems = findErrors(allErrors, setName, Problems.SUBPROCESS_MULTIPLE_START_EVENTS, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.SUBPROCESS_START_EVENT_EVENT_DEFINITION_NOT_ALLOWED, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Event subprocesses
    problems = findErrors(allErrors, setName, Problems.EVENT_SUBPROCESS_INVALID_START_EVENT_DEFINITION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Boundary events
    problems = findErrors(allErrors, setName, Problems.BOUNDARY_EVENT_NO_EVENT_DEFINITION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.BOUNDARY_EVENT_CANCEL_ONLY_ON_TRANSACTION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.BOUNDARY_EVENT_MULTIPLE_CANCEL_ON_TRANSACTION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Intermediate catch event
    problems = findErrors(allErrors, setName, Problems.INTERMEDIATE_CATCH_EVENT_NO_EVENTDEFINITION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.INTERMEDIATE_CATCH_EVENT_INVALID_EVENTDEFINITION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Intermediate throw event
    problems = findErrors(allErrors, setName, Problems.THROW_EVENT_INVALID_EVENTDEFINITION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Multi instance
    problems = findErrors(allErrors, setName, Problems.MULTI_INSTANCE_MISSING_COLLECTION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Message events
    problems = findErrors(allErrors, setName, Problems.MESSAGE_EVENT_MISSING_MESSAGE_REF, 2);
    assertCommonProblemFieldForActivity(problems.get(0));
    assertCommonProblemFieldForActivity(problems.get(1));
    // Signal events
    problems = findErrors(allErrors, setName, Problems.SIGNAL_EVENT_MISSING_SIGNAL_REF, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    problems = findErrors(allErrors, setName, Problems.SIGNAL_EVENT_INVALID_SIGNAL_REF, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Compensate event
    problems = findErrors(allErrors, setName, Problems.COMPENSATE_EVENT_INVALID_ACTIVITY_REF, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Timer event
    problems = findErrors(allErrors, setName, Problems.EVENT_TIMER_MISSING_CONFIGURATION, 2);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Data association
    problems = findErrors(allErrors, setName, Problems.DATA_ASSOCIATION_MISSING_TARGETREF, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Data object
    problems = findErrors(allErrors, setName, Problems.DATA_OBJECT_MISSING_NAME, 2);
    assertCommonErrorFields(problems.get(0));
    assertCommonErrorFields(problems.get(1));
    // End event
    problems = findErrors(allErrors, setName, Problems.END_EVENT_CANCEL_ONLY_INSIDE_TRANSACTION, 1);
    assertCommonProblemFieldForActivity(problems.get(0));
    // Messages
    problems = findErrors(allErrors, setName, Problems.MESSAGE_INVALID_ITEM_REF, 1);
    assertCommonErrorFields(problems.get(0));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) 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 9 with BpmnXMLConverter

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

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

the class ChineseConverterTest method exportAndReadXMLFile.

protected BpmnModel exportAndReadXMLFile(BpmnModel bpmnModel) throws Exception {
    byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel, processEngineConfiguration.getXmlEncoding());
    StreamSource xmlSource = new InputStreamSource(new ByteArrayInputStream(xml));
    BpmnModel parsedModel = new BpmnXMLConverter().convertToBpmnModel(xmlSource, false, false, processEngineConfiguration.getXmlEncoding());
    return parsedModel;
}
Also used : InputStreamSource(org.activiti.engine.impl.util.io.InputStreamSource) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(org.activiti.engine.impl.util.io.StreamSource) InputStreamSource(org.activiti.engine.impl.util.io.InputStreamSource) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) BpmnModel(org.activiti.bpmn.model.BpmnModel)

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