use of org.activiti.engine.repository.DeploymentQuery in project carbon-business-process by wso2.
the class DeploymentService method getDeployments.
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getDeployments() {
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();
// Apply filters
Map<String, String> allRequestParams = new HashMap<>();
for (String property : allPropertiesList) {
String value = uriInfo.getQueryParameters().getFirst(property);
if (value != null) {
allRequestParams.put(property, value);
}
}
String name = uriInfo.getQueryParameters().getFirst("name");
if (name != null) {
deploymentQuery.deploymentName(name);
}
String nameLike = uriInfo.getQueryParameters().getFirst("nameLike");
if (nameLike != null) {
deploymentQuery.deploymentNameLike(nameLike);
}
String category = uriInfo.getQueryParameters().getFirst("category");
if (category != null) {
deploymentQuery.deploymentCategory(category);
}
String categoryNotEquals = uriInfo.getQueryParameters().getFirst("categoryNotEquals");
if (categoryNotEquals != null) {
deploymentQuery.deploymentCategoryNotEquals(categoryNotEquals);
}
String tenantId = uriInfo.getQueryParameters().getFirst("tenantId");
if (tenantId != null) {
deploymentQuery.deploymentTenantId(tenantId);
}
String tenantIdLike = uriInfo.getQueryParameters().getFirst("tenantIdLike");
if (tenantIdLike != null) {
deploymentQuery.deploymentTenantIdLike(tenantIdLike);
}
String sWithoutTenantId = uriInfo.getQueryParameters().getFirst("withoutTenantId");
if (sWithoutTenantId != null) {
Boolean withoutTenantId = Boolean.valueOf(sWithoutTenantId);
if (withoutTenantId) {
deploymentQuery.deploymentWithoutTenantId();
}
}
DeploymentsPaginateList deploymentsPaginateList = new DeploymentsPaginateList(new RestResponseFactory(), uriInfo);
DataResponse dataResponse = deploymentsPaginateList.paginateList(allRequestParams, deploymentQuery, "id", allowedSortProperties);
return Response.ok().entity(dataResponse).build();
}
use of org.activiti.engine.repository.DeploymentQuery 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);
}
use of org.activiti.engine.repository.DeploymentQuery in project carbon-business-process by wso2.
the class BPMNDeploymentService method getProcessById.
public BPMNProcess getProcessById(String processId) {
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
ProcessDefinitionQuery query = engine.getRepositoryService().createProcessDefinitionQuery();
ProcessDefinition process = query.processDefinitionTenantId(tenantId.toString()).processDefinitionId(processId).singleResult();
DeploymentQuery deploymentQuery = engine.getRepositoryService().createDeploymentQuery();
Deployment deployment = deploymentQuery.deploymentId(process.getDeploymentId()).singleResult();
BPMNProcess bpmnProcess = new BPMNProcess();
bpmnProcess.setDeploymentId(process.getDeploymentId());
bpmnProcess.setName(process.getName());
bpmnProcess.setKey(process.getKey());
bpmnProcess.setProcessId(process.getId());
bpmnProcess.setVersion(process.getVersion());
bpmnProcess.setDeploymentTime(deployment.getDeploymentTime());
bpmnProcess.setDeploymentName(deployment.getName());
return bpmnProcess;
}
use of org.activiti.engine.repository.DeploymentQuery in project carbon-business-process by wso2.
the class BPMNDeploymentService method getDeployments.
public BPMNDeployment[] getDeployments() {
List<BPMNDeployment> bpmnDeploymentList = new ArrayList<>();
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeploymentQuery query = BPMNServerHolder.getInstance().getEngine().getRepositoryService().createDeploymentQuery();
query = query.deploymentTenantId(tenantId.toString());
List<Deployment> deployments = query.list();
for (Deployment deployment : deployments) {
BPMNDeployment bpmnDeployment = new BPMNDeployment();
bpmnDeployment.setDeploymentId(deployment.getId());
bpmnDeployment.setDeploymentName(deployment.getName());
bpmnDeployment.setDeploymentTime(deployment.getDeploymentTime());
bpmnDeploymentList.add(bpmnDeployment);
}
return bpmnDeploymentList.toArray(new BPMNDeployment[bpmnDeploymentList.size()]);
}
use of org.activiti.engine.repository.DeploymentQuery in project Activiti by Activiti.
the class DeploymentCategoryTest method testDeploymentKey.
public void testDeploymentKey() {
String noKeyDeploymentId = null;
String deploymentOneId = null;
String deploymentTwoV1Id = null;
String deploymentTwoV2Id = null;
String deploymentTwoNoKey = null;
try {
noKeyDeploymentId = repositoryService.createDeployment().name("0").addClasspathResource("org/activiti/engine/test/service/oneTaskProcess.bpmn20.xml").deploy().getId();
deploymentOneId = repositoryService.createDeployment().name("1").key("one").addClasspathResource("org/activiti/engine/test/repository/one.bpmn20.xml").deploy().getId();
deploymentTwoV1Id = repositoryService.createDeployment().name("2v1").key("two").addClasspathResource("org/activiti/engine/test/repository/two.bpmn20.xml").deploy().getId();
deploymentTwoV2Id = repositoryService.createDeployment().name("2v2").key("two").addClasspathResource("org/activiti/engine/test/repository/two.bpmn20.xml").deploy().getId();
DeploymentQuery query = repositoryService.createDeploymentQuery();
assertThat(query.list()).hasSize(4);
Set<String> deploymentNames = getDeploymentNames(repositoryService.createDeploymentQuery().deploymentKey("one").list());
Set<String> expectedDeploymentNames = new HashSet<String>();
expectedDeploymentNames.add("1");
assertThat(deploymentNames).isEqualTo(expectedDeploymentNames);
deploymentTwoNoKey = repositoryService.createDeployment().name("noCategory").addClasspathResource("org/activiti/engine/test/repository/two.bpmn20.xml").deploy().getId();
Deployment deploymentNoCategory = repositoryService.createDeploymentQuery().deploymentId(deploymentTwoNoKey).singleResult();
assertThat(deploymentNoCategory.getCategory()).isNull();
repositoryService.setDeploymentKey(deploymentTwoNoKey, "newKey");
deploymentNoCategory = repositoryService.createDeploymentQuery().deploymentId(deploymentTwoNoKey).singleResult();
assertThat(deploymentNoCategory.getKey()).isEqualTo("newKey");
} finally {
if (noKeyDeploymentId != null)
undeploy(noKeyDeploymentId);
if (deploymentOneId != null)
undeploy(deploymentOneId);
if (deploymentTwoV1Id != null)
undeploy(deploymentTwoV1Id);
if (deploymentTwoV2Id != null)
undeploy(deploymentTwoV2Id);
if (deploymentTwoNoKey != null)
undeploy(deploymentTwoNoKey);
}
}
Aggregations