1
0
Azure 2 лет назад
Родитель
Сommit
a2b8b56630

+ 2 - 2
pom.xml

@@ -11,7 +11,7 @@
 
     <groupId>com.nju.edu</groupId>
     <artifactId>seecoder-gitlab</artifactId>
-    <version>0.1.6</version>
+    <version>0.1.7</version>
     <packaging>pom</packaging>
     <description>Gitlab API project</description>
     <modules>
@@ -22,7 +22,7 @@
 
     <properties>
         <java.version>1.8</java.version>
-        <seecoder-gitlab-version>0.1.6</seecoder-gitlab-version>
+        <seecoder-gitlab-version>0.1.7</seecoder-gitlab-version>
     </properties>
 
     <dependencyManagement>

+ 2 - 2
seecoder-gitlab-client/pom.xml

@@ -5,14 +5,14 @@
     <parent>
         <artifactId>seecoder-gitlab</artifactId>
         <groupId>com.nju.edu</groupId>
-        <version>0.1.6</version>
+        <version>0.1.7</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>seecoder-gitlab-client</artifactId>
 
     <properties>
-        <seecoder-gitlab-version>0.1.6</seecoder-gitlab-version>
+        <seecoder-gitlab-version>0.1.7</seecoder-gitlab-version>
     </properties>
 
     <dependencies>

+ 2 - 1
seecoder-gitlab-client/src/main/java/com.nju.edu.gitlab/SeecoderGitlabApi.java

@@ -12,6 +12,7 @@ import org.gitlab4j.api.models.User;
 
 
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 public interface SeecoderGitlabApi{
@@ -40,7 +41,7 @@ public interface SeecoderGitlabApi{
 
     public boolean deleteProject(int projectId) throws SeecoderGitlabException;
 
-    public Integer forkProject(int projectId, int userId,String username,String examUuid) throws SeecoderGitlabException;
+    public Map<String,Integer> forkProject(int projectId, int userId, String username, String examUuid) throws SeecoderGitlabException;
 
     public Integer forkGroupProject(int projectId,int groupId) throws SeecoderGitlabException;
 

+ 4 - 7
seecoder-gitlab-client/src/main/java/com.nju.edu.gitlab/SeecoderGitlabClient.java

@@ -21,10 +21,7 @@ import okhttp3.*;
 
 import java.io.IOException;
 import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -423,7 +420,7 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
 
 
     @Override
-    public Integer forkProject(int projectId, int userId, String username,String examUuid) throws SeecoderGitlabException {
+    public Map<String,Integer> forkProject(int projectId, int userId, String username, String examUuid) throws SeecoderGitlabException {
         try {
             ObjectMapper objectMapper = new ObjectMapper();
             Request.Builder builder = new Request.Builder()
@@ -440,10 +437,10 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi {
             Request request = builder.build();
             final Call call = client.newCall(request);
             Response response = call.execute();
-            projectId = processResponse(objectMapper, response, new TypeReference<Integer>() {
+            Map<String,Integer> forkedAndId = processResponse(objectMapper, response, new TypeReference<Map<String,Integer>>() {
             });
             response.close();
-            return projectId;
+            return forkedAndId;
         } catch (JsonProcessingException e) {
             logger.error("JSON writeValueAsString error", e);
             throw SeecoderGitlabException.JSON_ERROR;

+ 1 - 1
seecoder-gitlab-common/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>seecoder-gitlab</artifactId>
         <groupId>com.nju.edu</groupId>
-        <version>0.1.6</version>
+        <version>0.1.7</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

+ 2 - 2
seecoder-gitlab-server/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>seecoder-gitlab</artifactId>
         <groupId>com.nju.edu</groupId>
-        <version>0.1.6</version>
+        <version>0.1.7</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
@@ -81,7 +81,7 @@
         <dependency>
             <groupId>com.nju.edu</groupId>
             <artifactId>seecoder-gitlab-common</artifactId>
-            <version>0.1.6</version>
+            <version>0.1.7</version>
         </dependency>
     </dependencies>
 

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

@@ -15,6 +15,7 @@ import org.gitlab4j.api.models.TreeItem;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 public interface ProjectService {
@@ -31,7 +32,7 @@ public interface ProjectService {
 
     public boolean deleteProject(Integer projectId) throws  GitLabApiException;
 
-    public Integer forkProject(UserForkDTO userForkDTO) throws GitLabApiException;
+    public Map<String,Integer> forkProject(UserForkDTO userForkDTO) throws GitLabApiException;
 
     public Integer forkGroupProject(GroupForkDTO groupForkDTO) throws GitLabApiException;
 

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

@@ -93,7 +93,8 @@ public class ProjectServiceImpl implements ProjectService {
     }
 
     @Override
-    public Integer forkProject(UserForkDTO userForkDTO) throws GitLabApiException {
+    public Map<String,Integer> forkProject(UserForkDTO userForkDTO) throws GitLabApiException {
+        Map<String,Integer> forkedAndId=new HashMap<>();
         int userId=userForkDTO.getUserId();
         int projectId=userForkDTO.getProjectId();
         String username=userForkDTO.getUsername();
@@ -103,9 +104,11 @@ public class ProjectServiceImpl implements ProjectService {
         Project project;
         log.info("trying to fork project {} to user {} (whose gitlab id is {})", projectId, userId, gitlabUser.getGitlabUserId());
         Integer existProjectId=searchForkedProject(username, examUuid);
-        if(existProjectId!=-1)
-            return existProjectId;
-
+        if(existProjectId!=-1){
+            forkedAndId.put("forked",1);
+            forkedAndId.put("id",existProjectId);
+            return forkedAndId;
+        }
         try{
             gitlabApi.setSudoAsId((long) gitlabUser.getGitlabUserId());
             project=gitlabApi.getProjectApi().forkProject(new Long(projectId), new Long(namespaceId));
@@ -114,7 +117,9 @@ public class ProjectServiceImpl implements ProjectService {
         }finally {
             gitlabApi.unsudo();
         }
-        return Math.toIntExact(project != null ? project.getId() : null);
+        forkedAndId.put("forked", 0);
+        forkedAndId.put("id", Math.toIntExact(project != null ? project.getId() : null));
+        return forkedAndId;
     }
 
     public Integer searchForkedProject(String username, String examUuid) throws GitLabApiException {