Search in sources :

Example 11 with BPSFault

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

the class BPMNDeploymentService method getDeployedProcesses.

public BPMNProcess[] getDeployedProcesses() throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    TenantRepository tenantRepository = BPMNServerHolder.getInstance().getTenantManager().getTenantRepository(tenantId);
    List<ProcessDefinition> processDefinitions = tenantRepository.getDeployedProcessDefinitions();
    BPMNProcess[] bpmnProcesses = new BPMNProcess[processDefinitions.size()];
    for (int i = 0; i < processDefinitions.size(); i++) {
        ProcessDefinition def = processDefinitions.get(i);
        BPMNProcess bpmnProcess = new BPMNProcess();
        bpmnProcess.setProcessId(def.getId());
        bpmnProcess.setDeploymentId(def.getDeploymentId());
        bpmnProcess.setKey(def.getKey());
        bpmnProcess.setVersion(def.getVersion());
        bpmnProcesses[i] = bpmnProcess;
    }
    return bpmnProcesses;
}
Also used : BPMNProcess(org.wso2.carbon.bpmn.core.mgt.model.BPMNProcess) TenantRepository(org.wso2.carbon.bpmn.core.deployment.TenantRepository) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 12 with BPSFault

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

the class BPMNDeploymentService method getProcessModel.

public String getProcessModel(String processId) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    BufferedReader br = null;
    try {
        RepositoryService repositoryService = BPMNServerHolder.getInstance().getEngine().getRepositoryService();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(tenantId.toString()).processDefinitionId(processId).singleResult();
        InputStream stream = repositoryService.getProcessModel(processDefinition.getId());
        br = new BufferedReader(new InputStreamReader(stream, Charset.defaultCharset()));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        return sb.toString();
    } catch (IOException e) {
        String msg = "Failed to create the diagram for process: " + processId;
        log.error(msg, e);
        throw new BPSFault(msg, e);
    } finally {
        try {
            if (br != null) {
                br.close();
            }
        } catch (IOException e) {
            log.error("Could not close the reader", e);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) BufferedReader(java.io.BufferedReader) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IOException(java.io.IOException) RepositoryService(org.activiti.engine.RepositoryService)

Example 13 with BPSFault

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

the class BPMNInstanceService method activateProcessInstance.

/**
 * Activate a process instance by passing the instance id
 *
 * @param instanceId
 * @throws BPSFault
 */
public void activateProcessInstance(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.activateProcessInstanceById(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 14 with BPSFault

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

the class ActivitiEngineBuilder method buildEngine.

/* Instantiates the engine. Builds the state of the engine
	 *
	 * @return  ProcessEngineImpl object
	 * @throws BPSFault  Throws in the event of failure of ProcessEngine
	 */
public ProcessEngine buildEngine() throws BPSFault {
    try {
        String carbonConfigDirPath = CarbonUtils.getCarbonConfigDirPath();
        String activitiConfigPath = carbonConfigDirPath + File.separator + BPMNConstants.ACTIVITI_CONFIGURATION_FILE_NAME;
        File activitiConfigFile = new File(activitiConfigPath);
        ProcessEngineConfigurationImpl processEngineConfigurationImpl = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(new FileInputStream(activitiConfigFile));
        // Add script engine resolvers
        setResolverFactories(processEngineConfigurationImpl);
        // Add supported variable types
        setSupportedVariableTypes(processEngineConfigurationImpl);
        // we have to build the process engine first to initialize session factories.
        processEngine = processEngineConfigurationImpl.buildProcessEngine();
        processEngineConfigurationImpl.getSessionFactories().put(UserIdentityManager.class, new BPSUserManagerFactory());
        processEngineConfigurationImpl.getSessionFactories().put(GroupIdentityManager.class, new BPSGroupManagerFactory());
        dataSourceJndiName = processEngineConfigurationImpl.getProcessEngineConfiguration().getDataSourceJndiName();
    } catch (FileNotFoundException e) {
        String msg = "Failed to create an Activiti engine. Activiti configuration file not found";
        throw new BPSFault(msg, e);
    }
    return processEngine;
}
Also used : BPSGroupManagerFactory(org.wso2.carbon.bpmn.core.integration.BPSGroupManagerFactory) BPSUserManagerFactory(org.wso2.carbon.bpmn.core.integration.BPSUserManagerFactory) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) FileInputStream(java.io.FileInputStream)

Example 15 with BPSFault

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

the class BPMNDeployer method undeploy.

/**
 * Undeployment operation for Bpmn Deployer
 *
 * @param bpmnArchivePath        archivePatch
 * @throws DeploymentException   Deployment failure will result in this exception
 */
public void undeploy(String bpmnArchivePath) throws DeploymentException {
    if (isWorkerNode()) {
        return;
    }
    if (System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP) != null && Boolean.parseBoolean(System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP)) || System.getProperty(BPMNConstants.RESOLVE_DEPLOYMENT_SYS_PROP) == null) {
        File bpmnArchiveFile = new File(bpmnArchivePath);
        if (bpmnArchiveFile.exists()) {
            if (log.isTraceEnabled()) {
                log.trace("BPMN package: " + bpmnArchivePath + " exists in the deployment folder. " + "Therefore, this can be an update of the package and the undeployment will be aborted.");
            }
            return;
        }
        Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        log.info("Undeploying BPMN archive " + bpmnArchivePath + " for tenant: " + tenantId);
        String deploymentName = FilenameUtils.getBaseName(bpmnArchivePath);
        try {
            tenantRepository.undeploy(deploymentName, true);
        } catch (BPSFault be) {
            String errorMsg = "Error un deploying BPMN Package " + deploymentName;
            throw new DeploymentException(errorMsg, be);
        }
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

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