Source Code Cross Referenced for AudienceTool.java in  » ERP-CRM-Financial » sakai » org » theospi » portfolio » security » tool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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


0001:        /**********************************************************************************
0002:         * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/tool-lib/src/java/org/theospi/portfolio/security/tool/AudienceTool.java $
0003:         * $Id:AudienceTool.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 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.theospi.portfolio.security.tool;
0021:
0022:        import org.sakaiproject.authz.api.Member;
0023:        import org.sakaiproject.authz.api.Role;
0024:        import org.sakaiproject.component.cover.ServerConfigurationService;
0025:        import org.sakaiproject.email.cover.EmailService;
0026:        import org.sakaiproject.exception.IdUnusedException;
0027:        import org.sakaiproject.metaobj.shared.mgt.AgentManager;
0028:        import org.sakaiproject.metaobj.shared.mgt.IdManager;
0029:        import org.sakaiproject.metaobj.shared.model.Agent;
0030:        import org.sakaiproject.metaobj.shared.model.Id;
0031:        import org.sakaiproject.site.api.Group;
0032:        import org.sakaiproject.site.api.Site;
0033:        import org.sakaiproject.site.api.SiteService;
0034:        import org.sakaiproject.tool.api.Placement;
0035:        import org.sakaiproject.tool.api.ToolManager;
0036:        import org.sakaiproject.tool.api.ToolSession;
0037:        import org.sakaiproject.tool.cover.SessionManager;
0038:        import org.sakaiproject.user.cover.UserDirectoryService;
0039:        import org.theospi.portfolio.security.AudienceSelectionHelper;
0040:        import org.theospi.portfolio.security.Authorization;
0041:        import org.theospi.portfolio.security.AuthorizationFacade;
0042:        import org.theospi.portfolio.shared.model.AgentImplOsp;
0043:        import org.theospi.portfolio.shared.model.OspException;
0044:        import org.theospi.portfolio.shared.tool.HelperToolBase;
0045:        import org.theospi.portfolio.shared.tool.PagingList;
0046:
0047:        import javax.faces.context.FacesContext;
0048:        import javax.faces.model.SelectItem;
0049:        import java.util.*;
0050:        import java.util.regex.Pattern;
0051:
0052:        /**
0053:         * Created by IntelliJ IDEA.
0054:         * User: John Ellis
0055:         * Date: Nov 16, 2005
0056:         * Time: 2:54:19 PM
0057:         * To change this template use File | Settings | File Templates.
0058:         */
0059:        public class AudienceTool extends HelperToolBase {
0060:
0061:            private AuthorizationFacade authzManager;
0062:            private IdManager idManager;
0063:            private SiteService siteService;
0064:            private ToolManager toolManager;
0065:            private AgentManager agentManager;
0066:            private int maxRoleMemberList;
0067:
0068:            private List selectedMembers = null;
0069:            private List originalMembers = null;
0070:            private List selectedRoles = null;
0071:            private String searchUsers;
0072:            private String searchEmails;
0073:            private Site site;
0074:
0075:            /**
0076:             * ***********************************
0077:             */
0078:            private String[] availableRoleMember;
0079:            private List availableRoleMemberList;
0080:
0081:            private String[] selectedRoleMember;
0082:            private List selectedRoleMemberList;
0083:
0084:            /**
0085:             * **********************************
0086:             */
0087:
0088:            private List selectedRolesFilter;
0089:            private List selectedGroupsFilter;
0090:            private PagingList browseUsers = null;
0091:            private String stepString = "2";
0092:            private String function;
0093:            private Id qualifier;
0094:
0095:            /** This accepts email addresses */
0096:            private static final Pattern emailPattern = Pattern.compile("^"
0097:                    + "(?>" + "\\.?[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+" + ")+"
0098:                    + "@" + "(" + "(" + "(?!-)[a-zA-Z\\d\\-]+(?<!-)\\." + ")+"
0099:                    + "[a-zA-Z]{2,}" + "|" + "(?!\\.)" + "(" + "\\.?" + "("
0100:                    + "25[0-5]" + "|" + "2[0-4]\\d" + "|" + "[01]?\\d?\\d"
0101:                    + ")" + "){4}" + ")" + "$");
0102:
0103:            private List roleMemberList = null;
0104:            private List groupMemberList = null;
0105:            private String LIST_SEPERATOR = "__________________";
0106:            private boolean publicAudience = false;
0107:
0108:            /*************************************************************************/
0109:
0110:            public boolean isMaxList() {
0111:
0112:                if (getMembersList().size() > getMaxRoleMemberList()) {
0113:                    return true;
0114:                } else {
0115:                    return false;
0116:                }
0117:            }
0118:
0119:            public int getMaxRoleMemberList() {
0120:                return maxRoleMemberList;
0121:            }
0122:
0123:            public void setMaxRoleMemberList(int maxRoleMemberList) {
0124:                this .maxRoleMemberList = maxRoleMemberList;
0125:            }
0126:
0127:            public List getSelectedMembers() {
0128:                if (getAttribute(AudienceSelectionHelper.AUDIENCE_FUNCTION) != null) {
0129:                    selectedMembers = fillMemberList();
0130:                }
0131:                setAttribute("PRESENTATION_VIEWERS", selectedMembers);
0132:
0133:                if (selectedMembers == null)
0134:                    selectedMembers = new ArrayList();
0135:                return selectedMembers;
0136:            }
0137:
0138:            protected List fillMemberList() {
0139:                List returned = new ArrayList();
0140:
0141:                originalMembers = new ArrayList();
0142:
0143:                String id = (String) getAttribute(AudienceSelectionHelper.AUDIENCE_QUALIFIER);
0144:                setQualifier(getIdManager().getId(id));
0145:                setFunction((String) getAttribute(AudienceSelectionHelper.AUDIENCE_FUNCTION));
0146:
0147:                List authzs = getAuthzManager().getAuthorizations(null,
0148:                        getFunction(), getQualifier());
0149:
0150:                for (Iterator i = authzs.iterator(); i.hasNext();) {
0151:                    Authorization authz = (Authorization) i.next();
0152:                    returned.add(new DecoratedMember(this , authz.getAgent()));
0153:                    originalMembers.add(authz.getAgent());
0154:                }
0155:
0156:                removeAttributes(new String[] {
0157:                        AudienceSelectionHelper.AUDIENCE_FUNCTION,
0158:                        AudienceSelectionHelper.AUDIENCE_QUALIFIER });
0159:
0160:                return returned;
0161:            }
0162:
0163:            public String getFunction() {
0164:                return function;
0165:            }
0166:
0167:            public void setFunction(String function) {
0168:                this .function = function;
0169:            }
0170:
0171:            public Id getQualifier() {
0172:                return qualifier;
0173:            }
0174:
0175:            public void setQualifier(Id qualifier) {
0176:                this .qualifier = qualifier;
0177:            }
0178:
0179:            public void setSelectedMembers(List selectedMembers) {
0180:                this .selectedMembers = selectedMembers;
0181:            }
0182:
0183:            public String processActionCancel() {
0184:                ToolSession session = SessionManager.getCurrentToolSession();
0185:                session.setAttribute("target", getCancelTarget());
0186:                clearAudienceSelectionVariables();
0187:                processActionClearFilter();
0188:                return returnToCaller();
0189:            }
0190:
0191:            public String processActionSaveNotify() {
0192:                ToolSession session = SessionManager.getCurrentToolSession();
0193:                session.setAttribute("target", getSaveNotifyTarget());
0194:                save();
0195:                clearAudienceSelectionVariables();
0196:                processActionClearFilter();
0197:                return returnToCaller();
0198:            }
0199:
0200:            public String processActionBack() {
0201:                ToolSession session = SessionManager.getCurrentToolSession();
0202:                session.setAttribute("target", getBackTarget());
0203:                clearAudienceSelectionVariables();
0204:                processActionClearFilter();
0205:                return returnToCaller();
0206:            }
0207:
0208:            public AuthorizationFacade getAuthzManager() {
0209:                return authzManager;
0210:            }
0211:
0212:            public void setAuthzManager(AuthorizationFacade authzManager) {
0213:                this .authzManager = authzManager;
0214:            }
0215:
0216:            public IdManager getIdManager() {
0217:                return idManager;
0218:            }
0219:
0220:            public String getCancelTarget() {
0221:                return (String) getAttribute(AudienceSelectionHelper.AUDIENCE_CANCEL_TARGET);
0222:            }
0223:
0224:            public String getSaveTarget() {
0225:                return (String) getAttribute(AudienceSelectionHelper.AUDIENCE_SAVE_TARGET);
0226:            }
0227:
0228:            public String getSaveNotifyTarget() {
0229:                return (String) getAttribute(AudienceSelectionHelper.AUDIENCE_SAVE_NOTIFY_TARGET);
0230:            }
0231:
0232:            public String getBackTarget() {
0233:                return (String) getAttribute(AudienceSelectionHelper.AUDIENCE_BACK_TARGET);
0234:            }
0235:
0236:            public void setIdManager(IdManager idManager) {
0237:                this .idManager = idManager;
0238:            }
0239:
0240:            public String getInstructions() {
0241:                return (String) getAttributeOrDefault(AudienceSelectionHelper.AUDIENCE_INSTRUCTIONS);
0242:            }
0243:
0244:            public String getBrowseUserInstructions() {
0245:                return (String) getAttributeOrDefault(AudienceSelectionHelper.AUDIENCE_BROWSE_INDIVIDUAL);
0246:            }
0247:
0248:            public String getPublicInstructions() {
0249:                return (String) getAttributeOrDefault(AudienceSelectionHelper.AUDIENCE_PUBLIC_INSTRUCTIONS);
0250:            }
0251:
0252:            public String getPublicURL() {
0253:                return (String) getAttributeOrDefault(AudienceSelectionHelper.AUDIENCE_PUBLIC_URL);
0254:            }
0255:
0256:            public String getFilterTitle() {
0257:                return (String) getAttributeOrDefault(AudienceSelectionHelper.AUDIENCE_FILTER_INSTRUCTIONS);
0258:            }
0259:
0260:            public String getGlobalTitle() {
0261:                return (String) getAttributeOrDefault(AudienceSelectionHelper.AUDIENCE_GLOBAL_TITLE);
0262:            }
0263:
0264:            public String getIndividualTitle() {
0265:                return (String) getAttributeOrDefault(AudienceSelectionHelper.AUDIENCE_INDIVIDUAL_TITLE);
0266:            }
0267:
0268:            public String getGroupTitle() {
0269:                return (String) getAttributeOrDefault(AudienceSelectionHelper.AUDIENCE_GROUP_TITLE);
0270:            }
0271:
0272:            public String getPublicTitle() {
0273:                return (String) getAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_TITLE);
0274:            }
0275:
0276:            public String getSelectedTitle() {
0277:                return (String) getAttributeOrDefault(AudienceSelectionHelper.AUDIENCE_SELECTED_TITLE);
0278:            }
0279:
0280:            public boolean isPortfolioWizard() {
0281:                if ("true"
0282:                        .equals(getAttribute(AudienceSelectionHelper.AUDIENCE_PORTFOLIO_WIZARD))) {
0283:                    return true;
0284:                } else {
0285:                    return false;
0286:                }
0287:            }
0288:
0289:            public boolean isPortfolioWizardNotify() {
0290:                if (isPortfolioWizard()
0291:                        || "true"
0292:                                .equals(getAttribute(AudienceSelectionHelper.AUDIENCE_PORTFOLIO_WIZARD))) {
0293:                    return true;
0294:                } else {
0295:                    return false;
0296:                }
0297:            }
0298:
0299:            public boolean isPublicCapable() {
0300:                return getAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_TITLE) != null;
0301:            }
0302:
0303:            public boolean isEmailCapable() {
0304:                return getAttribute(AudienceSelectionHelper.AUDIENCE_GUEST_EMAIL) != null;
0305:            }
0306:
0307:            public boolean isPublicAudience() {
0308:                if (getAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_FLAG) != null) {
0309:                    publicAudience = "true"
0310:                            .equalsIgnoreCase((String) getAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_FLAG));
0311:                    removeAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_FLAG);
0312:                }
0313:                return publicAudience;
0314:            }
0315:
0316:            public boolean isWorksiteLimited() {
0317:                if (getAttribute(AudienceSelectionHelper.AUDIENCE_WORKSITE_LIMITED) != null) {
0318:                    return "true"
0319:                            .equalsIgnoreCase((String) getAttribute(AudienceSelectionHelper.AUDIENCE_WORKSITE_LIMITED));
0320:                }
0321:                return false;
0322:            }
0323:
0324:            public void setPublicAudience(boolean publicAudience) {
0325:                this .publicAudience = publicAudience;
0326:                setAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_FLAG,
0327:                        publicAudience ? "true" : "false");
0328:            }
0329:
0330:            public String getSearchUsers() {
0331:                return searchUsers;
0332:            }
0333:
0334:            public void setSearchUsers(String searchUsers) {
0335:                this .searchUsers = searchUsers;
0336:            }
0337:
0338:            public String getSearchEmails() {
0339:                return searchEmails;
0340:            }
0341:
0342:            public void setSearchEmails(String searchEmails) {
0343:                this .searchEmails = searchEmails;
0344:            }
0345:
0346:            public List getSiteGroups() {
0347:                List returned = new ArrayList();
0348:                Collection groups = getSite().getGroups();
0349:
0350:                for (Iterator i = groups.iterator(); i.hasNext();) {
0351:                    Group group = (Group) i.next();
0352:                    returned.add(new SelectItem(group.getId(), group
0353:                            .getDescription(), "group"));
0354:                }
0355:
0356:                return returned;
0357:            }
0358:
0359:            public Site getSite() {
0360:                if (site == null) {
0361:                    Placement placement = getToolManager()
0362:                            .getCurrentPlacement();
0363:                    String currentSiteId = placement.getContext();
0364:                    try {
0365:                        site = getSiteService().getSite(currentSiteId);
0366:                    } catch (IdUnusedException e) {
0367:                        throw new RuntimeException(e);
0368:                    }
0369:                }
0370:                return site;
0371:            }
0372:
0373:            public void setSite(Site site) {
0374:                this .site = site;
0375:            }
0376:
0377:            public ToolManager getToolManager() {
0378:                return toolManager;
0379:            }
0380:
0381:            public void setToolManager(ToolManager toolManager) {
0382:                this .toolManager = toolManager;
0383:            }
0384:
0385:            public SiteService getSiteService() {
0386:                return siteService;
0387:            }
0388:
0389:            public void setSiteService(SiteService siteService) {
0390:                this .siteService = siteService;
0391:            }
0392:
0393:            public List getSelectedRoles() {
0394:                return selectedRoles;
0395:            }
0396:
0397:            public void setSelectedRoles(List selectedRoles) {
0398:                this .selectedRoles = selectedRoles;
0399:            }
0400:
0401:            public void processActionRemove() {
0402:                for (Iterator i = getSelectedMembers().iterator(); i.hasNext();) {
0403:                    DecoratedMember member = (DecoratedMember) i.next();
0404:                    if (member.isSelected()) {
0405:                        i.remove();
0406:                    }
0407:                }
0408:            }
0409:
0410:            /**
0411:             * This checks that the parameter does not contain the 
0412:             * invalidEmailInIdAccountString string from sakai.properties
0413:             * 
0414:             * @param id String email address
0415:             * @return boolean 
0416:             */
0417:            protected boolean isDomainAllowed(String email) {
0418:                String invalidEmailInIdAccountString = ServerConfigurationService
0419:                        .getString("invalidEmailInIdAccountString", null);
0420:
0421:                if (invalidEmailInIdAccountString != null) {
0422:                    String[] invalidDomains = invalidEmailInIdAccountString
0423:                            .split(",");
0424:
0425:                    for (int i = 0; i < invalidDomains.length; i++) {
0426:                        String domain = invalidDomains[i].trim();
0427:
0428:                        if (email.toLowerCase().indexOf(domain.toLowerCase()) != -1) {
0429:                            return false;
0430:                        }
0431:                    }
0432:                }
0433:                return true;
0434:            }
0435:
0436:            /*public String processActionAddUser() {
0437:                boolean worksiteLimited = isWorksiteLimited();
0438:                if (!findByEmailOrDisplayName(getSearchUsers(), false, worksiteLimited)) {
0439:                    FacesContext.getCurrentInstance().addMessage(null,
0440:                            getFacesMessageFromBundle(worksiteLimited ? "worksite_user_not_found" : "user_not_found",
0441:                                    (new Object[]{getSearchUsers()})));
0442:                } else {
0443:                    setSearchUsers("");
0444:                }
0445:                return "tool";
0446:            } */
0447:
0448:            public String processActionAddEmail() {
0449:                boolean worksiteLimited = isWorksiteLimited();
0450:
0451:                String email2add = getSearchEmails();
0452:
0453:                if (!findByEmailOrDisplayName(email2add, true, worksiteLimited)) {
0454:                    String msgKey = null;
0455:                    if (worksiteLimited) {
0456:                        msgKey = "worksite_user_not_found";
0457:                    } else { // if we get here, then the input was not an email address
0458:                        if (isDomainAllowed(email2add)) {
0459:                            msgKey = "email_not_formatted";
0460:                        } else {
0461:                            msgKey = "email_in_invalid_domain";
0462:                        }
0463:                    }
0464:                    if (msgKey != null)
0465:                        FacesContext.getCurrentInstance().addMessage(
0466:                                null,
0467:                                getFacesMessageFromBundle(msgKey,
0468:                                        (new Object[] { email2add })));
0469:
0470:                } else {
0471:                    setSearchEmails("");
0472:                }
0473:                return "tool";
0474:            }
0475:
0476:            public String processActionAddGroup() {
0477:                for (Iterator i = getSelectedRoles().iterator(); i.hasNext();) {
0478:                    String roleId = (String) i.next();
0479:                    Agent role = getAgentManager().getAgent(
0480:                            getIdManager().getId(roleId));
0481:                    addAgent(role, "role_exists");
0482:                }
0483:                getSelectedRoles().clear();
0484:                return "tool";
0485:            }
0486:
0487:            public AgentManager getAgentManager() {
0488:                return agentManager;
0489:            }
0490:
0491:            public void setAgentManager(AgentManager agentManager) {
0492:                this .agentManager = agentManager;
0493:            }
0494:
0495:            /**
0496:             * @param displayName - for a guest user, this is the email address
0497:             * 
0498:             */
0499:            protected boolean findByEmailOrDisplayName(String displayName,
0500:                    boolean includeEmail, boolean worksiteLimited) {
0501:                List retVal = new ArrayList();
0502:                List guestUsers = null;
0503:                AgentImplOsp viewer = new AgentImplOsp();
0504:                if (includeEmail) {
0505:                    guestUsers = getAgentManager().findByProperty("email",
0506:                            displayName);
0507:
0508:                    // When seaching is not limited to the worksite and the email was not found
0509:                    if (!worksiteLimited && guestUsers == null) {
0510:                        if (validateEmail(displayName)
0511:                                && isDomainAllowed(displayName)) {
0512:                            viewer.setDisplayName(displayName);
0513:                            viewer.setRole(Agent.ROLE_GUEST);
0514:                            viewer.setId(getIdManager().getId(
0515:                                    viewer.getDisplayName()));
0516:                            guestUsers = new ArrayList();
0517:                            guestUsers.add(viewer);
0518:                        }
0519:                    }
0520:
0521:                }
0522:
0523:                if (guestUsers == null || guestUsers.size() == 0) {
0524:                    guestUsers = getAgentManager().findByProperty(
0525:                            "displayName", displayName);
0526:                }
0527:
0528:                if (guestUsers != null) {
0529:                    retVal.addAll(guestUsers);
0530:                }
0531:
0532:                boolean found = false;
0533:
0534:                for (Iterator i = retVal.iterator(); i.hasNext();) {
0535:                    found = true;
0536:                    Agent agent = (Agent) i.next();
0537:                    if (worksiteLimited) {
0538:                        if (!checkWorksiteMember(agent)) {
0539:                            return false;
0540:                        }
0541:                    }
0542:                    if (agent instanceof  AgentImplOsp) {
0543:                        agent = createGuestUser(agent);
0544:                        if (agent != null) {
0545:                            notifyNewUserEmail(agent);
0546:                        }
0547:                    }
0548:                    addAgent(agent, "user_exists");
0549:                }
0550:
0551:                return found;
0552:            }
0553:
0554:            protected void addAgent(Agent agent, String key) {
0555:                DecoratedMember decoratedAgent = new DecoratedMember(this ,
0556:                        agent);
0557:                if (!getSelectedMembers().contains(decoratedAgent)) {
0558:                    getSelectedMembers().add(decoratedAgent);
0559:                } else {
0560:                    FacesContext.getCurrentInstance().addMessage(
0561:                            null,
0562:                            getFacesMessageFromBundle(key,
0563:                                    (new Object[] { agent.getDisplayName() })));
0564:                }
0565:            }
0566:
0567:            protected boolean checkWorksiteMember(Agent agent) {
0568:                List roles = agent.getWorksiteRoles(getSite().getId());
0569:                return (roles != null && roles.size() > 0);
0570:            }
0571:
0572:            public String processActionSave() {
0573:                ToolSession session = SessionManager.getCurrentToolSession();
0574:                session.setAttribute("target", getSaveTarget());
0575:                save();
0576:                clearAudienceSelectionVariables();
0577:                processActionClearFilter();
0578:                return returnToCaller();
0579:            }
0580:
0581:            public void save() {
0582:                List added = new ArrayList();
0583:
0584:                for (Iterator i = getSelectedMembers().iterator(); i.hasNext();) {
0585:                    DecoratedMember member = (DecoratedMember) i.next();
0586:
0587:                    if (originalMembers.contains(member.getBase())) {
0588:                        originalMembers.remove(member.getBase());
0589:                    } else {
0590:                        added.add(member.getBase());
0591:                    }
0592:                }
0593:                setSelectedMembers(null);
0594:                addMembers(added);
0595:                removeMembers(originalMembers);
0596:
0597:            }
0598:
0599:            protected void addMembers(List added) {
0600:                for (Iterator i = added.iterator(); i.hasNext();) {
0601:                    Agent agent = (Agent) i.next();
0602:
0603:                    getAuthzManager().createAuthorization(agent, getFunction(),
0604:                            getQualifier());
0605:                }
0606:            }
0607:
0608:            protected void removeMembers(List added) {
0609:                for (Iterator i = added.iterator(); i.hasNext();) {
0610:                    Agent agent = (Agent) i.next();
0611:
0612:                    getAuthzManager().deleteAuthorization(agent, getFunction(),
0613:                            getQualifier());
0614:                }
0615:            }
0616:
0617:            public void processActionClearFilter() {
0618:
0619:                getSelectedGroupsFilter().clear();
0620:                getSelectedRolesFilter().clear();
0621:                setSearchEmails("");
0622:                setSearchUsers("");
0623:                if (selectedMembers != null) {
0624:                    selectedMembers.clear();
0625:                }
0626:                if (selectedRoles != null) {
0627:                    selectedRoles.clear();
0628:                }
0629:                if (availableRoleMemberList != null) {
0630:                    availableRoleMemberList.clear();
0631:                }
0632:                if (selectedRoleMemberList != null) {
0633:                    selectedRoleMemberList.clear();
0634:                }
0635:                processActionApplyFilter();
0636:            }
0637:
0638:            public void processActionApplyFilter() {
0639:                Set members = getGroupMembers();
0640:                List siteUsers = new ArrayList();
0641:                MemberFilter filter = new MemberFilter(this );
0642:
0643:                for (Iterator i = members.iterator(); i.hasNext();) {
0644:                    Member user = (Member) i.next();
0645:                    DecoratedMember decoratedMember = new DecoratedMember(this ,
0646:                            getAgentManager().getAgent(user.getUserId()));
0647:                    if (filter.includeMember(decoratedMember)) {
0648:                        siteUsers.add(decoratedMember);
0649:                    }
0650:                }
0651:
0652:                setBrowseUsers(new PagingList(siteUsers));
0653:            }
0654:
0655:            protected Set getGroupMembers() {
0656:                Set members = new HashSet();
0657:                List filterGroups = new ArrayList();
0658:                filterGroups.addAll(getSelectedGroupsFilter());
0659:                filterGroups.remove("");
0660:
0661:                if (!getHasGroups() || filterGroups.size() == 0) {
0662:                    return getSite().getMembers();
0663:                }
0664:
0665:                for (Iterator i = filterGroups.iterator(); i.hasNext();) {
0666:                    String groupId = (String) i.next();
0667:                    Group group = getSite().getGroup(groupId);
0668:                    members.addAll(group.getMembers());
0669:                }
0670:
0671:                return members;
0672:            }
0673:
0674:            public List getMembersList() {
0675:                Set members = getSite().getMembers();
0676:                List memberList = new ArrayList();
0677:                for (Iterator i = members.iterator(); i.hasNext();) {
0678:                    Member member = (Member) i.next();
0679:
0680:                    Agent agent = getAgentManager().getAgent(
0681:                            (member.getUserId()));
0682:                    //Check for a null agent since the site.getMembers() will return member records for deleted users
0683:                    if (agent != null) {
0684:                        DecoratedMember decoratedMember = new DecoratedMember(
0685:                                this , agent);
0686:                        memberList.add(new SelectItem(decoratedMember.getBase()
0687:                                .getId().getValue(), decoratedMember.getBase()
0688:                                .getDisplayName(), "member"));
0689:                    }
0690:                }
0691:
0692:                return memberList;
0693:            }
0694:
0695:            public List getRoles() {
0696:                List returned = new ArrayList();
0697:                Set roles = getSite().getRoles();
0698:                String siteId = getSite().getId();
0699:
0700:                for (Iterator i = roles.iterator(); i.hasNext();) {
0701:                    Role role = (Role) i.next();
0702:                    Agent roleAgent = getAgentManager().getWorksiteRole(
0703:                            role.getId(), siteId);
0704:                    returned.add(new SelectItem(roleAgent.getId().getValue(),
0705:                            role.getId(), "role"));
0706:                }
0707:
0708:                return returned;
0709:            }
0710:
0711:            public boolean getHasGroups() {
0712:                return getSite().hasGroups();
0713:            }
0714:
0715:            public List getGroups() {
0716:                List siteGroups = getSiteGroups();
0717:                return siteGroups;
0718:            }
0719:
0720:            public List getSelectedRolesFilter() {
0721:                if (selectedRolesFilter == null) {
0722:                    selectedRolesFilter = new ArrayList();
0723:                }
0724:                return selectedRolesFilter;
0725:            }
0726:
0727:            public void setSelectedRolesFilter(List selectedRolesFilter) {
0728:                this .selectedRolesFilter = selectedRolesFilter;
0729:            }
0730:
0731:            public List getSelectedGroupsFilter() {
0732:                if (selectedGroupsFilter == null) {
0733:                    selectedGroupsFilter = new ArrayList();
0734:                }
0735:                return selectedGroupsFilter;
0736:            }
0737:
0738:            public void setSelectedGroupsFilter(List selectedGroupsFilter) {
0739:                this .selectedGroupsFilter = selectedGroupsFilter;
0740:            }
0741:
0742:            public String[] getAvailableRoleMember() {
0743:                return availableRoleMember;
0744:            }
0745:
0746:            public void setAvailableRoleMember(String[] availableRoleMember) {
0747:                this .availableRoleMember = availableRoleMember;
0748:            }
0749:
0750:            public void setAvailableRoleMemberList(List availableRoleMemberList) {
0751:                this .availableRoleMemberList = availableRoleMemberList;
0752:            }
0753:
0754:            public List getAvailableRoleMemberList() {
0755:
0756:                availableRoleMemberList = new ArrayList();
0757:
0758:                List roleMemberList = new ArrayList();
0759:                roleMemberList.addAll(getRoles());
0760:
0761:                roleMemberList.add(new SelectItem("null", LIST_SEPERATOR, ""));
0762:                if (!isMaxList()) {
0763:                    roleMemberList.addAll(getMembersList());
0764:                }
0765:
0766:                for (Iterator idx = roleMemberList.iterator(); idx.hasNext();) {
0767:                    SelectItem availableItem = (SelectItem) idx.next();
0768:                    boolean matchFound = false;
0769:                    for (Iterator jdx = getSelectedRoleMemberList().iterator(); jdx
0770:                            .hasNext();) {
0771:                        SelectItem selecteItem = (SelectItem) jdx.next();
0772:                        if (selecteItem.getValue().toString().equals(
0773:                                availableItem.getValue().toString())) {
0774:                            matchFound = true;
0775:                            break;
0776:
0777:                        }
0778:
0779:                    }
0780:                    if (!matchFound) {
0781:                        availableRoleMemberList.add(availableItem);
0782:                    }
0783:                }
0784:
0785:                return availableRoleMemberList;
0786:            }
0787:
0788:            public String[] getSelectedRoleMember() {
0789:                return selectedRoleMember;
0790:            }
0791:
0792:            public void setSelectedRoleMember(String[] selectedRoleMember) {
0793:                this .selectedRoleMember = selectedRoleMember;
0794:            }
0795:
0796:            public List getSelectedRoleMemberList() {
0797:
0798:                selectedRoleMemberList = new ArrayList();
0799:                for (Iterator i = getSelectedMembers().iterator(); i.hasNext();) {
0800:                    DecoratedMember decoratedMember = (DecoratedMember) i
0801:                            .next();
0802:                    String description = "member";
0803:                    if (decoratedMember.getBase().isRole()) {
0804:                        description = "role";
0805:                    }
0806:                    selectedRoleMemberList.add(new SelectItem(decoratedMember
0807:                            .getBase().getId().getValue(), decoratedMember
0808:                            .getBase().getDisplayName(), description));
0809:                }
0810:
0811:                return selectedRoleMemberList;
0812:            }
0813:
0814:            public void setSelectedRoleMemberList(List selectedRoleMemberList) {
0815:                this .selectedRoleMemberList = selectedRoleMemberList;
0816:            }
0817:
0818:            public PagingList getBrowseUsers() {
0819:                if (browseUsers == null) {
0820:                    processActionApplyFilter();
0821:                }
0822:                return browseUsers;
0823:            }
0824:
0825:            public void setBrowseUsers(PagingList browseUsers) {
0826:                this .browseUsers = browseUsers;
0827:            }
0828:
0829:            public void processActionAddBrowseSelected() {
0830:                for (Iterator i = getBrowseUsers().getWholeList().iterator(); i
0831:                        .hasNext();) {
0832:                    DecoratedMember member = (DecoratedMember) i.next();
0833:                    if (member.isSelected()) {
0834:                        Agent user = member.getBase();
0835:                        addAgent(user, "user_exists");
0836:                        member.setSelected(false);
0837:                    }
0838:                }
0839:                if (getSelectedRoles() != null) {
0840:                    getSelectedRoles().clear();
0841:                }
0842:            }
0843:
0844:            public String processActionAdd() {
0845:                String[] selected = getAvailableRoleMember();
0846:                if (selected.length < 1) {
0847:                    //put in a message that they need to select something from the lsit to add
0848:                    return "main";
0849:                }
0850:
0851:                for (int i = 0; i < selected.length; i++) {
0852:
0853:                    SelectItem addItem = removeItems(selected[i],
0854:                            getAvailableRoleMemberList());
0855:                    if (addItem.getDescription().equals("role")) {
0856:                        addAgent(getAgentManager().getAgent(
0857:                                getIdManager().getId(
0858:                                        addItem.getValue().toString())),
0859:                                "role_exists");
0860:                    } else if (addItem.getDescription().equals("member")) {
0861:                        addAgent(getAgentManager().getAgent(
0862:                                addItem.getValue().toString()), "user_exists");
0863:                    }
0864:                    getSelectedRoleMemberList().add(addItem);
0865:                    setSelectedRoleMemberList(sortList(
0866:                            getSelectedRoleMemberList(), false));
0867:                }
0868:
0869:                return "main";
0870:            }
0871:
0872:            public String processActionRemoveSelected() {
0873:                String[] selected = getSelectedRoleMember();
0874:                if (selected.length < 1) {
0875:                    //put in a message that they need to select something from the lsit to add
0876:                    return "main";
0877:                }
0878:
0879:                for (int i = 0; i < selected.length; i++) {
0880:                    for (Iterator idx = getSelectedMembers().iterator(); idx
0881:                            .hasNext();) {
0882:                        DecoratedMember member = (DecoratedMember) idx.next();
0883:                        if (member.getBase().getId().toString().equals(
0884:                                selected[i])) {
0885:                            idx.remove();
0886:                        }
0887:                        getAvailableRoleMemberList().add(
0888:                                removeItems(selected[i],
0889:                                        getSelectedRoleMemberList()));
0890:                        setAvailableRoleMemberList(sortList(
0891:                                getAvailableRoleMemberList(), true));
0892:
0893:                    }
0894:                }
0895:
0896:                return "main";
0897:            }
0898:
0899:            private SelectItem removeItems(String value, List items) {
0900:
0901:                SelectItem result = null;
0902:                for (int i = 0; i < items.size(); i++) {
0903:                    SelectItem item = (SelectItem) items.get(i);
0904:                    if (value.equals(item.getValue())) {
0905:                        result = (SelectItem) items.remove(i);
0906:                        break;
0907:                    }
0908:                }
0909:
0910:                return result;
0911:            }
0912:
0913:            /*public void processActionAddSelected() {
0914:                for (Iterator i = getAvailableRoleMemberList().iterator(); i.hasNext();) {
0915:                    Member user = (Member) i.next();
0916:                    DecoratedMember member = new DecoratedMember(this, getAgentManager().getAgent(user.getUserId()));
0917:                    if (member.isSelected()) {
0918:                        Agent agentUser = member.getBase();
0919:                        addAgent(agentUser, "user_exists");
0920:                        member.setSelected(false);
0921:                    }
0922:                }
0923:            }*/
0924:
0925:            protected void clearAudienceSelectionVariables() {
0926:                ToolSession session = SessionManager.getCurrentToolSession();
0927:                session
0928:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_FUNCTION);
0929:                session
0930:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_QUALIFIER);
0931:                session
0932:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_INSTRUCTIONS);
0933:                session
0934:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_GLOBAL_TITLE);
0935:                session
0936:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_INDIVIDUAL_TITLE);
0937:                session
0938:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_GROUP_TITLE);
0939:                session
0940:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_TITLE);
0941:                session
0942:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_SELECTED_TITLE);
0943:                session
0944:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_FILTER_INSTRUCTIONS);
0945:                session
0946:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_GUEST_EMAIL);
0947:                session
0948:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_WORKSITE_LIMITED);
0949:                session
0950:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_BACK_TARGET);
0951:                session
0952:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_CANCEL_TARGET);
0953:                session
0954:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_URL);
0955:                session
0956:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_SAVE_NOTIFY_TARGET);
0957:                session
0958:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_SAVE_TARGET);
0959:                session
0960:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_PORTFOLIO_WIZARD);
0961:                session
0962:                        .removeAttribute(AudienceSelectionHelper.AUDIENCE_BROWSE_INDIVIDUAL);
0963:            }
0964:
0965:            public String getStepString() {
0966:                return stepString;
0967:            }
0968:
0969:            protected boolean validateEmail(String displayName) {
0970:                if (!emailPattern.matcher(displayName).matches()) {
0971:                    return false;
0972:                }
0973:                /*
0974:                     try {
0975:                        InternetAddress.parse(displayName, true);
0976:                     } catch (AddressException e) {
0977:                        // errors.rejectValue("displayName", "Invalid email address",
0978:                        // new Object[0], "Invalid email address");
0979:                        return false;
0980:                     } */
0981:
0982:                return true;
0983:            }
0984:
0985:            protected Agent createGuestUser(Agent viewer) {
0986:                AgentImplOsp guest = (AgentImplOsp) viewer;
0987:                guest.setRole(Agent.ROLE_GUEST);
0988:                return getAgentManager().createAgent(guest);
0989:            }
0990:
0991:            private void notifyNewUserEmail(Agent guest) {
0992:                String from = ServerConfigurationService.getString(
0993:                        "setup.request", null);
0994:                if (from == null) {
0995:
0996:                    from = "postmaster@".concat(ServerConfigurationService
0997:                            .getServerName());
0998:                }
0999:                String productionSiteName = ServerConfigurationService
1000:                        .getString("ui.service", "");
1001:                String productionSiteUrl = ServerConfigurationService
1002:                        .getPortalUrl();
1003:
1004:                String to = guest.getDisplayName();
1005:                String headerTo = to;
1006:                String replyTo = to;
1007:                String message_subject = getMessageFromBundle(
1008:                        "email.guestusernoti",
1009:                        new Object[] { productionSiteName });
1010:                String content = "";
1011:
1012:                if (from != null && to != null) {
1013:                    StringBuffer buf = new StringBuffer();
1014:                    buf.setLength(0);
1015:
1016:                    // email body
1017:                    buf.append(to + ":\n\n");
1018:                    AgentImplOsp impl = (AgentImplOsp) guest;
1019:                    buf.append(getMessageFromBundle("email.addedto",
1020:                            new Object[] { productionSiteName,
1021:                                    productionSiteUrl })
1022:                            + "\n\n");
1023:                    buf.append(getMessageFromBundle("email.simpleby",
1024:                            new Object[] { UserDirectoryService
1025:                                    .getCurrentUser().getDisplayName() })
1026:                            + "\n\n");
1027:                    buf.append(getMessageFromBundle("email.userid",
1028:                            new Object[] { to })
1029:                            + "\n\n");
1030:                    buf.append(getMessageFromBundle("email.password",
1031:                            new Object[] { impl.getPassword() })
1032:                            + "\n\n");
1033:
1034:                    content = buf.toString();
1035:                    EmailService.send(from, to, message_subject, content,
1036:                            headerTo, replyTo, null);
1037:                }
1038:            }
1039:
1040:            private List sortList(List sortList, boolean seperator) {
1041:                List roleList = new ArrayList();
1042:                List groupList = new ArrayList();
1043:                List memberList = new ArrayList();
1044:                for (Iterator i = sortList.iterator(); i.hasNext();) {
1045:                    SelectItem item = (SelectItem) i.next();
1046:                    if (item.getDescription().equals("role")) {
1047:                        roleList.add(item);
1048:                    } else if (item.getDescription().equals("group")) {
1049:                        groupList.add(item);
1050:                    } else if (item.getDescription().equals("member")) {
1051:                        memberList.add(item);
1052:                    }
1053:                }
1054:                roleList.addAll(groupList);
1055:                if (seperator) {
1056:                    roleList.add(new SelectItem("null", LIST_SEPERATOR, ""));
1057:                }
1058:                roleList.addAll(memberList);
1059:                return roleList;
1060:
1061:            }
1062:
1063:            public String getBrowseMessage() {
1064:                String message = "";
1065:
1066:                message = getMessageFromBundle("browseUserInstruction1",
1067:                        new Object[] { new Integer(getMaxRoleMemberList()) });
1068:
1069:                return message;
1070:            }
1071:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.