Search in sources :

Example 1 with BPSFault

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);
        }
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 2 with BPSFault

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);
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) Resource(org.wso2.carbon.registry.api.Resource) Registry(org.wso2.carbon.registry.api.Registry) RegistryService(org.wso2.carbon.registry.api.RegistryService) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 3 with BPSFault

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);
}
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)

Example 4 with BPSFault

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()]);
}
Also used : BPMNInstance(org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance) ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) RuntimeService(org.activiti.engine.RuntimeService) ArrayList(java.util.ArrayList) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 5 with BPSFault

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);
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) HistoryService(org.activiti.engine.HistoryService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Aggregations

BPSFault (org.wso2.carbon.bpmn.core.BPSFault)13 File (java.io.File)6 ProcessEngine (org.activiti.engine.ProcessEngine)6 RuntimeService (org.activiti.engine.RuntimeService)5 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 RepositoryService (org.activiti.engine.RepositoryService)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 RegistryException (org.wso2.carbon.registry.api.RegistryException)4 IOException (java.io.IOException)3 Deployment (org.activiti.engine.repository.Deployment)3 Registry (org.wso2.carbon.registry.api.Registry)3 RegistryService (org.wso2.carbon.registry.api.RegistryService)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 TenantRepository (org.wso2.carbon.bpmn.core.deployment.TenantRepository)2 BPMNInstance (org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance)2 BufferedImage (java.awt.image.BufferedImage)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1