Time for action – suspending a process

So far, we have seen how to configure a process engine, deploy a process into the process engine, start a process, and query for a user task using an API.

Now, if there is a requirement to suspend a process, you can implement it using an API. We have already created a training process and now we want to suspend the process for some time. You can follow the ensuing steps to do so:

  1. Before suspending a process, just make sure that Training Schedule Process is available in the Deployed process definitions tab:
    Time for action – suspending a process
  2. Now create a SuspensionActivation class file to suspend the process with the following code in the class file:
    ProcessEngine processEngine = ProcessEngineConfiguration
    
      .createStandaloneProcessEngineConfiguration()
      .setJdbcDriver("com.mysql.jdbc.Driver")
      .setJdbcUrl("jdbc:mysql://localhost:3306/activiti_book")
      .setJdbcPassword("root").setJdbcUsername("root")
      .buildProcessEngine();
    
    RepositoryService repositoryService = processEngine
            .getRepositoryService();
    
    repositoryService.suspendProcessDefinitionByKey("traininngProcess");
  3. Once we finish with the coding part, just execute the class file and then browse to the Activiti Explorer and check for Training Schedule Process in the Deployed process definitions tab:
    Time for action – suspending a process
  4. If you don't find your process within the list, it means you have suspended the process successfully.
  5. So, once you suspend the process, it cannot be restarted for execution.
  6. To reactivate the process, you can add the following code within your SuspensionActivation class file:
    ProcessEngine processEngine = ProcessEngineConfiguration
    
      .createStandaloneProcessEngineConfiguration()
      .setJdbcDriver("com.mysql.jdbc.Driver")
      .setJdbcUrl("jdbc:mysql://localhost:3306/activiti_book")
      .setJdbcPassword("root").setJdbcUsername("root")
      .buildProcessEngine();
    
    RepositoryService repositoryService = processEngine
      .getRepositoryService();
    
    repositoryService.activateProcessDefinitionByKey("traininngProcess");
  7. On execution of the following code, you will again be able to see Training Schedule Process in the process list, as shown in the following screenshot:
    Time for action – suspending a process
  8. The preceding code will activate the process, and you can continue further executing the business process.

What just happened?

Recently, we learned the use of the suspendProcessDefinition and activateProcessDefinition methods of repositoryService. So, with their help, we can suspend and reactivate our processes.

ManagementService

ManagementService is used to maintain operations performed on the process engine. With the help of this service, we can upgrade the schema, fetch the executed commands and properties of the process engine, and execute the table page query for fetching table row data. ManagementService cannot be used in the workflow application. This service is just for managing your business process and not for executing any operations on the business process.

IdentityService

IdentityService is used for managing users and groups. We can create, update, delete, and update group and user information. Activiti doesn't perform checks on users at runtime, because in production you may have used a user management protocol such as LDAP. Using IdentityService, we can programmatically query for users and groups. We can delete a particular user or group. We can also create a new user and group.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset