doortts doortts 2017-06-26
api: Add author list of project
@fbfbc4e8a7368f96427a11443e40e23c7cf5d651
app/controllers/MigrationApp.java
--- app/controllers/MigrationApp.java
+++ app/controllers/MigrationApp.java
@@ -146,6 +146,18 @@
         return members;
     }
 
+    public static List<ObjectNode> getAuthors(Project project) {
+        List<ObjectNode> authors = new ArrayList<>();
+        for(User user: project.findAuthors()){
+            ObjectNode member = Json.newObject();
+            member.put("name", user.name);
+            member.put("login", user.loginId);
+            member.put("email", user.email);
+            authors.add(member);
+        }
+        return authors;
+    }
+
     @AnonymousCheck(requiresLogin = true, displaysFlashMessage = true)
     public static Result exportIssueLabelPairs(String owner, String projectName){
         ObjectNode issueLabelPairs = composeIssueLabelPairJson(owner, projectName);
app/controllers/ProjectApp.java
--- app/controllers/ProjectApp.java
+++ app/controllers/ProjectApp.java
@@ -828,7 +828,7 @@
             return;
         }
 
-        for (User user : findAuthorsAndWatchers(project)) {
+        for (User user : project.findAuthorsAndWatchers()) {
             if (!userList.contains(user)) {
                 userList.add(user);
             }
@@ -1226,36 +1226,4 @@
         }
         return ok();
     }
-
-    public static Set<User> findAuthorsAndWatchers(@Nonnull Project project) {
-        Set<User> allAuthors = new LinkedHashSet<>();
-
-        allAuthors.addAll(getIssueUsers(project));
-        allAuthors.addAll(getPostingUsers(project));
-        allAuthors.addAll(getPullRequestUsers(project));
-        allAuthors.addAll(getWatchedUsers(project));
-
-        return allAuthors;
-    }
-
-    private static Set<User> getPostingUsers(Project project) {
-        String postSql = "SELECT distinct author_id id FROM posting where project_id=" + project.id;
-        return User.find.setRawSql(RawSqlBuilder.parse(postSql).create()).findSet();
-    }
-
-    private static Set<User> getIssueUsers(Project project) {
-        String issueSql = "SELECT distinct author_id id FROM ISSUE where project_id=" + project.id;
-        return User.find.setRawSql(RawSqlBuilder.parse(issueSql).create()).findSet();
-    }
-
-    private static Set<User> getPullRequestUsers(Project project) {
-        String postSql = "SELECT distinct contributor_id id FROM pull_request where to_project_id=" + project.id;
-        return User.find.setRawSql(RawSqlBuilder.parse(postSql).create()).findSet();
-    }
-
-    private static Set<User> getWatchedUsers(Project project) {
-        String postSql = "SELECT distinct user_id id FROM watch where resource_type='PROJECT' and resource_id=" + project.id;
-        return User.find.setRawSql(RawSqlBuilder.parse(postSql).create()).findSet();
-    }
-
 }
app/controllers/api/ProjectApi.java
--- app/controllers/api/ProjectApi.java
+++ app/controllers/api/ProjectApi.java
@@ -25,7 +25,7 @@
 import java.util.stream.Collectors;
 
 import static controllers.MigrationApp.composePlainCommentsJson;
-import static controllers.MigrationApp.getAssginees;
+import static controllers.MigrationApp.*;
 import static models.AbstractPosting.findByProject;
 import static play.libs.Json.toJson;
 
@@ -40,6 +40,7 @@
         json.put("projectName", project.name);
         json.put("projectDescription", project.overview);
         json.put("assignees", toJson(getAssginees(project).toArray()));
+        json.put("authors", toJson(getAuthors(project).toArray()));
         json.put("memberCount", project.members().size());
         json.put("members", project.members().size());
         Optional.ofNullable(project.members())
app/models/Project.java
--- app/models/Project.java
+++ app/models/Project.java
@@ -9,6 +9,7 @@
 import com.avaje.ebean.Ebean;
 import com.avaje.ebean.ExpressionList;
 import com.avaje.ebean.Page;
+import com.avaje.ebean.RawSqlBuilder;
 import models.enumeration.ProjectScope;
 import models.enumeration.RequestState;
 import models.enumeration.ResourceType;
@@ -35,10 +36,7 @@
 import javax.persistence.*;
 import javax.servlet.ServletException;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 import static utils.CacheStore.getProjectCacheKey;
 import static utils.CacheStore.projectMap;
@@ -175,6 +173,43 @@
         }
     }
 
+    public Set<User> findAuthors() {
+        Set<User> allAuthors = new LinkedHashSet<>();
+        allAuthors.addAll(getIssueUsers());
+        allAuthors.addAll(getPostingUsers());
+        allAuthors.addAll(getPullRequestUsers());
+
+        return allAuthors;
+    }
+
+    public Set<User> findAuthorsAndWatchers() {
+        Set<User> allAuthors = new LinkedHashSet<>();
+        allAuthors.addAll(findAuthors());
+        allAuthors.addAll(getWatchedUsers());
+
+        return allAuthors;
+    }
+
+    private Set<User> getIssueUsers() {
+        String issueSql = "SELECT distinct author_id id FROM ISSUE where project_id=" + this.id;
+        return User.find.setRawSql(RawSqlBuilder.parse(issueSql).create()).findSet();
+    }
+
+    private Set<User> getPostingUsers() {
+        String postSql = "SELECT distinct author_id id FROM posting where project_id=" + this.id;
+        return User.find.setRawSql(RawSqlBuilder.parse(postSql).create()).findSet();
+    }
+
+    private Set<User> getPullRequestUsers() {
+        String postSql = "SELECT distinct contributor_id id FROM pull_request where to_project_id=" + this.id;
+        return User.find.setRawSql(RawSqlBuilder.parse(postSql).create()).findSet();
+    }
+
+    public Set<User> getWatchedUsers() {
+        String postSql = "SELECT distinct user_id id FROM watch where resource_type='PROJECT' and resource_id=" + this.id;
+        return User.find.setRawSql(RawSqlBuilder.parse(postSql).create()).findSet();
+    }
+
     public boolean hasMember(User user) {
         if (user.isMemberOf(this) ||
                 user.isManagerOf(this) ||
Add a comment
List