org.activiti.engine.impl.form.TaskFormHandler Java Examples

The following examples show how to use org.activiti.engine.impl.form.TaskFormHandler. 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: FormHandlerUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static TaskFormHandler getTaskFormHandlder(String processDefinitionId, String taskId) {
  org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
  FlowElement flowElement = process.getFlowElement(taskId, true);
  if (flowElement instanceof UserTask) {
    UserTask userTask = (UserTask) flowElement;
    
    ProcessDefinition processDefinitionEntity = ProcessDefinitionUtil.getProcessDefinition(processDefinitionId);
    DeploymentEntity deploymentEntity = Context.getProcessEngineConfiguration()
        .getDeploymentEntityManager().findById(processDefinitionEntity.getDeploymentId());
    
    TaskFormHandler taskFormHandler = new DefaultTaskFormHandler();
    taskFormHandler.parseConfiguration(userTask.getFormProperties(), userTask.getFormKey(), deploymentEntity, processDefinitionEntity);
    
    return taskFormHandler;
  }
  
  return null;
}
 
Example #2
Source File: SubmitTaskFormCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected Void execute(CommandContext commandContext, TaskEntity task) {
  
  // Backwards compatibility
  if (task.getProcessDefinitionId() != null) {
    if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, task.getProcessDefinitionId())) {
      Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); 
      activiti5CompatibilityHandler.submitTaskFormData(taskId, properties, completeTask);
      return null;
    }
  }
  
  commandContext.getHistoryManager().recordFormPropertiesSubmitted(task.getExecution(), properties, taskId);
  
  TaskFormHandler taskFormHandler = FormHandlerUtil.getTaskFormHandlder(task);

  if (taskFormHandler != null) {
    taskFormHandler.submitFormProperties(properties, task.getExecution());

    if (completeTask) {
      executeTaskComplete(commandContext, task, null, false);
    }

  }
  
  return null;
}
 
Example #3
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private String getFormKey(PvmActivity act)
{
    if(act instanceof ActivityImpl) 
    {
        ActivityImpl actImpl = (ActivityImpl) act;
        if (actImpl.getActivityBehavior() instanceof UserTaskActivityBehavior)        
        {
            UserTaskActivityBehavior uta = (UserTaskActivityBehavior) actImpl.getActivityBehavior();
            TaskFormHandler handler = uta.getTaskDefinition().getTaskFormHandler();
            if(handler != null && handler instanceof DefaultTaskFormHandler)
            {
                // We cast to DefaultTaskFormHandler since we do not configure our own
                return ((DefaultTaskFormHandler)handler).getFormKey().getExpressionText();
            }
            
        }
    }
    return null;
}
 
Example #4
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 #5
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 #6
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 #7
Source File: ActivitiTaskTypeManager.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public TypeDefinition getFullTaskDefinition(DelegateTask delegateTask)
{
    FormData formData = null;
    TaskEntity taskEntity = (TaskEntity) delegateTask;
    TaskFormHandler taskFormHandler = taskEntity.getTaskDefinition().getTaskFormHandler();
    if (taskFormHandler != null)
    {
        formData = taskFormHandler.createTaskForm(taskEntity);
    }
    return getFullTaskDefinition(delegateTask.getId(), formData);
}
 
Example #8
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String getFormKey(TaskDefinition taskDefinition) 
{
	 TaskFormHandler handler = taskDefinition.getTaskFormHandler();
     if(handler != null && handler instanceof DefaultTaskFormHandler)
     {
         // We cast to DefaultTaskFormHandler since we do not configure our own
         return ((DefaultTaskFormHandler)handler).getFormKey().getExpressionText();
     }
     return null;
}
 
Example #9
Source File: TaskCreateListener.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String getFormKey(DelegateTask task)
{
    FormData formData = null;
    TaskEntity taskEntity = (TaskEntity) task;
    TaskFormHandler taskFormHandler = taskEntity.getTaskDefinition().getTaskFormHandler();
    if (taskFormHandler != null)
    {
        formData = taskFormHandler.createTaskForm(taskEntity);
        if (formData != null) { return formData.getFormKey(); }
    }
    return null;
}
 
Example #10
Source File: TaskNotificationListener.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String getFormKey(DelegateTask task)
{
    FormData formData = null;
    TaskEntity taskEntity = (TaskEntity) task;
    TaskFormHandler taskFormHandler = taskEntity.getTaskDefinition().getTaskFormHandler();
    if (taskFormHandler != null)
    {
        formData = taskFormHandler.createTaskForm(taskEntity);
        if (formData != null) { return formData.getFormKey(); }
    }
    return null;
}
 
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: SubmitTaskFormCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected Object execute(CommandContext commandContext, TaskEntity task) {
    commandContext.getHistoryManager().reportFormPropertiesSubmitted(task.getExecution(), properties, taskId);

    TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
    taskFormHandler.submitFormProperties(properties, task.getExecution());

    if (completeTask) {
        task.complete(properties, false, true);
    }

    return null;
}
 
Example #13
Source File: UserTaskParseHandler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public TaskDefinition parseTaskDefinition(BpmnParse bpmnParse, UserTask userTask, String taskDefinitionKey, ProcessDefinitionEntity processDefinition) {
    TaskFormHandler taskFormHandler = new DefaultTaskFormHandler();
    taskFormHandler.parseConfiguration(userTask.getFormProperties(), userTask.getFormKey(), bpmnParse.getDeployment(), processDefinition);

    TaskDefinition taskDefinition = new TaskDefinition(taskFormHandler);

    taskDefinition.setKey(taskDefinitionKey);
    processDefinition.getTaskDefinitions().put(taskDefinitionKey, taskDefinition);
    ExpressionManager expressionManager = bpmnParse.getExpressionManager();

    if (StringUtils.isNotEmpty(userTask.getName())) {
        taskDefinition.setNameExpression(expressionManager.createExpression(userTask.getName()));
    }

    if (StringUtils.isNotEmpty(userTask.getDocumentation())) {
        taskDefinition.setDescriptionExpression(expressionManager.createExpression(userTask.getDocumentation()));
    }

    if (StringUtils.isNotEmpty(userTask.getAssignee())) {
        taskDefinition.setAssigneeExpression(expressionManager.createExpression(userTask.getAssignee()));
    }
    if (StringUtils.isNotEmpty(userTask.getOwner())) {
        taskDefinition.setOwnerExpression(expressionManager.createExpression(userTask.getOwner()));
    }
    for (String candidateUser : userTask.getCandidateUsers()) {
        taskDefinition.addCandidateUserIdExpression(expressionManager.createExpression(candidateUser));
    }
    for (String candidateGroup : userTask.getCandidateGroups()) {
        taskDefinition.addCandidateGroupIdExpression(expressionManager.createExpression(candidateGroup));
    }

    // Activiti custom extension

    // Task listeners
    for (FlowableListener taskListener : userTask.getTaskListeners()) {
        taskDefinition.addTaskListener(taskListener.getEvent(), createTaskListener(bpmnParse, taskListener, userTask.getId()));
    }

    // Due date
    if (StringUtils.isNotEmpty(userTask.getDueDate())) {
        taskDefinition.setDueDateExpression(expressionManager.createExpression(userTask.getDueDate()));
    }

    // Business calendar name
    if (StringUtils.isNotEmpty(userTask.getBusinessCalendarName())) {
        taskDefinition.setBusinessCalendarNameExpression(expressionManager.createExpression(userTask.getBusinessCalendarName()));
    } else {
        taskDefinition.setBusinessCalendarNameExpression(expressionManager.createExpression(DueDateBusinessCalendar.NAME));
    }

    // Category
    if (StringUtils.isNotEmpty(userTask.getCategory())) {
        taskDefinition.setCategoryExpression(expressionManager.createExpression(userTask.getCategory()));
    }

    // Priority
    if (StringUtils.isNotEmpty(userTask.getPriority())) {
        taskDefinition.setPriorityExpression(expressionManager.createExpression(userTask.getPriority()));
    }

    if (StringUtils.isNotEmpty(userTask.getFormKey())) {
        taskDefinition.setFormKeyExpression(expressionManager.createExpression(userTask.getFormKey()));
    }

    // CustomUserIdentityLinks
    for (String customUserIdentityLinkType : userTask.getCustomUserIdentityLinks().keySet()) {
        Set<Expression> userIdentityLinkExpression = new HashSet<>();
        for (String userIdentityLink : userTask.getCustomUserIdentityLinks().get(customUserIdentityLinkType)) {
            userIdentityLinkExpression.add(expressionManager.createExpression(userIdentityLink));
        }
        taskDefinition.addCustomUserIdentityLinkExpression(customUserIdentityLinkType, userIdentityLinkExpression);
    }

    // CustomGroupIdentityLinks
    for (String customGroupIdentityLinkType : userTask.getCustomGroupIdentityLinks().keySet()) {
        Set<Expression> groupIdentityLinkExpression = new HashSet<>();
        for (String groupIdentityLink : userTask.getCustomGroupIdentityLinks().get(customGroupIdentityLinkType)) {
            groupIdentityLinkExpression.add(expressionManager.createExpression(groupIdentityLink));
        }
        taskDefinition.addCustomGroupIdentityLinkExpression(customGroupIdentityLinkType, groupIdentityLinkExpression);
    }

    if (StringUtils.isNotEmpty(userTask.getSkipExpression())) {
        taskDefinition.setSkipExpression(expressionManager.createExpression(userTask.getSkipExpression()));
    }

    return taskDefinition;
}
 
Example #14
Source File: TaskDefinition.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void setTaskFormHandler(TaskFormHandler taskFormHandler) {
    this.taskFormHandler = taskFormHandler;
}
 
Example #15
Source File: TaskDefinition.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public TaskFormHandler getTaskFormHandler() {
    return taskFormHandler;
}
 
Example #16
Source File: TaskDefinition.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public TaskDefinition(TaskFormHandler taskFormHandler) {
    this.taskFormHandler = taskFormHandler;
}
 
Example #17
Source File: FormHandlerUtil.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public static TaskFormHandler getTaskFormHandlder(TaskEntity taskEntity) {
  if (taskEntity.getProcessDefinitionId() != null) {
    return getTaskFormHandlder(taskEntity.getProcessDefinitionId(), taskEntity.getTaskDefinitionKey());
  }
  return null;
}