Java Code Examples for org.activiti.engine.ProcessEngine

The following examples show how to use org.activiti.engine.ProcessEngine. These examples are extracted from open source projects. 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 Project: CrazyWorkflowHandoutsActiviti6   Source File: SaveGroup.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	
	IdentityService identityService = engine.getIdentityService();
	
	Random ran = new Random(10);
	for (int i = 0; i < 10; i++) {
		Group group = identityService.newGroup(String.valueOf(i));
		group.setName("Group_" + ran.nextInt(10));
		group.setType("TYPE_" + ran.nextInt(10));
		identityService.saveGroup(group);
	}

	// 关闭流程引擎
	engine.close();
}
 
Example 2
public static void main(String[] args) throws Exception {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	// 存储服务
	RepositoryService repositoryService = engine.getRepositoryService();
	// 新建部署构造器
	DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
	// 新建文件输入流
	FileInputStream fileInputStream = new FileInputStream(new File("resources/datas.zip"));
	// 新建Zip输入流
	ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
	// 将Zip输入流添加到部署构造器中
	deploymentBuilder.addZipInputStream(zipInputStream);
	// 发布部署构造器
	deploymentBuilder.deploy();
	// 关闭流程引擎
	engine.close();
}
 
Example 3
Source Project: CrazyWorkflowHandoutsActiviti6   Source File: SchemaErrorTest.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) {           
// 新建流程引擎
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
// 存储服务
RepositoryService repositoryService = engine.getRepositoryService();
// 新建部署构造器
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
// 增加错误的schema文件(包括无效的标签)<test>test</test> 
// 校验报错:发现了以元素 'test' 开头的无效内容。
deploymentBuilder.addClasspathResource("error/schema_error.bpmn");
// 禁用Schema验证
deploymentBuilder.disableSchemaValidation();
// 发布部署构造器
deploymentBuilder.deploy();
// 关闭流程引擎
engine.close();
  }
 
Example 4
Source Project: CrazyWorkflowHandoutsActiviti6   Source File: SortGroup.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

	IdentityService identityService = engine.getIdentityService();

	List<Group> groups = identityService.createGroupQuery()
			.orderByGroupName().desc().list();

	for (Group group : groups) {
		System.out.println(group.getId() + "---" + group.getName() + "---"
				+ group.getType());
	}

	// 关闭流程引擎
	engine.close();
}
 
Example 5
Source Project: activiti6-boot2   Source File: DbSqlSession.java    License: Apache License 2.0 6 votes vote down vote up
protected boolean isUpgradeNeeded(String versionInDatabase) {
  if (ProcessEngine.VERSION.equals(versionInDatabase)) {
    return false;
  }

  String cleanDbVersion = getCleanVersion(versionInDatabase);
  String[] cleanDbVersionSplitted = cleanDbVersion.split("\\.");
  int dbMajorVersion = Integer.valueOf(cleanDbVersionSplitted[0]);
  int dbMinorVersion = Integer.valueOf(cleanDbVersionSplitted[1]);

  String cleanEngineVersion = getCleanVersion(ProcessEngine.VERSION);
  String[] cleanEngineVersionSplitted = cleanEngineVersion.split("\\.");
  int engineMajorVersion = Integer.valueOf(cleanEngineVersionSplitted[0]);
  int engineMinorVersion = Integer.valueOf(cleanEngineVersionSplitted[1]);

  if ((dbMajorVersion > engineMajorVersion) || ((dbMajorVersion <= engineMajorVersion) && (dbMinorVersion > engineMinorVersion))) {
    throw new ActivitiException("Version of activiti database (" + versionInDatabase + ") is more recent than the engine (" + ProcessEngine.VERSION + ")");
  } else if (cleanDbVersion.compareTo(cleanEngineVersion) == 0) {
    // Versions don't match exactly, possibly snapshot is being used
    log.warn("Engine-version is the same, but not an exact match: {} vs. {}. Not performing database-upgrade.", versionInDatabase, ProcessEngine.VERSION);
    return false;
  }
  return true;
}
 
Example 6
Source Project: activiti6-boot2   Source File: MuleVMTest.java    License: 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/activiti5/mule/testVM.bpmn20.xml")
      .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_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 7
@Test
public void testLaunchingGatewayProcessDefinition() throws Exception {
    AnnotationConfigApplicationContext applicationContext = this.context(InboundGatewayConfiguration.class);
    
    RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
    RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
    ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);

    Assert.assertNotNull("the process engine should not be null", processEngine);
    Assert.assertNotNull("we should have a default repositoryService included", repositoryService);
    String integrationGatewayProcess = "integrationGatewayProcess";
    List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey(integrationGatewayProcess)
            .list();
    ProcessDefinition processDefinition = processDefinitionList.iterator().next();
    Assert.assertEquals(processDefinition.getKey(), integrationGatewayProcess);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("customerId", 232);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(integrationGatewayProcess, vars);
    Assert.assertNotNull("the processInstance should not be null", processInstance);
    org.junit.Assert.assertTrue(
            applicationContext.getBean(InboundGatewayConfiguration.AnalysingService.class)
                    .getStringAtomicReference().get().equals(projectId));
}
 
Example 8
@Override
public void onProcessEngineClosed(ProcessEngine processEngine) {
  LOG.info("--------------------- Callback for engine end");
  if (dataSource != null) {
    LOG.info("--------------------- Closing datasource");
    dataSource.close();
  }

  if (transactionManager != null) {
    transactionManager.shutdown();
  }
}
 
Example 9
Source Project: activiti-in-action-codes   Source File: ActivitiUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 单例模式获取引擎对象
 */
public static ProcessEngine getProcessEngine() {
    if (processEngine == null) {
  /*
   * 使用默认的配置文件名称(activiti.cfg.xml)创建引擎对象
   */
        processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault().buildProcessEngine();
    }
    return processEngine;
}
 
Example 10
@Test
public void testService() throws Exception {
    assertNotNull(runtimeService);

    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
}
 
Example 11
@Test
public void testService() throws Exception {
    assertNotNull(runtimeService);

    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
}
 
Example 12
Source Project: tutorials   Source File: ProcessEngineCreationIntegrationTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenDifferentNameXMLConfig_whenGetProcessEngineConfig_thenGotResult() {
    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("my.activiti.cfg.xml");
    ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
    assertNotNull(processEngine);
    assertEquals("baeldung", processEngine.getProcessEngineConfiguration().getJdbcUsername());
}
 
Example 13
Source Project: CrazyWorkflowHandoutsActiviti6   Source File: ImageQueryTest.java    License: MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	// 创建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	// 得到流程存储服务对象
	RepositoryService repositoryService = engine.getRepositoryService();
	// 部署一份流程文件与相应的流程图文件
	Deployment dep = repositoryService.createDeployment()
			.addClasspathResource("MyFirstProcess.bpmn").deploy();
	// 查询流程定义
	ProcessDefinition def = repositoryService
			.createProcessDefinitionQuery().deploymentId(dep.getId())
			.singleResult();
	// 查询资源文件
	InputStream is = repositoryService.getProcessDiagram(def.getId());
	// 将输入流转换为图片对象
	BufferedImage image = ImageIO.read(is);
	// 保存为图片文件
	File file = new File("resources/result.png");
	if (!file.exists()) {
		file.createNewFile();
	}
	FileOutputStream fos = new FileOutputStream(file);
	ImageIO.write(image, "png", fos);
	fos.close();
	is.close();
	// 关闭流程引擎
	engine.close();
}
 
Example 14
Source Project: opscenter   Source File: ModelTest.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping("create")
public void createModel(HttpServletRequest request, HttpServletResponse response){
    try{
        String modelName = "modelName";
        String modelKey = "modelKey";
        String description = "description";

        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        RepositoryService repositoryService = processEngine.getRepositoryService();

        ObjectMapper objectMapper = new ObjectMapper();
        ObjectNode editorNode = objectMapper.createObjectNode();
        editorNode.put("id", "canvas");
        editorNode.put("resourceId", "canvas");
        ObjectNode stencilSetNode = objectMapper.createObjectNode();
        stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
        editorNode.put("stencilset", stencilSetNode);
        Model modelData = repositoryService.newModel();

        ObjectNode modelObjectNode = objectMapper.createObjectNode();
        modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, modelName);
        modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
        modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
        modelData.setMetaInfo(modelObjectNode.toString());
        modelData.setName(modelName);
        modelData.setKey(modelKey);

        //保存模型
        repositoryService.saveModel(modelData);
        repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
        response.sendRedirect(request.getContextPath() + "/modeler.html?modelId=" + modelData.getId());
    }catch (Exception e){
    }
}
 
Example 15
Source Project: CrazyWorkflowHandoutsActiviti6   Source File: ListGroup.java    License: MIT License 5 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	
	IdentityService identityService = engine.getIdentityService();
	
	List<Group> groups = identityService.createGroupQuery().list();
	
	for (Group group : groups) {
		System.out.println(group.getId() + "---" + group.getName() + "---" + group.getType());
	}		

	// 关闭流程引擎
	engine.close();
}
 
Example 16
/**
 * 此测试会失败,因为本例没有配置oracle驱动
 */
@Test
public void specialName() {
    ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault().setProcessEngineName("oracleEngine").setJdbcDriver("oracle.jdbc.Driver")
            .setJdbcUrl("jdbc:oracle:thin:@localhost:1521:XE").setJdbcUsername("dbusername").setJdbcPassword("password").setDatabaseType("oracle")
            .buildProcessEngine();
    ProcessEngine oracleEngine = ProcessEngines.getProcessEngine("oracleEngine");
    assertNotNull(oracleEngine);
}
 
Example 17
Source Project: activiti-in-action-codes   Source File: ActivitiUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 单例模式获取引擎对象
 */
public static ProcessEngine getProcessEngine() {
    if (processEngine == null) {
  /*
   * 使用默认的配置文件名称(activiti.cfg.xml)创建引擎对象
   */
        processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault().buildProcessEngine();
    }
    return processEngine;
}
 
Example 18
@Override
public void generateTestData(ProcessEngine processEngine) {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment().addClasspathResource("migrationProcess.bpmn20.xml").deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    runtimeService.startProcessInstanceByKey("receiveTask", "activitiv5-migrate-process");
}
 
Example 19
public ActivitiUtil(ProcessEngine engine, boolean deployWorkflowsInTenant, boolean retentionHistoricProcessInstance)
{
    this.repoService = engine.getRepositoryService();
    this.runtimeService = engine.getRuntimeService();
    this.taskService = engine.getTaskService();
    this.historyService = engine.getHistoryService();
    this.formService = engine.getFormService();
    this.managementService = engine.getManagementService();
    this.deployWorkflowsInTenant = deployWorkflowsInTenant;
    this.retentionHistoricProcessInstance = retentionHistoricProcessInstance;
}
 
Example 20
@Test
public void testService() throws Exception {
    assertNotNull(runtimeService);

    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
}
 
Example 21
public DefaultTaskFlowControlService(RuntimeActivityDefinitionManager activitiesCreationStore,
		ProcessEngine processEngine, String processId)
{
	_activitiesCreationStore = activitiesCreationStore;
	_processEngine = processEngine;
	_processInstanceId = processId;

	String processDefId = _processEngine.getRuntimeService().createProcessInstanceQuery()
			.processInstanceId(_processInstanceId).singleResult().getProcessDefinitionId();

	_processDefinition = ProcessDefinitionUtils.getProcessDefinition(_processEngine, processDefId);
}
 
Example 22
Source Project: activiti6-boot2   Source File: TestHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static ProcessEngine getProcessEngine(String configurationResource) {
  ProcessEngine processEngine = processEngines.get(configurationResource);
  if (processEngine == null) {
    log.debug("==== BUILDING PROCESS ENGINE ========================================================================");
    processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(configurationResource).buildProcessEngine();
    log.debug("==== PROCESS ENGINE CREATED =========================================================================");
    processEngines.put(configurationResource, processEngine);
  }
  return processEngine;
}
 
Example 23
Source Project: activiti6-boot2   Source File: DbSqlSession.java    License: Apache License 2.0 5 votes vote down vote up
public void dbSchemaCheckVersion() {
  try {
    String dbVersion = getDbVersion();
    if (!ProcessEngine.VERSION.equals(dbVersion)) {
      throw new ActivitiWrongDbException(ProcessEngine.VERSION, dbVersion);
    }

    String errorMessage = null;
    if (!isEngineTablePresent()) {
      errorMessage = addMissingComponent(errorMessage, "engine");
    }
    if (dbSqlSessionFactory.isDbHistoryUsed() && !isHistoryTablePresent()) {
      errorMessage = addMissingComponent(errorMessage, "history");
    }
    if (dbSqlSessionFactory.isDbIdentityUsed() && !isIdentityTablePresent()) {
      errorMessage = addMissingComponent(errorMessage, "identity");
    }

    if (errorMessage != null) {
      throw new ActivitiException("Activiti database problem: " + errorMessage);
    }

  } catch (Exception e) {
    if (isMissingTablesException(e)) {
      throw new ActivitiException(
          "no activiti tables in db. set <property name=\"databaseSchemaUpdate\" to value=\"true\" or value=\"create-drop\" (use create-drop for testing only!) in bean processEngineConfiguration in activiti.cfg.xml for automatic schema creation",
          e);
    } else {
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      } else {
        throw new ActivitiException("couldn't get db schema version", e);
      }
    }
  }

  log.debug("activiti db schema check successful");
}
 
Example 24
Source Project: tutorials   Source File: ProcessEngineCreationIntegrationTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenNoXMLConfig_whenCreateInMemProcessEngineConfig_thenCreated() {
    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
    ProcessEngine processEngine = processEngineConfiguration
      .setJdbcUrl("jdbc:h2:mem:my-own-in-mem-db;DB_CLOSE_DELAY=1000")
      .buildProcessEngine();
    assertNotNull(processEngine);
    assertEquals("sa", processEngine.getProcessEngineConfiguration().getJdbcUsername());
}
 
Example 25
Source Project: activiti6-boot2   Source File: SpringActivitiTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeProcessEngine() {
  ContextConfiguration contextConfiguration = getClass().getAnnotation(ContextConfiguration.class);
  String[] value = contextConfiguration.value();
  boolean hasOneArg = value != null && value.length == 1;
  String key = hasOneArg ? value[0] : ProcessEngine.class.getName();
  ProcessEngine engine = this.cachedProcessEngines.containsKey(key) ? this.cachedProcessEngines.get(key) : this.applicationContext.getBean(ProcessEngine.class);

  this.cachedProcessEngines.put(key, engine);
  this.processEngine = engine;
}
 
Example 26
@Override
public ProcessEngine buildProcessEngine() {
  ProcessEngine processEngine = super.buildProcessEngine();
  ProcessEngines.setInitialized(true);
  autoDeployResources(processEngine);
  return processEngine;
}
 
Example 27
@Bean(name = "processEngine")
public ProcessEngine processEngine() {
  // Safe to call the getObject() on the @Bean annotated
  // processEngineFactoryBean(), will be
  // the fully initialized object instanced from the factory and will NOT
  // be created more than once
  try {
    return processEngineFactoryBean().getObject();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 28
@Override
protected void onBootstrap(ApplicationEvent event) {
	
	this.processEngine = getApplicationContext().getBean(ProcessEngine.class);
	
	if (workflowAdminService.isEngineEnabled(ActivitiConstants.ENGINE_ID)) 
	{
		((ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getJobExecutor().start();
	}
}
 
Example 29
Source Project: activiti6-boot2   Source File: EventRecorderTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void closeProcessEngine(ProcessEngine processEngine, ActivitiEventListener listener) {
  if (listener != null) {
    final ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
    processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
  }
  processEngine.close();
}
 
Example 30
@Test
public void testService() throws Exception {
    assertNotNull(runtimeService);

    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
}