Search in sources :

Example 76 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.

the class AbstractActivitiTestCase method createOneTaskTestProcess.

/**
   * Since the 'one task process' is used everywhere the actual process content
   * doesn't matter, instead of copying around the BPMN 2.0 xml one could use 
   * this method which gives a {@link BpmnModel} version of the same process back.
   */
public BpmnModel createOneTaskTestProcess() {
    BpmnModel model = new BpmnModel();
    org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
    model.addProcess(process);
    process.setId("oneTaskProcess");
    process.setName("The one task process");
    StartEvent startEvent = new StartEvent();
    startEvent.setId("start");
    process.addFlowElement(startEvent);
    UserTask userTask = new UserTask();
    userTask.setName("The Task");
    userTask.setId("theTask");
    userTask.setAssignee("kermit");
    process.addFlowElement(userTask);
    EndEvent endEvent = new EndEvent();
    endEvent.setId("theEnd");
    process.addFlowElement(endEvent);
    process.addFlowElement(new SequenceFlow("start", "theTask"));
    process.addFlowElement(new SequenceFlow("theTask", "theEnd"));
    return model;
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) StartEvent(org.activiti.bpmn.model.StartEvent) UserTask(org.activiti.bpmn.model.UserTask) EndEvent(org.activiti.bpmn.model.EndEvent) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 77 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.

the class AbstractActivitiTestCase method deployOneTaskTestProcess.

/**
   * Creates and deploys the one task process. See {@link #createOneTaskTestProcess()}.
   * 
   * @return The process definition id (NOT the process definition key) of deployed one task process.
   */
public String deployOneTaskTestProcess() {
    BpmnModel bpmnModel = createOneTaskTestProcess();
    Deployment deployment = repositoryService.createDeployment().addBpmnModel("oneTasktest.bpmn20.xml", bpmnModel).deploy();
    // For auto-cleanup
    deploymentIdsForAutoCleanup.add(deployment.getId());
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    return processDefinition.getId();
}
Also used : Deployment(org.activiti.engine.repository.Deployment) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 78 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.

the class DelegateHelper method getFlowElement.

/**
   * Returns the current {@link FlowElement} where the {@link DelegateExecution} is currently at.
   */
public static FlowElement getFlowElement(DelegateExecution execution) {
    BpmnModel bpmnModel = getBpmnModel(execution);
    FlowElement flowElement = bpmnModel.getFlowElement(execution.getCurrentActivityId());
    if (flowElement == null) {
        throw new ActivitiException("Could not find a FlowElement for activityId " + execution.getCurrentActivityId());
    }
    return flowElement;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) FlowElement(org.activiti.bpmn.model.FlowElement) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 79 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.

the class ProcessDefinitionInfoComponent method initImage.

protected void initImage() {
    processImageContainer = new VerticalLayout();
    Label processTitle = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
    processTitle.addStyleName(ExplorerLayout.STYLE_H3);
    processImageContainer.addComponent(processTitle);
    boolean didDrawImage = false;
    if (ExplorerApp.get().isUseJavascriptDiagram()) {
        try {
            final InputStream definitionStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
            XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
            XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
            BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
            if (!bpmnModel.getFlowLocationMap().isEmpty()) {
                int maxX = 0;
                int maxY = 0;
                for (String key : bpmnModel.getLocationMap().keySet()) {
                    GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
                    double elementX = graphicInfo.getX() + graphicInfo.getWidth();
                    if (maxX < elementX) {
                        maxX = (int) elementX;
                    }
                    double elementY = graphicInfo.getY() + graphicInfo.getHeight();
                    if (maxY < elementY) {
                        maxY = (int) elementY;
                    }
                }
                // using panel for scrollbars
                Panel imagePanel = new Panel();
                imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                imagePanel.setWidth(100, UNITS_PERCENTAGE);
                imagePanel.setHeight(100, UNITS_PERCENTAGE);
                URL explorerURL = ExplorerApp.get().getURL();
                URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "diagram-viewer/index.html?processDefinitionId=" + processDefinition.getId());
                Embedded browserPanel = new Embedded("", new ExternalResource(url));
                browserPanel.setType(Embedded.TYPE_BROWSER);
                browserPanel.setWidth(maxX + 350 + "px");
                browserPanel.setHeight(maxY + 220 + "px");
                HorizontalLayout panelLayout = new HorizontalLayout();
                panelLayout.setSizeUndefined();
                imagePanel.setContent(panelLayout);
                imagePanel.addComponent(browserPanel);
                processImageContainer.addComponent(imagePanel);
                didDrawImage = true;
            }
        } catch (Exception e) {
            LOGGER.error("Error loading process diagram component", e);
        }
    }
    if (didDrawImage == false) {
        StreamResource diagram = null;
        // Try generating process-image stream
        if (processDefinition.getDiagramResourceName() != null) {
            diagram = new ProcessDefinitionImageStreamResourceBuilder().buildStreamResource(processDefinition, repositoryService);
        }
        if (diagram != null) {
            Embedded embedded = new Embedded(null, diagram);
            embedded.setType(Embedded.TYPE_IMAGE);
            embedded.setSizeUndefined();
            // using panel for scrollbars
            Panel imagePanel = new Panel();
            imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
            imagePanel.setWidth(100, UNITS_PERCENTAGE);
            imagePanel.setHeight(100, UNITS_PERCENTAGE);
            HorizontalLayout panelLayout = new HorizontalLayout();
            panelLayout.setSizeUndefined();
            imagePanel.setContent(panelLayout);
            imagePanel.addComponent(embedded);
            processImageContainer.addComponent(imagePanel);
            didDrawImage = true;
        }
    }
    if (didDrawImage == false) {
        Label noImageAvailable = new Label(i18nManager.getMessage(Messages.PROCESS_NO_DIAGRAM));
        processImageContainer.addComponent(noImageAvailable);
    }
    addComponent(processImageContainer);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) Label(com.vaadin.ui.Label) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) ExternalResource(com.vaadin.terminal.ExternalResource) URL(java.net.URL) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Panel(com.vaadin.ui.Panel) StreamResource(com.vaadin.terminal.StreamResource) VerticalLayout(com.vaadin.ui.VerticalLayout) Embedded(com.vaadin.ui.Embedded) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 80 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel in project Activiti by Activiti.

the class CallActivityTest method testInstantiateSuspendedChildProcess.

public void testInstantiateSuspendedChildProcess() throws Exception {
    BpmnModel childBpmnModel = loadBPMNModel(CHILD_PROCESS_RESOURCE);
    Deployment childDeployment = processEngine.getRepositoryService().createDeployment().name("childProcessDeployment").addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).deploy();
    suspendProcessDefinitions(childDeployment);
    try {
        ProcessInstance childProcessInstance = runtimeService.startProcessInstanceByKey("childProcess");
        fail("Exception expected");
    } catch (ActivitiException ae) {
        assertTextPresent("Cannot start process instance. Process definition Child Process", ae.getMessage());
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Aggregations

BpmnModel (org.activiti.bpmn.model.BpmnModel)149 Test (org.junit.Test)101 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)15 InputStream (java.io.InputStream)13 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Deployment (org.activiti.engine.repository.Deployment)10 Process (org.activiti.bpmn.model.Process)8 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)8 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)8 StartEvent (org.activiti.bpmn.model.StartEvent)7 ActivitiException (org.activiti.engine.ActivitiException)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 ArrayList (java.util.ArrayList)6 XMLInputFactory (javax.xml.stream.XMLInputFactory)6 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 UserTask (org.activiti.bpmn.model.UserTask)6 FlowElement (org.activiti.bpmn.model.FlowElement)5 BpmnJsonConverter (org.activiti.editor.language.json.converter.BpmnJsonConverter)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 StreamResource (com.vaadin.terminal.StreamResource)4