Java Code Examples for org.flowable.engine.ProcessEngine#getRepositoryService()

The following examples show how to use org.flowable.engine.ProcessEngine#getRepositoryService() . 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: MuleVMTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void send() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deployment = repositoryService.createDeployment()
            .addClasspathResource("org/activiti/mule/testVM.bpmn20.xml")
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(30, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");

    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    repositoryService.deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
Example 2
Source File: SingleResourceAutoDeploymentStrategy.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void deployResourcesInternal(String deploymentNameHint, Resource[] resources, ProcessEngine engine) {
    // Create a separate deployment for each resource using the resource name
    RepositoryService repositoryService = engine.getRepositoryService();

    for (final Resource resource : resources) {

        final String resourceName = determineResourceName(resource);
        final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(resourceName);
        addResource(resource, resourceName, deploymentBuilder);
        try {
            deploymentBuilder.deploy();
        } catch (RuntimeException e) {
            if (isThrowExceptionOnDeploymentFailure()) {
                throw e;
            } else {
                LOGGER.warn(
                    "Exception while autodeploying process definitions for resource {}. This exception can be ignored if the root cause indicates a unique constraint violation, which is typically caused by two (or more) servers booting up at the exact same time and deploying the same definitions. ",
                    resource, e);
            }
        }
    }
}
 
Example 3
Source File: DefaultAutoDeploymentStrategy.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void deployResourcesInternal(String deploymentNameHint, Resource[] resources, ProcessEngine engine) {
    RepositoryService repositoryService = engine.getRepositoryService();

    // Create a single deployment for all resources using the name hint as the literal name
    final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentNameHint);

    for (final Resource resource : resources) {
        addResource(resource, deploymentBuilder);
    }

    try {
        deploymentBuilder.deploy();
    } catch (RuntimeException e) {
        if (isThrowExceptionOnDeploymentFailure()) {
            throw e;
        } else {
            LOGGER.warn("Exception while autodeploying process definitions. "
                + "This exception can be ignored if the root cause indicates a unique constraint violation, "
                + "which is typically caused by two (or more) servers booting up at the exact same time and deploying the same definitions. ", e);
        }
    }

}
 
Example 4
Source File: MuleVMTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void send() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deployment = repositoryService.createDeployment().addClasspathResource("org/flowable/mule/testVM.bpmn20.xml").deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(30, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");

    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    repositoryService.deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
Example 5
Source File: PlaybackRunTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private void checkStatus(ProcessEngine processEngine) {
    HistoryService historyService = processEngine.getHistoryService();
    final HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().finished().includeProcessVariables().singleResult();
    assertNotNull(historicProcessInstance);
    RepositoryService repositoryService = processEngine.getRepositoryService();
    final ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult();
    assertEquals(SIMPLEST_PROCESS, processDefinition.getKey());

    assertEquals(1, historicProcessInstance.getProcessVariables().size());
    assertEquals(TEST_VALUE, historicProcessInstance.getProcessVariables().get(TEST_VARIABLE));
    assertEquals(BUSINESS_KEY, historicProcessInstance.getBusinessKey());
}
 
Example 6
Source File: AbstractFlowableTestCase.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public final void initializeServices(ProcessEngine processEngine) {
    processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
    this.processEngine = processEngine;
    repositoryService = processEngine.getRepositoryService();
    runtimeService = processEngine.getRuntimeService();
    taskService = processEngine.getTaskService();
    formService = processEngine.getFormService();
    historyService = processEngine.getHistoryService();
    identityService = processEngine.getIdentityService();
    managementService = processEngine.getManagementService();
    dynamicBpmnService = processEngine.getDynamicBpmnService();
    processMigrationService = processEngine.getProcessMigrationService();
}
 
Example 7
Source File: ResourceParentFolderAutoDeploymentStrategy.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void deployResourcesInternal(String deploymentNameHint, Resource[] resources, ProcessEngine engine) {

    RepositoryService repositoryService = engine.getRepositoryService();
    // Create a deployment for each distinct parent folder using the namehint as a prefix
    final Map<String, Set<Resource>> resourcesMap = createMap(resources);
    for (final Entry<String, Set<Resource>> group : resourcesMap.entrySet()) {

        final String deploymentName = determineDeploymentName(deploymentNameHint, group.getKey());
        final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentName);

        for (final Resource resource : group.getValue()) {
            addResource(resource, deploymentBuilder);
        }

        try {
            deploymentBuilder.deploy();
        } catch (Exception e) {
            if (isThrowExceptionOnDeploymentFailure()) {
                throw e;
            } else {
                LOGGER.warn("Exception while autodeploying process definitions. "
                    + "This exception can be ignored if the root cause indicates a unique constraint violation, "
                    + "which is typically caused by two (or more) servers booting up at the exact same time and deploying the same definitions. ", e);
            }
        }
    }

}
 
Example 8
Source File: SpringJmsConfig.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
    return processEngine.getRepositoryService();
}
 
Example 9
Source File: EngineConfiguration.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
    return processEngine.getRepositoryService();
}
 
Example 10
Source File: BpmnEngineTestConfiguration.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
    return processEngine.getRepositoryService();
}
 
Example 11
Source File: ProcessDefinitionCacheTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {

    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test-schema")
            .setDatabaseSchemaUpdate(org.flowable.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000")
            .setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService1 = processEngine1.getRepositoryService();

    ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test")
            .setDatabaseSchemaUpdate(org.flowable.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000")
            .setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService2 = processEngine2.getRepositoryService();
    RuntimeService runtimeService2 = processEngine2.getRuntimeService();
    TaskService taskService2 = processEngine2.getTaskService();

    // Deploy first version of process: start->originalTask->end on first
    // process engine
    String deploymentId = repositoryService1.createDeployment().addClasspathResource("org/flowable/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();

    // Start process instance on second engine
    String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceById(processDefinitionId);
    org.flowable.task.api.Task task = taskService2.createTaskQuery().singleResult();
    assertEquals("original task", task.getName());

    // Delete the deployment on second process engine
    repositoryService2.deleteDeployment(deploymentId, true);
    assertEquals(0, repositoryService2.createDeploymentQuery().count());
    assertEquals(0, runtimeService2.createProcessInstanceQuery().count());

    // deploy a revised version of the process: start->revisedTask->end on first process engine
    //
    // Before the bugfix, this would set the cache on the first process
    // engine, but the second process engine still has the original process
    // definition in his cache. Since there is a deployment delete in between, the new generated
    // process definition id is the same as in the original deployment, making the second process engine using
    // the old cached process definition.
    deploymentId = repositoryService1.createDeployment().addClasspathResource("org/flowable/engine/test/cache/revisedProcess.bpmn20.xml").deploy().getId();

    // Start process instance on second process engine -> must use revised process definition
    repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceByKey("oneTaskProcess");
    task = taskService2.createTaskQuery().singleResult();
    assertEquals("revised task", task.getName());

    // cleanup
    repositoryService1.deleteDeployment(deploymentId, true);
    processEngine1.close();
    processEngine2.close();
}
 
Example 12
Source File: SpringJunitJupiterTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
    return processEngine.getRepositoryService();
}
 
Example 13
Source File: SpringAutoDeployTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
    return processEngine.getRepositoryService();
}
 
Example 14
Source File: EngineConfiguration.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
    return processEngine.getRepositoryService();
}
 
Example 15
Source File: JPAFlowableEngineConfiguration.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
    return processEngine.getRepositoryService();
}
 
Example 16
Source File: ProcessEngineServicesAutoConfiguration.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public RepositoryService repositoryServiceBean(ProcessEngine processEngine) {
    return processEngine.getRepositoryService();
}
 
Example 17
Source File: ProcessDefinitionCacheTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {

        // Setup both process engines
        StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration();
        standaloneProcessEngineConfiguration.setEngineName("reboot-test-schema");
        standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000");
        standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false);
        standaloneProcessEngineConfiguration.setFlowable5CompatibilityEnabled(true);
        ProcessEngine processEngine1 = standaloneProcessEngineConfiguration.buildProcessEngine();
        RepositoryService repositoryService1 = processEngine1.getRepositoryService();

        StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration2 = new StandaloneProcessEngineConfiguration();
        standaloneProcessEngineConfiguration2.setEngineName("reboot-test");
        standaloneProcessEngineConfiguration2.setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
        standaloneProcessEngineConfiguration2.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000");
        standaloneProcessEngineConfiguration2.setAsyncExecutorActivate(false);
        standaloneProcessEngineConfiguration2.setFlowable5CompatibilityEnabled(true);
        ProcessEngine processEngine2 = standaloneProcessEngineConfiguration2.buildProcessEngine();
        RepositoryService repositoryService2 = processEngine2.getRepositoryService();
        RuntimeService runtimeService2 = processEngine2.getRuntimeService();
        TaskService taskService2 = processEngine2.getTaskService();

        // Deploy first version of process: start->originalTask->end on first process engine
        String deploymentId = repositoryService1.createDeployment()
                .addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml")
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
                .deploy()
                .getId();

        // Start process instance on second engine
        String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
        runtimeService2.startProcessInstanceById(processDefinitionId);
        org.flowable.task.api.Task task = taskService2.createTaskQuery().singleResult();
        assertEquals("original task", task.getName());

        // Delete the deployment on second process engine
        repositoryService2.deleteDeployment(deploymentId, true);
        assertEquals(0, repositoryService2.createDeploymentQuery().count());
        assertEquals(0, runtimeService2.createProcessInstanceQuery().count());

        // deploy a revised version of the process: start->revisedTask->end on first process engine
        //
        // Before the bugfix, this would set the cache on the first process engine,
        // but the second process engine still has the original process definition in his cache.
        // Since there is a deployment delete in between, the new generated process definition id is the same
        // as in the original deployment, making the second process engine using the old cached process definition.
        deploymentId = repositoryService1.createDeployment()
                .addClasspathResource("org/activiti/engine/test/cache/revisedProcess.bpmn20.xml")
                .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
                .deploy()
                .getId();

        // Start process instance on second process engine -> must use revised process definition
        repositoryService2.createProcessDefinitionQuery().singleResult().getId();
        runtimeService2.startProcessInstanceByKey("oneTaskProcess");
        task = taskService2.createTaskQuery().singleResult();
        assertEquals("revised task", task.getName());

        // cleanup
        repositoryService1.deleteDeployment(deploymentId, true);
        processEngine1.close();
        processEngine2.close();
    }
 
Example 18
Source File: Extender.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void checkBundle(Bundle bundle) {
    LOGGER.debug("Scanning bundle {} for flowable process", bundle.getSymbolicName());
    try {
        List<URL> pathList = new ArrayList<>();
        String flowableHeader = bundle.getHeaders().get(BUNDLE_FLOWABLE_HEADER);
        if (flowableHeader == null) {
            flowableHeader = "OSGI-INF/flowable/";
        }
        List<PathElement> paths = HeaderParser.parseHeader(flowableHeader);
        for (PathElement path : paths) {
            String name = path.getName();
            if (name.endsWith("/")) {
                addEntries(bundle, name, "*.*", pathList);
            } else {
                String baseName;
                String filePattern;
                int pos = name.lastIndexOf('/');
                if (pos < 0) {
                    baseName = "/";
                    filePattern = name;
                } else {
                    baseName = name.substring(0, pos + 1);
                    filePattern = name.substring(pos + 1);
                }
                if (hasWildcards(filePattern)) {
                    addEntries(bundle, baseName, filePattern, pathList);
                } else {
                    addEntry(bundle, name, pathList);
                }
            }
        }

        if (!pathList.isEmpty()) {
            LOGGER.debug("Found flowable process in bundle {} with paths: {}", bundle.getSymbolicName(), pathList);

            ProcessEngine engine = (ProcessEngine) engineServiceTracker.waitForService(timeout);
            if (engine == null) {
                throw new IllegalStateException("Unable to find a ProcessEngine service");
            }

            RepositoryService service = engine.getRepositoryService();
            DeploymentBuilder builder = service.createDeployment();
            builder.name(bundle.getSymbolicName());
            for (URL url : pathList) {
                InputStream is = url.openStream();
                if (is == null) {
                    throw new IOException("Error opening url: " + url);
                }
                try {
                    builder.addInputStream(getPath(url), is);
                } finally {
                    is.close();
                }
            }
            builder.enableDuplicateFiltering();
            builder.deploy();
        } else {
            LOGGER.debug("No flowable process found in bundle {}", bundle.getSymbolicName());
        }
    } catch (Throwable t) {
        LOGGER.error("Unable to deploy flowable bundle", t);
    }
}