001: package com.technoetic.xplanner.domain;
002:
003: import java.util.Date;
004: import java.util.List;
005:
006: import com.technoetic.xplanner.db.hibernate.ThreadSession;
007: import com.technoetic.xplanner.file.File;
008: import com.technoetic.xplanner.tags.DomainContext;
009: import net.sf.hibernate.HibernateException;
010:
011: public class Note extends DomainObject implements Nameable {
012: private int attachedToId;
013: private int authorId;
014: private String subject;
015: private String body;
016: private Date submissionTime = new Date();
017: private File file;
018: public static final String ATTACHED_NOTES_QUERY = "AttachedNotesQuery";
019:
020: public void setAttachedToId(int attachedToId) {
021: this .attachedToId = attachedToId;
022: }
023:
024: public int getAttachedToId() {
025: return attachedToId;
026: }
027:
028: public void setAuthorId(int authorId) {
029: this .authorId = authorId;
030: }
031:
032: public int getAuthorId() {
033: return authorId;
034: }
035:
036: public void setSubject(String subject) {
037: this .subject = subject;
038: }
039:
040: public String getSubject() {
041: return subject;
042: }
043:
044: public void setBody(String body) {
045: this .body = body;
046: }
047:
048: public String getBody() {
049: return body;
050: }
051:
052: public void setFile(File file) {
053: this .file = file;
054: }
055:
056: public File getFile() {
057: return file;
058: }
059:
060: public void setSubmissionTime(Date submissionTime) {
061: this .submissionTime = submissionTime;
062: }
063:
064: public Date getSubmissionTime() {
065: return submissionTime;
066: }
067:
068: public boolean equals(Object o) {
069: if (this == o)
070: return true;
071: if (!(o instanceof Note))
072: return false;
073: //todo Get rid of this hack checking id == 0. Jacques will add an abstract fieldsEquals member to DomainObject that all inheriting classes will implement.
074: if (getId() != 0 && !super .equals(o))
075: return false;
076:
077: final Note note = (Note) o;
078:
079: if (attachedToId != note.attachedToId)
080: return false;
081: if (authorId != note.authorId)
082: return false;
083: if (body != null ? !body.equals(note.body) : note.body != null)
084: return false;
085: if (file != null ? isFilenameEqual(note.file)
086: : note.file != null)
087: return false;
088: if (subject != null ? !subject.equals(note.subject)
089: : note.subject != null)
090: return false;
091: return !(submissionTime != null ? !submissionTime
092: .equals(note.submissionTime)
093: : note.submissionTime != null);
094:
095: }
096:
097: private boolean isFilenameEqual(File otherFile) {
098: return otherFile != null && file.getName() != null ? !file
099: .getName().equals(otherFile.getName()) : false;
100: }
101:
102: public String toString() {
103: StringBuffer sb = new StringBuffer();
104: sb.append("Note - ");
105: sb.append("filename: "
106: + (file != null ? file.getName() : "none") + "\n");
107: sb.append("file: " + file + "\n");
108: sb.append("attachedToId: " + attachedToId + "\n");
109: sb.append("authorId: " + authorId + "\n");
110: sb.append("body: " + body + "\n");
111: sb.append("subject: " + subject + "\n");
112: sb.append("submissionTime: " + submissionTime + "\n");
113:
114: return sb.toString();
115: }
116:
117: public String getName() {
118: return getSubject();
119: }
120:
121: public String getDescription() {
122: return getBody();
123: }
124:
125: public int getAttachmentCount() throws HibernateException {
126: List noteList = null;
127: noteList = ThreadSession.get().find(
128: "select note from Note note where note.file.id="
129: + this .getFile().getId());
130: if (noteList != null) {
131: return noteList.size();
132: } else {
133: return 0;
134: }
135: }
136:
137: public DomainObject getParent() {
138: //DEBT: Remove the cycle. Note should not depends on a web tier operation
139: return DomainContext.getNoteTarget(getAttachedToId());
140: }
141: }
|