上篇整合Web版流程模型设计器,现在我们创建空的流程模型来测试一下
代码如下:
@Controller
@RequestMapping("/model")
public class ModelController {
public static final String name = "请假流程模型";
public static final String key = "leaveProcess";
public static final String desc = "请输入描述信息......";
public static final int version = 1;
@Resource
RepositoryService service;
@Resource
ObjectMapper mapper;
/**
* 创建空模型窗口:
* 创建模型对象
* 设置对象值
* 存储模型对象(表act_re_model)
* 存储模型对象基础数据(表act_ge_bytearray)
* 跳转到ActivitiModeler,编辑流程图,存储流程图片和流程定义等(表act_ge_bytearray)
*/
@GetMapping("/create")
public void create(HttpServletRequest req, HttpServletResponse resp) {
try {
//1,初始化空的模型
Model model = service.newModel();
model.setName(name);
model.setKey(key);
model.setVersion(version);
//封装模型的json对象
ObjectNode node = mapper.createObjectNode();
node.put(ModelDataJsonConstants.MODEL_NAME,name);
node.put(ModelDataJsonConstants.MODEL_DESCRIPTION,desc);
node.put(ModelDataJsonConstants.MODEL_REVISION,version);
model.setMetaInfo(node.toString());
//保存初始化的模型基本信息数据,存储模型对象(表ACT_RE_MODEL)
service.saveModel(model);
// 封装模型对象基础数据json串
// {"id":"canvas","resourceId":"canvas","stencilset":{"namespace":"http://b3mn.org/stencilset/bpmn2.0#"},"properties":{"process_id":"未定义"}}
ObjectNode editorNode = mapper.createObjectNode();
ObjectNode stencilSetNode = mapper.createObjectNode();
stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
editorNode.replace("stencilset", stencilSetNode);
// 标识key
ObjectNode propertiesNode = mapper.createObjectNode();
propertiesNode.put("process_id", key);
editorNode.replace("properties", propertiesNode);
// 存储模型对象基础数据(表 ACT_GE_BYTEARRAY )
service.addModelEditorSource(model.getId(),editorNode.toString().getBytes("UTF-8"));
// 编辑流程模型时,只需要直接跳转此url并传递上modelId即可
resp.sendRedirect(req.getContextPath() + "/modeler.html?modelId=" + model.getId());
} catch (Exception e) {
e.printStackTrace();
}
}
}
运行以下代码
@SpringBootApplication
public class workflowApplication {
public static void main(String[] args) {
SpringApplication.run(workflowApplication.class,args);
}
}
显示结果:
web端绘制请假流程定义模型
点击保存时会报400错误
需要将ModelSaveRestResource类的saveModel方法中的@RequestBody修改为@RequestParam
然后重启,再尝试保存,成功,数据库的act_re_mode也有相关数据: