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