From 29414a080f29edbd060721d1f617b4e32f743847 Mon Sep 17 00:00:00 2001 From: Jiajie Zhong Date: Tue, 7 Dec 2021 18:50:06 +0800 Subject: [PATCH] Fix homepage user wrong statistics result for new user (#7242) * Fix homepage user wrong statistics result for new user For now, when we create a new user, it would see homepage statistic info as admin user like, cause `projectCodeArray` would not filter when we render SQL. So I add prefix conditions to handle this situation. Also, I do some minimal refactor here. including change function name no quit fit fix: #7182 * Fix UT --- .../api/service/DataAnalysisService.java | 4 +- .../service/impl/DataAnalysisServiceImpl.java | 56 +++++++++------ .../api/service/DataAnalysisServiceTest.java | 12 ++-- .../dao/mapper/ProcessDefinitionMapper.java | 25 +++---- .../dao/mapper/ProcessInstanceMapper.java | 70 ++++++++++--------- .../dao/mapper/TaskInstanceMapper.java | 18 +++-- .../dao/mapper/ProcessDefinitionMapper.xml | 2 +- .../dao/mapper/ProcessInstanceMapper.xml | 2 +- .../dao/mapper/TaskInstanceMapper.xml | 2 +- .../mapper/ProcessDefinitionMapperTest.java | 6 +- .../dao/mapper/ProcessInstanceMapperTest.java | 2 +- .../dao/mapper/TaskInstanceMapperTest.java | 7 +- 12 files changed, 112 insertions(+), 94 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java index 9a5dbe50ca..80810ed40e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java @@ -49,7 +49,9 @@ public interface DataAnalysisService { Map countProcessInstanceStateByProject(User loginUser, long projectCode, String startDate, String endDate); /** - * statistics the process definition quantities of certain person + * statistics the process definition quantities of a certain person + * + * We only need projects which users have permission to see to determine whether the definition belongs to the user or not. * * @param loginUser login user * @param projectCode project code diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java index 1800dd2e37..c0dada657a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java @@ -44,6 +44,7 @@ import org.apache.dolphinscheduler.service.process.ProcessService; import org.apache.commons.lang.StringUtils; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; @@ -90,30 +91,30 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal /** * statistical task instance status data * - * @param loginUser login user + * @param loginUser login user * @param projectCode project code - * @param startDate start date - * @param endDate end date + * @param startDate start date + * @param endDate end date * @return task state count data */ @Override public Map countTaskStateByProject(User loginUser, long projectCode, String startDate, String endDate) { return countStateByProject( - loginUser, - projectCode, - startDate, - endDate, - (start, end, projectCodes) -> this.taskInstanceMapper.countTaskInstanceStateByUser(start, end, projectCodes)); + loginUser, + projectCode, + startDate, + endDate, + (start, end, projectCodes) -> this.taskInstanceMapper.countTaskInstanceStateByProjectCodes(start, end, projectCodes)); } /** * statistical process instance status data * - * @param loginUser login user + * @param loginUser login user * @param projectCode project code - * @param startDate start date - * @param endDate end date + * @param startDate start date + * @param endDate end date * @return process instance state count data */ @Override @@ -123,7 +124,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal projectCode, startDate, endDate, - (start, end, projectCodes) -> this.processInstanceMapper.countInstanceStateByUser(start, end, projectCodes)); + (start, end, projectCodes) -> this.processInstanceMapper.countInstanceStateByProjectCodes(start, end, projectCodes)); // process state count needs to remove state of forced success if (result.containsKey(Constants.STATUS) && result.get(Constants.STATUS).equals(Status.SUCCESS)) { ((TaskCountDto)result.get(Constants.DATA_LIST)).removeStateFromCountList(ExecutionStatus.FORCED_SUCCESS); @@ -131,6 +132,14 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal return result; } + /** + * Wrapper function of counting process instance state and task state + * + * @param loginUser login user + * @param projectCode project code + * @param startDate start date + * @param endDate end date + */ private Map countStateByProject(User loginUser, long projectCode, String startDate, String endDate , TriFunction> instanceStateCounter) { Map result = new HashMap<>(); @@ -154,10 +163,13 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal } } + List processInstanceStateCounts = new ArrayList<>(); Long[] projectCodeArray = projectCode == 0 ? getProjectCodesArrays(loginUser) - : new Long[] { projectCode }; - List processInstanceStateCounts = - instanceStateCounter.apply(start, end, projectCodeArray); + : new Long[] {projectCode}; + + if (projectCodeArray.length != 0 || loginUser.getUserType() == UserType.ADMIN_USER) { + processInstanceStateCounts = instanceStateCounter.apply(start, end, projectCodeArray); + } if (processInstanceStateCounts != null) { TaskCountDto taskCountResult = new TaskCountDto(processInstanceStateCounts); @@ -169,9 +181,11 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal /** - * statistics the process definition quantities of certain person + * statistics the process definition quantities of a certain person + *

+ * We only need projects which users have permission to see to determine whether the definition belongs to the user or not. * - * @param loginUser login user + * @param loginUser login user * @param projectCode project code * @return definition count data */ @@ -187,10 +201,12 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal } } + List defineGroupByUsers = new ArrayList<>(); Long[] projectCodeArray = projectCode == 0 ? getProjectCodesArrays(loginUser) - : new Long[] { projectCode }; - List defineGroupByUsers = processDefinitionMapper.countDefinitionGroupByUser( - loginUser.getId(), projectCodeArray, isAdmin(loginUser)); + : new Long[] {projectCode}; + if (projectCodeArray.length != 0 || loginUser.getUserType() == UserType.ADMIN_USER) { + defineGroupByUsers = processDefinitionMapper.countDefinitionByProjectCodes(projectCodeArray); + } DefineUserDto dto = new DefineUserDto(defineGroupByUsers); result.put(Constants.DATA_LIST, dto); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java index 163b310388..f93b30a580 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java @@ -130,7 +130,7 @@ public class DataAnalysisServiceTest { Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); //SUCCESS - Mockito.when(taskInstanceMapper.countTaskInstanceStateByUser(DateUtils.getScheduleDate(startDate), + Mockito.when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(DateUtils.getScheduleDate(startDate), DateUtils.getScheduleDate(endDate), new Long[]{1L})).thenReturn(getTaskInstanceStateCounts()); Mockito.when(projectMapper.selectById(Mockito.any())).thenReturn(getProject("test")); Mockito.when(projectService.hasProjectAndPerm(Mockito.any(), Mockito.any(), (Map)Mockito.any())).thenReturn(true); @@ -187,7 +187,7 @@ public class DataAnalysisServiceTest { // when general user doesn't have any task then return all count are 0 user.setUserType(UserType.GENERAL_USER); - Mockito.when(taskInstanceMapper.countTaskInstanceStateByUser(any(), any(), any())).thenReturn( + Mockito.when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())).thenReturn( Collections.emptyList()); result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); assertThat(result.get(Constants.DATA_LIST)).extracting("totalCount").isEqualTo(0); @@ -206,7 +206,7 @@ public class DataAnalysisServiceTest { // when instanceStateCounter return null, then return nothing user.setUserType(UserType.GENERAL_USER); - PowerMockito.when(taskInstanceMapper.countTaskInstanceStateByUser(any(), any(), any())).thenReturn(null); + PowerMockito.when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())).thenReturn(null); result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); Assert.assertNull(result.get(Constants.DATA_LIST)); } @@ -230,7 +230,7 @@ public class DataAnalysisServiceTest { Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); //SUCCESS - Mockito.when(processInstanceMapper.countInstanceStateByUser(DateUtils.getScheduleDate(startDate), + Mockito.when(processInstanceMapper.countInstanceStateByProjectCodes(DateUtils.getScheduleDate(startDate), DateUtils.getScheduleDate(endDate), new Long[]{1L})).thenReturn(getTaskInstanceStateCounts()); Mockito.when(projectService.hasProjectAndPerm(Mockito.any(), Mockito.any(), (Map)Mockito.any())).thenReturn(true); @@ -246,8 +246,8 @@ public class DataAnalysisServiceTest { putMsg(result, Status.SUCCESS, null); Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong())).thenReturn(result); - Mockito.when(processDefinitionMapper.countDefinitionGroupByUser(Mockito.anyInt(), Mockito.any(Long[].class), - Mockito.anyBoolean())).thenReturn(new ArrayList()); + Mockito.when(processDefinitionMapper.countDefinitionByProjectCodes( + Mockito.any(Long[].class))).thenReturn(new ArrayList()); result = dataAnalysisServiceImpl.countDefinitionByUser(user, 0); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java index 954b55ba12..280e04938b 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java @@ -77,7 +77,7 @@ public interface ProcessDefinitionMapper extends BaseMapper { * verify process definition by name * * @param projectCode projectCode - * @param name name + * @param name name * @return process definition */ ProcessDefinition verifyByDefineName(@Param("projectCode") long projectCode, @@ -87,7 +87,7 @@ public interface ProcessDefinitionMapper extends BaseMapper { * query process definition by name * * @param projectCode projectCode - * @param name name + * @param name name * @return process definition */ ProcessDefinition queryByDefineName(@Param("projectCode") long projectCode, @@ -104,11 +104,11 @@ public interface ProcessDefinitionMapper extends BaseMapper { /** * process definition page * - * @param page page - * @param searchVal searchVal - * @param userId userId + * @param page page + * @param searchVal searchVal + * @param userId userId * @param projectCode projectCode - * @param isAdmin isAdmin + * @param isAdmin isAdmin * @return process definition IPage */ IPage queryDefineListPaging(IPage page, @@ -142,17 +142,14 @@ public interface ProcessDefinitionMapper extends BaseMapper { List queryDefinitionListByTenant(@Param("tenantId") int tenantId); /** - * count process definition group by user + * Statistics process definition group by project codes list + *

+ * We only need project codes to determine whether the definition belongs to the user or not. * - * @param userId userId * @param projectCodes projectCodes - * @param isAdmin isAdmin - * @return process definition list + * @return definition group by user */ - List countDefinitionGroupByUser( - @Param("userId") Integer userId, - @Param("projectCodes") Long[] projectCodes, - @Param("isAdmin") boolean isAdmin); + List countDefinitionByProjectCodes(@Param("projectCodes") Long[] projectCodes); /** * list all resource ids diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java index ef22bd6021..6dbbdea8a8 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.java @@ -46,7 +46,7 @@ public interface ProcessInstanceMapper extends BaseMapper { /** * query process instance by host and stateArray * - * @param host host + * @param host host * @param stateArray stateArray * @return process instance list */ @@ -57,7 +57,7 @@ public interface ProcessInstanceMapper extends BaseMapper { * query process instance by tenantId and stateArray * * @param tenantId tenantId - * @param states states array + * @param states states array * @return process instance list */ List queryByTenantIdAndStatus(@Param("tenantId") int tenantId, @@ -65,7 +65,7 @@ public interface ProcessInstanceMapper extends BaseMapper { /** * @param workerGroupName workerGroupName - * @param states states array + * @param states states array * @return process instance list */ List queryByWorkerGroupNameAndStatus(@Param("workerGroupName") String workerGroupName, @@ -88,15 +88,15 @@ public interface ProcessInstanceMapper extends BaseMapper { /** * process instance page * - * @param page page - * @param projectCode projectCode + * @param page page + * @param projectCode projectCode * @param processDefinitionCode processDefinitionCode - * @param searchVal searchVal - * @param executorId executorId - * @param statusArray statusArray - * @param host host - * @param startTime startTime - * @param endTime endTime + * @param searchVal searchVal + * @param executorId executorId + * @param statusArray statusArray + * @param host host + * @param startTime startTime + * @param endTime endTime * @return process instance page */ IPage queryProcessInstanceListPaging(Page page, @@ -112,7 +112,7 @@ public interface ProcessInstanceMapper extends BaseMapper { /** * set failover by host and state array * - * @param host host + * @param host host * @param stateArray stateArray * @return set result */ @@ -123,7 +123,7 @@ public interface ProcessInstanceMapper extends BaseMapper { * update process instance by state * * @param originState originState - * @param destState destState + * @param destState destState * @return update result */ int updateProcessInstanceByState(@Param("originState") ExecutionStatus originState, @@ -133,7 +133,7 @@ public interface ProcessInstanceMapper extends BaseMapper { * update process instance by tenantId * * @param originTenantId originTenantId - * @param destTenantId destTenantId + * @param destTenantId destTenantId * @return update result */ int updateProcessInstanceByTenantId(@Param("originTenantId") int originTenantId, @@ -143,30 +143,32 @@ public interface ProcessInstanceMapper extends BaseMapper { * update process instance by worker groupId * * @param originWorkerGroupName originWorkerGroupName - * @param destWorkerGroupName destWorkerGroupName + * @param destWorkerGroupName destWorkerGroupName * @return update result */ int updateProcessInstanceByWorkerGroupName(@Param("originWorkerGroupName") String originWorkerGroupName, @Param("destWorkerGroupName") String destWorkerGroupName); /** - * count process instance state by user + * Statistics process instance state by given project codes list + *

+ * We only need project codes to determine whether the process instance belongs to the user or not. * - * @param startTime startTime - * @param endTime endTime + * @param startTime startTime + * @param endTime endTime * @param projectCodes projectCodes * @return ExecuteStatusCount list */ - List countInstanceStateByUser( - @Param("startTime") Date startTime, - @Param("endTime") Date endTime, - @Param("projectCodes") Long[] projectCodes); + List countInstanceStateByProjectCodes( + @Param("startTime") Date startTime, + @Param("endTime") Date endTime, + @Param("projectCodes") Long[] projectCodes); /** * query process instance by processDefinitionCode * * @param processDefinitionCode processDefinitionCode - * @param size size + * @param size size * @return process instance list */ List queryByProcessDefineCode(@Param("processDefinitionCode") Long processDefinitionCode, @@ -176,8 +178,8 @@ public interface ProcessInstanceMapper extends BaseMapper { * query last scheduler process instance * * @param definitionCode definitionCode - * @param startTime startTime - * @param endTime endTime + * @param startTime startTime + * @param endTime endTime * @return process instance */ ProcessInstance queryLastSchedulerProcess(@Param("processDefinitionCode") Long definitionCode, @@ -188,9 +190,9 @@ public interface ProcessInstanceMapper extends BaseMapper { * query last running process instance * * @param definitionCode definitionCode - * @param startTime startTime - * @param endTime endTime - * @param stateArray stateArray + * @param startTime startTime + * @param endTime endTime + * @param stateArray stateArray * @return process instance */ ProcessInstance queryLastRunningProcess(@Param("processDefinitionCode") Long definitionCode, @@ -202,8 +204,8 @@ public interface ProcessInstanceMapper extends BaseMapper { * query last manual process instance * * @param definitionCode definitionCode - * @param startTime startTime - * @param endTime endTime + * @param startTime startTime + * @param endTime endTime * @return process instance */ ProcessInstance queryLastManualProcess(@Param("processDefinitionCode") Long definitionCode, @@ -231,7 +233,7 @@ public interface ProcessInstanceMapper extends BaseMapper { * query process instance by processDefinitionCode and stateArray * * @param processDefinitionCode processDefinitionCode - * @param states states array + * @param states states array * @return process instance list */ @@ -239,12 +241,12 @@ public interface ProcessInstanceMapper extends BaseMapper { @Param("states") int[] states); List queryByProcessDefineCodeAndStatusAndNextId(@Param("processDefinitionCode") Long processDefinitionCode, - @Param("states") int[] states, @Param("id") int id); + @Param("states") int[] states, @Param("id") int id); int updateGlobalParamsById(@Param("globalParams") String globalParams, @Param("id") int id); - boolean updateNextProcessIdById(@Param("thisInstanceId") int thisInstanceId, @Param("runningInstanceId")int runningInstanceId); + boolean updateNextProcessIdById(@Param("thisInstanceId") int thisInstanceId, @Param("runningInstanceId") int runningInstanceId); - ProcessInstance loadNextProcess4Serial(@Param("processDefinitionCode") Long processDefinitionCode,@Param("state") int state); + ProcessInstance loadNextProcess4Serial(@Param("processDefinitionCode") Long processDefinitionCode, @Param("state") int state); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java index 26bddd311a..17c4672a28 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java @@ -52,14 +52,24 @@ public interface TaskInstanceMapper extends BaseMapper { @Param("name") String name); TaskInstance queryByInstanceIdAndCode(@Param("processInstanceId") int processInstanceId, - @Param("taskCode") Long taskCode); + @Param("taskCode") Long taskCode); Integer countTask(@Param("projectCodes") Long[] projectCodes, @Param("taskIds") int[] taskIds); - List countTaskInstanceStateByUser(@Param("startTime") Date startTime, - @Param("endTime") Date endTime, - @Param("projectCodes") Long[] projectCodes); + /** + * Statistics task instance group by given project codes list + *

+ * We only need project codes to determine whether the task instance belongs to the user or not. + * + * @param startTime Statistics start time + * @param endTime Statistics end time + * @param projectCodes Project codes list to filter + * @return List of ExecuteStatusCount + */ + List countTaskInstanceStateByProjectCodes(@Param("startTime") Date startTime, + @Param("endTime") Date endTime, + @Param("projectCodes") Long[] projectCodes); IPage queryTaskInstanceListPaging(IPage page, @Param("projectCode") Long projectCode, diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml index 39314bbc38..c92bb2105a 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml @@ -109,7 +109,7 @@ #{i} - SELECT td.user_id as user_id, tu.user_name as user_name, count(0) as count FROM t_ds_process_definition td JOIN t_ds_user tu on tu.id=td.user_id diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml index e46a20e5c0..5d718d3bf8 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml @@ -147,7 +147,7 @@ where worker_group = #{originWorkerGroupName} - select t.state, count(0) as count from t_ds_process_instance t join t_ds_process_definition d on d.code=t.process_definition_code diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml index f05696dd1f..d7af300143 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml @@ -69,7 +69,7 @@ - select state, count(0) as count from t_ds_task_instance t left join t_ds_task_definition_log d on d.code=t.task_code and d.version=t.task_definition_version diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java index 2eebc3b364..61a13707c1 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java @@ -318,11 +318,7 @@ public class ProcessDefinitionMapperTest extends BaseDaoTest { Long[] projectCodes = new Long[1]; projectCodes[0] = processDefinition.getProjectCode(); - List processDefinitions = processDefinitionMapper.countDefinitionGroupByUser( - processDefinition.getUserId(), - projectCodes, - user.getUserType() == UserType.ADMIN_USER - ); + List processDefinitions = processDefinitionMapper.countDefinitionByProjectCodes(projectCodes); Assert.assertNotEquals(processDefinitions.size(), 0); } diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java index 1e3b6ca444..8159c65f86 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java @@ -266,7 +266,7 @@ public class ProcessInstanceMapperTest extends BaseDaoTest { Long[] projectCodes = new Long[]{processDefinition.getProjectCode()}; - List executeStatusCounts = processInstanceMapper.countInstanceStateByUser(null, null, projectCodes); + List executeStatusCounts = processInstanceMapper.countInstanceStateByProjectCodes(null, null, projectCodes); Assert.assertNotEquals(executeStatusCounts.size(), 0); diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java index aab4bf2b3a..6a799e429d 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java @@ -32,12 +32,7 @@ import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -342,7 +337,7 @@ public class TaskInstanceMapperTest extends BaseDaoTest { taskInstanceMapper.updateById(task); - List count = taskInstanceMapper.countTaskInstanceStateByUser( + List count = taskInstanceMapper.countTaskInstanceStateByProjectCodes( null, null, new Long[]{definition.getProjectCode()} );