Browse Source

[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 <wenhemin@apache.com>
2.0.7-release
wen-hemin 3 years ago committed by GitHub
parent
commit
901bc9a43c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageController.java
  2. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java
  3. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkFlowLineageServiceImpl.java
  4. 32
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkFlowLineageControllerTest.java
  5. 8
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java
  6. 8
      dolphinscheduler-ui/src/js/conf/home/store/kinship/actions.js

10
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") @Api(tags = "WORK_FLOW_LINEAGE_TAG")
@RestController @RestController
@RequestMapping("lineages/{projectId}") @RequestMapping("lineages/{projectCode}")
public class WorkFlowLineageController extends BaseController { public class WorkFlowLineageController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(WorkFlowLineageController.class); private static final Logger logger = LoggerFactory.getLogger(WorkFlowLineageController.class);
@ -66,11 +66,11 @@ public class WorkFlowLineageController extends BaseController {
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result<List<WorkFlowLineage>> queryWorkFlowLineageByName(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result<List<WorkFlowLineage>> 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) { @ApiIgnore @RequestParam(value = "searchVal", required = false) String searchVal) {
try { try {
searchVal = ParameterUtils.handleEscapes(searchVal); searchVal = ParameterUtils.handleEscapes(searchVal);
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(searchVal,projectId); Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectCode);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) { } catch (Exception e) {
logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e); logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e);
@ -83,7 +83,7 @@ public class WorkFlowLineageController extends BaseController {
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result<Map<String, Object>> queryWorkFlowLineageByIds(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result<Map<String, Object>> 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) { @ApiIgnore @RequestParam(value = "ids", required = false) String ids) {
try { try {
ids = ParameterUtils.handleEscapes(ids); ids = ParameterUtils.handleEscapes(ids);
@ -95,7 +95,7 @@ public class WorkFlowLineageController extends BaseController {
} }
} }
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByIds(idsSet, projectId); Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByIds(idsSet, projectCode);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) { } catch (Exception e) {
logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e); logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(),e);

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageService.java

@ -25,8 +25,8 @@ import java.util.Set;
*/ */
public interface WorkFlowLineageService { public interface WorkFlowLineageService {
Map<String, Object> queryWorkFlowLineageByName(String workFlowName, int projectId); Map<String, Object> queryWorkFlowLineageByName(String workFlowName, long projectCode);
Map<String, Object> queryWorkFlowLineageByIds(Set<Integer> ids,int projectId); Map<String, Object> queryWorkFlowLineageByIds(Set<Integer> ids, long projectCode);
} }

8
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; private ProjectMapper projectMapper;
@Override @Override
public Map<String, Object> queryWorkFlowLineageByName(String workFlowName, int projectId) { public Map<String, Object> queryWorkFlowLineageByName(String workFlowName, long projectCode) {
Project project = projectMapper.selectById(projectId); Project project = projectMapper.queryByCode(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
List<WorkFlowLineage> workFlowLineageList = workFlowLineageMapper.queryByName(workFlowName, project.getCode()); List<WorkFlowLineage> workFlowLineageList = workFlowLineageMapper.queryByName(workFlowName, project.getCode());
result.put(Constants.DATA_LIST, workFlowLineageList); result.put(Constants.DATA_LIST, workFlowLineageList);
@ -103,9 +103,9 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF
} }
@Override @Override
public Map<String, Object> queryWorkFlowLineageByIds(Set<Integer> ids, int projectId) { public Map<String, Object> queryWorkFlowLineageByIds(Set<Integer> ids, long projectCode) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Project project = projectMapper.selectById(projectId); Project project = projectMapper.queryByCode(projectCode);
List<ProcessLineage> processLineages = workFlowLineageMapper.queryRelationByIds(ids, project.getCode()); List<ProcessLineage> processLineages = workFlowLineageMapper.queryRelationByIds(ids, project.getCode());
Map<Integer, WorkFlowLineage> workFlowLineages = new HashMap<>(); Map<Integer, WorkFlowLineage> workFlowLineages = new HashMap<>();

32
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.service.impl.WorkFlowLineageServiceImpl;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; 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.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.springframework.context.ApplicationContext;
/** /**
* work flow lineage controller test * work flow lineage controller test
@ -50,43 +44,29 @@ public class WorkFlowLineageControllerTest extends AbstractControllerTest {
@Mock @Mock
private WorkFlowLineageServiceImpl workFlowLineageService; 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 @Test
public void testQueryWorkFlowLineageByName() { public void testQueryWorkFlowLineageByName() {
int projectId = 1; long projectCode = 1L;
String searchVal = "test"; String searchVal = "test";
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, 1); result.put(Constants.DATA_LIST, 1);
Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectId)).thenReturn(result); Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectCode)).thenReturn(result);
Result response = workFlowLineageController.queryWorkFlowLineageByName(user, projectId, searchVal); Result response = workFlowLineageController.queryWorkFlowLineageByName(user, projectCode, searchVal);
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }
@Test @Test
public void testQueryWorkFlowLineageByIds() { public void testQueryWorkFlowLineageByIds() {
int projectId = 1; long projectCode = 1L;
String ids = "1"; String ids = "1";
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, 1); result.put(Constants.DATA_LIST, 1);
Set<Integer> idSet = new HashSet<>(); Set<Integer> idSet = new HashSet<>();
idSet.add(1); idSet.add(1);
Mockito.when(workFlowLineageService.queryWorkFlowLineageByIds(idSet, projectId)).thenReturn(result); Mockito.when(workFlowLineageService.queryWorkFlowLineageByIds(idSet, projectCode)).thenReturn(result);
Result response = workFlowLineageController.queryWorkFlowLineageByIds(user, projectId, ids); Result response = workFlowLineageController.queryWorkFlowLineageByIds(user, projectCode, ids);
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }

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

@ -77,9 +77,9 @@ public class WorkFlowLineageServiceTest {
public void testQueryWorkFlowLineageByName() { public void testQueryWorkFlowLineageByName() {
Project project = getProject("test"); Project project = getProject("test");
String searchVal = "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()); when(workFlowLineageMapper.queryByName(Mockito.any(), Mockito.any())).thenReturn(getWorkFlowLineages());
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, 1); Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, 1L);
List<WorkFlowLineage> workFlowLineageList = (List<WorkFlowLineage>) result.get(Constants.DATA_LIST); List<WorkFlowLineage> workFlowLineageList = (List<WorkFlowLineage>) result.get(Constants.DATA_LIST);
Assert.assertTrue(workFlowLineageList.size() > 0); Assert.assertTrue(workFlowLineageList.size() > 0);
} }
@ -106,7 +106,7 @@ public class WorkFlowLineageServiceTest {
WorkFlowLineage workFlowLineage = new WorkFlowLineage(); WorkFlowLineage workFlowLineage = new WorkFlowLineage();
workFlowLineage.setSourceWorkFlowId(""); workFlowLineage.setSourceWorkFlowId("");
when(projectMapper.selectById(1)).thenReturn(project); when(projectMapper.queryByCode(1L)).thenReturn(project);
when(workFlowLineageMapper.queryRelationByIds(ids, project.getCode())).thenReturn(processLineages); when(workFlowLineageMapper.queryRelationByIds(ids, project.getCode())).thenReturn(processLineages);
when(workFlowLineageMapper.queryCodeRelation(processLineage.getPostTaskCode() when(workFlowLineageMapper.queryCodeRelation(processLineage.getPostTaskCode()
, processLineage.getPreTaskVersion() , processLineage.getPreTaskVersion()
@ -117,7 +117,7 @@ public class WorkFlowLineageServiceTest {
.queryWorkFlowLineageByCode(processLineage.getProcessDefinitionCode(), processLineage.getProjectCode())) .queryWorkFlowLineageByCode(processLineage.getProcessDefinitionCode(), processLineage.getProjectCode()))
.thenReturn(workFlowLineage); .thenReturn(workFlowLineage);
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByIds(ids, 1); Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByIds(ids, 1L);
Map<String, Object> workFlowLists = (Map<String, Object>) result.get(Constants.DATA_LIST); Map<String, Object> workFlowLists = (Map<String, Object>) result.get(Constants.DATA_LIST);
Collection<WorkFlowLineage> workFlowLineages = (Collection<WorkFlowLineage>) workFlowLists.get(Constants.WORKFLOW_LIST); Collection<WorkFlowLineage> workFlowLineages = (Collection<WorkFlowLineage>) workFlowLists.get(Constants.WORKFLOW_LIST);

8
dolphinscheduler-ui/src/js/conf/home/store/kinship/actions.js

@ -24,9 +24,9 @@ export default {
* Get workFlow DAG * Get workFlow DAG
*/ */
getWorkFlowList ({ state }, payload) { getWorkFlowList ({ state }, payload) {
const projectId = localStore.getItem('projectId') const projectCode = localStore.getItem('projectCode')
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const url = `lineages/${projectId}/list-name` const url = `lineages/${projectCode}/list-name`
io.get(url, { io.get(url, {
searchVal: payload searchVal: payload
}, res => { }, res => {
@ -50,9 +50,9 @@ export default {
* Get workFlow DAG * Get workFlow DAG
*/ */
getWorkFlowDAG ({ state }, payload) { getWorkFlowDAG ({ state }, payload) {
const projectId = localStore.getItem('projectId') const projectCode = localStore.getItem('projectCode')
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const url = `lineages/${projectId}/list-ids` const url = `lineages/${projectCode}/list-ids`
io.get(url, { io.get(url, {
ids: payload ids: payload
}, res => { }, res => {

Loading…
Cancel
Save