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");
}
}
Aggregations