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