001: /*
002: * Coefficient - facilitates project based collaboration
003: * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
004: * PO Box 395
005: * Pretoria 0001, RSA
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package za.org.coefficient.core;
021:
022: import za.org.coefficient.authentication.CoefficientUser;
023: import za.org.coefficient.authentication.ProjectMember;
024: import za.org.coefficient.authentication.Role;
025: import za.org.coefficient.statistics.data.ProjectStatistics;
026: import za.org.coefficient.util.ejb.SecurityUtil;
027:
028: import java.io.Serializable;
029:
030: import java.util.ArrayList;
031: import java.util.Date;
032: import java.util.Iterator;
033: import java.util.List;
034:
035: /**
036: * @hibernate.class
037: * table="COEFFICIENT_PROJECT"
038: */
039: public class Project implements Serializable {
040: //~ Instance fields ========================================================
041:
042: private Date registrationDate;
043: private List attributeData = new ArrayList();
044: private List attributes = new ArrayList();
045: private List categories = new ArrayList();
046: private List members = new ArrayList();
047: private List membersPending = new ArrayList();
048: private List modules = new ArrayList();
049: private List versions = new ArrayList();
050: private List components = new ArrayList();
051: private Long id;
052: private ProjectStatistics statistics;
053: private ProjectVersion currentVersion;
054: private String description;
055: private String homePage;
056: private String name;
057: private boolean active;
058: private long version;
059: private boolean isPublic;
060: private boolean isWorkflow;
061: private String themeName = null;
062: private String shortName = null;
063:
064: //~ Constructors ===========================================================
065:
066: public Project() {
067: registrationDate = new Date(System.currentTimeMillis());
068: isPublic = true;
069: isWorkflow = false;
070: }
071:
072: //~ Methods ================================================================
073:
074: /**
075: * Sets the value of active
076: *
077: * @param active Value to assign to this.active
078: */
079: public void setActive(boolean active) {
080: this .active = active;
081: }
082:
083: /**
084: * Gets the value of active
085: *
086: * @return the value of active
087: * @hibernate.property
088: * column="ACTIVE"
089: * not-null="true"
090: */
091: public boolean getActive() {
092: return this .active;
093: }
094:
095: /**
096: * Sets the value of isPublic
097: *
098: * @param public Value to assign to this.isPublic
099: */
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 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 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 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 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 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 getCategories() {
216: return this .categories;
217: }
218:
219: /**
220: * returns a list of project champions only
221: */
222: public List getChampionsAsMembers() {
223: List champs = new ArrayList();
224: List members = getMembers();
225: ProjectMember member;
226: Role role;
227: String 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 t) {
240: System.err.println("getChampionsAsMembers throws " + t);
241: }
242: }
243:
244: return champs;
245: }
246:
247: public List getChampionsAsUsers() {
248: List champUsers = new ArrayList();
249: List 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 getName() {
531: return this .name;
532: }
533:
534: /**
535: * returns a list of project champions only
536: */
537: public List getNonChampionsAsMembers() {
538: List nonchamps = new ArrayList();
539:
540: for (Iterator it = getMembers().iterator(); it.hasNext();) {
541: ProjectMember member = (ProjectMember) it.next();
542: if (member.getProjectRole().getRoleValue() != SecurityUtil.PROJECT_CHAMPION_ROLE_VAL) {
543: nonchamps.add(member);
544: }
545: }
546:
547: return nonchamps;
548: }
549:
550: public List getNonChampionsAsUsers() {
551: List nonchampUsers = new ArrayList();
552:
553: for (Iterator it = getNonChampionsAsMembers().iterator(); it
554: .hasNext();) {
555: ProjectMember nonchamp = (ProjectMember) it.next();
556: nonchampUsers.add(nonchamp.getCoefficientUser());
557: }
558:
559: return nonchampUsers;
560: }
561:
562: /**
563: * Sets the value of registration date
564: *
565: * @param registrationDate Value to assign to this.registrationDate
566: */
567: public void setRegistrationDate(Date registrationDate) {
568: this .registrationDate = registrationDate;
569: }
570:
571: /**
572: * Gets the value of create date
573: *
574: * @return the value of create date
575: * @hibernate.property
576: * column="REGISTRATION_DATE"
577: */
578: public Date getRegistrationDate() {
579: return this .registrationDate;
580: }
581:
582: /**
583: * Sets the value of statistics
584: *
585: * @param argStatistics Value to assign to this.statistics
586: */
587: public void setStatistics(ProjectStatistics statistics) {
588: this .statistics = statistics;
589: }
590:
591: /**
592: * Gets the value of statistics
593: *
594: * @return the value of statistics
595: * @hibernate.many-to-one
596: * unique="true"
597: * column="STATISTICS_ID"
598: * cascade="delete"
599: */
600: public ProjectStatistics getStatistics() {
601: return this .statistics;
602: }
603:
604: /**
605: * Sets the value of version
606: *
607: * @param version Value to assign to this.version
608: */
609: public void setVersion(long version) {
610: this .version = version;
611: }
612:
613: /**
614: * Gets the value of version
615: *
616: * @return the value of version
617: * @hibernate.version
618: * column="VERSION"
619: * type="long"
620: */
621: public long getVersion() {
622: return this .version;
623: }
624:
625: /**
626: * Sets the value of attributes
627: *
628: * @param attribute Value to add to the projects attributes
629: */
630: public void addAttribute(ProjectAttribute attribute) {
631: System.out.println("adding attribute " + attribute.getName()
632: + " to project ");
633: this .attributes.add(attribute.getId());
634:
635: //this.attributes.add(attribute.getName());
636: }
637:
638: /**
639: * Sets the value of attributeData
640: *
641: * @param attribute Value to add to the projects attributeData
642: */
643: public void addAttributeData(ProjectAttributeData pad) {
644: this .attributeData.add(pad);
645: }
646:
647: /**
648: * Sets the value of categories
649: *
650: * @param cat Value to assign add to the projects categories
651: */
652: public void addCategory(Category cat) {
653: this .categories.add(cat);
654: }
655:
656: public void addComponent(ProjectComponent component) {
657: this .components.add(component);
658: }
659:
660: /**
661: * Adds the provided user to the projects members
662: *
663: * @param user Value to assign to the projects members
664: */
665: public void addMember(ProjectMember member) {
666: this .members.add(member);
667: }
668:
669: public void addModule(String moduleName) {
670: this .modules.add(moduleName);
671: }
672:
673: public void addVersion(ProjectVersion version) {
674: this .versions.add(version);
675: }
676:
677: public boolean containsMember(ProjectMember member) {
678: return members.contains(member);
679: }
680:
681: public boolean containsUser(CoefficientUser user) {
682: boolean retVal = false;
683: for (Iterator it = members.iterator(); it.hasNext();) {
684: ProjectMember pm = (ProjectMember) it.next();
685: if (pm.getCoefficientUser().equals(user)) {
686: retVal = true;
687:
688: break;
689: }
690: }
691:
692: return retVal;
693: }
694:
695: /**
696: * delete one attribute
697: *
698: * @param attribute Value to remove from the projects attributes
699: */
700: public void deleteAttribute(ProjectAttribute attribute) {
701: int idx = this .attributes.indexOf(attribute.getName());
702: if (idx != -1) {
703: this .attributes.remove(idx);
704: }
705: }
706:
707: /**
708: * delete one attributeData
709: *
710: * @param attribute Value to remove from the projects attributeData
711: */
712: public void deleteAttributeData(ProjectAttributeData pad) {
713: int idx = this .attributeData.indexOf(pad);
714: if (idx != -1) {
715: this .attributeData.remove(idx);
716: }
717: }
718:
719: /**
720: * Deletes the provided category from the projects categories
721: *
722: * @param user Value to remove from the projects categories
723: */
724: public void deleteCategory(Category cat) {
725: int idx = this .categories.indexOf(cat);
726: if (idx != -1) {
727: this .categories.remove(idx);
728: }
729: }
730:
731: /**
732: * Deletes the provided user from the projects members
733: *
734: * @param user Value to remove from the projects members
735: */
736: public void deleteMember(ProjectMember member) {
737: int idx = this .members.indexOf(member);
738: if (idx != -1) {
739: this .members.remove(idx);
740: }
741: }
742:
743: public void deleteModule(String moduleName) {
744: int idx = this .modules.indexOf(moduleName);
745: if (idx != -1) {
746: this .modules.remove(idx);
747: }
748: }
749:
750: public void deleteVersion(ProjectVersion version) {
751: int idx = this .versions.indexOf(version);
752: if (idx != -1) {
753: this .versions.remove(idx);
754: }
755: }
756:
757: public void updateVersion(ProjectVersion version) {
758: int idx = this .versions.indexOf(version);
759: if (idx != -1) {
760: this .versions.set(idx, version);
761: }
762: }
763:
764: public void deleteComponent(ProjectComponent component) {
765: int idx = this .components.indexOf(component);
766: if (idx != -1) {
767: this .components.remove(idx);
768: }
769: }
770:
771: public void updateComponent(ProjectComponent component) {
772: int idx = this .components.indexOf(component);
773: if (idx != -1) {
774: this .components.set(idx, component);
775: }
776: }
777:
778: /**
779: * Gets the value of shortName
780: *
781: * @return the value of shortName
782: * @hibernate.property
783: * column="SHORTNAME"
784: * not-null="true"
785: * unique="true"
786: */
787: public String getShortName() {
788: return shortName;
789: }
790:
791: public void setShortName(String string) {
792: shortName = string;
793: }
794:
795: }
|