Search in sources :

Example 6 with BPSFault

use of org.wso2.carbon.bpmn.core.BPSFault in project carbon-business-process by wso2.

the class BPMNInstanceService method getProcessInstances.

/**
 * Get All process instances
 *
 * @return list of BPMNInstances
 * @throws BPSFault
 */
public BPMNInstance[] getProcessInstances() throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
    RuntimeService runtimeService = engine.getRuntimeService();
    List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).list();
    BPMNInstance[] bpmnInstances = getTenantBPMNInstances(instances);
    return bpmnInstances;
}
Also used : BPMNInstance(org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance) RuntimeService(org.activiti.engine.RuntimeService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 7 with BPSFault

use of org.wso2.carbon.bpmn.core.BPSFault in project carbon-business-process by wso2.

the class BPMNInstanceService method suspendProcessInstance.

/**
 * Suspend process instance by instance ID
 *
 * @param instanceId
 * @throws BPSFault
 */
public void suspendProcessInstance(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()) {
        String msg = "No process instances with the ID: " + instanceId;
        log.error(msg);
        throw new BPSFault(msg);
    }
    runtimeService.suspendProcessInstanceById(instanceId);
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 8 with BPSFault

use of org.wso2.carbon.bpmn.core.BPSFault in project carbon-business-process by wso2.

the class BPMNDeployer method init.

/**
 * Initializes the deployment per tenant
 *
 * @param configurationContext axis2 configurationContext
 */
@Override
public void init(ConfigurationContext configurationContext) {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    log.info("Initializing BPMN Deployer for tenant " + tenantId + ".");
    try {
        File tenantRepoFolder = createTenantRepo(configurationContext);
        tenantRepository = BPMNServerHolder.getInstance().getTenantManager().createTenantRepository(tenantId);
        tenantRepository.setRepoFolder(tenantRepoFolder);
        // This is to check whether the user have added resolveDeploymentAtStartup system property to true if need
        // for resolving deployment to avoid inconsistencies
        boolean fixDeployments = true;
        if (System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP) != null && !Boolean.parseBoolean(System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP))) {
            fixDeployments = false;
            log.info("BPMN deployment inconsistencies will not resolved");
        }
        if (!isWorkerNode() && fixDeployments) {
            log.info("Resolving BPMN deployments to avoid inconsistencies");
            tenantRepository.fixDeployments();
        }
    } catch (BPSFault e) {
        String msg = "Tenant Error: " + tenantId;
        log.error(msg, e);
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) File(java.io.File)

Example 9 with BPSFault

use of org.wso2.carbon.bpmn.core.BPSFault in project carbon-business-process by wso2.

the class TenantRepository method undeploy.

/**
 * Undeploys a BPMN package.
 * This may be called by the BPMN deployer, when a BPMN package is deleted from the deployment folder or by admin services
 *
 * @param deploymentName package name to be undeployed
 * @param force          forceful deletion of package
 */
// public void undeploy(String deploymentName, boolean force) {
// 
// DeploymentMetaDataModel deploymentMetaDataModel;
// SqlSession sqlSession = null;
// try {
// // Remove the deployment from the tenant's registry
// deploymentMetaDataModel = activitiDAO
// .selectTenantAwareDeploymentModel(tenantId.toString(), deploymentName);
// 
// if ((deploymentMetaDataModel == null) && !force) {
// String msg = "Deployment: " + deploymentName + " does not exist.";
// log.warn(msg);
// return;
// }
// 
// ProcessEngineImpl engine = (ProcessEngineImpl) BPMNServerHolder.getInstance().getEngine();
// 
// DbSqlSessionFactory dbSqlSessionFactory =
// (DbSqlSessionFactory) engine.getProcessEngineConfiguration().
// getSessionFactories().get(DbSqlSession.class);
// 
// SqlSessionFactory sqlSessionFactory = dbSqlSessionFactory.getSqlSessionFactory();
// sqlSession = sqlSessionFactory.openSession();
// DeploymentMapper deploymentMapper = sqlSession.getMapper(DeploymentMapper.class);
// int rowCount = deploymentMapper.deleteDeploymentMetaData(deploymentMetaDataModel);
// 
// if (log.isDebugEnabled()) {
// log.debug("Total row count deleted=" + rowCount);
// }
// 
// // Remove the deployment archive from the tenant's deployment folder
// File deploymentArchive = new File(repoFolder, deploymentName + ".bar");
// FileUtils.deleteQuietly(deploymentArchive);
// 
// // Delete all versions of this package from the Activiti engine.
// RepositoryService repositoryService = engine.getRepositoryService();
// List<Deployment> deployments = repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString()).
// deploymentName(deploymentName).list();
// for (Deployment deployment : deployments) {
// repositoryService.deleteDeployment(deployment.getId());
// }
// 
// //commit metadata
// sqlSession.commit();
// } finally {
// if (sqlSession != null) {
// sqlSession.close();
// }
// }
// 
// }
public void undeploy(String deploymentName, boolean force) throws BPSFault {
    try {
        // Remove the deployment from the tenant's registry
        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) && !force) {
            String msg = "Deployment: " + deploymentName + " does not exist.";
            log.warn(msg);
            return;
        }
        tenantRegistry.delete(deploymentRegistryPath);
        // Remove the deployment archive from the tenant's deployment folder
        File deploymentArchive = new File(repoFolder, deploymentName + ".bar");
        FileUtils.deleteQuietly(deploymentArchive);
        // Delete all versions of this package from the Activiti engine.
        ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
        RepositoryService repositoryService = engine.getRepositoryService();
        List<Deployment> deployments = repositoryService.createDeploymentQuery().deploymentTenantId(tenantId.toString()).deploymentName(deploymentName).list();
        for (Deployment deployment : deployments) {
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    } catch (RegistryException e) {
        String msg = "Failed to undeploy BPMN deployment: " + deploymentName + " for tenant: " + tenantId;
        log.error(msg, e);
        throw new BPSFault(msg, e);
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) Deployment(org.activiti.engine.repository.Deployment) Registry(org.wso2.carbon.registry.api.Registry) RegistryService(org.wso2.carbon.registry.api.RegistryService) File(java.io.File) RegistryException(org.wso2.carbon.registry.api.RegistryException) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 10 with BPSFault

use of org.wso2.carbon.bpmn.core.BPSFault in project carbon-business-process by wso2.

the class BPMNDeploymentService method getProcessDiagram.

public String getProcessDiagram(String processId) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    try {
        RepositoryService repositoryService = BPMNServerHolder.getInstance().getEngine().getRepositoryService();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(tenantId.toString()).processDefinitionId(processId).singleResult();
        String diagramResourceName = processDefinition.getDiagramResourceName();
        InputStream imageStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName);
        BufferedImage bufferedImage = ImageIO.read(imageStream);
        return encodeToString(bufferedImage, "png");
    } catch (IOException e) {
        String msg = "Failed to create the diagram for process: " + processId;
        // log.error(msg, e);
        throw new BPSFault(msg, e);
    }
}
Also used : InputStream(java.io.InputStream) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) RepositoryService(org.activiti.engine.RepositoryService)

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