Browse Source

cherry-pick [Fix-13260][API] Ironed out the issue with lacking the value of user's name when querying the list of workflow definitions. #13261

3.1.3-release
calvin 2 years ago committed by zhuangchong
parent
commit
7fa8454906
  1. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  2. 8
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
  3. 2
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java

@ -156,6 +156,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.JsonNode;
@ -491,12 +492,15 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
.stream()
.collect(Collectors.toMap(Schedule::getProcessDefinitionCode, Function.identity()));
Map<Integer, String> userMap = userMapper.selectList(new QueryWrapper<>()).stream()
.collect(Collectors.toMap(User::getId, User::getUserName));
for (ProcessDefinition pd : processDefinitions) {
// todo: use batch query
ProcessDefinitionLog processDefinitionLog =
processDefinitionLogMapper.queryByDefinitionCodeAndVersion(pd.getCode(), pd.getVersion());
User user = userMapper.selectById(processDefinitionLog.getOperator());
pd.setModifyBy(user.getUserName());
pd.setModifyBy(userMap.get(processDefinitionLog.getOperator()));
pd.setUserName(userMap.get(pd.getUserId()));
Schedule schedule = scheduleMap.get(pd.getCode());
pd.setScheduleReleaseState(schedule == null ? null : schedule.getReleaseState());
}

8
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java

@ -63,6 +63,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.apache.dolphinscheduler.dao.model.PageListingResult;
import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionDao;
import org.apache.dolphinscheduler.service.process.ProcessService;
@ -164,6 +165,9 @@ public class ProcessDefinitionServiceTest {
@Mock
private WorkFlowLineageService workFlowLineageService;
@Mock
private UserMapper userMapper;
protected User user;
protected Exception exception;
protected final static long projectCode = 1L;
@ -221,7 +225,9 @@ public class ProcessDefinitionServiceTest {
@Test
@SuppressWarnings("unchecked")
public void testQueryProcessDefinitionListPaging() {
long projectCode = 1L;
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Mockito.when(userMapper.selectList(Mockito.any())).thenReturn(Lists.newArrayList());
Project project = getProject(projectCode);
User loginUser = new User();

2
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java

@ -121,7 +121,7 @@ public class ProcessDefinition {
private int userId;
/**
* user name
* create user name
*/
@TableField(exist = false)
private String userName;

Loading…
Cancel
Save