0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/ui/DiscussionForumManagerImpl.java $
0003: * $Id: DiscussionForumManagerImpl.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.component.app.messageforums.ui;
0021:
0022: import java.util.ArrayList;
0023: import java.util.Collection;
0024: import java.util.Collections;
0025: import java.util.Iterator;
0026: import java.util.List;
0027: import java.util.Map;
0028: import java.util.Set;
0029: import java.util.Vector;
0030:
0031: import org.apache.commons.logging.Log;
0032: import org.apache.commons.logging.LogFactory;
0033: import org.sakaiproject.api.app.messageforums.ActorPermissions;
0034: import org.sakaiproject.api.app.messageforums.Area;
0035: import org.sakaiproject.api.app.messageforums.AreaControlPermission;
0036: import org.sakaiproject.api.app.messageforums.AreaManager;
0037: import org.sakaiproject.api.app.messageforums.Attachment;
0038: import org.sakaiproject.api.app.messageforums.DBMembershipItem;
0039: import org.sakaiproject.api.app.messageforums.DiscussionForum;
0040: import org.sakaiproject.api.app.messageforums.DiscussionTopic;
0041: import org.sakaiproject.api.app.messageforums.DummyDataHelperApi;
0042: import org.sakaiproject.api.app.messageforums.ForumControlPermission;
0043: import org.sakaiproject.api.app.messageforums.MembershipManager;
0044: import org.sakaiproject.api.app.messageforums.Message;
0045: import org.sakaiproject.api.app.messageforums.MessageForumsForumManager;
0046: import org.sakaiproject.api.app.messageforums.MessageForumsMessageManager;
0047: import org.sakaiproject.api.app.messageforums.MessageForumsTypeManager;
0048: import org.sakaiproject.api.app.messageforums.MessageForumsUser;
0049: import org.sakaiproject.api.app.messageforums.MessagePermissions;
0050: import org.sakaiproject.api.app.messageforums.PermissionLevel;
0051: import org.sakaiproject.api.app.messageforums.PermissionLevelManager;
0052: import org.sakaiproject.api.app.messageforums.PermissionManager;
0053: import org.sakaiproject.api.app.messageforums.Topic;
0054: import org.sakaiproject.api.app.messageforums.TopicControlPermission;
0055: import org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager;
0056: import org.sakaiproject.authz.api.AuthzGroup;
0057: import org.sakaiproject.authz.api.GroupNotDefinedException;
0058: import org.sakaiproject.authz.api.Role;
0059: import org.sakaiproject.authz.api.SecurityService;
0060: import org.sakaiproject.authz.cover.AuthzGroupService;
0061: import org.sakaiproject.component.app.messageforums.MembershipItem;
0062: import org.sakaiproject.component.app.messageforums.dao.hibernate.ActorPermissionsImpl;
0063: import org.sakaiproject.component.app.messageforums.dao.hibernate.DBMembershipItemImpl;
0064: import org.sakaiproject.component.app.messageforums.dao.hibernate.MessageForumsUserImpl;
0065: import org.sakaiproject.component.cover.ServerConfigurationService;
0066: import org.sakaiproject.content.api.ContentResource;
0067: import org.sakaiproject.content.cover.ContentHostingService;
0068: import org.sakaiproject.site.api.SiteService;
0069: import org.sakaiproject.tool.api.SessionManager;
0070: import org.sakaiproject.tool.cover.ToolManager;
0071: import org.sakaiproject.user.api.User;
0072: import org.sakaiproject.user.api.UserDirectoryService;
0073: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
0074:
0075: /**
0076: * @author <a href="mailto:rshastri@iupui.edu">Rashmi Shastri</a>
0077: */
0078: public class DiscussionForumManagerImpl extends HibernateDaoSupport
0079: implements DiscussionForumManager {
0080: private static final String MC_DEFAULT = "mc.default.";
0081: private static final Log LOG = LogFactory
0082: .getLog(DiscussionForumManagerImpl.class);
0083: private AreaManager areaManager;
0084: private MessageForumsForumManager forumManager;
0085: private MessageForumsMessageManager messageManager;
0086: private DummyDataHelperApi helper;
0087: private PermissionManager permissionManager;
0088: private MessageForumsTypeManager typeManager;
0089: private SiteService siteService;
0090: private UserDirectoryService userDirectoryService;
0091: private MembershipManager membershipManager;
0092: private SecurityService securityService;
0093: private SessionManager sessionManager;
0094: private PermissionLevelManager permissionLevelManager;
0095: private Map courseMemberMap = null;
0096: private boolean usingHelper = false; // just a flag until moved to database from helper
0097:
0098: public void init() {
0099: LOG.info("init()");
0100: ;
0101: }
0102:
0103: public List searchTopicMessages(Long topicId, String searchText) {
0104: return forumManager.searchTopicMessages(topicId, searchText);
0105: }
0106:
0107: public Topic getTopicByIdWithAttachments(Long topicId) {
0108: if (LOG.isDebugEnabled()) {
0109: LOG.debug("getTopicByIdWithAttachments(Long " + topicId
0110: + ")");
0111: }
0112: return forumManager.getTopicByIdWithAttachments(topicId);
0113: }
0114:
0115: public List getTopicsByIdWithMessages(final Long forumId) {
0116: if (LOG.isDebugEnabled()) {
0117: LOG.debug("getTopicsByIdWithMessages(final Long" + forumId
0118: + ")");
0119: }
0120: return forumManager.getTopicsByIdWithMessages(forumId);
0121: }
0122:
0123: public List getTopicsByIdWithMessagesAndAttachments(
0124: final Long forumId) {
0125: if (LOG.isDebugEnabled()) {
0126: LOG
0127: .debug("getTopicsByIdWithMessagesAndAttachments(final Long"
0128: + forumId + ")");
0129: }
0130: return forumManager
0131: .getTopicsByIdWithMessagesAndAttachments(forumId);
0132: }
0133:
0134: public List getTopicsByIdWithMessagesMembershipAndAttachments(
0135: final Long forumId) {
0136: if (LOG.isDebugEnabled()) {
0137: LOG
0138: .debug("getTopicsByIdWithMessagesMembershipAndAttachments(final Long"
0139: + forumId + ")");
0140: }
0141: return forumManager
0142: .getTopicsByIdWithMessagesMembershipAndAttachments(forumId);
0143: }
0144:
0145: public Topic getTopicByIdWithMessages(final Long topicId) {
0146: if (LOG.isDebugEnabled()) {
0147: LOG.debug("getTopicByIdWithMessages(final Long" + topicId
0148: + ")");
0149: }
0150: return forumManager.getTopicByIdWithMessages(topicId);
0151: }
0152:
0153: public Topic getTopicByIdWithMessagesAndAttachments(
0154: final Long topicId) {
0155: if (LOG.isDebugEnabled()) {
0156: LOG
0157: .debug("getTopicByIdWithMessagesAndAttachments(final Long"
0158: + topicId + ")");
0159: }
0160: return forumManager
0161: .getTopicByIdWithMessagesAndAttachments(topicId);
0162: }
0163:
0164: public List getModeratedTopicsInSite() {
0165: if (LOG.isDebugEnabled()) {
0166: LOG.debug("getModeratedTopicsInSite()");
0167: }
0168: return forumManager.getModeratedTopicsInSite(ToolManager
0169: .getCurrentPlacement().getContext());
0170: }
0171:
0172: // start injection
0173: /**
0174: * @param helper
0175: */
0176: public void setHelper(DummyDataHelperApi helper) {
0177: if (LOG.isDebugEnabled()) {
0178: LOG.debug("setHelper(DummyDataHelperApi " + helper + ")");
0179: }
0180: this .helper = helper;
0181: }
0182:
0183: /**
0184: * @param areaManager
0185: */
0186: public void setAreaManager(AreaManager areaManager) {
0187: if (LOG.isDebugEnabled()) {
0188: LOG.debug("setAreaManager(AreaManager" + areaManager + ")");
0189: }
0190: this .areaManager = areaManager;
0191: }
0192:
0193: /**
0194: * @param permissionManager
0195: * The permissionManager to set.
0196: */
0197: public void setPermissionManager(PermissionManager permissionManager) {
0198: if (LOG.isDebugEnabled()) {
0199: LOG.debug("setPermissionManager(PermissionManager"
0200: + permissionManager + ")");
0201: }
0202: this .permissionManager = permissionManager;
0203: }
0204:
0205: /**
0206: * @param permissionLevelManager
0207: * The permissionLevelManager to set.
0208: */
0209: public void setPermissionLevelManager(
0210: PermissionLevelManager permissionLevelManager) {
0211: this .permissionLevelManager = permissionLevelManager;
0212: }
0213:
0214: /**
0215: * @param typeManager
0216: * The typeManager to set.
0217: */
0218: public void setTypeManager(MessageForumsTypeManager typeManager) {
0219: if (LOG.isDebugEnabled()) {
0220: LOG.debug("setTypeManager(MessageForumsTypeManager"
0221: + typeManager + ")");
0222: }
0223: this .typeManager = typeManager;
0224: }
0225:
0226: /**
0227: * @param siteService
0228: * The siteService to set.
0229: */
0230: public void setSiteService(SiteService siteService) {
0231: this .siteService = siteService;
0232: }
0233:
0234: /**
0235: * @param sessionManager
0236: * The sessionManager to set.
0237: */
0238: public void setSessionManager(SessionManager sessionManager) {
0239: this .sessionManager = sessionManager;
0240: }
0241:
0242: /**
0243: * @param securityService
0244: * The securityService to set.
0245: */
0246: public void setSecurityService(SecurityService securityService) {
0247: this .securityService = securityService;
0248: }
0249:
0250: /**
0251: * @param userDirectoryService
0252: * The userDirectoryService to set.
0253: */
0254: public void setUserDirectoryService(
0255: UserDirectoryService userDirectoryService) {
0256: this .userDirectoryService = userDirectoryService;
0257: }
0258:
0259: /**
0260: * @param membershipManager
0261: * The membershipManager to set.
0262: */
0263: public void setMembershipManager(MembershipManager membershipManager) {
0264: this .membershipManager = membershipManager;
0265: }
0266:
0267: /**
0268: * @return
0269: */
0270: public MessageForumsMessageManager getMessageManager() {
0271:
0272: LOG.debug("getMessageManager()");
0273:
0274: return messageManager;
0275: }
0276:
0277: /**
0278: * @param messageManager
0279: */
0280: public void setMessageManager(
0281: MessageForumsMessageManager messageManager) {
0282: if (LOG.isDebugEnabled()) {
0283: LOG.debug("setMessageManager(MessageForumsMessageManager"
0284: + messageManager + ")");
0285: }
0286: this .messageManager = messageManager;
0287: }
0288:
0289: // end injection
0290:
0291: /*
0292: * (non-Javadoc)
0293: *
0294: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getDiscussionForumArea()
0295: */
0296: public Area getDiscussionForumArea() {
0297: LOG.debug("getDiscussionForumArea");
0298:
0299: if (usingHelper) {
0300: return helper.getDiscussionForumArea();
0301: }
0302: return areaManager.getDiscusionArea();
0303: }
0304:
0305: /*
0306: * (non-Javadoc)
0307: *
0308: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getMessageById(java.lang.Long)
0309: */
0310: public Message getMessageById(Long id) {
0311: if (LOG.isDebugEnabled()) {
0312: LOG.debug("getMessageById( Long" + id + ")");
0313: }
0314: if (usingHelper) {
0315: return helper.getMessageById(id);
0316: }
0317: return messageManager.getMessageById(id);
0318: }
0319:
0320: /*
0321: * (non-Javadoc)
0322: *
0323: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveMessage(org.sakaiproject.api.app.messageforums.Message)
0324: */
0325: public void saveMessage(Message message) {
0326: if (LOG.isDebugEnabled()) {
0327: LOG.debug("saveMessage(Message " + message + ")");
0328: }
0329: if (message.getTopic().getBaseForum() == null) {
0330: message.setTopic(getTopicById(message.getTopic().getId()));
0331: }
0332: messageManager.saveMessage(message);
0333: }
0334:
0335: /*
0336: * (non-Javadoc)
0337: *
0338: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#deleteMessage(org.sakaiproject.api.app.messageforums.Message)
0339: */
0340: public void deleteMessage(Message message) {
0341: if (LOG.isDebugEnabled()) {
0342: LOG.debug("deleteMessage(Message" + message + ")");
0343: }
0344: messageManager.deleteMessage(message);
0345: }
0346:
0347: /*
0348: * (non-Javadoc)
0349: *
0350: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getTotalNoMessages(org.sakaiproject.api.app.messageforums.Topic)
0351: */
0352: public int getTotalNoMessages(Topic topic) {
0353: if (LOG.isDebugEnabled()) {
0354: LOG.debug("getTotalNoMessages(Topic" + topic + ")");
0355: }
0356: if (usingHelper) {
0357: return 20;
0358: }
0359: return messageManager.findMessageCountByTopicId(topic.getId());
0360: }
0361:
0362: /*
0363: * (non-Javadoc)
0364: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getTotalViewableMessagesWhenMod(org.sakaiproject.api.app.messageforums.Topic)
0365: */
0366: public int getTotalViewableMessagesWhenMod(Topic topic) {
0367: if (LOG.isDebugEnabled()) {
0368: LOG.debug("getTotalViewableMessagesWhenMod(Topic" + topic
0369: + ")");
0370: }
0371: if (usingHelper) {
0372: return 20;
0373: }
0374: return messageManager.findViewableMessageCountByTopicId(topic
0375: .getId());
0376: }
0377:
0378: /*
0379: * (non-Javadoc)
0380: *
0381: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getUnreadNoMessages(org.sakaiproject.api.app.messageforums.Topic)
0382: */
0383: public int getUnreadNoMessages(Topic topic) {
0384: if (LOG.isDebugEnabled()) {
0385: LOG.debug("getUnreadNoMessages(Topic" + topic + ")");
0386: }
0387: if (usingHelper) {
0388: return 10;
0389: }
0390: return messageManager.findUnreadMessageCountByTopicId(topic
0391: .getId());
0392: }
0393:
0394: /*
0395: * (non-Javadoc)
0396: *
0397: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getUnreadApprovedNoMessages(org.sakaiproject.api.app.messageforums.Topic)
0398: */
0399: public int getNumUnreadViewableMessagesWhenMod(Topic topic) {
0400: if (LOG.isDebugEnabled()) {
0401: LOG.debug("getNumUnreadViewableMessagesWhenMod(Topic"
0402: + topic + ")");
0403: }
0404: if (usingHelper) {
0405: return 10;
0406: }
0407: return messageManager
0408: .findUnreadViewableMessageCountByTopicId(topic.getId());
0409: }
0410:
0411: /*
0412: * (non-Javadoc)
0413: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#approveAllPendingMessages(java.lang.Long)
0414: */
0415: public void approveAllPendingMessages(Long topicId) {
0416: if (topicId == null) {
0417: LOG.error("approveAllPendingMessages failed with topicId: "
0418: + topicId);
0419: throw new IllegalArgumentException("Null Argument");
0420: }
0421: List messages = this .getMessagesByTopicId(topicId);
0422: if (messages != null && messages.size() > 0) {
0423: Iterator msgIter = messages.iterator();
0424: while (msgIter.hasNext()) {
0425: Message msg = (Message) msgIter.next();
0426: if (msg.getApproved() == null) {
0427: msg.setApproved(Boolean.TRUE);
0428: }
0429: }
0430: }
0431: }
0432:
0433: /*
0434: * (non-Javadoc)
0435: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getTotalNoPendingMessages()
0436: */
0437: public List getPendingMsgsInSiteByMembership(List membershipList) {
0438: return messageManager
0439: .getPendingMsgsInSiteByMembership(membershipList);
0440: }
0441:
0442: /*
0443: * (non-Javadoc)
0444: *
0445: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getDiscussionForums()
0446: */
0447: public List getDiscussionForums() {
0448: LOG.debug("getDiscussionForums()");
0449: if (usingHelper) {
0450: return helper.getDiscussionForumArea()
0451: .getDiscussionForums();
0452: }
0453: return forumManager.getForumByTypeAndContext(typeManager
0454: .getDiscussionForumType());
0455: // return getDiscussionForumArea().getDiscussionForums();
0456: }
0457:
0458: /*
0459: * (non-Javadoc)
0460: *
0461: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getDiscussionForumsByContextId()
0462: */
0463: public List getDiscussionForumsByContextId(String contextId) {
0464: LOG.debug("getDiscussionForumsByContextId(String contextId)");
0465:
0466: return forumManager.getForumByTypeAndContext(typeManager
0467: .getDiscussionForumType(), contextId);
0468: }
0469:
0470: /*
0471: * (non-Javadoc)
0472: *
0473: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getForumById(java.lang.Long)
0474: */
0475: public DiscussionForum getForumById(Long forumId) {
0476: if (LOG.isDebugEnabled()) {
0477: LOG.debug("getForumById(Long" + forumId + ")");
0478: }
0479: if (usingHelper) {
0480: return helper.getForumById(forumId);
0481: }
0482: return (DiscussionForum) forumManager.getForumById(true,
0483: forumId);
0484: }
0485:
0486: public DiscussionForum getForumByUuid(String forumId) {
0487: if (LOG.isDebugEnabled()) {
0488: LOG.debug("getForumByUuid(String" + forumId + ")");
0489: }
0490: return (DiscussionForum) forumManager.getForumByUuid(forumId);
0491: }
0492:
0493: /*
0494: * (non-Javadoc)
0495: *
0496: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getMessagesByTopicId(java.lang.Long)
0497: */
0498: public List getMessagesByTopicId(Long topicId) {
0499: if (LOG.isDebugEnabled()) {
0500: LOG.debug("getMessagesByTopicId(Long" + topicId + ")");
0501: }
0502: return messageManager.findMessagesByTopicId(topicId);
0503: }
0504:
0505: /*
0506: * (non-Javadoc)
0507: *
0508: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getTopicById(java.lang.Long)
0509: */
0510: public DiscussionTopic getTopicById(Long topicId) {
0511: if (LOG.isDebugEnabled()) {
0512: LOG.debug("getTopicById(Long" + topicId + ")");
0513: }
0514:
0515: return (DiscussionTopic) forumManager.getTopicById(true,
0516: topicId);
0517: }
0518:
0519: public DiscussionForum getForumByIdWithTopics(Long forumId) {
0520: if (LOG.isDebugEnabled()) {
0521: LOG.debug("getForumByIdWithTopics(Long" + forumId + ")");
0522: }
0523: return (DiscussionForum) forumManager
0524: .getForumByIdWithTopics(forumId);
0525: }
0526:
0527: public DiscussionTopic getTopicByUuid(String topicId) {
0528: if (LOG.isDebugEnabled()) {
0529: LOG.debug(" getTopicByUuid(String" + topicId + ")");
0530: }
0531: return (DiscussionTopic) forumManager.getTopicByUuid(topicId);
0532: }
0533:
0534: /*
0535: * (non-Javadoc)
0536: *
0537: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#hasNextTopic(org.sakaiproject.api.app.messageforums.DiscussionTopic)
0538: */
0539: public boolean hasNextTopic(DiscussionTopic topic) {
0540: if (LOG.isDebugEnabled()) {
0541: LOG.debug("hasNextTopic(DiscussionTopic" + topic + ")");
0542: }
0543: if (usingHelper) {
0544: return helper.hasNextTopic(topic);
0545: }
0546:
0547: // TODO: Needs optimized
0548: boolean next = false;
0549: DiscussionForum forum = getForumById(topic.getBaseForum()
0550: .getId());
0551: if (forum != null && forum.getTopics() != null) {
0552: for (Iterator iter = forum.getTopics().iterator(); iter
0553: .hasNext();) {
0554: DiscussionTopic t = (DiscussionTopic) iter.next();
0555: if (next && getTopicAccess(t)) {
0556: return true;
0557: }
0558: if (t != null && getTopicAccess(t)) {
0559: if (t.getId().equals(topic.getId())) {
0560: next = true;
0561: }
0562: }
0563: }
0564: }
0565:
0566: // if we get here, there is no next topic
0567: return false;
0568: }
0569:
0570: /*
0571: * (non-Javadoc)
0572: *
0573: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#hasPreviousTopic(org.sakaiproject.api.app.messageforums.DiscussionTopic)
0574: */
0575: public boolean hasPreviousTopic(DiscussionTopic topic) {
0576: if (LOG.isDebugEnabled()) {
0577: LOG.debug("hasPreviousTopic(DiscussionTopic" + topic + ")");
0578: }
0579: if (usingHelper) {
0580: return helper.hasPreviousTopic(topic);
0581: }
0582:
0583: // TODO: Needs optimized
0584: DiscussionTopic prev = null;
0585: DiscussionForum forum = getForumById(topic.getBaseForum()
0586: .getId());
0587: if (forum != null && forum.getTopics() != null) {
0588: for (Iterator iter = forum.getTopics().iterator(); iter
0589: .hasNext();) {
0590: DiscussionTopic t = (DiscussionTopic) iter.next();
0591: if (t != null && getTopicAccess(t)) {
0592: if (t.getId().equals(topic.getId())) {
0593: // need to check null because we might be on the first topic
0594: // which means there is no previous one
0595: return prev != null;
0596: }
0597: prev = (DiscussionTopic) t;
0598: }
0599: }
0600: }
0601:
0602: // if we get here, there is no previous topic
0603: return false;
0604: }
0605:
0606: /*
0607: * (non-Javadoc)
0608: *
0609: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getNextTopic(org.sakaiproject.api.app.messageforums.DiscussionTopic)
0610: */
0611: public DiscussionTopic getNextTopic(DiscussionTopic topic) {
0612: if (LOG.isDebugEnabled()) {
0613: LOG.debug("getNextTopic(DiscussionTopic" + topic + ")");
0614: }
0615: if (usingHelper) {
0616: if (hasNextTopic(topic)) {
0617: return helper.getNextTopic(topic);
0618: } else {
0619: return null;
0620: }
0621: }
0622:
0623: // TODO: Needs optimized and re-written to take advantage of the db... this is really horrible.
0624: boolean next = false;
0625: DiscussionForum forum = getForumById(topic.getBaseForum()
0626: .getId());
0627: if (forum != null && forum.getTopics() != null) {
0628: for (Iterator iter = forum.getTopics().iterator(); iter
0629: .hasNext();) {
0630: DiscussionTopic t = (DiscussionTopic) iter.next();
0631: if (next && getTopicAccess(t)) {
0632: if (t == null) {
0633: do {
0634: t = (DiscussionTopic) iter.next();
0635: } while (t == null);
0636: }
0637: return (DiscussionTopic) t;
0638: }
0639: if (t != null && getTopicAccess(t)) {
0640: if (t.getId().equals(topic.getId())) {
0641: next = true;
0642: }
0643: }
0644: }
0645: }
0646:
0647: // if we get here, there is no next topic
0648: return null;
0649: }
0650:
0651: /*
0652: * (non-Javadoc)
0653: *
0654: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getPreviousTopic(org.sakaiproject.api.app.messageforums.DiscussionTopic)
0655: */
0656: public DiscussionTopic getPreviousTopic(DiscussionTopic topic) {
0657: if (LOG.isDebugEnabled()) {
0658: LOG.debug("getPreviousTopic(DiscussionTopic" + topic + ")");
0659: }
0660: if (usingHelper) {
0661: if (hasPreviousTopic(topic)) {
0662: return helper.getPreviousTopic(topic);
0663: } else {
0664: return null;
0665: }
0666: }
0667: // TODO: Needs optimized
0668: DiscussionTopic prev = null;
0669: DiscussionForum forum = getForumById(topic.getBaseForum()
0670: .getId());
0671: if (forum != null && forum.getTopics() != null) {
0672: for (Iterator iter = forum.getTopics().iterator(); iter
0673: .hasNext();) {
0674: DiscussionTopic t = (DiscussionTopic) iter.next();
0675: if (t != null && getTopicAccess(t)) {
0676: if (t.getId().equals(topic.getId())) {
0677: return prev;
0678: }
0679: if (t != null && getTopicAccess(t)) {
0680: prev = (DiscussionTopic) t;
0681: }
0682: }
0683: }
0684: }
0685:
0686: // if we get here, there is no previous topic
0687: return null;
0688: }
0689:
0690: /*
0691: * (non-Javadoc)
0692: *
0693: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#isInstructor()
0694: */
0695: public boolean isInstructor() {
0696: LOG.debug("isInstructor()");
0697: return isInstructor(userDirectoryService.getCurrentUser());
0698: }
0699:
0700: /**
0701: * Check if the given user has site.upd access
0702: *
0703: * @param user
0704: * @return
0705: */
0706: private boolean isInstructor(User user) {
0707: if (LOG.isDebugEnabled()) {
0708: LOG.debug("isInstructor(User " + user + ")");
0709: }
0710: if (user != null)
0711: return securityService.unlock(user, "site.upd",
0712: getContextSiteId());
0713: else
0714: return false;
0715: }
0716:
0717: /**
0718: * @return siteId
0719: */
0720: private String getContextSiteId() {
0721: LOG.debug("getContextSiteId()");
0722: return ("/site/" + ToolManager.getCurrentPlacement()
0723: .getContext());
0724: }
0725:
0726: /**
0727: * @param forumManager
0728: */
0729: public void setForumManager(MessageForumsForumManager forumManager) {
0730: if (LOG.isDebugEnabled()) {
0731: LOG.debug("setForumManager(MessageForumsForumManager"
0732: + forumManager + ")");
0733: }
0734: this .forumManager = forumManager;
0735: }
0736:
0737: /*
0738: * (non-Javadoc)
0739: *
0740: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#createForum()
0741: */
0742: public DiscussionForum createForum() {
0743: LOG.debug("createForum()");
0744: return forumManager.createDiscussionForum();
0745: }
0746:
0747: /*
0748: * (non-Javadoc)
0749: *
0750: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#deleteForum(org.sakaiproject.api.app.messageforums.DiscussionForum)
0751: */
0752: public void deleteForum(DiscussionForum forum) {
0753: if (LOG.isDebugEnabled()) {
0754: LOG.debug("setForumManager(DiscussionForum" + forum + ")");
0755: }
0756: forumManager.deleteDiscussionForum(forum);
0757: }
0758:
0759: /*
0760: * (non-Javadoc)
0761: *
0762: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#createTopic(org.sakaiproject.api.app.messageforums.DiscussionForum)
0763: */
0764: public DiscussionTopic createTopic(DiscussionForum forum) {
0765: if (LOG.isDebugEnabled()) {
0766: LOG.debug("createTopic(DiscussionForum" + forum + ")");
0767: }
0768: if (forum == null) {
0769: LOG.debug("Attempt to create topic with out forum");
0770: return null;
0771: }
0772: return forumManager.createDiscussionForumTopic(forum);
0773: }
0774:
0775: /*
0776: * (non-Javadoc)
0777: *
0778: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveForum(org.sakaiproject.api.app.messageforums.DiscussionForum)
0779: */
0780: public void saveForum(DiscussionForum forum) {
0781: if (LOG.isDebugEnabled()) {
0782: LOG.debug("saveForum(DiscussionForum" + forum + ")");
0783: }
0784: saveForum(forum, false);
0785: }
0786:
0787: /*
0788: * (non-Javadoc)
0789: *
0790: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveForumAsDraft(org.sakaiproject.api.app.messageforums.DiscussionForum)
0791: */
0792: public void saveForumAsDraft(DiscussionForum forum) {
0793: if (LOG.isDebugEnabled()) {
0794: LOG.debug("saveForumAsDraft(DiscussionForum" + forum + ")");
0795: }
0796: saveForum(forum, true);
0797: }
0798:
0799: private void saveForum(DiscussionForum forum, boolean draft) {
0800: if (LOG.isDebugEnabled()) {
0801: LOG.debug("saveForum(DiscussionForum" + forum + "boolean "
0802: + draft + ")");
0803: }
0804:
0805: boolean saveArea = forum.getId() == null;
0806: forum.setDraft(new Boolean(draft));
0807: // ActorPermissions originalForumActorPermissions = null;
0808: // if (saveArea)
0809: // {
0810: // originalForumActorPermissions = new ActorPermissionsImpl();
0811: // }
0812: // else
0813: // {
0814: // originalForumActorPermissions = forum.getActorPermissions();
0815: // }
0816: // // setcontributors
0817: // List holdContributors = new ArrayList();
0818: // holdContributors = Arrays.asList(forum.getActorPermissions()
0819: // .getContributors().toArray());
0820: // originalForumActorPermissions.setContributors(new UniqueArrayList());// clearing list at this
0821: // // point.
0822: // if (holdContributors != null && holdContributors.size() > 0)
0823: // {
0824: // Iterator iter = holdContributors.iterator();
0825: // while (iter.hasNext())
0826: // {
0827: // MessageForumsUser user = (MessageForumsUser) iter.next();
0828: // forum.getActorPermissions().addContributor(user);
0829: // }
0830: // }
0831: // // setAccessors
0832: // List holdAccessors = new ArrayList();
0833: // holdAccessors = Arrays.asList(forum.getActorPermissions().getAccessors()
0834: // .toArray());
0835: // originalForumActorPermissions.setAccessors(new UniqueArrayList());// clearing list at this point.
0836: // if (holdAccessors != null && holdAccessors.size() > 0)
0837: // {
0838: // Iterator iter = holdAccessors.iterator();
0839: // while (iter.hasNext())
0840: // {
0841: // MessageForumsUser user = (MessageForumsUser) iter.next();
0842: // forum.getActorPermissions().addAccesssor(user);
0843: // }
0844: // }
0845:
0846: forumManager.saveDiscussionForum(forum, draft);
0847:
0848: if (saveArea) {
0849: Area area = getDiscussionForumArea();
0850: forum.setArea(area);
0851: forum.setSortIndex(new Integer(0));
0852: area.addDiscussionForum(forum);
0853: areaManager.saveArea(area);
0854: }
0855: }
0856:
0857: /*
0858: * (non-Javadoc)
0859: *
0860: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveTopic(org.sakaiproject.api.app.messageforums.DiscussionTopic)
0861: */
0862: public void saveTopic(DiscussionTopic topic) {
0863: if (LOG.isDebugEnabled()) {
0864: LOG.debug("saveTopic(DiscussionTopic" + topic + ")");
0865: }
0866: saveTopic(topic, false);
0867: }
0868:
0869: /*
0870: * (non-Javadoc)
0871: *
0872: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveTopicAsDraft(org.sakaiproject.api.app.messageforums.DiscussionTopic)
0873: */
0874: public void saveTopicAsDraft(DiscussionTopic topic) {
0875: if (LOG.isDebugEnabled()) {
0876: LOG.debug("saveTopicAsDraft(DiscussionTopic" + topic + ")");
0877: }
0878: saveTopic(topic, true);
0879: }
0880:
0881: private void saveTopic(DiscussionTopic topic, boolean draft) {
0882: LOG.debug("saveTopic(DiscussionTopic " + topic + ", boolean "
0883: + draft + ")");
0884:
0885: boolean saveForum = topic.getId() == null;
0886: topic.setDraft(new Boolean(draft));
0887: forumManager.saveDiscussionForumTopic(topic);
0888: if (saveForum) {
0889: DiscussionForum forum = (DiscussionForum) topic
0890: .getBaseForum();
0891: forum.addTopic(topic);
0892: forumManager.saveDiscussionForum(forum, forum.getDraft()
0893: .booleanValue());
0894: //sak-5146 forumManager.saveDiscussionForum(forum);
0895: }
0896: }
0897:
0898: /*
0899: * (non-Javadoc)
0900: *
0901: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#deleteTopic(org.sakaiproject.api.app.messageforums.DiscussionTopic)
0902: */
0903: public void deleteTopic(DiscussionTopic topic) {
0904: if (LOG.isDebugEnabled()) {
0905: LOG.debug("deleteTopic(DiscussionTopic " + topic + ")");
0906: }
0907: forumManager.deleteDiscussionForumTopic(topic);
0908: }
0909:
0910: /*
0911: * (non-Javadoc)
0912: *
0913: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getDefaultControlPermissions()
0914: */
0915: public List getDefaultControlPermissions() {
0916: LOG.debug("getDefaultControlPermissions()");
0917: List defaultControlPermissions = new ArrayList();
0918: Iterator roles = getRoles();
0919: while (roles.hasNext()) {
0920: String roleId = (String) roles.next();
0921: AreaControlPermission controlPermission = permissionManager
0922: .getDefaultAreaControlPermissionForRole(roleId,
0923: typeManager.getDiscussionForumType());
0924:
0925: defaultControlPermissions.add(controlPermission);
0926: }
0927: return defaultControlPermissions;
0928: }
0929:
0930: /*
0931: * (non-Javadoc)
0932: *
0933: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getAreaControlPermissions()
0934: */
0935: public List getAreaControlPermissions() {
0936: LOG.debug("getAreaControlPermissions()");
0937: List areaControlPermissions = new ArrayList();
0938: Iterator roles = getRoles();
0939: while (roles.hasNext()) {
0940: String roleId = (String) roles.next();
0941: AreaControlPermission controlPermission = permissionManager
0942: .getAreaControlPermissionForRole(roleId,
0943: typeManager.getDiscussionForumType());
0944: if (controlPermission == null) {
0945: controlPermission = permissionManager
0946: .createAreaControlPermissionForRole(roleId,
0947: typeManager.getDiscussionForumType());
0948: }
0949: areaControlPermissions.add(controlPermission);
0950: }
0951: return areaControlPermissions;
0952: }
0953:
0954: /*
0955: * (non-Javadoc)
0956: *
0957: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getAreaMessagePermissions()
0958: */
0959: public List getAreaMessagePermissions() {
0960: LOG.debug("getAreaMessagePermissions()");
0961: List areaMessagePermissions = new ArrayList();
0962: Iterator roles = getRoles();
0963: while (roles.hasNext()) {
0964: String roleId = (String) roles.next();
0965: MessagePermissions messagePermission = permissionManager
0966: .getAreaMessagePermissionForRole(roleId,
0967: typeManager.getDiscussionForumType());
0968: if (messagePermission == null) {
0969: messagePermission = permissionManager
0970: .createAreaMessagePermissionForRole(roleId,
0971: typeManager.getDiscussionForumType());
0972: }
0973: areaMessagePermissions.add(messagePermission);
0974: }
0975: return areaMessagePermissions;
0976: }
0977:
0978: /*
0979: * (non-Javadoc)
0980: *
0981: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getDefaultMessagePermissions()
0982: */
0983: public List getDefaultMessagePermissions() {
0984: LOG.debug("getDefaultMessagePermissions()");
0985: List defaultMessagePermissions = new ArrayList();
0986: Iterator roles = getRoles();
0987: while (roles.hasNext()) {
0988: String roleId = (String) roles.next();
0989: MessagePermissions messagePermission = permissionManager
0990: .getDefaultAreaMessagePermissionForRole(roleId,
0991: typeManager.getDiscussionForumType());
0992: defaultMessagePermissions.add(messagePermission);
0993: }
0994: return defaultMessagePermissions;
0995: }
0996:
0997: /*
0998: * (non-Javadoc)
0999: *
1000: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveDefaultMessagePermissions(java.util.List)
1001: */
1002: public void saveAreaMessagePermissions(List messagePermissions) {
1003: if (LOG.isDebugEnabled()) {
1004: LOG.debug("saveDefaultMessagePermissions(List "
1005: + messagePermissions + ")");
1006: }
1007: if (messagePermissions != null && messagePermissions.size() > 0) {
1008: Iterator iterator = messagePermissions.iterator();
1009: while (iterator.hasNext()) {
1010: MessagePermissions msgPermission = (MessagePermissions) iterator
1011: .next();
1012: permissionManager.saveAreaMessagePermissionForRole(
1013: getDiscussionForumArea(), msgPermission,
1014: typeManager.getDiscussionForumType());
1015: }
1016: }
1017:
1018: }
1019:
1020: /*
1021: * (non-Javadoc)
1022: *
1023: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getForumControlPermissions(org.sakaiproject.api.app.messageforums.DiscussionForum)
1024: */
1025: public List getForumControlPermissions(DiscussionForum forum) {
1026: if (LOG.isDebugEnabled()) {
1027: LOG.debug("getForumControlPermissions(DiscussionForum "
1028: + forum + ")");
1029: }
1030: List forumControlPermissions = new ArrayList();
1031: Iterator roles = getRoles();
1032: while (roles.hasNext()) {
1033: String roleId = (String) roles.next();
1034: ForumControlPermission controlPermission = permissionManager
1035: .getForumControlPermissionForRole(forum, roleId,
1036: typeManager.getDiscussionForumType());
1037:
1038: if (controlPermission == null) {
1039: controlPermission = permissionManager
1040: .createForumControlPermissionForRole(roleId,
1041: typeManager.getDiscussionForumType());
1042: }
1043: forumControlPermissions.add(controlPermission);
1044: }
1045: return forumControlPermissions;
1046: }
1047:
1048: /*
1049: * (non-Javadoc)
1050: *
1051: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getForumMessagePermissions(org.sakaiproject.api.app.messageforums.DiscussionForum)
1052: */
1053: public List getForumMessagePermissions(DiscussionForum forum) {
1054: if (LOG.isDebugEnabled()) {
1055: LOG.debug("getForumMessagePermissions(DiscussionForum "
1056: + forum + ")");
1057: }
1058:
1059: List forumMessagePermissions = new ArrayList();
1060: Iterator roles = getRoles();
1061: while (roles.hasNext()) {
1062: String roleId = (String) roles.next();
1063: MessagePermissions messagePermission = permissionManager
1064: .getForumMessagePermissionForRole(forum, roleId,
1065: typeManager.getDiscussionForumType());
1066:
1067: if (messagePermission == null) {
1068: messagePermission = permissionManager
1069: .createForumMessagePermissionForRole(roleId,
1070: typeManager.getDiscussionForumType());
1071: }
1072: forumMessagePermissions.add(messagePermission);
1073: }
1074: return forumMessagePermissions;
1075: }
1076:
1077: /*
1078: * (non-Javadoc)
1079: *
1080: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getTopicControlPermissions(org.sakaiproject.api.app.messageforums.DiscussionTopic)
1081: */
1082: public List getTopicControlPermissions(DiscussionTopic topic) {
1083: LOG.debug("getTopicControlPermissions(DiscussionTopic " + topic
1084: + ")");
1085:
1086: List topicControlPermissions = new ArrayList();
1087: Iterator roles = getRoles();
1088: while (roles.hasNext()) {
1089: String roleId = (String) roles.next();
1090: TopicControlPermission controlPermission = permissionManager
1091: .getTopicControlPermissionForRole(topic, roleId,
1092: typeManager.getDiscussionForumType());
1093:
1094: if (controlPermission == null) {
1095: controlPermission = permissionManager
1096: .createTopicControlPermissionForRole(topic
1097: .getBaseForum(), roleId, typeManager
1098: .getDiscussionForumType());
1099: }
1100: topicControlPermissions.add(controlPermission);
1101: }
1102: return topicControlPermissions;
1103:
1104: }
1105:
1106: /*
1107: * (non-Javadoc)
1108: *
1109: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getTopicMessagePermissions(org.sakaiproject.api.app.messageforums.DiscussionTopic)
1110: */
1111: public List getTopicMessagePermissions(DiscussionTopic topic) {
1112: LOG.debug("getTopicMessagePermissions(DiscussionTopic " + topic
1113: + ")");
1114:
1115: List topicMessagePermissions = new ArrayList();
1116: Iterator roles = getRoles();
1117: while (roles.hasNext()) {
1118: String roleId = (String) roles.next();
1119: MessagePermissions messagePermission = permissionManager
1120: .getTopicMessagePermissionForRole(topic, roleId,
1121: typeManager.getDiscussionForumType());
1122:
1123: if (messagePermission == null) {
1124: messagePermission = permissionManager
1125: .createTopicMessagePermissionForRole(topic
1126: .getBaseForum(), roleId, typeManager
1127: .getDiscussionForumType());
1128: }
1129: topicMessagePermissions.add(messagePermission);
1130: }
1131: return topicMessagePermissions;
1132:
1133: }
1134:
1135: /*
1136: * (non-Javadoc)
1137: *
1138: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveDefaultControlPermissions(java.util.List)
1139: */
1140: public void saveAreaControlPermissions(List controlpermissions) {
1141: if (LOG.isDebugEnabled()) {
1142: LOG.debug("saveAreaControlPermissions(List"
1143: + controlpermissions + ")");
1144: }
1145: if (controlpermissions != null && controlpermissions.size() > 0) {
1146: Iterator iterator = controlpermissions.iterator();
1147: while (iterator.hasNext()) {
1148: AreaControlPermission controlPermission = (AreaControlPermission) iterator
1149: .next();
1150: permissionManager.saveAreaControlPermissionForRole(
1151: getDiscussionForumArea(), controlPermission,
1152: typeManager.getDiscussionForumType());
1153: }
1154: }
1155:
1156: }
1157:
1158: /*
1159: * (non-Javadoc)
1160: *
1161: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveForumControlPermissions(org.sakaiproject.api.app.messageforums.DiscussionForum,
1162: * java.util.List)
1163: */
1164: public void saveForumControlPermissions(DiscussionForum forum,
1165: List controlPermissions) {
1166: if (LOG.isDebugEnabled()) {
1167: LOG.debug("saveForumControlPermissions(List "
1168: + controlPermissions + ")");
1169: }
1170: if (forum != null && controlPermissions != null
1171: && controlPermissions.size() > 0) {
1172: Iterator iterator = controlPermissions.iterator();
1173: while (iterator.hasNext()) {
1174: ForumControlPermission controlPermission = (ForumControlPermission) iterator
1175: .next();
1176: permissionManager.saveForumControlPermissionForRole(
1177: forum, controlPermission);
1178: }
1179: }
1180:
1181: }
1182:
1183: /*
1184: * (non-Javadoc)
1185: *
1186: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveForumMessagePermissions(org.sakaiproject.api.app.messageforums.DiscussionForum,
1187: * java.util.List)
1188: */
1189: public void saveForumMessagePermissions(DiscussionForum forum,
1190: List messagePermissions) {
1191: if (LOG.isDebugEnabled()) {
1192: LOG.debug("saveForumMessagePermissions(List "
1193: + messagePermissions + ")");
1194: }
1195: if (forum != null && messagePermissions != null
1196: && messagePermissions.size() > 0) {
1197: Iterator iterator = messagePermissions.iterator();
1198: while (iterator.hasNext()) {
1199: MessagePermissions messagePermission = (MessagePermissions) iterator
1200: .next();
1201: permissionManager.saveForumMessagePermissionForRole(
1202: forum, messagePermission);
1203: }
1204: }
1205:
1206: }
1207:
1208: /*
1209: * (non-Javadoc)
1210: *
1211: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveTopicControlPermissions(org.sakaiproject.api.app.messageforums.DiscussionForum,
1212: * java.util.List)
1213: */
1214: public void saveTopicControlPermissions(DiscussionTopic topic,
1215: List controlPermissions) {
1216: if (LOG.isDebugEnabled()) {
1217: LOG.debug("saveTopicControlPermissions(List "
1218: + controlPermissions + ")");
1219: }
1220: if (topic != null && controlPermissions != null
1221: && controlPermissions.size() > 0) {
1222: Iterator iterator = controlPermissions.iterator();
1223: while (iterator.hasNext()) {
1224: TopicControlPermission controlPermission = (TopicControlPermission) iterator
1225: .next();
1226: permissionManager.saveTopicControlPermissionForRole(
1227: topic, controlPermission);
1228: }
1229: }
1230: }
1231:
1232: /*
1233: * (non-Javadoc)
1234: *
1235: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#saveTopicMessagePermissions(org.sakaiproject.api.app.messageforums.DiscussionTopic,
1236: * java.util.List)
1237: */
1238: public void saveTopicMessagePermissions(DiscussionTopic topic,
1239: List messagePermissions) {
1240: if (LOG.isDebugEnabled()) {
1241: LOG.debug("saveTopicMessagePermissions(List "
1242: + messagePermissions + ")");
1243: }
1244: if (topic != null && messagePermissions != null
1245: && messagePermissions.size() > 0) {
1246: Iterator iterator = messagePermissions.iterator();
1247: while (iterator.hasNext()) {
1248: MessagePermissions messagePermission = (MessagePermissions) iterator
1249: .next();
1250: permissionManager.saveTopicMessagePermissionForRole(
1251: topic, messagePermission);
1252: }
1253: }
1254:
1255: }
1256:
1257: /**
1258: * @return Roles for the current site
1259: */
1260: private Iterator getRoles() {
1261: LOG.debug("getRoles()");
1262: List roleList = new ArrayList();
1263: AuthzGroup realm = null;
1264: try {
1265: realm = AuthzGroupService.getAuthzGroup(getContextSiteId());
1266: Set roles = realm.getRoles();
1267: if (roles != null && roles.size() > 0) {
1268: Iterator roleIter = roles.iterator();
1269: while (roleIter.hasNext()) {
1270: Role role = (Role) roleIter.next();
1271: if (role != null)
1272: roleList.add(role.getId());
1273: }
1274: }
1275: } catch (GroupNotDefinedException e) {
1276: // TODO Auto-generated catch block
1277: e.printStackTrace();
1278: }
1279: Collections.sort(roleList);
1280: return roleList.iterator();
1281: }
1282:
1283: public void markMessageAs(Message message, boolean readStatus) {
1284: if (LOG.isDebugEnabled()) {
1285: LOG.debug("markMessageAsRead(Message" + message + ")");
1286: }
1287: try {
1288: messageManager.markMessageReadForUser(message.getTopic()
1289: .getId(), message.getId(), readStatus);
1290: } catch (Exception e) {
1291: LOG.error(e.getMessage(), e);
1292: }
1293:
1294: }
1295:
1296: public void markMessageReadStatusForUser(Message message,
1297: boolean readStatus, String userId) {
1298: if (LOG.isDebugEnabled()) {
1299: LOG.debug("markMessageReadStatusForUser(Message" + message
1300: + " readStatus:" + readStatus + " userId: "
1301: + userId + ")");
1302: }
1303: try {
1304: messageManager.markMessageReadForUser(message.getTopic()
1305: .getId(), message.getId(), readStatus, userId);
1306: } catch (Exception e) {
1307: LOG.error(e.getMessage(), e);
1308: }
1309: }
1310:
1311: private boolean getTopicAccess(DiscussionTopic t) {
1312: if (LOG.isDebugEnabled()) {
1313: LOG.debug("getTopicAccess(DiscussionTopic" + t + ")");
1314: }
1315: if (t.getDraft().equals(Boolean.FALSE)
1316: || (t.getDraft().equals(Boolean.TRUE) && t
1317: .getCreatedBy().equals(
1318: sessionManager
1319: .getCurrentSessionUserId()))
1320: || isInstructor()
1321: || securityService.isSuperUser()
1322: || t.getCreatedBy().equals(
1323: sessionManager.getCurrentSessionUserId())) {
1324: return true;
1325: }
1326: return false;
1327: }
1328:
1329: /**
1330: * @param accessorList
1331: * @return
1332: */
1333: private List decodeActorPermissionTypeList(List selectedList) {
1334: if (LOG.isDebugEnabled()) {
1335: LOG.debug("decodeActorPermissionTypeList(List"
1336: + selectedList + ")");
1337: }
1338:
1339: List newSelectedMemberList = new ArrayList();
1340:
1341: for (Iterator i = selectedList.iterator(); i.hasNext();) {
1342: String selectedItem = (String) i.next();
1343: MessageForumsUser user = new MessageForumsUserImpl();
1344: /** lookup item in map */
1345: MembershipItem item = (MembershipItem) getAllCourseMembers()
1346: .get(selectedItem);
1347: if (item == null) {
1348: LOG
1349: .warn("decodeActorPermissionTypeList() could not resolve uuid: "
1350: + selectedItem);
1351: } else {
1352: if (MembershipItem.TYPE_ALL_PARTICIPANTS.equals(item
1353: .getType())) {
1354: user.setTypeUuid(typeManager
1355: .getAllParticipantType());
1356: user.setUserId(typeManager.getAllParticipantType());
1357: newSelectedMemberList.add(user);
1358: } else if (MembershipItem.TYPE_NOT_SPECIFIED
1359: .equals(item.getType())) {
1360: user.setTypeUuid(typeManager.getNotSpecifiedType());
1361: user.setUserId(typeManager.getNotSpecifiedType());
1362: // if not specified is seleted then only this value remains.
1363: newSelectedMemberList = null;
1364: newSelectedMemberList = new ArrayList();
1365: newSelectedMemberList.add(user);
1366: break;
1367: } else if (MembershipItem.TYPE_ROLE.equals(item
1368: .getType())) {
1369: user.setTypeUuid(typeManager.getRoleType());
1370: user.setUserId(item.getRole().getId());
1371: newSelectedMemberList.add(user);
1372:
1373: } else if (MembershipItem.TYPE_GROUP.equals(item
1374: .getType())) {
1375: user.setTypeUuid(typeManager.getGroupType());
1376: user.setUserId(item.getGroup().getId());
1377: newSelectedMemberList.add(user);
1378: } else if (MembershipItem.TYPE_USER.equals(item
1379: .getType())) {
1380: user.setTypeUuid(typeManager.getUserType());
1381: user.setUserId(item.getUser().getId());
1382: newSelectedMemberList.add(user);
1383: } else {
1384: LOG
1385: .warn("getRecipients() could not resolve membership type: "
1386: + item.getType());
1387: }
1388: }
1389: }
1390: return newSelectedMemberList;
1391: }
1392:
1393: /*
1394: * (non-Javadoc)
1395: *
1396: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#decodeAccessorsList(java.util.List)
1397: */
1398: public List decodeAccessorsList(ArrayList accessorList) {
1399: if (LOG.isDebugEnabled()) {
1400: LOG.debug("decodeAccessorsList(List" + accessorList + ")");
1401: }
1402: if (accessorList == null || accessorList.size() < 1) {
1403: return forumManager.createDefaultActorPermissions()
1404: .getAccessors();
1405: }
1406: return decodeActorPermissionTypeList(accessorList);
1407: }
1408:
1409: /*
1410: * (non-Javadoc)
1411: *
1412: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#decodeContributorsList(java.util.List)
1413: */
1414: public List decodeContributorsList(ArrayList contributorList) {
1415: if (LOG.isDebugEnabled()) {
1416: LOG.debug("decodeContributorsList(List" + contributorList
1417: + ")");
1418: }
1419: if (contributorList == null || contributorList.size() < 1) {
1420: return forumManager.createDefaultActorPermissions()
1421: .getContributors();
1422: }
1423: return decodeActorPermissionTypeList(contributorList);
1424: }
1425:
1426: /*
1427: * (non-Javadoc)
1428: *
1429: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getContributorsList(org.sakaiproject.api.app.messageforums.DiscussionForum)
1430: */
1431: public List getContributorsList(DiscussionForum forum) {
1432: if (LOG.isDebugEnabled()) {
1433: LOG.debug(" getContributorsList(DiscussionForum" + forum
1434: + ")");
1435: }
1436: List contributorList = null;
1437: if (forum == null) {
1438: return null;
1439: }
1440: if (forum.getActorPermissions() == null
1441: || forum.getActorPermissions().getContributors() == null) {
1442: forum.setActorPermissions(forumManager
1443: .createDefaultActorPermissions());
1444: contributorList = forumManager
1445: .createDefaultActorPermissions().getContributors();
1446: } else {
1447: contributorList = forum.getActorPermissions()
1448: .getContributors();
1449: }
1450: Iterator iterator = contributorList.iterator();
1451:
1452: return getContributorAccessorList(iterator);
1453: }
1454:
1455: /*
1456: * (non-Javadoc)
1457: *
1458: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getAccessorsList(org.sakaiproject.api.app.messageforums.DiscussionForum)
1459: */
1460: public List getAccessorsList(DiscussionForum forum) {
1461: if (LOG.isDebugEnabled()) {
1462: LOG.debug("getAccessorsList(DiscussionForum" + forum + ")");
1463: }
1464: List accessorsList = null;
1465: if (forum == null) {
1466: return null;
1467: }
1468: if (forum.getActorPermissions() == null
1469: || forum.getActorPermissions().getAccessors() == null) {
1470: forum.setActorPermissions(forumManager
1471: .createDefaultActorPermissions());
1472: accessorsList = forumManager
1473: .createDefaultActorPermissions().getAccessors();
1474: } else {
1475: accessorsList = forum.getActorPermissions().getAccessors();
1476: }
1477:
1478: Iterator iterator = accessorsList.iterator();
1479:
1480: return getContributorAccessorList(iterator);
1481: }
1482:
1483: /**
1484: * @param iterator
1485: * @return
1486: */
1487: private List getContributorAccessorList(Iterator iterator) {
1488: if (LOG.isDebugEnabled()) {
1489: LOG.debug("getContributorAccessorList(Iterator" + iterator
1490: + ")");
1491: }
1492: List modifiedContributorList = new ArrayList();
1493: while (iterator.hasNext()) {
1494: String selectedId = null;
1495: MessageForumsUser user = (MessageForumsUser) iterator
1496: .next();
1497: List totalmembers = membershipManager
1498: .convertMemberMapToList(courseMemberMap);
1499: Iterator iter = totalmembers.iterator();
1500:
1501: if (user.getTypeUuid().equals(
1502: typeManager.getAllParticipantType())) {
1503: while (iter.hasNext()) {
1504: MembershipItem member = (MembershipItem) iter
1505: .next();
1506: if (member.getType().equals(
1507: MembershipItem.TYPE_ALL_PARTICIPANTS)) {
1508: selectedId = member.getId();
1509: }
1510: }
1511: }
1512: if (user.getTypeUuid().equals(
1513: typeManager.getNotSpecifiedType())) {
1514: while (iter.hasNext()) {
1515: MembershipItem member = (MembershipItem) iter
1516: .next();
1517: if (member.getType().equals(
1518: MembershipItem.TYPE_NOT_SPECIFIED)) {
1519: selectedId = member.getId();
1520: }
1521: }
1522: }
1523:
1524: if (user.getTypeUuid().equals(typeManager.getGroupType())) {
1525: while (iter.hasNext()) {
1526: MembershipItem member = (MembershipItem) iter
1527: .next();
1528: if (member.getType().equals(
1529: MembershipItem.TYPE_GROUP)
1530: && user.getUserId().equals(
1531: member.getGroup().getId())) {
1532: selectedId = member.getId();
1533: }
1534: }
1535:
1536: }
1537: if (user.getTypeUuid().equals(typeManager.getRoleType())) {
1538: while (iter.hasNext()) {
1539: MembershipItem member = (MembershipItem) iter
1540: .next();
1541: if (member.getType().equals(
1542: MembershipItem.TYPE_ROLE)
1543: && user.getUserId().equals(
1544: member.getRole().getId())) {
1545: selectedId = member.getId();
1546: }
1547: }
1548: }
1549: if (user.getTypeUuid().equals(typeManager.getUserType())) {
1550: while (iter.hasNext()) {
1551: MembershipItem member = (MembershipItem) iter
1552: .next();
1553: if (member.getType().equals(
1554: MembershipItem.TYPE_USER)
1555: && user.getUserId().equals(
1556: member.getUser().getId())) {
1557: selectedId = member.getId();
1558: }
1559: }
1560:
1561: }
1562:
1563: modifiedContributorList.add(selectedId);
1564: }
1565: return modifiedContributorList;
1566: }
1567:
1568: /*
1569: * (non-Javadoc)
1570: *
1571: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getAllCourseMembers()
1572: */
1573: public Map getAllCourseMembers() {
1574: if (LOG.isDebugEnabled()) {
1575: LOG.debug("getAllCourseMembers()");
1576: }
1577: if (courseMemberMap == null) {
1578: courseMemberMap = membershipManager.getAllCourseMembers(
1579: true, false, true);
1580: }
1581: return courseMemberMap;
1582: }
1583:
1584: /**
1585: * @param courseMemberMap
1586: * The courseMemberMap to set.
1587: */
1588: public void setCourseMemberMapToNull() {
1589: this .courseMemberMap = null;
1590: }
1591:
1592: /*
1593: * (non-Javadoc)
1594: *
1595: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getContributorsList(org.sakaiproject.api.app.messageforums.DiscussionTopic)
1596: */
1597: public List getContributorsList(DiscussionTopic topic,
1598: DiscussionForum forum) {
1599: if (LOG.isDebugEnabled()) {
1600: LOG.debug("getContributorsList(DiscussionTopic " + topic
1601: + ", DiscussionForum " + forum + ")");
1602: }
1603: List contributorList = null;
1604: if (topic == null) {
1605: return null;
1606: }
1607: if (topic.getActorPermissions() == null
1608: || topic.getActorPermissions().getContributors() == null) {
1609: // hibernate does not permit this b/c saving forum and topics will
1610: // throw uniqueobjectexception
1611: topic
1612: .setActorPermissions(getDeepCopyOfParentActorPermissions(forum
1613: .getActorPermissions()));
1614: contributorList = topic.getActorPermissions()
1615: .getContributors();
1616: } else {
1617: contributorList = topic.getActorPermissions()
1618: .getContributors();
1619: }
1620: Iterator iterator = contributorList.iterator();
1621:
1622: return getContributorAccessorList(iterator);
1623: }
1624:
1625: private ActorPermissions getDeepCopyOfParentActorPermissions(
1626: ActorPermissions actorPermissions) {
1627: ActorPermissions newAP = new ActorPermissionsImpl();
1628: List parentAccessors = actorPermissions.getAccessors();
1629: List parentContributors = actorPermissions.getContributors();
1630: List newAccessors = new ArrayList();
1631: List newContributor = new ArrayList();
1632: Iterator iter = parentAccessors.iterator();
1633: while (iter.hasNext()) {
1634: MessageForumsUser accessParent = (MessageForumsUser) iter
1635: .next();
1636: MessageForumsUser newaccessor = new MessageForumsUserImpl();
1637: newaccessor.setTypeUuid(accessParent.getTypeUuid());
1638: newaccessor.setUserId(accessParent.getUserId());
1639: newaccessor.setUuid(accessParent.getUuid());
1640: newAccessors.add(newaccessor);
1641: }
1642: Iterator iter1 = parentContributors.iterator();
1643: while (iter1.hasNext()) {
1644: MessageForumsUser contribParent = (MessageForumsUser) iter1
1645: .next();
1646: MessageForumsUser newcontributor = new MessageForumsUserImpl();
1647: newcontributor.setTypeUuid(contribParent.getTypeUuid());
1648: newcontributor.setUserId(contribParent.getUserId());
1649: newcontributor.setUuid(contribParent.getUuid());
1650: newContributor.add(newcontributor);
1651: }
1652: newAP.setAccessors(newAccessors);
1653: newAP.setContributors(newContributor);
1654: return newAP;
1655: }
1656:
1657: /*
1658: * (non-Javadoc)
1659: *
1660: * @see org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager#getAccessorsList(org.sakaiproject.api.app.messageforums.DiscussionTopic)
1661: */
1662: public List getAccessorsList(DiscussionTopic topic,
1663: DiscussionForum forum) {
1664: if (LOG.isDebugEnabled()) {
1665: LOG.debug("getAccessorsList(DiscussionTopic " + topic
1666: + ", DiscussionForum " + forum + ")");
1667: }
1668: List accessorsList = null;
1669: if (topic == null) {
1670: return null;
1671: }
1672: if (topic.getActorPermissions() == null
1673: || topic.getActorPermissions().getAccessors() == null) {
1674: // hibernate does not permit this b/c saving forum and topics will
1675: // throw uniqueobjectexception
1676: topic
1677: .setActorPermissions(getDeepCopyOfParentActorPermissions(forum
1678: .getActorPermissions()));
1679: accessorsList = topic.getActorPermissions().getAccessors();
1680: } else {
1681: accessorsList = topic.getActorPermissions().getAccessors();
1682: }
1683:
1684: Iterator iterator = accessorsList.iterator();
1685:
1686: return getContributorAccessorList(iterator);
1687: }
1688:
1689: public DBMembershipItem getAreaDBMember(Set originalSet,
1690: String name, Integer type) {
1691: DBMembershipItem newItem = getDBMember(originalSet, name, type);
1692: return newItem;
1693: }
1694:
1695: public DBMembershipItem getDBMember(Set originalSet, String name,
1696: Integer type) {
1697:
1698: DBMembershipItem membershipItem = null;
1699: DBMembershipItem membershipItemIter;
1700:
1701: if (originalSet != null) {
1702: Iterator iter = originalSet.iterator();
1703: while (iter.hasNext()) {
1704: membershipItemIter = (DBMembershipItem) iter.next();
1705: if (membershipItemIter.getType().equals(type)
1706: && membershipItemIter.getName().equals(name)) {
1707: membershipItem = membershipItemIter;
1708: break;
1709: }
1710: }
1711: }
1712:
1713: if (membershipItem == null
1714: || membershipItem.getPermissionLevel() == null) {
1715: PermissionLevel level = null;
1716: //for groups awareness
1717: if (type.equals(DBMembershipItem.TYPE_ROLE)
1718: || type.equals(DBMembershipItem.TYPE_GROUP)) {
1719:
1720: String levelName = null;
1721:
1722: if (membershipItem != null) {
1723: /** use level from stored item */
1724: levelName = membershipItem.getPermissionLevelName();
1725: } else {
1726: /** get level from config file */
1727: levelName = ServerConfigurationService
1728: .getString(MC_DEFAULT + name);
1729:
1730: }
1731:
1732: if (levelName != null && levelName.trim().length() > 0) {
1733: level = permissionLevelManager
1734: .getPermissionLevelByName(levelName);
1735: } else {
1736: Collection siteIds = new Vector();
1737: siteIds.add(getContextSiteId());
1738: if (AuthzGroupService.getAllowedFunctions(name,
1739: siteIds).contains(
1740: SiteService.SECURE_UPDATE_SITE)) {
1741: level = permissionLevelManager
1742: .getDefaultOwnerPermissionLevel();
1743: } else if (type.equals(DBMembershipItem.TYPE_GROUP)) {
1744: level = permissionLevelManager
1745: .getDefaultNonePermissionLevel();
1746: } else {
1747: level = permissionLevelManager
1748: .getDefaultContributorPermissionLevel();
1749: }
1750:
1751: }
1752: }
1753: PermissionLevel noneLevel = permissionLevelManager
1754: .getDefaultNonePermissionLevel();
1755: membershipItem = new DBMembershipItemImpl();
1756: membershipItem.setName(name);
1757: membershipItem
1758: .setPermissionLevelName((level == null) ? noneLevel
1759: .getName() : level.getName());
1760: membershipItem.setType(type);
1761: membershipItem
1762: .setPermissionLevel((level == null) ? noneLevel
1763: : level);
1764: }
1765: return membershipItem;
1766: }
1767:
1768: //Attachment
1769: public Attachment createDFAttachment(String attachId, String name) {
1770: try {
1771: Attachment attach = messageManager.createAttachment();
1772:
1773: attach.setAttachmentId(attachId);
1774:
1775: attach.setAttachmentName(name);
1776:
1777: ContentResource cr = ContentHostingService
1778: .getResource(attachId);
1779: attach
1780: .setAttachmentSize((new Integer(cr
1781: .getContentLength())).toString());
1782: attach.setCreatedBy(cr.getProperties().getProperty(
1783: cr.getProperties().getNamePropCreator()));
1784: attach.setModifiedBy(cr.getProperties().getProperty(
1785: cr.getProperties().getNamePropModifiedBy()));
1786: attach.setAttachmentType(cr.getContentType());
1787: String tempString = cr.getUrl();
1788: String newString = new String();
1789: char[] oneChar = new char[1];
1790: for (int i = 0; i < tempString.length(); i++) {
1791: if (tempString.charAt(i) != ' ') {
1792: oneChar[0] = tempString.charAt(i);
1793: String concatString = new String(oneChar);
1794: newString = newString.concat(concatString);
1795: } else {
1796: newString = newString.concat("%20");
1797: }
1798: }
1799: //tempString.replaceAll(" ", "%20");
1800: //attach.setAttachmentUrl(newString);
1801: attach.setAttachmentUrl("/url");
1802:
1803: return attach;
1804: } catch (Exception e) {
1805: e.printStackTrace();
1806: return null;
1807: }
1808: }
1809:
1810: public List getDiscussionForumsWithTopics() {
1811: LOG.debug("getDiscussionForumsWithTopics()");
1812: return forumManager
1813: .getForumByTypeAndContextWithTopicsAllAttachments(typeManager
1814: .getDiscussionForumType());
1815: }
1816:
1817: public Map getReadStatusForMessagesWithId(List msgIds, String userId) {
1818: LOG.debug("getDiscussionForumsWithTopics()");
1819: return messageManager.getReadStatusForMessagesWithId(msgIds,
1820: userId);
1821: }
1822:
1823: public List getDiscussionForumsWithTopicsMembershipNoAttachments(
1824: String contextId) {
1825: LOG
1826: .debug("getDiscussionForumsWithTopicsMembershipNoAttachments()");
1827: return forumManager
1828: .getForumByTypeAndContextWithTopicsMembership(
1829: typeManager.getDiscussionForumType(), contextId);
1830: }
1831:
1832: public List getPendingMsgsInTopic(Long topicId) {
1833: return messageManager.getPendingMsgsInTopic(topicId);
1834: }
1835:
1836: public int getNumModTopicsWithModPermission(List membershipList) {
1837: return forumManager
1838: .getNumModTopicCurrentUserHasModPermFor(membershipList);
1839: }
1840:
1841: }
|