Browse Source

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

* fix the issue with lacking user name
3.2.0-release
calvin 2 years ago committed by GitHub
parent
commit
a98cae7065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  2. 5
      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

@ -162,6 +162,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;
@ -593,12 +594,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());
}

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

@ -67,6 +67,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.dao.repository.TaskDefinitionLogDao;
@ -171,6 +172,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Mock
private WorkFlowLineageService workFlowLineageService;
@Mock
private UserMapper userMapper;
protected User user;
protected Exception exception;
protected final static long projectCode = 1L;
@ -224,6 +228,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test
public void testQueryProcessDefinitionListPaging() {
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Mockito.when(userMapper.selectList(Mockito.any())).thenReturn(Lists.newArrayList());
Project project = getProject(projectCode);

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