use of org.flowable.bpmn.model.BpmnModel in project plumdo-work by wengwh.
the class ProcessDefinitionCopyResource method copyProcessDefinition.
@RequestMapping(value = "/process-definition/{processDefinitionId}/copy", method = RequestMethod.POST, produces = "application/json", name = "复制流程定义")
@ResponseStatus(value = HttpStatus.CREATED)
public ProcessDefinitionResponse copyProcessDefinition(@PathVariable String processDefinitionId, @RequestBody(required = false) ProcessDefinitionCopyRequest processDefinitionCopyRequest) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
try {
String name = null;
if (processDefinitionCopyRequest != null && processDefinitionCopyRequest.getName() != null) {
name = processDefinitionCopyRequest.getName();
} else {
name = "CopyOf" + processDefinition.getName();
}
String key = null;
if (processDefinitionCopyRequest != null && processDefinitionCopyRequest.getKey() != null) {
key = processDefinitionCopyRequest.getKey();
} else {
// 保证key不重复使用时间戳
key = "CopyOf" + System.currentTimeMillis();
}
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
bpmnModel.getMainProcess().setName(name);
bpmnModel.getMainProcess().setId(key);
byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(bpmnModel);
String fileName = processDefinition.getResourceName();
ByteArrayInputStream bis = new ByteArrayInputStream(bpmnBytes);
deploymentBuilder.addInputStream(fileName, bis);
deploymentBuilder.name(fileName);
if (processDefinition.getTenantId() != null) {
deploymentBuilder.tenantId(processDefinition.getTenantId());
}
String deploymentId = deploymentBuilder.deploy().getId();
ProcessDefinition processDefinitionNew = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
return restResponseFactory.createProcessDefinitionResponse(processDefinitionNew);
} catch (Exception e) {
throw new FlowableException("Error copy process-definition", e);
}
}
use of org.flowable.bpmn.model.BpmnModel in project plumdo-work by wengwh.
the class ModelEditorResource method saveModel.
@RequestMapping(value = "/models/{modelId}/editor", method = { RequestMethod.POST }, name = "模型设计器保存模型")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public void saveModel(@PathVariable String modelId, @RequestBody ModelEditorJsonRequest values) {
try {
Model model = getModelFromRequest(modelId);
ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
modelJson.put(MODEL_NAME, values.getName());
modelJson.put(MODEL_DESCRIPTION, values.getDescription());
model.setMetaInfo(modelJson.toString());
model.setName(values.getName());
if (model.getDeploymentId() != null) {
model.setDeploymentId(null);
}
if (values.isAddVersion()) {
model.setVersion(model.getVersion() + 1);
}
repositoryService.saveModel(model);
repositoryService.addModelEditorSource(model.getId(), values.getJson_xml().getBytes("utf-8"));
ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(values.getJson_xml().getBytes("utf-8"));
BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", Collections.<String>emptyList(), Collections.<String>emptyList(), processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0);
repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(resource));
} catch (Exception e) {
LOGGER.error("Error saving model", e);
throw new FlowableException("Error saving model", e);
}
}
use of org.flowable.bpmn.model.BpmnModel in project syncope by apache.
the class FlowableUserWorkflowAdapter method importDefinition.
@Override
public void importDefinition(final String key, final WorkflowDefinitionFormat format, final String definition) {
ProcessDefinition procDef = getProcessDefinitionByKey(key);
String resourceName = procDef == null ? key + ".bpmn20.xml" : procDef.getResourceName();
Deployment deployment;
switch(format) {
case JSON:
JsonNode definitionNode;
try {
definitionNode = OBJECT_MAPPER.readTree(definition);
if (definitionNode.has(MODEL_DATA_JSON_MODEL)) {
definitionNode = definitionNode.get(MODEL_DATA_JSON_MODEL);
}
if (!definitionNode.has(BpmnJsonConverter.EDITOR_CHILD_SHAPES)) {
throw new IllegalArgumentException("Could not find JSON node " + BpmnJsonConverter.EDITOR_CHILD_SHAPES);
}
BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(definitionNode);
deployment = FlowableDeployUtils.deployDefinition(engine, resourceName, new BpmnXMLConverter().convertToXML(bpmnModel));
} catch (Exception e) {
throw new WorkflowException("While creating or updating process " + key, e);
}
break;
case XML:
default:
deployment = FlowableDeployUtils.deployDefinition(engine, resourceName, definition.getBytes());
}
procDef = getProcessDefinitionByDeploymentId(deployment.getId());
if (!key.equals(procDef.getKey())) {
throw new WorkflowException("Mismatching key: expected " + key + ", found " + procDef.getKey());
}
FlowableDeployUtils.deployModel(engine, procDef);
}
use of org.flowable.bpmn.model.BpmnModel in project plumdo-work by wengwh.
the class DeployModelCmd method execute.
@Override
public Deployment execute(CommandContext commandContext) {
Deployment deployment;
RepositoryService repositoryService = CommandContextUtil.getProcessEngineConfiguration(commandContext).getRepositoryService();
Model model = repositoryService.getModel(modelId);
if (model == null) {
throw new FlowableObjectNotFoundException("Could not find a model with id '" + modelId + "'.", Model.class);
}
byte[] editorSource = CommandContextUtil.getProcessEngineConfiguration(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();
model.setDeploymentId(deployment.getId());
} catch (Exception e) {
if (e instanceof FlowableException) {
throw (FlowableException) e;
}
throw new FlowableException(e.getMessage(), e);
}
return deployment;
}
use of org.flowable.bpmn.model.BpmnModel in project plumdo-work by wengwh.
the class ModelXmlResource method getModelXml.
@GetMapping(value = "/models/{modelId}/xml", name = "获取模型XML")
public ResponseEntity<byte[]> getModelXml(@PathVariable String modelId) {
Model model = getModelFromRequest(modelId);
try {
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(model.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.TEXT_XML);
return new ResponseEntity<>(IOUtils.toByteArray(in), responseHeaders, HttpStatus.OK);
} catch (Exception e) {
logger.error("获取模型XML信息异常", e);
exceptionFactory.throwDefinedException(ErrorConstant.MODEL_XML_READ_ERROR, e.getMessage());
}
return null;
}
Aggregations