Skip to content

Commit

Permalink
Remove code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyichao-mango committed Aug 12, 2020
1 parent 224de49 commit 8a44c2c
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@

import static org.apache.dolphinscheduler.api.utils.CheckUtils.checkDesc;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.BaseService;
import org.apache.dolphinscheduler.api.service.ProjectService;
Expand All @@ -39,6 +31,15 @@
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -212,7 +213,7 @@ public Map<String, Object> deleteProject(User loginUser, Integer projectId) {

List<ProcessDefinition> processDefinitionList = processDefinitionMapper.queryAllDefinitionList(projectId);

if (processDefinitionList.size() > 0) {
if (!processDefinitionList.isEmpty()) {
putMsg(result, Status.DELETE_PROJECT_ERROR_DEFINES_NOT_NULL);
return result;
}
Expand All @@ -233,7 +234,7 @@ public Map<String, Object> deleteProject(User loginUser, Integer projectId) {
* @return check result
*/
private Map<String, Object> getCheckResult(User loginUser, Project project) {
String projectName = project == null ? null:project.getName();
String projectName = project == null ? null : project.getName();
Map<String, Object> checkResult = checkProjectAndAuth(loginUser, project, projectName);
Status status = (Status) checkResult.get(Constants.STATUS);
if (status != Status.SUCCESS) {
Expand Down Expand Up @@ -301,15 +302,15 @@ public Map<String, Object> queryUnauthorizedProject(User loginUser, Integer user
List<Project> projectList = projectMapper.queryProjectExceptUserId(userId);
List<Project> resultList = new ArrayList<>();
Set<Project> projectSet = null;
if (projectList != null && projectList.size() > 0) {
if (projectList != null && !projectList.isEmpty()) {
projectSet = new HashSet<>(projectList);

List<Project> authedProjectList = projectMapper.queryAuthedProjectListByUserId(userId);

resultList = getUnauthorizedProjects(projectSet, authedProjectList);
}
result.put(Constants.DATA_LIST, resultList);
putMsg(result,Status.SUCCESS);
putMsg(result, Status.SUCCESS);
return result;
}

Expand All @@ -323,7 +324,7 @@ public Map<String, Object> queryUnauthorizedProject(User loginUser, Integer user
private List<Project> getUnauthorizedProjects(Set<Project> projectSet, List<Project> authedProjectList) {
List<Project> resultList;
Set<Project> authedProjectSet = null;
if (authedProjectList != null && authedProjectList.size() > 0) {
if (authedProjectList != null && !authedProjectList.isEmpty()) {
authedProjectSet = new HashSet<>(authedProjectList);
projectSet.removeAll(authedProjectSet);

Expand All @@ -349,7 +350,7 @@ public Map<String, Object> queryAuthorizedProject(User loginUser, Integer userId

List<Project> projects = projectMapper.queryAuthedProjectListByUserId(userId);
result.put(Constants.DATA_LIST, projects);
putMsg(result,Status.SUCCESS);
putMsg(result, Status.SUCCESS);

return result;
}
Expand Down Expand Up @@ -395,12 +396,13 @@ private int queryPermission(User user, Project project) {

/**
* query all project list that have one or more process definitions.
*
* @return project list
*/
public Map<String, Object> queryAllProjectList() {
Map<String, Object> result = new HashMap<>();
List<Project> projects = projectMapper.selectList(null);
List<ProcessDefinition> processDefinitions = processDefinitionMapper.selectList(null);
List<ProcessDefinition> processDefinitions = processDefinitionMapper.selectList(null);
if (projects != null) {
Set<Integer> set = new HashSet<>();
for (ProcessDefinition processDefinition : processDefinitions) {
Expand All @@ -415,7 +417,7 @@ public Map<String, Object> queryAllProjectList() {
projects.removeAll(tempDeletelist);
}
result.put(Constants.DATA_LIST, projects);
putMsg(result,Status.SUCCESS);
putMsg(result, Status.SUCCESS);
return result;
}

Expand Down

0 comments on commit 8a44c2c

Please sign in to comment.