Search in sources :

Example 61 with BpmnModel

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

the class ProcessDefinitionImageStreamResourceBuilder method buildStreamResource.

public StreamResource buildStreamResource(String processInstanceId, String processDefinitionId, RepositoryService repositoryService, RuntimeService runtimeService, ProcessDiagramGenerator diagramGenerator, ProcessEngineConfiguration processEngineConfig) {
    StreamResource imageResource = null;
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinitionId);
    if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
        InputStream definitionImageStream = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstanceId), Collections.<String>emptyList(), processEngineConfig.getActivityFontName(), processEngineConfig.getLabelFontName(), processEngineConfig.getAnnotationFontName(), processEngineConfig.getClassLoader(), 1.0);
        StreamSource streamSource = new InputStreamStreamSource(definitionImageStream);
        // Create image name
        String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName());
        String fileName = processInstanceId + UUID.randomUUID() + "." + imageExtension;
        imageResource = new StreamResource(streamSource, fileName, ExplorerApp.get());
    }
    return imageResource;
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) InputStream(java.io.InputStream) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 62 with BpmnModel

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

the class RepositoryServiceTest method testGetBpmnModel.

@Deployment
public void testGetBpmnModel() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    // Some basic assertions
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
    assertNotNull(bpmnModel);
    assertEquals(1, bpmnModel.getProcesses().size());
    assertTrue(!bpmnModel.getLocationMap().isEmpty());
    assertTrue(!bpmnModel.getFlowLocationMap().isEmpty());
    // Test the flow
    org.activiti.bpmn.model.Process process = bpmnModel.getProcesses().get(0);
    List<StartEvent> startEvents = process.findFlowElementsOfType(StartEvent.class);
    assertEquals(1, startEvents.size());
    StartEvent startEvent = startEvents.get(0);
    assertEquals(1, startEvent.getOutgoingFlows().size());
    assertEquals(0, startEvent.getIncomingFlows().size());
    String nextElementId = startEvent.getOutgoingFlows().get(0).getTargetRef();
    UserTask userTask = (UserTask) process.getFlowElement(nextElementId);
    assertEquals("First Task", userTask.getName());
    assertEquals(1, userTask.getOutgoingFlows().size());
    assertEquals(1, userTask.getIncomingFlows().size());
    nextElementId = userTask.getOutgoingFlows().get(0).getTargetRef();
    ParallelGateway parallelGateway = (ParallelGateway) process.getFlowElement(nextElementId);
    assertEquals(2, parallelGateway.getOutgoingFlows().size());
    nextElementId = parallelGateway.getOutgoingFlows().get(0).getTargetRef();
    assertEquals(1, parallelGateway.getIncomingFlows().size());
    userTask = (UserTask) process.getFlowElement(nextElementId);
    assertEquals(1, userTask.getOutgoingFlows().size());
    nextElementId = userTask.getOutgoingFlows().get(0).getTargetRef();
    parallelGateway = (ParallelGateway) process.getFlowElement(nextElementId);
    assertEquals(1, parallelGateway.getOutgoingFlows().size());
    assertEquals(2, parallelGateway.getIncomingFlows().size());
    nextElementId = parallelGateway.getOutgoingFlows().get(0).getTargetRef();
    EndEvent endEvent = (EndEvent) process.getFlowElement(nextElementId);
    assertEquals(0, endEvent.getOutgoingFlows().size());
    assertEquals(1, endEvent.getIncomingFlows().size());
}
Also used : ParallelGateway(org.activiti.bpmn.model.ParallelGateway) StartEvent(org.activiti.bpmn.model.StartEvent) UserTask(org.activiti.bpmn.model.UserTask) EndEvent(org.activiti.bpmn.model.EndEvent) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel) Deployment(org.activiti.engine.test.Deployment)

Example 63 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel 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 64 with BpmnModel

use of org.activiti.bpmn.model.BpmnModel 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 65 with BpmnModel

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

the class DefaultProcessValidatorTest method testAllNonExecutableProcesses.

/*
	 * Test for https://activiti.atlassian.net/browse/ACT-2071:
	 * 
	 * If all processes in a deployment are not executable, throw an exception
	 * as this doesn't make sense to do.
	 */
@Test
public void testAllNonExecutableProcesses() {
    BpmnModel bpmnModel = new BpmnModel();
    for (int i = 0; i < 5; i++) {
        org.activiti.bpmn.model.Process process = TestProcessUtil.createOneTaskProcess();
        process.setExecutable(false);
        bpmnModel.addProcess(process);
    }
    List<ValidationError> errors = processValidator.validate(bpmnModel);
    Assert.assertEquals(1, errors.size());
}
Also used : ValidationError(org.activiti.validation.ValidationError) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

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