001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-app/src/java/org/sakaiproject/tool/messageforums/ui/DiscussionTopicBean.java $
003: * $Id: DiscussionTopicBean.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.Iterator;
024: import java.util.List;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.sakaiproject.api.app.messageforums.Attachment;
029: import org.sakaiproject.api.app.messageforums.DiscussionForum;
030: import org.sakaiproject.api.app.messageforums.DiscussionTopic;
031: import org.sakaiproject.api.app.messageforums.Message;
032: import org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager;
033: import org.sakaiproject.api.app.messageforums.ui.UIPermissionsManager;
034:
035: /**
036: * @author <a href="mailto:rshastri@iupui.edu">Rashmi Shastri</a>
037: * @author Chen Wen
038: */
039: public class DiscussionTopicBean {
040: private static final Log LOG = LogFactory
041: .getLog(DiscussionForumBean.class);
042: private DiscussionTopic topic;
043: private int totalNoMessages;
044: private int unreadNoMessages;
045: private boolean hasNextTopic;
046: private boolean hasPreviousTopic;
047: private Long nextTopicId;
048: private Long previousTopicId;
049: private boolean readFullDesciption;
050: private boolean markForDeletion;
051: private UIPermissionsManager uiPermissionsManager;
052: private DiscussionForumManager forumManager;
053: private ArrayList contributorsList = new ArrayList();
054: private ArrayList accessorList = new ArrayList();
055: private String gradeAssign;
056: private boolean nonePermission = true;
057:
058: private List messages = new ArrayList();
059:
060: public DiscussionTopicBean(DiscussionTopic topic,
061: DiscussionForum forum,
062: UIPermissionsManager uiPermissionsManager,
063: DiscussionForumManager forumManager) {
064: this .topic = topic;
065: this .uiPermissionsManager = uiPermissionsManager;
066: this .topic.setBaseForum(forum);
067: this .forumManager = forumManager;
068: }
069:
070: /**
071: * @return
072: */
073: public DiscussionTopic getTopic() {
074:
075: return topic;
076: }
077:
078: /**
079: * @return
080: */
081: public int getTotalNoMessages() {
082: return totalNoMessages;
083: }
084:
085: /**
086: * @param totalMessages
087: */
088: public void setTotalNoMessages(int totalMessages) {
089: this .totalNoMessages = totalMessages;
090: }
091:
092: /**
093: * @return
094: */
095: public int getUnreadNoMessages() {
096: return unreadNoMessages;
097: }
098:
099: /**
100: * @param unreadMessages
101: */
102: public void setUnreadNoMessages(int unreadMessages) {
103: this .unreadNoMessages = unreadMessages;
104: }
105:
106: /**
107: * @return Returns the hasNextTopic.
108: */
109: public boolean isHasNextTopic() {
110: return hasNextTopic;
111: }
112:
113: /**
114: * @param hasNextTopic
115: * The hasNextTopic to set.
116: */
117: public void setHasNextTopic(boolean hasNextTopic) {
118: this .hasNextTopic = hasNextTopic;
119: }
120:
121: /**
122: * @return Returns the hasPreviousTopic.
123: */
124: public boolean isHasPreviousTopic() {
125: return hasPreviousTopic;
126: }
127:
128: /**
129: * @param hasPreviousTopic
130: * The hasPreviousTopic to set.
131: */
132: public void setHasPreviousTopic(boolean hasPreviousTopic) {
133: this .hasPreviousTopic = hasPreviousTopic;
134: }
135:
136: /**
137: * @return Returns the nextTopicId.
138: */
139: public Long getNextTopicId() {
140: return nextTopicId;
141: }
142:
143: /**
144: * @param nextTopicId
145: * The nextTopicId to set.
146: */
147: public void setNextTopicId(Long nextTopicId) {
148: this .nextTopicId = nextTopicId;
149: }
150:
151: /**
152: * @return Returns the previousTopicId.
153: */
154: public Long getPreviousTopicId() {
155: return previousTopicId;
156: }
157:
158: /**
159: * @param previousTopicId
160: * The previousTopicId to set.
161: */
162: public void setPreviousTopicId(Long previousTopicId) {
163: this .previousTopicId = previousTopicId;
164: }
165:
166: /**
167: * @return Returns the decorated messages.
168: */
169: public List getMessages() {
170: return messages;
171: }
172:
173: public void setMessages(List messages) {
174: if (LOG.isDebugEnabled()) {
175: LOG.debug("setMessages(List" + messages + ")");
176: }
177: this .messages = messages;
178: }
179:
180: public void addMessage(DiscussionMessageBean decoMessage) {
181: if (LOG.isDebugEnabled()) {
182: LOG.debug("addMessage(DiscussionMessageBean" + decoMessage
183: + ")");
184: }
185: if (!messages.contains(decoMessage)) {
186: messages.add(decoMessage);
187: }
188: }
189:
190: public void insertMessage(DiscussionMessageBean decoMessage) {
191: if (LOG.isDebugEnabled()) {
192: LOG.debug("insertMessage(DiscussionMessageBean"
193: + decoMessage + ")");
194: }
195: if (!messages.contains(decoMessage)) {
196: messages.add(0, decoMessage);
197: }
198: }
199:
200: /**
201: * @return Returns the if ExtendedDesciption is available
202: */
203: public boolean getHasExtendedDesciption() {
204: LOG.debug("getHasExtendedDesciption()");
205: if (topic.getExtendedDescription() != null
206: && topic.getExtendedDescription().trim().length() > 0
207: && (!readFullDesciption)) {
208: return true;
209: }
210: return false;
211: }
212:
213: /**
214: * @return Returns the readFullDesciption.
215: */
216: public boolean isReadFullDesciption() {
217: LOG.debug("isReadFullDesciption()");
218: return readFullDesciption;
219: }
220:
221: /**
222: * @param readFullDesciption
223: * The readFullDesciption to set.
224: */
225: public void setReadFullDesciption(boolean readFullDesciption) {
226: if (LOG.isDebugEnabled()) {
227: LOG.debug("setReadFullDesciption(boolean "
228: + readFullDesciption + ")");
229: }
230: this .readFullDesciption = readFullDesciption;
231: }
232:
233: /**
234: * @return Returns the parentForumId.
235: */
236: public String getParentForumId() {
237: LOG.debug("getParentForumId()");
238: return topic.getBaseForum().getId().toString();
239: }
240:
241: /**
242: * @return Returns the mustRespondBeforeReading.
243: */
244: public String getMustRespondBeforeReading() {
245: LOG.debug("getMustRespondBeforeReading()");
246: if (topic == null
247: || topic.getMustRespondBeforeReading() == null
248: || topic.getMustRespondBeforeReading().booleanValue() == false) {
249: return Boolean.FALSE.toString();
250: }
251: return Boolean.TRUE.toString();
252: }
253:
254: /**
255: * @param mustRespondBeforeReading
256: */
257: public void setMustRespondBeforeReading(
258: String mustRespondBeforeReading) {
259: if (LOG.isDebugEnabled()) {
260: LOG.debug("setMustRespondBeforeReading(String"
261: + mustRespondBeforeReading + ")");
262: }
263: if (mustRespondBeforeReading.equals(Boolean.TRUE.toString())) {
264: topic.setMustRespondBeforeReading(new Boolean(true));
265: } else {
266: topic.setMustRespondBeforeReading(new Boolean(false));
267: }
268: }
269:
270: /**
271: * @return Returns the locked.
272: */
273: public String getLocked() {
274: LOG.debug("getLocked()");
275: if (topic == null || topic.getLocked() == null
276: || topic.getLocked().booleanValue() == false) {
277: return Boolean.FALSE.toString();
278: }
279: return Boolean.TRUE.toString();
280: }
281:
282: /**
283: * @param locked
284: * The locked to set.
285: */
286: public void setLocked(String locked) {
287: if (LOG.isDebugEnabled()) {
288: LOG.debug("setLocked(String " + locked + ")");
289: }
290: if (locked.equals(Boolean.TRUE.toString())) {
291: topic.setLocked(new Boolean(true));
292: } else {
293: topic.setLocked(new Boolean(false));
294: }
295: }
296:
297: /**
298: * returns topic moderated status
299: * @return
300: */
301: public boolean isTopicModerated() {
302: return topic.getModerated().booleanValue();
303: }
304:
305: /**
306: * @return Returns the moderated status.
307: */
308: public String getModerated() {
309: LOG.debug("getModerated()");
310: if (topic == null || topic.getModerated() == null
311: || topic.getModerated().booleanValue() == false) {
312: return Boolean.FALSE.toString();
313: }
314: return Boolean.TRUE.toString();
315: }
316:
317: /**
318: * @param moderated
319: * Set the moderated status.
320: */
321: public void setModerated(String moderated) {
322: if (LOG.isDebugEnabled()) {
323: LOG.debug("setModerated(String " + moderated + ")");
324: }
325: if (moderated.equals(Boolean.TRUE.toString())) {
326: topic.setModerated(new Boolean(true));
327: } else {
328: topic.setModerated(new Boolean(false));
329: }
330: }
331:
332: public void removeMessage(DiscussionMessageBean decoMessage) {
333: if (LOG.isDebugEnabled()) {
334: LOG.debug("removeMessage(DiscussionMessageBean"
335: + decoMessage + ")");
336: }
337: for (int i = 0; i < messages.size(); i++) {
338: if (((DiscussionMessageBean) messages.get(i)).getMessage()
339: .getId().equals(decoMessage.getMessage().getId())) {
340: messages.remove(i);
341: break;
342: }
343: }
344: }
345:
346: /**
347: * @return Returns the markForDeletion.
348: */
349: public boolean isMarkForDeletion() {
350: LOG.debug("isMarkForDeletion()");
351: return markForDeletion;
352: }
353:
354: /**
355: * @param markForDeletion
356: * The markForDeletion to set.
357: */
358: public void setMarkForDeletion(boolean markForDeletion) {
359: if (LOG.isDebugEnabled()) {
360: LOG.debug("setMarkForDeletion(boolean " + markForDeletion
361: + ")");
362: }
363: this .markForDeletion = markForDeletion;
364: }
365:
366: /**
367: * @param topic
368: */
369: public void setTopic(DiscussionTopic topic) {
370: if (LOG.isDebugEnabled()) {
371: LOG.debug("setTopic(DiscussionTopic" + topic + ")");
372: }
373: this .topic = topic;
374: }
375:
376: /**
377: * @return
378: */
379: public boolean getIsNewResponse() {
380: LOG.debug("getIsNewResponse()");
381: return uiPermissionsManager.isNewResponse(topic,
382: (DiscussionForum) topic.getBaseForum());
383: }
384:
385: /**
386: * @return
387: */
388: public boolean getIsNewResponseToResponse() {
389: LOG.debug("getIsNewResponseToResponse()");
390: return uiPermissionsManager.isNewResponseToResponse(topic,
391: (DiscussionForum) topic.getBaseForum());
392: }
393:
394: /**
395: * @return
396: */
397: public boolean getIsMovePostings() {
398: LOG.debug("getIsMovePostings()");
399: return uiPermissionsManager.isMovePostings(topic,
400: (DiscussionForum) topic.getBaseForum());
401: }
402:
403: /**
404: * @return
405: */
406: public boolean isChangeSettings() {
407: LOG.debug("isChangeSettings()");
408: return uiPermissionsManager.isChangeSettings(topic,
409: (DiscussionForum) topic.getBaseForum());
410: }
411:
412: /**
413: * @return
414: */
415: public boolean isPostToGradebook() {
416: LOG.debug("isPostToGradebook()");
417: return uiPermissionsManager.isPostToGradebook(topic,
418: (DiscussionForum) topic.getBaseForum());
419: }
420:
421: public boolean getIsPostToGradebook() {
422: LOG.debug("getIsPostToGradebook()");
423: return isPostToGradebook();
424: }
425:
426: /**
427: * @return
428: */
429: public boolean getIsRead() {
430: LOG.debug("getIsRead()");
431: return uiPermissionsManager.isRead(topic,
432: (DiscussionForum) topic.getBaseForum());
433: }
434:
435: /**
436: * @return
437: */
438: public boolean getIsReviseAny() {
439: LOG.debug("getIsReviseAny()");
440: return uiPermissionsManager.isReviseAny(topic,
441: (DiscussionForum) topic.getBaseForum());
442: }
443:
444: /**
445: * @return
446: */
447: public boolean getIsReviseOwn() {
448: LOG.debug("getIsReviseOwn()");
449: return uiPermissionsManager.isReviseOwn(topic,
450: (DiscussionForum) topic.getBaseForum());
451: }
452:
453: /**
454: * @return
455: */
456: public boolean getIsDeleteAny() {
457: LOG.debug("getIsDeleteAny()");
458: return uiPermissionsManager.isDeleteAny(topic,
459: (DiscussionForum) topic.getBaseForum());
460: }
461:
462: /**
463: * @return
464: */
465: public boolean getIsDeleteOwn() {
466: LOG.debug("getIsDeleteOwn()");
467: return uiPermissionsManager.isDeleteOwn(topic,
468: (DiscussionForum) topic.getBaseForum());
469: }
470:
471: /**
472: * @return
473: */
474: public boolean getIsMarkAsRead() {
475: LOG.debug("getIsMarkAsRead()");
476: return uiPermissionsManager.isMarkAsRead(topic,
477: (DiscussionForum) topic.getBaseForum());
478: }
479:
480: public boolean getIsModeratedAndHasPerm() {
481: LOG.debug("getIsModeratedAndHasPerm()");
482: return topic.getModerated().booleanValue()
483: && uiPermissionsManager.isModeratePostings(topic,
484: (DiscussionForum) topic.getBaseForum());
485: }
486:
487: /**
488: * @return
489: */
490: public ArrayList getContributorsList() {
491: LOG.debug("getContributorsList()");
492: Iterator iter = forumManager.getContributorsList(topic,
493: (DiscussionForum) topic.getBaseForum()).iterator();
494: while (iter.hasNext()) {
495: contributorsList.add((String) iter.next());
496: }
497: return contributorsList;
498:
499: }
500:
501: /**
502: * @return
503: */
504: public ArrayList getAccessorList() {
505: LOG.debug("getAccessorList()");
506: Iterator iter = forumManager.getAccessorsList(topic,
507: (DiscussionForum) topic.getBaseForum()).iterator();
508: while (iter.hasNext()) {
509: accessorList.add((String) iter.next());
510: }
511: return accessorList;
512: }
513:
514: /**
515: * @param accessorList The accessorList to set.
516: */
517: public void setAccessorList(ArrayList accessorList) {
518: if (LOG.isDebugEnabled()) {
519: LOG.debug("setAccessorList(List" + accessorList + ")");
520: }
521: topic.getActorPermissions().setAccessors(
522: forumManager.decodeAccessorsList(accessorList));
523: }
524:
525: /**
526: * @param contributorsList The contributorsList to set.
527: */
528: public void setContributorsList(ArrayList contributorsList) {
529: if (LOG.isDebugEnabled()) {
530: LOG.debug("setContributorsList(List" + contributorsList
531: + ")");
532: }
533: topic.getActorPermissions().setContributors(
534: forumManager.decodeContributorsList(contributorsList));
535: }
536:
537: public String getGradeAssign() {
538: return gradeAssign;
539: }
540:
541: public void setGradeAssign(String gradeAssign) {
542: this .gradeAssign = gradeAssign;
543: }
544:
545: public boolean getNonePermission() {
546: nonePermission = true;
547: /* if(uiPermissionsManager.isChangeSettings(topic, (DiscussionForum)topic.getBaseForum())
548: || uiPermissionsManager.isDeleteAny(topic, (DiscussionForum)topic.getBaseForum())
549: || uiPermissionsManager.isDeleteOwn(topic, (DiscussionForum)topic.getBaseForum())
550: || uiPermissionsManager.isMarkAsRead(topic, (DiscussionForum)topic.getBaseForum())
551: || uiPermissionsManager.isMovePostings(topic, (DiscussionForum)topic.getBaseForum())
552: || uiPermissionsManager.isNewResponse(topic, (DiscussionForum)topic.getBaseForum())
553: || uiPermissionsManager.isNewResponseToResponse(topic, (DiscussionForum)topic.getBaseForum())
554: || uiPermissionsManager.isPostToGradebook(topic, (DiscussionForum)topic.getBaseForum())
555: || uiPermissionsManager.isRead(topic, (DiscussionForum)topic.getBaseForum())
556: || uiPermissionsManager.isReviseAny(topic, (DiscussionForum)topic.getBaseForum())
557: || uiPermissionsManager.isReviseOwn(topic, (DiscussionForum)topic.getBaseForum()))*/
558: if (uiPermissionsManager.isChangeSettings(topic,
559: (DiscussionForum) topic.getBaseForum())
560: || uiPermissionsManager.isNewResponse(topic,
561: (DiscussionForum) topic.getBaseForum())
562: || uiPermissionsManager.isRead(topic,
563: (DiscussionForum) topic.getBaseForum())) {
564: nonePermission = false;
565: }
566: return nonePermission;
567: }
568:
569: public void setNonePermission(boolean nonePermission) {
570: this .nonePermission = nonePermission;
571: }
572:
573: public List getUnreadMessages() {
574:
575: ArrayList unreadMessages = new ArrayList();
576:
577: for (int i = 0; i < messages.size(); i++) {
578:
579: if (!((DiscussionMessageBean) messages.get(i)).isRead()) {
580:
581: unreadMessages.add(messages.get(i));
582:
583: }
584: }
585:
586: return unreadMessages;
587: }
588:
589: public List getUnreadMessagesInThreads() {
590: //remove all the threads that have been completely read
591:
592: return recursivelyGetUnreadMessagesInThreads(messages, 0);
593: }
594:
595: public List recursivelyGetUnreadMessagesInThreads(List curList,
596: int depth) {
597: List unreadList = new ArrayList();
598: List threadPart = new ArrayList();
599: Boolean foundUnRead = false;
600: DiscussionMessageBean newHead = null;
601:
602: for (int i = 0; i < curList.size(); i++) {
603: DiscussionMessageBean dmb = (DiscussionMessageBean) curList
604: .get(i);
605: //check either replys to no-one, or replys to current head
606: if (dmb.getDepth() == depth) {
607: if (foundUnRead && newHead != null) {
608: unreadList.add(newHead);
609: unreadList
610: .addAll(recursivelyGetUnreadMessagesInThreads(
611: threadPart, ++depth));
612: }
613: newHead = dmb;
614: threadPart = new ArrayList();
615: foundUnRead = false;
616: } else
617: threadPart.add(dmb);
618:
619: if (!dmb.isRead()) {
620: foundUnRead = true;
621: }
622:
623: }
624:
625: if (foundUnRead && newHead != null) {
626: unreadList.add(newHead);
627: //unreadList.addAll(threadPart);
628: if (threadPart.size() > 0)
629: unreadList
630: .addAll(recursivelyGetUnreadMessagesInThreads(
631: threadPart, ++depth));
632: }
633: return unreadList;
634:
635: }
636:
637: public ArrayList getAttachList() {
638: ArrayList decoAttachList = new ArrayList();
639: List attachList = topic.getAttachments();
640: if (attachList != null) {
641: for (int i = 0; i < attachList.size(); i++) {
642: DecoratedAttachment decoAttach = new DecoratedAttachment(
643: (Attachment) attachList.get(i));
644: decoAttachList.add(decoAttach);
645: }
646: }
647: return decoAttachList;
648: }
649: }
|