Search in sources :

Example 1 with DeploymentQuery

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();
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) DeploymentsPaginateList(org.wso2.carbon.bpmn.rest.model.repository.DeploymentsPaginateList) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with DeploymentQuery

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);
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) BPMNDeployment(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment) Deployment(org.activiti.engine.repository.Deployment) TenantRepository(org.wso2.carbon.bpmn.core.deployment.TenantRepository) RegistryException(org.wso2.carbon.registry.api.RegistryException) IOException(java.io.IOException) ProcessEngine(org.activiti.engine.ProcessEngine) BPMNDeletableInstances(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeletableInstances)

Example 3 with DeploymentQuery

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;
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) BPMNProcess(org.wso2.carbon.bpmn.core.mgt.model.BPMNProcess) BPMNDeployment(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment) Deployment(org.activiti.engine.repository.Deployment) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 4 with DeploymentQuery

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()]);
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) ArrayList(java.util.ArrayList) BPMNDeployment(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment) Deployment(org.activiti.engine.repository.Deployment) BPMNDeployment(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment)

Example 5 with DeploymentQuery

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);
    }
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) Deployment(org.activiti.engine.repository.Deployment) HashSet(java.util.HashSet)

Aggregations

DeploymentQuery (org.activiti.engine.repository.DeploymentQuery)28 Deployment (org.activiti.engine.repository.Deployment)8 BPMNDeployment (org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment)6 ArrayList (java.util.ArrayList)5 ActivitiException (org.activiti.engine.ActivitiException)3 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)3 ProcessEngine (org.activiti.engine.ProcessEngine)3 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)3 HashSet (java.util.HashSet)2 RepositoryService (org.activiti.engine.RepositoryService)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 Deployment (org.alfresco.rest.workflow.api.model.Deployment)2 BPMNProcess (org.wso2.carbon.bpmn.core.mgt.model.BPMNProcess)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 DataResponse (org.activiti.rest.common.api.DataResponse)1