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