0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/mailtool/tags/sakai_2-4-1/mailtool/src/java/org/sakaiproject/tool/mailtool/OptionsBean.java $
0003: * $Id: OptionsBean.java 27662 2007-03-22 19:44:57Z kimsooil@bu.edu $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2006, 2007 The Sakai Foundation.
0007: *
0008: * Licensed under the Educational Community License, Version 1.0 (the "License");
0009: * you may not use this file except in compliance with the License.
0010: * You may obtain a copy of the License at
0011: *
0012: * http://www.opensource.org/licenses/ecl1.php
0013: *
0014: * Unless required by applicable law or agreed to in writing, software
0015: * distributed under the License is distributed on an "AS IS" BASIS,
0016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: * See the License for the specific language governing permissions and
0018: * limitations under the License.
0019: *
0020: **********************************************************************************/package org.sakaiproject.tool.mailtool;
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.Set;
0028: import javax.faces.model.SelectItem;
0029: import org.sakaiproject.authz.api.AuthzGroup;
0030: import org.sakaiproject.authz.api.Role;
0031: import org.sakaiproject.authz.cover.AuthzGroupService;
0032: import org.sakaiproject.component.cover.ServerConfigurationService;
0033: import org.sakaiproject.site.api.Group;
0034: import org.sakaiproject.site.api.Site;
0035: import org.sakaiproject.site.cover.SiteService;
0036: import org.sakaiproject.tool.api.ToolSession;
0037: import org.sakaiproject.tool.cover.SessionManager;
0038: import org.sakaiproject.tool.cover.ToolManager;
0039: import org.sakaiproject.user.api.User;
0040: import org.sakaiproject.user.cover.UserDirectoryService;
0041: import org.apache.commons.logging.Log;
0042: import org.apache.commons.logging.LogFactory;
0043:
0044: /**
0045: * OptionsBean, will be used only when authorized user click "options" link
0046: *
0047: * @author kimsooil
0048: *
0049: */
0050: public class OptionsBean {
0051: private AuthzGroupService m_realmService;
0052: private AuthzGroup arole;
0053: private UserDirectoryService m_userDirectoryService;
0054: private SiteService siteService;
0055: protected Site currentSite = null;
0056:
0057: protected static final int NUMBER_ROLES = 15;
0058: private String m_currentViewChoice = "";
0059: private boolean m_buildNewView = false;
0060: protected String m_mode = "";
0061: protected String recipviewDefault = "tree";
0062: protected boolean m_selectByRole = false;
0063: protected boolean m_selectByUser = false;
0064: protected boolean m_selectByTree = false;
0065: protected boolean m_selectSideBySide = false;
0066: protected boolean m_selectByFoothill = false;
0067: protected boolean m_sendmecopy = false;
0068: protected boolean EmailArchiveInSite = false;
0069: protected boolean m_archiveMessage = false;
0070: protected String m_replyto = "";
0071: protected String m_textformat = "";
0072: private boolean showRenamingRolesClicked = false;
0073: private List renamedRoles = new ArrayList();
0074: protected String m_replytootheremail = "";
0075: protected boolean m_sendmecopyInOptions = false;
0076: private boolean groupviewClicked = false;
0077: private boolean sectionviewClicked = false;
0078: private boolean GroupAwareRoleExist = false;
0079: private boolean groupAwareRoleviewClicked = false;
0080: protected boolean m_archiveMessageInOptions = false;
0081: private boolean allGroupSelected = false;
0082: private boolean allSectionSelected = false;
0083: private boolean allGroupAwareRoleSelected = false;
0084: protected RecipientSelector m_recipientSelector = null;
0085: protected RecipientSelector m_recipientSelector1 = null;
0086: protected RecipientSelector m_recipientSelector2 = null;
0087: protected RecipientSelector m_recipientSelector3 = null;
0088: protected int num_groupawarerole = 0;
0089: private boolean already_configured = false;
0090: protected String m_sitetype = "";
0091: protected String m_siteid = "";
0092: protected String m_realmid = "";
0093: protected int num_groups = 0;
0094: protected int num_sections = 0;
0095: protected String groupAwareRoleFound = "";
0096: protected String groupAwareRoleDefault = "";
0097: protected String m_subject = "";
0098: protected String m_subjectprefix = "";
0099: private int num_role_id = 0;
0100: private int num_roles_renamed = 0;
0101: private final Log log = LogFactory.getLog(this .getClass());
0102:
0103: /**
0104: * Bean for Options page
0105: */
0106: public OptionsBean() {
0107: num_groups = 0;
0108: num_sections = 0;
0109: num_groupawarerole = 0;
0110: m_sitetype = getSiteType();
0111: m_siteid = getSiteID();
0112: m_realmid = getSiteRealmID();
0113: m_currentViewChoice = getRecipview();
0114: groupAwareRoleDefault = getGroupAwareRoleDefault();
0115: groupAwareRoleFound = getGroupAwareRole();
0116:
0117: setSelectorType();
0118: getRecipientSelectors();
0119:
0120: initializeCurrentRoles(); /* this initialization solves SAK-6810 */
0121: checkifGroupAwareRoleExist(); /* this initialization solves SAK-6810 */
0122:
0123: setMessageSubject(getSubjectPrefix().equals("") ? getSubjectPrefixFromConfig()
0124: : getSubjectPrefix());
0125: setSubjectPrefix(getSubjectPrefixFromConfig());
0126: setEmailArchiveInSite(isEmailArchiveAddedToSite());
0127:
0128: String reply = getConfigParam("replyto").trim().toLowerCase();
0129: if (reply.equals("") || reply.equals("yes")) {
0130: setReplyToSelected("yes");
0131: } else if (reply.equals("no")) {
0132: setReplyToSelected("no");
0133: } else { // reply to other email
0134: setReplyToSelected("otheremail");
0135: setReplyToOtherEmail(getConfigParam("replyto").trim()
0136: .toLowerCase());
0137: }
0138: setSendMeCopyInOptions(getConfigParam("sendmecopy").trim()
0139: .toLowerCase().equals("") != true);
0140: setSendMeCopy(getConfigParam("sendmecopy").trim().toLowerCase()
0141: .equals("yes"));
0142: setArchiveMessageInOptions(getConfigParam("emailarchive")
0143: .trim().toLowerCase().equals("") != true);
0144: setArchiveMessage(getConfigParam("emailarchive").trim()
0145: .toLowerCase().equals("yes"));
0146: String textformat = getConfigParam("messageformat").trim()
0147: .toLowerCase();
0148: if (textformat.equals("") || textformat.equals("htmltext"))
0149: setTextFormat("htmltext");
0150: else
0151: setTextFormat("plaintext");
0152:
0153: log.debug("OptionsBean Constructor");
0154: }
0155:
0156: public void setAuthzGroupService(AuthzGroupService service) {
0157: this .m_realmService = service;
0158: }
0159:
0160: public void setUserDirectoryService(UserDirectoryService service) {
0161: this .m_userDirectoryService = service;
0162: }
0163:
0164: protected String getSiteID() {
0165: return (ToolManager.getCurrentPlacement().getContext());
0166: }
0167:
0168: private String getSiteRealmID() {
0169: return ("/site/" + ToolManager.getCurrentPlacement()
0170: .getContext());
0171: }
0172:
0173: protected String getSiteType() {
0174: String type = "";
0175: try {
0176: type = SiteService.getSite(m_siteid).getType();
0177: } catch (Exception e) {
0178: log.debug("Exception: OptionsBean.getSiteType(), "
0179: + e.getMessage());
0180: }
0181: return type;
0182: }
0183:
0184: public String getGroupAwareRoleDefault() {
0185: if (getSiteType().equals("course"))
0186: return "Student";
0187: if (getSiteType().equals("project"))
0188: return "access";
0189: return "";
0190: }
0191:
0192: public String getGroupAwareRole() {
0193: String gar = ServerConfigurationService
0194: .getString("mailtool.group.aware.role");
0195: String[] gartokens = gar.split(",");
0196:
0197: try {
0198: arole = m_realmService.getAuthzGroup(m_realmid);
0199: } catch (Exception e) {
0200: log.debug("Exception: OptionsBean.getEmailRoles(), "
0201: + e.getMessage());
0202: }
0203: for (Iterator i = arole.getRoles().iterator(); i.hasNext();) {
0204: Role r = (Role) i.next();
0205: String rolename = r.getId();
0206: for (int t = 0; t < gartokens.length; t++) {
0207: if (gartokens[t].trim().equals(rolename.trim()))
0208: return rolename;
0209: }
0210: }
0211: return groupAwareRoleDefault;
0212: }
0213:
0214: public boolean isEmailArchiveAddedToSite() {
0215: boolean hasEmailArchive = false;
0216: String toolid = "sakai.mailbox";
0217: try {
0218: Site site = SiteService.getSite(m_siteid);
0219:
0220: Collection toolsInSite = site.getTools(toolid);
0221: if (!toolsInSite.isEmpty()) {
0222: hasEmailArchive = true;
0223: }
0224: } catch (Exception e) {
0225: log
0226: .debug("Exception: OptionsBean.isEmailArchiveAddedToSite(), "
0227: + e.getMessage());
0228: }
0229: return hasEmailArchive;
0230: }
0231:
0232: public void initializeCurrentRoles() {
0233: String realmid = getSiteRealmID();
0234: try {
0235: arole = m_realmService.getAuthzGroup(realmid);
0236: } catch (Exception e) {
0237: log
0238: .debug("Exception: OptionsBean.initializeCurrentRoles(), "
0239: + e.getMessage());
0240: }
0241: for (Iterator i = arole.getRoles().iterator(); i.hasNext();) {
0242: Role r = (Role) i.next();
0243: String rolename = r.getId();
0244: Configuration c = new Configuration();
0245: c.setId(num_role_id);
0246: c.setRoleId(rolename);
0247: c.setRealmid(getSiteRealmID());
0248: c.setSingular(rolename);
0249: c.setPlural(rolename + "s");
0250: c.setSingularNew(getConfigParam("role" + (num_role_id + 1)
0251: + "singular"));
0252: c.setPluralNew(getConfigParam("role" + (num_role_id + 1)
0253: + "plural"));
0254: renamedRoles.add(c);
0255: num_role_id++;
0256: num_roles_renamed++;
0257: if (isGroupAwareRoleInSettings(rolename)) {
0258: setGroupAwareRoleExist(true);
0259: }
0260: }
0261: }
0262:
0263: protected String getSiteTitle() {
0264: String title = "";
0265: try {
0266: title = SiteService.getSite(m_siteid).getTitle();
0267: } catch (Exception e) {
0268: log.debug("Exception: OptionsBean.getSiteTitle(), "
0269: + e.getMessage());
0270: }
0271: return title;
0272:
0273: }
0274:
0275: public String getSubjectPrefix() {
0276: return m_subjectprefix;
0277: }
0278:
0279: public void setSubjectPrefix(String prefix) {
0280: m_subjectprefix = prefix;
0281: }
0282:
0283: public String getSubjectPrefixFromConfig() {
0284: String prefix = this .getConfigParam("subjectprefix");
0285: if (prefix == null || prefix == "") {
0286: String titleDefault = getSiteTitle() + ": ";
0287: return titleDefault;
0288: } else
0289: return prefix;
0290: }
0291:
0292: public String getMessageSubject() {
0293: return m_subject;
0294: }
0295:
0296: public void setMessageSubject(String subject) {
0297: m_subject = subject;
0298: }
0299:
0300: protected String getConfigParam(String parameter) {
0301: String p = ToolManager.getCurrentPlacement()
0302: .getPlacementConfig().getProperty(parameter);
0303: if (p == null)
0304: return "";
0305: return p;
0306: }
0307:
0308: public RecipientSelector getRecipientSelector() {
0309: getRecipientSelectors();
0310:
0311: return m_recipientSelector;
0312: }
0313:
0314: public RecipientSelector getRecipientSelector_GroupAwareRole() {
0315: getRecipientSelectors();
0316:
0317: return m_recipientSelector1;
0318: }
0319:
0320: public RecipientSelector getRecipientSelector_Group() {
0321: getRecipientSelectors();
0322:
0323: return m_recipientSelector2;
0324: }
0325:
0326: public RecipientSelector getRecipientSelector_Section() {
0327: getRecipientSelectors();
0328:
0329: return m_recipientSelector3;
0330: }
0331:
0332: public void getRecipientSelectors() {
0333: if ((m_recipientSelector == null) || (m_buildNewView == true)) {
0334: if (m_selectByUser == true) {
0335: m_recipientSelector = new UserSelector();
0336: } else if (m_selectByTree == true) {
0337: m_recipientSelector = new TreeSelector();
0338: m_recipientSelector1 = new TreeSelector();
0339: m_recipientSelector2 = new TreeSelector(); // groups
0340: m_recipientSelector3 = new TreeSelector(); // sections
0341: } else if (m_selectSideBySide == true) {
0342: m_recipientSelector = new SideBySideSelector();
0343: } else if (m_selectByFoothill == true) {
0344: m_recipientSelector = new FoothillSelector();
0345: }
0346: if (m_selectByTree == true) {
0347: List emailGroups1 = getEmailGroupsByType("role");
0348: List emailGroups1_1 = getEmailGroupsByType("role_groupaware");
0349: List emailGroups2 = getEmailGroupsByType("group");
0350: List emailGroups3 = getEmailGroupsByType("section");
0351: m_recipientSelector.populate(emailGroups1);
0352: m_recipientSelector1.populate(emailGroups1_1);
0353: m_recipientSelector2.populate(emailGroups2);
0354: m_recipientSelector3.populate(emailGroups3);
0355: } else {
0356: List emailGroups = getEmailGroups();
0357: m_recipientSelector.populate(emailGroups);
0358: }
0359: m_buildNewView = false;
0360: }
0361: }
0362:
0363: public boolean isGroupAwareRoleInSettings(String role) {
0364: String gar = ServerConfigurationService
0365: .getString("mailtool.group.aware.role");
0366: String[] gartokens = gar.split(",");
0367:
0368: for (int i = 0; i < gartokens.length; i++) {
0369: if (gartokens[i].trim().equals(role.trim()))
0370: return true;
0371: }
0372: return false;
0373: }
0374:
0375: /**
0376: * check if group-aware role exist in the site
0377: */
0378: public void checkifGroupAwareRoleExist() {
0379: String realmid = getSiteRealmID();
0380: try {
0381: arole = m_realmService.getAuthzGroup(realmid);
0382: } catch (Exception e) {
0383: log
0384: .debug("Exception: OptionsBean.checkifGroupAwareRoleExist(), "
0385: + e.getMessage());
0386: }
0387: for (Iterator i = arole.getRoles().iterator(); i.hasNext();) {
0388: Role r = (Role) i.next();
0389: String rolename = r.getId();
0390: if (isGroupAwareRoleInSettings(rolename)) {
0391: setGroupAwareRoleExist(true);
0392: break;
0393: } else if (getGroupAwareRole().equals(rolename)) {
0394: setGroupAwareRoleExist(true);
0395: break;
0396: }
0397: }
0398: }
0399:
0400: public List /* EmailRole */getEmailRoles() {
0401: List /* EmailRole */theroles = new ArrayList();
0402: List allgroups = new ArrayList();
0403: List allsections = new ArrayList();
0404: for (int i = 1; i < (NUMBER_ROLES + 1); i++) {
0405: String rolerealm = this .getConfigParam("role" + i
0406: + "realmid");
0407: String rolename = this .getConfigParam("role" + i + "id");
0408: String rolesingular = this .getConfigParam("role" + i
0409: + "singular");
0410: String roleplural = this .getConfigParam("role" + i
0411: + "plural");
0412:
0413: if ((rolerealm != null && rolerealm != "")
0414: && (rolename != null && rolename != "")
0415: && (rolesingular != null && rolesingular != "")
0416: && (roleplural != null && roleplural != "")) {
0417: EmailRole emailrole = null;
0418: // if (isGroupAwareRoleInSettings(rolename)){
0419: if (getGroupAwareRole().equals(rolename)) {
0420: emailrole = new EmailRole(rolerealm, rolename,
0421: rolesingular, roleplural, "role_groupaware");
0422: num_groupawarerole++;
0423: } else
0424: emailrole = new EmailRole(rolerealm, rolename,
0425: rolesingular, roleplural, "role");
0426: theroles.add(emailrole);
0427: already_configured = true;
0428: }
0429: } // for
0430: if (already_configured == false) {
0431: try {
0432: arole = m_realmService.getAuthzGroup(m_realmid);
0433: } catch (Exception e) {
0434: log.debug("Exception: OptionsBean.getEmailRoles()1, "
0435: + e.getMessage());
0436: }
0437: for (Iterator i = arole.getRoles().iterator(); i.hasNext();) {
0438: Role r = (Role) i.next();
0439: String rolename = r.getId();
0440: String singular = "";
0441: String plural = "";
0442:
0443: if (rolename.equals("maintain")) {
0444: singular = rolename;
0445: plural = rolename + "ers";
0446: } else if (rolename.equals("access")) {
0447: singular = rolename;
0448: plural = rolename + " users";
0449: } else {
0450: singular = rolename;
0451: plural = rolename + "s";
0452: }
0453: EmailRole emailrole = null;
0454: // if (isGroupAwareRoleInSettings(rolename)){
0455: if (getGroupAwareRole().equals(rolename)) {
0456: emailrole = new EmailRole("/site/" + m_siteid,
0457: rolename, singular, plural,
0458: "role_groupaware");
0459: num_groupawarerole++;
0460: } else
0461: emailrole = new EmailRole("/site/" + m_siteid,
0462: rolename, singular, plural, "role");
0463: theroles.add(emailrole);
0464: }
0465: }
0466: // adding groups as roles
0467: try {
0468: currentSite = siteService.getSite(m_siteid);
0469: } catch (Exception e) {
0470: log.debug("Exception: OptionsBean.getEmailRoles()2, "
0471: + e.getMessage());
0472: }
0473: Collection groups = currentSite.getGroups();
0474: for (Iterator groupIterator = groups.iterator(); groupIterator
0475: .hasNext();) {
0476: Group currentGroup = (Group) groupIterator.next();
0477: String groupname = currentGroup.getTitle();
0478: String groupid = currentGroup.getProviderGroupId(); //???????????????????????????????
0479: //EmailRole emailrole2=new EmailRole("/site/"+siteid, groupname, groupname, groupname);
0480: EmailRole emailrole2 = null;
0481: if (currentGroup.getProperties().getProperty(
0482: "sections_category") != null) {
0483: emailrole2 = new EmailRole(groupid, groupname,
0484: groupname, groupname, "section");
0485: allsections.add(emailrole2);
0486: num_sections++;
0487: } else {
0488: emailrole2 = new EmailRole(groupid, groupname,
0489: groupname, groupname, "group");
0490: allgroups.add(emailrole2);
0491: num_groups++;
0492: }
0493: }
0494: theroles.addAll(allgroups); // for sorted list in side-by-side view & scrolling list view
0495: theroles.addAll(allsections); // for sorted list ...
0496: return theroles;
0497: }
0498:
0499: //Build all groups that will be used for this
0500: public List /* EmailGroup */getEmailGroups() {
0501: List /* EmailGroup */thegroups = new ArrayList();
0502:
0503: List emailroles = this .getEmailRoles();
0504:
0505: for (Iterator i = emailroles.iterator(); i.hasNext();) {
0506: EmailRole emailrole = (EmailRole) i.next();
0507:
0508: if (emailrole.roletype.equals("role")) {
0509: String realmid = emailrole.getRealmid();
0510:
0511: AuthzGroup therealm = null;
0512: try {
0513: therealm = m_realmService.getAuthzGroup(realmid);
0514: } catch (Exception e) {
0515: log
0516: .debug("Exception: OptionsBean.getEmailGroups() #1, "
0517: + e.getMessage());
0518: }
0519: Set users = therealm.getUsersHasRole(emailrole
0520: .getRoleid());
0521: List /* EmailUser */mailusers = new ArrayList();
0522: for (Iterator j = users.iterator(); j.hasNext();) {
0523: String userid = (String) j.next();
0524: try {
0525: User theuser = m_userDirectoryService
0526: .getUser(userid);
0527: String firstname_for_display = "";
0528: String lastname_for_display = "";
0529: if (theuser.getFirstName().trim().equals("")) {
0530: if (theuser.getEmail().trim().equals("")
0531: && theuser.getLastName().trim()
0532: .equals(""))
0533: firstname_for_display = theuser
0534: .getDisplayId(); // fix for SAK-7539
0535: else
0536: firstname_for_display = theuser
0537: .getEmail(); // fix for SAK-7356
0538: } else {
0539: firstname_for_display = theuser
0540: .getFirstName();
0541: }
0542:
0543: lastname_for_display = theuser.getLastName();
0544:
0545: EmailUser emailuser = new EmailUser(theuser
0546: .getId(), firstname_for_display,
0547: lastname_for_display, theuser
0548: .getEmail());
0549:
0550: mailusers.add(emailuser);
0551: } catch (Exception e) {
0552: log
0553: .debug("Exception: OptionsBean.getEmailGroups() #2, "
0554: + e.getMessage());
0555: }
0556: }
0557: Collections.sort(mailusers);
0558: EmailGroup thegroup = new EmailGroup(emailrole,
0559: mailusers);
0560: thegroups.add(thegroup);
0561: }
0562:
0563: else if (emailrole.roletype.equals("group")) {
0564: String sid = getSiteID();
0565: Site currentSite = null;
0566: try {
0567: currentSite = siteService.getSite(sid);
0568: } catch (Exception e) {
0569: log
0570: .debug("Exception: OptionsBean.getEmailGroups() #3, "
0571: + e.getMessage());
0572: }
0573: Collection groups = currentSite.getGroups();
0574: Group agroup = null;
0575: for (Iterator groupIterator = groups.iterator(); groupIterator
0576: .hasNext();) {
0577: agroup = (Group) groupIterator.next();
0578: String groupname = agroup.getTitle();
0579: if (emailrole.getRoleid().equals(groupname))
0580: break;
0581: }
0582: Set users2 = agroup.getUsers(); ////////////////////////// something like that ---- Need to be tested !!!!!!
0583: List mailusers2 = new ArrayList();
0584: for (Iterator k = users2.iterator(); k.hasNext();) {
0585: String userid2 = (String) k.next();
0586: try {
0587: User theuser2 = m_userDirectoryService
0588: .getUser(userid2);
0589: String firstname_for_display = "";
0590: String lastname_for_display = "";
0591: if (theuser2.getFirstName().trim().equals("")) {
0592: if (theuser2.getEmail().trim().equals("")
0593: && theuser2.getLastName().trim()
0594: .equals(""))
0595: firstname_for_display = theuser2
0596: .getDisplayId(); // fix for SAK-7539
0597: else
0598: firstname_for_display = theuser2
0599: .getEmail(); // fix for SAK-7356
0600: } else {
0601: firstname_for_display = theuser2
0602: .getFirstName();
0603: }
0604:
0605: lastname_for_display = theuser2.getLastName();
0606:
0607: EmailUser emailuser2 = new EmailUser(theuser2
0608: .getId(), firstname_for_display,
0609: lastname_for_display, theuser2
0610: .getEmail());
0611:
0612: mailusers2.add(emailuser2);
0613: } catch (Exception e) {
0614: log
0615: .debug("Exception: OptionsBean.getEmailGroups() #3-1, "
0616: + e.getMessage());
0617: }
0618: }
0619: Collections.sort(mailusers2);
0620: EmailGroup thegroup2 = new EmailGroup(emailrole,
0621: mailusers2);
0622: thegroups.add(thegroup2);
0623: } // else
0624: else if (emailrole.roletype.equals("section")) {
0625: String sid = getSiteID();
0626: Site currentSite = null;
0627: try {
0628: currentSite = siteService.getSite(sid);
0629: } catch (Exception e) {
0630: log
0631: .debug("Exception: Mailtool.getEmailGroups() #4, "
0632: + e.getMessage());
0633: }
0634: Collection groups = currentSite.getGroups();
0635: Group agroup = null;
0636: for (Iterator groupIterator = groups.iterator(); groupIterator
0637: .hasNext();) {
0638: agroup = (Group) groupIterator.next();
0639: String groupname = agroup.getTitle();
0640: if (emailrole.getRoleid().equals(groupname))
0641: break;
0642: }
0643: Set users2 = agroup.getUsers(); ////////////////////////// something like that ---- Need to be tested !!!!!!
0644: List mailusers2 = new ArrayList();
0645: for (Iterator k = users2.iterator(); k.hasNext();) {
0646: String userid2 = (String) k.next();
0647: try {
0648: User theuser2 = m_userDirectoryService
0649: .getUser(userid2);
0650: String firstname_for_display = "";
0651: String lastname_for_display = "";
0652: if (theuser2.getFirstName().trim().equals("")) {
0653: if (theuser2.getEmail().trim().equals("")
0654: && theuser2.getLastName().trim()
0655: .equals(""))
0656: firstname_for_display = theuser2
0657: .getDisplayId(); // fix for SAK-7539
0658: else
0659: firstname_for_display = theuser2
0660: .getEmail(); // fix for SAK-7356
0661: } else {
0662: firstname_for_display = theuser2
0663: .getFirstName();
0664: }
0665:
0666: lastname_for_display = theuser2.getLastName();
0667:
0668: EmailUser emailuser2 = new EmailUser(theuser2
0669: .getId(), firstname_for_display,
0670: lastname_for_display, theuser2
0671: .getEmail());
0672:
0673: mailusers2.add(emailuser2);
0674: } catch (Exception e) {
0675: log
0676: .debug("Exception: OptionsBean.getEmailGroups() #4-1, "
0677: + e.getMessage());
0678: }
0679: }
0680: Collections.sort(mailusers2);
0681: EmailGroup thegroup2 = new EmailGroup(emailrole,
0682: mailusers2);
0683: thegroups.add(thegroup2);
0684: } // else
0685: }
0686: return thegroups;
0687: }
0688:
0689: public List /* EmailGroup */getEmailGroupsByType(
0690: String roletypefilter) {
0691: List /* EmailGroup */thegroups = new ArrayList();
0692: List emailroles = this .getEmailRoles();
0693: for (Iterator i = emailroles.iterator(); i.hasNext();) {
0694: EmailRole emailrole = (EmailRole) i.next();
0695: if (emailrole.roletype.equals("role")
0696: && roletypefilter.equals("role")) {
0697: String realmid = emailrole.getRealmid();
0698: AuthzGroup therealm = null;
0699: try {
0700: therealm = m_realmService.getAuthzGroup(realmid);
0701: } catch (Exception e) {
0702: log
0703: .debug("Exception: OptionsBean.getEmailGroupsByType() #1, "
0704: + e.getMessage());
0705: }
0706: Set users = therealm.getUsersHasRole(emailrole
0707: .getRoleid());
0708: List /* EmailUser */mailusers = new ArrayList();
0709: for (Iterator j = users.iterator(); j.hasNext();) {
0710: String userid = (String) j.next();
0711: try {
0712: User theuser = m_userDirectoryService
0713: .getUser(userid);
0714: String firstname_for_display = "";
0715: String lastname_for_display = "";
0716: if (theuser.getFirstName().trim().equals("")) {
0717: if (theuser.getEmail().trim().equals("")
0718: && theuser.getLastName().trim()
0719: .equals(""))
0720: firstname_for_display = theuser
0721: .getDisplayId(); // fix for SAK-7539
0722: else
0723: firstname_for_display = theuser
0724: .getEmail(); // fix for SAK-7356
0725: } else {
0726: firstname_for_display = theuser
0727: .getFirstName();
0728: }
0729: lastname_for_display = theuser.getLastName();
0730: EmailUser emailuser = new EmailUser(theuser
0731: .getId(), firstname_for_display,
0732: lastname_for_display, theuser
0733: .getEmail());
0734: mailusers.add(emailuser);
0735: } catch (Exception e) {
0736: log
0737: .debug("Exception: OptionsBean.getEmailGroupsByType() #2, "
0738: + e.getMessage());
0739: }
0740: }
0741: Collections.sort(mailusers);
0742: EmailGroup thegroup = new EmailGroup(emailrole,
0743: mailusers);
0744: thegroups.add(thegroup);
0745: }
0746:
0747: else if (emailrole.roletype.equals("group")
0748: && roletypefilter.equals("group")) {
0749: String sid = getSiteID();
0750: Site currentSite = null;
0751: try {
0752: currentSite = siteService.getSite(sid);
0753: } catch (Exception e) {
0754: log
0755: .debug("Exception: Mailtool.getEmailGroupsByType() #3, "
0756: + e.getMessage());
0757: }
0758: Collection groups = currentSite.getGroups();
0759: Group agroup = null;
0760: for (Iterator groupIterator = groups.iterator(); groupIterator
0761: .hasNext();) {
0762: agroup = (Group) groupIterator.next();
0763: String groupname = agroup.getTitle();
0764: if (emailrole.getRoleid().equals(groupname))
0765: break;
0766: }
0767: Set users2 = agroup
0768: .getUsersHasRole(groupAwareRoleFound);
0769: List mailusers2 = new ArrayList();
0770: for (Iterator k = users2.iterator(); k.hasNext();) {
0771: String userid2 = (String) k.next();
0772: try {
0773: User theuser2 = m_userDirectoryService
0774: .getUser(userid2);
0775: String firstname_for_display = "";
0776: String lastname_for_display = "";
0777: if (theuser2.getFirstName().trim().equals("")) {
0778: if (theuser2.getEmail().trim().equals("")
0779: && theuser2.getLastName().trim()
0780: .equals(""))
0781: firstname_for_display = theuser2
0782: .getDisplayId(); // fix for SAK-7539
0783: else
0784: firstname_for_display = theuser2
0785: .getEmail(); // fix for SAK-7356
0786: } else {
0787: firstname_for_display = theuser2
0788: .getFirstName();
0789: }
0790:
0791: lastname_for_display = theuser2.getLastName();
0792:
0793: EmailUser emailuser2 = new EmailUser(theuser2
0794: .getId(), firstname_for_display,
0795: lastname_for_display, theuser2
0796: .getEmail());
0797:
0798: mailusers2.add(emailuser2);
0799: } catch (Exception e) {
0800: log
0801: .debug("Exception: OptionsBean.getEmailGroupsByType() #3-1, "
0802: + e.getMessage());
0803: }
0804: }
0805: Collections.sort(mailusers2);
0806: EmailGroup thegroup2 = new EmailGroup(emailrole,
0807: mailusers2);
0808: thegroups.add(thegroup2);
0809: } // else
0810: else if (emailrole.roletype.equals("section")
0811: && roletypefilter.equals("section")) {
0812: String sid = getSiteID();
0813: Site currentSite = null;
0814: try {
0815: currentSite = siteService.getSite(sid);
0816: } catch (Exception e) {
0817: log
0818: .debug("Exception: OptionsBean.getEmailGroupsByType() #4, "
0819: + e.getMessage());
0820: }
0821: Collection groups = currentSite.getGroups();
0822: Group agroup = null;
0823: for (Iterator groupIterator = groups.iterator(); groupIterator
0824: .hasNext();) {
0825: agroup = (Group) groupIterator.next();
0826: String groupname = agroup.getTitle();
0827: if (emailrole.getRoleid().equals(groupname))
0828: break;
0829: }
0830: Set users2 = agroup
0831: .getUsersHasRole(groupAwareRoleFound);
0832: List mailusers2 = new ArrayList();
0833: for (Iterator k = users2.iterator(); k.hasNext();) {
0834: String userid2 = (String) k.next();
0835: try {
0836: User theuser2 = m_userDirectoryService
0837: .getUser(userid2);
0838: String firstname_for_display = "";
0839: String lastname_for_display = "";
0840: if (theuser2.getFirstName().trim().equals("")) {
0841: if (theuser2.getEmail().trim().equals("")
0842: && theuser2.getLastName().trim()
0843: .equals(""))
0844: firstname_for_display = theuser2
0845: .getDisplayId(); // fix for SAK-7539
0846: else
0847: firstname_for_display = theuser2
0848: .getEmail(); // fix for SAK-7356
0849: } else {
0850: firstname_for_display = theuser2
0851: .getFirstName();
0852: }
0853: lastname_for_display = theuser2.getLastName();
0854: EmailUser emailuser2 = new EmailUser(theuser2
0855: .getId(), firstname_for_display,
0856: lastname_for_display, theuser2
0857: .getEmail());
0858: mailusers2.add(emailuser2);
0859: } catch (Exception e) {
0860: log
0861: .debug("Exception: OptionsBean.getEmailGroupsByType() #4-1, "
0862: + e.getMessage());
0863: }
0864: }
0865: Collections.sort(mailusers2);
0866: EmailGroup thegroup2 = new EmailGroup(emailrole,
0867: mailusers2);
0868: thegroups.add(thegroup2);
0869: } // else
0870: else if (emailrole.roletype.equals("role_groupaware")
0871: && roletypefilter.equals("role_groupaware")) {
0872: String realmid = emailrole.getRealmid();
0873:
0874: AuthzGroup therealm = null;
0875: try {
0876: therealm = m_realmService.getAuthzGroup(realmid);
0877: } catch (Exception e) {
0878: log
0879: .debug("Exception: OptionsBean.getEmailGroupsByType() #5, "
0880: + e.getMessage());
0881: }
0882: Set users = therealm.getUsersHasRole(emailrole
0883: .getRoleid());
0884: List /* EmailUser */mailusers = new ArrayList();
0885: for (Iterator j = users.iterator(); j.hasNext();) {
0886: String userid = (String) j.next();
0887: try {
0888: User theuser = m_userDirectoryService
0889: .getUser(userid);
0890: String firstname_for_display = "";
0891: String lastname_for_display = "";
0892: if (theuser.getFirstName().trim().equals("")) {
0893: if (theuser.getEmail().trim().equals("")
0894: && theuser.getLastName().trim()
0895: .equals(""))
0896: firstname_for_display = theuser
0897: .getDisplayId(); // fix for SAK-7539
0898: else
0899: firstname_for_display = theuser
0900: .getEmail(); // fix for SAK-7356
0901: } else {
0902: firstname_for_display = theuser
0903: .getFirstName();
0904: }
0905: lastname_for_display = theuser.getLastName();
0906: EmailUser emailuser = new EmailUser(theuser
0907: .getId(), firstname_for_display,
0908: lastname_for_display, theuser
0909: .getEmail());
0910: mailusers.add(emailuser);
0911: } catch (Exception e) {
0912: log
0913: .debug("Exception: OptionsBean.getEmailGroupsByType() #5-1, "
0914: + e.getMessage());
0915: }
0916: }
0917: Collections.sort(mailusers);
0918: EmailGroup thegroup = new EmailGroup(emailrole,
0919: mailusers);
0920: thegroups.add(thegroup);
0921: } // else
0922: }
0923: return thegroups;
0924: }
0925:
0926: public String processGoToComposeByCancel() {
0927: return "compose";
0928: }
0929:
0930: public String getViewChoice() {
0931: if (m_currentViewChoice.equals(""))
0932: return this .getRecipview();
0933: else
0934: return m_currentViewChoice;
0935: }
0936:
0937: public void setViewChoice(String view) {
0938: if (m_currentViewChoice.equals(view)) {
0939: m_buildNewView = false;
0940: } else {
0941: m_buildNewView = true;
0942: }
0943: m_currentViewChoice = view;
0944:
0945: setSelectorType();
0946: getRecipientSelectors();
0947: }
0948:
0949: public String getRecipview() {
0950: String recipview = this .getConfigParam("recipview");
0951: if (recipview == null || recipview.trim().equals(""))
0952: return recipviewDefault;
0953: else
0954: return recipview;
0955: }
0956:
0957: public List /* SelectItemGroup */getViewChoiceDropdown() {
0958: List selectItems = new ArrayList();
0959:
0960: SelectItem item = new SelectItem();
0961: item.setLabel("Users"); // User
0962: item.setValue("user");
0963: selectItems.add(item);
0964: item = new SelectItem();
0965: item.setLabel("Users by Role"); // Tree
0966: item.setValue("tree");
0967: selectItems.add(item);
0968: item = new SelectItem();
0969: item.setLabel("Side-by-Side"); // Side By Side
0970: item.setValue("sidebyside");
0971: selectItems.add(item);
0972: item = new SelectItem();
0973: item.setLabel("Scrolling List"); // Foothill
0974: item.setValue("foothill");
0975: selectItems.add(item);
0976:
0977: return selectItems;
0978: }
0979:
0980: protected void setSelectorType() {
0981: String type = m_currentViewChoice;
0982:
0983: m_selectByRole = false;
0984: m_selectByUser = false;
0985: m_selectByTree = false;
0986: m_selectSideBySide = false;
0987: m_selectByFoothill = false;
0988:
0989: if (type.equals("role")) {
0990: m_selectByRole = true;
0991: } else if (type.equals("user")) {
0992: m_selectByUser = true;
0993: } else if (type.equals("tree")) {
0994: m_selectByTree = true;
0995: } else if (type.equals("sidebyside")) {
0996: m_selectSideBySide = true;
0997: } else if (type.equals("foothill")) {
0998: m_selectByFoothill = true;
0999: } else /* default to role */
1000: {
1001: m_selectByRole = true;
1002: }
1003: }
1004:
1005: public boolean isShowRenamingRoles() {
1006: String rename = ServerConfigurationService
1007: .getString("mailtool.show.renaming.roles");
1008: if (rename != "" && rename != null) {
1009: return (rename.trim().toLowerCase().equals("yes")
1010: || rename.trim().toLowerCase().equals("true") ? true
1011: : false);
1012: }
1013: return false;
1014: }
1015:
1016: protected void setConfigParam(String parameter, String newvalue) {
1017: ToolManager.getCurrentPlacement().getPlacementConfig()
1018: .setProperty(parameter, newvalue);
1019: }
1020:
1021: /**
1022: * Update/save any change(s)
1023: * @return
1024: * return "compse" for immediately navigating to compose page
1025: */
1026: public String processUpdateOptions() {
1027: if (isShowRenamingRoles()) {
1028: int i = 1;
1029: Configuration c = null;
1030: Iterator iter = renamedRoles.iterator();
1031:
1032: while (iter.hasNext()) {
1033: c = (Configuration) iter.next();
1034: if (c.getSingularNew().trim().equals("") != true
1035: && c.getSingularNew() != null)
1036: setConfigParam("role" + i + "singular", c
1037: .getSingularNew());
1038: if (c.getPluralNew().trim().equals("") != true
1039: && c.getPluralNew() != null)
1040: setConfigParam("role" + i + "plural", c
1041: .getPluralNew());
1042: i++;
1043: }
1044: }
1045: setConfigParam("recipview", getViewChoice());
1046: setConfigParam("sendmecopy", isSendMeCopy() ? "yes" : "no");
1047: setConfigParam("emailarchive", isArchiveMessage() ? "yes"
1048: : "no");
1049: String reply = getReplyToSelected().trim().toLowerCase();
1050: if (reply.equals("yes")) {
1051: setConfigParam("replyto", "yes");
1052: } else if (reply.equals("no")) {
1053: setConfigParam("replyto", "no");
1054: } else if (reply.equals("otheremail")) {
1055: setConfigParam("replyto", getReplyToOtherEmail().trim());
1056: }
1057: if (getTextFormat().trim().toLowerCase().equals("htmltext")) {
1058: setConfigParam("messageformat", "htmltext");
1059: } else {
1060: setConfigParam("messageformat", "plaintext");
1061: }
1062: ToolManager.getCurrentPlacement().save();
1063: // reset Mailtool (with updated options)
1064: ToolSession ts = SessionManager.getCurrentSession()
1065: .getToolSession(
1066: ToolManager.getCurrentPlacement().getId());
1067: ts.clearAttributes();
1068: return "compose"; // go to Compose
1069: }
1070:
1071: public boolean isShowRenamingRolesClicked() {
1072: return showRenamingRolesClicked;
1073: }
1074:
1075: public void setShowRenamingRolesClicked(
1076: boolean showRenamingRolesClicked) {
1077: this .showRenamingRolesClicked = showRenamingRolesClicked;
1078: }
1079:
1080: public void toggle_showRemainingRoleClicked() {
1081: showRenamingRolesClicked = showRenamingRolesClicked ? false
1082: : true;
1083: }
1084:
1085: public void toggle_groupviewClicked() {
1086: groupviewClicked = groupviewClicked ? false : true;
1087: sectionviewClicked = false; // exclusive rendering
1088: groupAwareRoleviewClicked = false;
1089: }
1090:
1091: public void toggle_sectionviewClicked() {
1092: sectionviewClicked = sectionviewClicked ? false : true;
1093: groupviewClicked = false; // exclusive rendering
1094: groupAwareRoleviewClicked = false;
1095: }
1096:
1097: public void toggle_groupAwareRoleviewClicked() {
1098: groupAwareRoleviewClicked = groupAwareRoleviewClicked ? false
1099: : true;
1100: sectionviewClicked = false; // exclusive rendering
1101: groupviewClicked = false; // exclusive rendering
1102: }
1103:
1104: public List getRenamedRoles() {
1105:
1106: return renamedRoles;
1107: }
1108:
1109: public boolean isSelectByRole() {
1110: // setSelectorType();
1111: return m_selectByRole;
1112: }
1113:
1114: public boolean isSelectByUser() {
1115: // setSelectorType();
1116: return m_selectByUser;
1117: }
1118:
1119: public boolean isSelectByTree() {
1120: // setSelectorType();
1121: return m_selectByTree;
1122: }
1123:
1124: public boolean isSelectSideBySide() {
1125: // setSelectorType();
1126: return m_selectSideBySide;
1127: }
1128:
1129: public boolean isSelectByFoothill() {
1130: // setSelectorType();
1131: return m_selectByFoothill;
1132: }
1133:
1134: public boolean isSendMeCopy() {
1135: return m_sendmecopy;
1136: }
1137:
1138: public void setSendMeCopy(boolean value) {
1139: m_sendmecopy = value;
1140: }
1141:
1142: public void setSendMeCopyInOptions(boolean value) {
1143: m_sendmecopyInOptions = value;
1144: }
1145:
1146: public boolean isEmailArchiveInSite() {
1147: return EmailArchiveInSite;
1148: }
1149:
1150: public void setEmailArchiveInSite(boolean emailArchiveInSite) {
1151: EmailArchiveInSite = emailArchiveInSite;
1152: }
1153:
1154: public boolean isArchiveMessage() {
1155: return m_archiveMessage;
1156: }
1157:
1158: public void setArchiveMessage(boolean value) {
1159: m_archiveMessage = value;
1160: }
1161:
1162: public void setArchiveMessageInOptions(boolean value) {
1163: m_archiveMessageInOptions = value;
1164: }
1165:
1166: public String getReplyToSelected() {
1167: return m_replyto;
1168: }
1169:
1170: public void setReplyToSelected(String r) {
1171: this .m_replyto = r;
1172: }
1173:
1174: public String getTextFormat() {
1175: return m_textformat;
1176: }
1177:
1178: public void setTextFormat(String format) {
1179: m_textformat = format;
1180: }
1181:
1182: public String getReplyToOtherEmail() {
1183: return m_replytootheremail;
1184: }
1185:
1186: public void setReplyToOtherEmail(String email) {
1187: m_replytootheremail = email;
1188: }
1189:
1190: public boolean isGroupAwareRoleExist() {
1191: return GroupAwareRoleExist;
1192: }
1193:
1194: public void setGroupAwareRoleExist(boolean groupAwareRoleExist) {
1195: GroupAwareRoleExist = groupAwareRoleExist;
1196: }
1197:
1198: public boolean isGroupAwareRoleviewClicked() {
1199: return groupAwareRoleviewClicked;
1200: }
1201:
1202: public void setGroupAwareRoleviewClicked(
1203: boolean groupAwareRoleviewClicked) {
1204: this .groupAwareRoleviewClicked = groupAwareRoleviewClicked;
1205: }
1206:
1207: public boolean isGroupviewClicked() {
1208: return groupviewClicked;
1209: }
1210:
1211: public void setGroupviewClicked(boolean groupviewClicked) {
1212: this .groupviewClicked = groupviewClicked;
1213: }
1214:
1215: public boolean isSectionviewClicked() {
1216: return sectionviewClicked;
1217: }
1218:
1219: public void setSectionviewClicked(boolean sectionviewClicked) {
1220: this .sectionviewClicked = sectionviewClicked;
1221: }
1222:
1223: public int getNum_sections() {
1224: return num_sections;
1225: }
1226:
1227: public void setNum_sections(int num_sections) {
1228: this .num_sections = num_sections;
1229: }
1230:
1231: public int getNum_groups() {
1232: return num_groups;
1233: }
1234:
1235: public void setNum_groups(int num_groups) {
1236: this .num_groups = num_groups;
1237: }
1238:
1239: public boolean isAllGroupAwareRoleSelected() {
1240: return allGroupAwareRoleSelected;
1241: }
1242:
1243: public void setAllGroupAwareRoleSelected(
1244: boolean allGroupAwareRoleSelected) {
1245: this .allGroupAwareRoleSelected = allGroupAwareRoleSelected;
1246: }
1247:
1248: public boolean isAllGroupSelected() {
1249: return allGroupSelected;
1250: }
1251:
1252: public void setAllGroupSelected(boolean allGroupSelected) {
1253: this .allGroupSelected = allGroupSelected;
1254: }
1255:
1256: public boolean isAllSectionSelected() {
1257: return allSectionSelected;
1258: }
1259:
1260: public void setAllSectionSelected(boolean allSectionSelected) {
1261: this.allSectionSelected = allSectionSelected;
1262: }
1263: }
|