Advertisement
Guest User

Untitled

a guest
May 18th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1.  
  2.     private ProcessEngine processEngine;
  3.     private RuntimeService runtimeService;
  4.     private TaskService taskService;
  5.  
  6.     private void getProcessEngine( boolean historyOn, String jdbc ) {
  7.         ProcessEngineConfiguration configuration = ProcessEngineConfiguration
  8.             .createStandaloneProcessEngineConfiguration()
  9.             .setDatabaseSchemaUpdate(
  10.                     ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP )
  11.             .setJdbcUrl( jdbc ).setJdbcMaxActiveConnections( 1000 );
  12.         if( "postgresql".equalsIgnoreCase( jdbc.split( ":" )[1])) {
  13.             configuration.setJdbcUsername( "postgres" ).setJdbcPassword( "mypass" );
  14.         }
  15.  
  16.         if( historyOn ) {
  17.             configuration.setHistory( ProcessEngineConfiguration.HISTORY_FULL );
  18.         } else {
  19.             configuration.setHistory( ProcessEngineConfiguration.HISTORY_NONE );
  20.         }
  21.         processEngine = configuration.buildProcessEngine();
  22.     }
  23.  
  24.     @Override
  25.     public void init( File schema, boolean historyOn, String jdbc )
  26.             throws Exception {
  27.         getProcessEngine( historyOn, jdbc );
  28.         BpmnModelInstance modelInstance = Bpmn.readModelFromFile( schema );
  29.         RepositoryService repositoryService = processEngine
  30.             .getRepositoryService();
  31.         List< ProcessDefinition > processDefinitions = repositoryService
  32.             .createProcessDefinitionQuery().list();
  33.         if( processDefinitions.isEmpty() ) {
  34.             repositoryService.createDeployment()
  35.                 .addModelInstance( "test_PT.bpmn", modelInstance ).deploy();
  36.         }
  37.         runtimeService = processEngine.getRuntimeService();
  38.         taskService = processEngine.getTaskService();
  39.         class ExitHook extends Thread {
  40.  
  41.             public void run() {
  42.                 processEngine.close();
  43.             }
  44.         }
  45.         Runtime.getRuntime().addShutdownHook( new ExitHook() );
  46.     }
  47.  
  48. //This method is called by each thread in a loop and then sleeps for a second.
  49.     @Override
  50.     public String startProcessOrFinishCurrentTask( String procID )
  51.             throws Exception {
  52.         List< Task > list = taskService.createTaskQuery().active()
  53.             .processInstanceId( procID ).list();
  54.         if( list.isEmpty() ) {
  55.             return createProcessInstance().getId();
  56.         } else {
  57.             list.stream().forEach( c -> {
  58.                 if( c.getName().equals( "Stage3" ) ) {
  59.                     taskService.setVariable( c.getId(), "var1",
  60.                             flowSelector() );
  61.                 }
  62.                 taskService.complete( c.getId() );
  63.             } );
  64.             return procID;
  65.         }
  66.     }
  67.  
  68.     private ProcessInstance createProcessInstance() {
  69.         return runtimeService.startProcessInstanceByKey( "test_process" );
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement