org.activiti.engine.ProcessEngine Java Examples

The following examples show how to use org.activiti.engine.ProcessEngine. 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: SortGroup.java    From CrazyWorkflowHandoutsActiviti6 with 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 #2
Source File: SchemaErrorTest.java    From CrazyWorkflowHandoutsActiviti6 with 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 #3
Source File: MuleVMTest.java    From activiti6-boot2 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/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 #4
Source File: AddZipInputStreamTest.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 6 votes vote down vote up
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 #5
Source File: SaveGroup.java    From CrazyWorkflowHandoutsActiviti6 with 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 #6
Source File: DbSqlSession.java    From activiti6-boot2 with 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 #7
Source File: IntegrationAutoConfigurationTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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
Source File: CreateEngineUseSpringProxyByAnnotation.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
public void testService() throws Exception {
    assertNotNull(runtimeService);

    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
}
 
Example #9
Source File: ProcessEngineCreationIntegrationTest.java    From tutorials with 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 #10
Source File: DbSqlSession.java    From activiti6-boot2 with 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 #11
Source File: TestHelper.java    From activiti6-boot2 with 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 #12
Source File: DefaultTaskFlowControlService.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #13
Source File: ImageQueryTest.java    From CrazyWorkflowHandoutsActiviti6 with 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 File: ActivitiUtil.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #15
Source File: ModelTest.java    From opscenter with 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 #16
Source File: ProcessEngineFactoryBean.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessEngine getObject() throws Exception {
    configureExpressionManager();
    configureExternallyManagedTransactions();

    if (processEngineConfiguration.getBeans() == null) {
        processEngineConfiguration.setBeans(new SpringBeanFactoryProxyMap(applicationContext));
    }

    this.processEngine = processEngineConfiguration.buildProcessEngine();
    return this.processEngine;
}
 
Example #17
Source File: ProcessEngineConfigurationTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 此测试会失败,因为本例没有配置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 #18
Source File: MigrateProcessInstanceTestDataGenerator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@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
Source File: SpringActivitiTestCase.java    From activiti6-boot2 with 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 #20
Source File: ProcessExecutionIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenBPMN_whenDeployProcess_thenDeployed() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment()
      .addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
      .deploy();
    Long count = repositoryService.createProcessDefinitionQuery().count();
    assertTrue(count >= 1);
}
 
Example #21
Source File: SpringProcessEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessEngine buildProcessEngine() {
  ProcessEngine processEngine = super.buildProcessEngine();
  ProcessEngines.setInitialized(true);
  autoDeployResources(processEngine);
  return processEngine;
}
 
Example #22
Source File: JPAActivitiEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: SpringProcessEngineConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessEngine buildProcessEngine() {
    ProcessEngine processEngine = super.buildProcessEngine();
    ProcessEngines.setInitialized(true);
    autoDeployResources(processEngine);
    return processEngine;
}
 
Example #24
Source File: ActivitiEngineInitializer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onBootstrap(ApplicationEvent event) {
	
	this.processEngine = getApplicationContext().getBean(ProcessEngine.class);
	
	if (workflowAdminService.isEngineEnabled(ActivitiConstants.ENGINE_ID)) 
	{
		((ProcessEngineImpl)processEngine).getProcessEngineConfiguration().getJobExecutor().start();
	}
}
 
Example #25
Source File: EventRecorderTestUtils.java    From activiti6-boot2 with 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 #26
Source File: CreateEngineUseSpringProxyByAnnotation.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
public void testService() throws Exception {
    assertNotNull(runtimeService);

    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
}
 
Example #27
Source File: CreateEngineUseSpringProxyByAnnotation.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
public void testService() throws Exception {
    assertNotNull(runtimeService);

    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
}
 
Example #28
Source File: CreateEngineUseSpringProxyByAnnotation.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
public void testService() throws Exception {
    assertNotNull(runtimeService);

    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
}
 
Example #29
Source File: ActivitiEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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 #30
Source File: RuntimeActivityCreatorSupport.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ActivityImpl createActivity(ProcessEngine processEngine, ProcessDefinitionEntity processDefinition,
		String prototypeActivityId, String cloneActivityId, String assignee)
{
	ActivityImpl prototypeActivity = ProcessDefinitionUtils.getActivity(processEngine, processDefinition.getId(),
		prototypeActivityId);

	return createActivity(processEngine, processDefinition, prototypeActivity, cloneActivityId, assignee);
}