use of org.flowable.engine.RepositoryService in project plumdo-work by wengwh.
the class DeployModelCmd method execute.
public Deployment execute(CommandContext commandContext) {
Deployment deployment = null;
RepositoryService repositoryService = commandContext.getProcessEngineConfiguration().getRepositoryService();
Model model = repositoryService.getModel(modelId);
if (model == null) {
throw new FlowableObjectNotFoundException("Could not find a model with id '" + modelId + "'.", Model.class);
}
byte[] editorSource = commandContext.getModelEntityManager().findEditorSourceByModelId(modelId);
if (editorSource == null) {
throw new FlowableObjectNotFoundException("Model with id '" + modelId + "' does not have source available.", String.class);
}
try {
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(editorSource);
BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(bpmnModel);
String fileName = model.getId() + ".bpmn20.xml";
ByteArrayInputStream bis = new ByteArrayInputStream(bpmnBytes);
deploymentBuilder.addInputStream(fileName, bis);
deploymentBuilder.name(fileName);
// modelId设置为部署的分类字段作为后续关联的需要
deploymentBuilder.category(model.getId());
if (model.getTenantId() != null) {
deploymentBuilder.tenantId(model.getTenantId());
}
deployment = deploymentBuilder.deploy();
// 设置模型的部署ID
model.setDeploymentId(deployment.getId());
} catch (Exception e) {
if (e instanceof FlowableException) {
throw (FlowableException) e;
}
throw new FlowableException(e.getMessage(), e);
}
return deployment;
}
Aggregations