Yi EungJun 2012-12-08
issue: Fix failures related assignee.
* Remove initialization for assignee in initial-data.yml. It causes
Referential integrity constraint violation.
* Remove unnecessary code.
@9a0749b286d89a939d6f1baf963bc332a06b0ddd
app/controllers/IssueApp.java
--- app/controllers/IssueApp.java
+++ app/controllers/IssueApp.java
@@ -11,6 +11,7 @@
 
 import jxl.write.WriteException;
 
+import models.Assignee;
 import models.Attachment;
 import models.Issue;
 import models.IssueComment;
@@ -137,8 +138,8 @@
             newIssue.authorName = UserApp.currentUser().name;
             newIssue.project = project;
             newIssue.state = State.OPEN;
-            if (newIssue.assignee.id != null) {
-                newIssue.assignee.project = project;
+            if (newIssue.assignee.user.id != null) {
+                newIssue.assignee = Assignee.add(newIssue.assignee.user.id, project.id);
             } else {
                 newIssue.assignee = null;
             }
@@ -185,8 +186,8 @@
         issue.authorId = originalIssue.authorId;
         issue.authorName = originalIssue.authorName;
         issue.project = originalIssue.project;
-        if (issue.assignee.id != null) {
-            issue.assignee.project = originalIssue.project;
+        if (issue.assignee.user.id != null) {
+            issue.assignee = Assignee.add(issue.assignee.user.id, originalIssue.project.id);
         } else {
             issue.assignee = null;
         }
@@ -199,10 +200,6 @@
         }
 
         Issue.edit(issue);
-
-        if (originalIssue.assignee != null) {
-            originalIssue.assignee.deleteIfEmpty();
-        }
 
         // Attach the files in the current user's temporary storage.
         Attachment.attachFiles(UserApp.currentUser().id, originalIssue.project.id, Resource.ISSUE_POST, id);
app/models/Assignee.java
--- app/models/Assignee.java
+++ app/models/Assignee.java
@@ -54,29 +54,13 @@
         return assignee;
     }
 
-    @Override
-    public boolean equals(Object that) {
-        if (!(that instanceof Assignee))
-            return false;
-        Assignee castedThat = (Assignee) that;
-        if (id == castedThat.id)
-            return true;
-        return (this == castedThat) || (user.id == castedThat.user.id)
-                && (project.id == castedThat.project.id);
-    }
-
-    @Override
-    public int hashCode() {
-        return new HashCodeBuilder().append(user.hashCode()).append(project.hashCode())
-                .toHashCode();
-    }
-
-    public void deleteIfEmpty() {
-        Logger.debug("empty?");
-        Logger.debug(String.valueOf(issues.size()));
-        if (this.issues.isEmpty()) {
-            Logger.debug("del");
-            super.delete();
+    public static Assignee add(Long userId, Long projectId) {
+        Assignee assignee = finder.where()
+                .eq("user.id", userId).eq("project.id", projectId).findUnique();
+        if (assignee != null) {
+            return assignee;
+        } else {
+            return new Assignee(userId, projectId);
         }
     }
 }
(No newline at end of file)
app/models/Issue.java
--- app/models/Issue.java
+++ app/models/Issue.java
@@ -225,12 +225,7 @@
             Milestone milestone = Milestone.findById(issue.milestoneId);
             milestone.delete(issue);
         }
-        Assignee a = issue.assignee;
         issue.delete();
-        if (a != null) {
-            a.refresh();
-            a.deleteIfEmpty();
-        }
     }
 
     /**
app/models/support/FinderTemplate.java
--- app/models/support/FinderTemplate.java
+++ app/models/support/FinderTemplate.java
@@ -4,11 +4,8 @@
 
 import play.Logger;
 import play.db.ebean.*;
-import play.db.ebean.Model.Finder;
 
 import java.util.*;
-
-import models.Issue;
 
 public class FinderTemplate {
 
conf/initial-data.yml
--- conf/initial-data.yml
+++ conf/initial-data.yml
@@ -103,11 +103,6 @@
                             id: 1
     - !!models.Issue
         authorId:     3
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 2
-                     project: !!models.Project
-                                id: 1
         title:          다운로드는 익명 댓글에도 사용자명에 링크가 걸림
         body:           내용 다운로드는 익명 댓글에도 사용자명에 링크가 걸림
         state:      OPEN
@@ -117,11 +112,6 @@
                             id: 1
     - !!models.Issue
         authorId:     4
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 2
-                     project: !!models.Project
-                                id: 1
         title:          gittracker.php의 메모리 제한 에러
         body:           내용 gittracker.php의 메모리 제한 에러
         state:      CLOSED
@@ -132,11 +122,6 @@
         numOfComments:  1
     - !!models.Issue
         authorId:     4
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 1
         title:          git/hg 코드 브라우저에 i18n이 적용되지 않음
         body:           내용 git/hg 코드 브라우저에 i18n이 적용되지 않음
         state:      CLOSED
@@ -146,11 +131,6 @@
                             id: 1
     - !!models.Issue
         authorId:     4
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 1
         title:          CUBRID 설치 문제
         body:           IOS는 설치 못하나요?
         state:      OPEN
@@ -160,11 +140,6 @@
                             id: 3
     - !!models.Issue
         authorId:     4
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 1
         title:          메모리 누수 현상
         body:           메모리가 너무 누수가 되는듯.
         state:      CLOSED
@@ -174,11 +149,6 @@
                             id: 3
     - !!models.Issue
         authorId:     4
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 1
         title:          Client application for Mac.
         body:           Please make it.
         state:      OPEN
@@ -188,11 +158,6 @@
                             id: 3
     - !!models.Issue
         authorId:     4
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 1
         title:          CPU 무한 점유울 문제.
         body:           CPU를 무한사용 중이에요.
         state:      CLOSED
@@ -202,11 +167,6 @@
                             id: 3
     - !!models.Issue
         authorId:     1
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 1
         title:          Less chained imports causes compile error
         body:           When using Play, when I chain less files such as a.less imports b.less which in turn imports c.less
         state:      CLOSED
@@ -216,11 +176,6 @@
                             id: 1
     - !!models.Issue
         authorId:     1
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 2
-                     project: !!models.Project
-                                id: 1
         title:          Weird TypeDoesNotMatch exception in RC-3 and final
         body:           The following code works as expected in RC1-Snapshot, but breaks with an TypeDoesNotMatch exception in RC-3 and 2.0 final.
         state:      CLOSED
@@ -239,11 +194,6 @@
                             id: 1
     - !!models.Issue
         authorId:     1
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 2
         title:          Update sbt-idea to 1.1.0
         body:           Create sbt project definition module, if exists, for each subproject (pull 128)
         state:      CLOSED
@@ -253,11 +203,6 @@
                             id: 2
     - !!models.Issue
         authorId:     1
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 2
         title:          Support Tuple 22, not just Tuple 18 in api/data/Forms.scala
         body:           While creating some complex forms, Eclipse started hanging for some unknown reason.
         state:      CLOSED
@@ -267,11 +212,6 @@
                             id: 2
     - !!models.Issue
         authorId:     1
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 2
         title:          Support Tuple 22, not just Tuple 18 in api/data/Forms.scala
         body:           While creating some complex forms, Eclipse started hanging for some unknown reason.
         state:      OPEN
@@ -281,11 +221,6 @@
                             id: 2
     - !!models.Issue
         authorId:     1
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 2
         title:          Cookie Expires date
         body:           With Play 2.0.2, when creating a cookie with response().setCookie, HTTP output is like
         state:      OPEN
@@ -295,11 +230,6 @@
                             id: 2
     - !!models.Issue
         authorId:     1
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 2
         title:          require is not work in windows (Closure Compiler)
         body:           Test on Play2.1-Snapshot
         state:      OPEN
@@ -309,11 +239,6 @@
                             id: 2
     - !!models.Issue
         authorId:     2
-        assignee: !!models.Assignee
-                     user: !!models.User
-                                id: 3
-                     project: !!models.Project
-                                id: 3
         title:          Remember me is not working
         body:           Test on Play2.1-Snapshot
         state:      OPEN
test/models/IssueTest.java
--- test/models/IssueTest.java
+++ test/models/IssueTest.java
@@ -122,10 +122,17 @@
 
     @Test
     public void findAssigneeByIssueId() {
+        // Given
+        Long issueId = 2l;
+        Long userId = 1l;
+
         // When
-        Long assignee = Issue.findAssigneeIdByIssueId(2l);
+        Issue issue = Issue.findById(issueId);
+        issue.assignee = Assignee.add(userId, issue.project.id);
+        issue.save();
+
         // Then
-        assertThat(assignee).isEqualTo(2l);
+        assertThat(Issue.findAssigneeIdByIssueId(issueId)).isEqualTo(userId);
     }
 
     @Test
Add a comment
List