Search in sources :

Example 11 with BpmnXMLConverter

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

the class DeploymentManager method getBpmnModelById.

public BpmnModel getBpmnModelById(String processDefinitionId) {
    if (processDefinitionId == null) {
        throw new ActivitiIllegalArgumentException("Invalid process definition id : null");
    }
    // first try the cache
    BpmnModel bpmnModel = bpmnModelCache.get(processDefinitionId);
    if (bpmnModel == null) {
        ProcessDefinitionEntity processDefinition = findDeployedProcessDefinitionById(processDefinitionId);
        if (processDefinition == null) {
            throw new ActivitiObjectNotFoundException("no deployed process definition found with id '" + processDefinitionId + "'", ProcessDefinition.class);
        }
        // Fetch the resource
        String resourceName = processDefinition.getResourceName();
        ResourceEntity resource = Context.getCommandContext().getResourceEntityManager().findResourceByDeploymentIdAndResourceName(processDefinition.getDeploymentId(), resourceName);
        if (resource == null) {
            if (Context.getCommandContext().getDeploymentEntityManager().findDeploymentById(processDefinition.getDeploymentId()) == null) {
                throw new ActivitiObjectNotFoundException("deployment for process definition does not exist: " + processDefinition.getDeploymentId(), Deployment.class);
            } else {
                throw new ActivitiObjectNotFoundException("no resource found with name '" + resourceName + "' in deployment '" + processDefinition.getDeploymentId() + "'", InputStream.class);
            }
        }
        // Convert the bpmn 2.0 xml to a bpmn model
        BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
        bpmnModel = bpmnXMLConverter.convertToBpmnModel(new BytesStreamSource(resource.getBytes()), false, false);
        bpmnModelCache.add(processDefinition.getId(), bpmnModel);
    }
    return bpmnModel;
}
Also used : BytesStreamSource(org.activiti.engine.impl.util.io.BytesStreamSource) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ResourceEntity(org.activiti.engine.impl.persistence.entity.ResourceEntity) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 12 with BpmnXMLConverter

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

the class AbstractConverterTest method exportAndReadXMLFile.

protected BpmnModel exportAndReadXMLFile(BpmnModel bpmnModel) throws Exception {
    byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
    System.out.println("xml " + new String(xml, "UTF-8"));
    XMLInputFactory xif = XMLInputFactory.newInstance();
    InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(xml), "UTF-8");
    XMLStreamReader xtr = xif.createXMLStreamReader(in);
    return new BpmnXMLConverter().convertToBpmnModel(xtr);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLInputFactory(javax.xml.stream.XMLInputFactory) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 13 with BpmnXMLConverter

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

the class AbstractConverterTest method readXMLFile.

protected BpmnModel readXMLFile() throws Exception {
    InputStream xmlStream = this.getClass().getClassLoader().getResourceAsStream(getResource());
    XMLInputFactory xif = XMLInputFactory.newInstance();
    InputStreamReader in = new InputStreamReader(xmlStream, "UTF-8");
    XMLStreamReader xtr = xif.createXMLStreamReader(in);
    return new BpmnXMLConverter().convertToBpmnModel(xtr);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XMLInputFactory(javax.xml.stream.XMLInputFactory) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 14 with BpmnXMLConverter

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

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

the class ProcessWithCompensationConverterTest method testConvertingAfterAutoLayout.

@Test
public void testConvertingAfterAutoLayout() {
    final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ProcessWithCompensationAssociation.bpmn20.xml");
    BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
    BpmnModel bpmnModel1 = bpmnXMLConverter.convertToBpmnModel(new InputStreamProvider() {

        @Override
        public InputStream getInputStream() {
            return inputStream;
        }
    }, false, false);
    if (bpmnModel1.getLocationMap().size() == 0) {
        BpmnAutoLayout bpmnLayout = new BpmnAutoLayout(bpmnModel1);
        bpmnLayout.execute();
    }
    byte[] xmlByte = bpmnXMLConverter.convertToXML(bpmnModel1);
    final InputStream byteArrayInputStream = new ByteArrayInputStream(xmlByte);
    BpmnModel bpmnModel2 = bpmnXMLConverter.convertToBpmnModel(new InputStreamProvider() {

        @Override
        public InputStream getInputStream() {
            return byteArrayInputStream;
        }
    }, false, false);
    assertEquals(10, bpmnModel1.getLocationMap().size());
    assertEquals(10, bpmnModel2.getLocationMap().size());
    assertEquals(7, bpmnModel1.getFlowLocationMap().size());
    assertEquals(7, bpmnModel2.getFlowLocationMap().size());
}
Also used : InputStreamProvider(org.activiti.bpmn.converter.util.InputStreamProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

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