Explorar el Código

refactor: 修改基本类型为包装类型,以支持与新版GitlabApi交互

fanyanpeng hace 2 años
padre
commit
8014b4f78c

+ 3 - 3
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/entity/GitlabUser.java

@@ -15,9 +15,9 @@ import javax.persistence.Table;
 @NoArgsConstructor
 public class GitlabUser {
     @Id
-    private int gitlabUserId;
+    private Integer gitlabUserId;
 
-    private int userId;
-    private int namespaceId;
+    private Integer userId;
+    private Integer namespaceId;
     private String token;
 }

+ 1 - 1
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/api/GroupService.java

@@ -1,7 +1,7 @@
 package com.nju.edu.gitlab.service.api;
 
-import com.nju.edu.gitlab.vo.GitlabGroup;
 import com.nju.edu.gitlab.dto.member.GroupMemberDTO;
+import com.nju.edu.gitlab.vo.GitlabGroup;
 import org.gitlab4j.api.GitLabApiException;
 
 public interface GroupService {

+ 17 - 15
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/api/ProjectService.java

@@ -35,39 +35,41 @@ public interface ProjectService {
 
     public Integer forkGroupProject(GroupForkDTO groupForkDTO) throws GitLabApiException;
 
-    public Set<DiffVO> compare(int projectId, String fromBash, String toBash) throws GitLabApiException;
+
+    Set<DiffVO> compare(Integer projectId, String fromBash, String toBash) throws GitLabApiException;
 
     public boolean addWebHook(WebHookDTO webHookDTO) throws GitLabApiException;
 
-    public boolean archiveProject(int projectId) throws GitLabApiException;
 
-    public String getProjectFile(int projectId, ProjectFileDTO projectFileDTO) throws UnsupportedEncodingException, GitLabApiException;
+    boolean archiveProject(Integer projectId) throws GitLabApiException;
+
+    String getProjectFile(Integer projectId, ProjectFileDTO projectFileDTO) throws UnsupportedEncodingException, GitLabApiException;
 
-    public String getProjectRawFile(int projectId, ProjectRawFileDTO projectRawFileDTO) throws GitLabApiException, IOException;
+    String getProjectRawFile(Integer projectId, ProjectRawFileDTO projectRawFileDTO) throws GitLabApiException, IOException;
 
-    public CommitVO createCommit(int projectId, CommitDTO commitDTO) throws GitLabApiException;
+    CommitVO createCommit(Integer projectId, CommitDTO commitDTO) throws GitLabApiException;
 
-    public List<CommitVO> getAllCommitMessage(int projectId,String commitHash) throws GitLabApiException;
+    List<CommitVO> getAllCommitMessage(Integer projectId, String commitHash) throws GitLabApiException;
 
-    public CommitVO getCommitByHash(int projectId, String commitHash) throws GitLabApiException;
+    CommitVO getCommitByHash(Integer projectId, String commitHash) throws GitLabApiException;
 
-    public List<CommitVO> getCommitsByBranch(int projectId, String branchName) throws GitLabApiException;
+    List<CommitVO> getCommitsByBranch(Integer projectId, String branchName) throws GitLabApiException;
 
-    public List<BranchVO> getProjectBranches(int projectId) throws GitLabApiException;
+    List<BranchVO> getProjectBranches(Integer projectId) throws GitLabApiException;
 
     public boolean addAuthorization(UpdateMemberDTO updateMemberDTO) throws GitLabApiException;
 
-    public List<ProjectVO> getAllProjectByUserId(int userId) throws GitLabApiException;
+    List<ProjectVO> getAllProjectByUserId(Integer userId) throws GitLabApiException;
 
-    public List<Integer> getProjectJoinedUserId(int projectId) throws GitLabApiException;
+    List<Integer> getProjectJoinedUserId(Integer projectId) throws GitLabApiException;
 
-    public List<String> getFilePaths(int projectId, String basePath, String branch) throws GitLabApiException;
+    List<String> getFilePaths(Integer projectId, String basePath, String branch) throws GitLabApiException;
 
-    public List<TreeItem> getRepositoryTree(int projectId, String filePath, String branch) throws GitLabApiException;
+    List<TreeItem> getRepositoryTree(Integer projectId, String filePath, String branch) throws GitLabApiException;
 
-    public MergeRequest mergeBranch(int projectId, String sourceBranch, String targetBranch, String title, String description, int reviewerId) throws GitLabApiException;
+    MergeRequest mergeBranch(Integer projectId, String sourceBranch, String targetBranch, String title, String description, Integer reviewerId) throws GitLabApiException;
 
-    VisibilityVO getProjectVisibility(int projectId) throws GitLabApiException;
+    VisibilityVO getProjectVisibility(Integer projectId) throws GitLabApiException;
 
     VisibilityVO setProjectVisibility(VisibilityVO visibilityVO) throws GitLabApiException;
 }

+ 6 - 4
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/api/UserService.java

@@ -1,9 +1,9 @@
 package com.nju.edu.gitlab.service.api;
 
-import com.nju.edu.gitlab.dto.ChangeUserNameDTO;
-import com.nju.edu.gitlab.vo.GitlabUserVO;
 import com.nju.edu.gitlab.dto.ChangePasswordDTO;
+import com.nju.edu.gitlab.dto.ChangeUserNameDTO;
 import com.nju.edu.gitlab.dto.GitlabUserDTO;
+import com.nju.edu.gitlab.vo.GitlabUserVO;
 import org.gitlab4j.api.GitLabApiException;
 import org.gitlab4j.api.models.User;
 
@@ -15,11 +15,13 @@ public interface UserService {
 
     public boolean changeUserName(ChangeUserNameDTO changeUserNameDTO) throws GitLabApiException;
 
-    public boolean deleteUser(int userId) throws GitLabApiException;
+
+    boolean deleteUser(Integer userId) throws GitLabApiException;
 
     public User findByUsername(String username) throws GitLabApiException;
 
     public GitlabUserVO findByUsernameNew(String username) throws GitLabApiException;
 
-    public String getUserEmail(int userId) throws GitLabApiException;
+
+    String getUserEmail(Integer userId) throws GitLabApiException;
 }

+ 2 - 2
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/impl/GroupServiceImpl.java

@@ -50,7 +50,7 @@ public class GroupServiceImpl implements GroupService {
     }
 
 
-    private int fetchGroupNameSpace(String groupName) throws GitLabApiException {
+    private Integer fetchGroupNameSpace(String groupName) throws GitLabApiException {
         Namespace namespace;
         namespace = gitlabApi.getNamespaceApi().findNamespaces(groupName)
                 .stream()
@@ -60,7 +60,7 @@ public class GroupServiceImpl implements GroupService {
         return Math.toIntExact(namespace != null ? namespace.getId() : null);
     }
 
-    private GitlabUser getGitlabUser(int userId) throws GitLabApiException {
+    private GitlabUser getGitlabUser(Integer userId) throws GitLabApiException {
         if(gitlabUserRepository.existsById(userId))
             return gitlabUserRepository.getOne(userId);
         else

+ 16 - 16
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/impl/ProjectServiceImpl.java

@@ -132,7 +132,7 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public Set<DiffVO> compare(int projectId, String fromBash, String toBash) throws GitLabApiException {
+    public Set<DiffVO> compare(Integer projectId, String fromBash, String toBash) throws GitLabApiException {
         CompareResults compareResults = gitlabApi.getRepositoryApi().compare(projectId, fromBash, toBash);
         List<Diff> diffs=compareResults.getDiffs();
         Set<DiffVO> res=diffs.stream().map(diff -> DiffVO.builder()
@@ -160,13 +160,13 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public boolean archiveProject(int projectId) throws GitLabApiException {
+    public boolean archiveProject(Integer projectId) throws GitLabApiException {
         gitlabApi.getProjectApi().archiveProject(projectId);
         return true;
     }
 
     @Override
-    public String getProjectFile(int projectId,ProjectFileDTO projectFileDTO) throws UnsupportedEncodingException, GitLabApiException {
+    public String getProjectFile(Integer projectId, ProjectFileDTO projectFileDTO) throws UnsupportedEncodingException, GitLabApiException {
         String branch=projectFileDTO.getBranch();
         String path=projectFileDTO.getPath();
         RepositoryFile repositoryFile = gitlabApi.getRepositoryFileApi().getFile(path, (long) projectId,branch);
@@ -177,7 +177,7 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public String getProjectRawFile(int projectId, ProjectRawFileDTO projectRawFileDTO) throws GitLabApiException, IOException {
+    public String getProjectRawFile(Integer projectId, ProjectRawFileDTO projectRawFileDTO) throws GitLabApiException, IOException {
         String commitOrBranchName = projectRawFileDTO.getCommitOrBranchName();
         String path=projectRawFileDTO.getPath();
         InputStream inputStream=gitlabApi.getRepositoryFileApi().getRawFile(projectId,commitOrBranchName,path);
@@ -197,7 +197,7 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public CommitVO createCommit(int projectId, CommitDTO commitDTO) throws GitLabApiException {
+    public CommitVO createCommit(Integer projectId, CommitDTO commitDTO) throws GitLabApiException {
         String branch=commitDTO.getBranch();
         String commitMsg=commitDTO.getCommitMessage();
         String username=commitDTO.getUsername();
@@ -210,7 +210,7 @@ public class ProjectServiceImpl implements ProjectService {
 
 
     @Override
-    public List<CommitVO> getAllCommitMessage(int projectId, String commitHash) throws GitLabApiException {
+    public List<CommitVO> getAllCommitMessage(Integer projectId, String commitHash) throws GitLabApiException {
         Commit commit=gitlabApi.getCommitsApi().getCommit(projectId,commitHash);
         List<Branch> branches=gitlabApi.getRepositoryApi().getBranches(projectId);
         for (Branch branch:branches){
@@ -225,13 +225,13 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public CommitVO getCommitByHash(int projectId, String commitHash) throws GitLabApiException {
+    public CommitVO getCommitByHash(Integer projectId, String commitHash) throws GitLabApiException {
         Commit commit=gitlabApi.getCommitsApi().getCommit(projectId,commitHash);
         return castCommitToVO(commit);
     }
 
     @Override
-    public List<CommitVO> getCommitsByBranch(int projectId, String branchName) throws GitLabApiException {
+    public List<CommitVO> getCommitsByBranch(Integer projectId, String branchName) throws GitLabApiException {
         try {
             String branchNameDecode = URLDecoder.decode(branchName, "UTF-8");
             List<Commit> commits=gitlabApi.getCommitsApi().getCommits(projectId, branchName,null,null);
@@ -292,7 +292,7 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public List<BranchVO> getProjectBranches(int projectId) throws GitLabApiException {
+    public List<BranchVO> getProjectBranches(Integer projectId) throws GitLabApiException {
         return gitlabApi.getRepositoryApi().getBranches(projectId).stream()
                 .map(branch -> castBranchToVO(branch))
                 .collect(Collectors.toList());
@@ -309,7 +309,7 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public List<ProjectVO> getAllProjectByUserId(int userId) throws GitLabApiException {
+    public List<ProjectVO> getAllProjectByUserId(Integer userId) throws GitLabApiException {
         GitlabUser gitlabUser = getGitlabUser(userId);
         gitlabApi.setSudoAsId((long) gitlabUser.getGitlabUserId());
         List<ProjectVO> projectVOS = gitlabApi.getProjectApi().getMemberProjects().stream().map(project->ProjectVO.builder().projectId(Math.toIntExact(project.getId())).webUrl(project.getWebUrl()).projectName(project.getName()).build()).collect(Collectors.toList());
@@ -318,7 +318,7 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public List<Integer> getProjectJoinedUserId(int projectId) throws GitLabApiException {
+    public List<Integer> getProjectJoinedUserId(Integer projectId) throws GitLabApiException {
         List<Integer> gitlabUserIds = gitlabApi.getProjectApi().getMembers(projectId).stream().map(Member::getId).map(l -> Math.toIntExact(l)).collect(Collectors.toList());
         return gitlabUserRepository.findAllByGitlabUserIdIn(gitlabUserIds).stream()
                 .map(GitlabUser::getUserId)
@@ -326,7 +326,7 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public List<String> getFilePaths(int projectId, String basePath, String branch) throws GitLabApiException {
+    public List<String> getFilePaths(Integer projectId, String basePath, String branch) throws GitLabApiException {
         RepositoryApi repositoryApi = gitlabApi.getRepositoryApi();
         List<TreeItem> treeItems = new ArrayList<>();
         Pager<TreeItem> tree = repositoryApi.getTree(projectId, basePath, branch, true, 100);
@@ -343,21 +343,21 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public List<TreeItem> getRepositoryTree(int projectId, String filePath, String branch) throws GitLabApiException {
+    public List<TreeItem> getRepositoryTree(Integer projectId, String filePath, String branch) throws GitLabApiException {
         RepositoryApi repositoryApi = gitlabApi.getRepositoryApi();
         List<TreeItem> treeItems = repositoryApi.getTree(projectId, filePath, branch);
         return treeItems;
     }
 
     @Override
-    public MergeRequest mergeBranch(int projectId, String sourceBranch, String targetBranch, String title, String description, int reviewerId) throws GitLabApiException {
+    public MergeRequest mergeBranch(Integer projectId, String sourceBranch, String targetBranch, String title, String description, Integer reviewerId) throws GitLabApiException {
         MergeRequestApi mergeRequestApi = gitlabApi.getMergeRequestApi();
         MergeRequest mergeRequest = mergeRequestApi.createMergeRequest(projectId, sourceBranch, targetBranch, title, description, Long.valueOf(reviewerId));
         return mergeRequestApi.acceptMergeRequest(projectId, mergeRequest.getIid());
     }
 
     @Override
-    public VisibilityVO getProjectVisibility(int projectId) throws GitLabApiException {
+    public VisibilityVO getProjectVisibility(Integer projectId) throws GitLabApiException {
         ProjectApi projectApi = gitlabApi.getProjectApi();
         Project project = projectApi.getProject(projectId);
         return new VisibilityVO(projectId, project.getVisibility().toString());
@@ -389,7 +389,7 @@ public class ProjectServiceImpl implements ProjectService {
                 .build();
     }
 
-    private GitlabUser getGitlabUser(int userId) throws GitLabApiException {
+    private GitlabUser getGitlabUser(Integer userId) throws GitLabApiException {
         GitlabUser user = gitlabUserRepository.findByUserId(userId);
         if(user != null)
             return user;

+ 4 - 4
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/impl/UserServiceImpl.java

@@ -66,7 +66,7 @@ public class UserServiceImpl implements UserService {
         return null;
     }
 
-    private void check(int userId) throws GitLabApiException {
+    private void check(Integer userId) throws GitLabApiException {
         if (gitlabUserRepository.existsById(userId))
             throw new GitLabApiException("user already exists");
     }
@@ -92,7 +92,7 @@ public class UserServiceImpl implements UserService {
     }
 
     @Override
-    public synchronized boolean deleteUser(int userId) throws GitLabApiException {
+    public synchronized boolean deleteUser(Integer userId) throws GitLabApiException {
         gitlabApi.getUserApi().deleteUser(userId);
         return true;
     }
@@ -120,12 +120,12 @@ public class UserServiceImpl implements UserService {
     }
 
     @Override
-    public String getUserEmail(int userId) throws GitLabApiException {
+    public String getUserEmail(Integer userId) throws GitLabApiException {
         userId = gitlabUserRepository.findByUserId(userId).getGitlabUserId();
         return gitlabApi.getUserApi().getUser(Long.valueOf(userId)).getEmail();
     }
 
-    private String createToken(int userId) throws GitLabApiException {
+    private String createToken(Integer userId) throws GitLabApiException {
         Scope[] scopes = new Scope[]{Scope.API};
         ImpersonationToken token;
         token = gitlabApi.getUserApi().createImpersonationToken(userId, "AES-" + Tools.randomUUID(), null, scopes);