Search in sources :

Example 71 with Deployment

use of org.activiti.engine.repository.Deployment in project tutorials-java by Artister.

the class ModelController method deploy.

/**
 * 发布模型为流程定义
 *
 * @param id
 * @return
 * @throws Exception
 */
@ApiOperation(value = "发布模型为流程定义")
@PostMapping("{id}/deployment")
public Object deploy(@PathVariable("id") String id) throws Exception {
    // 获取模型
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Model modelData = repositoryService.getModel(id);
    byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
    if (bytes == null) {
        return failed("模型数据为空,请先设计流程并成功保存,再进行发布。");
    }
    JsonNode modelNode = new ObjectMapper().readTree(bytes);
    BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    if (model.getProcesses().size() == 0) {
        return failed("数据模型不符要求,请至少设计一条主线流程。");
    }
    byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
    // 发布流程
    String processName = modelData.getName() + ".bpmn20.xml";
    DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes, "UTF-8"));
    Deployment deployment = deploymentBuilder.deploy();
    modelData.setDeploymentId(deployment.getId());
    repositoryService.saveModel(modelData);
    return success();
}
Also used : Model(org.activiti.engine.repository.Model) BpmnModel(org.activiti.bpmn.model.BpmnModel) Deployment(org.activiti.engine.repository.Deployment) JsonNode(com.fasterxml.jackson.databind.JsonNode) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) RepositoryService(org.activiti.engine.RepositoryService) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) ApiOperation(io.swagger.annotations.ApiOperation)

Example 72 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class DeployCmd method executeDeploy.

protected Deployment executeDeploy(CommandContext commandContext) {
    DeploymentEntity deployment = deploymentBuilder.getDeployment();
    deployment.setDeploymentTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
    setProjectReleaseVersion(deployment);
    deployment.setVersion(1);
    if (deploymentBuilder.isDuplicateFilterEnabled()) {
        List<Deployment> existingDeployments = new ArrayList<Deployment>();
        if (deployment.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(deployment.getTenantId())) {
            DeploymentEntity existingDeployment = commandContext.getDeploymentEntityManager().findLatestDeploymentByName(deployment.getName());
            if (existingDeployment != null) {
                existingDeployments.add(existingDeployment);
            }
        } else {
            List<Deployment> deploymentList = commandContext.getProcessEngineConfiguration().getRepositoryService().createDeploymentQuery().deploymentName(deployment.getName()).deploymentTenantId(deployment.getTenantId()).orderByDeploymentId().desc().list();
            if (!deploymentList.isEmpty()) {
                existingDeployments.addAll(deploymentList);
            }
        }
        DeploymentEntity existingDeployment = null;
        if (!existingDeployments.isEmpty()) {
            existingDeployment = (DeploymentEntity) existingDeployments.get(0);
        }
        if (existingDeployment != null) {
            if (deploymentsDiffer(deployment, existingDeployment)) {
                applyUpgradeLogic(deployment, existingDeployment);
            } else {
                return existingDeployment;
            }
        }
    }
    deployment.setNew(true);
    // Save the data
    commandContext.getDeploymentEntityManager().insert(deployment);
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, deployment));
    }
    // Deployment settings
    Map<String, Object> deploymentSettings = new HashMap<String, Object>();
    deploymentSettings.put(DeploymentSettings.IS_BPMN20_XSD_VALIDATION_ENABLED, deploymentBuilder.isBpmn20XsdValidationEnabled());
    deploymentSettings.put(DeploymentSettings.IS_PROCESS_VALIDATION_ENABLED, deploymentBuilder.isProcessValidationEnabled());
    // Actually deploy
    commandContext.getProcessEngineConfiguration().getDeploymentManager().deploy(deployment, deploymentSettings);
    if (deploymentBuilder.getProcessDefinitionsActivationDate() != null) {
        scheduleProcessDefinitionActivation(commandContext, deployment);
    }
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, deployment));
    }
    return deployment;
}
Also used : DeploymentEntity(org.activiti.engine.impl.persistence.entity.DeploymentEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Deployment(org.activiti.engine.repository.Deployment)

Example 73 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class ModelQueryTest method testByDeploymentId.

public void testByDeploymentId() {
    Deployment deployment = repositoryService.createDeployment().addString("test", "test").deploy();
    assertThat(repositoryService.createModelQuery().deploymentId(deployment.getId()).count()).isEqualTo(0);
    assertThat(repositoryService.createModelQuery().deployed().count()).isEqualTo(0);
    assertThat(repositoryService.createModelQuery().notDeployed().count()).isEqualTo(1);
    Model model = repositoryService.createModelQuery().singleResult();
    model.setDeploymentId(deployment.getId());
    repositoryService.saveModel(model);
    assertThat(repositoryService.createModelQuery().deploymentId(deployment.getId()).count()).isEqualTo(1);
    assertThat(repositoryService.createModelQuery().deployed().count()).isEqualTo(1);
    assertThat(repositoryService.createModelQuery().notDeployed().count()).isEqualTo(0);
    // Cleanup
    repositoryService.deleteDeployment(deployment.getId(), true);
    // After cleanup the model should still exist
    assertThat(repositoryService.createDeploymentQuery().count()).isEqualTo(0);
    assertThat(repositoryService.createModelQuery().deploymentId(deployment.getId()).count()).isEqualTo(0);
    assertThat(repositoryService.createModelQuery().notDeployed().count()).isEqualTo(1);
    assertThat(repositoryService.createModelQuery().count()).isEqualTo(1);
}
Also used : Model(org.activiti.engine.repository.Model) Deployment(org.activiti.engine.repository.Deployment)

Example 74 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class DeploymentQueryTest method testVerifyDeploymentProperties.

public void testVerifyDeploymentProperties() {
    List<Deployment> deployments = repositoryService.createDeploymentQuery().orderByDeploymentName().asc().list();
    Deployment deploymentOne = deployments.get(0);
    assertThat(deploymentOne.getName()).isEqualTo("org/activiti/engine/test/repository/one.bpmn20.xml");
    assertThat(deploymentOne.getId()).isEqualTo(deploymentOneId);
    Deployment deploymentTwo = deployments.get(1);
    assertThat(deploymentTwo.getName()).isEqualTo("org/activiti/engine/test/repository/two.bpmn20.xml");
    assertThat(deploymentTwo.getId()).isEqualTo(deploymentTwoId);
    deployments = repositoryService.createDeploymentQuery().deploymentNameLike("%one%").orderByDeploymentName().asc().list();
    assertThat(deployments.get(0).getName()).isEqualTo("org/activiti/engine/test/repository/one.bpmn20.xml");
    assertThat(deployments).hasSize(1);
    assertThat(repositoryService.createDeploymentQuery().orderByDeploymentId().asc().list()).hasSize(2);
    assertThat(repositoryService.createDeploymentQuery().orderByDeploymenTime().asc().list()).hasSize(2);
}
Also used : Deployment(org.activiti.engine.repository.Deployment)

Example 75 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class DeploymentCategoryTest method testDeploymentCategory.

public void testDeploymentCategory() {
    String noCategoryDeploymentId = null;
    String deploymentOneId = null;
    String deploymentTwoV1Id = null;
    String deploymentTwoV2Id = null;
    String deploymentTwoNoCategory = null;
    try {
        noCategoryDeploymentId = repositoryService.createDeployment().name("0").addClasspathResource("org/activiti/engine/test/service/oneTaskProcess.bpmn20.xml").deploy().getId();
        deploymentOneId = repositoryService.createDeployment().name("1").category("one").addClasspathResource("org/activiti/engine/test/repository/one.bpmn20.xml").deploy().getId();
        deploymentTwoV1Id = repositoryService.createDeployment().name("2v1").category("two").addClasspathResource("org/activiti/engine/test/repository/two.bpmn20.xml").deploy().getId();
        deploymentTwoV2Id = repositoryService.createDeployment().name("2v2").category("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().deploymentCategory("one").list());
        Set<String> expectedDeploymentNames = new HashSet<String>();
        expectedDeploymentNames.add("1");
        assertThat(deploymentNames).isEqualTo(expectedDeploymentNames);
        deploymentNames = getDeploymentNames(repositoryService.createDeploymentQuery().deploymentCategoryNotEquals("two").list());
        expectedDeploymentNames.add("0");
        assertThat(deploymentNames).isEqualTo(expectedDeploymentNames);
        deploymentTwoNoCategory = repositoryService.createDeployment().name("noCategory").addClasspathResource("org/activiti/engine/test/repository/two.bpmn20.xml").deploy().getId();
        Deployment deploymentNoCategory = repositoryService.createDeploymentQuery().deploymentId(deploymentTwoNoCategory).singleResult();
        assertThat(deploymentNoCategory.getCategory()).isNull();
        repositoryService.setDeploymentCategory(deploymentTwoNoCategory, "newCategory");
        deploymentNoCategory = repositoryService.createDeploymentQuery().deploymentId(deploymentTwoNoCategory).singleResult();
        assertThat(deploymentNoCategory.getCategory()).isEqualTo("newCategory");
    } finally {
        if (noCategoryDeploymentId != null)
            undeploy(noCategoryDeploymentId);
        if (deploymentOneId != null)
            undeploy(deploymentOneId);
        if (deploymentTwoV1Id != null)
            undeploy(deploymentTwoV1Id);
        if (deploymentTwoV2Id != null)
            undeploy(deploymentTwoV2Id);
        if (deploymentTwoNoCategory != null)
            undeploy(deploymentTwoNoCategory);
    }
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) Deployment(org.activiti.engine.repository.Deployment) HashSet(java.util.HashSet)

Aggregations

Deployment (org.activiti.engine.repository.Deployment)96 ArrayList (java.util.ArrayList)11 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)11 ProcessEngine (org.activiti.engine.ProcessEngine)10 RepositoryService (org.activiti.engine.RepositoryService)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 BpmnModel (org.activiti.bpmn.model.BpmnModel)9 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)9 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 DeploymentQuery (org.activiti.engine.repository.DeploymentQuery)8 Test (org.junit.Test)8 ActivitiException (org.activiti.engine.ActivitiException)7 Test (org.junit.jupiter.api.Test)7 HttpGet (org.apache.http.client.methods.HttpGet)6 BPMNDeployment (org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment)6 InputStream (java.io.InputStream)5 HashSet (java.util.HashSet)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5