0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-app/src/java/org/sakaiproject/tool/messageforums/ui/MessageForumsSynopticBean.java $
0003: * $Id: MessageForumsSynopticBean.java $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2003, 2004, 2005, 2006 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.ui;
0021:
0022: import java.io.IOException;
0023:
0024: import java.util.ArrayList;
0025: import java.util.Collection;
0026: import java.util.Collections;
0027: import java.util.Iterator;
0028: import java.util.List;
0029: import java.util.Map;
0030: import java.util.Vector;
0031:
0032: import javax.faces.event.ActionEvent;
0033: import javax.faces.application.FacesMessage;
0034: import javax.faces.context.ExternalContext;
0035: import javax.faces.context.FacesContext;
0036: import javax.faces.model.SelectItem;
0037:
0038: import org.apache.commons.logging.Log;
0039: import org.apache.commons.logging.LogFactory;
0040: import org.sakaiproject.api.app.messageforums.Area;
0041: import org.sakaiproject.api.app.messageforums.AreaManager;
0042: import org.sakaiproject.api.app.messageforums.DiscussionForum;
0043: import org.sakaiproject.api.app.messageforums.DiscussionTopic;
0044: import org.sakaiproject.api.app.messageforums.MessageForumsMessageManager;
0045: import org.sakaiproject.api.app.messageforums.MessageForumsTypeManager;
0046: import org.sakaiproject.api.app.messageforums.PrivateForum;
0047: import org.sakaiproject.api.app.messageforums.PrivateMessage;
0048: import org.sakaiproject.api.app.messageforums.Topic;
0049: import org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager;
0050: import org.sakaiproject.api.app.messageforums.ui.PrivateMessageManager;
0051: import org.sakaiproject.api.app.messageforums.ui.UIPermissionsManager;
0052: import org.sakaiproject.authz.cover.AuthzGroupService;
0053: import org.sakaiproject.component.app.messageforums.dao.hibernate.PrivateTopicImpl;
0054: import org.sakaiproject.component.cover.ServerConfigurationService;
0055: import org.sakaiproject.entity.api.ResourceProperties;
0056: import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0057: import org.sakaiproject.exception.IdUnusedException;
0058: import org.sakaiproject.tool.cover.SessionManager;
0059: import org.sakaiproject.site.api.Site;
0060: import org.sakaiproject.site.api.SitePage;
0061: import org.sakaiproject.site.api.ToolConfiguration;
0062: import org.sakaiproject.site.cover.SiteService;
0063: import org.sakaiproject.tool.cover.ToolManager;
0064: import org.sakaiproject.user.api.Preferences;
0065: import org.sakaiproject.user.api.PreferencesEdit;
0066: import org.sakaiproject.user.api.PreferencesService;
0067: import org.sakaiproject.util.ResourceLoader;
0068:
0069: public class MessageForumSynopticBean {
0070:
0071: /**
0072: * Used to store synoptic information for a users unread messages.
0073: * Whether on the Home page of a site or in MyWorkspace determines
0074: * what properties are filled.
0075: * <p>
0076: * If in MyWorkspace, each object contains the number of unread
0077: * Private Messages and number of unread Discussion Forum messages.
0078: * </p>
0079: * <p>
0080: * If in the Home page of a site, each object contains either the
0081: * number of unread Private Messages or number of unread Discussion
0082: * Forum messages.</p>
0083: *
0084: * @author josephrodriguez
0085: *
0086: */
0087: public class DecoratedCompiledMessageStats {
0088: private String siteName;
0089: private String siteId;
0090:
0091: /** MyWorkspace information */
0092: private int unreadPrivateAmt;
0093: private int unreadForumsAmt;
0094: private String mcPageURL;
0095: private String privateMessagesUrl;
0096: private boolean messagesandForums;
0097: private boolean messages;
0098: private boolean forums;
0099:
0100: public String getSiteName() {
0101: return siteName;
0102: }
0103:
0104: public void setSiteName(String siteName) {
0105: this .siteName = siteName;
0106: }
0107:
0108: public int getUnreadPrivateAmt() {
0109: return unreadPrivateAmt;
0110: }
0111:
0112: public void setUnreadPrivateAmt(int unreadPrivateAmt) {
0113: this .unreadPrivateAmt = unreadPrivateAmt;
0114: }
0115:
0116: public int getUnreadForumsAmt() {
0117: return unreadForumsAmt;
0118: }
0119:
0120: public void setUnreadForumsAmt(int unreadForumsAmt) {
0121: this .unreadForumsAmt = unreadForumsAmt;
0122: }
0123:
0124: public String getMcPageURL() {
0125: return mcPageURL;
0126: }
0127:
0128: public void setMcPageURL(String mcPageURL) {
0129: this .mcPageURL = mcPageURL;
0130: }
0131:
0132: public String getSiteId() {
0133: return siteId;
0134: }
0135:
0136: public void setSiteId(String siteId) {
0137: this .siteId = siteId;
0138: }
0139:
0140: public String getPrivateMessagesUrl() {
0141: return privateMessagesUrl;
0142: }
0143:
0144: public void setPrivateMessagesUrl(String privateMessagesUrl) {
0145: this .privateMessagesUrl = privateMessagesUrl;
0146: }
0147:
0148: public boolean isMessagesandForums() {
0149: return messagesandForums;
0150: }
0151:
0152: public void setMessagesandForums(boolean messagesandForums) {
0153: this .messagesandForums = messagesandForums;
0154: }
0155:
0156: public boolean isMessages() {
0157: return messages;
0158: }
0159:
0160: public void setMessages(boolean messages) {
0161: this .messages = messages;
0162: }
0163:
0164: public boolean isForums() {
0165: return forums;
0166: }
0167:
0168: public void setForums(boolean forums) {
0169: this .forums = forums;
0170: }
0171: }
0172:
0173: /* =========== End of DecoratedCompiledMessageStats =========== */
0174:
0175: // transient only persists in request scope
0176: private transient Boolean myWorkspace = null;
0177: private transient Boolean pmEnabled = null;
0178: private transient Boolean anyMFToolInSite = null;
0179: private transient List contents = null;
0180:
0181: /** Used to determine if MessageCenter tool part of site */
0182: private final String MESSAGE_CENTER_ID = "sakai.messagecenter";
0183: private final String FORUMS_TOOL_ID = "sakai.forums";
0184: private final String MESSAGES_TOOL_ID = "sakai.messages";
0185:
0186: /** Used to get contextId when tool on MyWorkspace to set all private messages to Read status */
0187: private final String CONTEXTID = "contextId";
0188:
0189: /** Used to retrieve non-notification sites for MyWorkspace page */
0190: private static final String TABS_EXCLUDED_PREFS = "sakai:portal:sitenav";
0191: private final String TAB_EXCLUDED_SITES = "exclude";
0192:
0193: /** Preferences service (injected dependency) */
0194: protected PreferencesService preferencesService = null;
0195:
0196: /** =============== Main page bean values =============== */
0197: /** Used to determine if there are sites to display on page */
0198: private boolean sitesToView;
0199: private boolean sitesToViewSet = false;
0200:
0201: /** to get accces to log file */
0202: private static final Log LOG = LogFactory
0203: .getLog(MessageForumSynopticBean.class);
0204:
0205: /** Needed if within a site so we only need stats for this site */
0206: private MessageForumsMessageManager messageManager;
0207:
0208: /** Needed to get topics if tool within a site */
0209: private DiscussionForumManager forumManager;
0210:
0211: /** Needed to grab unread message count if tool within site */
0212: private PrivateMessageManager pvtMessageManager;
0213:
0214: /** Needed to get forum message counts as well as Uuids for private messages and discussions */
0215: private MessageForumsTypeManager typeManager;
0216:
0217: /** Needed to set up the counts for the private messages and forums */
0218: private AreaManager areaManager;
0219:
0220: /** Needed to determine if user has read permission of topic */
0221: private UIPermissionsManager uiPermissionsManager;
0222:
0223: public void setMessageManager(
0224: MessageForumsMessageManager messageManager) {
0225: this .messageManager = messageManager;
0226: }
0227:
0228: public void setForumManager(DiscussionForumManager forumManager) {
0229: this .forumManager = forumManager;
0230: }
0231:
0232: public void setPvtMessageManager(
0233: PrivateMessageManager pvtMessageManager) {
0234: this .pvtMessageManager = pvtMessageManager;
0235: }
0236:
0237: public void setTypeManager(MessageForumsTypeManager typeManager) {
0238: this .typeManager = typeManager;
0239: }
0240:
0241: public void setAreaManager(AreaManager areaManager) {
0242: this .areaManager = areaManager;
0243: }
0244:
0245: public void setUiPermissionsManager(
0246: UIPermissionsManager uiPermissionsManager) {
0247: this .uiPermissionsManager = uiPermissionsManager;
0248: }
0249:
0250: public void setPreferencesService(
0251: PreferencesService preferencesService) {
0252: this .preferencesService = preferencesService;
0253: }
0254:
0255: /**
0256: * Returns TRUE if on MyWorkspace, FALSE if on a specific site
0257: *
0258: * @return
0259: * TRUE if on MyWorkspace, FALSE if on a specific site
0260: */
0261: public boolean isMyWorkspace() {
0262: // myWorkspace is a transient variable
0263: if (myWorkspace == null) {
0264: // get context id
0265: final String siteId = getContext();
0266:
0267: if (SiteService.getUserSiteId("admin").equals(siteId))
0268: return false;
0269:
0270: myWorkspace = SiteService.isUserSite(siteId);
0271:
0272: LOG.debug("Result of determining if My Workspace: "
0273: + myWorkspace);
0274: }
0275:
0276: return myWorkspace.booleanValue();
0277: }
0278:
0279: /**
0280: * Returns TRUE if there is at least one site user can access
0281: * and user has not set it to be excluded
0282: *
0283: * @return
0284: * TRUE if there are/is site(s) user can access
0285: * FALSE if not
0286: */
0287: public boolean isSitesToView() {
0288: if (sitesToViewSet) {
0289: return sitesToView;
0290: } else {
0291: return !filterOutExcludedSites(getSiteList()).isEmpty();
0292: }
0293: }
0294:
0295: /**
0296: * @return
0297: * TRUE if (Private) Messages enabled, FALSE otherwise
0298: */
0299: public boolean isPmEnabled() {
0300: if (pmEnabled == null) {
0301: final Area area = pvtMessageManager.getPrivateMessageArea();
0302:
0303: pmEnabled = (area != null)
0304: && area.getEnabled().booleanValue();
0305: }
0306:
0307: return pmEnabled;
0308: }
0309:
0310: /**
0311: * @return
0312: * DecoratedCompiledMessageStats for a single site
0313: */
0314: public DecoratedCompiledMessageStats getSiteInfo() {
0315: return getSiteContents();
0316: }
0317:
0318: /**
0319: * Removes from message counts messages that the user currently
0320: * does not have read access to.
0321: *
0322: * @param currentList
0323: * List of message counts
0324: *
0325: * @param removeList
0326: * List of messages that user actually does not have
0327: * read access to
0328: * @return
0329: * List with the adjusted message counts
0330: */
0331: private List filterNoAccessMessages(List currentList,
0332: List removeList) {
0333: final List resultList = new ArrayList();
0334:
0335: // ****** if either list is empty, return currentList unchanged ******
0336: if (currentList.isEmpty() || removeList.isEmpty()) {
0337: return currentList;
0338: }
0339:
0340: // ****** Set up our iterator ******
0341: final Iterator currentIter = currentList.iterator();
0342:
0343: while (currentIter.hasNext()) {
0344: final Object[] resultValues = new Object[2];
0345: Object[] removeValues;
0346: Object[] currentValues = null;
0347:
0348: // get current values for this iteration
0349: if (currentIter.hasNext()) {
0350: currentValues = (Object[]) currentIter.next();
0351: }
0352:
0353: // is current site in the removeList. if so, return index where
0354: final int pos = indexOf((String) currentValues[0],
0355: getSiteIds(removeList));
0356:
0357: // if there are messages to remove, do so otherwise just add current values
0358: if (pos != -1) {
0359: removeValues = (Object[]) removeList.get(pos);
0360:
0361: resultValues[0] = currentValues[0];
0362: resultValues[1] = new Integer(
0363: ((Integer) currentValues[1]).intValue()
0364: - ((Integer) removeValues[2])
0365: .intValue());
0366:
0367: resultList.add(resultValues);
0368:
0369: removeList.remove(pos);
0370: } else {
0371: resultList.add(currentValues);
0372: }
0373: }
0374:
0375: return resultList;
0376: }
0377:
0378: /**
0379: * Returns a List of all roles a user has for all sites
0380: * they are a member of
0381: *
0382: * @param siteList
0383: * The List of site ids the user is a member of
0384: *
0385: * @return
0386: * List of role ids user has for all sites passed in
0387: */
0388: private List getUserRoles(List siteList) {
0389: final List roles = new ArrayList();
0390: final Iterator siteIter = siteList.iterator();
0391:
0392: while (siteIter.hasNext()) {
0393:
0394: Site curSite = null;
0395:
0396: try {
0397: curSite = getSite((String) siteIter.next());
0398: } catch (IdUnusedException e) {
0399: // Mucho weirdness, found by getSites() but now cannot find
0400: LOG
0401: .error("IdUnusedException while accessing site to determine user role");
0402: }
0403:
0404: if (curSite != null) {
0405: final String curRole = AuthzGroupService.getUserRole(
0406: SessionManager.getCurrentSessionUserId(),
0407: "/site/" + curSite.getId());
0408:
0409: if (curRole != null && !roles.contains(curRole)) {
0410: roles.add(curRole);
0411: }
0412: }
0413: }
0414:
0415: return roles;
0416: }
0417:
0418: /**
0419: * For this particular site, pick the correct role's count
0420: * that needs to be removed from the total count
0421: *
0422: * @param removeMessageCounts
0423: * List of counts to be removed ordered by site id
0424: *
0425: * @param siteList
0426: * List of sites this user is a member of
0427: *
0428: * @return
0429: * List of correct counts, at most one per site
0430: */
0431: private List selectCorrectRemoveMessageCount(
0432: List removeMessageCounts, List siteList) {
0433: // if message counts empty, nothing to do so return
0434: if (removeMessageCounts.isEmpty()) {
0435: return removeMessageCounts;
0436: }
0437:
0438: Object[] resultSet = null;
0439: final List resultList = new ArrayList();
0440: final Iterator siteIter = siteList.iterator();
0441:
0442: while (siteIter.hasNext()) {
0443:
0444: Site site;
0445:
0446: try {
0447: site = getSite((String) siteIter.next());
0448: } catch (IdUnusedException e) {
0449: // Weirdness - SiteService pulled this id and now it
0450: // can't find the site it pulled it from
0451: LOG
0452: .error("IdUnusedException trying to get site to remove non-read access messasges.");
0453: continue;
0454: }
0455:
0456: // does current site contain counts to remove. if so, return index where
0457: int pos = indexOf(site.getId(),
0458: getSiteIds(removeMessageCounts));
0459:
0460: // found, so get it and add to result list
0461: if (pos != -1) {
0462: resultSet = (Object[]) removeMessageCounts.get(pos);
0463:
0464: while (site.getId().equals((String) resultSet[0])) {
0465: // permissions based on roles, so need to check if user's role has messages
0466: // that need to be removed from totals (either total or unread)
0467: final String curRole = AuthzGroupService
0468: .getUserRole(SessionManager
0469: .getCurrentSessionUserId(),
0470: ("/site/" + site.getId()));
0471:
0472: if (curRole.equals((String) resultSet[1])) {
0473: resultList.add(resultSet);
0474:
0475: // remove all rows of removeMessageCounts for this site
0476: // since I've found the one I was looking for
0477: while (pos != -1) {
0478: removeMessageCounts.remove(pos);
0479:
0480: pos = indexOf(site.getId(),
0481: getSiteIds(removeMessageCounts));
0482: }
0483:
0484: // we're done removing rows, onto next site
0485: resultSet = new Object[2];
0486: resultSet[0] = "";
0487: } else {
0488: // this row is not it but may have others so remove it
0489: // to set up for next iteration of the loop
0490: removeMessageCounts.remove(pos++);
0491:
0492: if (pos < removeMessageCounts.size()) {
0493: resultSet = (Object[]) removeMessageCounts
0494: .get(pos);
0495: } else {
0496: // nope, no more for this site so do this to stop loop
0497: resultSet = new Object[2];
0498: resultSet[0] = "";
0499: }
0500: }
0501: } // end while (site id = remove message site id)
0502: } // end if (pos != -1)
0503: } // end while (sites to check)
0504:
0505: return resultList;
0506: }
0507:
0508: /**
0509: * Determines the number of unread messages for each site.
0510: * Filters out messages user does not have read permission for.
0511: *
0512: * @param siteList
0513: * List of sites user is a member of/has access to
0514: *
0515: * @return
0516: * List of unread message counts grouped by site
0517: */
0518: private List compileDFMessageCount(List siteList) {
0519: // retrieve what possible roles user could be in sites
0520: final List roleList = getUserRoles(siteList);
0521:
0522: // ******* Pulls total discussion forum message counts from DB *******
0523: List unreadDFMessageCounts = new ArrayList();
0524: List discussionForumMessageCounts = messageManager
0525: .findDiscussionForumMessageCountsForAllSites(siteList);
0526:
0527: // if still messages, keep processing
0528: if (!discussionForumMessageCounts.isEmpty()) {
0529: List discussionForumRemoveMessageCounts = messageManager
0530: .findDiscussionForumMessageRemoveCountsForAllSites(
0531: siteList, roleList);
0532:
0533: discussionForumRemoveMessageCounts = selectCorrectRemoveMessageCount(
0534: discussionForumRemoveMessageCounts, siteList);
0535:
0536: // if still read messages to remove, keep processing
0537: if (!discussionForumRemoveMessageCounts.isEmpty()) {
0538: discussionForumMessageCounts = filterNoAccessMessages(
0539: discussionForumMessageCounts,
0540: discussionForumRemoveMessageCounts);
0541: }
0542:
0543: // if messages left, get read messages
0544: if (!discussionForumMessageCounts.isEmpty()) {
0545: // Pulls read discussion forum message counts from DB
0546: List discussionForumReadMessageCounts = messageManager
0547: .findDiscussionForumReadMessageCountsForAllSites();
0548:
0549: // if no read messages, totals are current message counts
0550: if (discussionForumReadMessageCounts.isEmpty()) {
0551: unreadDFMessageCounts = discussionForumMessageCounts;
0552: } else {
0553: // else need to subtract read messages to get unread messages
0554: List discussionForumRemoveReadMessageCounts = messageManager
0555: .findDiscussionForumReadMessageRemoveCountsForAllSites(getUserRoles(siteList));
0556:
0557: // need to find correct read message counts for site and role
0558: discussionForumRemoveReadMessageCounts = selectCorrectRemoveMessageCount(
0559: discussionForumRemoveReadMessageCounts,
0560: siteList);
0561:
0562: // if still messages to remove, remove them
0563: if (!discussionForumRemoveReadMessageCounts
0564: .isEmpty()) {
0565: discussionForumReadMessageCounts = filterNoAccessMessages(
0566: discussionForumReadMessageCounts,
0567: discussionForumRemoveReadMessageCounts);
0568: }
0569:
0570: // if after filtering there are no read message counts, current
0571: // message counts are the result
0572: if (discussionForumReadMessageCounts.isEmpty()) {
0573: unreadDFMessageCounts = discussionForumMessageCounts;
0574: } else {
0575: // else subtract read from total to get unread counts
0576: unreadDFMessageCounts = computeUnreadDFMessages(
0577: discussionForumMessageCounts,
0578: discussionForumReadMessageCounts);
0579: } // end setting final unread message counts where subtraction needed
0580: } // end (discussionForumReadMessageCounts.isEmpty()) - after retrieving read messages from db
0581: } // end (! discussionForumMessageCounts.isEmpty()) - after fitering messsage not accessible
0582: } // end (! discussionForumMessageCounts.isEmpty()) - after initial retrieval of messages from db
0583:
0584: return unreadDFMessageCounts;
0585: }
0586:
0587: /**
0588: * Removes all sites user does not want message info about and
0589: * returns all sites left
0590: *
0591: * @param allSites
0592: * List of all sites user is a member of
0593: *
0594: * @return
0595: * List of sites user wants notification about
0596: */
0597: private List filterOutExcludedSites(List allSites) {
0598: final List excludedSites = getExcludedSitesFromTabs();
0599:
0600: if (excludedSites != null) {
0601: for (Iterator excludeIter = excludedSites.iterator(); excludeIter
0602: .hasNext();) {
0603: final String siteId = (String) excludeIter.next();
0604: final int pos = indexOf(siteId, allSites);
0605:
0606: if (pos != -1) {
0607: allSites.remove(pos);
0608: }
0609: }
0610: }
0611:
0612: return allSites;
0613: }
0614:
0615: /**
0616: * Return List to populate page if in MyWorkspace
0617: *
0618: * @return
0619: * List of DecoratedCompiledMessageStats to populate MyWorkspace page
0620: */
0621: private List getMyWorkspaceContents() {
0622: final List contents = new ArrayList();
0623: Object[] unreadDFCount;
0624: Object[] pmCounts;
0625:
0626: // Used to determine if there are any sites to view on UI
0627: sitesToView = false;
0628:
0629: // retrieve what sites is this user a member of
0630: final List siteList = filterOutExcludedSites(getSiteList());
0631:
0632: // no sites to work with, set boolean variable and return
0633: if (siteList.isEmpty()) {
0634: sitesToView = false;
0635: return contents;
0636: }
0637:
0638: // ******* Pulls unread private message counts from DB *******
0639: final List privateMessageCounts = pvtMessageManager
0640: .getPrivateMessageCountsForAllSites();
0641:
0642: // ******* Pulls unread discussion forum message counts from DB *******
0643: List unreadDFMessageCounts = compileDFMessageCount(siteList);
0644:
0645: // If both are empty, no unread messages so
0646: // create 0 count beans for both types for all sites not filtered so
0647: // displays proper messages
0648: if (privateMessageCounts.isEmpty()
0649: && unreadDFMessageCounts.isEmpty()) {
0650:
0651: for (Iterator siteIter = siteList.iterator(); siteIter
0652: .hasNext();) {
0653: String siteId = "";
0654: Site site = null;
0655:
0656: // ************ Get next site from List ************
0657: try {
0658: siteId = (String) siteIter.next();
0659: site = getSite(siteId);
0660: } catch (IdUnusedException e) {
0661: // Wierdness has happened - pulled from SiteService but now can't
0662: // find it. Log and skip
0663: LOG
0664: .error("IdUnusedException attempting to access site "
0665: + siteId);
0666: continue;
0667: }
0668:
0669: // ************ Each row on page gets info stored in DecoratedCompiledMessageStats bean ************
0670: final DecoratedCompiledMessageStats dcms = new DecoratedCompiledMessageStats();
0671:
0672: // fill site title
0673: dcms.setSiteName(site.getTitle());
0674: dcms.setSiteId(siteId);
0675:
0676: dcms.setUnreadForumsAmt(0);
0677: dcms.setUnreadPrivateAmt(0);
0678:
0679: dcms.setMcPageURL(getMCPageURL(siteId));
0680: dcms
0681: .setPrivateMessagesUrl(generatePrivateTopicMessagesUrl(siteId));
0682:
0683: try {
0684: dcms
0685: .setMessagesandForums(isMessageForumsPageInSite(getSite(siteId)));
0686: dcms
0687: .setMessages(isMessagesPageInSite(getSite(siteId)));
0688: dcms.setForums(isForumsPageInSite(getSite(siteId)));
0689: } catch (IdUnusedException e) {
0690: LOG
0691: .error("IdUnusedException while trying to determine what tools are in site "
0692: + siteId
0693: + "to set decorated synoptic messages & forums bean values.");
0694: }
0695:
0696: contents.add(dcms);
0697:
0698: sitesToView = true;
0699: }
0700:
0701: return contents;
0702: }
0703:
0704: //============= At least some unread messages so process =============
0705:
0706: // ************ loop through info to fill decorated bean ************
0707: for (Iterator si = siteList.iterator(); si.hasNext();) {
0708: boolean hasPrivate = false;
0709: boolean hasDF = false;
0710: String siteId = "";
0711: Site site = null;
0712:
0713: // ************ Get next site from List ************
0714: try {
0715: siteId = (String) si.next();
0716: site = getSite(siteId);
0717: } catch (IdUnusedException e) {
0718: // Wierdness has happened - pulled from SiteService but now can't
0719: // find it. Log and skip
0720: LOG
0721: .error("IdUnusedException attempting to access site "
0722: + siteId);
0723: continue;
0724: }
0725:
0726: // Determine if current site has unread private messages
0727: final int PMpos = indexOf(siteId,
0728: getSiteIds(privateMessageCounts));
0729:
0730: if (PMpos != -1) {
0731: pmCounts = (Object[]) privateMessageCounts.get(PMpos);
0732:
0733: // to make searching for remaining counts more efficient
0734: privateMessageCounts.remove(pmCounts);
0735: } else {
0736: pmCounts = new Object[1];
0737: pmCounts[0] = "";
0738: }
0739:
0740: // Determine if current site has unread discussion forum messages
0741: final int DFpos = indexOf(siteId,
0742: getSiteIds(unreadDFMessageCounts));
0743:
0744: if (DFpos != -1) {
0745: unreadDFCount = (Object[]) unreadDFMessageCounts
0746: .get(DFpos);
0747:
0748: // to make searching for remaining counts more efficient
0749: unreadDFMessageCounts.remove(DFpos);
0750: } else {
0751: unreadDFCount = new Object[1];
0752: unreadDFCount[0] = "";
0753: }
0754:
0755: // ************ Each row on page gets info stored in DecoratedCompiledMessageStats bean ************
0756: final DecoratedCompiledMessageStats dcms = new DecoratedCompiledMessageStats();
0757:
0758: // fill site title
0759: dcms.setSiteName(site.getTitle());
0760: dcms.setSiteId(siteId);
0761:
0762: // Put check here because if not in site, skip
0763: if (isMessageForumsPageInSite(site)
0764: || isMessagesPageInSite(site)) {
0765:
0766: // ************ checking for unread private messages for this site ************
0767: if (siteId.equals(pmCounts[0])) {
0768: if (isMessagesPageInSite(site)) {
0769: dcms
0770: .setUnreadPrivateAmt(((Integer) pmCounts[1])
0771: .intValue());
0772: hasPrivate = true;
0773: } else {
0774: // check if not enabled
0775: final Area area = areaManager
0776: .getAreaByContextIdAndTypeId(
0777: siteId,
0778: typeManager
0779: .getPrivateMessageAreaType());
0780:
0781: if (area != null) {
0782: if (area.getEnabled().booleanValue()) {
0783: dcms
0784: .setUnreadPrivateAmt(((Integer) pmCounts[1])
0785: .intValue());
0786: hasPrivate = true;
0787: } else {
0788: dcms.setUnreadPrivateAmt(0);
0789: hasPrivate = true;
0790: }
0791: } else {
0792: dcms.setUnreadPrivateAmt(0);
0793: hasPrivate = true;
0794: }
0795: }
0796: } else {
0797: dcms.setUnreadPrivateAmt(0);
0798: hasPrivate = true;
0799: }
0800: }
0801:
0802: if (isMessageForumsPageInSite(site)
0803: || isForumsPageInSite(site)) {
0804: // ************ check for unread discussion forum messages on this site ************
0805: if (siteId.equals(unreadDFCount[0])) {
0806: // counts exist, so put it in decorated bean
0807: dcms
0808: .setUnreadForumsAmt(((Integer) unreadDFCount[1])
0809: .intValue());
0810:
0811: hasDF = true;
0812: } else {
0813: // no unread counts, so set to zero
0814: dcms.setUnreadForumsAmt(0);
0815: hasDF = true;
0816: }
0817: }
0818:
0819: // ************ get the page URL for Message Center************
0820: // only if unread messages, ie, only if row will appear on page
0821: if (hasPrivate || hasDF) {
0822: dcms.setMcPageURL(getMCPageURL(siteId));
0823: dcms
0824: .setPrivateMessagesUrl(generatePrivateTopicMessagesUrl(siteId));
0825:
0826: try {
0827: dcms
0828: .setMessagesandForums(isMessageForumsPageInSite(getSite(siteId)));
0829: dcms
0830: .setMessages(isMessagesPageInSite(getSite(siteId)));
0831: dcms.setForums(isForumsPageInSite(getSite(siteId)));
0832: } catch (IdUnusedException e) {
0833: LOG
0834: .error("IdUnusedException while trying to determine what tools are in site "
0835: + siteId
0836: + "to set decorated synoptic messages & forums bean values.");
0837: }
0838:
0839: contents.add(dcms);
0840:
0841: sitesToView = true;
0842: }
0843: }
0844:
0845: return contents;
0846: }
0847:
0848: /**
0849: * Returns a list of Strings stored in index 0 of Object [] members of
0850: * list passed in.
0851: *
0852: * @param counts
0853: * List of Object [] members whose element at index 0 is a String
0854: *
0855: * @return
0856: * List of Strings extracted from list passed in
0857: */
0858: private List getSiteIds(List counts) {
0859: final List results = new ArrayList();
0860:
0861: if (!counts.isEmpty()) {
0862: for (final Iterator iter = counts.iterator(); iter
0863: .hasNext();) {
0864: final Object[] pmCount = (Object[]) iter.next();
0865:
0866: results.add(pmCount[0]);
0867: }
0868: }
0869:
0870: return results;
0871: }
0872:
0873: /**
0874: * Returns List to populate page if on Home page of a site
0875: *
0876: * @return
0877: * List of DecoratedCompiledMessageStats for a particular site
0878: */
0879: private DecoratedCompiledMessageStats getSiteContents() {
0880: final DecoratedCompiledMessageStats dcms = new DecoratedCompiledMessageStats();
0881:
0882: // Check if tool within site
0883: // if so, get stats for just this site
0884: if (isMessageForumsPageInSite() || isMessagesPageInSite()) {
0885: int unreadPrivate = 0;
0886:
0887: dcms.setSiteName(getSiteName());
0888: dcms.setSiteId(getSiteId());
0889:
0890: // Get private message area so we can get the private messasge forum so we can get the
0891: // List of topics so we can get the Received topic to finally determine number of unread messages
0892: final Area area = pvtMessageManager.getPrivateMessageArea();
0893:
0894: if (area.getEnabled().booleanValue()) {
0895: pvtMessageManager.initializePrivateMessageArea(area);
0896:
0897: unreadPrivate = pvtMessageManager
0898: .findUnreadMessageCount(typeManager
0899: .getReceivedPrivateMessageType());
0900:
0901: dcms.setUnreadPrivateAmt(unreadPrivate);
0902: dcms
0903: .setPrivateMessagesUrl(generatePrivateTopicMessagesUrl(getSiteId()));
0904: } else {
0905: dcms.setUnreadPrivateAmt(0);
0906: dcms.setPrivateMessagesUrl(getMCPageURL());
0907: }
0908: }
0909:
0910: if (isMessageForumsPageInSite() || isForumsPageInSite()) {
0911: // Number of unread forum messages is a little harder
0912: // need to loop through all topics and add them up
0913: final List topicsList = forumManager.getDiscussionForums();
0914: int unreadForum = 0;
0915:
0916: final Iterator forumIter = topicsList.iterator();
0917:
0918: while (forumIter.hasNext()) {
0919: final DiscussionForum df = (DiscussionForum) forumIter
0920: .next();
0921:
0922: final List topics = df.getTopics();
0923: final Iterator topicIter = topics.iterator();
0924:
0925: while (topicIter.hasNext()) {
0926: final DiscussionTopic topic = (DiscussionTopic) topicIter
0927: .next();
0928:
0929: if (uiPermissionsManager.isRead(topic, df)) {
0930: if (!topic.getModerated().booleanValue()
0931: || (topic.getModerated().booleanValue() && uiPermissionsManager
0932: .isModeratePostings(topic, df))) {
0933: unreadForum += messageManager
0934: .findUnreadMessageCountByTopicId(topic
0935: .getId());
0936: } else {
0937: // b/c topic is moderated and user does not have mod perm, user may only
0938: // see approved msgs or pending/denied msgs authored by user
0939: unreadForum += messageManager
0940: .findUnreadViewableMessageCountByTopicId(topic
0941: .getId());
0942: }
0943: }
0944: }
0945: }
0946:
0947: dcms.setUnreadForumsAmt(unreadForum);
0948: dcms.setMcPageURL(getMCPageURL());
0949: } else {
0950: // TODO: what to put on page? Alert? Leave Blank?
0951: }
0952:
0953: return dcms;
0954: }
0955:
0956: public boolean isAnyMFToolInSite() {
0957: if (anyMFToolInSite == null) {
0958: anyMFToolInSite = isMessageForumsPageInSite()
0959: || isMessagesPageInSite() || isForumsPageInSite();
0960: }
0961:
0962: return anyMFToolInSite;
0963: }
0964:
0965: /**
0966: * Returns List of decoratedCompiledMessageStats. Called by
0967: * jsp page and main processing of list to be displayed.
0968: * <p>
0969: * Used by both MyWorkspace and site Home page.
0970: *
0971: * @return
0972: * List of decoratedCompiledMessageStats
0973: */
0974: public List getContents() {
0975: if (isMyWorkspace()) {
0976: // Get stats for "all" sites this user is a member of
0977: // and has not turned displaying info off
0978: if (contents == null) {
0979: contents = getMyWorkspaceContents();
0980: }
0981:
0982: return contents;
0983:
0984: } else {
0985: // refactored to not use dataTable 12/12/06
0986: return new ArrayList();
0987: }
0988: }
0989:
0990: /**
0991: * Retrieve the site display title
0992: *
0993: * @return
0994: * String of the title of the site
0995: */
0996: private String getSiteName() {
0997: try {
0998: return getSite(getContext()).getTitle();
0999: } catch (IdUnusedException e) {
1000: LOG.error("IdUnusedException when trying to access site "
1001: + e.getMessage());
1002: }
1003:
1004: return null;
1005: }
1006:
1007: /**
1008: * Returns the site id String
1009: *
1010: * @return
1011: * The id for current site
1012: */
1013: private String getSiteId() {
1014: try {
1015: return getSite(getContext()).getId();
1016: } catch (IdUnusedException e) {
1017: LOG.error("IdUnusedException when trying to access site "
1018: + e.getMessage());
1019: }
1020:
1021: return null;
1022: }
1023:
1024: /**
1025: * Returns List of unread messages organized by site
1026: *
1027: * @param totalMessages
1028: * List of all messages by site
1029: *
1030: * @param readMessages
1031: * List of all read messages by site
1032: *
1033: * @param totalNoAccessMessages
1034: * List of all messages user does not have access to by site
1035: *
1036: * @pararm totalNoAccessReadMessages
1037: * List of all read messages user does not have access to by site
1038: * (ie, no read permission for that topic)
1039: *
1040: * @return
1041: * List of unread messages by site
1042: */
1043: private List computeUnreadDFMessages(List totalMessages,
1044: List readMessages) {
1045: final List unreadDFMessageCounts = new ArrayList();
1046: final List readSiteIds = getSiteIds(readMessages);
1047:
1048: // Constructs the unread message counts
1049: final Iterator dfMessagesIter = totalMessages.iterator();
1050:
1051: while (dfMessagesIter.hasNext()) {
1052: final Object[] dfMessageCountForASite = (Object[]) dfMessagesIter
1053: .next();
1054:
1055: final Object[] siteDFInfo = new Object[2];
1056:
1057: siteDFInfo[0] = (String) dfMessageCountForASite[0];
1058:
1059: int pos = indexOf((String) siteDFInfo[0], readSiteIds);
1060:
1061: // read message count for this site found, so subtract it
1062: if (pos != -1) {
1063: final Object[] dfReadMessageCountForASite = (Object[]) readMessages
1064: .get(pos);
1065:
1066: siteDFInfo[1] = new Integer(
1067: ((Integer) dfMessageCountForASite[1])
1068: .intValue()
1069: - ((Integer) dfReadMessageCountForASite[1])
1070: .intValue());
1071:
1072: // done with it, remove from list
1073: readMessages.remove(pos);
1074: readSiteIds.remove(pos);
1075: } else {
1076: // No messages read for this site so message count = unread message count
1077: siteDFInfo[1] = (Integer) dfMessageCountForASite[1];
1078: }
1079:
1080: unreadDFMessageCounts.add(siteDFInfo);
1081: }
1082:
1083: return unreadDFMessageCounts;
1084: }
1085:
1086: /**
1087: * @return TRUE if Message Forums (Message Center) exists in this site,
1088: * FALSE otherwise
1089: */
1090: public boolean isMessageForumsPageInSite() {
1091: boolean mfToolExists = false;
1092:
1093: try {
1094: final Site this Site = getSite(getContext());
1095:
1096: mfToolExists = isMessageForumsPageInSite(this Site);
1097:
1098: } catch (IdUnusedException e) {
1099: LOG
1100: .error("IdUnusedException while trying to check if site has MF tool.");
1101: }
1102:
1103: return mfToolExists;
1104: }
1105:
1106: /**
1107: * @return TRUE if Messages & Forums (Message Center) exists in this site,
1108: * FALSE otherwise
1109: */
1110: private boolean isMessageForumsPageInSite(Site this Site) {
1111: return isToolInSite(this Site, MESSAGE_CENTER_ID);
1112: }
1113:
1114: /**
1115: * @return TRUE if Messages tool exists in this site,
1116: * FALSE otherwise
1117: */
1118: public boolean isForumsPageInSite() {
1119: boolean mfToolExists = false;
1120:
1121: try {
1122: final Site this Site = getSite(getContext());
1123:
1124: mfToolExists = isForumsPageInSite(this Site);
1125:
1126: } catch (IdUnusedException e) {
1127: LOG
1128: .error("IdUnusedException while trying to check if site has MF tool.");
1129: }
1130:
1131: return mfToolExists;
1132: }
1133:
1134: /**
1135: * @return TRUE if Forums tool exists in this site,
1136: * FALSE otherwise
1137: */
1138: private boolean isForumsPageInSite(Site this Site) {
1139: return isToolInSite(this Site, FORUMS_TOOL_ID);
1140: }
1141:
1142: /**
1143: * @return TRUE if Messages tool exists in this site,
1144: * FALSE otherwise
1145: */
1146: public boolean isMessagesPageInSite() {
1147: boolean mfToolExists = false;
1148:
1149: try {
1150: final Site this Site = getSite(getContext());
1151:
1152: mfToolExists = isMessagesPageInSite(this Site);
1153:
1154: } catch (IdUnusedException e) {
1155: LOG
1156: .error("IdUnusedException while trying to check if site has MF tool.");
1157: }
1158:
1159: return mfToolExists;
1160: }
1161:
1162: /**
1163: * @return TRUE if Messages tool exists in this site,
1164: * FALSE otherwise
1165: */
1166: private boolean isMessagesPageInSite(Site this Site) {
1167: return isToolInSite(this Site, MESSAGES_TOOL_ID);
1168: }
1169:
1170: /**
1171: * Return TRUE if tool with id passed in exists in site passed in
1172: * FALSE otherwise.
1173: *
1174: * @param thisSite
1175: * Site object to check
1176: * @param toolId
1177: * Tool id to be checked
1178: *
1179: * @return
1180: */
1181: private boolean isToolInSite(Site this Site, String toolId) {
1182: Collection toolsInSite = this Site.getTools(toolId);
1183:
1184: return !toolsInSite.isEmpty();
1185:
1186: }
1187:
1188: /**
1189: * Returns the URL for the page the Message Center tool is on. Called if
1190: * tool on home page of a site.
1191: *
1192: * @return String A URL so the user can click to go to Message Center.
1193: * Needed since tool could possibly by in MyWorkspace
1194: */
1195: private String getMCPageURL() {
1196: return getMCPageURL(getContext());
1197: }
1198:
1199: /**
1200: * Returns the URL using a helper to go to MC home page directly.
1201: *
1202: * @return String A URL so the user can click to go to Message Center.
1203: * Needed since tool could possibly by in MyWorkspace
1204: */
1205: private String getMCPageURL(String siteId) {
1206: ToolConfiguration mcTool = null;
1207: String url = null;
1208:
1209: try {
1210: String toolId = "";
1211: final Site site = getSite(siteId);
1212:
1213: if (isMessageForumsPageInSite(site)) {
1214: toolId = MESSAGE_CENTER_ID;
1215: } else if (isMessagesPageInSite(site)) {
1216: toolId = MESSAGES_TOOL_ID;
1217: } else if (isForumsPageInSite(site)) {
1218: toolId = FORUMS_TOOL_ID;
1219: }
1220:
1221: mcTool = site.getToolForCommonId(toolId);
1222:
1223: if (mcTool != null) {
1224: if (toolId == MESSAGE_CENTER_ID) {
1225: url = ServerConfigurationService.getPortalUrl()
1226: + "/directtool/" + mcTool.getId()
1227: + "/sakai.messageforums.helper.helper/main";
1228: } else if (toolId == MESSAGES_TOOL_ID) {
1229: url = ServerConfigurationService.getPortalUrl()
1230: + "/directtool/"
1231: + mcTool.getId()
1232: + "/sakai.messageforums.helper.helper/privateMsg/pvtMsgHpView";
1233: } else if (toolId == FORUMS_TOOL_ID) {
1234: url = ServerConfigurationService.getPortalUrl()
1235: + "/directtool/"
1236: + mcTool.getId()
1237: + "/sakai.messageforums.helper.helper/discussionForum/forumsOnly/dfForums";
1238: }
1239: }
1240: } catch (IdUnusedException e) {
1241: // Weirdness since site ids used gotten from SiteService
1242: LOG
1243: .error("IdUnusedException while trying to check if site has MF tool.");
1244:
1245: }
1246:
1247: return url;
1248:
1249: }
1250:
1251: /**
1252: * This marks all Private messages as read for a particular site
1253: *
1254: * @param ActionEvent e
1255: */
1256: public void processReadAll(ActionEvent e) {
1257: final String typeUuid = typeManager
1258: .getReceivedPrivateMessageType();
1259:
1260: if (isMyWorkspace()) {
1261: // if within MyWorkspace, need to find the siteId
1262: final FacesContext context = FacesContext
1263: .getCurrentInstance();
1264: final Map requestParams = context.getExternalContext()
1265: .getRequestParameterMap();
1266:
1267: final String contextId = (String) requestParams
1268: .get(CONTEXTID);
1269:
1270: final List privateMessages = pvtMessageManager
1271: .getMessagesByTypeByContext(typeUuid, contextId);
1272:
1273: if (privateMessages == null) {
1274: LOG
1275: .error("No messages found while attempting to mark all as read "
1276: + "from synoptic Message Center tool.");
1277: } else {
1278: for (Iterator iter = privateMessages.iterator(); iter
1279: .hasNext();) {
1280: pvtMessageManager.markMessageAsReadForUser(
1281: (PrivateMessage) iter.next(), contextId);
1282: }
1283:
1284: // Need to null out contents variable to get new values
1285: contents = null;
1286: }
1287: } else {
1288: // Get the site id and user id and call query to
1289: // mark them all as read
1290: List privateMessages = pvtMessageManager.getMessagesByType(
1291: typeUuid, PrivateMessageManager.SORT_COLUMN_DATE,
1292: PrivateMessageManager.SORT_DESC);
1293:
1294: if (privateMessages == null) {
1295: LOG
1296: .error("No messages found while attempting to mark all as read "
1297: + "from synoptic Message Center tool.");
1298: } else {
1299: // TODO: construct query to be one roundtrip to DB
1300: for (Iterator iter = privateMessages.iterator(); iter
1301: .hasNext();) {
1302: pvtMessageManager
1303: .markMessageAsReadForUser((PrivateMessage) iter
1304: .next());
1305: }
1306: }
1307: }
1308: }
1309:
1310: /**
1311: * Returns the Site object for this id, if it exists.
1312: * If not, returns IdUnusedException
1313: *
1314: * @param siteId
1315: * The site id to check
1316: *
1317: * @return
1318: * Site object for this id
1319: */
1320: private Site getSite(String siteId) throws IdUnusedException {
1321: return SiteService.getSite(siteId);
1322: }
1323:
1324: /**
1325: * Returns current context
1326: *
1327: * @return
1328: * String The site id (context) where tool currently located
1329: */
1330: private String getContext() {
1331: return ToolManager.getCurrentPlacement().getContext();
1332: }
1333:
1334: /**
1335: *
1336: * @return
1337: * List A List of site ids that is published and the user is a member of
1338: */
1339: public List getSiteList() {
1340: List mySites = SiteService
1341: .getSites(
1342: org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
1343: null,
1344: null,
1345: null,
1346: org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC,
1347: null);
1348:
1349: Iterator lsi = mySites.iterator();
1350:
1351: if (!lsi.hasNext()) {
1352: LOG.debug("User "
1353: + SessionManager.getCurrentSessionUserId()
1354: + " does not belong to any sites.");
1355:
1356: return mySites;
1357: }
1358:
1359: final List siteList = new ArrayList();
1360:
1361: // only display sites that are published and have Message Center in them
1362: while (lsi.hasNext()) {
1363: Site site = (Site) lsi.next();
1364:
1365: // filter out unpublished or no messsage center
1366: if (site.isPublished()
1367: && (isMessageForumsPageInSite(site)
1368: || isForumsPageInSite(site) || isMessagesPageInSite(site))) {
1369: siteList.add(site.getId());
1370: }
1371: }
1372:
1373: return siteList;
1374: }
1375:
1376: /**
1377: * Construct the Url to bring up the Private Message section
1378: * for the site whose id is passed in
1379: *
1380: * @param contextId
1381: * The site id
1382: *
1383: * @return
1384: * String containing the Url to call the helper to move
1385: * to the Private Message section of a site
1386: */
1387: public String generatePrivateTopicMessagesUrl(String contextId) {
1388: Topic receivedTopic = null;
1389: String receivedTopicUuid = null;
1390:
1391: Area area = areaManager.getAreaByContextIdAndTypeId(contextId,
1392: typeManager.getPrivateMessageAreaType());
1393:
1394: if (area != null) {
1395: if (isMessagesPageInSite()
1396: || area.getEnabled().booleanValue()
1397: || pvtMessageManager.isInstructor()) {
1398: PrivateForum pf = pvtMessageManager
1399: .initializePrivateMessageArea(area);
1400: pf = pvtMessageManager.initializationHelper(pf, area);
1401: List pvtTopics = pf.getTopics();
1402: Collections.sort(pvtTopics,
1403: PrivateTopicImpl.TITLE_COMPARATOR); //changed to date comparator
1404:
1405: receivedTopic = (Topic) pvtTopics.iterator().next();
1406: receivedTopicUuid = receivedTopic.getUuid();
1407: }
1408:
1409: ToolConfiguration mcTool = null;
1410: String url = null;
1411:
1412: try {
1413: String toolId = "";
1414: final Site site = SiteService.getSite(contextId);
1415:
1416: if (isMessageForumsPageInSite(site)) {
1417: toolId = MESSAGE_CENTER_ID;
1418: } else if (isMessagesPageInSite(site)) {
1419: toolId = MESSAGES_TOOL_ID;
1420: } else if (isForumsPageInSite(site)) {
1421: toolId = FORUMS_TOOL_ID;
1422: }
1423:
1424: mcTool = site.getToolForCommonId(toolId);
1425:
1426: if (mcTool != null) {
1427: url = ServerConfigurationService.getPortalUrl()
1428: + "/directtool/"
1429: + mcTool.getId()
1430: + "/sakai.messageforums.helper.helper/privateMsg/pvtMsg?pvtMsgTopicId="
1431: + receivedTopicUuid + "&contextId="
1432: + contextId + "&selectedTopic=Received";
1433: return url;
1434: }
1435: } catch (IdUnusedException e) {
1436: LOG
1437: .error("IdUnusedException attempting to move to Private Messages for a site. Site id used is: "
1438: + contextId);
1439: }
1440: }
1441:
1442: return "";
1443: }
1444:
1445: /**
1446: * Pulls excluded site ids from Tabs preferences
1447: */
1448: private List getExcludedSitesFromTabs() {
1449: final Preferences prefs = preferencesService
1450: .getPreferences(SessionManager
1451: .getCurrentSessionUserId());
1452:
1453: final ResourceProperties props = prefs
1454: .getProperties(TABS_EXCLUDED_PREFS);
1455: final List l = props.getPropertyList(TAB_EXCLUDED_SITES);
1456:
1457: return l;
1458: }
1459:
1460: /**
1461: * Find the object in the list that has this value - return the position.
1462: *
1463: * @param value
1464: * The site id to find.
1465: * @param siteList
1466: * The list of Site objects.
1467: * @return The index position in siteList of the site with site id = value, or -1 if not found.
1468: */
1469: protected int indexOf(String value, List siteList) {
1470: if (LOG.isDebugEnabled()) {
1471: LOG.debug("indexOf(String " + value + ", List " + siteList
1472: + ")");
1473: }
1474:
1475: for (int i = 0; i < siteList.size(); i++) {
1476: final String siteId = (String) siteList.get(i);
1477:
1478: if (siteId.equals(value)) {
1479: return i;
1480: }
1481: }
1482:
1483: return -1;
1484: }
1485:
1486: }
|