use of org.wso2.carbon.bpmn.core.BPSFault 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);
}
}
}
use of org.wso2.carbon.bpmn.core.BPSFault in project carbon-business-process by wso2.
the class BPMNDeploymentService method getLatestChecksum.
/**
* Get the checksum of latest deployment for given deployment name
*
* @param deploymentName
* @return
* @throws BPSFault
*/
public String getLatestChecksum(String deploymentName) throws BPSFault {
try {
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
RegistryService registryService = BPMNServerHolder.getInstance().getRegistryService();
Registry tenantRegistry = registryService.getConfigSystemRegistry(tenantId);
String deploymentRegistryPath = BPMNConstants.BPMN_REGISTRY_PATH + BPMNConstants.REGISTRY_PATH_SEPARATOR + deploymentName;
if (tenantRegistry.resourceExists(deploymentRegistryPath)) {
Resource deploymentEntry = tenantRegistry.get(deploymentRegistryPath);
return deploymentEntry.getProperty(BPMNConstants.LATEST_CHECKSUM_PROPERTY);
} else {
return null;
}
} catch (RegistryException e) {
String msg = "Error while accessing registry to get latest checksum for package : " + deploymentName;
throw new BPSFault(msg, e);
}
}
use of org.wso2.carbon.bpmn.core.BPSFault 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);
}
use of org.wso2.carbon.bpmn.core.BPSFault in project carbon-business-process by wso2.
the class BPMNInstanceService method getPaginatedInstances.
/**
* Get paginated instances
*
* @param start
* @param size
* @return list of BPMNInstances
* @throws BPSFault
*/
public BPMNInstance[] getPaginatedInstances(int start, int size) throws BPSFault {
List<BPMNInstance> bpmnInstanceList = new ArrayList<>();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
RuntimeService runtimeService = engine.getRuntimeService();
ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString());
HistoricProcessInstanceQuery historicQuery = BPMNServerHolder.getInstance().getEngine().getHistoryService().createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString());
processInstanceCount = (int) query.count();
List<ProcessInstance> instances = query.includeProcessVariables().listPage(start, size);
for (ProcessInstance instance : instances) {
BPMNInstance bpmnInstance = new BPMNInstance();
bpmnInstance.setInstanceId(instance.getId());
bpmnInstance.setProcessId(instance.getProcessDefinitionId());
bpmnInstance.setSuspended(instance.isSuspended());
bpmnInstance.setStartTime(historicQuery.processInstanceId(instance.getId()).singleResult().getStartTime());
bpmnInstance.setVariables(formatVariables(instance.getProcessVariables()));
bpmnInstanceList.add(bpmnInstance);
}
return bpmnInstanceList.toArray(new BPMNInstance[bpmnInstanceList.size()]);
}
use of org.wso2.carbon.bpmn.core.BPSFault in project carbon-business-process by wso2.
the class BPMNInstanceService method deleteProcessInstance.
/**
* Delete process instance by passing instance ID
*
* @param instanceId
* @throws BPSFault
*/
public void deleteProcessInstance(String instanceId) throws BPSFault {
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
RuntimeService runtimeService = BPMNServerHolder.getInstance().getEngine().getRuntimeService();
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).processInstanceId(instanceId).list();
if (processInstances.isEmpty()) {
HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService();
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).processInstanceId(instanceId).list();
if (historicProcessInstances.isEmpty()) {
String msg = "No process instances with the ID: " + instanceId;
log.error(msg);
throw new BPSFault(msg);
}
historyService.deleteHistoricProcessInstance(instanceId);
return;
}
runtimeService.deleteProcessInstance(instanceId, "Deleted by user: " + tenantId);
}
Aggregations