Java Code Examples for org.flowable.bpmn.model.BpmnModel#getMainProcess()

The following examples show how to use org.flowable.bpmn.model.BpmnModel#getMainProcess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventListenerConverterTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
private void validateModel(BpmnModel model) {
    Process process = model.getMainProcess();
    assertThat(process).isNotNull();
    assertThat(process.getEventListeners()).isNotNull();
    assertThat(process.getEventListeners())
            .extracting(EventListener::getEvents, EventListener::getImplementation, EventListener::getImplementationType, EventListener::getEntityType)
            .containsExactly(
                    // Listener with class
                    tuple("ENTITY_CREATE", "org.activiti.test.MyListener", ImplementationType.IMPLEMENTATION_TYPE_CLASS, null),
                    // Listener with class, but no specific event (== all events)
                    tuple(null, "org.activiti.test.AllEventTypesListener", ImplementationType.IMPLEMENTATION_TYPE_CLASS, null),
                    // Listener with delegate expression
                    tuple("ENTITY_DELETE", "${myListener}", ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION, null),
                    // Listener that throws a signal-event
                    tuple("ENTITY_DELETE", "theSignal", ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT, null),
                    // Listener that throws a global signal-event
                    tuple("ENTITY_DELETE", "theSignal", ImplementationType.IMPLEMENTATION_TYPE_THROW_GLOBAL_SIGNAL_EVENT, null),
                    // Listener that throws a message-event
                    tuple("ENTITY_DELETE", "theMessage", ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT, null),
                    // Listener that throws an error-event
                    tuple("ENTITY_DELETE", "123", ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT, null),
                    // Listener restricted to a specific entity
                    tuple("ENTITY_DELETE", "123", ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT, "job")
            );
}
 
Example 2
Source File: LaneExtensionTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testLaneExtensionElement() {
    ProcessDefinition processDefinition = activitiRule.getRepositoryService().createProcessDefinitionQuery()
            .processDefinitionKey("swimlane-extension").singleResult();
    BpmnModel bpmnModel = activitiRule.getRepositoryService().getBpmnModel(processDefinition.getId());
    byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
    System.out.println(new String(xml));
    Process bpmnProcess = bpmnModel.getMainProcess();
    for (Lane l : bpmnProcess.getLanes()) {
        Map<String, List<ExtensionElement>> extensions = l.getExtensionElements();
        Assert.assertTrue(extensions.size() > 0);
    }
}
 
Example 3
Source File: BpmnParseTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testParseDiagramInterchangeElementsForUnknownModelElements() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("TestAnnotation").singleResult();
    BpmnModel model = repositoryService.getBpmnModel(processDefinition.getId());
    Process mainProcess = model.getMainProcess();
    assertEquals(0, mainProcess.getExtensionElements().size());
}
 
Example 4
Source File: LaneExtensionTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testLaneExtensionElement() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("swimlane-extension").singleResult();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
    byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
    Process bpmnProcess = bpmnModel.getMainProcess();
    for (Lane l : bpmnProcess.getLanes()) {
        Map<String, List<ExtensionElement>> extensions = l.getExtensionElements();
        assertThat(extensions).isNotEmpty();
    }
}
 
Example 5
Source File: BpmnParseTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testParseDiagramInterchangeElementsForUnknownModelElements() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("TestAnnotation").singleResult();
    BpmnModel model = repositoryService.getBpmnModel(processDefinition.getId());
    Process mainProcess = model.getMainProcess();
    assertEquals(0, mainProcess.getExtensionElements().size());
}
 
Example 6
Source File: CustomNamespaceAttributeConverterTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private void validateModel(BpmnModel model) {
    Process process = model.getMainProcess();
    assertThat(process.getAttributes()).isNotNull();
    List<ExtensionAttribute> attributes = process.getAttributes().get("version");
    // custom:version = "9"
    assertThat(attributes)
            .extracting(ExtensionAttribute::getNamespace, ExtensionAttribute::getNamespacePrefix, ExtensionAttribute::getName, ExtensionAttribute::getValue)
            .containsExactly(tuple("http://custom.org/bpmn", "custom", "version", "9"));

    FlowElement flowElement = model.getMainProcess().getFlowElement("usertask");
    assertThat(flowElement).isInstanceOf(UserTask.class);
    assertThat(flowElement.getId()).isEqualTo("usertask");
    assertThat(flowElement.getName()).isEqualTo("User Task");
    UserTask userTask = (UserTask) flowElement;

    Map<String, List<ExtensionAttribute>> attributesMap = userTask.getAttributes();
    assertThat(attributesMap).isNotNull();
    assertThat(attributesMap).hasSize(2);

    attributes = attributesMap.get("id");
    assertThat(attributes)
            .extracting(ExtensionAttribute::getName, ExtensionAttribute::getValue, ExtensionAttribute::getNamespacePrefix, ExtensionAttribute::getNamespace)
            .containsExactly(tuple("id", "test", "custom2", "http://custom2.org/bpmn"));

    attributes = attributesMap.get("attr");
    assertThat(attributes)
            .extracting(ExtensionAttribute::getName, ExtensionAttribute::getValue, ExtensionAttribute::getNamespacePrefix, ExtensionAttribute::getNamespace)
            .containsExactly(tuple("attr", "attrValue", "custom2", "http://custom2.org/bpmn"));
}
 
Example 7
Source File: ModelImportResource.java    From plumdo-work with Apache License 2.0 4 votes vote down vote up
@PostMapping(value = "/models/import", name = "流程模型导入")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public ModelResponse importModel(HttpServletRequest request) {
    if (!(request instanceof MultipartHttpServletRequest)) {
        exceptionFactory.throwIllegalArgument(ErrorConstant.REQUEST_NOT_MULTIPART);
    }

    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;

    if (multipartRequest.getFileMap().size() == 0) {
        exceptionFactory.throwIllegalArgument(ErrorConstant.MULTIPART_CONTENT_EMPTY);
    }

    MultipartFile file = multipartRequest.getFileMap().values().iterator().next();

    String fileName = file.getOriginalFilename();
    if (fileName == null || (!fileName.endsWith(".bpmn") && !fileName.endsWith(".bpmn20.xml"))) {
        exceptionFactory.throwIllegalArgument(ErrorConstant.FILE_NOT_BPMN, fileName);
    }
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        InputStreamReader xmlIn = new InputStreamReader(file.getInputStream(), "UTF-8");
        XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn);
        BpmnModel bpmnModel = bpmnXmlConverter.convertToBpmnModel(xtr);
        if (ObjectUtils.isEmpty(bpmnModel.getProcesses())) {
            exceptionFactory.throwObjectNotFound(ErrorConstant.MODEL_NOT_FOUND_PROCESS, fileName);
        }
        Process process = bpmnModel.getMainProcess();
        Model modelData = repositoryService.newModel();
        modelData.setKey(process.getId());
        Model lastModel = repositoryService.createModelQuery().modelKey(modelData.getKey()).latestVersion().singleResult();
        if (lastModel == null) {
            modelData.setVersion(TableConstant.MODEL_VESION_START);
        } else {
            modelData.setVersion(lastModel.getVersion() + 1);
        }
        if (ObjectUtils.isNotEmpty(process.getName())) {
            modelData.setName(process.getName());
        } else {
            modelData.setName(process.getId());
        }
        ObjectNode metaInfo = new ObjectMapper().createObjectNode();
        metaInfo.put("name", modelData.getName());
        metaInfo.put("description", process.getDocumentation());
        modelData.setMetaInfo(metaInfo.toString());
        repositoryService.saveModel(modelData);
        managementService.executeCommand(new SaveModelEditorCmd(modelData.getId(), bpmnJsonConverter.convertToJson(bpmnModel).toString()));
        return restResponseFactory.createModelResponse(modelData);
    } catch (Exception e) {
        logger.error("导入流程文件异常", e);
        exceptionFactory.throwDefinedException(ErrorConstant.MODEL_IMPORT_FILE_ERROR, fileName, e.getMessage());
    }
    return null;
}
 
Example 8
Source File: CustomExtensionsConverterTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void validateModel(BpmnModel model) {
    Process process = model.getMainProcess();
    assertThat(process.getAttributes()).hasSize(1);
    List<ExtensionAttribute> attributes = process.getAttributes().get("version");
    assertThat(attributes).isNotNull();
    // custom:version = "9"
    assertThat(attributes)
            .extracting(ExtensionAttribute::getNamespace, ExtensionAttribute::getNamespacePrefix, ExtensionAttribute::getName, ExtensionAttribute::getValue)
            .containsExactly(tuple("http://custom.org/bpmn", "custom", "version", "9"));

    List<FlowableListener> listeners = model.getMainProcess().getExecutionListeners();
    validateExecutionListeners(listeners);
    Map<String, List<ExtensionElement>> extensionElementMap = model.getMainProcess().getExtensionElements();
    validateExtensionElements(extensionElementMap);

    FlowElement flowElement = model.getMainProcess().getFlowElement("servicetask");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(ServiceTask.class);
    assertThat(flowElement.getId()).isEqualTo("servicetask");
    ServiceTask serviceTask = (ServiceTask) flowElement;
    assertThat(serviceTask.getId()).isEqualTo("servicetask");
    assertThat(serviceTask.getName()).isEqualTo("Service task");

    List<FieldExtension> fields = serviceTask.getFieldExtensions();
    assertThat(fields)
            .extracting(FieldExtension::getFieldName, FieldExtension::getStringValue, FieldExtension::getExpression)
            .containsExactly(
                    tuple("testField", "test", null),
                    tuple("testField2", null, "${test}")
            );

    listeners = serviceTask.getExecutionListeners();
    validateExecutionListeners(listeners);

    extensionElementMap = serviceTask.getExtensionElements();
    validateExtensionElements(extensionElementMap);

    assertThat(serviceTask.getBoundaryEvents()).hasSize(1);
    BoundaryEvent boundaryEvent = serviceTask.getBoundaryEvents().get(0);
    assertThat(boundaryEvent.getId()).isEqualTo("timerEvent");
    assertThat(boundaryEvent.getEventDefinitions()).hasSize(1);
    assertThat(boundaryEvent.getEventDefinitions().get(0)).isInstanceOf(TimerEventDefinition.class);
    extensionElementMap = boundaryEvent.getEventDefinitions().get(0).getExtensionElements();
    validateExtensionElements(extensionElementMap);
}
 
Example 9
Source File: SubProcessMultiDiagramConverterTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void validateModel(BpmnModel model) {
    Process process = model.getMainProcess();
    Collection<Artifact> artifacts = process.getArtifacts();
    List<ValuedDataObject> dataObjects = process.getDataObjects();

    // verify main process
    assertThat(process.getFlowElements()).hasSize(13);
    assertThat(artifacts).hasSize(2);
    assertThat(dataObjects).hasSize(6);

    Artifact artifact = artifacts.iterator().next();
    assertThat(artifact)
            .isInstanceOfSatisfying(TextAnnotation.class, art -> {
                assertThat(art.getId()).isEqualTo("textannotation1");
                assertThat(art.getText()).isEqualTo("Test Annotation");
            });

    FlowElement flowElement = process.getFlowElement("start1");
    assertThat(flowElement)
            .isInstanceOfSatisfying(StartEvent.class, startEvent -> {
                assertThat(startEvent.getId()).isEqualTo("start1");
            });

    flowElement = process.getFlowElement("userTask1");
    assertThat(flowElement)
            .isInstanceOfSatisfying(UserTask.class, userTask -> {
                assertThat(userTask.getName()).isEqualTo("User task 1");
                assertThat(userTask.getCandidateUsers()).hasSize(1);
                assertThat(userTask.getCandidateGroups()).hasSize(1);
            });

    flowElement = process.getFlowElement("subprocess1");
    assertThat(flowElement)
            .isInstanceOfSatisfying(SubProcess.class, subProcess -> {
                assertThat(subProcess.getId()).isEqualTo("subprocess1");
                assertThat(subProcess.getFlowElements()).hasSize(11);

                // verify subprocess
                assertThat(subProcess.getArtifacts()).hasSize(2);
                assertThat(subProcess.getDataObjects()).hasSize(6);

                assertThat(subProcess.getArtifacts().iterator().next())
                        .isInstanceOfSatisfying(TextAnnotation.class, art -> {
                            assertThat(art.getId()).isEqualTo("textannotation2");
                            assertThat(art.getText()).isEqualTo("Sub Test Annotation");
                        });

                assertThat(subProcess.getFlowElement("subStartEvent"))
                        .isInstanceOfSatisfying(StartEvent.class, startEvent -> {
                            assertThat(startEvent.getId()).isEqualTo("subStartEvent");
                        });

                assertThat(subProcess.getFlowElement("subUserTask1"))
                        .isInstanceOfSatisfying(UserTask.class, userTask -> {
                            assertThat(userTask.getName()).isEqualTo("User task 2");
                            assertThat(userTask.getCandidateUsers()).isEmpty();
                            assertThat(userTask.getCandidateGroups()).isEmpty();
                        });
            });
}
 
Example 10
Source File: BpmnModelWithDataObjectTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void convertModelToXML() throws Exception {
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId("myProcess");
    bpmnModel.addProcess(process);
    
    List<ValuedDataObject> dataObjects = new ArrayList<>();
    StringDataObject dataObject = new StringDataObject();
    dataObject.setId("dObj1");
    dataObject.setName("stringDataObject");
    dataObject.setValue("test");
    ItemDefinition itemDefinition = new ItemDefinition();
    itemDefinition.setStructureRef("xsd:string");
    dataObject.setItemSubjectRef(itemDefinition);
    dataObjects.add(dataObject);
    process.setDataObjects(dataObjects);
    process.addFlowElement(dataObject);
    
    StartEvent startEvent = new StartEvent();
    startEvent.setId("event1");
    
    EndEvent endEvent = new EndEvent();
    endEvent.setId("event2");
    
    SequenceFlow flow = new SequenceFlow("event1", "event2");
    
    process.addFlowElement(startEvent);
    process.addFlowElement(endEvent);
    process.addFlowElement(flow);
    
    BpmnModel parsedModel = exportAndReadXMLFile(bpmnModel);
    
    Process mainProcess = parsedModel.getMainProcess();

    // verify the main process data objects
    List<ValuedDataObject> processDataObjects = mainProcess.getDataObjects();
    assertThat(processDataObjects).hasSize(1);

    Map<String, ValuedDataObject> objectMap = new HashMap<>();
    for (ValuedDataObject valueObj : dataObjects) {
        objectMap.put(valueObj.getId(), valueObj);
    }

    ValuedDataObject dataObj = objectMap.get("dObj1");
    assertThat(dataObj.getId()).isEqualTo("dObj1");
    assertThat(dataObj.getName()).isEqualTo("stringDataObject");
    assertThat(dataObj.getItemSubjectRef().getStructureRef()).isEqualTo("xsd:string");
    assertThat(dataObj.getValue()).isEqualTo("test");
}