Search in sources :

Example 1 with InputStreamSource

use of org.activiti.engine.impl.util.io.InputStreamSource in project Activiti by Activiti.

the class ImportExportTest 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)

Example 2 with InputStreamSource

use of org.activiti.engine.impl.util.io.InputStreamSource in project Activiti by Activiti.

the class ImportExportTest method readXMLFile.

protected BpmnModel readXMLFile() throws Exception {
    InputStream xmlStream = this.getClass().getClassLoader().getResourceAsStream(getResource());
    StreamSource xmlSource = new InputStreamSource(xmlStream);
    BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xmlSource, false, false, processEngineConfiguration.getXmlEncoding());
    return bpmnModel;
}
Also used : InputStreamSource(org.activiti.engine.impl.util.io.InputStreamSource) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(org.activiti.engine.impl.util.io.StreamSource) InputStreamSource(org.activiti.engine.impl.util.io.InputStreamSource) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 3 with InputStreamSource

use of org.activiti.engine.impl.util.io.InputStreamSource in project Activiti by Activiti.

the class EventJavaTest method testStartEventWithExecutionListener.

public void testStartEventWithExecutionListener() throws Exception {
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId("simpleProcess");
    process.setName("Very simple process");
    bpmnModel.getProcesses().add(process);
    StartEvent startEvent = new StartEvent();
    startEvent.setId("startEvent1");
    TimerEventDefinition timerDef = new TimerEventDefinition();
    timerDef.setTimeDuration("PT5M");
    startEvent.getEventDefinitions().add(timerDef);
    ActivitiListener listener = new ActivitiListener();
    listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
    listener.setImplementation("${test}");
    listener.setEvent("end");
    startEvent.getExecutionListeners().add(listener);
    process.addFlowElement(startEvent);
    UserTask task = new UserTask();
    task.setId("reviewTask");
    task.setAssignee("kermit");
    process.addFlowElement(task);
    SequenceFlow flow1 = new SequenceFlow();
    flow1.setId("flow1");
    flow1.setSourceRef("startEvent1");
    flow1.setTargetRef("reviewTask");
    process.addFlowElement(flow1);
    EndEvent endEvent = new EndEvent();
    endEvent.setId("endEvent1");
    process.addFlowElement(endEvent);
    byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
    new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml)));
    Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml)).deploy();
    repositoryService.deleteDeployment(deployment.getId());
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) UserTask(org.activiti.bpmn.model.UserTask) Deployment(org.activiti.engine.repository.Deployment) Process(org.activiti.bpmn.model.Process) ActivitiListener(org.activiti.bpmn.model.ActivitiListener) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) InputStreamSource(org.activiti.engine.impl.util.io.InputStreamSource) ByteArrayInputStream(java.io.ByteArrayInputStream) StartEvent(org.activiti.bpmn.model.StartEvent) EndEvent(org.activiti.bpmn.model.EndEvent) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition)

Example 4 with InputStreamSource

use of org.activiti.engine.impl.util.io.InputStreamSource in project Activiti by Activiti.

the class CallActivityTest method loadBPMNModel.

protected BpmnModel loadBPMNModel(String bpmnModelFilePath) throws Exception {
    InputStream xmlStream = this.getClass().getClassLoader().getResourceAsStream(bpmnModelFilePath);
    StreamSource xmlSource = new InputStreamSource(xmlStream);
    BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xmlSource, false, false, processEngineConfiguration.getXmlEncoding());
    return bpmnModel;
}
Also used : InputStreamSource(org.activiti.engine.impl.util.io.InputStreamSource) InputStream(java.io.InputStream) InputStreamSource(org.activiti.engine.impl.util.io.InputStreamSource) StreamSource(org.activiti.engine.impl.util.io.StreamSource) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 5 with InputStreamSource

use of org.activiti.engine.impl.util.io.InputStreamSource in project Activiti by Activiti.

the class AbstractAutoDeploymentStrategy method validateModel.

protected boolean validateModel(Resource resource, final RepositoryService repositoryService) {
    String resourceName = determineResourceName(resource);
    if (isProcessDefinitionResource(resourceName)) {
        try {
            BpmnXMLConverter converter = new BpmnXMLConverter();
            BpmnModel bpmnModel = converter.convertToBpmnModel(new InputStreamSource(resource.getInputStream()), true, false);
            List<ValidationError> validationErrors = repositoryService.validateProcess(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");
                    }
                    // Write out warnings (if any)
                    if (warningBuilder.length() > 0) {
                        LOGGER.warn("Following warnings encountered during process validation: " + warningBuilder.toString());
                    }
                    if (errorBuilder.length() > 0) {
                        LOGGER.error("Errors while parsing:\n" + errorBuilder.toString());
                        return false;
                    }
                }
            }
        } catch (Exception e) {
            LOGGER.error("Error parsing XML", e);
            return false;
        }
    }
    return true;
}
Also used : InputStreamSource(org.activiti.engine.impl.util.io.InputStreamSource) ValidationError(org.activiti.validation.ValidationError) IOException(java.io.IOException) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Aggregations

BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)8 BpmnModel (org.activiti.bpmn.model.BpmnModel)8 InputStreamSource (org.activiti.engine.impl.util.io.InputStreamSource)8 ByteArrayInputStream (java.io.ByteArrayInputStream)5 StreamSource (org.activiti.engine.impl.util.io.StreamSource)5 InputStream (java.io.InputStream)3 ValidationError (org.activiti.validation.ValidationError)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)1 EndEvent (org.activiti.bpmn.model.EndEvent)1 Process (org.activiti.bpmn.model.Process)1 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)1 StartEvent (org.activiti.bpmn.model.StartEvent)1 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)1 UserTask (org.activiti.bpmn.model.UserTask)1 Deployment (org.activiti.engine.repository.Deployment)1 Test (org.junit.jupiter.api.Test)1