77import java .util .List ;
88
99import javax .persistence .CascadeType ;
10+ import javax .persistence .Column ;
1011import javax .persistence .Entity ;
1112import javax .persistence .JoinTable ;
12- import javax .persistence .OneToMany ;
13+ import javax .persistence .ManyToMany ;
1314import javax .persistence .UniqueConstraint ;
1415
1516import org .hibernate .annotations .Fetch ;
1617
1718import com .fasterxml .jackson .annotation .JsonIdentityInfo ;
1819import com .fasterxml .jackson .annotation .JsonIdentityReference ;
20+ import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
1921import com .fasterxml .jackson .annotation .ObjectIdGenerators ;
2022
2123@ Entity
24+ @ JsonIgnoreProperties (value = { "voters" }, allowGetters = true )
2225public class FeatureProposal extends AbstractIdea {
2326
24- @ OneToMany (fetch = EAGER , cascade = { CascadeType .REFRESH , CascadeType .DETACH , CascadeType .MERGE })
27+ @ ManyToMany (fetch = EAGER , cascade = { CascadeType .REFRESH , CascadeType .DETACH , CascadeType .MERGE })
2528 @ JoinTable (uniqueConstraints = @ UniqueConstraint (columnNames = { "feature_proposal_id" , "ideas_id" }))
2629 @ Fetch (value = SELECT )
2730 private List <Idea > ideas ;
2831
29- @ OneToMany (fetch = EAGER , cascade = { CascadeType .REFRESH , CascadeType .DETACH , CascadeType .MERGE })
32+ @ ManyToMany (fetch = EAGER , cascade = { CascadeType .REFRESH , CascadeType .DETACH , CascadeType .MERGE })
3033 @ JsonIdentityInfo (generator = ObjectIdGenerators .PropertyGenerator .class , scope = User .class , property = "id" )
3134 @ JsonIdentityReference (alwaysAsId = true )
3235 @ JoinTable (uniqueConstraints = @ UniqueConstraint (columnNames = { "feature_proposal_id" , "voters_id" }))
3336 @ Fetch (value = SELECT )
3437 private List <User > voters ;
3538
39+ @ Column (nullable = false )
40+ private boolean submitted ;
41+
3642 public FeatureProposal () {
3743 super ();
3844 setup ();
@@ -62,6 +68,7 @@ public FeatureProposal(Idea idea) {
6268 private void setup () {
6369 this .ideas = new ArrayList <Idea >();
6470 this .voters = new ArrayList <User >();
71+ this .submitted = false ;
6572 }
6673
6774 public List <Idea > getIdeas () {
@@ -79,10 +86,8 @@ public void setIdeas(List<Idea> ideas) {
7986 }
8087
8188 public void addIdea (Idea idea ) {
82- if (!this .ideas .contains (idea )) {
83- this .ideas .add (idea );
84- addVoter (idea .getAuthor ());
85- }
89+ this .ideas .add (idea );
90+ addVoter (idea .getAuthor ());
8691 }
8792
8893 public void removeIdea (Idea idea ) {
@@ -99,9 +104,7 @@ public void setVoters(List<User> voters) {
99104 }
100105
101106 public void addVoter (User voter ) {
102- if (!this .voters .contains (voter )) {
103- this .voters .add (voter );
104- }
107+ this .voters .add (voter );
105108 }
106109
107110 public void removeVoter (User voter ) {
@@ -112,4 +115,12 @@ public int getVotes() {
112115 return this .voters .size ();
113116 }
114117
118+ public boolean isSubmitted () {
119+ return submitted ;
120+ }
121+
122+ public void setSubmitted (boolean submitted ) {
123+ this .submitted = submitted ;
124+ }
125+
115126}
0 commit comments