Search in sources :

Example 1 with FormParseException

use of org.apache.inlong.manager.common.exceptions.FormParseException in project incubator-inlong by apache.

the class WorkflowFormParserUtils method parseTaskForm.

/**
 * Parse the task form in JSON string format into a WorkflowTask instance
 */
public static <T extends TaskForm> T parseTaskForm(WorkflowTaskEntity workflowTaskEntity, WorkflowProcess process) throws FormParseException {
    Preconditions.checkNotNull(workflowTaskEntity, "workflowTaskEntity cannot be null");
    Preconditions.checkNotNull(process, "process cannot be null");
    if (StringUtils.isEmpty(workflowTaskEntity.getFormData())) {
        return null;
    }
    WorkflowTask task = process.getTaskByName(workflowTaskEntity.getName());
    Preconditions.checkNotNull(task, "user task not exist " + workflowTaskEntity.getName());
    Preconditions.checkTrue(task instanceof UserTask, "task should be userTask " + workflowTaskEntity.getName());
    UserTask userTask = (UserTask) task;
    try {
        JavaType javaType = JsonUtils.MAPPER.constructType(userTask.getFormClass());
        return JsonUtils.parse(workflowTaskEntity.getFormData(), javaType);
    } catch (Exception e) {
        log.error("task form parse failed, form is: {}", workflowTaskEntity.getFormData(), e);
        throw new FormParseException("task form parse failed");
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) FormParseException(org.apache.inlong.manager.common.exceptions.FormParseException) UserTask(org.apache.inlong.manager.workflow.definition.UserTask) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) FormParseException(org.apache.inlong.manager.common.exceptions.FormParseException)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)1 FormParseException (org.apache.inlong.manager.common.exceptions.FormParseException)1 UserTask (org.apache.inlong.manager.workflow.definition.UserTask)1 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)1