Source Code Cross Referenced for DiscussionForumTool.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » tool » messageforums » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.tool.messageforums 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-app/src/java/org/sakaiproject/tool/messageforums/DiscussionForumTool.java $
0003:         * $Id: DiscussionForumTool.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2003, 2004, 2005, 2006, 2007 The Sakai Foundation.
0007:         * 
0008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
0009:         * you may not use this file except in compliance with the License. 
0010:         * You may obtain a copy of the License at
0011:         * 
0012:         *      http://www.opensource.org/licenses/ecl1.php
0013:         * 
0014:         * Unless required by applicable law or agreed to in writing, software 
0015:         * distributed under the License is distributed on an "AS IS" BASIS, 
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
0017:         * See the License for the specific language governing permissions and 
0018:         * limitations under the License.
0019:         *
0020:         **********************************************************************************/package org.sakaiproject.tool.messageforums;
0021:
0022:        import java.util.ArrayList;
0023:        import java.util.Collection;
0024:        import java.util.Collections;
0025:        import java.util.Date;
0026:        import java.util.HashMap;
0027:        import java.util.HashSet;
0028:        import java.util.Iterator;
0029:        import java.util.List;
0030:        import java.util.Map;
0031:        import java.util.ResourceBundle;
0032:        import java.util.Set;
0033:
0034:        import javax.faces.application.FacesMessage;
0035:        import javax.faces.component.UIData;
0036:        import javax.faces.context.ExternalContext;
0037:        import javax.faces.context.FacesContext;
0038:        import javax.faces.event.ValueChangeEvent;
0039:        import javax.faces.model.SelectItem;
0040:        import javax.servlet.http.HttpSession;
0041:
0042:        import org.apache.commons.logging.Log;
0043:        import org.apache.commons.logging.LogFactory;
0044:        import org.sakaiproject.api.app.messageforums.Area;
0045:        import org.sakaiproject.api.app.messageforums.AreaManager;
0046:        import org.sakaiproject.api.app.messageforums.Attachment;
0047:        import org.sakaiproject.api.app.messageforums.DBMembershipItem;
0048:        import org.sakaiproject.api.app.messageforums.DiscussionForum;
0049:        import org.sakaiproject.api.app.messageforums.DiscussionTopic;
0050:        import org.sakaiproject.api.app.messageforums.MembershipManager;
0051:        import org.sakaiproject.api.app.messageforums.Message;
0052:        import org.sakaiproject.api.app.messageforums.MessageForumsMessageManager;
0053:        import org.sakaiproject.api.app.messageforums.MessageForumsTypeManager;
0054:        import org.sakaiproject.api.app.messageforums.OpenForum;
0055:        import org.sakaiproject.api.app.messageforums.PermissionLevel;
0056:        import org.sakaiproject.api.app.messageforums.PermissionLevelManager;
0057:        import org.sakaiproject.api.app.messageforums.PermissionsMask;
0058:        import org.sakaiproject.api.app.messageforums.PrivateMessage;
0059:        import org.sakaiproject.api.app.messageforums.Topic;
0060:        import org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager;
0061:        import org.sakaiproject.api.app.messageforums.ui.PrivateMessageManager;
0062:        import org.sakaiproject.api.app.messageforums.ui.UIPermissionsManager;
0063:        import org.sakaiproject.authz.api.AuthzGroup;
0064:        import org.sakaiproject.authz.api.GroupNotDefinedException;
0065:        import org.sakaiproject.authz.api.Role;
0066:        import org.sakaiproject.authz.cover.AuthzGroupService;
0067:        import org.sakaiproject.authz.cover.SecurityService;
0068:        import org.sakaiproject.component.app.messageforums.MembershipItem;
0069:        import org.sakaiproject.component.cover.ComponentManager;
0070:        import org.sakaiproject.component.cover.ServerConfigurationService;
0071:        import org.sakaiproject.content.api.FilePickerHelper;
0072:        import org.sakaiproject.entity.api.Entity;
0073:        import org.sakaiproject.entity.api.Reference;
0074:        import org.sakaiproject.exception.IdUnusedException;
0075:        import org.sakaiproject.service.gradebook.shared.Assignment;
0076:        import org.sakaiproject.service.gradebook.shared.GradebookService;
0077:        import org.sakaiproject.service.gradebook.shared.CommentDefinition;
0078:        import org.sakaiproject.site.api.Group;
0079:        import org.sakaiproject.site.api.Site;
0080:        import org.sakaiproject.site.cover.SiteService;
0081:        import org.sakaiproject.tool.api.ToolSession;
0082:        import org.sakaiproject.tool.cover.SessionManager;
0083:        import org.sakaiproject.tool.cover.ToolManager;
0084:        import org.sakaiproject.tool.messageforums.ui.DecoratedAttachment;
0085:        import org.sakaiproject.tool.messageforums.ui.DiscussionAreaBean;
0086:        import org.sakaiproject.tool.messageforums.ui.DiscussionForumBean;
0087:        import org.sakaiproject.tool.messageforums.ui.DiscussionMessageBean;
0088:        import org.sakaiproject.tool.messageforums.ui.DiscussionTopicBean;
0089:        import org.sakaiproject.tool.messageforums.ui.PermissionBean;
0090:        import org.sakaiproject.user.api.User;
0091:        import org.sakaiproject.user.cover.UserDirectoryService;
0092:        import org.sakaiproject.util.FormattedText;
0093:
0094:        /**
0095:         * @author <a href="mailto:rshastri@iupui.edu">Rashmi Shastri</a>
0096:         * @author Chen wen
0097:         */
0098:        public class DiscussionForumTool {
0099:            private static final Log LOG = LogFactory
0100:                    .getLog(DiscussionForumTool.class);
0101:
0102:            /**
0103:             * List individual forum details
0104:             */
0105:            private static final String MAIN = "main";
0106:            private static final String FORUMS_MAIN = "forumsMain";
0107:            private static final String TEMPLATE_SETTING = "dfTemplateSettings";
0108:            private static final String TEMPLATE_ORGANIZE = "dfTemplateOrganize";
0109:            private static final String FORUM_DETAILS = "dfForumDetail";
0110:            private static final String FORUM_SETTING = "dfForumSettings";
0111:            private static final String FORUM_SETTING_REVISE = "dfReviseForumSettings";
0112:            private static final String TOPIC_SETTING = "dfTopicSettings";
0113:            private static final String TOPIC_SETTING_REVISE = "dfReviseTopicSettings";
0114:            private static final String MESSAGE_COMPOSE = "dfCompose";
0115:            private static final String MESSAGE_VIEW = "dfViewMessage";
0116:            private static final String THREAD_VIEW = "dfViewThread";
0117:            private static final String ALL_MESSAGES = "dfAllMessages";
0118:            private static final String SUBJECT_ONLY = "dfSubjectOnly";
0119:            private static final String ENTIRE_MSG = "dfEntireMsg";
0120:            private static final String EXPANDED_VIEW = "dfExpandAllView";
0121:            private static final String THREADED_VIEW = "dfThreadedView";
0122:            private static final String FLAT_VIEW = "dfFlatView";
0123:            private static final String UNREAD_VIEW = "dfUnreadView";
0124:            private static final String GRADE_MESSAGE = "dfMsgGrade";
0125:            private static final String FORUM_STATISTICS = "dfStatisticsList";
0126:            private static final String FORUM_STATISTICS_USER = "dfStatisticsUser";
0127:            private static final String ADD_COMMENT = "dfMsgAddComment";
0128:            private static final String PENDING_MSG_QUEUE = "dfPendingMessages";
0129:
0130:            private static final String PERMISSION_MODE_TEMPLATE = "template";
0131:            private static final String PERMISSION_MODE_FORUM = "forum";
0132:            private static final String PERMISSION_MODE_TOPIC = "topic";
0133:
0134:            private DiscussionForumBean selectedForum;
0135:            private DiscussionTopicBean selectedTopic;
0136:            private DiscussionTopicBean searchResults;
0137:            private DiscussionMessageBean selectedMessage;
0138:            private DiscussionAreaBean template;
0139:            private DiscussionMessageBean selectedThreadHead;
0140:            private List selectedThread = new ArrayList();
0141:            private UIData forumTable;
0142:            private List groupsUsersList;
0143:            private List totalGroupsUsersList;
0144:            private List selectedGroupsUsersList;
0145:            private Map courseMemberMap;
0146:            private List permissions;
0147:            private List levels;
0148:            private AreaManager areaManager;
0149:            private int numPendingMessages = 0;
0150:            private boolean refreshPendingMsgs = true;
0151:
0152:            private static final String TOPIC_ID = "topicId";
0153:            private static final String FORUM_ID = "forumId";
0154:            private static final String MESSAGE_ID = "messageId";
0155:            private static final String REDIRECT_PROCESS_ACTION = "redirectToProcessAction";
0156:
0157:            private static final String MESSAGECENTER_TOOL_ID = "sakai.messagecenter";
0158:            private static final String FORUMS_TOOL_ID = "sakai.forums";
0159:
0160:            private static final String MESSAGECENTER_BUNDLE = "org.sakaiproject.api.app.messagecenter.bundle.Messages";
0161:
0162:            private static final String INSUFFICIENT_PRIVILEGES_TO_EDIT_TEMPLATE_SETTINGS = "cdfm_insufficient_privileges";
0163:            private static final String INSUFFICIENT_PRIVILEGES_TO_EDIT_TEMPLATE_ORGANIZE = "cdfm_insufficient_privileges";
0164:            private static final String INSUFFICIENT_PRIVILEAGES_TO = "cdfm_insufficient_privileages_to";
0165:            private static final String INSUFFICIENT_PRIVILEGES_CHAGNE_FORUM = "cdfm_insufficient_privileges_change_forum";
0166:            private static final String INSUFFICIENT_PRIVILEGES_NEW_TOPIC = "cdfm_insufficient_privileges_new_topic";
0167:            private static final String INSUFFICIENT_PRIVILEGES_CREATE_TOPIC = "cdfm_insufficient_privileges_create_topic";
0168:            private static final String USER_NOT_ALLOWED_CREATE_FORUM = "cdfm_user_not_allowed_create_forum";
0169:            private static final String INSUFFICIENT_PRIVILEGES_TO_DELETE_FORUM = "cdfm_insufficient_privileges_delete_forum";
0170:            private static final String SHORT_DESC_TOO_LONG = "cdfm_short_desc_too_long";
0171:            private static final String LAST_REVISE_BY = "cdfm_last_revise_msg";
0172:            private static final String LAST_REVISE_ON = "cdfm_last_revise_msg_on";
0173:            private static final String VALID_FORUM_TITLE_WARN = "cdfm_valid_forum_title_warn";
0174:            private static final String VALID_TOPIC_TITLE_WARN = "cdfm_valid_topic_title_warn";
0175:            private static final String INVALID_SELECTED_FORUM = "cdfm_invalid_selected_forum";
0176:            private static final String FORUM_NOT_FOUND = "cdfm_forum_not_found";
0177:            private static final String SELECTED_FORUM_NOT_FOUND = "cdfm_selected_forum_not_found";
0178:            private static final String FAILED_NEW_TOPIC = "cdfm_failed_new_topic";
0179:            private static final String TOPIC_WITH_ID = "cdfm_topic_with_id";
0180:            private static final String MESSAGE_WITH_ID = "cdfm_message_with_id";
0181:            private static final String NOT_FOUND_WITH_QUOTE = "cdfm_not_found_quote";
0182:            private static final String PARENT_FORUM_NOT_FOUND = "cdfm_parent_forum_not_found";
0183:            private static final String NOT_FOUND_REDIRECT_PAGE = "cdfm_not_found_redirect_page";
0184:            private static final String MESSAGE_REFERENCE_NOT_FOUND = "cdfm_message_reference_not_found";
0185:            private static final String TOPC_REFERENCE_NOT_FOUND = "cdfm_topic_reference_not_found";
0186:            private static final String UNABLE_RETRIEVE_TOPIC = "cdfm_unable_retrieve_topic";
0187:            private static final String PARENT_TOPIC_NOT_FOUND = "cdfm_parent_topic_not_found";
0188:            private static final String FAILED_CREATE_TOPIC = "cdfm_failed_create_topic";
0189:            private static final String FAILED_REND_MESSAGE = "cdfm_failed_rend_message";
0190:            private static final String VIEW_UNDER_CONSTRUCT = "cdfm_view_under_construct";
0191:            private static final String LOST_ASSOCIATE = "cdfm_lost_association";
0192:            private static final String NO_MARKED_READ_MESSAGE = "cdfm_no_message_mark_read";
0193:            private static final String GRADE_SUCCESSFUL = "cdfm_grade_successful";
0194:            private static final String GRADE_GREATER_ZERO = "cdfm_grade_greater_than_zero";
0195:            private static final String GRADE_DECIMAL_WARN = "cdfm_grade_decimal_warn";
0196:            private static final String ALERT = "cdfm_alert";
0197:            private static final String SELECT_ASSIGN = "cdfm_select_assign";
0198:            private static final String INVALID_COMMENT = "cdfm_add_comment_invalid";
0199:            private static final String INSUFFICIENT_PRIVILEGES_TO_ADD_COMMENT = "cdfm_insufficient_privileges_add_comment";
0200:            private static final String MOD_COMMENT_TEXT = "cdfm_moderator_comment_text";
0201:            private static final String NO_MSG_SEL_FOR_APPROVAL = "cdfm_no_message_mark_approved";
0202:            private static final String MSGS_APPROVED = "cdfm_approve_msgs_success";
0203:            private static final String MSGS_DENIED = "cdfm_deny_msgs_success";
0204:            private static final String MSG_REPLY_PREFIX = "cdfm_reply_prefix";
0205:            private static final String NO_GRADE_PTS = "cdfm_no_points_for_grade";
0206:            private static final String NO_ASSGN = "cdfm_no_assign_for_grade";
0207:
0208:            private static final String FROM_PAGE = "msgForum:mainOrForumOrTopic";
0209:            private String fromPage = null; // keep track of originating page for common functions
0210:
0211:            private List forums = new ArrayList();
0212:            private List pendingMsgs = new ArrayList();
0213:
0214:            // compose
0215:            private MessageForumsMessageManager messageManager;
0216:            private String composeTitle;
0217:            private String composeBody;
0218:            private String composeLabel;
0219:            private String searchText = "";
0220:            private String selectedMessageView = ALL_MESSAGES;
0221:            private String selectedMessageShow = SUBJECT_ONLY;
0222:            private String selectedMessageOrganize = "thread";
0223:            private String threadAnchorMessageId = null;
0224:            private boolean deleteMsg;
0225:            private boolean displayUnreadOnly;
0226:            private boolean errorSynch = false;
0227:            // attachment
0228:            private ArrayList attachments = new ArrayList();
0229:            private ArrayList prepareRemoveAttach = new ArrayList();
0230:            // private boolean attachCaneled = false;
0231:            // private ArrayList oldAttachments = new ArrayList();
0232:            // private List allAttachments = new ArrayList();
0233:            private boolean threaded = true;
0234:            private boolean expandedView = false;
0235:            private String expanded = "false";
0236:            private boolean orderAsc = true;
0237:            private boolean disableLongDesc = false;
0238:            private boolean isDisplaySearchedMessages;
0239:            private List siteMembers = new ArrayList();
0240:            private String selectedRole;
0241:            private String moderatorComments;
0242:
0243:            private boolean editMode = true;
0244:            private String permissionMode;
0245:
0246:            //grading 
0247:            private boolean gradeNotify = false;
0248:            private List assignments = new ArrayList();
0249:            private String selectedAssign = "Default_0";
0250:            private String gradePoint = "";
0251:            private String gradeComment;
0252:            private boolean gradebookExist = false;
0253:            private boolean displayDeniedMsg = false;
0254:
0255:            /**
0256:             * Dependency Injected
0257:             */
0258:            private DiscussionForumManager forumManager;
0259:            private UIPermissionsManager uiPermissionsManager;
0260:            private MessageForumsTypeManager typeManager;
0261:            private MembershipManager membershipManager;
0262:            private PermissionLevelManager permissionLevelManager;
0263:
0264:            /**
0265:             * 
0266:             */
0267:            public DiscussionForumTool() {
0268:                LOG.debug("DiscussionForumTool()");
0269:                if ("true".equalsIgnoreCase(ServerConfigurationService
0270:                        .getString("mc.threadedview"))) {
0271:                    threaded = true;
0272:                    selectedMessageView = THREADED_VIEW;
0273:                }
0274:                if ("true".equalsIgnoreCase(ServerConfigurationService
0275:                        .getString("mc.disableLongDesc"))) {
0276:                    disableLongDesc = true;
0277:                }
0278:            }
0279:
0280:            /**
0281:             * @param forumManager
0282:             */
0283:            public void setForumManager(DiscussionForumManager forumManager) {
0284:                if (LOG.isDebugEnabled()) {
0285:                    LOG.debug("setForumManager(DiscussionForumManager "
0286:                            + forumManager + ")");
0287:                }
0288:                this .forumManager = forumManager;
0289:            }
0290:
0291:            /**
0292:             * @param uiPermissionsManager
0293:             *          The uiPermissionsManager to set.
0294:             */
0295:            public void setUiPermissionsManager(
0296:                    UIPermissionsManager uiPermissionsManager) {
0297:                if (LOG.isDebugEnabled()) {
0298:                    LOG.debug("setUiPermissionsManager(UIPermissionsManager "
0299:                            + uiPermissionsManager + ")");
0300:                }
0301:                this .uiPermissionsManager = uiPermissionsManager;
0302:            }
0303:
0304:            /**
0305:             * @param typeManager The typeManager to set.
0306:             */
0307:            public void setTypeManager(MessageForumsTypeManager typeManager) {
0308:                this .typeManager = typeManager;
0309:            }
0310:
0311:            /**
0312:             * @param membershipManager The membershipManager to set.
0313:             */
0314:            public void setMembershipManager(MembershipManager membershipManager) {
0315:                this .membershipManager = membershipManager;
0316:            }
0317:
0318:            /**
0319:             * @return
0320:             */
0321:            public String processActionHome() {
0322:                LOG.debug("processActionHome()");
0323:                reset();
0324:                return gotoMain();
0325:            }
0326:
0327:            /**
0328:             * @return
0329:             */
0330:            public boolean isInstructor() {
0331:                LOG.debug("isInstructor()");
0332:                return forumManager.isInstructor();
0333:            }
0334:
0335:            /**
0336:             * @return List of SelectItem
0337:             */
0338:            public List getForumSelectItems() {
0339:                List f = getForums();
0340:                int num = (f == null) ? 0 : f.size();
0341:
0342:                List retSort = new ArrayList();
0343:                for (int i = 1; i <= num; i++) {
0344:                    Integer index = new Integer(i);
0345:                    retSort.add(new SelectItem(index, index.toString()));
0346:                }
0347:
0348:                return retSort;
0349:            }
0350:
0351:            /**
0352:             * @return List of DiscussionForumBean
0353:             */
0354:            public List getForums() {
0355:                LOG.debug("getForums()");
0356:
0357:                if (forums == null || forums.size() < 1) {
0358:                    try {
0359:                        assignments = new ArrayList();
0360:                        SelectItem item = new SelectItem("Default_0",
0361:                                getResourceBundleString(SELECT_ASSIGN));
0362:                        assignments.add(item);
0363:
0364:                        GradebookService gradebookService = (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
0365:                                .get("org.sakaiproject.service.gradebook.GradebookService");
0366:                        if (getGradebookExist()) {
0367:                            List gradeAssignmentsBeforeFilter = gradebookService
0368:                                    .getAssignments(ToolManager
0369:                                            .getCurrentPlacement().getContext());
0370:                            List gradeAssignments = new ArrayList();
0371:                            for (int i = 0; i < gradeAssignmentsBeforeFilter
0372:                                    .size(); i++) {
0373:                                Assignment this Assign = (Assignment) gradeAssignmentsBeforeFilter
0374:                                        .get(i);
0375:                                if (!this Assign.isExternallyMaintained()) {
0376:                                    gradeAssignments.add(this Assign);
0377:                                }
0378:                            }
0379:
0380:                            for (int i = 0; i < gradeAssignments.size(); i++) {
0381:                                try {
0382:                                    Assignment this Assign = (Assignment) gradeAssignments
0383:                                            .get(i);
0384:
0385:                                    String assignName = this Assign.getName();
0386:
0387:                                    item = new SelectItem((new Integer(i + 1))
0388:                                            .toString(), assignName);
0389:                                    assignments.add(item);
0390:                                } catch (Exception e) {
0391:                                    LOG
0392:                                            .error("DiscussionForumTool - processDfMsgGrd:"
0393:                                                    + e);
0394:                                    e.printStackTrace();
0395:                                }
0396:                            }
0397:                        }
0398:                    } catch (SecurityException se) {
0399:                        // ignore - don't want to print out stacktrace every time a non-admin user uses MC
0400:                    } catch (Exception e1) {
0401:                        LOG.error("DiscussionForumTool&processDfMsgGrad:" + e1);
0402:                        e1.printStackTrace();
0403:                    }
0404:                    forums = new ArrayList();
0405:                    //List tempForum = forumManager.getDiscussionForums();
0406:                    List tempForum = forumManager
0407:                            .getDiscussionForumsWithTopics();
0408:                    if (tempForum == null) {
0409:                        return null;
0410:                    }
0411:                    Iterator iterForum = tempForum.iterator();
0412:                    List msgIds = new ArrayList();
0413:                    while (iterForum.hasNext()) {
0414:                        DiscussionForum forum = (DiscussionForum) iterForum
0415:                                .next();
0416:                        if (forum != null) {
0417:                            List topicList = forum.getTopics();
0418:                            if (topicList != null) {
0419:                                for (int i = 0; i < topicList.size(); i++) {
0420:                                    Topic this Topic = (Topic) topicList.get(i);
0421:                                    if (this Topic != null) {
0422:                                        List msgList = this Topic.getMessages();
0423:                                        if (msgList != null) {
0424:                                            for (int j = 0; j < msgList.size(); j++) {
0425:                                                Message tempMsg = (Message) msgList
0426:                                                        .get(j);
0427:                                                if (tempMsg != null
0428:                                                        && !tempMsg.getDraft()
0429:                                                                .booleanValue()) {
0430:                                                    msgIds.add(tempMsg.getId());
0431:                                                }
0432:                                            }
0433:                                        }
0434:                                    }
0435:                                }
0436:                            }
0437:                        }
0438:                    }
0439:
0440:                    iterForum = tempForum.iterator();
0441:                    while (iterForum.hasNext()) {
0442:                        DiscussionForum forum = (DiscussionForum) iterForum
0443:                                .next();
0444:                        if (forum == null) {
0445:                            return forums;
0446:                        }
0447:                        List temp_topics = forum.getTopics();
0448:                        if (temp_topics == null) {
0449:                            return forums;
0450:                        }
0451:                        // TODO: put this logic in database layer
0452:                        if (forum.getDraft().equals(Boolean.FALSE)
0453:                                || (forum.getDraft().equals(Boolean.TRUE) && forum
0454:                                        .getCreatedBy()
0455:                                        .equals(
0456:                                                SessionManager
0457:                                                        .getCurrentSessionUserId()))
0458:                                || SecurityService.isSuperUser()
0459:                                || isInstructor()
0460:                                || forum.getCreatedBy().equals(
0461:                                        SessionManager
0462:                                                .getCurrentSessionUserId())) {
0463:                            //DiscussionForumBean decoForum = getDecoratedForum(forum);
0464:                            DiscussionForumBean decoForum = getDecoratedForumWithPersistentForumAndTopics(forum);
0465:                            decoForum.setGradeAssign("Default_0");
0466:                            for (int i = 0; i < assignments.size(); i++) {
0467:                                if (((String) ((SelectItem) assignments.get(i))
0468:                                        .getLabel()).equals(forum
0469:                                        .getDefaultAssignName())) {
0470:                                    decoForum.setGradeAssign(new Integer(i)
0471:                                            .toString());
0472:                                    break;
0473:                                }
0474:                            }
0475:                            forums.add(decoForum);
0476:                        }
0477:                    }
0478:                }
0479:                return forums;
0480:            }
0481:
0482:            /**
0483:             * @return Returns the selectedForum.
0484:             */
0485:            public DiscussionForumBean getSelectedForum() {
0486:                LOG.debug("getSelectedForum()");
0487:                return selectedForum;
0488:            }
0489:
0490:            /**
0491:             * @return
0492:             */
0493:            public String processActionOrganize() {
0494:                LOG.debug("processActionOrganize()");
0495:                return MAIN;
0496:            }
0497:
0498:            /**
0499:             * @return
0500:             */
0501:            public String processActionStatistics() {
0502:                LOG.debug("processActionStatistics()");
0503:                return FORUM_STATISTICS;
0504:            }
0505:
0506:            /**
0507:             * @return
0508:             */
0509:            public String processActionTemplateSettings() {
0510:                LOG.debug("processActionTemplateSettings()");
0511:
0512:                setEditMode(true);
0513:                setPermissionMode(PERMISSION_MODE_TEMPLATE);
0514:                template = new DiscussionAreaBean(areaManager
0515:                        .getDiscusionArea());
0516:
0517:                if (!isInstructor()) {
0518:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_TO_EDIT_TEMPLATE_SETTINGS));
0519:                    return gotoMain();
0520:                }
0521:                return TEMPLATE_SETTING;
0522:            }
0523:
0524:            /**
0525:             * @return
0526:             */
0527:            public String processActionTemplateOrganize() {
0528:                LOG.debug("processActionTemplateOrganize()");
0529:
0530:                setEditMode(false);
0531:                setPermissionMode(PERMISSION_MODE_TEMPLATE);
0532:
0533:                if (!isInstructor()) {
0534:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_TO_EDIT_TEMPLATE_ORGANIZE));
0535:                    return gotoMain();
0536:                }
0537:                return TEMPLATE_ORGANIZE;
0538:            }
0539:
0540:            /**
0541:             * @return
0542:             */
0543:            public List getPermissions() {
0544:
0545:                if (permissions == null) {
0546:                    siteMembers = null;
0547:                    getSiteRoles();
0548:                }
0549:                return permissions;
0550:            }
0551:
0552:            /**
0553:             * @return
0554:             */
0555:            public void setPermissions(List permissions) {
0556:                this .permissions = permissions;
0557:            }
0558:
0559:            //  /**
0560:            //   * @return Returns the templateMessagePermissions.
0561:            //   */
0562:            //  public List getTemplateMessagePermissions()
0563:            //  {
0564:            //    if (templateMessagePermissions == null)
0565:            //    {
0566:            //      templateMessagePermissions = forumManager.getAreaMessagePermissions();
0567:            //    }
0568:            //    return templateMessagePermissions;
0569:            //  }
0570:            //
0571:            //  /**
0572:            //   * @param templateMessagePermissions
0573:            //   *          The templateMessagePermissions to set.
0574:            //   */
0575:            //  public void setTemplateMessagePermissions(List templateMessagePermissions)
0576:            //  {
0577:            //    this.templateMessagePermissions = templateMessagePermissions;
0578:            //  }
0579:
0580:            /*/**
0581:             * @return
0582:             */
0583:            /*public String processActionReviseTemplateSettings()
0584:            {
0585:            	if (LOG.isDebugEnabled()){
0586:                LOG.debug("processActionReviseTemplateSettings()");
0587:            	}
0588:              
0589:            	setEditMode(true); 
0590:            	setPermissionMode(PERMISSION_MODE_TEMPLATE);
0591:              return TEMPLATE_SETTING;
0592:            }*/
0593:
0594:            /**
0595:             * @return
0596:             */
0597:            public String processActionSaveTemplateSettings() {
0598:                LOG.debug("processActionSaveTemplateSettings()");
0599:                if (!isInstructor()) {
0600:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_TO_EDIT_TEMPLATE_SETTINGS));
0601:                    return gotoMain();
0602:                }
0603:
0604:                setObjectPermissions(template.getArea());
0605:                areaManager.saveArea(template.getArea());
0606:
0607:                return gotoMain();
0608:            }
0609:
0610:            /**
0611:             * @return
0612:             */
0613:            public String processActionSaveTemplateOrganization() {
0614:                LOG.debug("processActionSaveTemplateOrganization()");
0615:                if (!isInstructor()) {
0616:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_TO_EDIT_TEMPLATE_ORGANIZE));
0617:                    return gotoMain();
0618:                }
0619:
0620:                for (Iterator i = forums.iterator(); i.hasNext();) {
0621:                    DiscussionForumBean forum = (DiscussionForumBean) i.next();
0622:
0623:                    // because there is no straight up save forum function we need to retain the draft status
0624:                    if (forum.getForum().getDraft().booleanValue())
0625:                        forumManager.saveForumAsDraft(forum.getForum());
0626:                    else
0627:                        forumManager.saveForum(forum.getForum());
0628:                }
0629:
0630:                //reload the forums so they change position in the list
0631:                forums = null;
0632:
0633:                return gotoMain();
0634:            }
0635:
0636:            /**
0637:             * @return
0638:             */
0639:            public String processActionRestoreDefaultTemplate() {
0640:                LOG.debug("processActionRestoreDefaultTemplate()");
0641:                if (!isInstructor()) {
0642:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_TO_EDIT_TEMPLATE_SETTINGS));
0643:                    return gotoMain();
0644:                }
0645:
0646:                Area area = null;
0647:                if ((area = areaManager.getDiscusionArea()) != null) {
0648:                    area.setMembershipItemSet(new HashSet());
0649:                    area.setModerated(Boolean.FALSE);
0650:                    areaManager.saveArea(area);
0651:                    permissions = null;
0652:                } else {
0653:                    throw new IllegalStateException(
0654:                            "Could not obtain area for site: "
0655:                                    + getContextSiteId());
0656:                }
0657:
0658:                return TEMPLATE_SETTING;
0659:            }
0660:
0661:            /**
0662:             * Check out if the user is allowed to create new forum
0663:             * 
0664:             * @return
0665:             */
0666:            public boolean getNewForum() {
0667:                LOG.debug("getNewForum()");
0668:                return uiPermissionsManager.isNewForum();
0669:            }
0670:
0671:            /**
0672:             * Display Individual forum
0673:             * 
0674:             * @return
0675:             */
0676:            public String processActionDisplayForum() {
0677:                LOG.debug("processDisplayForum()");
0678:                if (getDecoratedForum() == null) {
0679:                    LOG.error("Forum not found");
0680:                    return gotoMain();
0681:                }
0682:                return FORUM_DETAILS;
0683:            }
0684:
0685:            /**
0686:             * Forward to delete forum confirmation screen
0687:             * 
0688:             * @return
0689:             */
0690:            public String processActionDeleteForumConfirm() {
0691:                LOG.debug("processActionDeleteForumConfirm()");
0692:                if (selectedForum == null) {
0693:                    LOG.debug("There is no forum selected for deletion");
0694:                    return gotoMain();
0695:                }
0696:                //  TODO:
0697:                if (!uiPermissionsManager.isChangeSettings(selectedForum
0698:                        .getForum())) {
0699:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_TO_DELETE_FORUM));
0700:                    return gotoMain();
0701:                }
0702:                selectedForum.setMarkForDeletion(true);
0703:                return FORUM_SETTING;
0704:            }
0705:
0706:            /**
0707:             * @return
0708:             */
0709:            public String processActionDeleteForum() {
0710:                if (selectedForum == null) {
0711:                    LOG.debug("There is no forum selected for deletion");
0712:                }
0713:                if (!uiPermissionsManager.isChangeSettings(selectedForum
0714:                        .getForum())) {
0715:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEAGES_TO));
0716:                    return gotoMain();
0717:                }
0718:                forumManager.deleteForum(selectedForum.getForum());
0719:                reset();
0720:                return gotoMain();
0721:            }
0722:
0723:            /**
0724:             * @return
0725:             */
0726:            public String processActionNewForum() {
0727:                LOG.debug("processActionNewForum()");
0728:
0729:                setEditMode(true);
0730:                setPermissionMode(PERMISSION_MODE_FORUM);
0731:
0732:                if (getNewForum()) {
0733:                    DiscussionForum forum = forumManager.createForum();
0734:                    forum.setModerated(areaManager.getDiscusionArea()
0735:                            .getModerated()); // default to template setting
0736:                    selectedForum = null;
0737:                    selectedForum = new DiscussionForumBean(forum,
0738:                            uiPermissionsManager, forumManager);
0739:                    if ("true".equalsIgnoreCase(ServerConfigurationService
0740:                            .getString("mc.defaultLongDescription"))) {
0741:                        selectedForum.setReadFullDesciption(true);
0742:                    }
0743:
0744:                    setNewForumBeanAssign();
0745:
0746:                    return FORUM_SETTING_REVISE;
0747:                } else {
0748:                    setErrorMessage(getResourceBundleString(USER_NOT_ALLOWED_CREATE_FORUM));
0749:                    return gotoMain();
0750:                }
0751:            }
0752:
0753:            /**
0754:             * @return
0755:             */
0756:            public String processActionForumSettings() {
0757:                LOG.debug("processForumSettings()");
0758:                setEditMode(true);
0759:                setPermissionMode(PERMISSION_MODE_FORUM);
0760:
0761:                String forumId = getExternalParameterByKey(FORUM_ID);
0762:                if ((forumId) == null) {
0763:                    setErrorMessage(getResourceBundleString(INVALID_SELECTED_FORUM));
0764:                    return gotoMain();
0765:                }
0766:                DiscussionForum forum = forumManager.getForumById(new Long(
0767:                        forumId));
0768:                if (forum == null) {
0769:                    setErrorMessage(getResourceBundleString(FORUM_NOT_FOUND));
0770:                    return gotoMain();
0771:                }
0772:
0773:                if (!uiPermissionsManager.isChangeSettings(forum)) {
0774:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_CHAGNE_FORUM));
0775:                    return gotoMain();
0776:                }
0777:
0778:                List attachList = forum.getAttachments();
0779:                if (attachList != null) {
0780:                    for (int i = 0; i < attachList.size(); i++) {
0781:                        attachments.add(new DecoratedAttachment(
0782:                                (Attachment) attachList.get(i)));
0783:                    }
0784:                }
0785:
0786:                selectedForum = new DiscussionForumBean(forum,
0787:                        uiPermissionsManager, forumManager);
0788:                if ("true".equalsIgnoreCase(ServerConfigurationService
0789:                        .getString("mc.defaultLongDescription"))) {
0790:                    selectedForum.setReadFullDesciption(true);
0791:                }
0792:
0793:                setForumBeanAssign();
0794:                setFromMainOrForumOrTopic();
0795:
0796:                return FORUM_SETTING_REVISE;
0797:
0798:            }
0799:
0800:            /**
0801:             * @return
0802:             */
0803:            /*public String processActionReviseForumSettings()
0804:            {
0805:              LOG.debug("processActionReviseForumSettings()");    
0806:              setEditMode(true);
0807:              setPermissionMode(PERMISSION_MODE_FORUM);
0808:              if ((selectedForum) == null)
0809:              {
0810:                setErrorMessage(getResourceBundleString(FORUM_NOT_FOUND));
0811:                return gotoMain();
0812:              }
0813:              if(!uiPermissionsManager.isChangeSettings(selectedForum.getForum()))
0814:              {
0815:                setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_CHAGNE_FORUM));
0816:                return gotoMain();
0817:              }
0818:              List attachList = selectedForum.getForum().getAttachments();
0819:              if (attachList != null)
0820:              {
0821:                for (int i = 0; i < attachList.size(); i++)
0822:                {
0823:                  attachments.add(new DecoratedAttachment((Attachment)attachList.get(i)));
0824:                }
0825:              }
0826:              
0827:              setFromMainOrForumOrTopic();
0828:
0829:              return FORUM_SETTING_REVISE; //
0830:            }*/
0831:
0832:            /**
0833:             * @return
0834:             */
0835:            public String processActionSaveForumAndAddTopic() {
0836:                LOG.debug("processActionSaveForumAndAddTopic()");
0837:
0838:                if (selectedForum != null
0839:                        && selectedForum.getForum() != null
0840:                        && (selectedForum.getForum().getShortDescription() != null)
0841:                        && (selectedForum.getForum().getShortDescription()
0842:                                .length() > 255)) {
0843:                    setErrorMessage(getResourceBundleString(SHORT_DESC_TOO_LONG));
0844:                    return null;
0845:                }
0846:
0847:                if (selectedForum != null
0848:                        && selectedForum.getForum() != null
0849:                        && (selectedForum.getForum().getTitle() == null || selectedForum
0850:                                .getForum().getTitle().trim().length() < 1)) {
0851:                    setErrorMessage(getResourceBundleString(VALID_FORUM_TITLE_WARN));
0852:                    return FORUM_SETTING_REVISE;
0853:                }
0854:                if (!uiPermissionsManager.isChangeSettings(selectedForum
0855:                        .getForum())) {
0856:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_CHAGNE_FORUM));
0857:                    return gotoMain();
0858:                }
0859:
0860:                DiscussionForum forum = saveForumSettings(false);
0861:                if (!uiPermissionsManager.isNewTopic(selectedForum.getForum())) {
0862:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_CREATE_TOPIC));
0863:                    return gotoMain();
0864:                }
0865:                selectedTopic = createTopic(forum.getId());
0866:                if (selectedTopic == null) {
0867:                    setErrorMessage(getResourceBundleString(FAILED_NEW_TOPIC));
0868:                    attachments.clear();
0869:                    prepareRemoveAttach.clear();
0870:                    return gotoMain();
0871:                }
0872:                attachments.clear();
0873:                prepareRemoveAttach.clear();
0874:                return TOPIC_SETTING_REVISE;
0875:            }
0876:
0877:            /**
0878:             * @return
0879:             */
0880:            public String processActionSaveForumSettings() {
0881:                LOG.debug("processActionSaveForumSettings()");
0882:
0883:                if (selectedForum != null
0884:                        && selectedForum.getForum() != null
0885:                        && (selectedForum.getForum().getShortDescription() != null)
0886:                        && (selectedForum.getForum().getShortDescription()
0887:                                .length() > 255)) {
0888:                    setErrorMessage(getResourceBundleString(SHORT_DESC_TOO_LONG));
0889:                    return null;
0890:                }
0891:
0892:                if (!uiPermissionsManager.isChangeSettings(selectedForum
0893:                        .getForum())) {
0894:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_CHAGNE_FORUM));
0895:                    return gotoMain();
0896:                }
0897:                if (selectedForum != null
0898:                        && selectedForum.getForum() != null
0899:                        && (selectedForum.getForum().getTitle() == null || selectedForum
0900:                                .getForum().getTitle().trim().length() < 1)) {
0901:                    setErrorMessage(getResourceBundleString(VALID_FORUM_TITLE_WARN));
0902:                    return FORUM_SETTING_REVISE;
0903:                }
0904:                saveForumSettings(false);
0905:
0906:                //reset();
0907:                //return MAIN;
0908:                return processReturnToOriginatingPage();
0909:            }
0910:
0911:            /**
0912:             * @return
0913:             */
0914:            public String processActionSaveForumAsDraft() {
0915:                LOG.debug("processActionSaveForumAsDraft()");
0916:
0917:                if (selectedForum != null
0918:                        && selectedForum.getForum() != null
0919:                        && (selectedForum.getForum().getShortDescription() != null)
0920:                        && (selectedForum.getForum().getShortDescription()
0921:                                .length() > 255)) {
0922:                    setErrorMessage(getResourceBundleString(SHORT_DESC_TOO_LONG));
0923:                    return null;
0924:                }
0925:
0926:                if (!uiPermissionsManager.isChangeSettings(selectedForum
0927:                        .getForum())) {
0928:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_CHAGNE_FORUM));
0929:                    return gotoMain();
0930:                }
0931:                if (selectedForum != null
0932:                        && selectedForum.getForum() != null
0933:                        && (selectedForum.getForum().getTitle() == null || selectedForum
0934:                                .getForum().getTitle().trim().length() < 1)) {
0935:                    setErrorMessage(getResourceBundleString(VALID_FORUM_TITLE_WARN));
0936:                    return FORUM_SETTING_REVISE;
0937:                }
0938:                saveForumSettings(true);
0939:
0940:                //reset();
0941:                //return MAIN;
0942:                return processReturnToOriginatingPage();
0943:            }
0944:
0945:            private DiscussionForum saveForumSettings(boolean draft) {
0946:                LOG.debug("saveForumSettings(boolean " + draft + ")");
0947:
0948:                if (selectedForum == null) {
0949:                    setErrorMessage(getResourceBundleString(SELECTED_FORUM_NOT_FOUND));
0950:                    return null;
0951:                }
0952:
0953:                DiscussionForum forum = selectedForum.getForum();
0954:                if (forum == null) {
0955:                    setErrorMessage(getResourceBundleString(FORUM_NOT_FOUND));
0956:                    return null;
0957:                }
0958:
0959:                saveForumSelectedAssignment(forum);
0960:                saveForumAttach(forum);
0961:                setObjectPermissions(forum);
0962:                if (draft)
0963:                    forumManager.saveForumAsDraft(forum);
0964:                else
0965:                    forumManager.saveForum(forum);
0966:                //forumManager.saveForumControlPermissions(forum, forumControlPermissions);
0967:                //forumManager.saveForumMessagePermissions(forum, forumMessagePermissions);
0968:                if (forum.getId() == null) {
0969:                    String forumUuid = forum.getUuid();
0970:                    forum = null;
0971:                    forum = forumManager.getForumByUuid(forumUuid);
0972:                }
0973:                return forum;
0974:            }
0975:
0976:            /**
0977:             * @return Returns the selectedTopic.
0978:             */
0979:            public DiscussionTopicBean getSelectedTopic() {
0980:                rearrageTopicMsgsThreaded();
0981:                setMessageBeanPreNextStatus();
0982:
0983:                return selectedTopic;
0984:            }
0985:
0986:            /**
0987:             * @return Returns the selected Area
0988:             */
0989:            public DiscussionAreaBean getTemplate() {
0990:                return template;
0991:            }
0992:
0993:            /**
0994:             * @return
0995:             */
0996:            public String processActionNewTopic() {
0997:                LOG.debug("processActionNewTopic()");
0998:
0999:                setEditMode(true);
1000:                setPermissionMode(PERMISSION_MODE_TOPIC);
1001:
1002:                selectedTopic = createTopic();
1003:                setNewTopicBeanAssign();
1004:                if (selectedTopic == null) {
1005:                    setErrorMessage(getResourceBundleString(FAILED_NEW_TOPIC));
1006:                    attachments.clear();
1007:                    prepareRemoveAttach.clear();
1008:                    return gotoMain();
1009:                }
1010:                if (!uiPermissionsManager.isNewTopic(selectedForum.getForum())) {
1011:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_CREATE_TOPIC));
1012:                    return gotoMain();
1013:                }
1014:                attachments.clear();
1015:                prepareRemoveAttach.clear();
1016:                setFromMainOrForumOrTopic();
1017:                return TOPIC_SETTING_REVISE;
1018:            }
1019:
1020:            /**
1021:             * @return
1022:             */
1023:            public String processActionReviseTopicSettings() {
1024:                LOG.debug("processActionReviseTopicSettings()");
1025:
1026:                setPermissionMode(PERMISSION_MODE_TOPIC);
1027:                setEditMode(true);
1028:
1029:                DiscussionTopic topic = selectedTopic.getTopic();
1030:
1031:                if (topic == null) {
1032:                    topic = forumManager.getTopicById(new Long(
1033:                            getExternalParameterByKey(TOPIC_ID)));
1034:                }
1035:                if (topic == null) {
1036:                    setErrorMessage(getResourceBundleString(TOPIC_WITH_ID)
1037:                            + getExternalParameterByKey(TOPIC_ID)
1038:                            + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
1039:                    return gotoMain();
1040:                }
1041:
1042:                setSelectedForumForCurrentTopic(topic);
1043:                selectedTopic = new DiscussionTopicBean(topic, selectedForum
1044:                        .getForum(), uiPermissionsManager, forumManager);
1045:                if ("true".equalsIgnoreCase(ServerConfigurationService
1046:                        .getString("mc.defaultLongDescription"))) {
1047:                    selectedTopic.setReadFullDesciption(true);
1048:                }
1049:
1050:                setTopicBeanAssign();
1051:
1052:                if (!uiPermissionsManager.isChangeSettings(selectedTopic
1053:                        .getTopic(), selectedForum.getForum())) {
1054:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_NEW_TOPIC));
1055:                    return gotoMain();
1056:                }
1057:                List attachList = selectedTopic.getTopic().getAttachments();
1058:                if (attachList != null) {
1059:                    for (int i = 0; i < attachList.size(); i++) {
1060:                        attachments.add(new DecoratedAttachment(
1061:                                (Attachment) attachList.get(i)));
1062:                    }
1063:                }
1064:
1065:                setFromMainOrForumOrTopic();
1066:
1067:                return TOPIC_SETTING_REVISE;
1068:            }
1069:
1070:            /**
1071:             * @return
1072:             */
1073:            public String processActionSaveTopicAndAddTopic() {
1074:                LOG.debug("processActionSaveTopicAndAddTopic()");
1075:
1076:                if (selectedTopic != null
1077:                        && selectedTopic.getTopic() != null
1078:                        && (selectedTopic.getTopic().getShortDescription() != null)
1079:                        && (selectedTopic.getTopic().getShortDescription()
1080:                                .length() > 255)) {
1081:                    setErrorMessage(getResourceBundleString(SHORT_DESC_TOO_LONG));
1082:                    return null;
1083:                }
1084:
1085:                setPermissionMode(PERMISSION_MODE_TOPIC);
1086:                if (selectedTopic != null
1087:                        && selectedTopic.getTopic() != null
1088:                        && (selectedTopic.getTopic().getTitle() == null || selectedTopic
1089:                                .getTopic().getTitle().trim().length() < 1)) {
1090:                    setErrorMessage(getResourceBundleString(VALID_TOPIC_TITLE_WARN));
1091:                    return TOPIC_SETTING_REVISE;
1092:                }
1093:
1094:                // if the topic is not moderated (and already exists), all of the pending messages must be approved
1095:                if (selectedTopic != null && selectedTopic.getTopic() != null
1096:                        && !selectedTopic.isTopicModerated()
1097:                        && selectedTopic.getTopic().getId() != null) {
1098:                    forumManager.approveAllPendingMessages(selectedTopic
1099:                            .getTopic().getId());
1100:                }
1101:
1102:                saveTopicSettings(false);
1103:                Long forumId = selectedForum.getForum().getId();
1104:                if (forumId == null) {
1105:                    setErrorMessage(getResourceBundleString(PARENT_FORUM_NOT_FOUND));
1106:                    return gotoMain();
1107:                }
1108:                selectedTopic = null;
1109:                selectedTopic = createTopic(forumId);
1110:                if (selectedTopic == null) {
1111:                    setErrorMessage(getResourceBundleString(FAILED_NEW_TOPIC));
1112:                    attachments.clear();
1113:                    prepareRemoveAttach.clear();
1114:
1115:                    return gotoMain();
1116:                }
1117:                attachments.clear();
1118:                prepareRemoveAttach.clear();
1119:                return TOPIC_SETTING_REVISE;
1120:
1121:            }
1122:
1123:            /**
1124:             * @return
1125:             */
1126:            public String processActionSaveTopicSettings() {
1127:                LOG.debug("processActionSaveTopicSettings()");
1128:
1129:                if (selectedTopic != null
1130:                        && selectedTopic.getTopic() != null
1131:                        && (selectedTopic.getTopic().getShortDescription() != null)
1132:                        && (selectedTopic.getTopic().getShortDescription()
1133:                                .length() > 255)) {
1134:                    setErrorMessage(getResourceBundleString(SHORT_DESC_TOO_LONG));
1135:                    return null;
1136:                }
1137:
1138:                setPermissionMode(PERMISSION_MODE_TOPIC);
1139:                if (selectedTopic != null
1140:                        && selectedTopic.getTopic() != null
1141:                        && (selectedTopic.getTopic().getTitle() == null || selectedTopic
1142:                                .getTopic().getTitle().trim().length() < 1)) {
1143:                    setErrorMessage(getResourceBundleString(VALID_TOPIC_TITLE_WARN));
1144:                    return TOPIC_SETTING_REVISE;
1145:                }
1146:
1147:                // if the topic is not moderated, all of the messages must be approved
1148:                if (selectedTopic != null
1149:                        && selectedTopic.getTopic().getId() != null
1150:                        && !selectedTopic.isTopicModerated()) {
1151:                    forumManager.approveAllPendingMessages(selectedTopic
1152:                            .getTopic().getId());
1153:                }
1154:                saveTopicSettings(false);
1155:
1156:                return processReturnToOriginatingPage();
1157:                //reset();
1158:                //return MAIN;
1159:            }
1160:
1161:            /**
1162:             * @return
1163:             */
1164:            public String processActionSaveTopicAsDraft() {
1165:                LOG.debug("processActionSaveTopicAsDraft()");
1166:
1167:                if (selectedTopic != null
1168:                        && selectedTopic.getTopic() != null
1169:                        && (selectedTopic.getTopic().getShortDescription() != null)
1170:                        && (selectedTopic.getTopic().getShortDescription()
1171:                                .length() > 255)) {
1172:                    setErrorMessage(getResourceBundleString(SHORT_DESC_TOO_LONG));
1173:                    return null;
1174:                }
1175:
1176:                setPermissionMode(PERMISSION_MODE_TOPIC);
1177:                if (selectedTopic != null
1178:                        && selectedTopic.getTopic() != null
1179:                        && (selectedTopic.getTopic().getTitle() == null || selectedTopic
1180:                                .getTopic().getTitle().trim().length() < 1)) {
1181:                    setErrorMessage(getResourceBundleString(VALID_TOPIC_TITLE_WARN));
1182:                    return TOPIC_SETTING_REVISE;
1183:                }
1184:                if (!uiPermissionsManager.isChangeSettings(selectedTopic
1185:                        .getTopic(), selectedForum.getForum())) {
1186:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_NEW_TOPIC));
1187:                    return gotoMain();
1188:                }
1189:                saveTopicSettings(true);
1190:                //reset();
1191:                //return MAIN;
1192:
1193:                return processReturnToOriginatingPage();
1194:            }
1195:
1196:            private String saveTopicSettings(boolean draft) {
1197:                LOG.debug("saveTopicSettings(" + draft + ")");
1198:                setPermissionMode(PERMISSION_MODE_TOPIC);
1199:                if (selectedTopic != null) {
1200:                    DiscussionTopic topic = selectedTopic.getTopic();
1201:                    if (selectedForum != null) {
1202:                        topic.setBaseForum(selectedForum.getForum());
1203:                        saveTopicSelectedAssignment(topic);
1204:                        saveTopicAttach(topic);
1205:                        setObjectPermissions(topic);
1206:                        if (draft) {
1207:                            forumManager.saveTopicAsDraft(topic);
1208:                        } else {
1209:                            forumManager.saveTopic(topic);
1210:                        }
1211:                        //forumManager
1212:                        //    .saveTopicControlPermissions(topic, topicControlPermissions);
1213:                        //forumManager
1214:                        //    .saveTopicMessagePermissions(topic, topicMessagePermissions);
1215:                    }
1216:                }
1217:                return gotoMain();
1218:            }
1219:
1220:            /**
1221:             * @return
1222:             */
1223:            public String processActionDeleteTopicConfirm() {
1224:                LOG.debug("processActionDeleteTopicConfirm()");
1225:
1226:                if (selectedTopic == null) {
1227:                    LOG.debug("There is no topic selected for deletion");
1228:                    return gotoMain();
1229:                }
1230:                if (!uiPermissionsManager.isChangeSettings(selectedTopic
1231:                        .getTopic(), selectedForum.getForum())) {
1232:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_NEW_TOPIC));
1233:                    return gotoMain();
1234:                }
1235:                selectedTopic.setMarkForDeletion(true);
1236:                return TOPIC_SETTING;
1237:            }
1238:
1239:            /**
1240:             * @return
1241:             */
1242:            public String processActionDeleteTopic() {
1243:                LOG.debug("processActionDeleteTopic()");
1244:                if (selectedTopic == null) {
1245:                    LOG.debug("There is no topic selected for deletion");
1246:                }
1247:                if (!uiPermissionsManager.isChangeSettings(selectedTopic
1248:                        .getTopic(), selectedForum.getForum())) {
1249:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_NEW_TOPIC));
1250:                    return gotoMain();
1251:                }
1252:                forumManager.deleteTopic(selectedTopic.getTopic());
1253:                reset();
1254:                return gotoMain();
1255:            }
1256:
1257:            /**
1258:             * @return
1259:             */
1260:            public String processActionTopicSettings() {
1261:                LOG.debug("processActionTopicSettings()");
1262:
1263:                setEditMode(true);
1264:                setPermissionMode(PERMISSION_MODE_TOPIC);
1265:                DiscussionTopic topic = null;
1266:                if (getExternalParameterByKey(TOPIC_ID) != ""
1267:                        && getExternalParameterByKey(TOPIC_ID) != null) {
1268:                    topic = (DiscussionTopic) forumManager
1269:                            .getTopicByIdWithAttachments(new Long(
1270:                                    getExternalParameterByKey(TOPIC_ID)));
1271:                } else if (selectedTopic != null) {
1272:                    topic = selectedTopic.getTopic();
1273:                }
1274:                if (topic == null) {
1275:                    return gotoMain();
1276:                }
1277:                setSelectedForumForCurrentTopic(topic);
1278:                if (!uiPermissionsManager.isChangeSettings(topic, selectedForum
1279:                        .getForum())) {
1280:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_NEW_TOPIC));
1281:                    return gotoMain();
1282:                }
1283:                selectedTopic = new DiscussionTopicBean(topic, selectedForum
1284:                        .getForum(), uiPermissionsManager, forumManager);
1285:                if ("true".equalsIgnoreCase(ServerConfigurationService
1286:                        .getString("mc.defaultLongDescription"))) {
1287:                    selectedTopic.setReadFullDesciption(true);
1288:                }
1289:
1290:                List attachList = selectedTopic.getTopic().getAttachments();
1291:                if (attachList != null) {
1292:                    for (int i = 0; i < attachList.size(); i++) {
1293:                        attachments.add(new DecoratedAttachment(
1294:                                (Attachment) attachList.get(i)));
1295:                    }
1296:                }
1297:
1298:                setTopicBeanAssign();
1299:                setFromMainOrForumOrTopic();
1300:
1301:                //return TOPIC_SETTING;
1302:                return TOPIC_SETTING_REVISE;
1303:            }
1304:
1305:            public String processActionToggleDisplayForumExtendedDescription() {
1306:                LOG
1307:                        .debug("processActionToggleDisplayForumExtendedDescription()");
1308:                String redirectTo = getExternalParameterByKey(REDIRECT_PROCESS_ACTION);
1309:                if (redirectTo == null) {
1310:                    setErrorMessage(getResourceBundleString(NOT_FOUND_REDIRECT_PAGE));
1311:                    return gotoMain();
1312:                }
1313:
1314:                if (redirectTo.equals("displayHome")) {
1315:                    displayHomeWithExtendedForumDescription();
1316:                    return gotoMain();
1317:                }
1318:                if (redirectTo.equals("processActionDisplayForum")) {
1319:                    if (selectedForum.isReadFullDesciption()) {
1320:                        selectedForum.setReadFullDesciption(false);
1321:                    } else {
1322:                        selectedForum.setReadFullDesciption(true);
1323:                    }
1324:                    return FORUM_DETAILS;
1325:                }
1326:                return gotoMain();
1327:            }
1328:
1329:            /**
1330:             * @return
1331:             */
1332:            public String processActionToggleDisplayExtendedDescription() {
1333:                LOG.debug("processActionToggleDisplayExtendedDescription()");
1334:                String redirectTo = getExternalParameterByKey(REDIRECT_PROCESS_ACTION);
1335:                if (redirectTo == null) {
1336:                    setErrorMessage(getResourceBundleString(NOT_FOUND_REDIRECT_PAGE));
1337:                    return gotoMain();
1338:                }
1339:                if (redirectTo.equals("displayHome")) {
1340:                    return displayHomeWithExtendedTopicDescription();
1341:                }
1342:                if (redirectTo.equals("processActionDisplayTopic")) {
1343:                    if (selectedTopic.isReadFullDesciption()) {
1344:                        selectedTopic.setReadFullDesciption(false);
1345:                    } else {
1346:                        selectedTopic.setReadFullDesciption(true);
1347:                    }
1348:                    return ALL_MESSAGES;
1349:                }
1350:                if (redirectTo.equals("processActionDisplayMessage")) {
1351:                    if (selectedTopic.isReadFullDesciption()) {
1352:                        selectedTopic.setReadFullDesciption(false);
1353:                    } else {
1354:                        selectedTopic.setReadFullDesciption(true);
1355:                    }
1356:                    return MESSAGE_VIEW;
1357:                }
1358:                if (redirectTo.equals("processActionGradeMessage")) {
1359:                    if (selectedTopic.isReadFullDesciption()) {
1360:                        selectedTopic.setReadFullDesciption(false);
1361:                    } else {
1362:                        selectedTopic.setReadFullDesciption(true);
1363:                    }
1364:                    return GRADE_MESSAGE;
1365:                }
1366:
1367:                return gotoMain();
1368:
1369:            }
1370:
1371:            /**
1372:             * @return
1373:             */
1374:            public String processActionDisplayTopic() {
1375:                LOG.debug("processActionDisplayTopic()");
1376:
1377:                return displayTopicById(TOPIC_ID);
1378:            }
1379:
1380:            /**
1381:             * @return
1382:             */
1383:            public String processActionDisplayNextTopic() {
1384:                LOG.debug("processActionDisplayNextTopic()");
1385:                return displayTopicById("nextTopicId");
1386:            }
1387:
1388:            /**
1389:             * @return
1390:             */
1391:            public String processActionDisplayPreviousTopic() {
1392:                LOG.debug("processActionDisplayNextTopic()");
1393:                return displayTopicById("previousTopicId");
1394:            }
1395:
1396:            /**
1397:             * @return Returns the selectedMessage.
1398:             */
1399:            public DiscussionMessageBean getSelectedMessage() {
1400:                return selectedMessage;
1401:            }
1402:
1403:            /**
1404:             * @return Returns the selectedThread.
1405:             */
1406:            public DiscussionMessageBean getSelectedThreadHead() {
1407:                return selectedThreadHead;
1408:            }
1409:
1410:            /**
1411:             * @return Returns an array of Messages for the current selected thread
1412:             */
1413:            public List getSelectedThread() {
1414:                List returnArray = new ArrayList();
1415:                returnArray = selectedThread;
1416:                if (displayUnreadOnly) {
1417:                    ArrayList tempmes = new ArrayList();
1418:                    for (int i = returnArray.size() - 1; i >= 0; i--) {
1419:                        if (!((DiscussionMessageBean) returnArray.get(i))
1420:                                .isRead()) {
1421:                            tempmes.add(returnArray.get(i));
1422:                        }
1423:                    }
1424:                    returnArray = tempmes;
1425:                }
1426:                if (!orderAsc) {
1427:                    ArrayList tempmes = new ArrayList();
1428:                    for (int i = returnArray.size() - 1; i >= 0; i--) {
1429:                        tempmes.add(returnArray.get(i));
1430:                    }
1431:                    return tempmes;
1432:                } else
1433:                    return returnArray;
1434:            }
1435:
1436:            /**
1437:             * @return
1438:             */
1439:            public String processActionDisplayFlatView() {
1440:                return FLAT_VIEW;
1441:            }
1442:
1443:            /**
1444:             * @return
1445:             */
1446:            public String processActionDisplayThreadedView() {
1447:                return ALL_MESSAGES;
1448:            }
1449:
1450:            public String processActionGetDisplayThread() {
1451:                selectedTopic = getDecoratedTopic(selectedTopic.getTopic());
1452:
1453:                setTopicBeanAssign();
1454:                getSelectedTopic();
1455:
1456:                List msgsList = selectedTopic.getMessages();
1457:
1458:                if (msgsList != null && !msgsList.isEmpty())
1459:                    msgsList = filterModeratedMessages(msgsList, selectedTopic
1460:                            .getTopic(), (DiscussionForum) selectedTopic
1461:                            .getTopic().getBaseForum());
1462:
1463:                List orderedList = new ArrayList();
1464:                selectedThread = new ArrayList();
1465:
1466:                Boolean foundHead = false;
1467:                Boolean foundAfterHead = false;
1468:
1469:                //determine to make sure that selectedThreadHead does exist!
1470:                if (selectedThreadHead == null) {
1471:                    return MAIN;
1472:                }
1473:
1474:                for (int i = 0; i < msgsList.size(); i++) {
1475:                    if (((DiscussionMessageBean) msgsList.get(i)).getMessage()
1476:                            .getId().equals(
1477:                                    selectedThreadHead.getMessage().getId())) {
1478:                        ((DiscussionMessageBean) msgsList.get(i)).setDepth(0);
1479:                        selectedThread.add((DiscussionMessageBean) msgsList
1480:                                .get(i));
1481:                        foundHead = true;
1482:                    } else if (((DiscussionMessageBean) msgsList.get(i))
1483:                            .getMessage().getInReplyTo() == null
1484:                            && foundHead && !foundAfterHead) {
1485:                        selectedThreadHead.setHasNextThread(true);
1486:                        selectedThreadHead
1487:                                .setNextThreadId(((DiscussionMessageBean) msgsList
1488:                                        .get(i)).getMessage().getId());
1489:                        foundAfterHead = true;
1490:                    } else if (((DiscussionMessageBean) msgsList.get(i))
1491:                            .getMessage().getInReplyTo() == null
1492:                            && !foundHead) {
1493:                        selectedThreadHead.setHasPreThread(true);
1494:                        selectedThreadHead
1495:                                .setPreThreadId(((DiscussionMessageBean) msgsList
1496:                                        .get(i)).getMessage().getId());
1497:                    }
1498:                }
1499:
1500:                recursiveGetThreadedMsgs(msgsList, orderedList,
1501:                        selectedThreadHead);
1502:                selectedThread.addAll(orderedList);
1503:
1504:                return THREAD_VIEW;
1505:            }
1506:
1507:            /**
1508:             * @return
1509:             */
1510:            public String processActionDisplayThread() {
1511:                LOG.debug("processActionDisplayThread()");
1512:
1513:                threadAnchorMessageId = null;
1514:                String threadId = getExternalParameterByKey(MESSAGE_ID);
1515:                String topicId = getExternalParameterByKey(TOPIC_ID);
1516:                if (threadId == "") {
1517:                    setErrorMessage(getResourceBundleString(MESSAGE_REFERENCE_NOT_FOUND));
1518:                    return gotoMain();
1519:                }
1520:                if (topicId == "") {
1521:                    setErrorMessage(getResourceBundleString(TOPC_REFERENCE_NOT_FOUND));
1522:                    return gotoMain();
1523:                }
1524:                // Message message=forumManager.getMessageById(new Long(messageId));
1525:                Message threadMessage = messageManager
1526:                        .getMessageByIdWithAttachments(new Long(threadId));
1527:                if (threadMessage == null) {
1528:                    setErrorMessage(getResourceBundleString(MESSAGE_WITH_ID)
1529:                            + threadId
1530:                            + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
1531:                    return gotoMain();
1532:                }
1533:                //threadMessage = messageManager.getMessageByIdWithAttachments(threadMessage.getId());
1534:                selectedThreadHead = new DiscussionMessageBean(threadMessage,
1535:                        messageManager);
1536:                //make sure we have the thread head of depth 0
1537:                while (selectedThreadHead.getMessage().getInReplyTo() != null) {
1538:                    threadMessage = messageManager
1539:                            .getMessageByIdWithAttachments(selectedThreadHead
1540:                                    .getMessage().getInReplyTo().getId());
1541:                    selectedThreadHead = new DiscussionMessageBean(
1542:                            threadMessage, messageManager);
1543:                }
1544:                DiscussionTopic topic = forumManager.getTopicById(new Long(
1545:                        getExternalParameterByKey(TOPIC_ID)));
1546:                selectedMessage = selectedThreadHead;
1547:                setSelectedForumForCurrentTopic(topic);
1548:                selectedTopic = new DiscussionTopicBean(topic, selectedForum
1549:                        .getForum(), uiPermissionsManager, forumManager);
1550:                if ("true".equalsIgnoreCase(ServerConfigurationService
1551:                        .getString("mc.defaultLongDescription"))) {
1552:                    selectedTopic.setReadFullDesciption(true);
1553:                }
1554:                setTopicBeanAssign();
1555:                String currentForumId = getExternalParameterByKey(FORUM_ID);
1556:                if (currentForumId != null
1557:                        && (!currentForumId.trim().equals(""))
1558:                        && (!currentForumId.trim().equals("null"))) {
1559:                    DiscussionForum forum = forumManager.getForumById(new Long(
1560:                            currentForumId));
1561:                    selectedForum = getDecoratedForum(forum);
1562:                    setForumBeanAssign();
1563:                    selectedTopic.getTopic().setBaseForum(forum);
1564:                }
1565:                selectedTopic = getDecoratedTopic(forumManager
1566:                        .getTopicById(new Long(
1567:                                getExternalParameterByKey(TOPIC_ID))));
1568:
1569:                return processActionGetDisplayThread();
1570:            }
1571:
1572:            /**
1573:             * @return
1574:             */
1575:            public String processActionDisplayThreadAnchor() {
1576:                String returnString = processActionDisplayThread();
1577:                threadAnchorMessageId = getExternalParameterByKey(MESSAGE_ID);
1578:                return returnString;
1579:            }
1580:
1581:            /**
1582:             * @return
1583:             */
1584:            public String processActionDisplayMessage() {
1585:                LOG.debug("processActionDisplayMessage()");
1586:
1587:                String messageId = getExternalParameterByKey(MESSAGE_ID);
1588:                String topicId = getExternalParameterByKey(TOPIC_ID);
1589:                if (messageId == null) {
1590:                    setErrorMessage(getResourceBundleString(MESSAGE_REFERENCE_NOT_FOUND));
1591:                    return gotoMain();
1592:                }
1593:                if (topicId == null) {
1594:                    setErrorMessage(getResourceBundleString(TOPC_REFERENCE_NOT_FOUND));
1595:                    return gotoMain();
1596:                }
1597:                // Message message=forumManager.getMessageById(new Long(messageId));
1598:                Message message = messageManager
1599:                        .getMessageByIdWithAttachments(new Long(messageId));
1600:                messageManager.markMessageReadForUser(new Long(topicId),
1601:                        new Long(messageId), true);
1602:                if (message == null) {
1603:                    setErrorMessage(getResourceBundleString(MESSAGE_WITH_ID)
1604:                            + messageId
1605:                            + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
1606:                    return gotoMain();
1607:                }
1608:                message = messageManager.getMessageByIdWithAttachments(message
1609:                        .getId());
1610:                selectedMessage = new DiscussionMessageBean(message,
1611:                        messageManager);
1612:                DiscussionTopic topic = forumManager.getTopicById(new Long(
1613:                        getExternalParameterByKey(TOPIC_ID)));
1614:                setSelectedForumForCurrentTopic(topic);
1615:                selectedTopic = new DiscussionTopicBean(topic, selectedForum
1616:                        .getForum(), uiPermissionsManager, forumManager);
1617:                if ("true".equalsIgnoreCase(ServerConfigurationService
1618:                        .getString("mc.defaultLongDescription"))) {
1619:                    selectedTopic.setReadFullDesciption(true);
1620:                }
1621:                setTopicBeanAssign();
1622:                String currentForumId = getExternalParameterByKey(FORUM_ID);
1623:                if (currentForumId != null
1624:                        && (!currentForumId.trim().equals(""))
1625:                        && (!currentForumId.trim().equals("null"))) {
1626:                    DiscussionForum forum = forumManager.getForumById(new Long(
1627:                            currentForumId));
1628:                    selectedForum = getDecoratedForum(forum);
1629:                    setForumBeanAssign();
1630:                    selectedTopic.getTopic().setBaseForum(forum);
1631:                }
1632:                selectedTopic = getDecoratedTopic(forumManager
1633:                        .getTopicById(new Long(
1634:                                getExternalParameterByKey(TOPIC_ID))));
1635:                setTopicBeanAssign();
1636:                getSelectedTopic();
1637:                //get thread from message
1638:                getThreadFromMessage();
1639:                selectedMessage.setRevise(selectedTopic.getIsReviseAny()
1640:                        || (selectedTopic.getIsReviseOwn() && message
1641:                                .getCreatedBy().equals(
1642:                                        UserDirectoryService.getCurrentUser()
1643:                                                .getId())));
1644:                // selectedTopic= new DiscussionTopicBean(message.getTopic());
1645:                return MESSAGE_VIEW;
1646:            }
1647:
1648:            public void getThreadFromMessage() {
1649:                Message mes = selectedMessage.getMessage();
1650:                String messageId = mes.getId().toString();
1651:                while (mes.getInReplyTo() != null) {
1652:                    mes = messageManager.getMessageById(mes.getInReplyTo()
1653:                            .getId());
1654:                }
1655:                selectedThreadHead = new DiscussionMessageBean(mes,
1656:                        messageManager);
1657:
1658:                List tempMsgs = selectedTopic.getMessages();
1659:                Boolean foundHead = false;
1660:                Boolean foundAfterHead = false;
1661:                if (tempMsgs != null) {
1662:                    for (int i = 0; i < tempMsgs.size(); i++) {
1663:                        DiscussionMessageBean this Dmb = (DiscussionMessageBean) tempMsgs
1664:                                .get(i);
1665:                        if (((DiscussionMessageBean) tempMsgs.get(i))
1666:                                .getMessage().getId().toString().equals(
1667:                                        messageId)) {
1668:                            selectedMessage.setDepth(this Dmb.getDepth());
1669:                            selectedMessage.setHasNext(this Dmb.getHasNext());
1670:                            selectedMessage.setHasPre(this Dmb.getHasPre());
1671:                            foundHead = true;
1672:                        } else if (((DiscussionMessageBean) tempMsgs.get(i))
1673:                                .getMessage().getInReplyTo() == null
1674:                                && foundHead && !foundAfterHead) {
1675:                            selectedThreadHead.setHasNextThread(true);
1676:                            selectedThreadHead
1677:                                    .setNextThreadId(((DiscussionMessageBean) tempMsgs
1678:                                            .get(i)).getMessage().getId());
1679:                            foundAfterHead = true;
1680:                        } else if (((DiscussionMessageBean) tempMsgs.get(i))
1681:                                .getMessage().getInReplyTo() == null
1682:                                && !foundHead) {
1683:                            selectedThreadHead.setHasPreThread(true);
1684:                            selectedThreadHead
1685:                                    .setPreThreadId(((DiscussionMessageBean) tempMsgs
1686:                                            .get(i)).getMessage().getId());
1687:                        }
1688:                    }
1689:                }
1690:            }
1691:
1692:            public String processDisplayPreviousMsg() {
1693:                List tempMsgs = selectedTopic.getMessages();
1694:                int currentMsgPosition = -1;
1695:                if (tempMsgs != null) {
1696:                    for (int i = 0; i < tempMsgs.size(); i++) {
1697:                        DiscussionMessageBean this Dmb = (DiscussionMessageBean) tempMsgs
1698:                                .get(i);
1699:                        if (selectedMessage.getMessage().getId().equals(
1700:                                this Dmb.getMessage().getId())) {
1701:                            currentMsgPosition = i;
1702:                            break;
1703:                        }
1704:                    }
1705:                }
1706:
1707:                if (currentMsgPosition > 0) {
1708:                    DiscussionMessageBean this Dmb = (DiscussionMessageBean) tempMsgs
1709:                            .get(currentMsgPosition - 1);
1710:                    Message message = messageManager
1711:                            .getMessageByIdWithAttachments(this Dmb.getMessage()
1712:                                    .getId());
1713:                    selectedMessage = new DiscussionMessageBean(message,
1714:                            messageManager);
1715:                    selectedMessage.setDepth(this Dmb.getDepth());
1716:                    selectedMessage.setHasNext(this Dmb.getHasNext());
1717:                    selectedMessage.setHasPre(this Dmb.getHasPre());
1718:
1719:                    messageManager.markMessageReadForUser(selectedTopic
1720:                            .getTopic().getId(), selectedMessage.getMessage()
1721:                            .getId(), true);
1722:                }
1723:
1724:                return null;
1725:            }
1726:
1727:            public String processDfDisplayNextMsg() {
1728:                List tempMsgs = selectedTopic.getMessages();
1729:                int currentMsgPosition = -1;
1730:                if (tempMsgs != null) {
1731:                    for (int i = 0; i < tempMsgs.size(); i++) {
1732:                        DiscussionMessageBean this Dmb = (DiscussionMessageBean) tempMsgs
1733:                                .get(i);
1734:                        if (selectedMessage.getMessage().getId().equals(
1735:                                this Dmb.getMessage().getId())) {
1736:                            currentMsgPosition = i;
1737:                            break;
1738:                        }
1739:                    }
1740:                }
1741:
1742:                if (currentMsgPosition > -2
1743:                        && currentMsgPosition < (tempMsgs.size() - 1)) {
1744:                    DiscussionMessageBean this Dmb = (DiscussionMessageBean) tempMsgs
1745:                            .get(currentMsgPosition + 1);
1746:                    Message message = messageManager
1747:                            .getMessageByIdWithAttachments(this Dmb.getMessage()
1748:                                    .getId());
1749:                    selectedMessage = new DiscussionMessageBean(message,
1750:                            messageManager);
1751:                    selectedMessage.setDepth(this Dmb.getDepth());
1752:                    selectedMessage.setHasNext(this Dmb.getHasNext());
1753:                    selectedMessage.setHasPre(this Dmb.getHasPre());
1754:
1755:                    messageManager.markMessageReadForUser(selectedTopic
1756:                            .getTopic().getId(), selectedMessage.getMessage()
1757:                            .getId(), true);
1758:                }
1759:
1760:                return null;
1761:            }
1762:
1763:            // **************************************** helper methods**********************************
1764:
1765:            private String getExternalParameterByKey(String parameterId) {
1766:                ExternalContext context = FacesContext.getCurrentInstance()
1767:                        .getExternalContext();
1768:                Map paramMap = context.getRequestParameterMap();
1769:
1770:                return (String) paramMap.get(parameterId);
1771:            }
1772:
1773:            /**
1774:             * @param forum
1775:             * @return List of DiscussionTopicBean
1776:             */
1777:            private DiscussionForumBean getDecoratedForum(DiscussionForum forum) {
1778:                if (LOG.isDebugEnabled()) {
1779:                    LOG
1780:                            .debug("getDecoratedForum(DiscussionForum" + forum
1781:                                    + ")");
1782:                }
1783:                forum = forumManager.getForumByIdWithTopics(forum.getId());
1784:                DiscussionForumBean decoForum = new DiscussionForumBean(forum,
1785:                        uiPermissionsManager, forumManager);
1786:                if ("true".equalsIgnoreCase(ServerConfigurationService
1787:                        .getString("mc.defaultLongDescription"))) {
1788:                    decoForum.setReadFullDesciption(true);
1789:                }
1790:                List temp_topics = forum.getTopics();
1791:                if (temp_topics == null) {
1792:                    return decoForum;
1793:                }
1794:                Iterator iter = temp_topics.iterator();
1795:                while (iter.hasNext()) {
1796:                    DiscussionTopic topic = (DiscussionTopic) iter.next();
1797:                    //    TODO: put this logic in database layer
1798:                    if (topic.getDraft().equals(Boolean.FALSE)
1799:                            || (topic.getDraft().equals(Boolean.TRUE) && topic
1800:                                    .getCreatedBy().equals(
1801:                                            SessionManager
1802:                                                    .getCurrentSessionUserId()))
1803:                            || isInstructor()
1804:                            || SecurityService.isSuperUser()
1805:                            || topic.getCreatedBy().equals(
1806:                                    SessionManager.getCurrentSessionUserId())) {
1807:                        topic = (DiscussionTopic) forumManager
1808:                                .getTopicByIdWithAttachments(topic.getId());
1809:                        if (topic != null) {
1810:                            DiscussionTopicBean decoTopic = new DiscussionTopicBean(
1811:                                    topic, forum, uiPermissionsManager,
1812:                                    forumManager);
1813:                            if ("true"
1814:                                    .equalsIgnoreCase(ServerConfigurationService
1815:                                            .getString("mc.defaultLongDescription"))) {
1816:                                decoTopic.setReadFullDesciption(true);
1817:                            }
1818:                            if (uiPermissionsManager.isModeratePostings(topic,
1819:                                    forum)) {
1820:                                decoTopic.setTotalNoMessages(forumManager
1821:                                        .getTotalNoMessages(topic));
1822:                                decoTopic.setUnreadNoMessages(forumManager
1823:                                        .getUnreadNoMessages(topic));
1824:                            } else {
1825:                                decoTopic
1826:                                        .setTotalNoMessages(forumManager
1827:                                                .getTotalViewableMessagesWhenMod(topic));
1828:                                decoTopic
1829:                                        .setUnreadNoMessages(forumManager
1830:                                                .getNumUnreadViewableMessagesWhenMod(topic));
1831:                            }
1832:                            decoForum.addTopic(decoTopic);
1833:                        }
1834:                    }
1835:                }
1836:                return decoForum;
1837:            }
1838:
1839:            private DiscussionForumBean getDecoratedForumWithPersistentForumAndTopics(
1840:                    DiscussionForum forum) {
1841:                if (LOG.isDebugEnabled()) {
1842:                    LOG
1843:                            .debug("getDecoratedForum(DiscussionForum" + forum
1844:                                    + ")");
1845:                }
1846:                DiscussionForumBean decoForum = new DiscussionForumBean(forum,
1847:                        uiPermissionsManager, forumManager);
1848:                if ("true".equalsIgnoreCase(ServerConfigurationService
1849:                        .getString("mc.defaultLongDescription"))) {
1850:                    decoForum.setReadFullDesciption(true);
1851:                }
1852:                List temp_topics = forum.getTopics();
1853:                if (temp_topics == null) {
1854:                    return decoForum;
1855:                }
1856:                Iterator iter = temp_topics.iterator();
1857:                while (iter.hasNext()) {
1858:                    DiscussionTopic topic = (DiscussionTopic) iter.next();
1859:                    //    TODO: put this logic in database layer
1860:                    if (topic.getDraft().equals(Boolean.FALSE)
1861:                            || (topic.getDraft().equals(Boolean.TRUE) && topic
1862:                                    .getCreatedBy().equals(
1863:                                            SessionManager
1864:                                                    .getCurrentSessionUserId()))
1865:                            || isInstructor()
1866:                            || SecurityService.isSuperUser()
1867:                            || topic.getCreatedBy().equals(
1868:                                    SessionManager.getCurrentSessionUserId())) {
1869:                        if (topic != null) {
1870:                            DiscussionTopicBean decoTopic = new DiscussionTopicBean(
1871:                                    topic, forum, uiPermissionsManager,
1872:                                    forumManager);
1873:                            if ("true"
1874:                                    .equalsIgnoreCase(ServerConfigurationService
1875:                                            .getString("mc.defaultLongDescription"))) {
1876:                                decoTopic.setReadFullDesciption(true);
1877:                            }
1878:
1879:                            if (uiPermissionsManager.isModeratePostings(topic,
1880:                                    forum)) {
1881:                                decoTopic.setTotalNoMessages(forumManager
1882:                                        .getTotalNoMessages(topic));
1883:                                decoTopic.setUnreadNoMessages(forumManager
1884:                                        .getUnreadNoMessages(topic));
1885:                            } else {
1886:                                decoTopic
1887:                                        .setTotalNoMessages(forumManager
1888:                                                .getTotalViewableMessagesWhenMod(topic));
1889:                                decoTopic
1890:                                        .setUnreadNoMessages(forumManager
1891:                                                .getNumUnreadViewableMessagesWhenMod(topic));
1892:                            }
1893:
1894:                            decoForum.addTopic(decoTopic);
1895:                        }
1896:                    }
1897:                }
1898:                return decoForum;
1899:            }
1900:
1901:            /**
1902:             * @return DiscussionForumBean
1903:             */
1904:            private DiscussionForumBean getDecoratedForum() {
1905:                LOG.debug("decorateSelectedForum()");
1906:                String forumId = getExternalParameterByKey(FORUM_ID);
1907:                if ((forumId) != null) {
1908:                    DiscussionForum forum = forumManager.getForumById(new Long(
1909:                            forumId));
1910:                    if (forum == null) {
1911:                        return null;
1912:                    }
1913:                    selectedForum = getDecoratedForum(forum);
1914:                    return selectedForum;
1915:                }
1916:                return null;
1917:            }
1918:
1919:            /**
1920:             * @return
1921:             */
1922:            private String displayHomeWithExtendedForumDescription() {
1923:                LOG.debug("displayHomeWithExtendedForumDescription()");
1924:                List tmpForums = getForums();
1925:                if (tmpForums != null) {
1926:                    Iterator iter = tmpForums.iterator();
1927:                    while (iter.hasNext()) {
1928:                        DiscussionForumBean decoForumBean = (DiscussionForumBean) iter
1929:                                .next();
1930:                        if (decoForumBean != null) {
1931:                            // if this forum is selected to display full desciption
1932:                            if (getExternalParameterByKey("forumId_displayExtended") != null
1933:                                    && getExternalParameterByKey(
1934:                                            "forumId_displayExtended").trim()
1935:                                            .length() > 0
1936:                                    && decoForumBean
1937:                                            .getForum()
1938:                                            .getId()
1939:                                            .equals(
1940:                                                    new Long(
1941:                                                            getExternalParameterByKey("forumId_displayExtended")))) {
1942:                                decoForumBean.setReadFullDesciption(true);
1943:                            }
1944:                            // if this topic is selected to display hide extended desciption
1945:                            if (getExternalParameterByKey("forumId_hideExtended") != null
1946:                                    && getExternalParameterByKey(
1947:                                            "forumId_hideExtended").trim()
1948:                                            .length() > 0
1949:                                    && decoForumBean
1950:                                            .getForum()
1951:                                            .getId()
1952:                                            .equals(
1953:                                                    new Long(
1954:                                                            getExternalParameterByKey("forumId_hideExtended")))) {
1955:                                decoForumBean.setReadFullDesciption(false);
1956:                            }
1957:
1958:                        }
1959:                    }
1960:
1961:                }
1962:                return gotoMain();
1963:            }
1964:
1965:            /**
1966:             * @return
1967:             */
1968:            private String displayHomeWithExtendedTopicDescription() {
1969:                LOG.debug("displayHomeWithExtendedTopicDescription()");
1970:                List tmpForums = getForums();
1971:                if (tmpForums != null) {
1972:                    Iterator iter = tmpForums.iterator();
1973:                    while (iter.hasNext()) {
1974:                        DiscussionForumBean decoForumBean = (DiscussionForumBean) iter
1975:                                .next();
1976:                        if (decoForumBean != null) {
1977:                            List tmpTopics = decoForumBean.getTopics();
1978:                            Iterator iter2 = tmpTopics.iterator();
1979:                            while (iter2.hasNext()) {
1980:                                DiscussionTopicBean decoTopicBean = (DiscussionTopicBean) iter2
1981:                                        .next();
1982:                                if (decoTopicBean != null) {
1983:                                    // if this topic is selected to display full desciption
1984:                                    if (getExternalParameterByKey("topicId_displayExtended") != null
1985:                                            && getExternalParameterByKey(
1986:                                                    "topicId_displayExtended")
1987:                                                    .trim().length() > 0
1988:                                            && decoTopicBean
1989:                                                    .getTopic()
1990:                                                    .getId()
1991:                                                    .equals(
1992:                                                            new Long(
1993:                                                                    getExternalParameterByKey("topicId_displayExtended")))) {
1994:                                        decoTopicBean
1995:                                                .setReadFullDesciption(true);
1996:                                    }
1997:                                    // if this topic is selected to display hide extended desciption
1998:                                    if (getExternalParameterByKey("topicId_hideExtended") != null
1999:                                            && getExternalParameterByKey(
2000:                                                    "topicId_hideExtended")
2001:                                                    .trim().length() > 0
2002:                                            && decoTopicBean
2003:                                                    .getTopic()
2004:                                                    .getId()
2005:                                                    .equals(
2006:                                                            new Long(
2007:                                                                    getExternalParameterByKey("topicId_hideExtended")))) {
2008:                                        decoTopicBean
2009:                                                .setReadFullDesciption(false);
2010:                                    }
2011:                                }
2012:                            }
2013:                        }
2014:                    }
2015:
2016:                }
2017:                return gotoMain();
2018:            }
2019:
2020:            /**
2021:             * @param topic
2022:             * @return
2023:             */
2024:            private DiscussionTopicBean getDecoratedTopic(DiscussionTopic topic) {
2025:                if (LOG.isDebugEnabled()) {
2026:                    LOG.debug("getDecoratedTopic(DiscussionTopic " + topic
2027:                            + ")");
2028:                }
2029:                DiscussionTopicBean decoTopic = new DiscussionTopicBean(topic,
2030:                        selectedForum.getForum(), uiPermissionsManager,
2031:                        forumManager);
2032:                if ("true".equalsIgnoreCase(ServerConfigurationService
2033:                        .getString("mc.defaultLongDescription"))) {
2034:                    decoTopic.setReadFullDesciption(true);
2035:                }
2036:                if (!decoTopic.isTopicModerated()
2037:                        || decoTopic.getIsModeratedAndHasPerm()) {
2038:                    decoTopic.setTotalNoMessages(forumManager
2039:                            .getTotalNoMessages(topic));
2040:                    decoTopic.setUnreadNoMessages(forumManager
2041:                            .getUnreadNoMessages(topic));
2042:                } else {
2043:                    decoTopic.setTotalNoMessages(forumManager
2044:                            .getTotalViewableMessagesWhenMod(topic));
2045:                    decoTopic.setUnreadNoMessages(forumManager
2046:                            .getNumUnreadViewableMessagesWhenMod(topic));
2047:                }
2048:                decoTopic.setHasNextTopic(forumManager.hasNextTopic(topic));
2049:                decoTopic.setHasPreviousTopic(forumManager
2050:                        .hasPreviousTopic(topic));
2051:                if (forumManager.hasNextTopic(topic)) {
2052:                    DiscussionTopic nextTopic = forumManager
2053:                            .getNextTopic(topic);
2054:
2055:                    decoTopic.setNextTopicId(nextTopic.getId());
2056:
2057:                }
2058:                if (forumManager.hasPreviousTopic(topic)) {
2059:                    decoTopic.setPreviousTopicId(forumManager.getPreviousTopic(
2060:                            topic).getId());
2061:
2062:                }
2063:
2064:                List temp_messages = forumManager
2065:                        .getTopicByIdWithMessagesAndAttachments(topic.getId())
2066:                        .getMessages();
2067:                if (temp_messages == null || temp_messages.size() < 1) {
2068:                    return decoTopic;
2069:                }
2070:
2071:                Iterator iter = temp_messages.iterator();
2072:
2073:                final boolean isRead = decoTopic.getIsRead();
2074:                final boolean isNewResponse = decoTopic.getIsNewResponse();
2075:
2076:                while (iter.hasNext()) {
2077:                    Message message = (Message) iter.next();
2078:                    if (topic != null) {
2079:                        if (message != null) {
2080:                            DiscussionMessageBean decoMsg = new DiscussionMessageBean(
2081:                                    message, messageManager);
2082:                            if (isRead || (isNewResponse && decoMsg.getIsOwn())) {
2083:                                decoMsg.setRead(messageManager
2084:                                        .isMessageReadForUser(topic.getId(),
2085:                                                message.getId()));
2086:                                decoMsg
2087:                                        .setRevise(decoTopic.getIsReviseAny()
2088:                                                || (decoTopic.getIsReviseOwn() && decoMsg
2089:                                                        .getMessage()
2090:                                                        .getCreatedBy()
2091:                                                        .equals(
2092:                                                                UserDirectoryService
2093:                                                                        .getCurrentUser()
2094:                                                                        .getId())));
2095:                                decoTopic.addMessage(decoMsg);
2096:                            }
2097:                        }
2098:
2099:                    }
2100:                }
2101:                return decoTopic;
2102:            }
2103:
2104:            private Boolean resetTopicById(String externalTopicId) {
2105:                String topicId = null;
2106:                //threaded = true;
2107:                selectedTopic = null;
2108:                try {
2109:                    topicId = getExternalParameterByKey(externalTopicId);
2110:
2111:                    if (topicId != null) {
2112:                        DiscussionTopic topic = null;
2113:                        try {
2114:                            Long.parseLong(topicId);
2115:                            topic = forumManager
2116:                                    .getTopicById(new Long(topicId));
2117:                        } catch (NumberFormatException e) {
2118:                            LOG.error(e.getMessage(), e);
2119:                            setErrorMessage(getResourceBundleString(UNABLE_RETRIEVE_TOPIC));
2120:                            return false;
2121:                        }
2122:
2123:                        setSelectedForumForCurrentTopic(topic);
2124:                        selectedTopic = getDecoratedTopic(topic);
2125:                    } else {
2126:                        LOG.error("Topic with id '" + externalTopicId
2127:                                + "' not found");
2128:                        setErrorMessage(getResourceBundleString(TOPIC_WITH_ID)
2129:                                + externalTopicId
2130:                                + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
2131:                        return false;
2132:                    }
2133:                } catch (Exception e) {
2134:                    LOG.error(e.getMessage(), e);
2135:                    setErrorMessage(e.getMessage());
2136:                    return false;
2137:                }
2138:                return true;
2139:            }
2140:
2141:            /**
2142:             * @param externalTopicId
2143:             * @return
2144:             */
2145:            private String displayTopicById(String externalTopicId) {
2146:                if (LOG.isDebugEnabled()) {
2147:                    LOG.debug("processActionDisplayTopicById(String"
2148:                            + externalTopicId + ")");
2149:                }
2150:                if (resetTopicById(externalTopicId)) {
2151:                    return ALL_MESSAGES;
2152:                } else {
2153:                    return gotoMain();
2154:                }
2155:            }
2156:
2157:            private void reset() {
2158:                this .forums = null;
2159:                this .selectedForum = null;
2160:                this .selectedTopic = null;
2161:                this .selectedMessage = null;
2162:                //    this.templateControlPermissions = null;
2163:                //    this.templateMessagePermissions = null;
2164:                this .permissions = null;
2165:                this .errorSynch = false;
2166:                this .siteMembers = null;
2167:                attachments.clear();
2168:                prepareRemoveAttach.clear();
2169:                assignments.clear();
2170:                refreshPendingMsgs = true;
2171:
2172:            }
2173:
2174:            /**
2175:             * @return newly created topic
2176:             */
2177:            private DiscussionTopicBean createTopic() {
2178:                String forumId = getExternalParameterByKey(FORUM_ID);
2179:                if (forumId == null) {
2180:                    setErrorMessage(getResourceBundleString(PARENT_TOPIC_NOT_FOUND));
2181:                    return null;
2182:                }
2183:                return createTopic(new Long(forumId));
2184:            }
2185:
2186:            /**
2187:             * @param forumID
2188:             * @return
2189:             */
2190:            private DiscussionTopicBean createTopic(Long forumId) {
2191:                if (forumId == null) {
2192:                    setErrorMessage(getResourceBundleString(PARENT_TOPIC_NOT_FOUND));
2193:                    return null;
2194:                }
2195:                DiscussionForum forum = forumManager.getForumById(forumId);
2196:                if (forum == null) {
2197:                    setErrorMessage(getResourceBundleString(PARENT_TOPIC_NOT_FOUND));
2198:                    return null;
2199:                }
2200:                selectedForum = new DiscussionForumBean(forum,
2201:                        uiPermissionsManager, forumManager);
2202:                if ("true".equalsIgnoreCase(ServerConfigurationService
2203:                        .getString("mc.defaultLongDescription"))) {
2204:                    selectedForum.setReadFullDesciption(true);
2205:                }
2206:
2207:                setForumBeanAssign();
2208:
2209:                DiscussionTopic topic = forumManager.createTopic(forum);
2210:                if (topic == null) {
2211:                    setErrorMessage(getResourceBundleString(FAILED_CREATE_TOPIC));
2212:                    return null;
2213:                }
2214:                selectedTopic = new DiscussionTopicBean(topic, forum,
2215:                        uiPermissionsManager, forumManager);
2216:                if ("true".equalsIgnoreCase(ServerConfigurationService
2217:                        .getString("mc.defaultLongDescription"))) {
2218:                    selectedTopic.setReadFullDesciption(true);
2219:                }
2220:
2221:                selectedTopic.setModerated(selectedForum.getModerated()); // default to parent forum's setting
2222:
2223:                setNewTopicBeanAssign();
2224:
2225:                DiscussionTopicBean this DTB = new DiscussionTopicBean(topic,
2226:                        forum, uiPermissionsManager, forumManager);
2227:                if ("true".equalsIgnoreCase(ServerConfigurationService
2228:                        .getString("mc.defaultLongDescription"))) {
2229:                    this DTB.setReadFullDesciption(true);
2230:                }
2231:
2232:                setNewTopicBeanAssign(selectedForum, this DTB);
2233:                return this DTB;
2234:                //return new DiscussionTopicBean(topic, forum, uiPermissionsManager, forumManager);
2235:            }
2236:
2237:            // compose
2238:            public String processAddMessage() {
2239:                return MESSAGE_COMPOSE;
2240:            }
2241:
2242:            public String processAddAttachmentRedirect() {
2243:                LOG.debug("processAddAttachmentRedirect()");
2244:                try {
2245:                    ExternalContext context = FacesContext.getCurrentInstance()
2246:                            .getExternalContext();
2247:                    context.redirect("sakai.filepicker.helper/tool");
2248:                    return null;
2249:                } catch (Exception e) {
2250:                    return null;
2251:                }
2252:            }
2253:
2254:            public void setMessageManager(
2255:                    MessageForumsMessageManager messageManager) {
2256:                this .messageManager = messageManager;
2257:            }
2258:
2259:            public String getComposeTitle() {
2260:                return composeTitle;
2261:            }
2262:
2263:            public void setComposeTitle(String composeTitle) {
2264:                this .composeTitle = composeTitle;
2265:            }
2266:
2267:            public String getComposeBody() {
2268:                return composeBody;
2269:            }
2270:
2271:            public void setComposeBody(String composeBody) {
2272:                this .composeBody = composeBody;
2273:            }
2274:
2275:            public String getComposeLabel() {
2276:                return composeLabel;
2277:            }
2278:
2279:            public void setComposeLabel(String composeLabel) {
2280:                this .composeLabel = composeLabel;
2281:            }
2282:
2283:            public ArrayList getAttachments() {
2284:                ToolSession session = SessionManager.getCurrentToolSession();
2285:                if (session.getAttribute(FilePickerHelper.FILE_PICKER_CANCEL) == null
2286:                        && session
2287:                                .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) != null) {
2288:                    List refs = (List) session
2289:                            .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
2290:                    if (refs != null && refs.size() > 0) {
2291:                        Reference ref = (Reference) refs.get(0);
2292:
2293:                        for (int i = 0; i < refs.size(); i++) {
2294:                            ref = (Reference) refs.get(i);
2295:                            Attachment this Attach = messageManager
2296:                                    .createAttachment();
2297:                            this Attach.setAttachmentName(ref.getProperties()
2298:                                    .getProperty(
2299:                                            ref.getProperties()
2300:                                                    .getNamePropDisplayName()));
2301:                            this Attach
2302:                                    .setAttachmentSize(ref
2303:                                            .getProperties()
2304:                                            .getProperty(
2305:                                                    ref
2306:                                                            .getProperties()
2307:                                                            .getNamePropContentLength()));
2308:                            this Attach.setAttachmentType(ref.getProperties()
2309:                                    .getProperty(
2310:                                            ref.getProperties()
2311:                                                    .getNamePropContentType()));
2312:                            this Attach.setAttachmentId(ref.getId());
2313:                            //thisAttach.setAttachmentUrl(ref.getUrl());
2314:                            this Attach.setAttachmentUrl("/url");
2315:
2316:                            attachments
2317:                                    .add(new DecoratedAttachment(this Attach));
2318:                        }
2319:                    }
2320:                }
2321:                session
2322:                        .removeAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
2323:                session.removeAttribute(FilePickerHelper.FILE_PICKER_CANCEL);
2324:
2325:                return attachments;
2326:            }
2327:
2328:            public void setAttachments(ArrayList attachments) {
2329:                this .attachments = attachments;
2330:            }
2331:
2332:            public String processDeleteAttach() {
2333:                LOG.debug("processDeleteAttach()");
2334:
2335:                ExternalContext context = FacesContext.getCurrentInstance()
2336:                        .getExternalContext();
2337:                String attachId = null;
2338:
2339:                Map paramMap = context.getRequestParameterMap();
2340:                Iterator itr = paramMap.keySet().iterator();
2341:                while (itr.hasNext()) {
2342:                    Object key = itr.next();
2343:                    if (key instanceof  String) {
2344:                        String name = (String) key;
2345:                        int pos = name.lastIndexOf("dfmsg_current_attach");
2346:
2347:                        if (pos >= 0
2348:                                && name.length() == pos
2349:                                        + "dfmsg_current_attach".length()) {
2350:                            attachId = (String) paramMap.get(key);
2351:                            break;
2352:                        }
2353:                    }
2354:                }
2355:
2356:                if ((attachId != null) && (!attachId.equals(""))) {
2357:                    for (int i = 0; i < attachments.size(); i++) {
2358:                        if (attachId
2359:                                .equalsIgnoreCase(((DecoratedAttachment) attachments
2360:                                        .get(i)).getAttachment()
2361:                                        .getAttachmentId())) {
2362:                            attachments.remove(i);
2363:                            break;
2364:                        }
2365:                    }
2366:                }
2367:
2368:                return null;
2369:            }
2370:
2371:            public String processDfMsgCancel() {
2372:                this .composeBody = null;
2373:                this .composeLabel = null;
2374:                this .composeTitle = null;
2375:
2376:                this .attachments.clear();
2377:
2378:                return ALL_MESSAGES;
2379:            }
2380:
2381:            public String processDfMsgPost() {
2382:                Message dMsg = constructMessage();
2383:
2384:                forumManager.saveMessage(dMsg);
2385:                setSelectedForumForCurrentTopic((DiscussionTopic) forumManager
2386:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
2387:                                .getId()));
2388:                selectedTopic.setTopic((DiscussionTopic) forumManager
2389:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
2390:                                .getId()));
2391:                selectedTopic.getTopic().setBaseForum(selectedForum.getForum());
2392:                //selectedTopic.addMessage(new DiscussionMessageBean(dMsg, messageManager));
2393:                selectedTopic.insertMessage(new DiscussionMessageBean(dMsg,
2394:                        messageManager));
2395:
2396:                selectedTopic.getTopic().addMessage(dMsg);
2397:
2398:                /** mark message creator as having read the message */
2399:                messageManager.markMessageReadForUser(selectedTopic.getTopic()
2400:                        .getId(), dMsg.getId(), true);
2401:
2402:                this .composeBody = null;
2403:                this .composeLabel = null;
2404:                this .composeTitle = null;
2405:
2406:                this .attachments.clear();
2407:
2408:                // refresh page with unread status     
2409:                selectedTopic = getDecoratedTopic(forumManager
2410:                        .getTopicById(selectedTopic.getTopic().getId()));
2411:
2412:                return ALL_MESSAGES;
2413:            }
2414:
2415:            public String processDfMsgSaveDraft() {
2416:                Message dMsg = constructMessage();
2417:                dMsg.setDraft(Boolean.TRUE);
2418:
2419:                forumManager.saveMessage(dMsg);
2420:                setSelectedForumForCurrentTopic((DiscussionTopic) forumManager
2421:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
2422:                                .getId()));
2423:                selectedTopic.setTopic((DiscussionTopic) forumManager
2424:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
2425:                                .getId()));
2426:                selectedTopic.getTopic().setBaseForum(selectedForum.getForum());
2427:                //selectedTopic.addMessage(new DiscussionMessageBean(dMsg, messageManager));
2428:                selectedTopic.insertMessage(new DiscussionMessageBean(dMsg,
2429:                        messageManager));
2430:                selectedTopic.getTopic().addMessage(dMsg);
2431:
2432:                this .composeBody = null;
2433:                this .composeLabel = null;
2434:                this .composeTitle = null;
2435:
2436:                this .attachments.clear();
2437:
2438:                return ALL_MESSAGES;
2439:            }
2440:
2441:            public Message constructMessage() {
2442:                Message aMsg;
2443:
2444:                aMsg = messageManager.createDiscussionMessage();
2445:
2446:                if (aMsg != null) {
2447:                    StringBuffer alertMsg = new StringBuffer();
2448:                    aMsg.setTitle(FormattedText.processFormattedText(
2449:                            getComposeTitle(), alertMsg));
2450:                    aMsg.setBody(FormattedText.processFormattedText(
2451:                            getComposeBody(), alertMsg));
2452:
2453:                    aMsg.setAuthor(getUserNameOrEid());
2454:
2455:                    aMsg.setDraft(Boolean.FALSE);
2456:
2457:                    // if the topic is moderated, we want to leave approval null.
2458:                    // if the topic is not moderated, all msgs are approved
2459:                    // if the author has moderator perm, the msg is automatically approved
2460:                    if (!selectedTopic.isTopicModerated()
2461:                            || selectedTopic.getIsModeratedAndHasPerm()) {
2462:                        aMsg.setApproved(Boolean.TRUE);
2463:                    }
2464:                    aMsg.setTopic(selectedTopic.getTopic());
2465:                }
2466:                for (int i = 0; i < attachments.size(); i++) {
2467:                    aMsg.addAttachment(((DecoratedAttachment) attachments
2468:                            .get(i)).getAttachment());
2469:                }
2470:                attachments.clear();
2471:                // oldAttachments.clear();
2472:
2473:                return aMsg;
2474:            }
2475:
2476:            /**
2477:             * Prevents users from trying to delete the topic they are currently creating
2478:             * @return
2479:             */
2480:            public boolean isDisplayTopicDeleteOption() {
2481:                Topic topic = selectedTopic.getTopic();
2482:                if (topic == null || topic.getId() == null)
2483:                    return false;
2484:
2485:                Topic topicInDb = forumManager.getTopicById(topic.getId());
2486:
2487:                return topicInDb != null;
2488:            }
2489:
2490:            /**
2491:             * Prevents users from trying to delete the forum they are currently creating
2492:             * @return
2493:             */
2494:            public boolean isDisplayForumDeleteOption() {
2495:                OpenForum forum = selectedForum.getForum();
2496:                if (forum == null || forum.getId() == null)
2497:                    return false;
2498:
2499:                OpenForum forumInDb = forumManager.getForumById(forum.getId());
2500:
2501:                return forumInDb != null;
2502:            }
2503:
2504:            public String processDfComposeToggle() {
2505:                String redirectTo = getExternalParameterByKey(REDIRECT_PROCESS_ACTION);
2506:                String expand = getExternalParameterByKey("composeExpand");
2507:
2508:                if (redirectTo == null) {
2509:                    return gotoMain();
2510:                }
2511:                if (redirectTo.equals("dfCompose")) {
2512:                    if ((expand != null) && (expand.equalsIgnoreCase("true"))) {
2513:                        selectedTopic.setReadFullDesciption(true);
2514:                    } else {
2515:                        selectedTopic.setReadFullDesciption(false);
2516:                    }
2517:                    return MESSAGE_COMPOSE;
2518:                }
2519:                if (redirectTo.equals("dfViewMessage")) {
2520:                    if ((expand != null) && (expand.equalsIgnoreCase("true"))) {
2521:                        selectedTopic.setReadFullDesciption(true);
2522:                    } else {
2523:                        selectedTopic.setReadFullDesciption(false);
2524:                    }
2525:                    return MESSAGE_VIEW;
2526:                }
2527:                if (redirectTo.equals("dfTopicReply")) {
2528:                    if ((expand != null) && (expand.equalsIgnoreCase("true"))) {
2529:                        selectedTopic.setReadFullDesciption(true);
2530:                    } else {
2531:                        selectedTopic.setReadFullDesciption(false);
2532:                    }
2533:                    return "dfTopicReply";
2534:                }
2535:
2536:                return gotoMain();
2537:            }
2538:
2539:            public String getUserId() {
2540:                return SessionManager.getCurrentSessionUserId();
2541:            }
2542:
2543:            public boolean getFullAccess() {
2544:                return forumManager.isInstructor();
2545:            }
2546:
2547:            /**
2548:             * @return
2549:             */
2550:            public String processDfMsgMarkMsgAsRead() {
2551:                String messageId = getExternalParameterByKey(MESSAGE_ID);
2552:                String topicId = getExternalParameterByKey(TOPIC_ID);
2553:                if (messageId == null) {
2554:                    setErrorMessage(getResourceBundleString(MESSAGE_REFERENCE_NOT_FOUND));
2555:                    return gotoMain();
2556:                }
2557:                if (topicId == null) {
2558:                    setErrorMessage(getResourceBundleString(TOPC_REFERENCE_NOT_FOUND));
2559:                    return gotoMain();
2560:                }
2561:                // Message message=forumManager.getMessageById(new Long(messageId));
2562:                Message message = messageManager
2563:                        .getMessageByIdWithAttachments(new Long(messageId));
2564:                messageManager.markMessageReadForUser(new Long(topicId),
2565:                        new Long(messageId), true);
2566:                if (message == null) {
2567:                    setErrorMessage(getResourceBundleString(MESSAGE_WITH_ID)
2568:                            + messageId
2569:                            + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
2570:                    return gotoMain();
2571:                }
2572:                if (resetTopicById(TOPIC_ID)) { // reconstruct topic again;
2573:                    return null;
2574:                } else {
2575:                    return gotoMain();
2576:                }
2577:            }
2578:
2579:            /**
2580:             * @return
2581:             */
2582:            public String processDfMsgMarkMsgAsReadFromThread() {
2583:                String messageId = getExternalParameterByKey(MESSAGE_ID);
2584:                String topicId = getExternalParameterByKey(TOPIC_ID);
2585:                if (messageId == null) {
2586:                    setErrorMessage(getResourceBundleString(MESSAGE_REFERENCE_NOT_FOUND));
2587:                    return gotoMain();
2588:                }
2589:                if (topicId == null) {
2590:                    setErrorMessage(getResourceBundleString(TOPC_REFERENCE_NOT_FOUND));
2591:                    return gotoMain();
2592:                }
2593:                // Message message=forumManager.getMessageById(new Long(messageId));
2594:                Message message = messageManager
2595:                        .getMessageByIdWithAttachments(new Long(messageId));
2596:                messageManager.markMessageReadForUser(new Long(topicId),
2597:                        new Long(messageId), true);
2598:                if (message == null) {
2599:                    setErrorMessage(getResourceBundleString(MESSAGE_WITH_ID)
2600:                            + messageId
2601:                            + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
2602:                    return gotoMain();
2603:                }
2604:                return processActionGetDisplayThread(); // reconstruct thread again;
2605:            }
2606:
2607:            public String processDfMsgReplyMsgFromEntire() {
2608:                String messageId = getExternalParameterByKey(MESSAGE_ID);
2609:                String topicId = getExternalParameterByKey(TOPIC_ID);
2610:                if (messageId == null) {
2611:                    setErrorMessage(getResourceBundleString(MESSAGE_REFERENCE_NOT_FOUND));
2612:                    return gotoMain();
2613:                }
2614:                if (topicId == null) {
2615:                    setErrorMessage(getResourceBundleString(TOPC_REFERENCE_NOT_FOUND));
2616:                    return gotoMain();
2617:                }
2618:                // Message message=forumManager.getMessageById(new Long(messageId));
2619:                Message message = messageManager
2620:                        .getMessageByIdWithAttachments(new Long(messageId));
2621:                messageManager.markMessageReadForUser(new Long(topicId),
2622:                        new Long(messageId), true);
2623:                if (message == null) {
2624:                    setErrorMessage(getResourceBundleString(MESSAGE_WITH_ID)
2625:                            + messageId
2626:                            + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
2627:                    return gotoMain();
2628:                }
2629:                message = messageManager.getMessageByIdWithAttachments(message
2630:                        .getId());
2631:                selectedMessage = new DiscussionMessageBean(message,
2632:                        messageManager);
2633:
2634:                return processDfMsgReplyMsg();
2635:            }
2636:
2637:            public String processDfMsgReplyMsg() {
2638:                if (selectedMessage.getMessage().getTitle() != null
2639:                        && !selectedMessage.getMessage().getTitle().startsWith(
2640:                                getResourceBundleString(MSG_REPLY_PREFIX)))
2641:                    this .composeTitle = getResourceBundleString(MSG_REPLY_PREFIX)
2642:                            + " "
2643:                            + selectedMessage.getMessage().getTitle()
2644:                            + " ";
2645:                else
2646:                    this .composeTitle = selectedMessage.getMessage().getTitle();
2647:
2648:                return "dfMessageReply";
2649:            }
2650:
2651:            public String processDfMsgReplyThread() {
2652:                //we have to get the depth 0 message that this is in response to
2653:                DiscussionMessageBean cur = selectedMessage;
2654:                int depth = 0;
2655:                long messageId = 0;
2656:                while (cur.getDepth() > 0) {
2657:                    messageId = cur.getMessage().getInReplyTo().getId();
2658:                    depth = cur.getDepth();
2659:                    cur = new DiscussionMessageBean(messageManager
2660:                            .getMessageByIdWithAttachments(cur.getMessage()
2661:                                    .getInReplyTo().getId()), messageManager);
2662:                    cur.setDepth(--depth);
2663:                }
2664:                selectedMessage = cur;
2665:                List tempMsgs = selectedTopic.getMessages();
2666:                if (tempMsgs != null) {
2667:                    for (int i = 0; i < tempMsgs.size(); i++) {
2668:                        DiscussionMessageBean this Dmb = (DiscussionMessageBean) tempMsgs
2669:                                .get(i);
2670:                        if (((DiscussionMessageBean) tempMsgs.get(i))
2671:                                .getMessage().getId().toString().equals(
2672:                                        messageId)) {
2673:                            selectedMessage.setDepth(this Dmb.getDepth());
2674:                            selectedMessage.setHasNext(this Dmb.getHasNext());
2675:                            selectedMessage.setHasPre(this Dmb.getHasPre());
2676:                            break;
2677:                        }
2678:                    }
2679:                }
2680:                composeTitle = getResourceBundleString(MSG_REPLY_PREFIX) + " "
2681:                        + selectedMessage.getMessage().getTitle();
2682:
2683:                return "dfMessageReplyThread";
2684:            }
2685:
2686:            public String processDfMsgReplyTp() {
2687:                return "dfTopicReply";
2688:            }
2689:
2690:            public String processDfMsgGrdFromThread() {
2691:                String messageId = getExternalParameterByKey(MESSAGE_ID);
2692:                String topicId = getExternalParameterByKey(TOPIC_ID);
2693:                if (messageId == null) {
2694:                    setErrorMessage(getResourceBundleString(MESSAGE_REFERENCE_NOT_FOUND));
2695:                    return gotoMain();
2696:                }
2697:                if (topicId == null) {
2698:                    setErrorMessage(getResourceBundleString(TOPC_REFERENCE_NOT_FOUND));
2699:                    return gotoMain();
2700:                }
2701:                // Message message=forumManager.getMessageById(new Long(messageId));
2702:                Message message = messageManager
2703:                        .getMessageByIdWithAttachments(new Long(messageId));
2704:                if (message == null) {
2705:                    setErrorMessage(getResourceBundleString(MESSAGE_WITH_ID)
2706:                            + messageId
2707:                            + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
2708:                    return gotoMain();
2709:                }
2710:                message = messageManager.getMessageByIdWithAttachments(message
2711:                        .getId());
2712:                selectedMessage = new DiscussionMessageBean(message,
2713:                        messageManager);
2714:                return processDfMsgGrd();
2715:            }
2716:
2717:            public String processDfMsgGrd() {
2718:                selectedAssign = "Default_0";
2719:                gradePoint = "";
2720:                gradeComment = "";
2721:
2722:                try {
2723:                    GradebookService gradebookService = (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
2724:                            .get("org.sakaiproject.service.gradebook.GradebookService");
2725:
2726:                    String createdById = UserDirectoryService.getUser(
2727:                            selectedMessage.getMessage().getCreatedBy())
2728:                            .getId();
2729:                    String gradebookUid = ToolManager.getCurrentPlacement()
2730:                            .getContext();
2731:                    String msgAssignmentName = selectedMessage.getMessage()
2732:                            .getGradeAssignmentName();
2733:                    String topicDefaultAssignment = selectedTopic.getTopic()
2734:                            .getDefaultAssignName();
2735:                    String forumDefaultAssignment = selectedForum.getForum()
2736:                            .getDefaultAssignName();
2737:
2738:                    if (msgAssignmentName != null
2739:                            && msgAssignmentName.trim().length() > 0) {
2740:                        if ((gradebookService.getAssignmentScore(gradebookUid,
2741:                                msgAssignmentName, createdById)) != null) {
2742:                            gradePoint = (gradebookService.getAssignmentScore(
2743:                                    gradebookUid, msgAssignmentName,
2744:                                    createdById)).toString();
2745:                            gradePoint = new Double(gradePoint).toString();
2746:                            CommentDefinition assgnComment = gradebookService
2747:                                    .getAssignmentScoreComment(gradebookUid,
2748:                                            msgAssignmentName, createdById);
2749:                            if (assgnComment != null)
2750:                                gradeComment = assgnComment.getCommentText();
2751:                            setSelectedAssignForMessage(msgAssignmentName);
2752:                        }
2753:                    } else if (topicDefaultAssignment != null
2754:                            && topicDefaultAssignment.trim().length() > 0) {
2755:                        if ((gradebookService.getAssignmentScore(gradebookUid,
2756:                                topicDefaultAssignment, createdById)) != null) {
2757:                            gradePoint = (gradebookService.getAssignmentScore(
2758:                                    gradebookUid, topicDefaultAssignment,
2759:                                    createdById)).toString();
2760:                            gradePoint = new Double(gradePoint).toString();
2761:                            CommentDefinition assgnComment = gradebookService
2762:                                    .getAssignmentScoreComment(gradebookUid,
2763:                                            topicDefaultAssignment, createdById);
2764:                            if (assgnComment != null)
2765:                                gradeComment = assgnComment.getCommentText();
2766:                            setSelectedAssignForMessage(topicDefaultAssignment);
2767:                        } else {
2768:                            gradePoint = "";
2769:                            setSelectedAssignForMessage(topicDefaultAssignment);
2770:                        }
2771:                    } else if (forumDefaultAssignment != null
2772:                            && forumDefaultAssignment.trim().length() > 0) {
2773:                        if ((gradebookService.getAssignmentScore(gradebookUid,
2774:                                forumDefaultAssignment, createdById)) != null) {
2775:                            gradePoint = (gradebookService.getAssignmentScore(
2776:                                    gradebookUid, forumDefaultAssignment,
2777:                                    createdById)).toString();
2778:                            gradePoint = new Double(gradePoint).toString();
2779:                            CommentDefinition assgnComment = gradebookService
2780:                                    .getAssignmentScoreComment(gradebookUid,
2781:                                            forumDefaultAssignment, createdById);
2782:                            if (assgnComment != null)
2783:                                gradeComment = assgnComment.getCommentText();
2784:                            setSelectedAssignForMessage(forumDefaultAssignment);
2785:                        } else {
2786:                            gradePoint = "";
2787:                            setSelectedAssignForMessage(topicDefaultAssignment);
2788:                        }
2789:                    }
2790:                } catch (Exception e) {
2791:                    LOG.error("processDfMsgGrd in DiscussionFOrumTool - " + e);
2792:                    e.printStackTrace();
2793:                    return null;
2794:                }
2795:
2796:                return "dfMsgGrade";
2797:            }
2798:
2799:            public String processDfMsgRvsFromThread() {
2800:                String messageId = getExternalParameterByKey(MESSAGE_ID);
2801:                String topicId = getExternalParameterByKey(TOPIC_ID);
2802:                if (messageId == null) {
2803:                    setErrorMessage(getResourceBundleString(MESSAGE_REFERENCE_NOT_FOUND));
2804:                    return gotoMain();
2805:                }
2806:                if (topicId == null) {
2807:                    setErrorMessage(getResourceBundleString(TOPC_REFERENCE_NOT_FOUND));
2808:                    return gotoMain();
2809:                }
2810:                // Message message=forumManager.getMessageById(new Long(messageId));
2811:                Message message = messageManager
2812:                        .getMessageByIdWithAttachments(new Long(messageId));
2813:                if (message == null) {
2814:                    setErrorMessage(getResourceBundleString(MESSAGE_WITH_ID)
2815:                            + messageId
2816:                            + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
2817:                    return gotoMain();
2818:                }
2819:                message = messageManager.getMessageByIdWithAttachments(message
2820:                        .getId());
2821:                selectedMessage = new DiscussionMessageBean(message,
2822:                        messageManager);
2823:                return processDfMsgRvs();
2824:            }
2825:
2826:            public String processDfMsgRvs() {
2827:                attachments.clear();
2828:
2829:                composeBody = selectedMessage.getMessage().getBody();
2830:                composeLabel = selectedMessage.getMessage().getLabel();
2831:                composeTitle = selectedMessage.getMessage().getTitle();
2832:                List attachList = selectedMessage.getMessage().getAttachments();
2833:                if (attachList != null) {
2834:                    for (int i = 0; i < attachList.size(); i++) {
2835:                        attachments.add(new DecoratedAttachment(
2836:                                (Attachment) attachList.get(i)));
2837:                    }
2838:                }
2839:
2840:                return "dfMsgRevise";
2841:            }
2842:
2843:            public String processDfMsgMove() {
2844:                List childMsgs = new ArrayList();
2845:                messageManager.getChildMsgs(selectedMessage.getMessage()
2846:                        .getId(), childMsgs);
2847:                // selectedMessage.getMessage().setTopic(selectedTopic.getTopic());
2848:
2849:                return null;
2850:            }
2851:
2852:            public String processDfMsgDeleteConfirm() {
2853:                deleteMsg = true;
2854:                return null;
2855:            }
2856:
2857:            public String processDfReplyMsgPost() {
2858:                List tempList = forumManager.getMessagesByTopicId(selectedTopic
2859:                        .getTopic().getId());
2860:                if (tempList != null) {
2861:                    boolean existed = false;
2862:                    for (int i = 0; i < tempList.size(); i++) {
2863:                        Message tempMsg = (Message) tempList.get(i);
2864:                        if (tempMsg.getId().equals(
2865:                                selectedMessage.getMessage().getId())) {
2866:                            existed = true;
2867:                            break;
2868:                        }
2869:                    }
2870:                    if (!existed) {
2871:                        this .errorSynch = true;
2872:                        return null;
2873:                    }
2874:                } else {
2875:                    this .errorSynch = true;
2876:                    return null;
2877:                }
2878:
2879:                Message dMsg = constructMessage();
2880:
2881:                dMsg.setInReplyTo(selectedMessage.getMessage());
2882:                forumManager.saveMessage(dMsg);
2883:                setSelectedForumForCurrentTopic((DiscussionTopic) forumManager
2884:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
2885:                                .getId()));
2886:                selectedTopic.setTopic((DiscussionTopic) forumManager
2887:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
2888:                                .getId()));
2889:                selectedTopic.getTopic().setBaseForum(selectedForum.getForum());
2890:                //selectedTopic.addMessage(new DiscussionMessageBean(dMsg, messageManager));
2891:                selectedTopic.insertMessage(new DiscussionMessageBean(dMsg,
2892:                        messageManager));
2893:                selectedTopic.getTopic().addMessage(dMsg);
2894:                messageManager.markMessageReadForUser(selectedTopic.getTopic()
2895:                        .getId(), dMsg.getId(), true);
2896:
2897:                this .composeBody = null;
2898:                this .composeLabel = null;
2899:                this .composeTitle = null;
2900:
2901:                this .attachments.clear();
2902:
2903:                //return ALL_MESSAGES;
2904:                //check selectedThreadHead exists
2905:                if (selectedThreadHead == null) {
2906:                    selectedThreadHead = new DiscussionMessageBean(
2907:                            selectedMessage.getMessage(), messageManager);
2908:                    //make sure we have the thread head of depth 0
2909:                    while (selectedThreadHead.getMessage().getInReplyTo() != null) {
2910:                        selectedThreadHead = new DiscussionMessageBean(
2911:                                messageManager
2912:                                        .getMessageByIdWithAttachments(selectedThreadHead
2913:                                                .getMessage().getInReplyTo()
2914:                                                .getId()), messageManager);
2915:                    }
2916:                }
2917:                return processActionGetDisplayThread();
2918:            }
2919:
2920:            public String processDfReplyMsgSaveDraft() {
2921:                List tempList = forumManager.getMessagesByTopicId(selectedTopic
2922:                        .getTopic().getId());
2923:                if (tempList != null) {
2924:                    boolean existed = false;
2925:                    for (int i = 0; i < tempList.size(); i++) {
2926:                        Message tempMsg = (Message) tempList.get(i);
2927:                        if (tempMsg.getId().equals(
2928:                                selectedMessage.getMessage().getId())) {
2929:                            existed = true;
2930:                            break;
2931:                        }
2932:                    }
2933:                    if (!existed) {
2934:                        this .errorSynch = true;
2935:                        return null;
2936:                    }
2937:                } else {
2938:                    this .errorSynch = true;
2939:                    return null;
2940:                }
2941:
2942:                Message dMsg = constructMessage();
2943:                dMsg.setDraft(Boolean.TRUE);
2944:                dMsg.setInReplyTo(selectedMessage.getMessage());
2945:                forumManager.saveMessage(dMsg);
2946:                setSelectedForumForCurrentTopic((DiscussionTopic) forumManager
2947:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
2948:                                .getId()));
2949:                selectedTopic.setTopic((DiscussionTopic) forumManager
2950:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
2951:                                .getId()));
2952:                selectedTopic.getTopic().setBaseForum(selectedForum.getForum());
2953:                //selectedTopic.addMessage(new DiscussionMessageBean(dMsg, messageManager));
2954:                selectedTopic.insertMessage(new DiscussionMessageBean(dMsg,
2955:                        messageManager));
2956:                selectedTopic.getTopic().addMessage(dMsg);
2957:
2958:                this .composeBody = null;
2959:                this .composeLabel = null;
2960:                this .composeTitle = null;
2961:
2962:                this .attachments.clear();
2963:
2964:                return processActionGetDisplayThread();
2965:            }
2966:
2967:            public String processDeleteAttachRevise() {
2968:                ExternalContext context = FacesContext.getCurrentInstance()
2969:                        .getExternalContext();
2970:                String attachId = null;
2971:
2972:                Map paramMap = context.getRequestParameterMap();
2973:                Iterator itr = paramMap.keySet().iterator();
2974:                while (itr.hasNext()) {
2975:                    Object key = itr.next();
2976:                    if (key instanceof  String) {
2977:                        String name = (String) key;
2978:                        int pos = name.lastIndexOf("dfmsg_current_attach");
2979:
2980:                        if (pos >= 0
2981:                                && name.length() == pos
2982:                                        + "dfmsg_current_attach".length()) {
2983:                            attachId = (String) paramMap.get(key);
2984:                            break;
2985:                        }
2986:                    }
2987:                }
2988:
2989:                if ((attachId != null) && (!attachId.equals(""))) {
2990:                    for (int i = 0; i < attachments.size(); i++) {
2991:                        if (attachId
2992:                                .equalsIgnoreCase(((DecoratedAttachment) attachments
2993:                                        .get(i)).getAttachment()
2994:                                        .getAttachmentId())) {
2995:                            prepareRemoveAttach
2996:                                    .add((DecoratedAttachment) attachments
2997:                                            .get(i));
2998:                            attachments.remove(i);
2999:                            break;
3000:                        }
3001:                    }
3002:                }
3003:
3004:                return null;
3005:            }
3006:
3007:            public String processDfMsgRevisedCancel() {
3008:                getThreadFromMessage();
3009:                return MESSAGE_VIEW;
3010:            }
3011:
3012:            public String processDfMsgRevisedPost() {
3013:                Message dMsg = selectedMessage.getMessage();
3014:
3015:                for (int i = 0; i < prepareRemoveAttach.size(); i++) {
3016:                    DecoratedAttachment removeAttach = (DecoratedAttachment) prepareRemoveAttach
3017:                            .get(i);
3018:                    dMsg.removeAttachment(removeAttach.getAttachment());
3019:                }
3020:
3021:                List oldList = dMsg.getAttachments();
3022:                for (int i = 0; i < attachments.size(); i++) {
3023:                    DecoratedAttachment this Attach = (DecoratedAttachment) attachments
3024:                            .get(i);
3025:                    boolean existed = false;
3026:                    for (int j = 0; j < oldList.size(); j++) {
3027:                        Attachment existedAttach = (Attachment) oldList.get(j);
3028:                        if (existedAttach.getAttachmentId().equals(
3029:                                this Attach.getAttachment().getAttachmentId())) {
3030:                            existed = true;
3031:                            break;
3032:                        }
3033:                    }
3034:                    if (!existed) {
3035:                        dMsg.addAttachment(this Attach.getAttachment());
3036:                    }
3037:                }
3038:                String currentBody = getComposeBody();
3039:                String revisedInfo = getResourceBundleString(LAST_REVISE_BY);
3040:
3041:                revisedInfo += getUserNameOrEid();
3042:
3043:                revisedInfo += " " + getResourceBundleString(LAST_REVISE_ON);
3044:                Date now = new Date();
3045:                revisedInfo += now.toString() + " <br/> ";
3046:
3047:                /*    if(currentBody != null && currentBody.length()>0 && currentBody.startsWith("Last Revised By "))
3048:                 {
3049:                 if(currentBody.lastIndexOf(" <br/> ") > 0)
3050:                 {
3051:                 currentBody = currentBody.substring(currentBody.lastIndexOf(" <br/> ") + 7);
3052:                 }
3053:                 }*/
3054:
3055:                revisedInfo = revisedInfo.concat(currentBody);
3056:
3057:                dMsg.setTitle(getComposeTitle());
3058:                dMsg.setBody(revisedInfo);
3059:                dMsg.setDraft(Boolean.FALSE);
3060:                dMsg.setModified(new Date());
3061:
3062:                dMsg.setModifiedBy(getUserNameOrEid());
3063:                if (!selectedTopic.isTopicModerated()
3064:                        || selectedTopic.getIsModeratedAndHasPerm()) {
3065:                    dMsg.setApproved(Boolean.TRUE);
3066:                } else {
3067:                    dMsg.setApproved(null);
3068:                }
3069:
3070:                setSelectedForumForCurrentTopic((DiscussionTopic) forumManager
3071:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3072:                                .getId()));
3073:                selectedTopic.setTopic((DiscussionTopic) forumManager
3074:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3075:                                .getId()));
3076:                dMsg.setTopic((DiscussionTopic) forumManager
3077:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3078:                                .getId()));
3079:                //    selectedTopic.getTopic().setBaseForum(selectedForum.getForum());
3080:                //    Topic currentTopic = forumManager.getTopicByIdWithMessagesAndAttachments(dMsg.getTopic().getId());
3081:                //    dMsg.getTopic().setBaseForum(currentTopic.getBaseForum());
3082:                //dMsg.getTopic().setBaseForum(selectedTopic.getTopic().getBaseForum());
3083:                forumManager.saveMessage(dMsg);
3084:
3085:                List messageList = selectedTopic.getMessages();
3086:                for (int i = 0; i < messageList.size(); i++) {
3087:                    DiscussionMessageBean dmb = (DiscussionMessageBean) messageList
3088:                            .get(i);
3089:                    if (dmb.getMessage().getId().equals(dMsg.getId())) {
3090:                        selectedTopic.getMessages()
3091:                                .set(
3092:                                        i,
3093:                                        new DiscussionMessageBean(dMsg,
3094:                                                messageManager));
3095:                    }
3096:                }
3097:
3098:                try {
3099:                    DiscussionTopic topic = null;
3100:                    try {
3101:                        topic = forumManager.getTopicById(selectedTopic
3102:                                .getTopic().getId());
3103:                    } catch (NumberFormatException e) {
3104:                        LOG.error(e.getMessage(), e);
3105:                    }
3106:                    setSelectedForumForCurrentTopic(topic);
3107:                    selectedTopic = getDecoratedTopic(topic);
3108:
3109:                } catch (Exception e) {
3110:                    LOG.error(e.getMessage(), e);
3111:                    setErrorMessage(e.getMessage());
3112:                    return null;
3113:                }
3114:
3115:                prepareRemoveAttach.clear();
3116:                composeBody = null;
3117:                composeLabel = null;
3118:                composeTitle = null;
3119:                attachments.clear();
3120:
3121:                getThreadFromMessage();
3122:                return MESSAGE_VIEW;
3123:            }
3124:
3125:            public String processDfMsgSaveRevisedDraft() {
3126:                Message dMsg = selectedMessage.getMessage();
3127:
3128:                for (int i = 0; i < prepareRemoveAttach.size(); i++) {
3129:                    DecoratedAttachment removeAttach = (DecoratedAttachment) prepareRemoveAttach
3130:                            .get(i);
3131:                    dMsg.removeAttachment(removeAttach.getAttachment());
3132:                }
3133:
3134:                List oldList = dMsg.getAttachments();
3135:                for (int i = 0; i < attachments.size(); i++) {
3136:                    DecoratedAttachment this Attach = (DecoratedAttachment) attachments
3137:                            .get(i);
3138:                    boolean existed = false;
3139:                    for (int j = 0; j < oldList.size(); j++) {
3140:                        Attachment existedAttach = (Attachment) oldList.get(j);
3141:                        if (existedAttach.getAttachmentId().equals(
3142:                                this Attach.getAttachment().getAttachmentId())) {
3143:                            existed = true;
3144:                            break;
3145:                        }
3146:                    }
3147:                    if (!existed) {
3148:                        dMsg.addAttachment(this Attach.getAttachment());
3149:                    }
3150:                }
3151:                String currentBody = getComposeBody();
3152:                String revisedInfo = getResourceBundleString(LAST_REVISE_BY);
3153:
3154:                revisedInfo += getUserNameOrEid();
3155:
3156:                revisedInfo += " " + getResourceBundleString(LAST_REVISE_ON);
3157:                Date now = new Date();
3158:                revisedInfo += now.toString() + " <br/> ";
3159:                revisedInfo = revisedInfo.concat(currentBody);
3160:
3161:                dMsg.setTitle(getComposeTitle());
3162:                dMsg.setBody(revisedInfo);
3163:                dMsg.setDraft(Boolean.TRUE);
3164:                dMsg.setModified(new Date());
3165:
3166:                dMsg.setModifiedBy(getUserNameOrEid());
3167:
3168:                //  if the topic is moderated, we want to leave approval null.
3169:                // if the topic is not moderated, all msgs are approved
3170:                if (!selectedTopic.isTopicModerated()) {
3171:                    dMsg.setApproved(Boolean.TRUE);
3172:                }
3173:
3174:                //    setSelectedForumForCurrentTopic((DiscussionTopic) forumManager
3175:                //        .getTopicByIdWithMessages(selectedTopic.getTopic().getId()));
3176:                //    selectedTopic.setTopic((DiscussionTopic) forumManager
3177:                //        .getTopicByIdWithMessages(selectedTopic.getTopic().getId()));
3178:                //    selectedTopic.getTopic().setBaseForum(selectedForum.getForum());    
3179:                setSelectedForumForCurrentTopic((DiscussionTopic) forumManager
3180:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3181:                                .getId()));
3182:                selectedTopic.setTopic((DiscussionTopic) forumManager
3183:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3184:                                .getId()));
3185:                dMsg.setTopic((DiscussionTopic) forumManager
3186:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3187:                                .getId()));
3188:                //dMsg.getTopic().setBaseForum(selectedTopic.getTopic().getBaseForum());
3189:                forumManager.saveMessage(dMsg);
3190:
3191:                List messageList = selectedTopic.getMessages();
3192:                for (int i = 0; i < messageList.size(); i++) {
3193:                    DiscussionMessageBean dmb = (DiscussionMessageBean) messageList
3194:                            .get(i);
3195:                    if (dmb.getMessage().getId().equals(dMsg.getId())) {
3196:                        selectedTopic.getMessages()
3197:                                .set(
3198:                                        i,
3199:                                        new DiscussionMessageBean(dMsg,
3200:                                                messageManager));
3201:                    }
3202:                }
3203:
3204:                try {
3205:                    DiscussionTopic topic = null;
3206:                    try {
3207:                        topic = forumManager.getTopicById(selectedTopic
3208:                                .getTopic().getId());
3209:                    } catch (NumberFormatException e) {
3210:                        LOG.error(e.getMessage(), e);
3211:                    }
3212:                    setSelectedForumForCurrentTopic(topic);
3213:                    selectedTopic = getDecoratedTopic(topic);
3214:                } catch (Exception e) {
3215:                    LOG.error(e.getMessage(), e);
3216:                    setErrorMessage(e.getMessage());
3217:                    return null;
3218:                }
3219:
3220:                prepareRemoveAttach.clear();
3221:                composeBody = null;
3222:                composeLabel = null;
3223:                composeTitle = null;
3224:                attachments.clear();
3225:
3226:                return ALL_MESSAGES;
3227:            }
3228:
3229:            public String processDfReplyMsgCancel() {
3230:                this .errorSynch = false;
3231:                this .composeBody = null;
3232:                this .composeLabel = null;
3233:                this .composeTitle = null;
3234:
3235:                this .attachments.clear();
3236:
3237:                getThreadFromMessage();
3238:                return MESSAGE_VIEW;
3239:            }
3240:
3241:            public String processDfReplyThreadCancel() {
3242:                this .errorSynch = false;
3243:                this .composeBody = null;
3244:                this .composeLabel = null;
3245:                this .composeTitle = null;
3246:
3247:                this .attachments.clear();
3248:
3249:                return processActionGetDisplayThread();
3250:            }
3251:
3252:            public String processDfReplyTopicPost() {
3253:                Message dMsg = constructMessage();
3254:
3255:                forumManager.saveMessage(dMsg);
3256:                setSelectedForumForCurrentTopic((DiscussionTopic) forumManager
3257:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3258:                                .getId()));
3259:                selectedTopic.setTopic((DiscussionTopic) forumManager
3260:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3261:                                .getId()));
3262:                selectedTopic.getTopic().setBaseForum(selectedForum.getForum());
3263:                //selectedTopic.addMessage(new DiscussionMessageBean(dMsg, messageManager));
3264:                selectedTopic.insertMessage(new DiscussionMessageBean(dMsg,
3265:                        messageManager));
3266:                selectedTopic.getTopic().addMessage(dMsg);
3267:
3268:                this .composeBody = null;
3269:                this .composeLabel = null;
3270:                this .composeTitle = null;
3271:
3272:                this .attachments.clear();
3273:
3274:                return ALL_MESSAGES;
3275:            }
3276:
3277:            public String processDfReplyTopicSaveDraft() {
3278:                Message dMsg = constructMessage();
3279:                dMsg.setDraft(Boolean.TRUE);
3280:
3281:                forumManager.saveMessage(dMsg);
3282:                setSelectedForumForCurrentTopic((DiscussionTopic) forumManager
3283:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3284:                                .getId()));
3285:                selectedTopic.setTopic((DiscussionTopic) forumManager
3286:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3287:                                .getId()));
3288:                selectedTopic.getTopic().setBaseForum(selectedForum.getForum());
3289:                //selectedTopic.addMessage(new DiscussionMessageBean(dMsg, messageManager));
3290:                selectedTopic.insertMessage(new DiscussionMessageBean(dMsg,
3291:                        messageManager));
3292:                selectedTopic.getTopic().addMessage(dMsg);
3293:
3294:                this .composeBody = null;
3295:                this .composeLabel = null;
3296:                this .composeTitle = null;
3297:
3298:                this .attachments.clear();
3299:
3300:                return ALL_MESSAGES;
3301:            }
3302:
3303:            public String processDfReplyTopicCancel() {
3304:                this .composeBody = null;
3305:                this .composeLabel = null;
3306:                this .composeTitle = null;
3307:
3308:                this .attachments.clear();
3309:
3310:                return ALL_MESSAGES;
3311:            }
3312:
3313:            public boolean getDeleteMsg() {
3314:                return deleteMsg;
3315:            }
3316:
3317:            public String processDfMsgDeleteConfirmYes() {
3318:                List delList = new ArrayList();
3319:                messageManager.getChildMsgs(selectedMessage.getMessage()
3320:                        .getId(), delList);
3321:
3322:                if (delList.size() > 0) {
3323:                    if (!selectedTopic.getIsDeleteAny()) {
3324:                        errorSynch = true;
3325:                        return null;
3326:                    }
3327:                }
3328:
3329:                selectedTopic.removeMessage(selectedMessage);
3330:                Topic tempTopic = forumManager
3331:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3332:                                .getId());
3333:                tempTopic.removeMessage(selectedMessage.getMessage());
3334:                // selectedTopic.getTopic().removeMessage(selectedMessage.getMessage());
3335:                for (int i = 0; i < delList.size(); i++) {
3336:                    selectedTopic.removeMessage(new DiscussionMessageBean(
3337:                            (Message) delList.get(i), messageManager));
3338:                    // tempTopic.removeMessage((Message) delList.get(i));
3339:                    // selectedTopic.getTopic().removeMessage((Message) delList.get(i));
3340:                }
3341:
3342:                messageManager.deleteMsgWithChild(selectedMessage.getMessage()
3343:                        .getId());
3344:
3345:                try {
3346:                    DiscussionTopic topic = null;
3347:                    try {
3348:                        topic = forumManager.getTopicById(selectedTopic
3349:                                .getTopic().getId());
3350:                    } catch (NumberFormatException e) {
3351:                        LOG.error(e.getMessage(), e);
3352:                    }
3353:                    setSelectedForumForCurrentTopic(topic);
3354:                    selectedTopic = getDecoratedTopic(topic);
3355:                } catch (Exception e) {
3356:                    LOG.error(e.getMessage(), e);
3357:                    setErrorMessage(e.getMessage());
3358:                    this .deleteMsg = false;
3359:                    return gotoMain();
3360:                }
3361:
3362:                this .deleteMsg = false;
3363:
3364:                return ALL_MESSAGES;
3365:            }
3366:
3367:            public String processDfMsgDeleteCancel() {
3368:                this .deleteMsg = false;
3369:                this .errorSynch = false;
3370:
3371:                return null;
3372:            }
3373:
3374:            /**
3375:             * A moderator view of all msgs pending approval
3376:             * @return
3377:             */
3378:            public String processPendingMsgQueue() {
3379:                return PENDING_MSG_QUEUE;
3380:            }
3381:
3382:            /**
3383:             * "Pending Messages" link will be displayed if current user
3384:             * has moderate perm for at least one moderated topic in site.
3385:             * Also sets number of pending msgs
3386:             * @return
3387:             */
3388:            public boolean isDisplayPendingMsgQueue() {
3389:                List membershipList = uiPermissionsManager
3390:                        .getCurrentUserMemberships();
3391:                int numModTopicWithPerm = forumManager
3392:                        .getNumModTopicsWithModPermission(membershipList);
3393:
3394:                if (numModTopicWithPerm < 1)
3395:                    return false;
3396:
3397:                if (refreshPendingMsgs) {
3398:                    refreshPendingMessages();
3399:                }
3400:
3401:                return true;
3402:            }
3403:
3404:            public int getNumPendingMessages() {
3405:                return numPendingMessages;
3406:            }
3407:
3408:            public void setNumPendingMessages(int numPendingMessages) {
3409:                this .numPendingMessages = numPendingMessages;
3410:            }
3411:
3412:            /**
3413:             * Retrieve pending msgs from db and make DiscussionMessageBeans
3414:             *
3415:             */
3416:            private void refreshPendingMessages() {
3417:                pendingMsgs = new ArrayList();
3418:                numPendingMessages = 0;
3419:                List messages = forumManager
3420:                        .getPendingMsgsInSiteByMembership(uiPermissionsManager
3421:                                .getCurrentUserMemberships());
3422:
3423:                if (messages != null && !messages.isEmpty()) {
3424:                    messages = messageManager.sortMessageByDate(messages, true);
3425:
3426:                    Iterator msgIter = messages.iterator();
3427:                    while (msgIter.hasNext()) {
3428:                        Message msg = (Message) msgIter.next();
3429:                        DiscussionMessageBean decoMsg = new DiscussionMessageBean(
3430:                                msg, messageManager);
3431:                        pendingMsgs.add(decoMsg);
3432:                        numPendingMessages++;
3433:                    }
3434:                }
3435:
3436:                refreshPendingMsgs = false;
3437:            }
3438:
3439:            /**
3440:             * returns all messages in the site that are pending and curr user has
3441:             * moderate perm to view
3442:             * @return
3443:             */
3444:            public List getPendingMessages() {
3445:                if (refreshPendingMsgs) {
3446:                    refreshPendingMessages();
3447:                }
3448:
3449:                return pendingMsgs;
3450:            }
3451:
3452:            /**
3453:             * Will approve all "selected" messags
3454:             * @return
3455:             */
3456:            public String markCheckedAsApproved() {
3457:                approveOrDenySelectedMsgs(true);
3458:
3459:                if (numPendingMessages > 0)
3460:                    return PENDING_MSG_QUEUE;
3461:
3462:                return processActionHome();
3463:            }
3464:
3465:            /**
3466:             * Will deny all "selected" messages
3467:             * @return
3468:             */
3469:            public String markCheckedAsDenied() {
3470:                approveOrDenySelectedMsgs(false);
3471:
3472:                if (numPendingMessages > 0)
3473:                    return PENDING_MSG_QUEUE;
3474:
3475:                return processActionHome();
3476:            }
3477:
3478:            /**
3479:             * Mark selected msgs as denied or approved
3480:             * @param approved
3481:             */
3482:            private void approveOrDenySelectedMsgs(boolean approved) {
3483:                if (pendingMsgs == null || pendingMsgs.isEmpty()) {
3484:                    return;
3485:                }
3486:
3487:                int numSelected = 0;
3488:
3489:                Iterator iter = pendingMsgs.iterator();
3490:                while (iter.hasNext()) {
3491:                    DiscussionMessageBean decoMessage = (DiscussionMessageBean) iter
3492:                            .next();
3493:                    if (decoMessage.isSelected()) {
3494:                        Message msg = decoMessage.getMessage();
3495:                        messageManager.markMessageApproval(msg.getId(),
3496:                                approved);
3497:                        messageManager.markMessageReadForUser(msg.getTopic()
3498:                                .getId(), msg.getId(), true);
3499:                        numSelected++;
3500:                        numPendingMessages--;
3501:                    }
3502:                }
3503:
3504:                if (numSelected < 1)
3505:                    setErrorMessage(getResourceBundleString(NO_MSG_SEL_FOR_APPROVAL));
3506:                else {
3507:                    if (approved)
3508:                        setSuccessMessage(getResourceBundleString(MSGS_APPROVED));
3509:                    else
3510:                        setSuccessMessage(getResourceBundleString(MSGS_DENIED));
3511:                }
3512:
3513:                refreshPendingMsgs = true;
3514:            }
3515:
3516:            /**
3517:             * Deny a message
3518:             * @return
3519:             */
3520:            public String processDfMsgDeny() {
3521:                Long msgId = selectedMessage.getMessage().getId();
3522:                if (msgId != null) {
3523:                    messageManager.markMessageApproval(msgId, false);
3524:                    selectedMessage = new DiscussionMessageBean(messageManager
3525:                            .getMessageByIdWithAttachments(msgId),
3526:                            messageManager);
3527:                    setSuccessMessage(getResourceBundleString("cdfm_denied_alert"));
3528:                    getThreadFromMessage();
3529:                }
3530:
3531:                refreshPendingMsgs = true;
3532:
3533:                return MESSAGE_VIEW;
3534:            }
3535:
3536:            /**
3537:             * Deny a message and return to comment page
3538:             * @return
3539:             */
3540:            public String processDfMsgDenyAndComment() {
3541:                Long msgId = selectedMessage.getMessage().getId();
3542:                if (msgId != null) {
3543:                    messageManager.markMessageApproval(msgId, false);
3544:                    selectedMessage = new DiscussionMessageBean(messageManager
3545:                            .getMessageByIdWithAttachments(msgId),
3546:                            messageManager);
3547:                    displayDeniedMsg = true;
3548:                }
3549:
3550:                refreshPendingMsgs = true;
3551:
3552:                return ADD_COMMENT;
3553:            }
3554:
3555:            /**
3556:             * Approve a message
3557:             * @return
3558:             */
3559:            public String processDfMsgApprove() {
3560:                Long msgId = selectedMessage.getMessage().getId();
3561:                if (msgId != null) {
3562:                    messageManager.markMessageApproval(msgId, true);
3563:                    selectedMessage = new DiscussionMessageBean(messageManager
3564:                            .getMessageByIdWithAttachments(msgId),
3565:                            messageManager);
3566:                    setSuccessMessage(getResourceBundleString("cdfm_approved_alert"));
3567:                    getThreadFromMessage();
3568:                }
3569:
3570:                refreshPendingMsgs = true;
3571:
3572:                return MESSAGE_VIEW;
3573:            }
3574:
3575:            /**
3576:             * @return
3577:             */
3578:            public String processDfMsgAddComment() {
3579:                moderatorComments = "";
3580:                return ADD_COMMENT;
3581:            }
3582:
3583:            /**
3584:             * 
3585:             * @return
3586:             */
3587:            public String processCancelAddComment() {
3588:                if (displayDeniedMsg) // only displayed if from Deny & Comment path
3589:                {
3590:                    setSuccessMessage(getResourceBundleString("cdfm_denied_alert"));
3591:                    displayDeniedMsg = false;
3592:                }
3593:
3594:                return MESSAGE_VIEW;
3595:            }
3596:
3597:            /**
3598:             * Moderators may add a comment that is prepended to the text
3599:             * of the denied msg
3600:             * @return
3601:             */
3602:            public String processAddCommentToDeniedMsg() {
3603:                if (!selectedTopic.getIsModeratedAndHasPerm()) {
3604:                    setErrorMessage(getResourceBundleString(INSUFFICIENT_PRIVILEGES_TO_ADD_COMMENT));
3605:                    return ADD_COMMENT;
3606:                }
3607:
3608:                if (moderatorComments == null
3609:                        || moderatorComments.trim().length() < 1) {
3610:                    setErrorMessage(getResourceBundleString(INVALID_COMMENT));
3611:                    return ADD_COMMENT;
3612:                }
3613:
3614:                Message currMessage = selectedMessage.getMessage();
3615:
3616:                StringBuffer sb = new StringBuffer();
3617:                sb
3618:                        .append("<div style=\"font-style:italic; padding-bottom: 1.0em;\">");
3619:                sb.append("<div style=\"font-weight:bold;\">");
3620:                sb.append(getResourceBundleString(MOD_COMMENT_TEXT) + " ");
3621:                sb.append(UserDirectoryService.getCurrentUser()
3622:                        .getDisplayName());
3623:                sb.append("</div>");
3624:                sb.append(moderatorComments);
3625:                sb.append("</div>");
3626:
3627:                String originalText = currMessage.getBody();
3628:                currMessage.setBody(sb.toString() + originalText);
3629:
3630:                currMessage.setTopic((DiscussionTopic) forumManager
3631:                        .getTopicByIdWithMessages(selectedTopic.getTopic()
3632:                                .getId()));
3633:                forumManager.saveMessage(currMessage);
3634:
3635:                if (displayDeniedMsg) // only displayed if from Deny & Comment path
3636:                {
3637:                    setSuccessMessage(getResourceBundleString("cdfm_denied_alert"));
3638:                    displayDeniedMsg = false;
3639:                }
3640:
3641:                // we also must mark this message as unread for the author to let them
3642:                // know there is a comment
3643:                forumManager.markMessageReadStatusForUser(currMessage, false,
3644:                        currMessage.getCreatedBy());
3645:
3646:                return MESSAGE_VIEW;
3647:            }
3648:
3649:            /**
3650:             * Approve option is displayed if:
3651:             * 1) topic is moderated
3652:             * 2) user has moderate perm
3653:             * 3) message has not been approved
3654:             * @return
3655:             */
3656:            public boolean isAllowedToApproveMsg() {
3657:                return selectedTopic.getIsModeratedAndHasPerm()
3658:                        && !selectedMessage.isMsgApproved();
3659:            }
3660:
3661:            /**
3662:             * Deny option is displayed if:
3663:             * 1) topic is moderated
3664:             * 2) user has moderate perm
3665:             * 3) message has not been denied
3666:             * 4) message has no responses
3667:             * @return
3668:             */
3669:            public boolean isAllowedToDenyMsg() {
3670:                return selectedTopic.getIsModeratedAndHasPerm()
3671:                        && !selectedMessage.isMsgDenied()
3672:                        && !selectedMessage.getHasChild();
3673:            }
3674:
3675:            public void setNewForumBeanAssign() {
3676:                selectedForum.setGradeAssign("Default_0");
3677:            }
3678:
3679:            public void setNewTopicBeanAssign() {
3680:                if (selectedForum != null
3681:                        && selectedForum.getGradeAssign() != null
3682:                        && selectedForum.getForum() != null) {
3683:                    selectedTopic
3684:                            .setGradeAssign(selectedForum.getGradeAssign());
3685:                    selectedTopic.getTopic().setDefaultAssignName(
3686:                            selectedForum.getForum().getDefaultAssignName());
3687:                }
3688:            }
3689:
3690:            public void setNewTopicBeanAssign(DiscussionForumBean dfb,
3691:                    DiscussionTopicBean dtb) {
3692:                if (dfb != null && dfb.getGradeAssign() != null
3693:                        && dfb.getForum() != null) {
3694:                    dtb.setGradeAssign(dfb.getGradeAssign());
3695:                    dtb.getTopic().setDefaultAssignName(
3696:                            dfb.getForum().getDefaultAssignName());
3697:                }
3698:            }
3699:
3700:            public void setForumBeanAssign() {
3701:                if (assignments != null) {
3702:                    for (int i = 0; i < assignments.size(); i++) {
3703:                        if (((SelectItem) assignments.get(i)).getLabel()
3704:                                .equals(
3705:                                        selectedForum.getForum()
3706:                                                .getDefaultAssignName())) {
3707:                            selectedForum
3708:                                    .setGradeAssign((String) ((SelectItem) assignments
3709:                                            .get(i)).getValue());
3710:                            break;
3711:                        }
3712:                    }
3713:                }
3714:            }
3715:
3716:            public void setTopicBeanAssign() {
3717:                if (assignments != null) {
3718:                    for (int i = 0; i < assignments.size(); i++) {
3719:                        if (((SelectItem) assignments.get(i)).getLabel()
3720:                                .equals(
3721:                                        selectedTopic.getTopic()
3722:                                                .getDefaultAssignName())) {
3723:                            selectedTopic
3724:                                    .setGradeAssign((String) ((SelectItem) assignments
3725:                                            .get(i)).getValue());
3726:                            break;
3727:                        }
3728:                    }
3729:                }
3730:            }
3731:
3732:            public void setSelectedAssignForMessage(String assignName) {
3733:                if (assignments != null) {
3734:                    for (int i = 0; i < assignments.size(); i++) {
3735:                        if (((SelectItem) assignments.get(i)).getLabel()
3736:                                .equals(assignName)) {
3737:                            this .selectedAssign = (String) ((SelectItem) assignments
3738:                                    .get(i)).getValue();
3739:                            break;
3740:                        }
3741:                    }
3742:                }
3743:            }
3744:
3745:            public void saveForumSelectedAssignment(DiscussionForum forum) {
3746:                if (selectedForum.getGradeAssign() != null
3747:                        && !selectedForum.getGradeAssign().equals("Default_0")) {
3748:                    forum.setDefaultAssignName(((SelectItem) assignments
3749:                            .get(new Integer(selectedForum.getGradeAssign())
3750:                                    .intValue())).getLabel());
3751:                }
3752:            }
3753:
3754:            public void saveForumAttach(DiscussionForum forum) {
3755:                for (int i = 0; i < prepareRemoveAttach.size(); i++) {
3756:                    DecoratedAttachment removeAttach = (DecoratedAttachment) prepareRemoveAttach
3757:                            .get(i);
3758:                    List oldList = forum.getAttachments();
3759:                    for (int j = 0; j < oldList.size(); j++) {
3760:                        Attachment existedAttach = (Attachment) oldList.get(j);
3761:                        if (existedAttach.getAttachmentId().equals(
3762:                                removeAttach.getAttachment().getAttachmentId())) {
3763:                            forum
3764:                                    .removeAttachment(removeAttach
3765:                                            .getAttachment());
3766:                            break;
3767:                        }
3768:                    }
3769:                }
3770:
3771:                List oldList = forum.getAttachments();
3772:                if (oldList != null) {
3773:                    for (int i = 0; i < attachments.size(); i++) {
3774:                        DecoratedAttachment this Attach = (DecoratedAttachment) attachments
3775:                                .get(i);
3776:                        boolean existed = false;
3777:                        for (int j = 0; j < oldList.size(); j++) {
3778:                            Attachment existedAttach = (Attachment) oldList
3779:                                    .get(j);
3780:                            if (existedAttach.getAttachmentId().equals(
3781:                                    this Attach.getAttachment()
3782:                                            .getAttachmentId())) {
3783:                                existed = true;
3784:                                break;
3785:                            }
3786:                        }
3787:                        if (!existed) {
3788:                            forum.addAttachment(this Attach.getAttachment());
3789:                        }
3790:                    }
3791:                }
3792:
3793:                prepareRemoveAttach.clear();
3794:                attachments.clear();
3795:            }
3796:
3797:            public void saveTopicSelectedAssignment(DiscussionTopic topic) {
3798:                if (selectedTopic.getGradeAssign() != null
3799:                        && !selectedTopic.getGradeAssign().equals("Default_0")) {
3800:                    topic.setDefaultAssignName(((SelectItem) assignments
3801:                            .get(new Integer(selectedTopic.getGradeAssign())
3802:                                    .intValue())).getLabel());
3803:                }
3804:            }
3805:
3806:            public void saveTopicAttach(DiscussionTopic topic) {
3807:                for (int i = 0; i < prepareRemoveAttach.size(); i++) {
3808:                    DecoratedAttachment removeAttach = (DecoratedAttachment) prepareRemoveAttach
3809:                            .get(i);
3810:                    List oldList = topic.getAttachments();
3811:                    for (int j = 0; j < oldList.size(); j++) {
3812:                        Attachment existedAttach = (Attachment) oldList.get(j);
3813:                        if (existedAttach.getAttachmentId().equals(
3814:                                removeAttach.getAttachment().getAttachmentId())) {
3815:                            topic
3816:                                    .removeAttachment(removeAttach
3817:                                            .getAttachment());
3818:                            break;
3819:                        }
3820:                    }
3821:                }
3822:
3823:                List oldList = topic.getAttachments();
3824:                if (oldList != null) {
3825:                    for (int i = 0; i < attachments.size(); i++) {
3826:                        DecoratedAttachment this Attach = (DecoratedAttachment) attachments
3827:                                .get(i);
3828:                        boolean existed = false;
3829:                        for (int j = 0; j < oldList.size(); j++) {
3830:                            Attachment existedAttach = (Attachment) oldList
3831:                                    .get(j);
3832:                            if (existedAttach.getAttachmentId().equals(
3833:                                    this Attach.getAttachment()
3834:                                            .getAttachmentId())) {
3835:                                existed = true;
3836:                                break;
3837:                            }
3838:                        }
3839:                        if (!existed) {
3840:                            topic.addAttachment(this Attach.getAttachment());
3841:                        }
3842:                    }
3843:                }
3844:
3845:                prepareRemoveAttach.clear();
3846:                attachments.clear();
3847:            }
3848:
3849:            public String processDeleteAttachSetting() {
3850:                LOG.debug("processDeleteAttach()");
3851:
3852:                ExternalContext context = FacesContext.getCurrentInstance()
3853:                        .getExternalContext();
3854:                String attachId = null;
3855:
3856:                Map paramMap = context.getRequestParameterMap();
3857:                Iterator itr = paramMap.keySet().iterator();
3858:                while (itr.hasNext()) {
3859:                    Object key = itr.next();
3860:                    if (key instanceof  String) {
3861:                        String name = (String) key;
3862:                        int pos = name.lastIndexOf("dfmsg_current_attach");
3863:
3864:                        if (pos >= 0
3865:                                && name.length() == pos
3866:                                        + "dfmsg_current_attach".length()) {
3867:                            attachId = (String) paramMap.get(key);
3868:                            break;
3869:                        }
3870:                    }
3871:                }
3872:
3873:                if ((attachId != null) && (!attachId.equals(""))) {
3874:                    for (int i = 0; i < attachments.size(); i++) {
3875:                        if (attachId
3876:                                .equalsIgnoreCase(((DecoratedAttachment) attachments
3877:                                        .get(i)).getAttachment()
3878:                                        .getAttachmentId())) {
3879:                            prepareRemoveAttach
3880:                                    .add((DecoratedAttachment) attachments
3881:                                            .get(i));
3882:                            attachments.remove(i);
3883:                            break;
3884:                        }
3885:                    }
3886:                }
3887:
3888:                return null;
3889:            }
3890:
3891:            public boolean getThreaded() {
3892:                return threaded;
3893:            }
3894:
3895:            public void setThreaded(boolean threaded) {
3896:                this .threaded = threaded;
3897:            }
3898:
3899:            public String getExpanded() {
3900:                return expanded;
3901:            }
3902:
3903:            public boolean getExpandedView() {
3904:                return expandedView;
3905:            }
3906:
3907:            public void setExpanded(String expanded) {
3908:                this .expanded = expanded;
3909:            }
3910:
3911:            public void setGradeNotify(boolean gradeNotify) {
3912:                this .gradeNotify = gradeNotify;
3913:            }
3914:
3915:            public boolean getGradeNotify() {
3916:                return gradeNotify;
3917:            }
3918:
3919:            public String getSelectedAssign() {
3920:                return selectedAssign;
3921:            }
3922:
3923:            public void setSelectedAssign(String selectedAssign) {
3924:                this .selectedAssign = selectedAssign;
3925:            }
3926:
3927:            public void setGradePoint(String gradePoint) {
3928:                this .gradePoint = gradePoint;
3929:            }
3930:
3931:            public String getGradePoint() {
3932:                return gradePoint;
3933:            }
3934:
3935:            public List getAssignments() {
3936:                return assignments;
3937:            }
3938:
3939:            public void setAssignments(List assignments) {
3940:                this .assignments = assignments;
3941:            }
3942:
3943:            public void setGradeComment(String gradeComment) {
3944:                this .gradeComment = gradeComment;
3945:            }
3946:
3947:            public String getGradeComment() {
3948:                return gradeComment;
3949:            }
3950:
3951:            public void rearrageTopicMsgsThreaded() {
3952:                if (selectedTopic != null) {
3953:
3954:                    List msgsList = selectedTopic.getMessages();
3955:                    if (msgsList != null && !msgsList.isEmpty())
3956:                        msgsList = filterModeratedMessages(msgsList,
3957:                                selectedTopic.getTopic(),
3958:                                (DiscussionForum) selectedTopic.getTopic()
3959:                                        .getBaseForum());
3960:
3961:                    List orderedList = new ArrayList();
3962:                    List threadList = new ArrayList();
3963:
3964:                    if (msgsList != null) {
3965:                        for (int i = 0; i < msgsList.size(); i++) {
3966:                            DiscussionMessageBean dmb = (DiscussionMessageBean) msgsList
3967:                                    .get(i);
3968:                            if (dmb.getMessage().getInReplyTo() == null) {
3969:                                threadList.add(dmb);
3970:                                dmb.setDepth(0);
3971:                                orderedList.add(dmb);
3972:                                //for performance speed - operate with existing selectedTopic msgs instead of getting from manager through DB again 
3973:                                //recursiveGetThreadedMsgs(msgsList, orderedList, dmb);
3974:                                //use arrays so as to pass by reference during recursion
3975:                                recursiveGetThreadedMsgsFromListWithCounts(
3976:                                        msgsList, orderedList, dmb, new int[1],
3977:                                        new int[1]);
3978:                            }
3979:                        }
3980:                    }
3981:
3982:                    selectedTopic.setMessages(orderedList);
3983:                }
3984:
3985:            }
3986:
3987:            public void recursiveGetThreadedMsgs(List msgsList,
3988:                    List returnList, DiscussionMessageBean currentMsg) {
3989:                List childList = messageManager
3990:                        .getFirstLevelChildMsgs(currentMsg.getMessage().getId());
3991:
3992:                for (int j = 0; j < childList.size(); j++) {
3993:                    Message currentChild = (Message) childList.get(j);
3994:                    for (int k = 0; k < msgsList.size(); k++) {
3995:                        Message existedMsg = ((DiscussionMessageBean) msgsList
3996:                                .get(k)).getMessage();
3997:                        if (currentChild.getId().equals(existedMsg.getId())) {
3998:                            DiscussionMessageBean dmb = new DiscussionMessageBean(
3999:                                    currentChild, messageManager);
4000:                            /*					dmb.setDepth(currentMsg.getDepth() + 1);
4001:                             returnList.add(dmb);*/
4002:                            ((DiscussionMessageBean) msgsList.get(k))
4003:                                    .setDepth(currentMsg.getDepth() + 1);
4004:                            returnList.add(((DiscussionMessageBean) msgsList
4005:                                    .get(k)));
4006:                            recursiveGetThreadedMsgs(msgsList, returnList,
4007:                                    ((DiscussionMessageBean) msgsList.get(k)));
4008:                            break;
4009:                        }
4010:                    }
4011:                }
4012:
4013:            }
4014:
4015:            private void recursiveGetThreadedMsgsFromList(List msgsList,
4016:                    List returnList, DiscussionMessageBean currentMsg) {
4017:                for (int i = 0; i < msgsList.size(); i++) {
4018:                    DiscussionMessageBean this MsgBean = (DiscussionMessageBean) msgsList
4019:                            .get(i);
4020:                    Message this Msg = this MsgBean.getMessage();
4021:                    if (this Msg.getInReplyTo() != null
4022:                            && this Msg.getInReplyTo().getId().equals(
4023:                                    currentMsg.getMessage().getId())) {
4024:                        /*
4025:                         * DiscussionMessageBean dmb = new DiscussionMessageBean(thisMsg, messageManager);
4026:                         * dmb.setDepth(currentMsg.getDepth() + 1); returnList.add(dmb);
4027:                         * this.recursiveGetThreadedMsgsFromList(msgsList, returnList, dmb);
4028:                         */
4029:
4030:                        this MsgBean.setDepth(currentMsg.getDepth() + 1);
4031:                        returnList.add(this MsgBean);
4032:                        this .recursiveGetThreadedMsgsFromList(msgsList,
4033:                                returnList, this MsgBean);
4034:                    }
4035:                }
4036:            }
4037:
4038:            private void recursiveGetThreadedMsgsFromListWithCounts(
4039:                    List msgsList, List returnList,
4040:                    DiscussionMessageBean currentMsg, int[] childCount,
4041:                    int[] childUnread) {
4042:                for (int i = 0; i < msgsList.size(); i++) {
4043:                    DiscussionMessageBean this MsgBean = (DiscussionMessageBean) msgsList
4044:                            .get(i);
4045:                    Message this Msg = this MsgBean.getMessage();
4046:                    if (this Msg.getInReplyTo() != null
4047:                            && this Msg.getInReplyTo().getId().equals(
4048:                                    currentMsg.getMessage().getId())) {
4049:                        /*
4050:                         * DiscussionMessageBean dmb = new DiscussionMessageBean(thisMsg, messageManager);
4051:                         * dmb.setDepth(currentMsg.getDepth() + 1); returnList.add(dmb);
4052:                         * this.recursiveGetThreadedMsgsFromList(msgsList, returnList, dmb);
4053:                         */
4054:                        childCount[0]++;
4055:                        if (!this MsgBean.isRead()) {
4056:                            childUnread[0]++;
4057:                        }
4058:                        this MsgBean.setDepth(currentMsg.getDepth() + 1);
4059:                        returnList.add(this MsgBean);
4060:                        this .recursiveGetThreadedMsgsFromListWithCounts(
4061:                                msgsList, returnList, this MsgBean, childCount,
4062:                                childUnread);
4063:                    }
4064:                }
4065:                currentMsg.setChildCount(childCount[0]);
4066:                currentMsg.setChildUnread(childUnread[0]);
4067:            }
4068:
4069:            public String processDfGradeCancel() {
4070:
4071:                gradeNotify = false;
4072:                selectedAssign = "Default_0";
4073:                gradePoint = "";
4074:                gradeComment = "";
4075:                getThreadFromMessage();
4076:                return MESSAGE_VIEW;
4077:            }
4078:
4079:            public String processGradeAssignChange(ValueChangeEvent vce) {
4080:                String changeAssign = (String) vce.getNewValue();
4081:                if (changeAssign == null) {
4082:                    return null;
4083:                } else {
4084:                    try {
4085:                        selectedAssign = changeAssign;
4086:
4087:                        GradebookService gradebookService = (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
4088:                                .get("org.sakaiproject.service.gradebook.GradebookService");
4089:
4090:                        if ((!selectedAssign.equalsIgnoreCase("Default_0"))
4091:                                && ((gradebookService.getAssignmentScore(
4092:                                        ToolManager.getCurrentPlacement()
4093:                                                .getContext(),
4094:                                        ((SelectItem) assignments
4095:                                                .get((new Integer(
4096:                                                        selectedAssign))
4097:                                                        .intValue()))
4098:                                                .getLabel(),
4099:                                        UserDirectoryService.getUser(
4100:                                                selectedMessage.getMessage()
4101:                                                        .getCreatedBy())
4102:                                                .getId())) != null)) {
4103:                            gradePoint = (gradebookService.getAssignmentScore(
4104:                                    ToolManager.getCurrentPlacement()
4105:                                            .getContext(),
4106:                                    ((SelectItem) assignments.get((new Integer(
4107:                                            selectedAssign)).intValue()))
4108:                                            .getLabel(), UserDirectoryService
4109:                                            .getUser(
4110:                                                    selectedMessage
4111:                                                            .getMessage()
4112:                                                            .getCreatedBy())
4113:                                            .getId())).toString();
4114:                        } else {
4115:                            gradePoint = "";
4116:                        }
4117:
4118:                        return "dfMsgGrade";
4119:                    } catch (Exception e) {
4120:                        LOG
4121:                                .error("processGradeAssignChange in DiscussionFOrumTool - "
4122:                                        + e);
4123:                        e.printStackTrace();
4124:                        return null;
4125:                    }
4126:                }
4127:            }
4128:
4129:            public boolean isNumber(String validateString) {
4130:                try {
4131:                    double d = Double.valueOf(validateString).doubleValue();
4132:                    if (d >= 0)
4133:                        return true;
4134:                    else
4135:                        return false;
4136:                } catch (NumberFormatException e) {
4137:                    e.printStackTrace();
4138:                    return false;
4139:                }
4140:            }
4141:
4142:            public boolean isFewerDigit(String validateString) {
4143:                String stringValue = new Double(validateString).toString();
4144:                if (stringValue.lastIndexOf(".") >= 0) {
4145:                    String subString = stringValue.substring(stringValue
4146:                            .lastIndexOf("."));
4147:                    if (subString != null && subString.length() > 3)
4148:                        return false;
4149:                }
4150:
4151:                return true;
4152:            }
4153:
4154:            private boolean validateGradeInput() {
4155:                if (!isNumber(gradePoint)) {
4156:                    FacesContext currentContext = FacesContext
4157:                            .getCurrentInstance();
4158:                    String uiComponentId = "msgForum:dfMsgGradeGradePoint";
4159:                    FacesMessage validateMessage = new FacesMessage(
4160:                            getResourceBundleString(GRADE_GREATER_ZERO));
4161:                    validateMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
4162:                    currentContext.addMessage(uiComponentId, validateMessage);
4163:
4164:                    return false;
4165:                } else if (!isFewerDigit(gradePoint)) {
4166:                    FacesContext currentContext = FacesContext
4167:                            .getCurrentInstance();
4168:                    String uiComponentId = "msgForum:dfMsgGradeGradePoint";
4169:                    FacesMessage validateMessage = new FacesMessage(
4170:                            getResourceBundleString(GRADE_DECIMAL_WARN));
4171:                    validateMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
4172:                    currentContext.addMessage(uiComponentId, validateMessage);
4173:
4174:                    return false;
4175:                }
4176:
4177:                return true;
4178:            }
4179:
4180:            public String processDfGradeSubmit() {
4181:                if (gradePoint == null || gradePoint.trim().length() == 0) {
4182:                    setErrorMessage(getResourceBundleString(NO_GRADE_PTS));
4183:                    return null;
4184:                }
4185:
4186:                if (selectedAssign == null
4187:                        || selectedAssign.trim().length() == 0
4188:                        || selectedAssign.equalsIgnoreCase("Default_0")) {
4189:                    setErrorMessage(getResourceBundleString(NO_ASSGN));
4190:                    return null;
4191:                }
4192:
4193:                if (!validateGradeInput())
4194:                    return null;
4195:
4196:                try {
4197:                    if (selectedAssign != null
4198:                            && selectedAssign.trim().length() > 0) {
4199:                        if (!selectedAssign.equalsIgnoreCase("Default_0")) {
4200:                            if (gradePoint != null
4201:                                    && gradePoint.trim().length() > 0) {
4202:                                GradebookService gradebookService = (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
4203:                                        .get("org.sakaiproject.service.gradebook.GradebookService");
4204:                                String selectedAssignName = ((SelectItem) assignments
4205:                                        .get((new Integer(selectedAssign))
4206:                                                .intValue())).getLabel();
4207:                                String gradebookUuid = ToolManager
4208:                                        .getCurrentPlacement().getContext();
4209:                                String studentUid = UserDirectoryService
4210:                                        .getUser(
4211:                                                selectedMessage.getMessage()
4212:                                                        .getCreatedBy())
4213:                                        .getId();
4214:
4215:                                gradebookService.setAssignmentScore(
4216:                                        gradebookUuid, selectedAssignName,
4217:                                        studentUid, new Double(gradePoint), "");
4218:                                if (gradeComment != null
4219:                                        && gradeComment.trim().length() > 0) {
4220:                                    gradebookService.setAssignmentScoreComment(
4221:                                            gradebookUuid, selectedAssignName,
4222:                                            studentUid, gradeComment);
4223:                                }
4224:
4225:                                Message msg = selectedMessage.getMessage();
4226:                                msg.setGradeAssignmentName(selectedAssignName);
4227:                                msg.setTopic((DiscussionTopic) forumManager
4228:                                        .getTopicByIdWithMessages(selectedTopic
4229:                                                .getTopic().getId()));
4230:                                forumManager.saveMessage(msg);
4231:
4232:                                setSuccessMessage(getResourceBundleString(GRADE_SUCCESSFUL));
4233:                            }
4234:                        }
4235:                    }
4236:                } catch (Exception e) {
4237:                    LOG
4238:                            .error("DiscussionForumTool - processDfGradeSubmit:"
4239:                                    + e);
4240:                    e.printStackTrace();
4241:                }
4242:
4243:                gradeNotify = false;
4244:                selectedAssign = "Default_0";
4245:                gradePoint = "";
4246:                gradeComment = "";
4247:                getThreadFromMessage();
4248:                return MESSAGE_VIEW;
4249:            }
4250:
4251:            public String processCheckAll() {
4252:                for (int i = 0; i < selectedTopic.getMessages().size(); i++) {
4253:                    ((DiscussionMessageBean) selectedTopic.getMessages().get(i))
4254:                            .setSelected(true);
4255:                }
4256:                return null;
4257:            }
4258:
4259:            private void setMessageBeanPreNextStatus() {
4260:                if (selectedTopic != null) {
4261:                    if (selectedTopic.getMessages() != null) {
4262:                        List tempMsgs = selectedTopic.getMessages();
4263:                        for (int i = 0; i < tempMsgs.size(); i++) {
4264:                            DiscussionMessageBean dmb = (DiscussionMessageBean) tempMsgs
4265:                                    .get(i);
4266:                            if (i == 0) {
4267:                                dmb.setHasPre(false);
4268:                                if (i == (tempMsgs.size() - 1)) {
4269:                                    dmb.setHasNext(false);
4270:                                } else {
4271:                                    dmb.setHasNext(true);
4272:                                }
4273:                            } else if (i == (tempMsgs.size() - 1)) {
4274:                                dmb.setHasPre(true);
4275:                                dmb.setHasNext(false);
4276:                            } else {
4277:                                dmb.setHasNext(true);
4278:                                dmb.setHasPre(true);
4279:                            }
4280:                        }
4281:                    }
4282:                }
4283:            }
4284:
4285:            /**
4286:             * @return Returns the selectedMessageView.
4287:             */
4288:            public String getSelectedMessageView() {
4289:                return selectedMessageView;
4290:            }
4291:
4292:            /**
4293:             * @param selectedMessageView
4294:             *          The selectedMessageView to set.
4295:             */
4296:            public void setSelectedMessageView(String selectedMessageView) {
4297:                this .selectedMessageView = selectedMessageView;
4298:            }
4299:
4300:            /**
4301:             * @return Returns the selectedMessageShow.
4302:             */
4303:            public String getSelectedMessageShow() {
4304:                return selectedMessageShow;
4305:            }
4306:
4307:            /**
4308:             * @param selectedMessageShow
4309:             *          The selectedMessageShow to set.
4310:             */
4311:            public void setSelectedMessageShow(String selectedMessageShow) {
4312:                this .selectedMessageShow = selectedMessageShow;
4313:            }
4314:
4315:            /**
4316:             * @return Returns the selectedMessagOrganize.
4317:             */
4318:            public String getSelectedMessageOrganize() {
4319:                return selectedMessageOrganize;
4320:            }
4321:
4322:            /**
4323:             * @param selectedMessageOrganize
4324:             *          The selectedMessageOrganize to set.
4325:             */
4326:            public void setSelectedMessageOrganize(
4327:                    String selectedMessageOrganize) {
4328:                this .selectedMessageOrganize = selectedMessageOrganize;
4329:            }
4330:
4331:            public String getThreadAnchorMessageId() {
4332:                return threadAnchorMessageId;
4333:            }
4334:
4335:            public void setThreadAnchorMessageId(String newValue) {
4336:                threadAnchorMessageId = newValue;
4337:            }
4338:
4339:            /**
4340:             * @return Returns the displayUnreadOnly.
4341:             */
4342:            public boolean getDisplayUnreadOnly() {
4343:                return displayUnreadOnly;
4344:            }
4345:
4346:            public void processActionToggleExpanded() {
4347:                if (expanded.equals("true")) {
4348:                    expanded = "false";
4349:                } else {
4350:                    expanded = "true";
4351:                }
4352:            }
4353:
4354:            /**
4355:             * @param vce
4356:             */
4357:            public void processValueChangeForMessageView(ValueChangeEvent vce) {
4358:                if (LOG.isDebugEnabled())
4359:                    LOG
4360:                            .debug("processValueChangeForMessageView(ValueChangeEvent "
4361:                                    + vce + ")");
4362:                isDisplaySearchedMessages = false;
4363:                searchText = "";
4364:                String changeView = (String) vce.getNewValue();
4365:                this .displayUnreadOnly = false;
4366:                //expandedView = false;
4367:                if (changeView == null) {
4368:                    //threaded = false;
4369:                    setErrorMessage(getResourceBundleString(FAILED_REND_MESSAGE));
4370:                    return;
4371:                }
4372:                if (changeView.equals(ALL_MESSAGES)) {
4373:                    //threaded = false;
4374:                    setSelectedMessageView(ALL_MESSAGES);
4375:
4376:                    DiscussionTopic topic = null;
4377:                    topic = forumManager.getTopicById(selectedTopic.getTopic()
4378:                            .getId());
4379:                    setSelectedForumForCurrentTopic(topic);
4380:                    selectedTopic = getDecoratedTopic(topic);
4381:
4382:                    return;
4383:                } else if (changeView.equals(UNREAD_VIEW)) {
4384:                    //threaded = false;
4385:                    this .displayUnreadOnly = true;
4386:                    return;
4387:                }
4388:                /*
4389:                  else
4390:                	if (changeView.equals(EXPANDED_VIEW))
4391:                	{
4392:                		threaded = false;
4393:                		expandedView = true;
4394:                		return;
4395:                	}
4396:                    else
4397:                      if (changeView.equals(THREADED_VIEW))
4398:                      {
4399:                        threaded = true;
4400:                        expanded = "true";
4401:                        return;
4402:                      }
4403:                      else
4404:                        if (changeView.equals("expand"))
4405:                        {
4406:                          threaded = true;
4407:                          expanded = "true";
4408:                          return;
4409:                        }
4410:                        else
4411:                          if (changeView.equals("collapse"))
4412:                          {
4413:                            threaded = true;
4414:                            expanded = "false";
4415:                            return;
4416:                          }
4417:                 */
4418:                else {
4419:                    //threaded = false;
4420:                    setErrorMessage(getResourceBundleString(VIEW_UNDER_CONSTRUCT));
4421:                    return;
4422:                }
4423:            }
4424:
4425:            public void processValueChangedForMessageShow(ValueChangeEvent vce) {
4426:                if (LOG.isDebugEnabled())
4427:                    LOG
4428:                            .debug("processValueChangeForMessageView(ValueChangeEvent "
4429:                                    + vce + ")");
4430:                isDisplaySearchedMessages = false;
4431:                searchText = "";
4432:                String changeShow = (String) vce.getNewValue();
4433:                if (changeShow == null) {
4434:                    //threaded = false;
4435:                    setErrorMessage(getResourceBundleString(FAILED_REND_MESSAGE));
4436:                    return;
4437:                }
4438:                if (changeShow.equals(ENTIRE_MSG)) {
4439:                    //threaded = false;
4440:                    selectedMessageShow = ENTIRE_MSG;
4441:                    expandedView = true;
4442:                    return;
4443:                } else {
4444:                    selectedMessageShow = SUBJECT_ONLY;
4445:                    expandedView = false;
4446:                    return;
4447:                }
4448:            }
4449:
4450:            public void processValueChangedForMessageOrganize(
4451:                    ValueChangeEvent vce) {
4452:                if (LOG.isDebugEnabled())
4453:                    LOG
4454:                            .debug("processValueChangeForMessageView(ValueChangeEvent "
4455:                                    + vce + ")");
4456:                isDisplaySearchedMessages = false;
4457:                searchText = "";
4458:                //expanded="false";
4459:                String changeOrganize = (String) vce.getNewValue();
4460:
4461:                threadAnchorMessageId = null;
4462:                DiscussionTopic topic = null;
4463:                topic = forumManager.getTopicById(selectedTopic.getTopic()
4464:                        .getId());
4465:                setSelectedForumForCurrentTopic(topic);
4466:                selectedTopic = getDecoratedTopic(topic);
4467:
4468:                if (changeOrganize == null) {
4469:                    //threaded = false;
4470:                    setErrorMessage(getResourceBundleString(FAILED_REND_MESSAGE));
4471:                    return;
4472:                }
4473:                if (changeOrganize.equals("thread")) {
4474:                    threaded = true;
4475:                    orderAsc = true;
4476:                    displayUnreadOnly = false;
4477:                } else if (changeOrganize.equals("date_desc")) {
4478:                    threaded = false;
4479:                    orderAsc = false;
4480:                    displayUnreadOnly = false;
4481:                } else if (changeOrganize.equals("date")) {
4482:                    orderAsc = true;
4483:                    threaded = false;
4484:                    displayUnreadOnly = false;
4485:                } else if (changeOrganize.equals("unread")) {
4486:                    orderAsc = true;
4487:                    threaded = false;
4488:                    displayUnreadOnly = true;
4489:                }
4490:
4491:                return;
4492:            }
4493:
4494:            public boolean getErrorSynch() {
4495:                return errorSynch;
4496:            }
4497:
4498:            public void setErrorSynch(boolean errorSynch) {
4499:                this .errorSynch = errorSynch;
4500:            }
4501:
4502:            /**
4503:             * @return
4504:             */
4505:            public String processActionSearch() {
4506:                LOG.debug("processActionSearch()");
4507:
4508:                //    //TODO : should be fetched via a query in db
4509:                //    //Subject, Authored By, Date,
4510:                //    isDisplaySearchedMessages=true;
4511:                //  
4512:                //    if(searchText==null || searchText.trim().length()<1)
4513:                //    {
4514:                //      setErrorMessage("Invalid search criteria");  
4515:                //      return ALL_MESSAGES;
4516:                //    }
4517:                //    if(selectedTopic == null)
4518:                //    {
4519:                //      setErrorMessage("There is no topic selected for search");     
4520:                //      return ALL_MESSAGES;
4521:                //    }
4522:                //    searchResults=new  DiscussionTopicBean(selectedTopic.getTopic(),selectedForum.getForum() ,uiPermissionsManager);
4523:                //   if(selectedTopic.getMessages()!=null)
4524:                //    {
4525:                //     Iterator iter = selectedTopic.getMessages().iterator();
4526:                //     
4527:                //     while (iter.hasNext())
4528:                //      {
4529:                //            DiscussionMessageBean decoMessage = (DiscussionMessageBean) iter.next();
4530:                //        if((decoMessage.getMessage()!= null && (decoMessage.getMessage().getTitle().matches(".*"+searchText+".*") ||
4531:                //            decoMessage.getMessage().getCreatedBy().matches(".*"+searchText+".*") ||
4532:                //            decoMessage.getMessage().getCreated().toString().matches(".*"+searchText+".*") )))
4533:                //        {
4534:                //          searchResults.addMessage(decoMessage);
4535:                //        }
4536:                //      }
4537:                //    }  
4538:                return ALL_MESSAGES;
4539:            }
4540:
4541:            /**
4542:             * @return
4543:             */
4544:            public String processActionMarkAllAsRead() {
4545:                return markAllMessages(true);
4546:            }
4547:
4548:            /**
4549:             * @return
4550:             */
4551:            public String processActionMarkAllThreadAsRead() {
4552:                return markAllThreadAsRead(true);
4553:            }
4554:
4555:            /**
4556:             * @return
4557:             */
4558:            public String processActionMarkCheckedAsRead() {
4559:                return markCheckedMessages(true);
4560:            }
4561:
4562:            /**
4563:             * @return
4564:             */
4565:            public String processActionMarkCheckedAsUnread() {
4566:                return markCheckedMessages(false);
4567:            }
4568:
4569:            private String markCheckedMessages(boolean readStatus) {
4570:                if (selectedTopic == null) {
4571:                    setErrorMessage(getResourceBundleString(LOST_ASSOCIATE));
4572:                    return ALL_MESSAGES;
4573:                }
4574:                List messages = selectedTopic.getMessages();
4575:                if (messages == null || messages.size() < 1) {
4576:                    setErrorMessage(getResourceBundleString(NO_MARKED_READ_MESSAGE));
4577:                    return ALL_MESSAGES;
4578:                }
4579:                Iterator iter = messages.iterator();
4580:                while (iter.hasNext()) {
4581:                    DiscussionMessageBean decoMessage = (DiscussionMessageBean) iter
4582:                            .next();
4583:                    if (decoMessage.isSelected()) {
4584:                        forumManager.markMessageAs(decoMessage.getMessage(),
4585:                                readStatus);
4586:                    }
4587:                }
4588:                return displayTopicById(TOPIC_ID); // reconstruct topic again;
4589:            }
4590:
4591:            private String markAllMessages(boolean readStatus) {
4592:                if (selectedTopic == null) {
4593:                    setErrorMessage(getResourceBundleString(LOST_ASSOCIATE));
4594:                    return ALL_MESSAGES;
4595:                }
4596:                List messages = selectedTopic.getMessages();
4597:                if (messages == null || messages.size() < 1) {
4598:                    setErrorMessage(getResourceBundleString(NO_MARKED_READ_MESSAGE));
4599:                    return ALL_MESSAGES;
4600:                }
4601:                Iterator iter = messages.iterator();
4602:                while (iter.hasNext()) {
4603:                    DiscussionMessageBean decoMessage = (DiscussionMessageBean) iter
4604:                            .next();
4605:                    forumManager.markMessageAs(decoMessage.getMessage(),
4606:                            readStatus);
4607:
4608:                }
4609:                //return displayTopicById(TOPIC_ID); // reconstruct topic again;
4610:                setSelectedForumForCurrentTopic(selectedTopic.getTopic());
4611:                selectedTopic = getDecoratedTopic(selectedTopic.getTopic());
4612:                return processActionDisplayFlatView();
4613:            }
4614:
4615:            private String markAllThreadAsRead(boolean readStatus) {
4616:                if (selectedThreadHead == null) {
4617:                    setErrorMessage(getResourceBundleString(LOST_ASSOCIATE));
4618:                    return ALL_MESSAGES;
4619:                }
4620:                if (selectedThread == null || selectedThread.size() < 1) {
4621:                    setErrorMessage(getResourceBundleString(NO_MARKED_READ_MESSAGE));
4622:                    return ALL_MESSAGES;
4623:                }
4624:                Iterator iter = selectedThread.iterator();
4625:                while (iter.hasNext()) {
4626:                    DiscussionMessageBean decoMessage = (DiscussionMessageBean) iter
4627:                            .next();
4628:                    forumManager.markMessageAs(decoMessage.getMessage(),
4629:                            readStatus);
4630:                }
4631:                return processActionGetDisplayThread();
4632:            }
4633:
4634:            /**
4635:             * @return Returns the isDisplaySearchedMessages.
4636:             */
4637:            public boolean getIsDisplaySearchedMessages() {
4638:                return isDisplaySearchedMessages;
4639:            }
4640:
4641:            /**
4642:             * @return Returns the searchText.
4643:             */
4644:            public String getSearchText() {
4645:                return searchText;
4646:            }
4647:
4648:            /**
4649:             * @param searchText
4650:             *          The searchText to set.
4651:             */
4652:            public void setSearchText(String searchText) {
4653:                this .searchText = searchText;
4654:            }
4655:
4656:            public List getSiteMembers() {
4657:                return getSiteMembers(true);
4658:            }
4659:
4660:            public List getSiteRoles() {
4661:                //for group awareness
4662:                //return getSiteMembers(false);
4663:                return getSiteMembers(true);
4664:            }
4665:
4666:            public List getSiteMembers(boolean includeGroup) {
4667:                LOG.debug("getSiteMembers()");
4668:
4669:                if (siteMembers != null && siteMembers.size() > 0) {
4670:                    return siteMembers;
4671:                }
4672:
4673:                permissions = new ArrayList();
4674:
4675:                Set membershipItems = null;
4676:
4677:                if (PERMISSION_MODE_TEMPLATE.equals(getPermissionMode())) {
4678:                    //membershipItems = forumManager.getDiscussionForumArea().getMembershipItemSet();
4679:                    membershipItems = uiPermissionsManager
4680:                            .getAreaItemsSet(forumManager
4681:                                    .getDiscussionForumArea());
4682:                } else if (PERMISSION_MODE_FORUM.equals(getPermissionMode())) {
4683:                    if (selectedForum != null
4684:                            && selectedForum.getForum() != null) {
4685:                        membershipItems = uiPermissionsManager
4686:                                .getForumItemsSet(selectedForum.getForum());
4687:                        if (membershipItems == null
4688:                                || membershipItems.size() == 0) {
4689:                            membershipItems = uiPermissionsManager
4690:                                    .getAreaItemsSet(forumManager
4691:                                            .getDiscussionForumArea());
4692:                        }
4693:                    } else {
4694:                        membershipItems = uiPermissionsManager
4695:                                .getAreaItemsSet(forumManager
4696:                                        .getDiscussionForumArea());
4697:                    }
4698:                } else if (PERMISSION_MODE_TOPIC.equals(getPermissionMode())) {
4699:                    if (selectedTopic != null
4700:                            && selectedTopic.getTopic() != null) {
4701:                        membershipItems = uiPermissionsManager
4702:                                .getTopicItemsSet(selectedTopic.getTopic());
4703:                    }
4704:                    if (membershipItems == null
4705:                            || membershipItems.size() == 0
4706:                            && (selectedForum != null && selectedForum
4707:                                    .getForum() != null)) {
4708:                        membershipItems = uiPermissionsManager
4709:                                .getForumItemsSet(selectedForum.getForum());
4710:                    }
4711:                }
4712:
4713:                siteMembers = new ArrayList();
4714:                // get Roles     
4715:                AuthzGroup realm;
4716:                Site currentSite = null;
4717:                int i = 0;
4718:                try {
4719:                    realm = AuthzGroupService.getAuthzGroup(getContextSiteId());
4720:
4721:                    Set roles1 = realm.getRoles();
4722:
4723:                    if (roles1 != null && roles1.size() > 0) {
4724:                        List rolesList = sortRoles(roles1);
4725:
4726:                        Iterator roleIter = rolesList.iterator();
4727:                        while (roleIter.hasNext()) {
4728:                            Role role = (Role) roleIter.next();
4729:                            if (role != null) {
4730:                                if (i == 0) {
4731:                                    selectedRole = role.getId();
4732:                                    i = 1;
4733:                                }
4734:                                DBMembershipItem item = forumManager
4735:                                        .getAreaDBMember(membershipItems, role
4736:                                                .getId(),
4737:                                                DBMembershipItem.TYPE_ROLE);
4738:                                siteMembers.add(new SelectItem(role.getId(),
4739:                                        role.getId() + " ("
4740:                                                + item.getPermissionLevelName()
4741:                                                + ")"));
4742:                                permissions.add(new PermissionBean(item,
4743:                                        permissionLevelManager));
4744:                            }
4745:                        }
4746:                    }
4747:
4748:                    if (includeGroup) {
4749:                        currentSite = SiteService.getSite(ToolManager
4750:                                .getCurrentPlacement().getContext());
4751:
4752:                        Collection groups = currentSite.getGroups();
4753:
4754:                        groups = sortGroups(groups);
4755:
4756:                        for (Iterator groupIterator = groups.iterator(); groupIterator
4757:                                .hasNext();) {
4758:                            Group currentGroup = (Group) groupIterator.next();
4759:                            DBMembershipItem item = forumManager
4760:                                    .getAreaDBMember(membershipItems,
4761:                                            currentGroup.getTitle(),
4762:                                            DBMembershipItem.TYPE_GROUP);
4763:                            siteMembers
4764:                                    .add(new SelectItem(
4765:                                            currentGroup.getTitle(),
4766:                                            currentGroup.getTitle()
4767:                                                    + " ("
4768:                                                    + item.getPermissionLevel()
4769:                                                            .getName() + ")"));
4770:                            permissions.add(new PermissionBean(item,
4771:                                    permissionLevelManager));
4772:                        }
4773:                    }
4774:                } catch (IdUnusedException e) {
4775:                    LOG.error(e.getMessage(), e);
4776:                } catch (GroupNotDefinedException e) {
4777:                    // TODO Auto-generated catch block
4778:                    e.printStackTrace();
4779:                }
4780:
4781:                return siteMembers;
4782:            }
4783:
4784:            /**
4785:             * Takes roles defined and sorts them alphabetically by id
4786:             * so when displayed will be in order.
4787:             * 
4788:             * @param roles
4789:             * 			Set of defined roles
4790:             * 
4791:             * @return
4792:             * 			Set of defined roles sorted
4793:             */
4794:            private List sortRoles(Set roles) {
4795:                final List rolesList = new ArrayList();
4796:
4797:                rolesList.addAll(roles);
4798:
4799:                final AuthzGroupComparator authzGroupComparator = new AuthzGroupComparator(
4800:                        "id", true);
4801:
4802:                Collections.sort(rolesList, authzGroupComparator);
4803:
4804:                return rolesList;
4805:            }
4806:
4807:            /**
4808:             * Takes groups defined and sorts them alphabetically by title
4809:             * so will be in some order when displayed on permission widget.
4810:             * 
4811:             * @param groups
4812:             * 			Collection of groups to be sorted
4813:             * 
4814:             * @return
4815:             * 		Collection of groups in sorted order
4816:             */
4817:            private Collection sortGroups(Collection groups) {
4818:                List sortGroupsList = new ArrayList();
4819:
4820:                sortGroupsList.addAll(groups);
4821:
4822:                final GroupComparator groupComparator = new GroupComparator(
4823:                        "title", true);
4824:
4825:                Collections.sort(sortGroupsList, groupComparator);
4826:
4827:                groups.clear();
4828:
4829:                groups.addAll(sortGroupsList);
4830:
4831:                return groups;
4832:            }
4833:
4834:            /**
4835:             * @return siteId
4836:             */
4837:            private String getContextSiteId() {
4838:                LOG.debug("getContextSiteId()");
4839:                return ("/site/" + ToolManager.getCurrentPlacement()
4840:                        .getContext());
4841:            }
4842:
4843:            /**
4844:             * @param topic
4845:             */
4846:            private void setSelectedForumForCurrentTopic(DiscussionTopic topic) {
4847:                if (selectedForum != null) {
4848:                    return;
4849:                }
4850:                DiscussionForum forum = (DiscussionForum) topic.getBaseForum();
4851:                if (forum == null) {
4852:
4853:                    String forumId = getExternalParameterByKey(FORUM_ID);
4854:                    if (forumId == null || forumId.trim().length() < 1) {
4855:                        selectedForum = null;
4856:                        return;
4857:                    }
4858:                    forum = forumManager.getForumById(new Long(forumId));
4859:                    if (forum == null) {
4860:                        selectedForum = null;
4861:                        return;
4862:                    }
4863:                }
4864:                selectedForum = new DiscussionForumBean(forum,
4865:                        uiPermissionsManager, forumManager);
4866:                if ("true".equalsIgnoreCase(ServerConfigurationService
4867:                        .getString("mc.defaultLongDescription"))) {
4868:                    selectedForum.setReadFullDesciption(true);
4869:                }
4870:
4871:                setForumBeanAssign();
4872:            }
4873:
4874:            /**
4875:             * @param errorMsg
4876:             */
4877:            private void setErrorMessage(String errorMsg) {
4878:                LOG.debug("setErrorMessage(String " + errorMsg + ")");
4879:                FacesContext.getCurrentInstance()
4880:                        .addMessage(
4881:                                null,
4882:                                new FacesMessage(FacesMessage.SEVERITY_ERROR,
4883:                                        getResourceBundleString(ALERT)
4884:                                                + errorMsg, null));
4885:            }
4886:
4887:            private void setSuccessMessage(String successMsg) {
4888:                LOG.debug("setSuccessMessage(String " + successMsg + ")");
4889:                FacesContext.getCurrentInstance().addMessage(
4890:                        null,
4891:                        new FacesMessage(FacesMessage.SEVERITY_INFO,
4892:                                successMsg, null));
4893:            }
4894:
4895:            public void processPost() {
4896:
4897:            }
4898:
4899:            public String generatePermissionScript() {
4900:
4901:                PermissionLevel ownerLevel = permissionLevelManager
4902:                        .getDefaultOwnerPermissionLevel();
4903:                PermissionLevel authorLevel = permissionLevelManager
4904:                        .getDefaultAuthorPermissionLevel();
4905:                PermissionLevel noneditingAuthorLevel = permissionLevelManager
4906:                        .getDefaultNoneditingAuthorPermissionLevel();
4907:                PermissionLevel reviewerLevel = permissionLevelManager
4908:                        .getDefaultReviewerPermissionLevel();
4909:                PermissionLevel noneLevel = permissionLevelManager
4910:                        .getDefaultNonePermissionLevel();
4911:                PermissionLevel contributorLevel = permissionLevelManager
4912:                        .getDefaultContributorPermissionLevel();
4913:
4914:                StringBuffer sBuffer = new StringBuffer();
4915:                sBuffer.append("<script type=\"text/javascript\">\n");
4916:                sBuffer.append("var ownerLevelArray = " + ownerLevel + ";\n");
4917:                sBuffer.append("var authorLevelArray = " + authorLevel + ";\n");
4918:                sBuffer.append("var noneditingAuthorLevelArray = "
4919:                        + noneditingAuthorLevel + ";\n");
4920:                sBuffer.append("var reviewerLevelArray = " + reviewerLevel
4921:                        + ";\n");
4922:                sBuffer.append("var noneLevelArray = " + noneLevel + ";\n");
4923:                sBuffer.append("var contributorLevelArray = "
4924:                        + contributorLevel + ";\n");
4925:                sBuffer.append("var owner = 'Owner';\n");
4926:                sBuffer.append("var author = 'Author';\n");
4927:                sBuffer.append("var nonEditingAuthor = 'Nonediting Author';\n");
4928:                sBuffer.append("var reviewer = 'Reviewer';\n");
4929:                sBuffer.append("var none = 'None';\n");
4930:                sBuffer.append("var contributor = 'Contributor';\n");
4931:                sBuffer.append("var custom = 'Custom';\n");
4932:                sBuffer.append("var all = 'All';\n");
4933:                sBuffer.append("var own = 'Own';\n");
4934:
4935:                sBuffer
4936:                        .append("function checkLevel(selectedLevel){\n"
4937:                                + "  var ownerVal = true;\n"
4938:                                + "  var authorVal = true;\n"
4939:                                + "  var noneditingAuthorVal = true;\n"
4940:                                + "  var reviewerVal = true;\n"
4941:                                + "  var noneVal = true;\n"
4942:                                + "  var contributorVal = true;\n\n"
4943:                                + "  for (var i = 0; i < selectedLevel.length; i++){\n"
4944:                                + "    if (ownerVal && ownerLevelArray[i] != selectedLevel[i])\n"
4945:                                + "      ownerVal = false;\n"
4946:                                + "    if (authorVal && authorLevelArray[i] != selectedLevel[i])\n"
4947:                                + "      authorVal = false;\n"
4948:                                + "    if (noneditingAuthorVal && noneditingAuthorLevelArray[i] != selectedLevel[i])\n"
4949:                                + "      noneditingAuthorVal = false;\n"
4950:                                + "    if (reviewerVal && reviewerLevelArray[i] != selectedLevel[i])\n"
4951:                                + "      reviewerVal = false;\n"
4952:                                + "    if (noneVal && noneLevelArray[i] != selectedLevel[i])\n"
4953:                                + "      noneVal = false;\n"
4954:                                + "    if (contributorVal && contributorLevelArray[i] != selectedLevel[i])\n"
4955:                                + "      contributorVal = false;\n" + "  }\n\n"
4956:                                + "  if (ownerVal)\n" + "    return 'Owner';\n"
4957:                                + "  else if (authorVal)\n"
4958:                                + "    return 'Author';\n"
4959:                                + "  else if (noneditingAuthorVal)\n"
4960:                                + "    return 'Nonediting Author';\n"
4961:                                + "  else if (reviewerVal)\n"
4962:                                + "    return 'Reviewer';\n"
4963:                                + "  else if (noneVal)\n"
4964:                                + "    return 'None';\n"
4965:                                + "  else if (contributorVal)\n"
4966:                                + "    return 'Contributor';\n"
4967:                                + "  else return 'Custom';\n" + "}\n");
4968:
4969:                sBuffer.append("</script>");
4970:                return sBuffer.toString();
4971:            }
4972:
4973:            public void setObjectPermissions(Object target) {
4974:                Set membershipItemSet = null;
4975:                Set oldMembershipItemSet = null;
4976:
4977:                DiscussionForum forum = null;
4978:                Area area = null;
4979:                //Topic topic = null;
4980:                DiscussionTopic topic = null;
4981:
4982:                /** get membership item set */
4983:                if (target instanceof  DiscussionForum) {
4984:                    forum = ((DiscussionForum) target);
4985:                    //membershipItemSet = forum.getMembershipItemSet();
4986:                    //membershipItemSet = uiPermissionsManager.getForumItemsSet(forum);
4987:                    oldMembershipItemSet = uiPermissionsManager
4988:                            .getForumItemsSet(forum);
4989:                } else if (target instanceof  Area) {
4990:                    area = ((Area) target);
4991:                    //membershipItemSet = area.getMembershipItemSet();
4992:                    //membershipItemSet = uiPermissionsManager.getAreaItemsSet();
4993:                    oldMembershipItemSet = uiPermissionsManager
4994:                            .getAreaItemsSet(area);
4995:                } else if (target instanceof  Topic) {
4996:                    //topic = ((Topic) target);
4997:                    //membershipItemSet = topic.getMembershipItemSet();
4998:                    topic = ((DiscussionTopic) target);
4999:                    //membershipItemSet = uiPermissionsManager.getTopicItemsSet(topic);
5000:                    oldMembershipItemSet = uiPermissionsManager
5001:                            .getTopicItemsSet(topic);
5002:                }
5003:
5004:                if (membershipItemSet != null) {
5005:                    membershipItemSet.clear();
5006:                } else {
5007:                    membershipItemSet = new HashSet();
5008:                }
5009:
5010:                if (permissions != null) {
5011:                    Iterator iter = permissions.iterator();
5012:                    while (iter.hasNext()) {
5013:                        PermissionBean permBean = (PermissionBean) iter.next();
5014:                        //for group awareness
5015:                        //DBMembershipItem membershipItem = permissionLevelManager.createDBMembershipItem(permBean.getItem().getName(), permBean.getSelectedLevel(), DBMembershipItem.TYPE_ROLE);
5016:                        DBMembershipItem membershipItem = permissionLevelManager
5017:                                .createDBMembershipItem(permBean.getItem()
5018:                                        .getName(),
5019:                                        permBean.getSelectedLevel(), permBean
5020:                                                .getItem().getType());
5021:
5022:                        if (PermissionLevelManager.PERMISSION_LEVEL_NAME_CUSTOM
5023:                                .equals(membershipItem.getPermissionLevelName())) {
5024:                            PermissionsMask mask = new PermissionsMask();
5025:                            mask.put(PermissionLevel.NEW_FORUM, new Boolean(
5026:                                    permBean.getNewForum()));
5027:                            mask.put(PermissionLevel.NEW_TOPIC, new Boolean(
5028:                                    permBean.getNewTopic()));
5029:                            mask.put(PermissionLevel.NEW_RESPONSE, new Boolean(
5030:                                    permBean.getNewResponse()));
5031:                            mask.put(PermissionLevel.NEW_RESPONSE_TO_RESPONSE,
5032:                                    new Boolean(permBean
5033:                                            .getResponseToResponse()));
5034:                            mask.put(PermissionLevel.MOVE_POSTING, new Boolean(
5035:                                    permBean.getMovePosting()));
5036:                            mask.put(PermissionLevel.CHANGE_SETTINGS,
5037:                                    new Boolean(permBean.getChangeSettings()));
5038:                            mask.put(PermissionLevel.POST_TO_GRADEBOOK,
5039:                                    new Boolean(permBean.getPostToGradebook()));
5040:                            mask.put(PermissionLevel.READ, new Boolean(permBean
5041:                                    .getRead()));
5042:                            mask.put(PermissionLevel.MARK_AS_READ, new Boolean(
5043:                                    permBean.getMarkAsRead()));
5044:                            mask
5045:                                    .put(PermissionLevel.MODERATE_POSTINGS,
5046:                                            new Boolean(permBean
5047:                                                    .getModeratePostings()));
5048:                            mask.put(PermissionLevel.DELETE_OWN, new Boolean(
5049:                                    permBean.getDeleteOwn()));
5050:                            mask.put(PermissionLevel.DELETE_ANY, new Boolean(
5051:                                    permBean.getDeleteAny()));
5052:                            mask.put(PermissionLevel.REVISE_OWN, new Boolean(
5053:                                    permBean.getReviseOwn()));
5054:                            mask.put(PermissionLevel.REVISE_ANY, new Boolean(
5055:                                    permBean.getReviseAny()));
5056:
5057:                            PermissionLevel level = permissionLevelManager
5058:                                    .createPermissionLevel(permBean
5059:                                            .getSelectedLevel(), typeManager
5060:                                            .getCustomLevelType(), mask);
5061:                            membershipItem.setPermissionLevel(level);
5062:                        }
5063:
5064:                        // save DBMembershiptItem here to get an id so we can add to the set
5065:                        permissionLevelManager
5066:                                .saveDBMembershipItem(membershipItem);
5067:                        membershipItemSet.add(membershipItem);
5068:                    }
5069:
5070:                    if (((area != null && area.getId() != null)
5071:                            || (forum != null && forum.getId() != null) || (topic != null && topic
5072:                            .getId() != null))
5073:                            && oldMembershipItemSet != null)
5074:                        permissionLevelManager
5075:                                .deleteMembershipItems(oldMembershipItemSet);
5076:
5077:                    if (target instanceof  DiscussionForum) {
5078:                        forum.setMembershipItemSet(membershipItemSet);
5079:                        //forumManager.saveForum(forum);
5080:                    } else if (area != null) {
5081:                        area.setMembershipItemSet(membershipItemSet);
5082:                        //areaManager.saveArea(area);
5083:                    } else if (topic != null) {
5084:                        topic.setMembershipItemSet(membershipItemSet);
5085:                        //forumManager.saveTopic((DiscussionTopic) topic);
5086:                    }
5087:                }
5088:                siteMembers = null;
5089:            }
5090:
5091:            /**
5092:             * processActionAddGroupsUsers
5093:             * @return navigation String
5094:             */
5095:            public String processActionAddGroupsUsers() {
5096:
5097:                totalGroupsUsersList = null;
5098:
5099:                ExternalContext exContext = FacesContext.getCurrentInstance()
5100:                        .getExternalContext();
5101:                HttpSession session = (HttpSession) exContext.getSession(false);
5102:
5103:                String attr = null;
5104:
5105:                if (session != null) {
5106:                    /** get navigation string of previous navigation (set by navigation handler) */
5107:                    attr = (String) session.getAttribute("MC_PREVIOUS_NAV");
5108:                }
5109:
5110:                /** store caller navigation string in session (used to return from add groups/users) */
5111:                session.setAttribute("MC_ADD_GROUPS_USERS_CALLER", attr);
5112:
5113:                return "addGroupsUsers";
5114:            }
5115:
5116:            /**
5117:             * processAddGroupsUsersSubmit
5118:             * @return navigation String
5119:             */
5120:            public String processAddGroupsUsersSubmit() {
5121:
5122:                ExternalContext exContext = FacesContext.getCurrentInstance()
5123:                        .getExternalContext();
5124:                HttpSession session = (HttpSession) exContext.getSession(false);
5125:
5126:                /** get navigation string of previous navigation (set by navigation handler) */
5127:                return (String) session
5128:                        .getAttribute("MC_ADD_GROUPS_USERS_CALLER");
5129:            }
5130:
5131:            /**
5132:             * processAddGroupsUsersCancel
5133:             * @return navigation String
5134:             */
5135:            public String processAddGroupsUsersCancel() {
5136:
5137:                ExternalContext exContext = FacesContext.getCurrentInstance()
5138:                        .getExternalContext();
5139:                HttpSession session = (HttpSession) exContext.getSession(false);
5140:
5141:                /** get navigation string of previous navigation (set by navigation handler) */
5142:                return (String) session
5143:                        .getAttribute("MC_ADD_GROUPS_USERS_CALLER");
5144:            }
5145:
5146:            public List getTotalGroupsUsersList() {
5147:
5148:                /** protect from jsf calling multiple times */
5149:                if (totalGroupsUsersList != null) {
5150:                    return totalGroupsUsersList;
5151:                }
5152:
5153:                courseMemberMap = membershipManager.getAllCourseMembers(true,
5154:                        false, false);
5155:
5156:                List members = membershipManager
5157:                        .convertMemberMapToList(courseMemberMap);
5158:                totalGroupsUsersList = new ArrayList();
5159:
5160:                /** create a list of SelectItem elements */
5161:                for (Iterator i = members.iterator(); i.hasNext();) {
5162:
5163:                    MembershipItem item = (MembershipItem) i.next();
5164:                    totalGroupsUsersList.add(new SelectItem(item.getId(), item
5165:                            .getName()));
5166:                }
5167:
5168:                return totalGroupsUsersList;
5169:            }
5170:
5171:            public void setPermissionLevelManager(
5172:                    PermissionLevelManager permissionLevelManager) {
5173:                this .permissionLevelManager = permissionLevelManager;
5174:            }
5175:
5176:            public List getPostingOptions() {
5177:                List postingOptions = new ArrayList();
5178:                postingOptions.add(new SelectItem(PermissionBean
5179:                        .getResourceBundleString(PermissionBean.NONE),
5180:                        PermissionBean
5181:                                .getResourceBundleString(PermissionBean.NONE)));
5182:                postingOptions.add(new SelectItem(PermissionBean
5183:                        .getResourceBundleString(PermissionBean.OWN),
5184:                        PermissionBean
5185:                                .getResourceBundleString(PermissionBean.OWN)));
5186:                postingOptions.add(new SelectItem(PermissionBean
5187:                        .getResourceBundleString(PermissionBean.ALL),
5188:                        PermissionBean
5189:                                .getResourceBundleString(PermissionBean.ALL)));
5190:                return postingOptions;
5191:            }
5192:
5193:            /**
5194:             * @return Returns the levels.
5195:             */
5196:            public List getLevels() {
5197:                boolean hasCustom = false;
5198:                if (levels == null || levels.size() == 0) {
5199:                    levels = new ArrayList();
5200:                    List origLevels = permissionLevelManager
5201:                            .getOrderedPermissionLevelNames();
5202:                    if (origLevels != null) {
5203:                        Iterator iter = origLevels.iterator();
5204:
5205:                        while (iter.hasNext()) {
5206:                            String level = (String) iter.next();
5207:                            levels.add(new SelectItem(level));
5208:                            if (level.equals("Custom")) {
5209:                                hasCustom = true;
5210:                            }
5211:                        }
5212:                    }
5213:                    if (!hasCustom) {
5214:                        levels.add(new SelectItem("Custom"));
5215:                    }
5216:                }
5217:                return levels;
5218:            }
5219:
5220:            /**
5221:             * @param areaManager The areaManager to set.
5222:             */
5223:            public void setAreaManager(AreaManager areaManager) {
5224:                this .areaManager = areaManager;
5225:            }
5226:
5227:            /**
5228:             * @return Returns the selectedRole.
5229:             */
5230:            public String getSelectedRole() {
5231:                return selectedRole;
5232:            }
5233:
5234:            /**
5235:             * @param selectedRole The selectedRole to set.
5236:             */
5237:            public void setSelectedRole(String selectedRole) {
5238:                this .selectedRole = selectedRole;
5239:            }
5240:
5241:            public boolean getEditMode() {
5242:                return editMode;
5243:            }
5244:
5245:            public void setEditMode(boolean editMode) {
5246:                this .editMode = editMode;
5247:            }
5248:
5249:            public String getPermissionMode() {
5250:                return permissionMode;
5251:            }
5252:
5253:            public void setPermissionMode(String permissionMode) {
5254:                this .permissionMode = permissionMode;
5255:            }
5256:
5257:            public List getSelectedGroupsUsersList() {
5258:                return selectedGroupsUsersList;
5259:            }
5260:
5261:            public void setSelectedGroupsUsersList(List selectedGroupsUsersList) {
5262:                this .selectedGroupsUsersList = selectedGroupsUsersList;
5263:            }
5264:
5265:            public void setTotalGroupsUsersList(List totalGroupsUsersList) {
5266:                this .totalGroupsUsersList = totalGroupsUsersList;
5267:            }
5268:
5269:            /**
5270:             * Pulls messages from bundle
5271:             * 
5272:             * @param key
5273:             * 			Key of message to get
5274:             * 
5275:             * @return
5276:             * 			String for key passed in or [missing: key] if not found
5277:             */
5278:            public static String getResourceBundleString(String key) {
5279:                final ResourceBundle rb = ResourceBundle
5280:                        .getBundle(MESSAGECENTER_BUNDLE);
5281:                return rb.getString(key);
5282:            }
5283:
5284:            public boolean getGradebookExist() {
5285:                try {
5286:                    GradebookService gradebookService = (org.sakaiproject.service.gradebook.shared.GradebookService) ComponentManager
5287:                            .get("org.sakaiproject.service.gradebook.GradebookService");
5288:                    gradebookExist = gradebookService
5289:                            .isGradebookDefined(ToolManager
5290:                                    .getCurrentPlacement().getContext());
5291:                    return gradebookExist;
5292:                } catch (Exception e) {
5293:                    gradebookExist = false;
5294:                    return gradebookExist;
5295:                }
5296:            }
5297:
5298:            public void setGradebookExist(boolean gradebookExist) {
5299:                this .gradebookExist = gradebookExist;
5300:            }
5301:
5302:            public String getUserNameOrEid() {
5303:                try {
5304:                    String currentUserId = getUserId();
5305:                    if (!"false"
5306:                            .equalsIgnoreCase(ServerConfigurationService
5307:                                    .getString("separateIdEid@org.sakaiproject.user.api.UserDirectoryService"))) {
5308:                        String userString = "";
5309:                        String userLastName = UserDirectoryService.getUser(
5310:                                currentUserId).getLastName();
5311:                        String userFirstName = UserDirectoryService.getUser(
5312:                                currentUserId).getFirstName();
5313:                        if ((userLastName != null && userLastName.length() > 0)
5314:                                || (userFirstName != null && userFirstName
5315:                                        .length() > 0)) {
5316:                            userString += userLastName + ", ";
5317:                            userString += userFirstName;
5318:                            return userString;
5319:                        } else {
5320:                            return UserDirectoryService
5321:                                    .getUserEid(currentUserId);
5322:                        }
5323:                    } else {
5324:                        String userString = "";
5325:                        String userLastName = UserDirectoryService.getUser(
5326:                                currentUserId).getLastName();
5327:                        String userFirstName = UserDirectoryService.getUser(
5328:                                currentUserId).getFirstName();
5329:                        if ((userLastName != null && userLastName.length() > 0)
5330:                                || (userFirstName != null && userFirstName
5331:                                        .length() > 0)) {
5332:                            userString += userLastName + ", ";
5333:                            userString += userFirstName;
5334:                            return userString;
5335:                        } else {
5336:                            return UserDirectoryService
5337:                                    .getUserEid(currentUserId);
5338:                        }
5339:                    }
5340:                } catch (Exception e) {
5341:                    e.printStackTrace();
5342:                }
5343:
5344:                return getUserId();
5345:            }
5346:
5347:            public boolean isDisableLongDesc() {
5348:                return disableLongDesc;
5349:            }
5350:
5351:            /**
5352:             * Determines current level (template, forum, or topic) and
5353:             * returns boolean indicating whether moderating is enabled or not.
5354:             * @return
5355:             */
5356:            public boolean isDisableModeratePerm() {
5357:                if (permissionMode == null)
5358:                    return true;
5359:                else if (permissionMode.equals(PERMISSION_MODE_TEMPLATE)
5360:                        && template != null)
5361:                    return !template.isAreaModerated();
5362:                else if (permissionMode.equals(PERMISSION_MODE_FORUM)
5363:                        && selectedForum != null)
5364:                    return !selectedForum.isForumModerated();
5365:                else if (permissionMode.equals(PERMISSION_MODE_TOPIC)
5366:                        && selectedTopic != null)
5367:                    return !selectedTopic.isTopicModerated();
5368:                else
5369:                    return true;
5370:            }
5371:
5372:            public List getMessages() {
5373:                List messages = new ArrayList();
5374:
5375:                //if(displayUnreadOnly) 
5376:                //	messages = selectedTopic.getUnreadMessages();	
5377:                //else
5378:
5379:                messages = selectedTopic.getMessages();
5380:
5381:                if (messages != null && !messages.isEmpty())
5382:                    messages = filterModeratedMessages(messages, selectedTopic
5383:                            .getTopic(), selectedForum.getForum());
5384:
5385:                return messages;
5386:            }
5387:
5388:            /**
5389:             * Given a list of messages, will return all messages that meet at
5390:             * least one of the following criteria:
5391:             * 1) message is approved
5392:             * 2) message was written by current user
5393:             * 3) current user has moderator perm
5394:             */
5395:            private List filterModeratedMessages(List messages,
5396:                    DiscussionTopic topic, DiscussionForum forum) {
5397:                List viewableMsgs = new ArrayList();
5398:                if (messages != null || messages.size() > 0) {
5399:                    boolean hasModeratePerm = uiPermissionsManager
5400:                            .isModeratePostings(topic, forum);
5401:
5402:                    if (hasModeratePerm)
5403:                        return messages;
5404:
5405:                    Iterator msgIter = messages.iterator();
5406:                    while (msgIter.hasNext()) {
5407:                        DiscussionMessageBean msg = (DiscussionMessageBean) msgIter
5408:                                .next();
5409:                        if (msg.isMsgApproved() || msg.getIsOwn())
5410:                            viewableMsgs.add(msg);
5411:                    }
5412:                }
5413:
5414:                return viewableMsgs;
5415:            }
5416:
5417:            public String getModeratorComments() {
5418:                return moderatorComments;
5419:            }
5420:
5421:            public void setModeratorComments(String moderatorComments) {
5422:                this .moderatorComments = moderatorComments;
5423:            }
5424:
5425:            public UIData getForumTable() {
5426:                return forumTable;
5427:            }
5428:
5429:            public void setForumTable(UIData forumTable) {
5430:                this .forumTable = forumTable;
5431:            }
5432:
5433:            public String processReturnToOriginatingPage() {
5434:                LOG.debug("processReturnToOriginatingPage()");
5435:                if (fromPage != null) {
5436:                    String returnToPage = fromPage;
5437:                    fromPage = "";
5438:                    if (returnToPage.equals(ALL_MESSAGES)
5439:                            && selectedTopic != null) {
5440:                        selectedTopic = getDecoratedTopic(selectedTopic
5441:                                .getTopic());
5442:                        return ALL_MESSAGES;
5443:                    }
5444:                    if (returnToPage.equals(FORUM_DETAILS)
5445:                            && selectedForum != null) {
5446:                        selectedForum = getDecoratedForum(selectedForum
5447:                                .getForum());
5448:                        return FORUM_DETAILS;
5449:                    }
5450:                }
5451:
5452:                return processActionHome();
5453:            }
5454:
5455:            private void setFromMainOrForumOrTopic() {
5456:                String originatingPage = getExternalParameterByKey(FROM_PAGE);
5457:                if (originatingPage != null
5458:                        && (originatingPage.equals(MAIN)
5459:                                || originatingPage.equals(ALL_MESSAGES)
5460:                                || originatingPage.equals(FORUM_DETAILS)
5461:                                || originatingPage.equals(THREAD_VIEW) || originatingPage
5462:                                .equals(FLAT_VIEW))) {
5463:                    fromPage = originatingPage;
5464:                }
5465:            }
5466:
5467:            /**
5468:             * @return TRUE if within Messages & Forums tool, FALSE otherwise
5469:             */
5470:            public boolean isMessagesandForums() {
5471:                return messageManager.currentToolMatch(MESSAGECENTER_TOOL_ID);
5472:            }
5473:
5474:            /**
5475:             * @return TRUE if within Forums tool, FALSE otherwise
5476:             */
5477:            public boolean isForumsTool() {
5478:                return messageManager.currentToolMatch(FORUMS_TOOL_ID);
5479:            }
5480:
5481:            private String gotoMain() {
5482:                if (isForumsTool()) {
5483:                    return FORUMS_MAIN;
5484:                } else {
5485:                    return MAIN;
5486:                }
5487:            }
5488:
5489:            /**
5490:             * @return TRUE if Messages & Forums (Message Center) exists in this site,
5491:             *         FALSE otherwise
5492:             */
5493:            private boolean isMessageForumsPageInSite(String siteId) {
5494:                return messageManager.isToolInSite(siteId,
5495:                        MESSAGECENTER_TOOL_ID);
5496:            }
5497:
5498:            /**
5499:             * @return TRUE if Messages & Forums (Message Center) exists in this site,
5500:             *         FALSE otherwise
5501:             */
5502:            private boolean isForumsPageInSite(String siteId) {
5503:                return messageManager.isToolInSite(siteId, FORUMS_TOOL_ID);
5504:            }
5505:
5506:            public String getPrintFriendlyUrl() {
5507:                return ServerConfigurationService.getToolUrl()
5508:                        + Entity.SEPARATOR
5509:                        + ToolManager.getCurrentPlacement().getId()
5510:                        + Entity.SEPARATOR + "discussionForum"
5511:                        + Entity.SEPARATOR + "message" + Entity.SEPARATOR
5512:                        + "printFriendly";
5513:            }
5514:
5515:            public String getPrintFriendlyUrlThread() {
5516:                return ServerConfigurationService.getToolUrl()
5517:                        + Entity.SEPARATOR
5518:                        + ToolManager.getCurrentPlacement().getId()
5519:                        + Entity.SEPARATOR + "discussionForum"
5520:                        + Entity.SEPARATOR + "message" + Entity.SEPARATOR
5521:                        + "printFriendlyThread";
5522:            }
5523:
5524:            public Boolean isMessageReadForUser(Long topicId, Long messageId) {
5525:                return messageManager.isMessageReadForUser(topicId, messageId);
5526:            }
5527:
5528:            public void markMessageReadForUser(Long topicId, Long messageId,
5529:                    Boolean read) {
5530:                messageManager.markMessageReadForUser(topicId, messageId, read);
5531:                if (selectedThreadHead != null) {
5532:                    //reset the thread to show unread
5533:                    processActionGetDisplayThread();
5534:                }
5535:                //also go ahead and reset the the topic
5536:                DiscussionTopic topic = forumManager.getTopicById(new Long(
5537:                        topicId));
5538:                setSelectedForumForCurrentTopic(topic);
5539:                selectedTopic = getDecoratedTopic(topic);
5540:                setTopicBeanAssign();
5541:                getSelectedTopic();
5542:            }
5543:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.