JinyLeeChina commented on a change in pull request #5160:
URL: 
https://github.com/apache/incubator-dolphinscheduler/pull/5160#discussion_r603104123



##########
File path: 
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
##########
@@ -2524,10 +2526,84 @@ public ProcessData genProcessData(ProcessDefinition 
processDefinition) {
         return new ArrayList<>(taskNodeMap.values());
     }
 
+    /**
+     * getTaskNodeFromTaskInstance
+     * return null if task definition do not exists
+     *
+     * @param taskInstance
+     * @return
+     */
+    public TaskNode getTaskNodeFromTaskInstance(TaskInstance taskInstance) {
+        TaskNode taskNode = new TaskNode();
+        ProcessInstance processInstance = 
processInstanceMapper.selectById(taskInstance.getProcessInstanceId());
+        TaskDefinition taskDefinition = 
taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(
+                taskInstance.getTaskCode(),
+                taskInstance.getTaskDefinitionVersion());
+        if (taskDefinition == null) {
+            return null;
+        }
+        List<ProcessTaskRelationLog> taskRelationList = 
processTaskRelationLogMapper.queryByProcessCodeAndVersion(
+                taskInstance.getProcessDefinitionCode(), 
processInstance.getProcessDefinitionVersion()
+        );
+        Map<Long, Integer> taskCodeMap = new HashedMap();
+
+        taskRelationList.forEach(relation -> 
taskCodeMap.putIfAbsent(relation.getPostTaskCode(), 
relation.getPostTaskVersion()));
+
+        taskNode.setCode(taskDefinition.getCode());
+        taskNode.setVersion(taskDefinition.getVersion());
+        taskNode.setName(taskDefinition.getName());
+        taskNode.setId("task-" + taskDefinition.getId());
+        taskNode.setCode(taskDefinition.getCode());
+        taskNode.setName(taskDefinition.getName());
+        taskNode.setDesc(taskDefinition.getDescription());
+        taskNode.setType(taskDefinition.getTaskType().getDescp());
+        taskNode.setRunFlag(taskDefinition.getFlag() == Flag.YES ? 
Constants.FLOWNODE_RUN_FLAG_FORBIDDEN : "NORMAL");

Review comment:
       This can use enum of Constants

##########
File path: 
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
##########
@@ -2524,10 +2526,84 @@ public ProcessData genProcessData(ProcessDefinition 
processDefinition) {
         return new ArrayList<>(taskNodeMap.values());
     }
 
+    /**
+     * getTaskNodeFromTaskInstance
+     * return null if task definition do not exists
+     *
+     * @param taskInstance
+     * @return
+     */
+    public TaskNode getTaskNodeFromTaskInstance(TaskInstance taskInstance) {
+        TaskNode taskNode = new TaskNode();
+        ProcessInstance processInstance = 
processInstanceMapper.selectById(taskInstance.getProcessInstanceId());
+        TaskDefinition taskDefinition = 
taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(
+                taskInstance.getTaskCode(),
+                taskInstance.getTaskDefinitionVersion());
+        if (taskDefinition == null) {
+            return null;
+        }
+        List<ProcessTaskRelationLog> taskRelationList = 
processTaskRelationLogMapper.queryByProcessCodeAndVersion(
+                taskInstance.getProcessDefinitionCode(), 
processInstance.getProcessDefinitionVersion()
+        );
+        Map<Long, Integer> taskCodeMap = new HashedMap();
+
+        taskRelationList.forEach(relation -> 
taskCodeMap.putIfAbsent(relation.getPostTaskCode(), 
relation.getPostTaskVersion()));
+
+        taskNode.setCode(taskDefinition.getCode());
+        taskNode.setVersion(taskDefinition.getVersion());
+        taskNode.setName(taskDefinition.getName());
+        taskNode.setId("task-" + taskDefinition.getId());

Review comment:
       Front taskId can't use taskDefinitionId




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to