From 901bc9a43cc3f6f48a9681b1884a714c143759f1 Mon Sep 17 00:00:00 2001 From: wen-hemin <39549317+wen-hemin@users.noreply.github.com> Date: Mon, 19 Jul 2021 09:49:40 +0800 Subject: [PATCH] [Fix-5517]: The workflow lineage interface, projectId change to projectCode (#5834) * fix: The workflow lineage api, projectId change to projectCode * fix checkstyle Co-authored-by: wen-hemin --- .../controller/WorkFlowLineageController.java | 10 +++--- .../api/service/WorkFlowLineageService.java | 4 +-- .../impl/WorkFlowLineageServiceImpl.java | 8 ++--- .../WorkFlowLineageControllerTest.java | 32 ++++--------------- .../service/WorkFlowLineageServiceTest.java | 8 ++--- .../src/js/conf/home/store/kinship/actions.js | 8 ++--- 6 files changed, 25 insertions(+), 45 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java index 507580d60b..f5e17e3cb6 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java @@ -54,7 +54,7 @@ import springfox.documentation.annotations.ApiIgnore; */ @Api(tags = "WORK_FLOW_LINEAGE_TAG") @RestController -@RequestMapping("lineages/{projectId}") +@RequestMapping("lineages/{projectCode}") public class WorkFlowLineageController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(WorkFlowLineageController.class); @@ -66,11 +66,11 @@ public class WorkFlowLineageController extends BaseController { @ResponseStatus(HttpStatus.OK) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result> queryWorkFlowLineageByName(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectId", value = "PROJECT_ID", required = true, example = "1") @PathVariable int projectId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true, example = "1") @PathVariable long projectCode, @ApiIgnore @RequestParam(value = "searchVal", required = false) String searchVal) { try { searchVal = ParameterUtils.handleEscapes(searchVal); - Map result = workFlowLineageService.queryWorkFlowLineageByName(searchVal,projectId); + Map result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectCode); return returnDataList(result); } catch (Exception e) { logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e); @@ -83,7 +83,7 @@ public class WorkFlowLineageController extends BaseController { @ResponseStatus(HttpStatus.OK) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result> queryWorkFlowLineageByIds(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectId", value = "PROJECT_ID", required = true, example = "1") @PathVariable int projectId, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true, example = "1") @PathVariable long projectCode, @ApiIgnore @RequestParam(value = "ids", required = false) String ids) { try { ids = ParameterUtils.handleEscapes(ids); @@ -95,7 +95,7 @@ public class WorkFlowLineageController extends BaseController { } } - Map result = workFlowLineageService.queryWorkFlowLineageByIds(idsSet, projectId); + Map result = workFlowLineageService.queryWorkFlowLineageByIds(idsSet, projectCode); return returnDataList(result); } catch (Exception e) { logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java index 360e813c68..c88d3529f5 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java @@ -25,8 +25,8 @@ import java.util.Set; */ public interface WorkFlowLineageService { - Map queryWorkFlowLineageByName(String workFlowName, int projectId); + Map queryWorkFlowLineageByName(String workFlowName, long projectCode); - Map queryWorkFlowLineageByIds(Set ids,int projectId); + Map queryWorkFlowLineageByIds(Set ids, long projectCode); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkFlowLineageServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkFlowLineageServiceImpl.java index 72aa12eb1b..bcf7bddf8b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkFlowLineageServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkFlowLineageServiceImpl.java @@ -50,8 +50,8 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF private ProjectMapper projectMapper; @Override - public Map queryWorkFlowLineageByName(String workFlowName, int projectId) { - Project project = projectMapper.selectById(projectId); + public Map queryWorkFlowLineageByName(String workFlowName, long projectCode) { + Project project = projectMapper.queryByCode(projectCode); Map result = new HashMap<>(); List workFlowLineageList = workFlowLineageMapper.queryByName(workFlowName, project.getCode()); result.put(Constants.DATA_LIST, workFlowLineageList); @@ -103,9 +103,9 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF } @Override - public Map queryWorkFlowLineageByIds(Set ids, int projectId) { + public Map queryWorkFlowLineageByIds(Set ids, long projectCode) { Map result = new HashMap<>(); - Project project = projectMapper.selectById(projectId); + Project project = projectMapper.queryByCode(projectCode); List processLineages = workFlowLineageMapper.queryRelationByIds(ids, project.getCode()); Map workFlowLineages = new HashMap<>(); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java index 4fa6ef7df7..8c413b2d8c 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java @@ -21,23 +21,17 @@ import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.service.impl.WorkFlowLineageServiceImpl; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.dao.entity.Project; -import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; -import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; -import java.text.MessageFormat; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.springframework.context.ApplicationContext; /** * work flow lineage controller test @@ -50,43 +44,29 @@ public class WorkFlowLineageControllerTest extends AbstractControllerTest { @Mock private WorkFlowLineageServiceImpl workFlowLineageService; - @Before - public void init() { - ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class); - SpringApplicationContext springApplicationContext = new SpringApplicationContext(); - springApplicationContext.setApplicationContext(applicationContext); - - ProjectMapper projectMapper = Mockito.mock(ProjectMapper.class); - Mockito.when(applicationContext.getBean(ProjectMapper.class)).thenReturn(projectMapper); - Project project = new Project(); - project.setId(1); - project.setCode(1L); - Mockito.when(projectMapper.selectById(1)).thenReturn(project); - } - @Test public void testQueryWorkFlowLineageByName() { - int projectId = 1; + long projectCode = 1L; String searchVal = "test"; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, 1); - Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectId)).thenReturn(result); - Result response = workFlowLineageController.queryWorkFlowLineageByName(user, projectId, searchVal); + Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectCode)).thenReturn(result); + Result response = workFlowLineageController.queryWorkFlowLineageByName(user, projectCode, searchVal); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } @Test public void testQueryWorkFlowLineageByIds() { - int projectId = 1; + long projectCode = 1L; String ids = "1"; Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); result.put(Constants.DATA_LIST, 1); Set idSet = new HashSet<>(); idSet.add(1); - Mockito.when(workFlowLineageService.queryWorkFlowLineageByIds(idSet, projectId)).thenReturn(result); - Result response = workFlowLineageController.queryWorkFlowLineageByIds(user, projectId, ids); + Mockito.when(workFlowLineageService.queryWorkFlowLineageByIds(idSet, projectCode)).thenReturn(result); + Result response = workFlowLineageController.queryWorkFlowLineageByIds(user, projectCode, ids); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java index 8b00eefd81..c43a9ad395 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java @@ -77,9 +77,9 @@ public class WorkFlowLineageServiceTest { public void testQueryWorkFlowLineageByName() { Project project = getProject("test"); String searchVal = "test"; - when(projectMapper.selectById(1)).thenReturn(project); + when(projectMapper.queryByCode(1L)).thenReturn(project); when(workFlowLineageMapper.queryByName(Mockito.any(), Mockito.any())).thenReturn(getWorkFlowLineages()); - Map result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, 1); + Map result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, 1L); List workFlowLineageList = (List) result.get(Constants.DATA_LIST); Assert.assertTrue(workFlowLineageList.size() > 0); } @@ -106,7 +106,7 @@ public class WorkFlowLineageServiceTest { WorkFlowLineage workFlowLineage = new WorkFlowLineage(); workFlowLineage.setSourceWorkFlowId(""); - when(projectMapper.selectById(1)).thenReturn(project); + when(projectMapper.queryByCode(1L)).thenReturn(project); when(workFlowLineageMapper.queryRelationByIds(ids, project.getCode())).thenReturn(processLineages); when(workFlowLineageMapper.queryCodeRelation(processLineage.getPostTaskCode() , processLineage.getPreTaskVersion() @@ -117,7 +117,7 @@ public class WorkFlowLineageServiceTest { .queryWorkFlowLineageByCode(processLineage.getProcessDefinitionCode(), processLineage.getProjectCode())) .thenReturn(workFlowLineage); - Map result = workFlowLineageService.queryWorkFlowLineageByIds(ids, 1); + Map result = workFlowLineageService.queryWorkFlowLineageByIds(ids, 1L); Map workFlowLists = (Map) result.get(Constants.DATA_LIST); Collection workFlowLineages = (Collection) workFlowLists.get(Constants.WORKFLOW_LIST); diff --git a/dolphinscheduler-ui/src/js/conf/home/store/kinship/actions.js b/dolphinscheduler-ui/src/js/conf/home/store/kinship/actions.js index dc444462e9..d2d1e17fc4 100644 --- a/dolphinscheduler-ui/src/js/conf/home/store/kinship/actions.js +++ b/dolphinscheduler-ui/src/js/conf/home/store/kinship/actions.js @@ -24,9 +24,9 @@ export default { * Get workFlow DAG */ getWorkFlowList ({ state }, payload) { - const projectId = localStore.getItem('projectId') + const projectCode = localStore.getItem('projectCode') return new Promise((resolve, reject) => { - const url = `lineages/${projectId}/list-name` + const url = `lineages/${projectCode}/list-name` io.get(url, { searchVal: payload }, res => { @@ -50,9 +50,9 @@ export default { * Get workFlow DAG */ getWorkFlowDAG ({ state }, payload) { - const projectId = localStore.getItem('projectId') + const projectCode = localStore.getItem('projectCode') return new Promise((resolve, reject) => { - const url = `lineages/${projectId}/list-ids` + const url = `lineages/${projectCode}/list-ids` io.get(url, { ids: payload }, res => {