001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-hbm/src/java/org/sakaiproject/component/app/messageforums/dao/hibernate/TopicImpl.java $
003: * $Id: TopicImpl.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.component.app.messageforums.dao.hibernate;
021:
022: import java.util.Comparator;
023: import java.util.Date;
024: import java.util.HashSet;
025: import java.util.List;
026: import java.util.Set;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.sakaiproject.api.app.messageforums.Attachment;
031: import org.sakaiproject.api.app.messageforums.BaseForum;
032: import org.sakaiproject.api.app.messageforums.DBMembershipItem;
033: import org.sakaiproject.api.app.messageforums.Message;
034: import org.sakaiproject.api.app.messageforums.OpenForum;
035: import org.sakaiproject.api.app.messageforums.PermissionLevel;
036: import org.sakaiproject.api.app.messageforums.PrivateForum;
037: import org.sakaiproject.api.app.messageforums.Topic;
038:
039: public abstract class TopicImpl extends MutableEntityImpl implements
040: Topic {
041:
042: private static final Log LOG = LogFactory.getLog(TopicImpl.class);
043:
044: private String title;
045: private String shortDescription;
046: private String extendedDescription;
047: private Set attachmentsSet;// = new HashSet();
048: private Boolean mutable;
049: private Integer sortIndex;
050: private String typeUuid;
051: private BaseForum baseForum;
052: private Set messagesSet;// = new HashSet();
053: private Set membershipItemSet;
054: private String defaultAssignName;
055: private Boolean moderated;
056:
057: // foreign keys for hibernate
058: private PrivateForum privateForum;
059: private OpenForum openForum;
060:
061: // indecies for hibernate
062: //private int ofindex;
063: //private int pfindex;
064:
065: public List getMessages() {
066: return Util.setToList(messagesSet);
067: }
068:
069: public void setMessages(List messages) {
070: this .messagesSet = Util.listToSet(messages);
071: }
072:
073: public Set getMessagesSet() {
074: return messagesSet;
075: }
076:
077: public void setMessagesSet(Set messagesSet) {
078: this .messagesSet = messagesSet;
079: }
080:
081: public Set getAttachmentsSet() {
082: return attachmentsSet;
083: }
084:
085: public void setAttachmentsSet(Set attachmentsSet) {
086: this .attachmentsSet = attachmentsSet;
087: }
088:
089: public List getAttachments() {
090: return Util.setToList(attachmentsSet);
091: }
092:
093: public void setAttachments(List attachments) {
094: this .attachmentsSet = Util.listToSet(attachments);
095: }
096:
097: public Set getMembershipItemSet() {
098: return membershipItemSet;
099: }
100:
101: public void setMembershipItemSet(Set membershipItemSet) {
102: this .membershipItemSet = membershipItemSet;
103: }
104:
105: public String getExtendedDescription() {
106: return extendedDescription;
107: }
108:
109: public void setExtendedDescription(String extendedDescription) {
110: this .extendedDescription = extendedDescription;
111: }
112:
113: public Boolean getMutable() {
114: return mutable;
115: }
116:
117: public void setMutable(Boolean mutable) {
118: this .mutable = mutable;
119: }
120:
121: public String getShortDescription() {
122: return shortDescription;
123: }
124:
125: public void setShortDescription(String shortDescription) {
126: this .shortDescription = shortDescription;
127: }
128:
129: public Integer getSortIndex() {
130: return sortIndex;
131: }
132:
133: public void setSortIndex(Integer sortIndex) {
134: this .sortIndex = sortIndex;
135: }
136:
137: public String getTitle() {
138: return title;
139: }
140:
141: public void setTitle(String title) {
142: this .title = title;
143: }
144:
145: public String getTypeUuid() {
146: return typeUuid;
147: }
148:
149: public void setTypeUuid(String typeUuid) {
150: this .typeUuid = typeUuid;
151: }
152:
153: public BaseForum getBaseForum() {
154: return baseForum;
155: }
156:
157: public void setBaseForum(BaseForum forum) {
158: this .baseForum = forum;
159: }
160:
161: public OpenForum getOpenForum() {
162: return openForum;
163: }
164:
165: public void setOpenForum(OpenForum openForum) {
166: this .openForum = openForum;
167: }
168:
169: public PrivateForum getPrivateForum() {
170: return privateForum;
171: }
172:
173: public void setPrivateForum(PrivateForum privateForum) {
174: this .privateForum = privateForum;
175: }
176:
177: public Boolean getModerated() {
178: return moderated;
179: }
180:
181: public void setModerated(Boolean moderated) {
182: this .moderated = moderated;
183: }
184:
185: // public int getOfindex() {
186: // try {
187: // return getOpenForum().getTopics().indexOf(this);
188: // } catch (Exception e) {
189: // return ofindex;
190: // }
191: // }
192: //
193: // public void setOfindex(int ofindex) {
194: // this.ofindex = ofindex;
195: // }
196: //
197: // public int getPfindex() {
198: // try {
199: // return getPrivateForum().getTopics().indexOf(this);
200: // } catch (Exception e) {
201: // return pfindex;
202: // }
203: // }
204: //
205: // public void setPfindex(int pfindex) {
206: // this.pfindex = pfindex;
207: // }
208:
209: public String toString() {
210: return "Topic/" + id;
211: //return "Topic.id:" + id;
212: }
213:
214: public boolean equals(Object obj) {
215: if (obj != null && obj instanceof Topic) {
216: return getId().equals(((Topic) obj).getId());
217: }
218: return false;
219: }
220:
221: // needs a better impl
222: public int hashCode() {
223: return getId() == null ? 0 : getId().hashCode();
224: }
225:
226: ////////////////////////////////////////////////////////////////////////
227: // helper methods for collections
228: ////////////////////////////////////////////////////////////////////////
229:
230: public void addMessage(Message message) {
231: if (LOG.isDebugEnabled()) {
232: LOG.debug("addForum(message " + message + ")");
233: }
234:
235: if (message == null) {
236: throw new IllegalArgumentException("message == null");
237: }
238:
239: if (messagesSet == null) {
240: messagesSet = new HashSet();
241: }
242: message.setTopic(this );
243: messagesSet.add(message);
244: }
245:
246: public void removeMessage(Message message) {
247: if (LOG.isDebugEnabled()) {
248: LOG.debug("removeForum(message " + message + ")");
249: }
250:
251: if (message == null) {
252: throw new IllegalArgumentException(
253: "Illegal message argument passed!");
254: }
255:
256: message.setTopic(null);
257: messagesSet.remove(message);
258: }
259:
260: public void addAttachment(Attachment attachment) {
261: if (LOG.isDebugEnabled()) {
262: LOG.debug("addAttachment(Attachment " + attachment + ")");
263: }
264:
265: if (attachment == null) {
266: throw new IllegalArgumentException("attachment == null");
267: }
268:
269: if (attachmentsSet == null) {
270: attachmentsSet = new HashSet();
271: }
272: attachment.setTopic(this );
273: attachmentsSet.add(attachment);
274: }
275:
276: public void removeAttachment(Attachment attachment) {
277: if (LOG.isDebugEnabled()) {
278: LOG
279: .debug("removeAttachment(Attachment " + attachment
280: + ")");
281: }
282:
283: if (attachment == null) {
284: throw new IllegalArgumentException(
285: "Illegal attachment argument passed!");
286: }
287:
288: attachment.setTopic(null);
289: attachmentsSet.remove(attachment);
290: }
291:
292: public void addMembershipItem(DBMembershipItem item) {
293: if (LOG.isDebugEnabled()) {
294: LOG.debug("addMembershipItem(item " + item + ")");
295: }
296:
297: if (item == null) {
298: throw new IllegalArgumentException("item == null");
299: }
300:
301: if (membershipItemSet == null) {
302: membershipItemSet = new HashSet();
303: }
304: membershipItemSet.add(item);
305: }
306:
307: public void removeMembershipItem(DBMembershipItem item) {
308: if (LOG.isDebugEnabled()) {
309: LOG.debug("removeMembershipItem(item " + item + ")");
310: }
311:
312: if (item == null) {
313: throw new IllegalArgumentException(
314: "Illegal level argument passed!");
315: }
316:
317: membershipItemSet.remove(item);
318: }
319:
320: public String getDefaultAssignName() {
321: return defaultAssignName;
322: }
323:
324: public void setDefaultAssignName(String defaultAssignName) {
325: this.defaultAssignName = defaultAssignName;
326: }
327:
328: }
|