org.activiti.engine.form.TaskFormData Java Examples

The following examples show how to use org.activiti.engine.form.TaskFormData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    if (taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("task", task);
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else {
        mav.addObject("taskFormData", taskFormData);
    }
    return mav;
}
 
Example #2
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    if (taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("task", task);
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else {
        mav.addObject("taskFormData", taskFormData);
    }
    return mav;
}
 
Example #3
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    if (taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("task", task);
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else {
        mav.addObject("taskFormData", taskFormData);
    }
    return mav;
}
 
Example #4
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    if (taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("task", task);
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else {
        mav.addObject("taskFormData", taskFormData);
    }
    return mav;
}
 
Example #5
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    if (taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("task", task);
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else {
        mav.addObject("taskFormData", taskFormData);
    }
    return mav;
}
 
Example #6
Source File: GetTaskFormCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public TaskFormData execute(CommandContext commandContext) {
    TaskEntity task = commandContext
            .getTaskEntityManager()
            .findTaskById(taskId);
    if (task == null) {
        throw new ActivitiObjectNotFoundException("No task found for taskId '" + taskId + "'", Task.class);
    }

    if (task.getTaskDefinition() != null) {
        TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
        if (taskFormHandler == null) {
            throw new ActivitiException("No taskFormHandler specified for task '" + taskId + "'");
        }

        return taskFormHandler.createTaskForm(task);
    } else {
        // Standalone task, no TaskFormData available
        return null;
    }
}
 
Example #7
Source File: ActivitiResourceMapperTest.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
@Test
public void checkForm() {
	Map<String, Object> variables = mapper.mapToVariables(formResource);
	Assert.assertEquals(1, variables.size());
	Assert.assertEquals(Boolean.TRUE, variables.get("approved"));

	TestForm resourceCopy = new TestForm();
	mapper.mapFromVariables(resourceCopy, variables);
	checkFormResource(resourceCopy);

	List<FormProperty> formProperties = new ArrayList<>();
	FormProperty formProperty = Mockito.mock(FormProperty.class);
	Mockito.when(formProperty.getId()).thenReturn("approved");
	Mockito.when(formProperty.getValue()).thenReturn("true");
	formProperties.add(formProperty);

	TaskFormData formData = Mockito.mock(TaskFormData.class);
	Mockito.when(formData.getFormProperties()).thenReturn(formProperties);
	Task task = Mockito.mock(Task.class);
	Mockito.when(task.getId()).thenReturn("someTask");
	Mockito.when(formData.getTask()).thenReturn(task);
	TestForm formCopy = mapper.mapToResource(TestForm.class, formData);
	checkFormResource(formCopy);
	Assert.assertEquals("someTask", formCopy.getId());
}
 
Example #8
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public WorkflowTaskDefinition getTaskDefinition(Task task)
{
	// Get the task-form used (retrieved from cached process-definition)
	TaskFormData taskFormData = formService.getTaskFormData(task.getId());
    String taskDefId = null;
    if(taskFormData != null) 
    {
        taskDefId = taskFormData.getFormKey();
    }
    
    // Fetch node based on cached process-definition
    ReadOnlyProcessDefinition procDef = activitiUtil.getDeployedProcessDefinition(task.getProcessDefinitionId());
    WorkflowNode node = convert(procDef.findActivity(task.getTaskDefinitionKey()), true);
    
    return factory.createTaskDefinition(taskDefId, node, taskDefId, false);
}
 
Example #9
Source File: WorkspaceController.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * 完成任务页面
 * 
 * @return
 */
@RequestMapping("workspace-prepareCompleteTask")
public String prepareCompleteTask(@RequestParam("taskId") String taskId,
        Model model) {
    FormService formService = processEngine.getFormService();

    TaskFormData taskFormData = formService.getTaskFormData(taskId);

    model.addAttribute("taskFormData", taskFormData);

    return "bpm/workspace-prepareCompleteTask";
}
 
Example #10
Source File: SimpleFlowWorkController.java    From activiti-demo with Apache License 2.0 5 votes vote down vote up
/**
     * 跳转到任务执行页面
     * @param request
     * @return
     */
    @RequestMapping(value = "/form.do")
    public String from(HttpServletRequest request,
                       @RequestParam("taskId")String taskId,
                       Model model){

        List<Task> taskList =  taskService.createTaskQuery().taskId(taskId).list();
        Task task = taskList.get(0);
        //获取表单数据
        TaskFormData tfd =  formService.getTaskFormData(taskId);
        List<FormProperty>   fpList = tfd.getFormProperties();

        Map map = runtimeService.getVariables(task.getExecutionId());

        List<ActivityImpl> activityList = new ArrayList<ActivityImpl>();

        try {
            //查找所有可驳回的节点
            activityList = processExtensionService.findBackActivity(taskId);
            //model.addAttribute("activityList",activityList);
        }catch (Exception e){
            e.printStackTrace();
        }


//        model.addAttribute("task",task);
//        model.addAttribute("fpList",fpList);
//        model.addAttribute("map",map);
//        model.addAttribute("taskId",taskId);

        request.setAttribute("task", task);
        request.setAttribute("fpList", fpList);
        request.setAttribute("map", map);
        request.setAttribute("taskId", taskId);
        request.setAttribute("activityList", activityList);
        
        return "/simple/form";
    }
 
Example #11
Source File: GetRenderedTaskFormCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {
    TaskEntity task = commandContext
            .getTaskEntityManager()
            .findTaskById(taskId);
    if (task == null) {
        throw new ActivitiObjectNotFoundException("Task '" + taskId + "' not found", Task.class);
    }

    if (task.getTaskDefinition() == null) {
        throw new ActivitiException("Task form definition for '" + taskId + "' not found");
    }

    TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
    if (taskFormHandler == null) {
        return null;
    }

    FormEngine formEngine = commandContext
            .getProcessEngineConfiguration()
            .getFormEngines()
            .get(formEngineName);

    if (formEngine == null) {
        throw new ActivitiException("No formEngine '" + formEngineName + "' defined process engine configuration");
    }

    TaskFormData taskForm = taskFormHandler.createTaskForm(task);

    return formEngine.renderTaskForm(taskForm);
}
 
Example #12
Source File: JuelFormEngine.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Object renderTaskForm(TaskFormData taskForm) {
    if (taskForm.getFormKey() == null) {
        return null;
    }
    String formTemplateString = getFormTemplateString(taskForm, taskForm.getFormKey());
    ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines();
    TaskEntity task = (TaskEntity) taskForm.getTask();
    return scriptingEngines.evaluate(formTemplateString, ScriptingEngines.DEFAULT_SCRIPTING_LANGUAGE, task.getExecution());
}
 
Example #13
Source File: DefaultTaskFormHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public TaskFormData createTaskForm(TaskEntity task) {
    TaskFormDataImpl taskFormData = new TaskFormDataImpl();
    if (formKey != null) {
        Object formValue = formKey.getValue(task.getExecution());
        if (formValue != null) {
            taskFormData.setFormKey(formValue.toString());
        }
    }
    taskFormData.setDeploymentId(deploymentId);
    taskFormData.setTask(task);
    initializeFormProperties(taskFormData, task.getExecution());
    return taskFormData;
}
 
Example #14
Source File: ActivitiResourceMapper.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
public <T extends FormResource> T mapToResource(Class<T> resourceClass, TaskFormData formData) {
	T resource = io.crnk.core.engine.internal.utils.ClassUtils.newInstance(resourceClass);
	Map<String, Object> formPropertyMap = new HashMap<>();
	List<FormProperty> formProperties = formData.getFormProperties();
	for (FormProperty formProperty : formProperties) {
		formPropertyMap.put(formProperty.getId(), formProperty.getValue());
	}
	copyInternal(resource, null, formPropertyMap, true, Optional.empty());
	resource.setId(formData.getTask().getId());
	return resource;
}
 
Example #15
Source File: FormResourceRepository.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Override
public F findOne(String id, QuerySpec querySpec) {
    try {
        TaskFormData taskFormData = formService.getTaskFormData(id);

        FormResource formResource = resourceMapper.mapToResource(getResourceClass(), taskFormData);
        return (F) formResource;
    } catch (ActivitiObjectNotFoundException e) {
        // happens after completion when task is returned one last time.
        // FIXME better solution since still log out
        return null;
    }
}
 
Example #16
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Converts the given task into a {@link WorkflowTask}, allows ignoring domain mismatch (ALF-12264)
 * @param task Task
 * @param ignoreDomainMismatch whether or not to ignore domain mismatch exception
 * @return the converter task. Returns null when the domain mismatched and ignoreDomainMismatch was true.
 */
public WorkflowTask convert(Task task, boolean ignoreDomainMismatch)
{
    if(task == null)
        return null;
    String id = task.getId();
    String defaultTitle = task.getName();
    String defaultDescription = task.getDescription();
    
    WorkflowTaskState state = WorkflowTaskState.IN_PROGRESS;
    WorkflowPath path = getWorkflowPath(task.getExecutionId(), ignoreDomainMismatch);
    
    if(path != null) 
    {
    	// Since the task is active, it's safe to use the active node on
        // the execution path
        WorkflowNode node = path.getNode();
        
        TaskFormData taskFormData =formService.getTaskFormData(task.getId());
        String taskDefId = null;
        if(taskFormData != null) 
        {
            taskDefId = taskFormData.getFormKey();
        }
        WorkflowTaskDefinition taskDef = factory.createTaskDefinition(taskDefId, node, taskDefId, false);
        
        // All task-properties should be fetched, not only local
        Map<QName, Serializable> properties = propertyConverter.getTaskProperties(task);
        
        return factory.createTask(id,
                    taskDef, taskDef.getId(), defaultTitle, defaultDescription, state, path, properties);
    }
    else
    {
    	// Ignoring this task, domain mismatched and safely ignoring that
    	return null;
    }
}
 
Example #17
Source File: FormPropertyDefaultValueTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testDefaultValue() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("FormPropertyDefaultValueTest.testDefaultValue");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  TaskFormData formData = formService.getTaskFormData(task.getId());
  List<FormProperty> formProperties = formData.getFormProperties();
  assertEquals(4, formProperties.size());

  for (FormProperty prop : formProperties) {
    if ("booleanProperty".equals(prop.getId())) {
      assertEquals("true", prop.getValue());
    } else if ("stringProperty".equals(prop.getId())) {
      assertEquals("someString", prop.getValue());
    } else if ("longProperty".equals(prop.getId())) {
      assertEquals("42", prop.getValue());
    } else if ("longExpressionProperty".equals(prop.getId())) {
      assertEquals("23", prop.getValue());
    } else {
      assertTrue("Invalid form property: " + prop.getId(), false);
    }
  }

  Map<String, String> formDataUpdate = new HashMap<String, String>();
  formDataUpdate.put("longExpressionProperty", "1");
  formDataUpdate.put("booleanProperty", "false");
  formService.submitTaskFormData(task.getId(), formDataUpdate);

  assertEquals(false, runtimeService.getVariable(processInstance.getId(), "booleanProperty"));
  assertEquals("someString", runtimeService.getVariable(processInstance.getId(), "stringProperty"));
  assertEquals(42L, runtimeService.getVariable(processInstance.getId(), "longProperty"));
  assertEquals(1L, runtimeService.getVariable(processInstance.getId(), "longExpressionProperty"));
}
 
Example #18
Source File: FormServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testFormPropertyExpression() {
  Map<String, Object> varMap = new HashMap<String, Object>();
  varMap.put("speaker", "Mike"); // variable name mapping
  Address address = new Address();
  varMap.put("address", address);

  String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
  ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, varMap);

  String taskId = taskService.createTaskQuery().singleResult().getId();
  TaskFormData taskFormData = formService.getTaskFormData(taskId);

  List<FormProperty> formProperties = taskFormData.getFormProperties();
  FormProperty propertySpeaker = formProperties.get(0);
  assertEquals("speaker", propertySpeaker.getId());
  assertEquals("Mike", propertySpeaker.getValue());

  assertEquals(2, formProperties.size());

  Map<String, String> properties = new HashMap<String, String>();
  properties.put("street", "Broadway");
  formService.submitTaskFormData(taskId, properties);

  address = (Address) runtimeService.getVariable(processInstance.getId(), "address");
  assertEquals("Broadway", address.getStreet());
}
 
Example #19
Source File: JuelFormEngine.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Object renderTaskForm(TaskFormData taskForm) {
  if (taskForm.getFormKey() == null) {
    return null;
  }
  String formTemplateString = getFormTemplateString(taskForm, taskForm.getFormKey());
  ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines();
  TaskEntity task = (TaskEntity) taskForm.getTask();
  return scriptingEngines.evaluate(formTemplateString, ScriptingEngines.DEFAULT_SCRIPTING_LANGUAGE, task.getExecution());
}
 
Example #20
Source File: FormPropertyDefaultValueTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testDefaultValue() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("FormPropertyDefaultValueTest.testDefaultValue");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  TaskFormData formData = formService.getTaskFormData(task.getId());
  List<FormProperty> formProperties = formData.getFormProperties();
  assertEquals(4, formProperties.size());

  for (FormProperty prop : formProperties) {
    if ("booleanProperty".equals(prop.getId())) {
      assertEquals("true", prop.getValue());
    } else if ("stringProperty".equals(prop.getId())) {
      assertEquals("someString", prop.getValue());
    } else if ("longProperty".equals(prop.getId())) {
      assertEquals("42", prop.getValue());
    } else if ("longExpressionProperty".equals(prop.getId())) {
      assertEquals("23", prop.getValue());
    } else {
      assertTrue("Invalid form property: " + prop.getId(), false);
    }
  }

  Map<String, String> formDataUpdate = new HashMap<String, String>();
  formDataUpdate.put("longExpressionProperty", "1");
  formDataUpdate.put("booleanProperty", "false");
  formService.submitTaskFormData(task.getId(), formDataUpdate);

  assertEquals(false, runtimeService.getVariable(processInstance.getId(), "booleanProperty"));
  assertEquals("someString", runtimeService.getVariable(processInstance.getId(), "stringProperty"));
  assertEquals(42L, runtimeService.getVariable(processInstance.getId(), "longProperty"));
  assertEquals(1L, runtimeService.getVariable(processInstance.getId(), "longExpressionProperty"));
}
 
Example #21
Source File: FormServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testFormPropertyExpression() {
  Map<String, Object> varMap = new HashMap<String, Object>();
  varMap.put("speaker", "Mike"); // variable name mapping
  Address address = new Address();
  varMap.put("address", address);

  String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
  ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, varMap);

  String taskId = taskService.createTaskQuery().singleResult().getId();
  TaskFormData taskFormData = formService.getTaskFormData(taskId);

  List<FormProperty> formProperties = taskFormData.getFormProperties();
  FormProperty propertySpeaker = formProperties.get(0);
  assertEquals("speaker", propertySpeaker.getId());
  assertEquals("Mike", propertySpeaker.getValue());

  assertEquals(2, formProperties.size());

  Map<String, String> properties = new HashMap<String, String>();
  properties.put("street", "Broadway");
  formService.submitTaskFormData(taskId, properties);

  address = (Address) runtimeService.getVariable(processInstance.getId(), "address");
  assertEquals("Broadway", address.getStreet());
}
 
Example #22
Source File: DefaultTaskFormHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public TaskFormData createTaskForm(TaskEntity task) {
  TaskFormDataImpl taskFormData = new TaskFormDataImpl();
  if (formKey != null) {
    Object formValue = formKey.getValue(task.getExecution());
    if (formValue != null) {
      taskFormData.setFormKey(formValue.toString());
    }
  }
  taskFormData.setDeploymentId(deploymentId);
  taskFormData.setTask(task);
  initializeFormProperties(taskFormData, task.getExecution());
  return taskFormData;
}
 
Example #23
Source File: GetTaskFormCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public TaskFormData execute(CommandContext commandContext) {
  TaskEntity task = commandContext.getTaskEntityManager().findById(taskId);
  if (task == null) {
    throw new ActivitiObjectNotFoundException("No task found for taskId '" + taskId + "'", Task.class);
  }
  
  TaskFormHandler taskFormHandler = FormHandlerUtil.getTaskFormHandlder(task);
  if (taskFormHandler == null) {
    throw new ActivitiException("No taskFormHandler specified for task '" + taskId + "'");
  }

  return taskFormHandler.createTaskForm(task);
}
 
Example #24
Source File: GetRenderedTaskFormCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Object execute(CommandContext commandContext) {
  
  if (taskId == null) {
    throw new ActivitiIllegalArgumentException("Task id should not be null");
  }
  
  TaskEntity task = commandContext.getTaskEntityManager().findById(taskId);
  if (task == null) {
    throw new ActivitiObjectNotFoundException("Task '" + taskId + "' not found", Task.class);
  }
  
  TaskFormHandler taskFormHandler = FormHandlerUtil.getTaskFormHandlder(task);
  if (taskFormHandler != null) {
  
    FormEngine formEngine = commandContext.getProcessEngineConfiguration().getFormEngines().get(formEngineName);

    if (formEngine == null) {
      throw new ActivitiException("No formEngine '" + formEngineName + "' defined process engine configuration");
    }

    TaskFormData taskForm = taskFormHandler.createTaskForm(task);

    return formEngine.renderTaskForm(taskForm);
  }
  
  return null;
}
 
Example #25
Source File: MyFormEngine.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
@Override
public Object renderTaskForm(TaskFormData taskForm) {
    javax.swing.JButton jButton = new javax.swing.JButton();
    jButton.setName("My Task Form Button");
    return jButton;
}
 
Example #26
Source File: AppTest.java    From tutorial with MIT License 4 votes vote down vote up
@Test
public void listTasks() {
    // 1. 查寻/设置 用户和组
    logger.trace("query and create managers group and user waytt if they are not exist.");
    String groupId = "hosts";
    String userId = "dolores";
    //查询有没有ID为 managers 的组
    List<Group> hostGroups = identityService.createGroupQuery().groupId(groupId).list();
    Group hostGroup;
    if(hostGroups == null || hostGroups.size() == 0) {
        // 没有,增加一个
        hostGroup = identityService.newGroup(groupId); //参数是groupId
        hostGroup.setName("接待员");
        hostGroup.setType("business-role");
        identityService.saveGroup(hostGroup);
    }else{
        hostGroup = hostGroups.get(0);
    }

    List<User> users = identityService.createUserQuery().userId(userId).list();
    User userDolores;
    if(users == null || users.size() == 0) {
        userDolores = identityService.newUser(userId);
        userDolores.setFirstName("Dolores");
        userDolores.setLastName("Abernathy");
        userDolores.setPassword("none");
        userDolores.setEmail("[email protected]");
        identityService.saveUser(userDolores);
        identityService.createMembership(userDolores.getId(), hostGroup.getId());
    }else{
        userDolores = users.get(0);
    }


    logger.trace("listTasks");
    List<Task> tasks = taskService.createTaskQuery().list();

    if(tasks == null || tasks.size() == 0){
        logger.trace("donot found any tasks; add one");

        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("applicantName", "Bernard Lowe");
        variables.put("email", "[email protected]");
        variables.put("phoneNumber", "123456789");
        runtimeService.startProcessInstanceByKey("hireProcess", variables);
    }else{
        for(Task t : tasks){
            logger.trace("  task {}, {}, {}, {}, {}", t.getCategory(), t.getClaimTime(),
                    t.getName(), t.getId(), t.getFormKey());


            TaskFormData taskFormData = formService.getTaskFormData(t.getId());
            List<FormProperty> formProperties = taskFormData.getFormProperties();
            for (FormProperty property : formProperties) {
                logger.trace("  FormData property  id: {}, name: {}, type: {} value: {}", property.getId(), property.getName(), property.getType(), property.getValue());
            }

        }
    }

    //query again
    tasks = taskService.createTaskQuery().list();
    assertTrue(tasks.size() > 0);
    for(int i=0; i<tasks.size() && i < 3; i++) {
        //认领几个任务(最多3个)
        Task task = tasks.get(i);
        //认领此任务
        taskService.claim(task.getId(), userDolores.getId());
    }

    //查看dolores用户当前的任务列表
    List<Task> tasksOfDolores = taskService.createTaskQuery().taskAssignee(userDolores.getId()).list();
    for (Task dt : tasksOfDolores) {
        logger.trace("Dolores's task: {}, {}, {}", dt.getId(), dt.getCreateTime(), dt.getProcessVariables());
        // 设置此任务为完成状态
        Map<String, Object> vars = new HashMap<>();
        vars.put("telephoneInterviewOutcome", true);
        vars.put("techOk", false);
        vars.put("financialOk", true);
        taskService.complete(dt.getId(), vars);

        // 查询这个任务对应的流程的最终状态
        HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().processInstanceId(dt.getProcessInstanceId()).singleResult();
        logger.trace("HistoricProcessInstance {}, {}, {}, {}", hpi.getName(), hpi.getEndActivityId(), hpi.getStartTime(), hpi.getEndTime());
    }


}
 
Example #27
Source File: MyFormEngine.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
@Override
public Object renderTaskForm(TaskFormData taskForm) {
    javax.swing.JButton jButton = new javax.swing.JButton();
    jButton.setName("My Task Form Button");
    return jButton;
}
 
Example #28
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    Task task = null;

    // 外置表单
    if (taskFormData != null && taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else if (taskFormData != null) { // 动态表单
        mav.addObject("taskFormData", taskFormData);
        task = taskFormData.getTask();
    } else { // 手动创建的任务(包括子任务)
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("manualTask", true);
    }
    mav.addObject("task", task);

    // 读取任务参与人列表
    List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(taskId);
    mav.addObject("identityLinksForTask", identityLinksForTask);

    // 读取所有人员
    List<User> users = identityService.createUserQuery().list();
    mav.addObject("users", users);

    // 读取所有组
    List<Group> groups = identityService.createGroupQuery().list();
    mav.addObject("groups", groups);

    // 读取子任务
    List<HistoricTaskInstance> subTasks = historyService.createHistoricTaskInstanceQuery().taskParentTaskId(taskId).list();
    mav.addObject("subTasks", subTasks);

    // 读取上级任务
    if (task != null && task.getParentTaskId() != null) {
        HistoricTaskInstance parentTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getParentTaskId()).singleResult();
        mav.addObject("parentTask", parentTask);
    }

    // 读取附件
    List<Attachment> attachments = null;
    if (task.getTaskDefinitionKey() != null) {
        attachments = taskService.getTaskAttachments(taskId);
    } else {
        attachments = taskService.getProcessInstanceAttachments(task.getProcessInstanceId());
    }
    mav.addObject("attachments", attachments);

    return mav;
}
 
Example #29
Source File: MyFormEngine.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
@Override
public Object renderTaskForm(TaskFormData taskForm) {
    javax.swing.JButton jButton = new javax.swing.JButton();
    jButton.setName("My Task Form Button");
    return jButton;
}
 
Example #30
Source File: TaskController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取用户任务的表单字段
 */
@RequestMapping(value = "task/getform/{taskId}")
public ModelAndView readTaskForm(@PathVariable("taskId") String taskId) throws Exception {
    String viewName = "chapter6/task-form";
    ModelAndView mav = new ModelAndView(viewName);
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    Task task = null;

    // 外置表单
    if (taskFormData != null && taskFormData.getFormKey() != null) {
        Object renderedTaskForm = formService.getRenderedTaskForm(taskId);
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("taskFormData", renderedTaskForm);
        mav.addObject("hasFormKey", true);
    } else if (taskFormData != null) { // 动态表单
        mav.addObject("taskFormData", taskFormData);
        task = taskFormData.getTask();
    } else { // 手动创建的任务(包括子任务)
        task = taskService.createTaskQuery().taskId(taskId).singleResult();
        mav.addObject("manualTask", true);
    }
    mav.addObject("task", task);

    // 读取任务参与人列表
    List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(taskId);
    mav.addObject("identityLinksForTask", identityLinksForTask);

    // 读取所有人员
    List<User> users = identityService.createUserQuery().list();
    mav.addObject("users", users);

    // 读取所有组
    List<Group> groups = identityService.createGroupQuery().list();
    mav.addObject("groups", groups);

    // 读取子任务
    List<HistoricTaskInstance> subTasks = historyService.createHistoricTaskInstanceQuery().taskParentTaskId(taskId).list();
    mav.addObject("subTasks", subTasks);

    // 读取上级任务
    if (task != null && task.getParentTaskId() != null) {
        HistoricTaskInstance parentTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getParentTaskId()).singleResult();
        mav.addObject("parentTask", parentTask);
    }

    // 读取附件
    List<Attachment> attachments = null;
    if (task.getTaskDefinitionKey() != null) {
        attachments = taskService.getTaskAttachments(taskId);
    } else {
        attachments = taskService.getProcessInstanceAttachments(task.getProcessInstanceId());
    }
    mav.addObject("attachments", attachments);

    return mav;
}