Package org.activiti.engine

Examples of org.activiti.engine.ProcessEngine


  @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();
  }
View Full Code Here


    // Creating the DB schema (without building a process engine)
    ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
    processEngineConfiguration.setProcessEngineName("reboot-test-schema");
    processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
    ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();
   
    // Create process engine and deploy test process
     ProcessEngine processEngine = new StandaloneProcessEngineConfiguration()
       .setProcessEngineName("reboot-test")
       .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
       .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000")
       .setJobExecutorActivate(false)
       .buildProcessEngine();
    
     processEngine.getRepositoryService()
       .createDeployment()
       .addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml")
       .deploy();
 
     // verify existance of process definiton
     List<ProcessDefinition> processDefinitions = processEngine
       .getRepositoryService()
       .createProcessDefinitionQuery()
       .list();
    
     assertEquals(1, processDefinitions.size());
    
     // Start a new Process instance
     ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
     String processInstanceId = processInstance.getId();
     assertNotNull(processInstance);
       
     // Close the process engine
     processEngine.close();
     assertNotNull(processEngine.getRuntimeService());
    
     // Reboot the process engine
     processEngine = new StandaloneProcessEngineConfiguration()
       .setProcessEngineName("reboot-test")
       .setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
       .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000")
       .setJobExecutorActivate(false)
       .buildProcessEngine();
    
     // Check if the existing process instance is still alive
     processInstance = processEngine
       .getRuntimeService()
       .createProcessInstanceQuery()
       .processInstanceId(processInstanceId)
       .singleResult();
    
     assertNotNull(processInstance);
    
     // Complete the task.  That will end the process instance
     TaskService taskService = processEngine.getTaskService();
     Task task = taskService
       .createTaskQuery()
       .list()
       .get(0);
     taskService.complete(task.getId());
    
     // Check if the process instance has really ended.  This means that the process definition has
     // re-loaded into the process definition cache
     processInstance = processEngine
       .getRuntimeService()
       .createProcessInstanceQuery()
       .processInstanceId(processInstanceId)
       .singleResult();

     assertNull(processInstance);
    
     // Extra check to see if a new process instance can be started as well
     processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
     assertNotNull(processInstance);

     // close the process engine
     processEngine.close();
     
     // Cleanup schema
     schemaProcessEngine.close();
   }
View Full Code Here

 
 
  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();
  }
View Full Code Here

        deploymentStrategies.add(new ResourceParentFolderAutoDeploymentStrategy());
    }

    @Override
    public ProcessEngine buildProcessEngine() {
        ProcessEngine processEngine = super.buildProcessEngine();
        ProcessEngines.setInitialized(true);
        autoDeployResources(processEngine);
        return processEngine;
    }
View Full Code Here

 
 
  // Engine startup and shutdown helpers  ///////////////////////////////////////////////////

  public static ProcessEngine getProcessEngine(String configurationResource) {
  ProcessEngine processEngine = processEngines.get(configurationResource);
  if (processEngine == null) {
    log.debug("==== BUILDING PROCESS ENGINE ========================================================================");
    processEngine = ProcessEngineConfiguration
    .createProcessEngineConfigurationFromResource(
      configurationResource).buildProcessEngine();
View Full Code Here

 
  protected static final Logger LOGGER = LoggerFactory.getLogger(ActivitiServletContextListener.class);

  public void contextInitialized(ServletContextEvent event) {
    LOGGER.info("Booting Activiti Process Engine");
    ProcessEngine processEngine = null;
    try {
      processEngine = ProcessEngines.getDefaultProcessEngine();
    } catch (Exception e) {
      LOGGER.error("Error starting the Activiti REST API", e);
    }
View Full Code Here

    parentPage.getToolBar().addButton(saveButton);
  }
 
  protected void initForm() {
    // Check if a start form is defined
    final ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    StartFormData startFormData = processEngine.getFormService().getStartFormData(processDefinition.getId());
   
    if(startFormData != null && ((startFormData.getFormProperties() != null && !startFormData.getFormProperties()
                                                                                             .isEmpty()) || startFormData.getFormKey() != null)) {
      processDefinitionStartForm = new FormPropertiesForm();
      detailContainer.addComponent(processDefinitionStartForm);
View Full Code Here

    public <T> T withProcessToolContextNonJta(ReturningProcessToolContextCallback<T> callback) {
        Session session = registry.getSessionFactory().openSession();
        try {
            CustomStandaloneProcessEngineConfiguration processEngineConfiguration = getProcessEngineConfiguration(session);
            ProcessEngine pi = getProcessEngine(processEngineConfiguration);
            try {
                org.hibernate.Transaction tx = session.beginTransaction();
                T res;
                try {
                    ActivitiContextImpl ctx = new ActivitiContextImpl(session, this, pi, processEngineConfiguration);
                    res = callback.processWithContext(ctx);
                } catch (RuntimeException e) {
                    logger.log(Level.SEVERE, e.getMessage(), e);
                    try {
                        tx.rollback();
                    } catch (Exception e1) {
                        logger.log(Level.WARNING, e1.getMessage(), e1);
                    }
                    throw e;
                }
                tx.commit();
                return res;
            } finally {
                pi.close();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            session.close();
View Full Code Here

            Session session = registry.getSessionFactory().getCurrentSession();
            T res;
            try {
                //init activiti
                CustomStandaloneProcessEngineConfiguration processEngineConfiguration = getProcessEngineConfiguration(session);
                ProcessEngine processEngine = getProcessEngine(processEngineConfiguration);
                try {
                    try {
                        ActivitiContextImpl ctx = new ActivitiContextImpl(session, this, processEngine, processEngineConfiguration);
                        res = callback.processWithContext(ctx);
                    } catch (Exception e) {
                        logger.log(Level.SEVERE, e.getMessage(), e);
                        try {
                            ut.rollback();
                        } catch (Exception e1) {
                            logger.log(Level.WARNING, e1.getMessage(), e1);
                        }
                        throw e;
                    }
                } finally {
                    processEngine.close();
                }
            } finally {
                session.flush();
            }
            ut.commit();
View Full Code Here

import com.cisco.surf.Console;

public class ActualTest extends TestCase{
 
  public void testWfSleep() throws Exception{
    ProcessEngine eng = ProcessEngineConfiguration
              .createStandaloneInMemProcessEngineConfiguration()
              .setJobExecutorActivate(true)
              .buildProcessEngine();
   
    System.out.println("engine version: "+eng.VERSION);
   
    RepositoryService repoSvc = eng.getRepositoryService();
    RuntimeService rtSvc = eng.getRuntimeService();
   
    String wfn = "/diagrams/Wf.bpmn";
    String wffn = wfn+"20.xml"; // workaround for http://forums.activiti.org/en/viewtopic.php?f=8&t=3745&start=10
        DeploymentBuilder db = repoSvc
                 .createDeployment()
                 .addInputStream(wffn,this.getClass().getResourceAsStream(wfn));
   
        Deployment d = db.deploy();
        ProcessDefinition pDef = repoSvc
                                 .createProcessDefinitionQuery()
                                 .deploymentId(d.getId())
                                 .singleResult();

        Map<String,Object> varMap = new HashMap<String,Object>();
        varMap.put("console",new Console());

        ProcessInstance proc = rtSvc.startProcessInstanceById(pDef.getId(),varMap);
       
        String procId = proc.getId();
        System.out.println("procId="+procId);
       
        long timeout = System.currentTimeMillis()+15*1000;
        HistoryService hstSvc = eng.getHistoryService();
        while (true){
            if (System.currentTimeMillis() > timeout) throw new TimeoutException();
            HistoricProcessInstance hProcInst = hstSvc.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
            if (hProcInst.getEndTime() != null){
                System.out.println(wfn+" ended");
View Full Code Here

TOP

Related Classes of org.activiti.engine.ProcessEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.