001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-app/src/java/org/sakaiproject/tool/messageforums/ui/DiscussionMessageBean.java $
003: * $Id: DiscussionMessageBean.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006, 2007 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.tool.messageforums.ui;
021:
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import org.sakaiproject.api.app.messageforums.Attachment;
026: import org.sakaiproject.api.app.messageforums.Message;
027:
028: import org.sakaiproject.component.cover.ComponentManager;
029: import org.sakaiproject.tool.cover.SessionManager;
030: import org.sakaiproject.api.app.messageforums.MessageForumsMessageManager;
031:
032: /**
033: * @author <a href="mailto:rshastri@iupui.edu">Rashmi Shastri</a>
034: * @author Chen Wen
035: *
036: */
037: public class DiscussionMessageBean {
038: private boolean selected;
039: private Message message;
040: private boolean read;
041: private int depth;
042: private boolean hasNext;
043: private boolean hasPre;
044: private boolean hasChild;
045: private int childUnread;
046: private int childCount;
047: private boolean hasNextThread;
048: private boolean hasPreThread;
049: private long nextThreadId;
050: private long preThreadId;
051: private String parentTopicTitle;
052: private String parentForumTitle;
053: private boolean revise;
054:
055: private MessageForumsMessageManager messageManager;
056:
057: public DiscussionMessageBean(Message msg,
058: MessageForumsMessageManager messageManager) {
059: this .message = msg;
060: this .messageManager = messageManager;
061: }
062:
063: /**
064: * @return Returns the selected.
065: */
066: public boolean isSelected() {
067: return selected;
068: }
069:
070: /**
071: * @param selected The selected to set.
072: */
073: public void setSelected(boolean selected) {
074: this .selected = selected;
075: }
076:
077: /**
078: * @return Returns the msg.
079: */
080: public Message getMessage() {
081: return message;
082: }
083:
084: /**
085: * @return Returns the hasAttachment.
086: */
087: public boolean isHasAttachment() {
088: if (message == null) {
089: return false;
090: }
091: message = messageManager.getMessageByIdWithAttachments(message
092: .getId());
093: if (message.getAttachments() == null) {
094: return false;
095: } else if (message.getAttachments().size() > 0) {
096: return true;
097: }
098: /* else (changed after not lazy loading attachments.)
099: {
100: MessageForumsMessageManager mfmm =
101: (org.sakaiproject.api.app.messageforums.MessageForumsMessageManager)ComponentManager.get("org.sakaiproject.api.app.messageforums.MessageForumsMessageManager");
102: Message messageWithAttach = mfmm.getMessageByIdWithAttachments(message.getId());
103: if(messageWithAttach != null)
104: {
105: if(messageWithAttach.getAttachments().size()>0)
106: return true;
107: }
108: }*/
109: return false;
110: }
111:
112: /**
113: * @return Returns the read.
114: */
115: public boolean isRead() {
116: return read;
117: }
118:
119: /**
120: * @param read The read to set.
121: */
122: public void setRead(boolean read) {
123: this .read = read;
124: }
125:
126: public void setDepth(int depth) {
127: this .depth = depth;
128: }
129:
130: public int getDepth() {
131: return depth;
132: }
133:
134: /**
135: * @return Returns the hasNext.
136: */
137: public boolean getHasNext() {
138: return hasNext;
139: }
140:
141: /**
142: * @param hasNext The hasNext to set.
143: */
144: public void setHasNext(boolean hasNext) {
145: this .hasNext = hasNext;
146: }
147:
148: /**
149: * @return Returns the hasPre.
150: */
151: public boolean getHasPre() {
152: return hasPre;
153: }
154:
155: /**
156: * @param hasPre The hasPre to set.
157: */
158: public void setHasPre(boolean hasPre) {
159: this .hasPre = hasPre;
160: }
161:
162: public boolean getIsOwn() {
163: if (this .getMessage().getCreatedBy().equals(
164: SessionManager.getCurrentSessionUserId()))
165: return true;
166: return false;
167: }
168:
169: public void setHasChild(boolean hasChild) {
170: this .hasChild = hasChild;
171: }
172:
173: public boolean getHasChild() {
174: List childList = messageManager.getFirstLevelChildMsgs(this
175: .getMessage().getId());
176: if ((childList != null) && (childList.size() > 0))
177: hasChild = true;
178: else
179: hasChild = false;
180:
181: return hasChild;
182: }
183:
184: public ArrayList getAttachList() {
185: ArrayList decoAttachList = new ArrayList();
186: List attachList = message.getAttachments();
187: if (attachList != null) {
188: for (int i = 0; i < attachList.size(); i++) {
189: DecoratedAttachment decoAttach = new DecoratedAttachment(
190: (Attachment) attachList.get(i));
191: decoAttachList.add(decoAttach);
192: }
193: }
194: return decoAttachList;
195: }
196:
197: public int getChildUnread() {
198: return childUnread;
199: }
200:
201: public void setChildUnread(int newValue) {
202: childUnread = newValue;
203: }
204:
205: public int getChildCount() {
206: return childCount;
207: }
208:
209: public void setChildCount(int newValue) {
210: childCount = newValue;
211: }
212:
213: public boolean getHasNextThread() {
214: return hasNextThread;
215: }
216:
217: public void setHasNextThread(boolean newValue) {
218: hasNextThread = newValue;
219: }
220:
221: public boolean getHasPreThread() {
222: return hasPreThread;
223: }
224:
225: public void setHasPreThread(boolean newValue) {
226: hasPreThread = newValue;
227: }
228:
229: public long getNextThreadId() {
230: return nextThreadId;
231: }
232:
233: public void setNextThreadId(long newValue) {
234: nextThreadId = newValue;
235: }
236:
237: public long getPreThreadId() {
238: return preThreadId;
239: }
240:
241: public void setPreThreadId(long newValue) {
242: preThreadId = newValue;
243: }
244:
245: /**
246: * returns true if message has been approved
247: * @return
248: */
249: public boolean isMsgApproved() {
250: return message.getApproved() == Boolean.TRUE;
251: }
252:
253: /**
254: * returns true if message has approval pending
255: * @return
256: */
257: public boolean isMsgPending() {
258: return message.getApproved() == null;
259: }
260:
261: /**
262: * returns true if message was denied
263: * @return
264: */
265: public boolean isMsgDenied() {
266: return message.getApproved() == Boolean.FALSE;
267: }
268:
269: public void setRevise(boolean revise) {
270: this .revise = revise;
271: }
272:
273: public boolean getRevise() {
274: return this.revise;
275: }
276: }
|