0

I'm New to Flowable. I tried to create the BPMN Deployment to MYSQL and it's getting deployed successfully.

But In UnDeployment process i'm storing all the deployments in a List then i'm performing the undeployment based on the My Criteria, like if Both resouceName and CompanyCode matches then we are deleting the deployment.

Suppose if we have more deployment, We can't store it in a List then try to match with my criteria with entire List.

How can I perform this Efficiently.

public void deployResource(String resourceName, InputStream resourceStream, 
    String companyCode) {

    RepositoryService repoService = processEngine.getRepositoryService();
    DeploymentBuilder dbuilder = repoService.createDeployment();
    dbuilder.addInputStream(resourceName, resourceStream);
    dbuilder.name(resourceId);

    if (companyCode != null && !companyCode.isEmpty()) {
        logger.info("Setting Tenant ID with companyCode {}", companyCode);
        dbuilder.tenantId(companyCode);
    }
    dbuilder.deploy();
}

// This is the Undeployment Method

 public void undeploy(String resourceName, String companyCode) {
    try {

        logger.debug(LogMarker.ENTRY, "Undeployment Process {} is Started for Resource Name{}", resourceName, companyCode);

        RepositoryService repoService = processEngine.getRepositoryService();

        List<ProcessDefinition> list = repoService.createProcessDefinitionQuery().processDefinitionResourceNameLike(resourceName)
            .processDefinitionTenantIdLike(companyCode).list();

        for (ProcessDefinition processDefinition : list) {
            repoService.deleteDeployment(processDefinition.getDeploymentId(), true);

            logger.debug(LogMarker.EXIT, "Undeployment Process {} is Successfully Completed for Resource Name{}", resourceName);
            break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Fábio Nascimento
  • 2,644
  • 1
  • 21
  • 27
AVINASH M
  • 487
  • 3
  • 7
  • 19
  • Hi, can you explain what do you mean by, `we cannot store in list`? – Arpit Agrawal Mar 25 '19 at 07:07
  • Now i am reading all the deployed resources but instead of doing this How can i try to get the specific deployment using combination of resource name and tenantId. Suppose if we have 500 deployments then i need to store all my deployments in a list then try to match with all elements.Instead of storing in List How can I perform efficiently @ArpitAgrawal – AVINASH M Mar 25 '19 at 07:34
  • Why dont you use these filters while creating query ?https://www.activiti.org/javadocs/org/activiti/engine/repository/processdefinitionquery#processDefinitionResourceNameLike-java.lang.String- and https://www.activiti.org/javadocs/org/activiti/engine/repository/processdefinitionquery#processDefinitionTenantIdLike-java.lang.String- . these filter will directly give you only desired rows from db. – Arpit Agrawal Mar 25 '19 at 08:17
  • How can i use this : ProcessDefinitionQuery processDefinitionResourceNameLike = repoService.createProcessDefinitionQuery(). processDefinitionResourceNameLike(resourceName); and processDefinitionTenantIdLike with my code @ArpitAgrawal – AVINASH M Mar 25 '19 at 08:53
  • 1
    Like this : `List list = repoService.createProcessDefinitionQuery().processDefinitionResourceNameLike(resourceName).processDefinitionTenantIdLike(tenantId).list(); ` – Arpit Agrawal Mar 25 '19 at 09:14
  • I have Updated my updeploy()...Still the list is getting filled with all the deployment names...Where i'm going wrong @ArpitAgrawal – AVINASH M Mar 25 '19 at 09:52
  • Sorry, can you be little more specific. Like, if the query is not filtering the data based on the filters you applied and returning all the data. If your database already has a lot of data and all the data returned satisfy the filter, then i don't think you can do anything except for maybe using pagination to get limited data at a time. You can look for paginated results here : https://www.activiti.org/javadocs/org/activiti/engine/query/query#listPage-int-int- – Arpit Agrawal Mar 25 '19 at 11:13

1 Answers1

1

Instead of querying for process definitions why not query for Deployment(s)?

You could do:

List<Deployment> deployments = repositoryService.createDeploymentQuery()
    .deploymentTenantId(companyCode)
    .processDefinitionKey(processDefinitionKey)
    .list();

You can then delete those deployments. Keep in mind that your current way of doing the undeployment could delete process definitions that do not match your critieria, but are part of a deployment of another process definition (You can deploy multiple process definitions per deployment).

Filip
  • 19,269
  • 7
  • 51
  • 60
  • I'm Undeploying based on my matching criteria like resouceName as deploymentId and tenantId as companyCode. How to get the **processDefinitionKey** – AVINASH M Mar 25 '19 at 10:18
  • The `resourceName` is not the `deploymentId`. The `processDefinitionKey` is the process id in the BPMN XML – Filip Mar 25 '19 at 15:30