Activiti6-FormService(学习笔记)重要

Activiti6-FormService(学习笔记)重要

设置流程定义文件:

<?xml version="1.0" encoding="UTF-8"?>

<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"> <process id="my-process">
<!--startEvent/userTask都可以配置的表单项-->
<!-- 1.activiti:formKey指定表单的key,也就是一个url,获取到这个值以后,
后端可以设置一些算法,和逻辑,解析出所定义的模板 -->
<startEvent id="start" activiti:formKey="/rest/process/form/start">
<!--扩展属性,设置表单内容-->
<extensionElements>
<activiti:formProperty id="message" name="信息" type="string" required="true"/>
</extensionElements>
</startEvent> <sequenceFlow id="flow1" sourceRef="start" targetRef="someTask" /> <userTask id="someTask" name="Activiti is awesome!"
activiti:formKey="/rest/process/form/userTask">
<extensionElements>
<activiti:formProperty id="yesORno" name="审批" type="string" required="true"/>
</extensionElements>
</userTask>
<sequenceFlow id="flow2" sourceRef="someTask" targetRef="end" /> <endEvent id="end" /> </process> </definitions>

编写测试类:

public class FormServiceTest {
private static final Logger LOGGER = LoggerFactory.getLogger(FormServiceTest.class); @Rule
public ActivitiRule activitiRule = new ActivitiRule(); @Test
@Deployment(resources = {"my-process-form.bpmn20.xml"})//部署定义文件
public void testFormService(){
FormService formService = activitiRule.getFormService();
//获取流程定义文件
ProcessDefinition processDefinition = activitiRule.getRepositoryService().createProcessDefinitionQuery().singleResult(); //用formService获取前面在流程定义文件里的内容
//获取startFormKey
String startFormKey = formService.getStartFormKey(processDefinition.getId());
LOGGER.info("startFormKey = {}",startFormKey);
//获取表单内容(区分start还是task表单),要先获取FromData,然后从中解析出表单的数量跟列表
StartFormData startFormData = formService.getStartFormData(processDefinition.getId());
//通过startFormData获取表单集合、列表
List<FormProperty> formProperties = startFormData.getFormProperties();
for (FormProperty formProperty : formProperties) {
LOGGER.info("formProperty = {}",ToStringBuilder.reflectionToString(formProperty,ToStringStyle.JSON_STYLE));
}
//获取task内容.这里用到的getTaskFormData()需要获取TaskID但是只有流程启
// 动后运行到Task才会有TaskID,所以在这里需要启动流程
//假装一个表单提交需要用到的内容
Map<String,String> properties = Maps.newHashMap();
properties.put("message","my test message");
//用提交表单的方式 启动流程
ProcessInstance processInstance = formService.submitStartFormData(processDefinition.getId(), properties);
//Task就会生成了,接着获取Task
Task task = activitiRule.getTaskService().createTaskQuery().singleResult();
//接着就可以获取Task表单了
TaskFormData taskFormData = formService.getTaskFormData(task.getId());
List<FormProperty> taskFormDataFormProperties = taskFormData.getFormProperties();
for (FormProperty property : taskFormDataFormProperties) {
LOGGER.info("property = {}",ToStringBuilder.reflectionToString(property,ToStringStyle.JSON_STYLE));
}
//让表单继续执行
// 这里Task里的yesORno设的是必填属性,所以必须给予其值
HashMap<String,String> properties1 = Maps.newHashMap();
properties1.put("yesORno","yes");
formService.submitTaskFormData(task.getId(),properties1);
//查询一下表单是否还存在
Task task1 = activitiRule.getTaskService().createTaskQuery().taskId(task.getId()).singleResult();
LOGGER.info("task1 = {}",task1); } }

测试结果如下:

ProcessEngine default created
startFormKey = /rest/process/form/start
formProperty = {"id":"message","name":"\u4FE1\u606F","type":"org.activiti.engine.impl.form.StringFormType@352c308","isRequired":true,"isReadable":true,"isWritable":true,"value":null}
property = {"id":"yesORno","name":"\u5BA1\u6279","type":"org.activiti.engine.impl.form.StringFormType@352c308","isRequired":true,"isReadable":true,"isWritable":true,"value":null}
task1 = null
上一篇:Java 操作符


下一篇:MATLAB:图像选取局部区域滤波(roicolor、roipoly、roifill、fspecial、roifilt2函数)