KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > core > Project


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package za.org.coefficient.core;
21
22 import za.org.coefficient.authentication.CoefficientUser;
23 import za.org.coefficient.authentication.ProjectMember;
24 import za.org.coefficient.authentication.Role;
25 import za.org.coefficient.statistics.data.ProjectStatistics;
26 import za.org.coefficient.util.ejb.SecurityUtil;
27
28 import java.io.Serializable JavaDoc;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.Date JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34
35 /**
36  * @hibernate.class
37  * table="COEFFICIENT_PROJECT"
38  */

39 public class Project implements Serializable JavaDoc {
40     //~ Instance fields ========================================================
41

42     private Date JavaDoc registrationDate;
43     private List JavaDoc attributeData = new ArrayList JavaDoc();
44     private List JavaDoc attributes = new ArrayList JavaDoc();
45     private List JavaDoc categories = new ArrayList JavaDoc();
46     private List JavaDoc members = new ArrayList JavaDoc();
47     private List JavaDoc membersPending = new ArrayList JavaDoc();
48     private List JavaDoc modules = new ArrayList JavaDoc();
49     private List JavaDoc versions = new ArrayList JavaDoc();
50     private List JavaDoc components = new ArrayList JavaDoc();
51     private Long JavaDoc id;
52     private ProjectStatistics statistics;
53     private ProjectVersion currentVersion;
54     private String JavaDoc description;
55     private String JavaDoc homePage;
56     private String JavaDoc name;
57     private boolean active;
58     private long version;
59     private boolean isPublic;
60     private boolean isWorkflow;
61     private String JavaDoc themeName = null;
62     private String JavaDoc shortName = null;
63
64     //~ Constructors ===========================================================
65

66     public Project() {
67         registrationDate = new Date JavaDoc(System.currentTimeMillis());
68         isPublic = true;
69         isWorkflow = false;
70     }
71
72     //~ Methods ================================================================
73

74     /**
75      * Sets the value of active
76      *
77      * @param active Value to assign to this.active
78      */

79     public void setActive(boolean active) {
80         this.active = active;
81     }
82
83     /**
84      * Gets the value of active
85      *
86      * @return the value of active
87      * @hibernate.property
88      * column="ACTIVE"
89      * not-null="true"
90      */

91     public boolean getActive() {
92         return this.active;
93     }
94
95     /**
96      * Sets the value of isPublic
97      *
98      * @param public Value to assign to this.isPublic
99      */

100     public void setIsPublic(boolean isPublic) {
101         this.isPublic = isPublic;
102     }
103
104     /**
105      * Gets the value of public
106      *
107      * @return the value of isPublic
108      * @hibernate.property
109      * column="ISPUBLIC"
110      * not-null="true"
111      */

112     public boolean getIsPublic() {
113         return this.isPublic;
114     }
115
116     /**
117      * Sets the value of isWorkflow
118      *
119      * @param workflow Value to assign to this.isWorkflow
120      */

121     public void setIsWorkflow(boolean isWorkflow) {
122         this.isWorkflow = isWorkflow;
123     }
124
125     /**
126      * Gets the value of workflow
127      *
128      * @return the value of isWorkflow
129      * @hibernate.property
130      * column="ISWORKFLOW"
131      * not-null="true"
132      */

133     public boolean getIsWorkflow() {
134         return this.isWorkflow;
135     }
136
137     /**
138      * Sets the value of attributeData
139      *
140      * @param argAttributeData Value to assign to this.attributeData
141      */

142     public void setAttributeData(List JavaDoc argAttributeData) {
143         this.attributeData = argAttributeData;
144     }
145
146     /**
147      * Gets the value of attributeData
148      *
149      * @return the value of attributeData
150      * @hibernate.list
151      * table="COEFFICIENT_PROJECT_ATTRIBUTES_DATA"
152      * @hibernate.collection-key
153      * column="PROJECT_ID"
154      * @hibernate.collection-index
155      * column="IDX"
156      * @hibernate.collection-many-to-many
157      * class="za.org.coefficient.core.ProjectAttributeData"
158      * column="ATTRIBUTE_DATA"
159      */

160     public List JavaDoc getAttributeData() {
161         return this.attributeData;
162     }
163
164     /**
165      * Sets the value of attributes
166      *
167      * @param argAttributes Value to assign to this.attributes
168      */

169     public void setAttributes(List JavaDoc argAttributes) {
170         this.attributes = argAttributes;
171     }
172
173     /**
174      * Gets the value of attributes
175      *
176      * @return the value of attributes
177      * @hibernate.list
178      * cascade="all"
179      * table="COEFFICIENT_PROJECT_ATTRIBUTES"
180      * @hibernate.collection-key
181      * column="PROJECT_ID"
182      * @hibernate.collection-index
183      * column="IDX"
184      * @hibernate.collection-element
185      * column="ATTRIBUTE"
186      * type="long"
187      */

188     public List JavaDoc getAttributes() {
189         return this.attributes;
190     }
191
192     /**
193      * Sets the value of categories
194      *
195      * @param argCategories Value to assign to this.categories
196      */

197     public void setCategories(List JavaDoc argCategories) {
198         this.categories = argCategories;
199     }
200
201     /**
202      * Gets the value of categories
203      *
204      * @return the value of categories
205      * @hibernate.list
206      * table="COEFFICIENT_PROJECT_CATEGORIES"
207      * @hibernate.collection-key
208      * column="PROJECT_ID"
209      * @hibernate.collection-index
210      * column="IDX"
211      * @hibernate.collection-many-to-many
212      * class="za.org.coefficient.core.Category"
213      * column="CATEGORY"
214      */

215     public List JavaDoc getCategories() {
216         return this.categories;
217     }
218
219     /**
220      * returns a list of project champions only
221      */

222     public List JavaDoc getChampionsAsMembers() {
223         List JavaDoc champs = new ArrayList JavaDoc();
224         List JavaDoc members = getMembers();
225         ProjectMember member;
226         Role role;
227         String JavaDoc st;
228
229         int i;
230
231         for (i = 0; i < members.size(); i++) {
232             try {
233                 member = (ProjectMember) (members.get(i));
234                 role = member.getProjectRole();
235                 st = role.getDescription();
236                 if (st.equals(SecurityUtil.PROJECT_CHAMPION_ROLE_DESC)) {
237                     champs.add(member);
238                 }
239             } catch (Throwable JavaDoc t) {
240                 System.err.println("getChampionsAsMembers throws " + t);
241             }
242         }
243
244         return champs;
245     }
246
247     public List JavaDoc getChampionsAsUsers() {
248         List JavaDoc champUsers = new ArrayList JavaDoc();
249         List JavaDoc champMembers = getChampionsAsMembers();
250         ProjectMember champ;
251         CoefficientUser user;
252
253         int i;
254
255         for (i = 0; i < champMembers.size(); i++) {
256             try {
257                 champ = (ProjectMember) (champMembers.get(i));
258                 user = champ.getCoefficientUser();
259                 champUsers.add(user);
260             } catch (Throwable JavaDoc t) {
261                 System.err.println("getChampionsAsUsers throws " + t);
262             }
263         }
264
265         return champUsers;
266     }
267
268     /**
269      * Sets the value of currentVersion
270      *
271      * @param argCurrentVersion Value to assign to this.currentVersion
272      */

273     public void setCurrentVersion(ProjectVersion currentVersion) {
274         this.currentVersion = currentVersion;
275     }
276
277     /**
278      * Gets the value of currentVersion
279      *
280      * @return the value of currentVersion
281      * @hibernate.many-to-one
282      * column="CURRENT_VERSION_ID"
283      */

284     public ProjectVersion getCurrentVersion() {
285         return this.currentVersion;
286     }
287
288     /**
289      * Sets the value of description
290      *
291      * @param argDescription Value to assign to this.description
292      */

293     public void setDescription(String JavaDoc description) {
294         this.description = description;
295     }
296
297     /**
298      * Gets the value of description
299      *
300      * @return the value of description
301      * @hibernate.property
302      * column="DESCRIPTION"
303      * length="3999"
304      */

305     public String JavaDoc getDescription() {
306         return this.description;
307     }
308
309     /**
310      * Sets the value of themeName
311      *
312      * @param argThemeName Value to assign to this.themeName
313      *
314      * NB: null or empty means use the installed theme
315      */

316     public void setThemeName(String JavaDoc themeName) {
317         this.themeName = themeName;
318     }
319
320     /**
321      * Gets the value of themeName
322      *
323      * @return the value of themeName
324      * @hibernate.property
325      * column="THEME_NAME"
326      * length="255"
327      */

328     public String JavaDoc getThemeName() {
329         return this.themeName;
330     }
331
332     /**
333      * Sets the value of homePage
334      *
335      * @param argHomePage Value to assign to this.homePage
336      */

337     public void setHomePage(String JavaDoc homePage) {
338         this.homePage = homePage;
339     }
340
341     /**
342      * Gets the value of homePage
343      *
344      * @return the value of homePage
345      * @hibernate.property
346      * column="HOMEPAGE"
347      */

348     public String JavaDoc getHomePage() {
349         return this.homePage;
350     }
351
352     /**
353      * Sets the value of id
354      *
355      * @param argId Value to assign to this.id
356      */

357     public void setId(Long JavaDoc argId) {
358         this.id = argId;
359     }
360
361     /**
362      * Gets the value of id
363      *
364      * @return the value of id
365      * @hibernate.id
366      * generator-class="native"
367      */

368     public Long JavaDoc getId() {
369         return this.id;
370     }
371
372     /**
373      * Sets the value of members
374      *
375      * @param argMembers Value to assign to this.members
376      */

377     public void setMembers(List JavaDoc argMembers) {
378         this.members = argMembers;
379     }
380
381     /**
382      * Gets the value of members
383      *
384      * @return the value of members
385      * @hibernate.list
386      * order-by="USERNAME"
387      * cascade="all"
388      * table="COEFFICIENT_PROJECT_MEMBERS"
389      * @hibernate.collection-key
390      * column="PROJECT_ID"
391      * @hibernate.collection-index
392      * column="IDX"
393      * @hibernate.collection-many-to-many
394      * class="za.org.coefficient.authentication.ProjectMember"
395      * column="MEMBERS"
396      */

397     public List JavaDoc getMembers() {
398         return this.members;
399     }
400
401     /**
402      * Sets the value of membersPending
403      *
404      * @param argMembers Value to assign to this.membersPending
405      */

406     public void setMembersPending(List JavaDoc argMembers) {
407         this.membersPending = argMembers;
408     }
409
410     /**
411      * Gets the value of membersPending
412      *
413      * @return the value of membersPending
414      * @hibernate.list
415      * order-by="USERNAME"
416      * cascade="none"
417      * table="COEFFICIENT_PROJECT_PENDING_MEMBERS"
418      * @hibernate.collection-key
419      * column="PROJECT_ID"
420      * @hibernate.collection-index
421      * column="IDX"
422      * @hibernate.collection-many-to-many
423      * class="za.org.coefficient.authentication.CoefficientUser"
424      * column="MEMBERS_PENDING"
425      */

426     public List JavaDoc getMembersPending() {
427         return this.membersPending;
428     }
429
430     /**
431      * Sets the value of modules
432      *
433      * @param modules Value to assign to this.modules
434      */

435     public void setModules(List JavaDoc modules) {
436         this.modules = modules;
437     }
438
439     /**
440      * Gets the value of modules
441      *
442      * @return the value of modules
443      * @hibernate.list
444      * cascade="all"
445      * table="COEFFICIENT_PROJECT_MODULES"
446      * @hibernate.collection-key
447      * column="PROJECT_ID"
448      * @hibernate.collection-index
449      * column="IDX"
450      * @hibernate.collection-element
451      * column="MODULES"
452      * type="string"
453      */

454     public List JavaDoc getModules() {
455         return this.modules;
456     }
457
458     /**
459      * Sets the value of versions
460      *
461      * @param versions Value to assign to this.versions
462      */

463     public void setVersions(List JavaDoc versions) {
464         this.versions = versions;
465     }
466
467     /**
468      * Gets the value of versions
469      *
470      * @return the value of versions
471      * @hibernate.list
472      * cascade="all"
473      * table="COEFFICIENT_PROJECT_VERSIONS"
474      * @hibernate.collection-key
475      * column="PROJECT_ID"
476      * @hibernate.collection-index
477      * column="IDX"
478      * @hibernate.collection-many-to-many
479      * class="za.org.coefficient.core.ProjectVersion"
480      * column="VERSIONS"
481      */

482     public List JavaDoc getVersions() {
483         return this.versions;
484     }
485
486     /**
487      * Sets the value of components
488      *
489      * @param components Value to assign to this.components
490      */

491     public void setComponents(List JavaDoc components) {
492         this.components = components;
493     }
494
495     /**
496      * Gets the value of components
497      *
498      * @return the value of components
499      * @hibernate.list
500      * cascade="all"
501      * table="COEFFICIENT_PROJECT_COMPONENTS"
502      * @hibernate.collection-key
503      * column="PROJECT_ID"
504      * @hibernate.collection-index
505      * column="IDX"
506      * @hibernate.collection-many-to-many
507      * class="za.org.coefficient.core.ProjectComponent"
508      * column="COMPONENTS"
509      */

510     public List JavaDoc getComponents() {
511         return this.components;
512     }
513
514     /**
515      * Sets the value of name
516      *
517      * @param argName Value to assign to this.name
518      */

519     public void setName(String JavaDoc name) {
520         this.name = name;
521     }
522
523     /**
524      * Gets the value of name
525      *
526      * @return the value of name
527      * @hibernate.property
528      * column="NAME"
529      */

530     public String JavaDoc getName() {
531         return this.name;
532     }
533
534     /**
535      * returns a list of project champions only
536      */

537     public List JavaDoc getNonChampionsAsMembers() {
538         List JavaDoc nonchamps = new ArrayList JavaDoc();
539
540         for (Iterator JavaDoc it = getMembers()
541                                .iterator(); it.hasNext();) {
542             ProjectMember member = (ProjectMember) it.next();
543             if (member.getProjectRole()
544                       .getRoleValue() != SecurityUtil.PROJECT_CHAMPION_ROLE_VAL) {
545                 nonchamps.add(member);
546             }
547         }
548
549         return nonchamps;
550     }
551
552     public List JavaDoc getNonChampionsAsUsers() {
553         List JavaDoc nonchampUsers = new ArrayList JavaDoc();
554
555         for (Iterator JavaDoc it = getNonChampionsAsMembers()
556                                .iterator(); it.hasNext();) {
557             ProjectMember nonchamp = (ProjectMember) it.next();
558             nonchampUsers.add(nonchamp.getCoefficientUser());
559         }
560
561         return nonchampUsers;
562     }
563
564     /**
565      * Sets the value of registration date
566      *
567      * @param registrationDate Value to assign to this.registrationDate
568      */

569     public void setRegistrationDate(Date JavaDoc registrationDate) {
570         this.registrationDate = registrationDate;
571     }
572
573     /**
574      * Gets the value of create date
575      *
576      * @return the value of create date
577      * @hibernate.property
578      * column="REGISTRATION_DATE"
579      */

580     public Date JavaDoc getRegistrationDate() {
581         return this.registrationDate;
582     }
583
584     /**
585      * Sets the value of statistics
586      *
587      * @param argStatistics Value to assign to this.statistics
588      */

589     public void setStatistics(ProjectStatistics statistics) {
590         this.statistics = statistics;
591     }
592
593     /**
594      * Gets the value of statistics
595      *
596      * @return the value of statistics
597      * @hibernate.many-to-one
598      * unique="true"
599      * column="STATISTICS_ID"
600      * cascade="delete"
601      */

602     public ProjectStatistics getStatistics() {
603         return this.statistics;
604     }
605
606     /**
607      * Sets the value of version
608      *
609      * @param version Value to assign to this.version
610      */

611     public void setVersion(long version) {
612         this.version = version;
613     }
614
615     /**
616      * Gets the value of version
617      *
618      * @return the value of version
619      * @hibernate.version
620      * column="VERSION"
621      * type="long"
622      */

623     public long getVersion() {
624         return this.version;
625     }
626
627     /**
628      * Sets the value of attributes
629      *
630      * @param attribute Value to add to the projects attributes
631      */

632     public void addAttribute(ProjectAttribute attribute) {
633         System.out.println("adding attribute " + attribute.getName()
634             + " to project ");
635         this.attributes.add(attribute.getId());
636
637         //this.attributes.add(attribute.getName());
638
}
639
640     /**
641      * Sets the value of attributeData
642      *
643      * @param attribute Value to add to the projects attributeData
644      */

645     public void addAttributeData(ProjectAttributeData pad) {
646         this.attributeData.add(pad);
647     }
648
649     /**
650      * Sets the value of categories
651      *
652      * @param cat Value to assign add to the projects categories
653      */

654     public void addCategory(Category cat) {
655         this.categories.add(cat);
656     }
657
658     public void addComponent(ProjectComponent component) {
659         this.components.add(component);
660     }
661
662     /**
663      * Adds the provided user to the projects members
664      *
665      * @param user Value to assign to the projects members
666      */

667     public void addMember(ProjectMember member) {
668         this.members.add(member);
669     }
670
671     public void addModule(String JavaDoc moduleName) {
672         this.modules.add(moduleName);
673     }
674
675     public void addVersion(ProjectVersion version) {
676         this.versions.add(version);
677     }
678
679     public boolean containsMember(ProjectMember member) {
680         return members.contains(member);
681     }
682
683     public boolean containsUser(CoefficientUser user) {
684         boolean retVal = false;
685         for (Iterator JavaDoc it = members.iterator(); it.hasNext();) {
686             ProjectMember pm = (ProjectMember) it.next();
687             if (pm.getCoefficientUser()
688                   .equals(user)) {
689                 retVal = true;
690
691                 break;
692             }
693         }
694
695         return retVal;
696     }
697
698     /**
699      * delete one attribute
700      *
701      * @param attribute Value to remove from the projects attributes
702      */

703     public void deleteAttribute(ProjectAttribute attribute) {
704         int idx = this.attributes.indexOf(attribute.getName());
705         if (idx != -1) {
706             this.attributes.remove(idx);
707         }
708     }
709
710     /**
711      * delete one attributeData
712      *
713      * @param attribute Value to remove from the projects attributeData
714      */

715     public void deleteAttributeData(ProjectAttributeData pad) {
716         int idx = this.attributeData.indexOf(pad);
717         if (idx != -1) {
718             this.attributeData.remove(idx);
719         }
720     }
721
722     /**
723      * Deletes the provided category from the projects categories
724      *
725      * @param user Value to remove from the projects categories
726      */

727     public void deleteCategory(Category cat) {
728         int idx = this.categories.indexOf(cat);
729         if (idx != -1) {
730             this.categories.remove(idx);
731         }
732     }
733
734     /**
735      * Deletes the provided user from the projects members
736      *
737      * @param user Value to remove from the projects members
738      */

739     public void deleteMember(ProjectMember member) {
740         int idx = this.members.indexOf(member);
741         if (idx != -1) {
742             this.members.remove(idx);
743         }
744     }
745
746     public void deleteModule(String JavaDoc moduleName) {
747         int idx = this.modules.indexOf(moduleName);
748         if (idx != -1) {
749             this.modules.remove(idx);
750         }
751     }
752
753     public void deleteVersion(ProjectVersion version) {
754         int idx = this.versions.indexOf(version);
755         if (idx != -1) {
756             this.versions.remove(idx);
757         }
758     }
759
760     public void updateVersion(ProjectVersion version) {
761         int idx = this.versions.indexOf(version);
762         if (idx != -1) {
763             this.versions.set(idx, version);
764         }
765     }
766
767     public void deleteComponent(ProjectComponent component) {
768         int idx = this.components.indexOf(component);
769         if (idx != -1) {
770             this.components.remove(idx);
771         }
772     }
773
774     public void updateComponent(ProjectComponent component) {
775         int idx = this.components.indexOf(component);
776         if (idx != -1) {
777             this.components.set(idx, component);
778         }
779     }
780     
781     /**
782      * Gets the value of shortName
783      *
784      * @return the value of shortName
785      * @hibernate.property
786      * column="SHORTNAME"
787      * not-null="true"
788      * unique="true"
789      */

790     public String JavaDoc getShortName() {
791         return shortName;
792     }
793     
794     public void setShortName(String JavaDoc string) {
795         shortName = string;
796     }
797
798 }
799
Popular Tags