88import javax .persistence .*;
99import javax .persistence .Index ;
1010
11+ import lombok .EqualsAndHashCode ;
12+ import lombok .Getter ;
13+ import lombok .Setter ;
14+ import lombok .ToString ;
1115import org .hibernate .annotations .OnDelete ;
1216import org .hibernate .annotations .OnDeleteAction ;
1317import org .hibernate .validator .constraints .Length ;
3135 @ Index (name = "ix_project_row_created_at" , columnList = "row_created_at" )
3236 }
3337)
38+ @ Getter
39+ @ Setter
40+ @ EqualsAndHashCode
41+ @ ToString
3442public class Project extends AuditModel implements Serializable , ComparableById <Project > {
3543
3644 private static final long serialVersionUID = 4566653175832872422L ;
@@ -45,44 +53,53 @@ public class Project extends AuditModel implements Serializable, ComparableById<
4553 private Long id ;
4654
4755 @ ManyToOne (
48- fetch = FetchType .LAZY ,
49- optional = true ,
50- cascade = {
51- CascadeType .MERGE ,
52- CascadeType .REFRESH
53- }
56+ fetch = FetchType .LAZY ,
57+ optional = true ,
58+ cascade = {
59+ CascadeType .MERGE ,
60+ CascadeType .REFRESH
61+ }
5462 )
5563 @ JoinColumn (name = "parent_id" )
5664 @ OnDelete (action = OnDeleteAction .NO_ACTION )
5765 private Project parent ;
5866
5967 @ ManyToOne (
60- fetch = FetchType .LAZY ,
61- optional = false ,
62- cascade = {
63- CascadeType .MERGE ,
64- CascadeType .REFRESH
65- }
68+ fetch = FetchType .LAZY ,
69+ optional = false ,
70+ cascade = {
71+ CascadeType .MERGE ,
72+ CascadeType .REFRESH
73+ }
6674 )
6775 @ JoinColumn (name = "context_id" )
6876 @ OnDelete (action = OnDeleteAction .NO_ACTION )
6977 private Context context ;
7078
71- @ SafeHtml (whitelistType = SafeHtml .WhiteListType .NONE )
79+ @ SafeHtml (whitelistType = SafeHtml .WhiteListType .NONE )
7280 @ NotBlank
73- @ Length (min = 1 , max = 255 )
74- @ Column (name = "name" ,nullable = false )
81+ @ Length (min = 1 , max = 255 )
82+ @ Column (name = "name" , nullable = false )
7583 private String name ;
7684
7785 //@SafeHtml(whitelistType= SafeHtml.WhiteListType.RELAXED)
7886 @ NotBlank
79- @ Length (min = 0 , max = 65535 )
80- @ Column (name = "description" , nullable = true , length = 65535 , columnDefinition = "text" )
87+ @ Length (min = 0 , max = 65535 )
88+ @ Column (name = "description" , nullable = true , length = 65535 , columnDefinition = "text" )
8189 private String description ;
8290
83- @ OneToMany (fetch = FetchType .LAZY , mappedBy = "parent" , cascade = { CascadeType .ALL })
91+ @ OneToMany (fetch = FetchType .LAZY , mappedBy = "parent" , cascade = {CascadeType .ALL })
8492 private List <Project > children = new ArrayList <>();
8593
94+ @ Transient
95+ public String getUrl () {
96+ if (this .getId () == null || this .getId () == 0L ) {
97+ return "redirect:/project/root" ;
98+ } else {
99+ return "redirect:/project/" + this .getId ();
100+ }
101+ }
102+
86103 @ Transient
87104 public boolean hasNoChildren () {
88105 return this .children .size () == 0 ;
@@ -108,7 +125,7 @@ public boolean equalsById(Project otherObject) {
108125 @ Override
109126 public boolean equalsByUniqueConstraint (Project otherObject ) {
110127 boolean okParent ;
111- if (this .isRootProject ()){
128+ if (this .isRootProject ()) {
112129 okParent = (otherObject .isRootProject ());
113130 } else {
114131 okParent = this .getParent ().equalsByUniqueConstraint (otherObject .getParent ());
@@ -137,92 +154,22 @@ public static Project newRootProjectFactory(UserAccount userAccount) {
137154 return n ;
138155 }
139156
140- public static Project newRootProjectFactory (UserAccount userAccount , Context context ) {
157+ public static Project newRootProjectFactory (Context context ) {
141158 Project n = new Project ();
142159 n .setParent (null );
143160 n .setContext (context );
144161 return n ;
145162 }
146163
147- public Long getId () {
148- return id ;
149- }
150-
151- public void setId (Long id ) {
152- this .id = id ;
153- }
154-
155- public Project getParent () {
156- return parent ;
157- }
158-
159- public void setParent (Project parent ) {
160- this .parent = parent ;
161- }
162-
163- public String getName () {
164- return name ;
165- }
166-
167- public void setName (String name ) {
168- this .name = name ;
169- }
170-
171- public String getDescription () {
172- return description ;
173- }
174-
175- public void setDescription (String description ) {
176- this .description = description ;
177- }
178-
179- public List <Project > getChildren () {
180- return children ;
181- }
182164
183- public void setChildren (List <Project > children ) {
184- this .children = children ;
185- }
186-
187- public Context getContext () {
188- return context ;
189- }
190-
191- public void setContext (Context context ) {
192- this .context = context ;
193- }
194-
195- @ Override
196- public boolean equals (Object o ) {
197- if (this == o ) return true ;
198- if (!(o instanceof Project )) return false ;
199- if (!super .equals (o )) return false ;
200- Project project = (Project ) o ;
201- return Objects .equals (getId (), project .getId ()) &&
202- Objects .equals (getParent (), project .getParent ()) &&
203- getContext ().equals (project .getContext ()) &&
204- getName ().equals (project .getName ()) &&
205- getDescription ().equals (project .getDescription ()) &&
206- getChildren ().equals (project .getChildren ());
207- }
208-
209- @ Override
210- public int hashCode () {
211- return Objects .hash (super .hashCode (), getId (), getParent (), getContext (), getName (), getDescription (), getChildren ());
212- }
213-
214- @ Override
215- public String toString () {
216- return "Project{" +
217- "id=" + id +
218- ", parent=" + parent +
219- ", context=" + context +
220- ", name='" + name + '\'' +
221- ", description='" + description + '\'' +
222- ", uuid='" + uuid + '\'' +
223- ", rowCreatedAt=" + rowCreatedAt +
224- ", rowUpdatedAt=" + rowUpdatedAt +
225- '}' ;
165+ //TODO: use newRootProjectFactory(Context context);
166+ @ Deprecated
167+ public static Project newRootProjectFactory (UserAccount userAccount , Context context ) {
168+ Project n = new Project ();
169+ n .setParent (null );
170+ n .setContext (context );
171+ return n ;
226172 }
227173
228174}
175+
0 commit comments