Search in sources :

Example 1 with BPMNDeletableInstances

use of org.wso2.carbon.bpmn.core.mgt.model.BPMNDeletableInstances in project carbon-business-process by wso2.

the class BPMNDeploymentService method aggregateRemovableProcessInstances.

private void aggregateRemovableProcessInstances(BPMNDeletableInstances bpmnDeletableInstances, String deploymentId, Integer tenantId, ProcessEngine processEngine) throws BPSFault {
    ProcessDefinitionQuery query = processEngine.getRepositoryService().createProcessDefinitionQuery();
    List<ProcessDefinition> processes = query.processDefinitionTenantId(tenantId.toString()).deploymentId(deploymentId).list();
    for (ProcessDefinition process : processes) {
        if (!constructBPMNInstancesByProcessID(bpmnDeletableInstances, process.getId(), tenantId, processEngine)) {
            String errorMessage = " Failed to undeploy the package. Please delete the instances before undeploying " + "the package";
            throw new BPSFault(errorMessage);
        }
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 2 with BPMNDeletableInstances

use of org.wso2.carbon.bpmn.core.mgt.model.BPMNDeletableInstances in project carbon-business-process by wso2.

the class BPMNDeploymentService method undeploy.

public void undeploy(String deploymentName) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    ProcessEngine processEngine = BPMNServerHolder.getInstance().getEngine();
    DeploymentQuery query = processEngine.getRepositoryService().createDeploymentQuery();
    query = query.deploymentTenantId(tenantId.toString());
    query = query.deploymentNameLike("%" + deploymentName + "%");
    int deploymentCount = (int) query.count();
    log.info("Package " + deploymentName + " id going to be undeployed for the deployment count : " + deploymentCount);
    BPMNDeletableInstances bpmnDeletableInstances = new BPMNDeletableInstances();
    bpmnDeletableInstances.setTenantId(tenantId);
    List<Deployment> deployments = query.listPage(0, deploymentCount + 1);
    for (Deployment deployment : deployments) {
        aggregateRemovableProcessInstances(bpmnDeletableInstances, deployment.getId(), tenantId, processEngine);
    }
    if ((bpmnDeletableInstances.getActiveInstanceCount() + bpmnDeletableInstances.getCompletedInstanceCount()) > maximumDeleteCount) {
        String errorMessage = " Failed to un deploy the package. Please delete the instances before un deploying " + "the package";
        throw new BPSFault(errorMessage, new Exception(errorMessage));
    }
    deleteInstances(bpmnDeletableInstances, processEngine);
    TenantRepository tenantRepository = BPMNServerHolder.getInstance().getTenantManager().getTenantRepository(tenantId);
    tenantRepository.undeploy(deploymentName, false);
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) BPMNDeployment(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment) Deployment(org.activiti.engine.repository.Deployment) TenantRepository(org.wso2.carbon.bpmn.core.deployment.TenantRepository) RegistryException(org.wso2.carbon.registry.api.RegistryException) IOException(java.io.IOException) ProcessEngine(org.activiti.engine.ProcessEngine) BPMNDeletableInstances(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeletableInstances)

Aggregations

BPSFault (org.wso2.carbon.bpmn.core.BPSFault)2 IOException (java.io.IOException)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 Deployment (org.activiti.engine.repository.Deployment)1 DeploymentQuery (org.activiti.engine.repository.DeploymentQuery)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)1 TenantRepository (org.wso2.carbon.bpmn.core.deployment.TenantRepository)1 BPMNDeletableInstances (org.wso2.carbon.bpmn.core.mgt.model.BPMNDeletableInstances)1 BPMNDeployment (org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment)1 RegistryException (org.wso2.carbon.registry.api.RegistryException)1