Search in sources :

Example 6 with RepositoryService

use of org.activiti.engine.RepositoryService in project Activiti by Activiti.

the class ProcessDefinitionInfoCacheTest method testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.

public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {
    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test-schema").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService1 = processEngine1.getRepositoryService();
    ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(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/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();
    // Start process instance on second engine
    String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceById(processDefinitionId);
    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").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();
}
Also used : Task(org.activiti.engine.task.Task) StandaloneProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 7 with RepositoryService

use of org.activiti.engine.RepositoryService in project Activiti by Activiti.

the class PlaybackProcessStartTest method demoCheckStatus.

public void demoCheckStatus() {
    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());
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RepositoryService(org.activiti.engine.RepositoryService)

Example 8 with RepositoryService

use of org.activiti.engine.RepositoryService in project Activiti by Activiti.

the class MuleVMTest method send.

@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").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();
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Example 9 with RepositoryService

use of org.activiti.engine.RepositoryService in project Activiti by Activiti.

the class Extender method checkBundle.

private void checkBundle(Bundle bundle) {
    LOGGER.debug("Scanning bundle {} for activiti process", bundle.getSymbolicName());
    try {
        List<URL> pathList = new ArrayList<URL>();
        String activitiHeader = (String) bundle.getHeaders().get(BUNDLE_ACTIVITI_HEADER);
        if (activitiHeader == null) {
            activitiHeader = "OSGI-INF/activiti/";
        }
        List<PathElement> paths = HeaderParser.parseHeader(activitiHeader);
        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 activiti 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 activiti process found in bundle {}", bundle.getSymbolicName());
        }
    } catch (Throwable t) {
        LOGGER.error("Unable to deploy activiti bundle", t);
    }
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) PathElement(org.activiti.osgi.HeaderParser.PathElement) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 10 with RepositoryService

use of org.activiti.engine.RepositoryService in project bamboobsc by billchen198318.

the class TestBPMN001 method queryProcessDefinition.

@Test
public void queryProcessDefinition() throws Exception {
    RepositoryService repositoryService = (RepositoryService) AppContext.getBean("repositoryService");
    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
    List<ProcessDefinition> processDefs = processDefinitionQuery.processDefinitionKey("Employee360DegreeFeedbackProjectPublishProcess").orderByProcessDefinitionVersion().desc().list();
    for (ProcessDefinition pd : processDefs) {
        System.out.println(pd.getId() + " , " + pd.getName() + " , " + pd.getKey() + " , " + pd.getVersion());
        ProcessDefinitionImpl pdObj = (ProcessDefinitionImpl) repositoryService.getProcessDefinition(pd.getId());
        System.out.println(pdObj.getActivities());
    }
}
Also used : ProcessDefinitionImpl(org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Aggregations

RepositoryService (org.activiti.engine.RepositoryService)16 Test (org.junit.Test)8 ProcessEngine (org.activiti.engine.ProcessEngine)7 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)5 RuntimeService (org.activiti.engine.RuntimeService)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)3 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)3 FileInputStream (java.io.FileInputStream)2 URL (java.net.URL)2 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)2 TaskService (org.activiti.engine.TaskService)2 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)2 Deployment (org.activiti.engine.repository.Deployment)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Task (org.activiti.engine.task.Task)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1