Source Code Cross Referenced for CommunityImpl.java in  » Portal » Open-Portal » com » sun » portal » community » impl » 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 » Portal » Open Portal » com.sun.portal.community.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
0003:         *
0004:         * Redistribution and use in source and binary forms, with or without
0005:         * modification, are permitted provided that the following conditions
0006:         * are met:
0007:         *
0008:         * - Redistributions of source code must retain the above copyright
0009:         *   notice, this list of conditions and the following disclaimer.getc
0010:         *
0011:         * - Redistribution in binary form must reproduce the above copyright
0012:         *   notice, this list of conditions and the following disclaimer in
0013:         *   the documentation and/or other materials provided with thesuffix
0014:         *   distribution.
0015:         *
0016:         * Neither the name of Sun Microsystems, Inc. or the names of
0017:         * contributors may be used to endorse or promote products derived
0018:         * from this software without specific prior written permission.
0019:         *
0020:         * This software is provided "AS IS," without a warranty of any
0021:         * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
0022:         * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
0023:         * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
0024:         * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
0025:         * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
0026:         * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
0027:         * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
0028:         * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
0029:         * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
0030:         * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
0031:         * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
0032:         *
0033:         * You acknowledge that Software is not designed, licensed or intended
0034:         * any nuclear facility.
0035:         */
0036:
0037:        package com.sun.portal.community.impl;
0038:
0039:        import java.util.Iterator;
0040:        import java.util.Set;
0041:        import java.util.HashSet;
0042:        import java.util.LinkedHashSet;
0043:        import java.util.Map;
0044:        import java.util.HashMap;
0045:        import java.util.Properties;
0046:        import java.util.List;
0047:        import java.util.ArrayList;
0048:        import java.util.Collection;
0049:        import java.util.Collections;
0050:        import java.util.Locale;
0051:        import java.util.ResourceBundle;
0052:        import java.util.logging.Logger;
0053:        import java.util.logging.LogRecord;
0054:        import java.util.logging.Level;
0055:
0056:        import java.io.ByteArrayInputStream;
0057:        import java.io.FileInputStream;
0058:        import java.io.FileNotFoundException;
0059:        import java.io.IOException;
0060:        import java.io.UnsupportedEncodingException;
0061:        import java.net.URLConnection;
0062:        import java.net.URL;
0063:
0064:        import javax.servlet.http.HttpServletRequest;
0065:        import javax.servlet.http.HttpServletResponse;
0066:
0067:        import com.iplanet.sso.SSOTokenManager;
0068:        import com.iplanet.sso.SSOToken;
0069:        import com.iplanet.sso.SSOException;
0070:
0071:        import com.sun.portal.log.common.PortalLogger;
0072:
0073:        import com.sun.portal.community.mc.CMCFactory;
0074:        import com.sun.portal.community.mc.CMCException;
0075:        import com.sun.portal.community.mc.CMCPrincipal;
0076:        import com.sun.portal.community.mc.CMCNode;
0077:        import com.sun.portal.community.mc.CMCUser;
0078:        import com.sun.portal.community.mc.CMCRolePrincipal;
0079:        import com.sun.portal.community.mc.ConfigTable;
0080:        import com.sun.portal.community.mc.ConfigTable.ConfigKey;
0081:        import com.sun.portal.community.mc.CMCExistsException;
0082:
0083:        import com.sun.portal.desktop.context.DSAMEAdminDPContext;
0084:        import com.sun.portal.desktop.context.AdminDPContext;
0085:        import com.sun.portal.desktop.context.ContextError;
0086:        import com.sun.portal.desktop.dp.DPRoot;
0087:        import com.sun.portal.desktop.dp.DPNode;
0088:        import com.sun.portal.desktop.dp.DPChannel;
0089:        import com.sun.portal.desktop.dp.DPContainerChannel;
0090:        import com.sun.portal.desktop.dp.DPError;
0091:        import com.sun.portal.desktop.dp.xml.XMLDPFactory;
0092:
0093:        import com.sun.portal.community.Community;
0094:        import com.sun.portal.community.CommunityFactory;
0095:        import com.sun.portal.community.CommunityManager;
0096:        import com.sun.portal.community.CommunityDoesNotExistException;
0097:        import com.sun.portal.community.CommunityServiceException;
0098:        import com.sun.portal.community.CommunityServiceExceptionEntry;
0099:        import com.sun.portal.community.CommunityUserServiceExceptionEntry;
0100:        import com.sun.portal.community.CommunityId;
0101:        import com.sun.portal.community.CommunityUser;
0102:        import com.sun.portal.community.RoleId;
0103:        import com.sun.portal.community.DPName;
0104:        import com.sun.portal.community.CommunityException;
0105:        import com.sun.portal.community.TemplateTokens;
0106:        import com.sun.portal.community.RoleAssignmentException;
0107:
0108:        import com.sun.portal.community.template.Template;
0109:        import com.sun.portal.community.template.TemplateManager;
0110:        import com.sun.portal.community.template.TemplateManagerFactory;
0111:        import com.sun.portal.community.template.TemplateException;
0112:
0113:        import com.sun.portal.community.notification.NotificationManagerFactory;
0114:        import com.sun.portal.community.notification.NotificationManager;
0115:        import com.sun.portal.community.notification.Notification;
0116:        import com.sun.portal.community.notification.NotificationType;
0117:        import com.sun.portal.community.notification.NotificationException;
0118:
0119:        import com.sun.portal.community.urlmanager.CommunityURLManagerFactory;
0120:        import com.sun.portal.community.urlmanager.CommunityURLManager;
0121:
0122:        import com.sun.portal.service.serviceregistry.ServiceRegistryFactory;
0123:        import com.sun.portal.service.serviceregistry.ServiceRegistry;
0124:        import com.sun.portal.service.serviceregistry.ServiceRegistryException;
0125:        import com.sun.portal.service.Service;
0126:        import com.sun.portal.service.ServiceException;
0127:        import com.sun.portal.service.ProvisionRequest;
0128:        import com.sun.portal.service.ProvisionResponse;
0129:        import com.sun.portal.service.MembershipRequest;
0130:        import com.sun.portal.service.MembershipResponse;
0131:        import com.sun.portal.service.ProvisionRoles;
0132:        import com.sun.portal.search.soif.*;
0133:        import com.sun.portal.search.demo.*;
0134:
0135:        import com.sun.portal.desktop.context.CommunityUserMembershipThreadLocalizer;
0136:
0137:        import netscape.ldap.LDAPDN;
0138:
0139:        import com.sun.portal.util.ResourceLoader;
0140:        import java.util.regex.Pattern;
0141:
0142:        public class CommunityImpl implements  Community, TemplateTokens {
0143:            public static final String NOTIFICATION_RB_BASE = "CommunityNotificationMessages";
0144:            private static final Pattern ALL_PATTERN = Pattern.compile(".*");
0145:
0146:            private static CMCFactory cmcFactory = null;
0147:            private static NotificationManager notifManager = null;
0148:            private static CommunityURLManager urlManager = null;
0149:            static {
0150:                try {
0151:                    cmcFactory = CMCFactory.getInstance();
0152:                } catch (CMCException ce) {
0153:                    throw new RuntimeException(
0154:                            "failed to get CMC factory instance", ce);
0155:                }
0156:
0157:                notifManager = NotificationManagerFactory.getInstance()
0158:                        .getNotificationManager();
0159:                urlManager = CommunityURLManagerFactory.getInstance()
0160:                        .getCommunityURLManager();
0161:            }
0162:
0163:            private HttpServletRequest req;
0164:            private HttpServletResponse res;
0165:            private SSOToken ssoToken;
0166:            private CommunityId cid;
0167:            private DSAMEAdminDPContext _dpContext = null;
0168:            private ServiceRegistry _serviceRegistry = null;
0169:            private CMCNode cmcNode;
0170:
0171:            private static Logger logger = PortalLogger
0172:                    .getLogger(CommunityUserImpl.class);
0173:
0174:            public CommunityImpl(HttpServletRequest req,
0175:                    HttpServletResponse res, SSOToken ssoToken, CommunityId cid)
0176:                    throws CommunityDoesNotExistException, CommunityException {
0177:                this .req = req;
0178:                this .res = res;
0179:                this .cid = cid;
0180:                this .ssoToken = ssoToken;
0181:
0182:                try {
0183:                    cmcNode = cmcFactory.getCMCNode(TypeConverter
0184:                            .communityIdToPrincipal(cid));
0185:                    //
0186:                    // verify existence
0187:                    //
0188:                    if (!cmcNode.exists()) {
0189:                        throw new CommunityDoesNotExistException(
0190:                                "does not exist, cid=" + cid);
0191:                    }
0192:                } catch (CMCException cmce) {
0193:                    throw new CommunityException(cmce);
0194:                }
0195:
0196:                //
0197:                // init dpcontext
0198:                //
0199:                // todo: find out how to get a handle on propertiesFile then use getAdminDPContext()
0200:                //_dpContext = getAdminDPContext();
0201:                _dpContext = new com.sun.portal.desktop.context.DSAMEAdminDPContext();
0202:                try {
0203:                    _dpContext.init(req, ssoToken);
0204:                } catch (ContextError ce) {
0205:                    throw new CommunityException(
0206:                            "CommunityImpl.init(): failed to initialize AdminDPContext.",
0207:                            ce);
0208:                }
0209:
0210:                //
0211:                // init service registry
0212:                //
0213:                try {
0214:                    _serviceRegistry = ServiceRegistryFactory.getInstance()
0215:                            .getServiceRegistry(req);
0216:                } catch (ServiceRegistryException sre) {
0217:                    throw new CommunityException(
0218:                            "CommunityImpl.init(): failed to get service registry",
0219:                            sre);
0220:                }
0221:            }
0222:
0223:            public CommunityId getCommunityId() {
0224:                return cid;
0225:            }
0226:
0227:            void provisionServices(String templateId, Map tokenMapping)
0228:                    throws CommunityServiceException, CommunityException {
0229:                //
0230:                // get role templates
0231:                //
0232:                Map roleTemplates = getRoleTemplates(templateId, tokenMapping);
0233:
0234:                //
0235:                // collect a set (union) of channel names from the role templates
0236:                //
0237:                Set channelNames = collectChannelNames(roleTemplates.values());
0238:
0239:                //
0240:                // get merged dpRoot for each role
0241:                //
0242:                Map mergedDPRoots = getMergedDPRoots(roleTemplates);
0243:
0244:                //
0245:                // provision all channels/services
0246:                //
0247:                CommunityServiceResult csr = provisionServicesHelper(cmcNode,
0248:                        ProvisionRequest.EVENT_TYPE_CREATED, channelNames,
0249:                        mergedDPRoots);
0250:                Map provisionedDPDocs = csr.getDPDocs();
0251:                // if errors were found, prepare to throw CommunityServiceException
0252:                CommunityServiceException serviceError = null;
0253:                if (csr.hasErrors()) {
0254:                    serviceError = new CommunityServiceException(mergedDPRoots);
0255:                    for (Iterator i = csr.getErrors().iterator(); i.hasNext();) {
0256:                        serviceError
0257:                                .addEntry((CommunityServiceExceptionEntry) i
0258:                                        .next());
0259:                    }
0260:                }
0261:
0262:                //
0263:                // assign community DP's
0264:                //
0265:                setCommunityDPs(cmcNode, provisionedDPDocs);
0266:
0267:                //
0268:                // throw CommunityServiceException if any
0269:                //
0270:                if (serviceError != null) {
0271:                    throw serviceError;
0272:                }
0273:            }
0274:
0275:            /**
0276:             * Get the <code>Template</code> for the given templateID.  Grab all
0277:             * role templates that are associated with this template.  The templates
0278:             * should have been token-replaced.
0279:             *
0280:             * @param templateId ID of the template you want to retrieve
0281:             * @param communityName community name to be used in token replacement
0282:             * @param communityDesc community description to be used in token replacement
0283:             * @throws com.sun.portal.community.mgmt.CommunityException
0284:             * @return a map mapping <code>CMCRolePrincipal</code> to its corresponding template
0285:             */
0286:            protected Map getRoleTemplates(String templateId, Map tokenMapping)
0287:                    throws CommunityException {
0288:
0289:                //
0290:                // get a handle on the TemplateManager
0291:                //
0292:                TemplateManager tm = null;
0293:                try {
0294:                    tm = TemplateManagerFactory.getInstance()
0295:                            .getTemplateManager();
0296:                } catch (TemplateException te) {
0297:                    throw new CommunityException(
0298:                            "CommunityImpl.getRoleTemplate(): failed to get TemplateManager.  ",
0299:                            te);
0300:                }
0301:
0302:                //
0303:                // get role templates
0304:                //
0305:                Map roleTemplates = null;
0306:                try {
0307:                    Template t = tm.getTemplate(templateId, tokenMapping);
0308:                    roleTemplates = t.getRoleTemplates();
0309:                } catch (TemplateException te) {
0310:                    throw new CommunityException("templateId=" + templateId
0311:                            + ", communityId=" + getCommunityId(), te);
0312:                }
0313:
0314:                //
0315:                // convert role (string value) to CMCRolePrincipal in the Map
0316:                //
0317:                Map rTemplates = new HashMap();
0318:                for (Iterator i = roleTemplates.keySet().iterator(); i
0319:                        .hasNext();) {
0320:                    String role = (String) i.next();
0321:                    CMCRolePrincipal rPrincipal = CMCRolePrincipal
0322:                            .valueOf(role);
0323:                    if (rPrincipal == null) {
0324:                        throw new CommunityException("Invalid role=" + role);
0325:                    }
0326:                    rTemplates.put(rPrincipal, roleTemplates.get(role));
0327:                }
0328:
0329:                return rTemplates;
0330:            }
0331:
0332:            /**
0333:             * Get a union set of channel names that appear in given set of display profiles.
0334:             *
0335:             * @param dpDocs display profile documents
0336:             * @return set of channel names
0337:             */
0338:            protected Set collectChannelNames(Collection dpDocs)
0339:                    throws CommunityException {
0340:
0341:                Set channelNames = new HashSet();
0342:                for (Iterator i = dpDocs.iterator(); i.hasNext();) {
0343:                    byte[] dpDoc = (byte[]) i.next();
0344:                    DPRoot dpRoot = getDPRoot(dpDoc);
0345:
0346:                    getSelectedChannelNames(dpRoot, dpRoot, channelNames);
0347:                }
0348:
0349:                return channelNames;
0350:            }
0351:
0352:            /**
0353:             * Recursively get all channel names selected in the given node.
0354:             * Only the names of the leaf channels (i.e. non-container) will be collected.
0355:             *
0356:             * @param node node from where you want to start collecting the channel names
0357:             * @return channelNames of all channels selected in the given node
0358:             */
0359:            private void getSelectedChannelNames(DPNode node, DPRoot root,
0360:                    Set channelNames) {
0361:
0362:                if (node instanceof  DPContainerChannel
0363:                        || node instanceof  DPRoot) {
0364:                    Set names = new HashSet();
0365:
0366:                    if (node instanceof  DPRoot) {
0367:                        // get names of all containers/channels contained in the DPRoot
0368:                        names.addAll(node.getChannelNames());
0369:                    } else { // DPContainerChannel
0370:                        // get names of all selected containers/channels
0371:                        DPContainerChannel cont = (DPContainerChannel) node;
0372:                        Map selected = cont.getSelected().getCollectionValue();
0373:                        if (selected != null) {
0374:                            names.addAll(selected.keySet());
0375:                        }
0376:                    }
0377:                    // recurse!
0378:                    for (Iterator i = names.iterator(); i.hasNext();) {
0379:                        String cname = (String) i.next();
0380:                        DPNode cnode = root.getChannel(cname);
0381:                        if (cnode != null) {
0382:                            getSelectedChannelNames(cnode, root, channelNames);
0383:                        } else {
0384:                            // trying to reference a channel that does not exist in the dp
0385:                            if (logger.isLoggable(Level.WARNING)) {
0386:                                logger.log(Level.WARNING, "PSCPM_CSPCI00316",
0387:                                        cname);
0388:                            }
0389:                        }
0390:                    }
0391:                } else {
0392:                    // base case: reached the leaf channel
0393:                    channelNames.add(node.getName());
0394:                }
0395:            }
0396:
0397:            private void removeSelectedChannels(DPNode node, DPRoot root,
0398:                    Set channelNames) {
0399:
0400:                if (node instanceof  DPContainerChannel
0401:                        || node instanceof  DPRoot) {
0402:
0403:                    Set names = new HashSet();
0404:                    if (node instanceof  DPRoot) {
0405:                        // get names of all containers/channels contained in the DPRoot
0406:                        names.addAll(node.getChannelNames());
0407:
0408:                    } else { // DPContainerChannel
0409:                        // remove channel from the selected list if there is a match
0410:                        DPContainerChannel cont = (DPContainerChannel) node;
0411:                        Map selectedMap = cont.getSelected()
0412:                                .getCollectionValue();
0413:
0414:                        if (selectedMap != null
0415:                                && selectedMap.keySet().size() > 0) {
0416:                            boolean removed = false;
0417:                            for (Iterator i = selectedMap.keySet().iterator(); i
0418:                                    .hasNext();) {
0419:                                String chname = (String) i.next();
0420:                                if (channelNames.contains(chname)) {
0421:                                    i.remove();
0422:                                    removed = true;
0423:                                    if (logger.isLoggable(Level.WARNING)) {
0424:                                        logger.log(Level.WARNING,
0425:                                                "PSCPM_CSPCI00300", chname);
0426:                                    }
0427:                                } else {
0428:                                    names.add(chname);
0429:                                }
0430:                            }
0431:
0432:                            // put back changed list
0433:                            if (removed) {
0434:                                cont.getSelected().setCollectionValue(
0435:                                        selectedMap);
0436:                            }
0437:                        }
0438:
0439:                    }
0440:
0441:                    // recurse!
0442:                    for (Iterator i = names.iterator(); i.hasNext();) {
0443:                        String cname = (String) i.next();
0444:                        DPNode cnode = root.getChannel(cname);
0445:                        if (cnode instanceof  DPContainerChannel) {
0446:                            removeSelectedChannels(cnode, root, channelNames);
0447:                        }
0448:                    }
0449:
0450:                } else {
0451:                    // base case: reached the leaf channel
0452:                }
0453:            }
0454:
0455:            /**
0456:             * Build <code>DPRoot</code> from the base display profile then merge in the global display profile.
0457:             * Repeat this process for each entry in the map.
0458:             *
0459:             * @param baseDPs a map mapping <code>CMCRolePrincipal</code> to its corresponding display profile document.
0460:             * @throws com.sun.portal.community.mgmt.CommunityException
0461:             * @return a map mapping <code>CMCRolePrincipal</code> to its corresponding merged <code>DPRoot</code>
0462:             */
0463:            protected Map getMergedDPRoots(Map baseDPs)
0464:                    throws CommunityException {
0465:
0466:                Map mergedDPRoots = new HashMap();
0467:                for (Iterator i = baseDPs.keySet().iterator(); i.hasNext();) {
0468:
0469:                    CMCRolePrincipal rPrincipal = (CMCRolePrincipal) i.next();
0470:
0471:                    //
0472:                    // create base DPRoot
0473:                    //
0474:                    byte[] baseDP = (byte[]) baseDPs.get(rPrincipal);
0475:                    DPRoot dpRoot = getDPRoot(baseDP);
0476:
0477:                    //
0478:                    // merge global display profile
0479:                    // we only need global DP because community space is global
0480:                    //
0481:                    //String globalDP = _dpContext.getGlobalDPDocument();
0482:                    //DPRoot globalDPRoot = f.createRoot(_dpContext, globalDP);
0483:                    Set names = new HashSet();
0484:                    // todo: find out how to not hard-code this value
0485:                    // file rfe against desktop: XMLDPFactory.addMerger(DPContext, DPRoot, DPRoot)
0486:                    names.add("_!global!_");
0487:                    XMLDPFactory f = XMLDPFactory.getInstance();
0488:                    DPRoot mergedDPRoot = f.addMergers(_dpContext, dpRoot,
0489:                            names, null);
0490:
0491:                    String serviceRole = convertToServiceRole(rPrincipal);
0492:                    mergedDPRoots.put(serviceRole, mergedDPRoot);
0493:                }
0494:
0495:                return mergedDPRoots;
0496:            }
0497:
0498:            /**
0499:             * Provision services corresponding to the channel names.
0500:             *
0501:             * @param cNode <code>CommunityNode</code> for which this service is provisioned for
0502:             * @param event the event for which the service is provisioned
0503:             * @param channelNames names of the channels to be provisioned
0504:             * @param mergedDPRoots a map mapping <code>CMCRolePrincipal</code> to its corresponding <code>DPRoot</code>
0505:             * @throws com.sun.portal.community.CommunityException
0506:             */
0507:            protected CommunityServiceResult provisionServicesHelper(
0508:                    CMCNode cNode, String event, Set channelNames,
0509:                    Map mergedDPRoots) throws CommunityException {
0510:
0511:                //
0512:                // get community principal
0513:                //
0514:                CMCPrincipal cPrincipal = null;
0515:                try {
0516:                    cPrincipal = cNode.getCMCPrincipal();
0517:                } catch (CMCException ce) {
0518:                    throw new CommunityException(
0519:                            "CommunityImpl.provisionServicesHelper(): failed to get community principal.  cNode="
0520:                                    + cNode, ce);
0521:                }
0522:
0523:                if (logger.isLoggable(Level.FINER)) {
0524:                    logger.entering("CommunityImpl", "provisionServicesHelper",
0525:                            new Object[] { cPrincipal.toString(), event,
0526:                                    channelNames });
0527:                }
0528:
0529:                //
0530:                // provision channels
0531:                //
0532:                CommunityServiceResult csr = new CommunityServiceResult();
0533:                for (Iterator i = channelNames.iterator(); i.hasNext();) {
0534:                    String channelName = (String) i.next();
0535:
0536:                    try {
0537:                        provisionServiceHelper(cPrincipal, event, channelName,
0538:                                mergedDPRoots);
0539:
0540:                    } catch (Exception ex) {
0541:                        if (logger.isLoggable(Level.INFO)) {
0542:                            logRecord(logger, Level.INFO, "PSCPM_CSPCI00309",
0543:                                    ex, new Object[] { cPrincipal.toString(),
0544:                                            event, channelName });
0545:                        }
0546:                        csr.addError(cPrincipal.toString(), channelName, ex);
0547:                    }
0548:                }
0549:
0550:                if (csr.hasErrors()) {
0551:                    if (logger.isLoggable(Level.INFO)) {
0552:                        logger.log(Level.INFO, "PSCPM_CSPCI00310", csr
0553:                                .getFailedServiceNames());
0554:                    }
0555:                }
0556:
0557:                //
0558:                // when creating cty, process resulting mergedDPRoots and store it into csr
0559:                //
0560:                if (event.equals(ProvisionRequest.EVENT_TYPE_CREATED)) {
0561:                    Map provisionedDPDocs = new HashMap();
0562:                    for (Iterator i = mergedDPRoots.keySet().iterator(); i
0563:                            .hasNext();) {
0564:                        String role = (String) i.next();
0565:                        DPRoot mergedDPRoot = (DPRoot) mergedDPRoots.get(role);
0566:
0567:                        // flatten DPRoot (i.e. take only the base DPRoot)
0568:                        DPRoot dpRoot = null;
0569:                        StringBuffer sb = new StringBuffer(256);
0570:                        mergedDPRoot.toXML(sb, 0);
0571:                        XMLDPFactory f = XMLDPFactory.getInstance();
0572:                        try {
0573:                            dpRoot = f.createRoot(_dpContext, sb.toString());
0574:                        } catch (DPError de) {
0575:                            throw new CommunityException(
0576:                                    "CommunityImpl.provisionServicesHelper(): failed to create dproot.  dpDoc="
0577:                                            + sb.toString(), de);
0578:                        }
0579:
0580:                        // remove channels that failed to provision properly
0581:                        Set failedServices = csr.getFailedServiceNames();
0582:                        if (failedServices != null && failedServices.size() > 0) {
0583:                            removeSelectedChannels(mergedDPRoot, mergedDPRoot,
0584:                                    failedServices);
0585:                        }
0586:
0587:                        // set dirty bit off before writing it out.  (otherwise you get validation error)
0588:                        if (dpRoot.isDirty()) {
0589:                            dpRoot.setDirty(false);
0590:                        }
0591:
0592:                        // convert to byte[] in UTF-8 which is expected by communitymc
0593:                        byte[] dpDoc = null;
0594:                        sb = new StringBuffer(256);
0595:                        mergedDPRoot.toXML(sb, 0);
0596:                        try {
0597:                            dpDoc = sb.toString().getBytes("UTF-8");
0598:                        } catch (UnsupportedEncodingException uee) {
0599:                            throw new CommunityException(
0600:                                    "CommunityImpl.provisionServices(): failed to convert to UTF-8 bytes. ",
0601:                                    uee);
0602:                        }
0603:
0604:                        CMCRolePrincipal rPrincipal = convertToCMCRolePrincipal(role);
0605:                        provisionedDPDocs.put(rPrincipal, dpDoc);
0606:                    }
0607:
0608:                    csr.setDPDocs(provisionedDPDocs);
0609:                }
0610:
0611:                if (logger.isLoggable(Level.FINER)) {
0612:                    logger.exiting("CommunityImpl", "provisionServices", csr);
0613:                }
0614:
0615:                return csr;
0616:            }
0617:
0618:            /**
0619:             * First convert the given map (<code>CMCRolePrincipal</code> to its corresponding
0620:             * <code>DPRoot</code>) to <code>ConfigTable</code>.  Then assign  the
0621:             * <code>ConfigTable</code> to the community node.
0622:             *
0623:             * @param cNode <code>CommunityNode</code> to operate on
0624:             * @param dpDocs a map mapping <code>CMCRolePrincipal</code> to its corresponding display profile document
0625:             */
0626:            protected void setCommunityDPs(CMCNode cNode, Map dpDocs)
0627:                    throws CommunityException {
0628:
0629:                //
0630:                // get community principal
0631:                //
0632:                CMCPrincipal cPrincipal = null;
0633:                try {
0634:                    cPrincipal = cNode.getCMCPrincipal();
0635:                } catch (CMCException ce) {
0636:                    throw new CommunityException(
0637:                            "CommunityImpl.setCommunityDPs(): failed to get community principal.  cNode="
0638:                                    + cNode, ce);
0639:                }
0640:
0641:                //
0642:                // build config table
0643:                //
0644:                ConfigTable dpCT = new ConfigTable();
0645:                for (Iterator i = dpDocs.keySet().iterator(); i.hasNext();) {
0646:                    CMCRolePrincipal rPrincipal = (CMCRolePrincipal) i.next();
0647:                    byte[] dpDoc = (byte[]) dpDocs.get(rPrincipal);
0648:                    ConfigTable.ConfigKey ckey = new ConfigTable.ConfigKey(
0649:                            cPrincipal, rPrincipal);
0650:                    dpCT.put(ckey, dpDoc);
0651:                }
0652:
0653:                //
0654:                // set community dp docs
0655:                //
0656:                try {
0657:                    cNode.setDPDocuments(dpCT);
0658:                } catch (CMCException ce) {
0659:                    throw new CommunityException(
0660:                            "CommunityImpl.setCommunityDPDocuments(): failed to set community dp's.  cNode="
0661:                                    + cNode, ce);
0662:                }
0663:            }
0664:
0665:            /**
0666:             * get DPRoot object from a display profile document
0667:             */
0668:            protected DPRoot getDPRoot(byte[] dpDoc) throws CommunityException {
0669:                DPRoot dpRoot = null;
0670:                XMLDPFactory f = XMLDPFactory.getInstance();
0671:                try {
0672:                    dpRoot = f.createRoot(_dpContext, new ByteArrayInputStream(
0673:                            dpDoc));
0674:                } catch (DPError de) {
0675:                    throw new CommunityException(
0676:                            "CommunityImpl.getDPRoot(): failed to create dproot.  dpDoc="
0677:                                    + dpDoc, de);
0678:                }
0679:
0680:                return dpRoot;
0681:            }
0682:
0683:            private AdminDPContext getAdminDPContext(String propertiesFile)
0684:                    throws CommunityException {
0685:
0686:                Properties desktopProps = new Properties();
0687:                try {
0688:                    desktopProps.load(new FileInputStream(propertiesFile));
0689:                } catch (FileNotFoundException fnfe) {
0690:                    throw new CommunityException(
0691:                            "CommunityImpl.getAdminDPContext() ", fnfe);
0692:                } catch (IOException ioe) {
0693:                    throw new CommunityException(
0694:                            "CommunityImpl.getAdminDPContext() ", ioe);
0695:                }
0696:
0697:                String adminDPContextClassName = desktopProps
0698:                        .getProperty(AdminDPContext.ADMINDPCONTEXTCLASSNAME_KEY);
0699:                AdminDPContext adc = null;
0700:
0701:                try {
0702:                    adc = (AdminDPContext) (Class
0703:                            .forName(adminDPContextClassName).newInstance());
0704:                } catch (ClassNotFoundException cnfe) {
0705:                    throw new CommunityException(
0706:                            "CommunityImpl.getAdminDPContext()", cnfe);
0707:                } catch (NoClassDefFoundError ncdfe) {
0708:                    throw new CommunityException(
0709:                            "CommunityImpl.getAdminDPContext()", ncdfe);
0710:                } catch (IllegalAccessException iae) {
0711:                    throw new CommunityException(
0712:                            "CommunityImpl.getAdminDPContext()", iae);
0713:                } catch (ClassCastException cce) {
0714:                    throw new CommunityException(
0715:                            "CommunityImpl.getAdminDPContext()", cce);
0716:                } catch (InstantiationException ie) {
0717:                    throw new CommunityException(
0718:                            "CommunityImpl.getAdminDPContext()", ie);
0719:                } catch (SecurityException se) {
0720:                    throw new CommunityException(
0721:                            "CommunityImpl.getAdminDPContext()", se);
0722:                }
0723:
0724:                return adc;
0725:            }
0726:
0727:            /**
0728:             * convert CMCRolePrincipal to the role representation used in service provisioning
0729:             * todo: would be nice if this conversion doesn't have to take place.
0730:             *      make it a consipiracy that the CMCRolePrincipal and ProvisionRequest
0731:             *      use the same role representation
0732:             */
0733:            public static String convertToServiceRole(
0734:                    CMCRolePrincipal rPrincipal) throws CommunityException {
0735:
0736:                String serviceRole = null;
0737:                if (rPrincipal.equals(CMCRolePrincipal.MEMBER_ROLE)) {
0738:                    serviceRole = ProvisionRequest.DP_MEMBER;
0739:                } else if (rPrincipal.equals(CMCRolePrincipal.OWNER_ROLE)) {
0740:                    serviceRole = ProvisionRequest.DP_OWNER;
0741:                } else if (rPrincipal.equals(CMCRolePrincipal.VISITOR_ROLE)) {
0742:                    serviceRole = ProvisionRequest.DP_VISITOR;
0743:                } else if (rPrincipal.equals(CMCRolePrincipal.PENDING_ROLE)) {
0744:                    serviceRole = ProvisionRequest.DP_PENDING;
0745:                } else if (rPrincipal.equals(CMCRolePrincipal.BANNED_ROLE)) {
0746:                    serviceRole = ProvisionRequest.DP_BANNED;
0747:                } else if (rPrincipal.equals(CMCRolePrincipal.REJECTED_ROLE)) {
0748:                    serviceRole = ProvisionRequest.DP_REJECTED;
0749:                } else if (rPrincipal.equals(CMCRolePrincipal.INVITED_ROLE)) {
0750:                    serviceRole = ProvisionRequest.DP_INVITED;
0751:                } else if (rPrincipal.equals(CMCRolePrincipal.DISABLED_ROLE)) {
0752:                    serviceRole = ProvisionRequest.DP_DISABLED_COMMUNITY;
0753:                } else if (rPrincipal.equals(CMCRolePrincipal.DELETED_ROLE)) {
0754:                    serviceRole = ProvisionRequest.DP_DELETED_COMMUNITY;
0755:                } else {
0756:                    throw new CommunityException(
0757:                            "CommunityImpl.convertToServiceRole(): invalid role="
0758:                                    + rPrincipal.toString());
0759:                }
0760:
0761:                return serviceRole;
0762:            }
0763:
0764:            /**
0765:             * Provision a service
0766:             *
0767:             * @param cPrincipal <code>CommunityPrincipal</code> for which this service is provisioned
0768:             * @param event the event for which the service is provisioned
0769:             * @param channelName name of the channels to be provisioned
0770:             * @param mergedDPRoots a map mapping <code>CMCRolePrincipal</code> to its corresponding <code>DPRoot</code>
0771:             * @throws com.sun.portal.community.mgmt.CommunityException
0772:             * @return a map mapping <code>CMCRolePrincipal</code> to its corresponding display profile document
0773:             */
0774:            protected Map provisionServiceHelper(CMCPrincipal cPrincipal,
0775:                    String event, String channelName, Map mergedDPRoots)
0776:                    throws ServiceException, CommunityException {
0777:
0778:                if (logger.isLoggable(Level.FINER)) {
0779:                    logger.entering("CommunityImpl", "provisionServiceHelper",
0780:                            new Object[] { cPrincipal, event, channelName });
0781:                }
0782:
0783:                //
0784:                // find the DPChannel object that corresponds to the channel name
0785:                //
0786:                DPChannel dpChannel = null;
0787:                for (Iterator r = mergedDPRoots.values().iterator(); r
0788:                        .hasNext()
0789:                        && dpChannel == null;) {
0790:                    DPRoot mergedDPRoot = (DPRoot) r.next();
0791:                    dpChannel = mergedDPRoot.getChannel(channelName);
0792:                }
0793:
0794:                if (dpChannel == null) {
0795:                    throw new CommunityException(
0796:                            "CommunityImpl.provisionService(): failed to find channel element for channelName="
0797:                                    + channelName
0798:                                    + ", cPrincipal="
0799:                                    + cPrincipal);
0800:                }
0801:
0802:                //
0803:                // get Service instance
0804:                //
0805:                Service service = _serviceRegistry.getService(dpChannel);
0806:
0807:                //
0808:                // prepare provision request/response
0809:                //
0810:                String cpId = cPrincipal.toString();
0811:                ProvisionRequest pReq = new ProvisionRequest(event, req,
0812:                        ssoToken, mergedDPRoots, cpId, channelName);
0813:                ProvisionResponse pRes = new ProvisionResponse(res);
0814:
0815:                //
0816:                // invoke provision
0817:                //
0818:                service.handleProvisionEvent(pReq, pRes);
0819:
0820:                if (logger.isLoggable(Level.FINER)) {
0821:                    logger.exiting("CommunityImpl", "provisionServiceHelper",
0822:                            pRes);
0823:                }
0824:
0825:                return mergedDPRoots;
0826:            }
0827:
0828:            /**
0829:             * convert role representation used in service provisioning to CMCRolePrincipal
0830:             * todo: would be nice if this conversion doesn't have to take place.
0831:             *      make it a consipiracy that the CMCRolePrincipal and ProvisionRequest
0832:             *      use the same role representation
0833:             */
0834:            public static CMCRolePrincipal convertToCMCRolePrincipal(
0835:                    String serviceDPType) throws CommunityException {
0836:
0837:                CMCRolePrincipal rPrincipal = null;
0838:                if (serviceDPType.equals(ProvisionRequest.DP_MEMBER)) {
0839:                    rPrincipal = CMCRolePrincipal.MEMBER_ROLE;
0840:                } else if (serviceDPType.equals(ProvisionRequest.DP_OWNER)) {
0841:                    rPrincipal = CMCRolePrincipal.OWNER_ROLE;
0842:                } else if (serviceDPType.equals(ProvisionRequest.DP_VISITOR)) {
0843:                    rPrincipal = CMCRolePrincipal.VISITOR_ROLE;
0844:                } else if (serviceDPType.equals(ProvisionRequest.DP_INVITED)) {
0845:                    rPrincipal = CMCRolePrincipal.INVITED_ROLE;
0846:                } else if (serviceDPType.equals(ProvisionRequest.DP_BANNED)) {
0847:                    rPrincipal = CMCRolePrincipal.BANNED_ROLE;
0848:                } else if (serviceDPType.equals(ProvisionRequest.DP_PENDING)) {
0849:                    rPrincipal = CMCRolePrincipal.PENDING_ROLE;
0850:                } else if (serviceDPType.equals(ProvisionRequest.DP_REJECTED)) {
0851:                    rPrincipal = CMCRolePrincipal.REJECTED_ROLE;
0852:                } else if (serviceDPType
0853:                        .equals(ProvisionRequest.DP_DISABLED_COMMUNITY)) {
0854:                    rPrincipal = CMCRolePrincipal.DISABLED_ROLE;
0855:                } else if (serviceDPType
0856:                        .equals(ProvisionRequest.DP_DELETED_COMMUNITY)) {
0857:                    rPrincipal = CMCRolePrincipal.DELETED_ROLE;
0858:
0859:                } else {
0860:                    throw new CommunityException("unknown serviceDPType="
0861:                            + serviceDPType);
0862:                }
0863:
0864:                return rPrincipal;
0865:            }
0866:
0867:            /**
0868:             * Provision services for a user.
0869:             *
0870:             * @param cNode <code>CommunityNode</code> for which this service is provisioned for
0871:             * @param userId ID of the user for whom the service is provisioned
0872:             * @param rPrincipal <code>CMCRolePrincipal</code> for which the service is provisioned
0873:             * @throws com.sun.portal.community.mgmt.CommunityException
0874:             */
0875:            protected void provisionUserServices(CMCPrincipal cmcp,
0876:                    String userId, CMCRolePrincipal rPrincipal)
0877:                    throws CommunityServiceException, CommunityException {
0878:
0879:                provisionUserServicesHelper(cmcp, userId, rPrincipal, true);
0880:            }
0881:
0882:            /**
0883:             * Unprovision services for a user.
0884:             *
0885:             * @param cNode <code>CommunityNode</code> for which this service is unprovisioned for
0886:             * @param userId ID of the user for whom the service is unprovisioned
0887:             * @param rPrincipal <code>CMCRolePrincipal</code> for which the service is unprovisioned
0888:             * @throws com.sun.portal.community.mgmt.CommunityException
0889:             */
0890:            protected void unprovisionUserServices(CMCPrincipal cmcp,
0891:                    String userId, CMCRolePrincipal rPrincipal)
0892:                    throws CommunityServiceException, CommunityException {
0893:
0894:                provisionUserServicesHelper(cmcp, userId, rPrincipal, false);
0895:            }
0896:
0897:            protected void provisionUserServicesHelper(CMCPrincipal cmcp,
0898:                    String userId, CMCRolePrincipal rPrincipal,
0899:                    boolean doProvision) throws CommunityServiceException,
0900:                    CommunityException {
0901:
0902:                byte[] dpDoc = getCommunityDP(cmcNode, rPrincipal);
0903:
0904:                if (dpDoc != null) {
0905:                    //
0906:                    // collect names of the channels being used for the role in the community
0907:                    //
0908:                    Set dpDocs = new HashSet();
0909:                    dpDocs.add(dpDoc);
0910:                    Set channelNames = collectChannelNames(dpDocs);
0911:
0912:                    //
0913:                    // get merged dproot
0914:                    //
0915:                    Map dpRoots = new HashMap();
0916:                    dpRoots.put(rPrincipal, dpDoc);
0917:                    DPRoot dpRoot = (DPRoot) getMergedDPRoots(dpRoots).values()
0918:                            .iterator().next();
0919:
0920:                    //
0921:                    // [un]provision channels
0922:                    //
0923:                    CommunityServiceException cse = null;
0924:                    for (Iterator i = channelNames.iterator(); i.hasNext();) {
0925:                        String channelName = (String) i.next();
0926:                        try {
0927:                            if (doProvision) {
0928:                                provisionUserService(cmcp, userId, channelName,
0929:                                        dpRoot, rPrincipal);
0930:                            } else {
0931:                                unprovisionUserService(cmcp, userId,
0932:                                        channelName, dpRoot, rPrincipal);
0933:                            }
0934:
0935:                        } catch (Exception ex) {
0936:                            // log it
0937:                            ex.printStackTrace();
0938:                            if (logger.isLoggable(Level.INFO)) {
0939:                                logRecord(logger, Level.INFO,
0940:                                        doProvision ? "PSCPM_CSPCI00314"
0941:                                                : "PSCPM_CSPCI00315", ex,
0942:                                        new Object[] {
0943:                                                cmcp.toString(),
0944:                                                channelName,
0945:                                                userId,
0946:                                                RoleId.valueOf(rPrincipal
0947:                                                        .getName()) });
0948:                            }
0949:
0950:                            // prepare exception
0951:                            if (cse == null) {
0952:                                cse = new CommunityServiceException(null);
0953:                            }
0954:                            CommunityUserServiceExceptionEntry cusee = new CommunityUserServiceExceptionEntry(
0955:                                    cmcp.toString(), channelName, userId,
0956:                                    RoleId.valueOf(rPrincipal.getName()), ex);
0957:                            cse.addEntry(cusee);
0958:
0959:                        }
0960:                    }
0961:
0962:                    if (cse != null) {
0963:                        throw cse;
0964:                    }
0965:                }
0966:            }
0967:
0968:            /**
0969:             * Provision a service for a user.
0970:             *
0971:             * @param cPrincipal <code>CommunityPrincipal</code> for which this service is provisioned for
0972:             * @param userId ID of the user for whom the service is provisioned
0973:             * @param dpRoot DPRoot of the role for the given community
0974:             * @throws com.sun.portal.community.mgmt.CommunityException
0975:             */
0976:            protected void provisionUserService(CMCPrincipal cPrincipal,
0977:                    String userId, String channelName, DPRoot dpRoot,
0978:                    CMCRolePrincipal rPrincipal) throws ServiceException,
0979:                    CommunityException {
0980:
0981:                provisionUserServiceHelper(cPrincipal, userId, channelName,
0982:                        dpRoot, rPrincipal, true);
0983:            }
0984:
0985:            /**
0986:             * Unprovision a service for a user.
0987:             *
0988:             * @param cPrincipal <code>CommunityPrincipal</code> for which this service is unprovisioned for
0989:             * @param userId ID of the user for whom the service is unprovisioned
0990:             * @param dpRoot DPRoot of the role for the given community
0991:             * @throws com.sun.portal.community.mgmt.CommunityException
0992:             */
0993:            protected void unprovisionUserService(CMCPrincipal cPrincipal,
0994:                    String userId, String channelName, DPRoot dpRoot,
0995:                    CMCRolePrincipal rPrincipal) throws ServiceException,
0996:                    CommunityException {
0997:
0998:                provisionUserServiceHelper(cPrincipal, userId, channelName,
0999:                        dpRoot, rPrincipal, false);
1000:            }
1001:
1002:            protected void provisionUserServiceHelper(CMCPrincipal cPrincipal,
1003:                    String userId, String channelName, DPRoot dpRoot,
1004:                    CMCRolePrincipal rPrincipal, boolean doProvision)
1005:                    throws ServiceException, CommunityException {
1006:
1007:                if (logger.isLoggable(Level.FINER)) {
1008:                    logger.entering("CommunityImpl",
1009:                            "provisionUserServiceHelper", new Object[] {
1010:                                    cPrincipal.toString(),
1011:                                    rPrincipal.toString(), userId, channelName,
1012:                                    new Boolean(doProvision) });
1013:                }
1014:
1015:                //
1016:                // get the DPChannel object that corresponds to the channel name
1017:                //
1018:                DPChannel dpChannel = dpRoot.getChannel(channelName);
1019:                Service service = _serviceRegistry.getService(dpChannel);
1020:
1021:                //
1022:                // prepare membership request/response
1023:                //
1024:                String cpId = cPrincipal.toString();
1025:                MembershipRequest mReq = new MembershipRequest(req, ssoToken,
1026:                        dpRoot, convertToServiceRole(rPrincipal), cpId,
1027:                        channelName, userId);
1028:                MembershipResponse mRes = new MembershipResponse(res);
1029:
1030:                //
1031:                // invoke user [un]provision
1032:                //
1033:                if (doProvision) {
1034:                    service.memberAdded(mReq, mRes);
1035:                } else {
1036:                    service.memberRemoved(mReq, mRes);
1037:                }
1038:
1039:                if (logger.isLoggable(Level.FINER)) {
1040:                    logger.exiting("CommunityImpl",
1041:                            "provisionUserServiceHelper");
1042:                }
1043:            }
1044:
1045:            /**
1046:             * Reprovision all services for the given event.
1047:             *
1048:             * @throws com.sun.portal.community.mgmt.CommunityException
1049:             */
1050:            void reprovisionServices(String event)
1051:                    throws CommunityServiceException, CommunityException {
1052:                //
1053:                // get community dp's
1054:                //
1055:                Map dpDocs = getCommunityDPs(cmcNode);
1056:
1057:                //
1058:                // collect a set (union) of channel names from the community dp's
1059:                //
1060:                Set channelNames = collectChannelNames(dpDocs.values());
1061:
1062:                //
1063:                // get merged dpRoot for each role
1064:                //
1065:                Map mergedDPRoots = getMergedDPRoots(dpDocs);
1066:
1067:                //
1068:                // reprovision services
1069:                //
1070:                CommunityServiceResult csr = provisionServicesHelper(cmcNode,
1071:                        event, channelNames, mergedDPRoots);
1072:                // if errors were found, prepare to throw CommunityServiceException
1073:                CommunityServiceException serviceError = null;
1074:                if (csr.hasErrors()) {
1075:                    serviceError = new CommunityServiceException(mergedDPRoots);
1076:                    for (Iterator i = csr.getErrors().iterator(); i.hasNext();) {
1077:                        serviceError
1078:                                .addEntry((CommunityServiceExceptionEntry) i
1079:                                        .next());
1080:                    }
1081:                }
1082:
1083:                //
1084:                // throw CommunityServiceException if any
1085:                //
1086:                if (serviceError != null) {
1087:                    throw serviceError;
1088:                }
1089:            }
1090:
1091:            void unprovisionServices() throws CommunityServiceException,
1092:                    CommunityException {
1093:
1094:                //
1095:                // get community dp's
1096:                //
1097:                Map dpDocs = getCommunityDPs(cmcNode);
1098:
1099:                //
1100:                // collect a set (union) of channel names from the community dp's
1101:                //
1102:                Set channelNames = collectChannelNames(dpDocs.values());
1103:
1104:                //
1105:                // get merged dpRoot for each role
1106:                //
1107:                Map mergedDPRoots = getMergedDPRoots(dpDocs);
1108:
1109:                //
1110:                // unprovision services
1111:                // note: we're not explicitly unprovisioning individual users
1112:                //
1113:                CommunityServiceResult csr = provisionServicesHelper(cmcNode,
1114:                        ProvisionRequest.EVENT_TYPE_DESTROYED, channelNames,
1115:                        mergedDPRoots);
1116:                // if errors were found, prepare to throw CommunityServiceException
1117:                CommunityServiceException serviceError = null;
1118:                if (csr.hasErrors()) {
1119:                    serviceError = new CommunityServiceException(mergedDPRoots);
1120:                    for (Iterator i = csr.getErrors().iterator(); i.hasNext();) {
1121:                        serviceError
1122:                                .addEntry((CommunityServiceExceptionEntry) i
1123:                                        .next());
1124:                    }
1125:                }
1126:
1127:                //
1128:                // throw CommunityServiceException if any
1129:                //
1130:                if (serviceError != null) {
1131:                    throw serviceError;
1132:                }
1133:            }
1134:
1135:            /**
1136:             * Get community display profiles for all roles
1137:             *
1138:             * @param cNode <code>CommunityNode</code> to operate on
1139:             * @return a map mapping <code>CMCRolePrincipal</code> to its corresponding display profile document
1140:             */
1141:            protected Map getCommunityDPs(CMCNode cNode)
1142:                    throws CommunityException {
1143:
1144:                ConfigTable dpCT = null;
1145:                try {
1146:                    dpCT = cNode.getDPDocuments();
1147:                } catch (CMCException ce) {
1148:                    throw new CommunityException(
1149:                            "CommunityImpl.getCommunityDPs(): failed to fetch community dp for cNode="
1150:                                    + cNode, ce);
1151:                }
1152:
1153:                //
1154:                // convert to map
1155:                //
1156:                Map dpDocs = new HashMap();
1157:                Set keys = dpCT.getConfigKeys();
1158:                if (keys != null && keys.size() > 0) {
1159:                    for (Iterator i = keys.iterator(); i.hasNext();) {
1160:                        ConfigTable.ConfigKey key = (ConfigTable.ConfigKey) i
1161:                                .next();
1162:                        byte[] dpDoc = (byte[]) dpCT.get(key);
1163:                        if (dpDoc != null) {
1164:                            dpDocs.put(key.getRolePrincipal(), dpDoc);
1165:                        }
1166:                    }
1167:                }
1168:
1169:                return dpDocs;
1170:            }
1171:
1172:            /**
1173:             * Get community display profile for the given DPName
1174:             *
1175:             * @param dpName <code>DPName</code> for which to retrieve the display profile
1176:             * @return display profile document
1177:             */
1178:            public byte[] getDP(DPName dpName) throws CommunityException {
1179:
1180:                CMCRolePrincipal rPrincipal = TypeConverter
1181:                        .dpNameToCMCRolePrincipal(dpName);
1182:
1183:                return getCommunityDP(cmcNode, rPrincipal);
1184:            }
1185:
1186:            /**
1187:             * Set community display profile for the given DPName
1188:             *
1189:             * @param dpName <code>DPName</code> for which to set the display profile
1190:             * @param dp <code>byte[]</code> the display profile
1191:             */
1192:            public void setDP(DPName dpName, byte[] dp)
1193:                    throws CommunityException {
1194:
1195:                CMCRolePrincipal rPrincipal = TypeConverter
1196:                        .dpNameToCMCRolePrincipal(dpName);
1197:
1198:                Map m = new HashMap();
1199:                m.put(rPrincipal, dp);
1200:                setCommunityDPs(cmcNode, m);
1201:            }
1202:
1203:            /**
1204:             * Get community display profiles for the given role roles
1205:             *
1206:             * @param cNode <code>CommunityNode</code> from which to retrieve the display profile
1207:             * @param rPrincipal <code>CMCRolePrincipal</code> for which to retrieve the display profile
1208:             * @return display profile document
1209:             */
1210:            protected byte[] getCommunityDP(CMCNode cNode,
1211:                    CMCRolePrincipal rPrincipal) throws CommunityException {
1212:
1213:                //
1214:                // get display profile for the given community and the given role
1215:                //
1216:                Set rolePrincipals = new HashSet();
1217:                rolePrincipals.add(rPrincipal);
1218:                ConfigTable dpCT = null;
1219:                try {
1220:                    dpCT = cNode.getDPDocuments(rolePrincipals);
1221:                } catch (CMCException ce) {
1222:                    throw new CommunityException(
1223:                            "CommunityImpl.getCommunityDP(): failed to fetch community dp for cNode="
1224:                                    + cNode, ce);
1225:                }
1226:
1227:                //
1228:                // get community principal
1229:                //
1230:                CMCPrincipal cPrincipal = null;
1231:                try {
1232:                    cPrincipal = cNode.getCMCPrincipal();
1233:                } catch (CMCException ce) {
1234:                    throw new CommunityException(
1235:                            "CommunityImpl.getCommunityDP(): failed to get community principal.  cNode="
1236:                                    + cNode, ce);
1237:                }
1238:
1239:                byte[] dpDoc = (byte[]) dpCT.get(new ConfigTable.ConfigKey(
1240:                        cPrincipal, rPrincipal));
1241:
1242:                return dpDoc;
1243:            }
1244:
1245:            /**
1246:             * Add a user to the community.  Invoke user provision on all services offered
1247:             * by the community.
1248:             */
1249:
1250:            public void addUser(String userId, RoleId rid)
1251:                    throws CommunityServiceException, CommunityException {
1252:                CMCRolePrincipal rPrincipal = TypeConverter
1253:                        .roleIdToPrincipal(rid);
1254:
1255:                CommunityServiceException serviceError = null;
1256:
1257:                try {
1258:
1259:                    CommunityUser user = new CommunityUserImpl(req, userId);
1260:                    Map membershipMap = user.getMembership();
1261:                    if (membershipMap != null) {
1262:                        //
1263:                        // Get the existing roles of the user in the community
1264:                        // and iterate through them to make sure the new role
1265:                        // being added will not invalidate the user membership
1266:                        // state.
1267:                        //
1268:                        Set existingRoles = (Set) membershipMap.get(cid);
1269:                        String msg;
1270:                        if (existingRoles != null) {
1271:                            msg = "Existing roles:" + existingRoles.toString();
1272:                        } else {
1273:                            msg = "Existing roles is null";
1274:                        }
1275:                        logger.log(Level.FINE, msg);
1276:
1277:                        if (existingRoles != null) {
1278:                            Iterator iter = existingRoles.iterator();
1279:                            while (iter.hasNext()) {
1280:                                RoleId existingRoleId = (RoleId) iter.next();
1281:                                Integer stat = RoleAssignment.validate(
1282:                                        existingRoleId, rid);
1283:
1284:                                String message = "Existing role:"
1285:                                        + existingRoleId + " :New Role:" + rid
1286:                                        + ":status:" + stat;
1287:                                logger.log(Level.FINE, message);
1288:
1289:                                //
1290:                                // No-op - just return
1291:                                //
1292:                                if (stat.equals(RoleAssignment.NOOP)) {
1293:                                    return;
1294:                                }
1295:                                //
1296:                                // Invalid - throw exception
1297:                                //
1298:                                else if (stat.equals(RoleAssignment.INVALID)) {
1299:                                    throw new RoleAssignmentException(cid,
1300:                                            userId, existingRoleId, rid);
1301:                                }
1302:                                //
1303:                                // Replace - remove the old one
1304:                                //
1305:                                else if (stat.equals(RoleAssignment.REPLACE)) {
1306:                                    removeUser(userId, existingRoleId);
1307:                                }
1308:                            }
1309:
1310:                        }
1311:                        // finally
1312:                        // add the new role
1313:                        //
1314:                        addUser(cmcNode,
1315:                                LDAPDN.normalize(userId.toLowerCase()),
1316:                                rPrincipal);
1317:                    }
1318:
1319:                } catch (CommunityServiceException cse) {
1320:                    // save the error
1321:                    serviceError = cse;
1322:                }
1323:
1324:                Set cmcMembership = CommunityUserMembershipThreadLocalizer
1325:                        .get(userId);
1326:                if (cmcMembership != null) {
1327:                    // update membership cache
1328:                    CMCPrincipal cmcp = TypeConverter
1329:                            .communityIdToPrincipal(getCommunityId());
1330:                    CMCRolePrincipal cmcrp = TypeConverter
1331:                            .roleIdToPrincipal(rid);
1332:                    ConfigKey ck = new ConfigKey(cmcp, cmcrp);
1333:                    cmcMembership.add(ck);
1334:                }
1335:
1336:                //
1337:                // throw CommunityServiceException if any
1338:                //
1339:                if (serviceError != null) {
1340:                    throw serviceError;
1341:                }
1342:            }
1343:
1344:            private void addUser(CMCNode cNode, String userId,
1345:                    CMCRolePrincipal rPrincipal)
1346:                    throws CommunityServiceException, CommunityException {
1347:                //
1348:                // check if the operation is supported
1349:                //
1350:                boolean supportsAddUsers = false;
1351:                try {
1352:                    supportsAddUsers = cNode.supportsAddUsers();
1353:                } catch (CMCException ce) {
1354:                    throw new CommunityException(ce);
1355:                }
1356:
1357:                if (!supportsAddUsers) {
1358:                    throw new CommunityException(
1359:                            "adding users is not supported for this community, communityNode="
1360:                                    + cNode);
1361:                }
1362:
1363:                //
1364:                // add user to the community node
1365:                //
1366:                Set uids = new HashSet();
1367:                uids.add(userId);
1368:                try {
1369:                    cNode.addUsers(uids, rPrincipal);
1370:                } catch (CMCException ce) {
1371:                    throw new CommunityException(
1372:                            "failed to add user to the community. communityNode="
1373:                                    + cNode + ", userId=" + userId, ce);
1374:                }
1375:
1376:                if (logger.isLoggable(Level.INFO)) {
1377:                    logger.log(Level.INFO, "PSCPM_CSPCI00311", new Object[] {
1378:                            userId, rPrincipal.toString() });
1379:                }
1380:
1381:                //
1382:                // provision service for the user
1383:                //
1384:                CMCPrincipal cmcp;
1385:                try {
1386:                    cmcp = cNode.getCMCPrincipal();
1387:                } catch (CMCException cmce) {
1388:                    throw new CommunityException(cmce);
1389:                }
1390:                provisionUserServices(cmcp, userId, rPrincipal);
1391:            }
1392:
1393:            /**
1394:             * Remove the user from the community.
1395:             */
1396:            public void removeUser(String userId, RoleId rid)
1397:                    throws CommunityServiceException, CommunityException {
1398:                CMCRolePrincipal rPrincipal = TypeConverter
1399:                        .roleIdToPrincipal(rid);
1400:                removeUser(cmcNode, LDAPDN.normalize(userId.toLowerCase()),
1401:                        rPrincipal);
1402:
1403:                Set cmcMembership = CommunityUserMembershipThreadLocalizer
1404:                        .get(userId);
1405:                if (cmcMembership != null) {
1406:                    // update membership cache
1407:                    CMCPrincipal cmcp = TypeConverter
1408:                            .communityIdToPrincipal(getCommunityId());
1409:                    CMCRolePrincipal cmcrp = TypeConverter
1410:                            .roleIdToPrincipal(rid);
1411:                    ConfigKey ck = new ConfigKey(cmcp, cmcrp);
1412:                    cmcMembership.remove(ck);
1413:                }
1414:            }
1415:
1416:            private void removeUser(CMCNode cNode, String userId,
1417:                    CMCRolePrincipal rPrincipal)
1418:                    throws CommunityServiceException, CommunityException {
1419:                //
1420:                // check if the operation is supported
1421:                //
1422:                boolean supportsRemoveUsers = false;
1423:                try {
1424:                    supportsRemoveUsers = cmcNode.supportsRemoveUsers();
1425:                } catch (CMCException ce) {
1426:                    throw new CommunityException(ce);
1427:                }
1428:
1429:                if (!supportsRemoveUsers) {
1430:                    throw new CommunityException(
1431:                            "Removing users is not supported for this community, communityNode="
1432:                                    + cNode);
1433:                }
1434:
1435:                //
1436:                // remove user from the community node
1437:                //
1438:                Set uids = new HashSet();
1439:                uids.add(userId);
1440:                Set roles = new HashSet();
1441:                roles.add(rPrincipal);
1442:                try {
1443:                    cmcNode.removeUsers(uids, roles);
1444:                } catch (CMCException ce) {
1445:                    throw new CommunityException(
1446:                            "failed to add user to the community. communityNode="
1447:                                    + cNode + ", userId=" + userId, ce);
1448:                }
1449:
1450:                //
1451:                // unprovision services for the user
1452:                //
1453:                //
1454:                CMCPrincipal cmcp;
1455:                try {
1456:                    cmcp = cNode.getCMCPrincipal();
1457:                } catch (CMCException cmce) {
1458:                    throw new CommunityException(cmce);
1459:                }
1460:                unprovisionUserServices(cmcp, userId, rPrincipal);
1461:            }
1462:
1463:            public Set getUsers() throws CommunityException {
1464:                return getUsers(null);
1465:            }
1466:
1467:            public Set getUsers(Set roleIds) throws CommunityException {
1468:                Set members = new HashSet();
1469:                try {
1470:                    if (roleIds == null || roleIds.size() == 0) {
1471:                        members = cmcNode.getUsers();
1472:                    } else {
1473:                        Set rolePrincipals = TypeConverter
1474:                                .roleIdsToPrincipals(roleIds);
1475:                        members = cmcNode.getUsers(rolePrincipals);
1476:                    }
1477:                } catch (CMCException ce) {
1478:                    throw new CommunityException(ce);
1479:                }
1480:                return members;
1481:            }
1482:
1483:            /**
1484:             * Adds a member to the community. This method assigns the user RoleId.MEMBER role.
1485:             */
1486:            public void addMember(String userId)
1487:                    throws CommunityServiceException, CommunityException {
1488:                addUser(userId, RoleId.MEMBER_ROLE);
1489:            }
1490:
1491:            /**
1492:             * Adds a owner. This method assigns the user RoleId.OWNER role.
1493:             */
1494:            public void addOwner(String userId)
1495:                    throws CommunityServiceException, CommunityException {
1496:                addUser(userId, RoleId.OWNER_ROLE);
1497:            }
1498:
1499:            /**
1500:             * Invite User to the community
1501:             */
1502:            public void inviteUser(String userId, String message)
1503:                    throws CommunityServiceException, CommunityException {
1504:                addUser(userId, RoleId.INVITED_ROLE);
1505:
1506:                //
1507:                // send notification
1508:                //
1509:                try {
1510:                    String senderId = LDAPDN.normalize(ssoToken.getPrincipal()
1511:                            .getName().toLowerCase());
1512:                    sendNotification(NotificationType.USER_INVITED, senderId,
1513:                            userId, message);
1514:                } catch (NotificationException ne) {
1515:                    // not a fatal error.  just log it
1516:                    if (logger.isLoggable(Level.SEVERE)) {
1517:                        logRecord(logger, Level.SEVERE, "PSCPM_CSPCI00317", ne,
1518:                                new Object[] { cid });
1519:                    }
1520:                } catch (CommunityException ce) {
1521:                    // not a fatal error. just log it.
1522:                    if (logger.isLoggable(Level.SEVERE)) {
1523:                        logRecord(logger, Level.SEVERE, "PSCPM_CSPCI00317", ce,
1524:                                new Object[] { cid });
1525:                    }
1526:                } catch (SSOException se) {
1527:                    // not a fatal error. just log it.
1528:                    if (logger.isLoggable(Level.SEVERE)) {
1529:                        logRecord(logger, Level.SEVERE, "PSCPM_CSPCI00317", se,
1530:                                new Object[] { cid });
1531:                    }
1532:                }
1533:            }
1534:
1535:            /**
1536:             * Accept invitation to the community
1537:             */
1538:            public void denyInvitation(String userId)
1539:                    throws CommunityServiceException, CommunityException {
1540:                removeUser(userId, RoleId.INVITED_ROLE);
1541:            }
1542:
1543:            /**
1544:             * Accept invitation to the community
1545:             */
1546:            public void acceptInvitation(String userId)
1547:                    throws CommunityServiceException, CommunityException {
1548:                addUser(userId, RoleId.MEMBER_ROLE);
1549:            }
1550:
1551:            /**
1552:             * Register the membership request for a user
1553:             */
1554:            public void requestMembership(String userId)
1555:                    throws CommunityServiceException, CommunityException {
1556:                addUser(userId, RoleId.PENDING_ROLE);
1557:            }
1558:
1559:            /**
1560:             * Reject the membership request
1561:             */
1562:            public void rejectMembershipRequest(String userId)
1563:                    throws CommunityServiceException, CommunityException {
1564:                addUser(userId, RoleId.REJECTED_ROLE);
1565:            }
1566:
1567:            /**
1568:             * Approve the membership request for the user
1569:             */
1570:            public void approveMembershipRequest(String userId)
1571:                    throws CommunityServiceException, CommunityException {
1572:                addUser(userId, RoleId.MEMBER_ROLE);
1573:            }
1574:
1575:            /**
1576:             * Ban a user from the community
1577:             */
1578:            public void banUser(String userId)
1579:                    throws CommunityServiceException, CommunityException {
1580:                addUser(userId, RoleId.BANNED_ROLE);
1581:            }
1582:
1583:            /**
1584:             * Unban a user from the community
1585:             */
1586:            public void unbanUser(String userId)
1587:                    throws CommunityServiceException, CommunityException {
1588:                removeUser(userId, RoleId.BANNED_ROLE);
1589:            }
1590:
1591:            /**
1592:             * Get the description for the community
1593:             */
1594:            public String getDescription() throws CommunityException {
1595:                try {
1596:                    if (!cmcNode.supportsDescription()) {
1597:                        throw new CommunityException(
1598:                                "CommunityManagerImpl.supportsDescription(): Secure functionality is not supported.  cmcNode="
1599:                                        + cmcNode);
1600:                    }
1601:                    String description = cmcNode.getDescription();
1602:
1603:                    //
1604:                    // migrating the data from search to database
1605:                    //
1606:                    if (description == null) {
1607:                        description = getDescriptionFromSearchDatabase();
1608:                        if (description != null) {
1609:                            cmcNode.setDescription(description);
1610:                        }
1611:                    }
1612:                    return description;
1613:
1614:                } catch (CMCException ce) {
1615:                    throw new CommunityException(
1616:                            "CommunityManagerImpl.supportsDescription(): cmcNode="
1617:                                    + cmcNode, ce);
1618:                }
1619:
1620:            }
1621:
1622:            /**
1623:             *Set the description for the community
1624:             */
1625:            public void setDescription(String description)
1626:                    throws CommunityException {
1627:                try {
1628:                    if (!cmcNode.supportsDescription()) {
1629:                        throw new CommunityException(
1630:                                "CommunityManagerImpl.supportsDescription(): Secure functionality is not supported.  cmcNode="
1631:                                        + cmcNode);
1632:                    }
1633:                    cmcNode.setDescription(description);
1634:                } catch (CMCException ce) {
1635:                    throw new CommunityException(
1636:                            "CommunityManagerImpl.supportsDescription(): cmcNode="
1637:                                    + cmcNode, ce);
1638:                }
1639:
1640:                reindex();
1641:            }
1642:
1643:            /**
1644:             *Get the classification for the community
1645:             */
1646:            public String getCategory() throws CommunityException {
1647:                try {
1648:                    if (!cmcNode.supportsCategory()) {
1649:                        throw new CommunityException(
1650:                                "CommunityManagerImpl.setCategory(): Secure functionality is not supported.  cmcNode="
1651:                                        + cmcNode);
1652:                    }
1653:                    //
1654:                    // call getDescription and getCategory method 
1655:                    // to migrate these values(7.0/JES5) from search database to
1656:                    // community database.
1657:                    //
1658:                    String category = cmcNode.getCategory();
1659:                    if (category == null) {
1660:                        category = getCategoryFromSearchDatabase();
1661:                        if (category != null) {
1662:                            cmcNode.setCategory(category);
1663:                        }
1664:                    }
1665:                    return category;
1666:                } catch (CMCException ce) {
1667:                    throw new CommunityException(
1668:                            "CommunityManagerImpl.setCategory(): cmcNode="
1669:                                    + cmcNode, ce);
1670:                }
1671:
1672:            }
1673:
1674:            /**
1675:             * Set the classification for the community
1676:             */
1677:
1678:            public void setCategory(String category) throws CommunityException {
1679:                try {
1680:                    if (!cmcNode.supportsCategory()) {
1681:                        throw new CommunityException(
1682:                                "CommunityManagerImpl.setCategory(): Secure functionality is not supported.  cNode="
1683:                                        + cmcNode);
1684:                    }
1685:                    cmcNode.setCategory(category);
1686:                } catch (CMCException ce) {
1687:                    throw new CommunityException(
1688:                            "CommunityManagerImpl.setCategory(): cmcNode="
1689:                                    + cmcNode, ce);
1690:                }
1691:
1692:                reindex();
1693:            }
1694:
1695:            /**
1696:             * Return true if the community membership is restricted.
1697:             */
1698:
1699:            public boolean isMembershipRestricted() throws CommunityException {
1700:                try {
1701:                    if (!cmcNode.supportsMembershipRestriction()) {
1702:                        throw new CommunityException(
1703:                                "CommunityManagerImpl.setMembershipRestricted(): Secure functionality is not supported.  cNode="
1704:                                        + cmcNode);
1705:                    }
1706:                    return cmcNode.isMembershipRestricted();
1707:                } catch (CMCException ce) {
1708:                    throw new CommunityException(
1709:                            "CommunityManagerImpl.setMembershipRestricted(): cmcNode="
1710:                                    + cmcNode, ce);
1711:                }
1712:
1713:            }
1714:
1715:            /**
1716:             * Set whether community membership is restricted.
1717:             */
1718:            public void setMembershipRestricted(boolean isMembershipRestricted)
1719:                    throws CommunityException {
1720:                try {
1721:                    if (!cmcNode.supportsMembershipRestriction()) {
1722:                        throw new CommunityException(
1723:                                "CommunityManagerImpl.setMembershipRestricted(): Secure functionality is not supported.  cNode="
1724:                                        + cmcNode);
1725:                    }
1726:                    cmcNode.setMembershipRestricted(isMembershipRestricted);
1727:                } catch (CMCException ce) {
1728:                    throw new CommunityException(
1729:                            "CommunityManagerImpl.setMembershipRestricted(): cmcNode="
1730:                                    + cmcNode, ce);
1731:                }
1732:
1733:            }
1734:
1735:            /**
1736:             * Returns true if the community content is secured based.
1737:             */
1738:            public boolean isSecure() throws CommunityException {
1739:                try {
1740:                    if (!cmcNode.supportsSecuring()) {
1741:                        throw new CommunityException(
1742:                                "CommunityManagerImpl.setSecure(): Secure functionality is not supported.  cNode="
1743:                                        + cmcNode);
1744:                    }
1745:                    return cmcNode.isSecure();
1746:                } catch (CMCException ce) {
1747:                    throw new CommunityException(
1748:                            "CommunityManagerImpl.setSecure(): cmcNode="
1749:                                    + cmcNode, ce);
1750:                }
1751:
1752:            }
1753:
1754:            /**
1755:             * Set whether the community content needs to be secured.
1756:             */
1757:            public void setSecure(boolean isSecure) throws CommunityException {
1758:                //
1759:                // Check if the operation is supported
1760:                //
1761:                try {
1762:                    if (!cmcNode.supportsSecuring()) {
1763:                        throw new CommunityException(
1764:                                "CommunityManagerImpl.setSecure(): Secure functionality is not supported.  cNode="
1765:                                        + cmcNode);
1766:                    }
1767:                    cmcNode.setSecure(isSecure);
1768:                    String readAcl = isSecure ? this .getCommunityId().getName()
1769:                            + ":" + RoleId.MEMBER_ROLE : "";
1770:                    this .secureSearchIndexForCommunityContent(readAcl);
1771:                } catch (CMCException ce) {
1772:                    throw new CommunityException(
1773:                            "CommunityManagerImpl.setSecure(): cmcNode="
1774:                                    + cmcNode, ce);
1775:                }
1776:
1777:            }
1778:
1779:            /**
1780:             * Returns whether community is listed or not
1781:             */
1782:            public boolean isListed() throws CommunityException {
1783:
1784:                //
1785:                // Check if the operation is supported
1786:                //
1787:                try {
1788:                    if (!cmcNode.supportsListing()) {
1789:                        throw new CommunityException(
1790:                                "CommunityManagerImpl.supportsListing(): Listing functionality is not supported.  cNode="
1791:                                        + cmcNode);
1792:                    }
1793:                    return cmcNode.isListed();
1794:                } catch (CMCException ce) {
1795:                    throw new CommunityException(
1796:                            "CommunityManagerImpl.isListed(): cmcNode="
1797:                                    + cmcNode, ce);
1798:                }
1799:
1800:            }
1801:
1802:            /**
1803:             * Sets whether community needs to be listed
1804:             */
1805:            public void setListed(boolean isListed) throws CommunityException {
1806:                //
1807:                // Check if the operation is supported
1808:                //
1809:                try {
1810:                    if (!cmcNode.supportsListing()) {
1811:                        throw new CommunityException(
1812:                                "CommunityManagerImpl.supportsListing(): Listing functionality is not supported.  cNode="
1813:                                        + cmcNode);
1814:                    }
1815:                    if (cmcNode.isListed() == isListed) {
1816:                        return;
1817:                    }
1818:                    cmcNode.setListed(isListed);
1819:                } catch (CMCException ce) {
1820:                    throw new CommunityException(
1821:                            "CommunityManagerImpl.isListed(): cmcNode="
1822:                                    + cmcNode, ce);
1823:                }
1824:
1825:                if (isListed == true) {
1826:                    reindex();
1827:                } else {
1828:                    //
1829:                    // call getDescription and getCategory method 
1830:                    // to migrate these values(7.0/JES5) from search database to
1831:                    // community database.
1832:
1833:                    getDescription();
1834:                    getCategory();
1835:
1836:                    //
1837:                    // remove the RD for this community so it can't be searched.
1838:                    //
1839:                    removeSearchIndexForCommunity();
1840:                }
1841:
1842:            }
1843:
1844:            //-----------------------------------------------------------------
1845:            // SEARCH RELATED METHODS
1846:            //
1847:            //------------------------------------------------------------------
1848:
1849:            String getSearchUrl() {
1850:                return CommunityProperties.getInstance().getSearchUrl();
1851:            }
1852:
1853:            String getSearchDbPrefix() {
1854:                return CommunityProperties.getInstance().getSearchDbPrefix();
1855:            }
1856:
1857:            public String getSearchDb() {
1858:                String pre = getSearchDbPrefix();
1859:                return pre + "_communities_" + getPortalId();
1860:            }
1861:
1862:            public String getContentsSearchDb() throws CommunityException {
1863:                CommunityManager cmgr = CommunityFactory.getInstance()
1864:                        .getCommunityManager(req, res);
1865:                return cmgr.getContentsSearchDb(getCommunityId());
1866:            }
1867:
1868:            public String getDiscussionsSearchDb() throws CommunityException {
1869:                CommunityManager cmgr = CommunityFactory.getInstance()
1870:                        .getCommunityManager(req, res);
1871:                return cmgr.getDiscussionsSearchDb(getCommunityId());
1872:            }
1873:
1874:            public List getContentsSearchDbs() throws CommunityException {
1875:                CommunityManager cmgr = CommunityFactory.getInstance()
1876:                        .getCommunityManager(req, res, ssoToken);
1877:                return cmgr.getContentsSearchDbs(getCommunityId());
1878:            }
1879:
1880:            void addSearchIndex(String category, String description,
1881:                    String ownerId) throws CommunityException {
1882:                SOIF doc = new SOIF("DOCUMENT", getCommunityId().toString());
1883:                doc.insert("title", getCommunityId().getName());
1884:                doc.insert("Author", ownerId);
1885:                if (category != null) {
1886:                    doc.insert("classification", category);
1887:                }
1888:                doc.insert("description", description);
1889:                try {
1890:                    URLConnection pc = new URL(getSearchUrl()).openConnection();
1891:                    pc.setAllowUserInteraction(true);
1892:                    pc.setUseCaches(false);
1893:                    pc.setDoOutput(true);
1894:                    pc.setDoInput(true);
1895:                    SOIFOutputStream sos = new SOIFOutputStream(pc
1896:                            .getOutputStream());
1897:                    pc.connect();
1898:                    SOIF hdr = new SOIF("RDMHEADER", "-");
1899:                    hdr.insert("rdm-type", "rd-submit-request");
1900:                    hdr.insert("submit-database", getSearchDb());
1901:                    sos.write(hdr);
1902:
1903:                    SOIF req = new SOIF("Request", "-");
1904:                    req.insert("submit-type", "nonpersistent");
1905:                    req.insert("submit-operation", "insert");
1906:                    //req.insert("submit-view", "classification,description");
1907:                    sos.write(req);
1908:                    if (logger.isLoggable(Level.INFO)) {
1909:                        logger.log(Level.INFO, "PSCPM_CSPCI00301", req);
1910:                    }
1911:
1912:                    sos.write(doc);
1913:                    if (logger.isLoggable(Level.INFO)) {
1914:                        logger.log(Level.INFO, "PSCPM_CSPCI00302", doc);
1915:                    }
1916:
1917:                    sos.close();
1918:
1919:                    SOIFInputStream sis = new SOIFInputStream(pc
1920:                            .getInputStream());
1921:                    SOIF s;
1922:                    if (logger.isLoggable(Level.INFO)) {
1923:                        while ((s = sis.readSOIF()) != null) {
1924:                            logger.log(Level.INFO, "PSCPM_CSPCI00303", s);
1925:                        }
1926:                    }
1927:                } catch (Exception e) {
1928:                    throw new CommunityException(e);
1929:                }
1930:            }
1931:
1932:            void removeSearchIndexForCommunity() throws CommunityException {
1933:                try {
1934:                    URLConnection pc = new URL(getSearchUrl()).openConnection();
1935:                    pc.setAllowUserInteraction(true);
1936:                    pc.setUseCaches(false);
1937:                    pc.setDoOutput(true);
1938:                    pc.setDoInput(true);
1939:                    SOIFOutputStream sos = new SOIFOutputStream(pc
1940:                            .getOutputStream());
1941:                    pc.connect();
1942:                    SOIF hdr = new SOIF("RDMHEADER", "-");
1943:                    hdr.insert("rdm-type", "rd-submit-request");
1944:                    hdr.insert("submit-database", getSearchDb());
1945:                    sos.write(hdr);
1946:
1947:                    SOIF req = new SOIF("Request", "-");
1948:                    req.insert("submit-type", "merged");
1949:                    req.insert("submit-operation", "delete");
1950:                    //req.insert("submit-view", "classification,description");
1951:                    sos.write(req);
1952:                    if (logger.isLoggable(Level.INFO)) {
1953:                        logger.log(Level.INFO, "PSCPM_CSPCI00304", req);
1954:                    }
1955:                    SOIF doc = new SOIF("DOCUMENT", getCommunityId().toString());
1956:                    sos.write(doc);
1957:                    if (logger.isLoggable(Level.INFO)) {
1958:                        logger.log(Level.INFO, "PSCPM_CSPCI00305", doc);
1959:                    }
1960:                    sos.close();
1961:
1962:                    SOIFInputStream sis = new SOIFInputStream(pc
1963:                            .getInputStream());
1964:                    SOIF s;
1965:                    if (logger.isLoggable(Level.INFO)) {
1966:                        while ((s = sis.readSOIF()) != null) {
1967:                            logger.log(Level.INFO, "PSCPM_CSPCI00306", s);
1968:                        }
1969:                    }
1970:                } catch (Exception e) {
1971:                    throw new CommunityException(e);
1972:                }
1973:
1974:            }
1975:
1976:            //
1977:            // TODO:Ask Allen why removeVirtualDatabase is not throwing exception
1978:            //
1979:
1980:            void removeSearchIndexForCommunityContent()
1981:                    throws CommunityException {
1982:                try {
1983:                    List contentDbs = getContentsSearchDbs();
1984:                    if (contentDbs != null) {
1985:                        Iterator ci = contentDbs.iterator();
1986:                        while (ci.hasNext()) {
1987:                            removeVirtualDatabase((String) ci.next());
1988:                        }
1989:                    }
1990:                } catch (Exception e) {
1991:                    throw new CommunityException(e);
1992:                }
1993:
1994:            }
1995:
1996:            void secureSearchIndexForCommunityContent(String ctyMemberRole)
1997:                    throws CommunityException {
1998:                try {
1999:                    SOIF s = new SOIF("Document", "-");
2000:                    s.insert("ReadACL", ctyMemberRole);
2001:                    List contentDbs = getContentsSearchDbs();
2002:                    if (contentDbs != null) {
2003:                        Iterator ci = contentDbs.iterator();
2004:                        while (ci.hasNext()) {
2005:                            this .updateVirtualDatabase((String) ci.next(), s);
2006:                        }
2007:                    }
2008:                } catch (Exception e) {
2009:                    throw new CommunityException(e);
2010:                }
2011:
2012:            }
2013:
2014:            protected SOIFInputStream getVirtualDatabaseRDs(String database) {
2015:                Search s = new Search();
2016:                s.setRDMServer(getSearchUrl());
2017:                s.setRDMType("rd-request");
2018:                s.setQueryLanguage("search");
2019:                s.setViewAttributes("url");
2020:                s.setScope("*");
2021:                s.setDatabase(database);
2022:                s.setViewHits(-1);
2023:                s.setSessionID(ssoToken.getTokenID().toString());
2024:                s.doQuery();
2025:                int docCount = s.getHitCount();
2026:                if (docCount > 0) {
2027:                    return s.getResultStream();
2028:                }
2029:                return null;
2030:            }
2031:
2032:            protected void updateVirtualDatabase(String database, SOIF s) {
2033:                SOIFInputStream resultStream = getVirtualDatabaseRDs(database);
2034:                if (resultStream != null) {
2035:
2036:                    try {
2037:                        URLConnection pc = new URL(getSearchUrl())
2038:                                .openConnection();
2039:                        pc.setAllowUserInteraction(true);
2040:                        pc.setUseCaches(false);
2041:                        pc.setDoOutput(true);
2042:                        pc.setDoInput(true);
2043:                        SOIFOutputStream sos = new SOIFOutputStream(pc
2044:                                .getOutputStream());
2045:                        pc.connect();
2046:
2047:                        SOIF hdr = new SOIF("RDMHEADER", "-");
2048:                        hdr.insert("rdm-type", "rd-submit-request");
2049:                        hdr.insert("submit-database", database);
2050:                        hdr.insert("rdm-access-token", ssoToken.getTokenID()
2051:                                .toString());
2052:                        sos.write(hdr);
2053:
2054:                        SOIF req = new SOIF("Request", "-");
2055:                        req.insert("submit-type", "nonpersistent");
2056:                        req.insert("submit-operation", "update");
2057:                        //req.insert("submit-view", "ReadACL");
2058:                        sos.write(req);
2059:                        if (logger.isLoggable(Level.INFO)) {
2060:                            logger.log(Level.INFO, "PSCPM_CSPCI00307", req);
2061:                        }
2062:
2063:                        SOIF soif;
2064:                        for (soif = resultStream.readSOIF(); soif != null; soif = resultStream
2065:                                .readSOIF()) {
2066:                            if (soif.getSchemaName().equalsIgnoreCase(
2067:                                    "document")) {
2068:                                soif.merge(s);
2069:                                sos.write(soif);
2070:                            }
2071:                        }
2072:                        sos.close();
2073:
2074:                        SOIFInputStream sis = new SOIFInputStream(pc
2075:                                .getInputStream());
2076:                        if (logger.isLoggable(Level.INFO)) {
2077:                            while ((soif = sis.readSOIF()) != null) {
2078:                                logger
2079:                                        .log(Level.INFO, "PSCPM_CSPCI00308",
2080:                                                soif);
2081:                            }
2082:                        }
2083:                    } catch (Exception e) {
2084:
2085:                    }
2086:                }
2087:            }
2088:
2089:            protected void removeVirtualDatabase(String database) {
2090:                SOIFInputStream resultStream = getVirtualDatabaseRDs(database);
2091:                if (resultStream != null) {
2092:                    try {
2093:                        URLConnection pc = new URL(getSearchUrl())
2094:                                .openConnection();
2095:                        pc.setAllowUserInteraction(true);
2096:                        pc.setUseCaches(false);
2097:                        pc.setDoOutput(true);
2098:                        pc.setDoInput(true);
2099:                        SOIFOutputStream sos = new SOIFOutputStream(pc
2100:                                .getOutputStream());
2101:                        pc.connect();
2102:
2103:                        SOIF hdr = new SOIF("RDMHEADER", "-");
2104:                        hdr.insert("rdm-type", "rd-submit-request");
2105:                        hdr.insert("submit-database", database);
2106:                        hdr.insert("rdm-access-token", ssoToken.getTokenID()
2107:                                .toString());
2108:                        sos.write(hdr);
2109:
2110:                        SOIF req = new SOIF("Request", "-");
2111:                        req.insert("submit-type", "merged");
2112:                        req.insert("submit-operation", "delete");
2113:                        //req.insert("submit-view", "classification,description");
2114:                        sos.write(req);
2115:                        if (logger.isLoggable(Level.INFO)) {
2116:                            logger.log(Level.INFO, "PSCPM_CSPCI00307", req);
2117:                        }
2118:
2119:                        SOIF soif;
2120:                        for (soif = resultStream.readSOIF(); soif != null; soif = resultStream
2121:                                .readSOIF()) {
2122:                            if (soif.getSchemaName().equalsIgnoreCase(
2123:                                    "document")) {
2124:                                sos.write(soif);
2125:                            }
2126:                        }
2127:                        sos.close();
2128:
2129:                        SOIFInputStream sis = new SOIFInputStream(pc
2130:                                .getInputStream());
2131:                        if (logger.isLoggable(Level.INFO)) {
2132:                            while ((soif = sis.readSOIF()) != null) {
2133:                                logger
2134:                                        .log(Level.INFO, "PSCPM_CSPCI00308",
2135:                                                soif);
2136:                            }
2137:                        }
2138:                    } catch (Exception e) {
2139:
2140:                    }
2141:
2142:                }
2143:            }
2144:
2145:            private String getDescriptionFromSearchDatabase()
2146:                    throws CommunityException {
2147:                return getAttributeFromSearchDatabase("description");
2148:
2149:            }
2150:
2151:            private String getCategoryFromSearchDatabase()
2152:                    throws CommunityException {
2153:                return getAttributeFromSearchDatabase("classification");
2154:
2155:            }
2156:
2157:            private String getAttributeFromSearchDatabase(String attrName)
2158:                    throws CommunityException {
2159:                try {
2160:                    Search s = new Search();
2161:                    s.setRDMServer(getSearchUrl());
2162:                    s.setRDMType("rd-request");
2163:                    s.setQueryLanguage("search");
2164:                    s.setScope("url = " + getCommunityId());
2165:                    s.setViewAttributes(attrName);
2166:                    s.setDatabase(getSearchDb());
2167:                    s.setFirstHit(1);
2168:                    s.setViewHits(1);
2169:                    s.doQuery();
2170:                    SOIFInputStream resultStream = s.getResultStream();
2171:                    SOIF soif;
2172:                    StringBuffer sb = new StringBuffer();
2173:                    for (soif = resultStream.readSOIF(); soif != null; soif = resultStream
2174:                            .readSOIF()) {
2175:                        if (soif.getSchemaName().equalsIgnoreCase("document")) {
2176:                            String desc = soif.getValue(attrName); //
2177:                            if (desc != null) {
2178:                                sb.append(desc);
2179:                            }
2180:                        }
2181:                    }
2182:                    return sb.toString();
2183:                } catch (Exception e) {
2184:                    throw new CommunityException(
2185:                            "Error reading data from search:" + e);
2186:                }
2187:
2188:            }
2189:
2190:            private void reindex() throws CommunityException {
2191:                Set roleIds = new HashSet();
2192:                roleIds.add(RoleId.OWNER_ROLE);
2193:
2194:                //TODO what is this owner story.
2195:                addSearchIndex(getCategory(), getDescription(), getUsers(
2196:                        roleIds).toString());
2197:
2198:            }
2199:
2200:            private void sendNotification(NotificationType type,
2201:                    String senderId, String recipientId, String message)
2202:                    throws CommunityException, NotificationException {
2203:
2204:                // prepare arguments to be passed into notification messages
2205:                String ctyName = null;
2206:                try {
2207:                    ctyName = cmcNode.getCMCPrincipal().getName();
2208:                } catch (CMCException cmce) {
2209:                    throw new CommunityException(
2210:                            "CommunityImpl.sendNotification(): failed to retrieve community info"
2211:                                    + cmce);
2212:                }
2213:
2214:                CommunityUser cu = new CommunityUserImpl(req, senderId);
2215:                String senderFullName = cu.getFullName();
2216:
2217:                String ctyURL = urlManager.getCommunityAccessURL(req, cid);
2218:                String[] args = new String[] { ctyName, senderFullName, ctyURL,
2219:                        message };
2220:
2221:                //
2222:                // create notification
2223:                //
2224:                Notification notif = new Notification();
2225:                notif.setType(type);
2226:                notif.setSender(senderId);
2227:                Set recipients = new HashSet();
2228:                recipients.add(recipientId);
2229:                notif.setRecipients(recipients);
2230:                // TODO: use classloader?
2231:                Locale locale = cu.getPreferredLocale();
2232:                if (locale == null) {
2233:                    locale = Locale.getDefault();
2234:                }
2235:                ResourceBundle rb = ResourceBundle.getBundle(
2236:                        NOTIFICATION_RB_BASE, locale);
2237:                notif.setResourceBundle(rb);
2238:                notif.setArguments(args);
2239:
2240:                //
2241:                // send it away
2242:                //
2243:                notifManager.send(req, notif);
2244:            }
2245:
2246:            //----------------------------------------------------
2247:            // Logging Methods
2248:            //----------------------------------------------------
2249:
2250:            public void logRecord(Logger logger, Level level, String msgKey,
2251:                    Throwable th, Object parameter) {
2252:                LogRecord logRecord = new LogRecord(level, msgKey);
2253:                logRecord.setLoggerName(logger.getName());
2254:                logRecord.setThrown(th);
2255:                logRecord.setParameters(new Object[] { parameter });
2256:                logger.log(logRecord);
2257:            }
2258:
2259:            public void logRecord(Logger logger, Level level, String msgKey,
2260:                    Throwable th, Object[] parameters) {
2261:                LogRecord logRecord = new LogRecord(level, msgKey);
2262:                logRecord.setLoggerName(logger.getName());
2263:                logRecord.setThrown(th);
2264:                logRecord.setParameters(parameters);
2265:                logger.log(logRecord);
2266:            }
2267:
2268:            //--------------------------------------------------------
2269:            // Utility methods
2270:            //----------------------------------------------------------
2271:
2272:            String getPortalId() {
2273:                String id = ResourceLoader.getInstance(System.getProperties())
2274:                        .getPortalId();
2275:                if (id == null || id.length() == 0) {
2276:                    throw new NullPointerException(
2277:                            "portal id was null or empty");
2278:                }
2279:
2280:                return id;
2281:            }
2282:
2283:            //-----------------------------------------------------------
2284:            // INTERNAL CLASS
2285:            //
2286:            //-----------------------------------------------------------
2287:
2288:            class CommunityServiceResult {
2289:
2290:                private Map dpMap = null;
2291:                private List errors = null;
2292:
2293:                CommunityServiceResult() {
2294:                }
2295:
2296:                Map getDPDocs() {
2297:                    return dpMap;
2298:                }
2299:
2300:                void setDPDocs(Map dpDocs) {
2301:                    dpMap = dpDocs;
2302:                }
2303:
2304:                List getErrors() {
2305:                    return errors;
2306:                }
2307:
2308:                boolean hasErrors() {
2309:                    return (errors != null && errors.size() > 0);
2310:                }
2311:
2312:                Set getFailedServiceNames() {
2313:                    Set names = new LinkedHashSet();
2314:                    if (errors != null) {
2315:                        for (Iterator i = errors.iterator(); i.hasNext();) {
2316:                            CommunityServiceExceptionEntry cse = (CommunityServiceExceptionEntry) i
2317:                                    .next();
2318:                            names.add(cse.getServiceName());
2319:                        }
2320:                    }
2321:                    return names;
2322:                }
2323:
2324:                void addError(String communityId, String serviceName,
2325:                        Throwable t) {
2326:                    if (errors == null) {
2327:                        errors = new ArrayList();
2328:                    }
2329:                    errors.add(new CommunityServiceExceptionEntry(communityId,
2330:                            serviceName, t));
2331:                }
2332:            }
2333:
2334:            public boolean isDisabled() throws CommunityException {
2335:                try {
2336:                    Set roles = cmcNode.getRoles();
2337:                    if (roles.contains(CMCRolePrincipal.DISABLED_ROLE)) {
2338:                        return true;
2339:                    }
2340:                    return false;
2341:                } catch (CMCException cmce) {
2342:                    throw new CommunityException(cmce);
2343:                }
2344:            }
2345:
2346:            private static boolean setContainsPattern(Set patterns, Pattern p1) {
2347:                for (Iterator i = patterns.iterator(); i.hasNext();) {
2348:                    Pattern p2 = (Pattern) i.next();
2349:                    if (p1.pattern().equals(p2.pattern())) {
2350:                        return true;
2351:                    }
2352:                }
2353:                return false;
2354:            }
2355:
2356:            public void setDisabled(boolean disabled)
2357:                    throws CommunityServiceException, CommunityException {
2358:
2359:                if (disabled) {
2360:                    // need to set acl before adding disable role, or it will failed due to db level security on disabled community.
2361:                    secureSearchIndexForCommunityContent("admin_only");
2362:                    addRole(CMCRolePrincipal.DISABLED_ROLE);
2363:                    reprovisionServices(ProvisionRequest.EVENT_TYPE_DISABLED);
2364:                    if (isListed()) {
2365:                        removeSearchIndexForCommunity();
2366:                    }
2367:                } else {
2368:                    removeRole(CMCRolePrincipal.DISABLED_ROLE);
2369:                    reprovisionServices(ProvisionRequest.EVENT_TYPE_ENABLED);
2370:                    if (isListed()) {
2371:                        reindex();
2372:                    }
2373:                    String readAcl = isSecure() ? getCommunityId().getName()
2374:                            + ":" + RoleId.MEMBER_ROLE : "";
2375:                    secureSearchIndexForCommunityContent(readAcl);
2376:                }
2377:            }
2378:
2379:            public boolean isDeleted() throws CommunityException {
2380:
2381:                try {
2382:                    Set roles = cmcNode.getRoles();
2383:                    if (roles.contains(CMCRolePrincipal.DELETED_ROLE)) {
2384:                        return true;
2385:                    }
2386:                    return false;
2387:                } catch (CMCException cmce) {
2388:                    throw new CommunityException(cmce);
2389:                }
2390:            }
2391:
2392:            public void setDeleted(boolean deleted)
2393:                    throws CommunityServiceException, CommunityException {
2394:
2395:                if (deleted) {
2396:                    secureSearchIndexForCommunityContent("admin_only");
2397:                    addRole(CMCRolePrincipal.DELETED_ROLE);
2398:                    reprovisionServices(ProvisionRequest.EVENT_TYPE_DELETED);
2399:                    if (isListed()) {
2400:                        removeSearchIndexForCommunity();
2401:                    }
2402:                } else {
2403:                    removeRole(CMCRolePrincipal.DELETED_ROLE);
2404:                    reprovisionServices(ProvisionRequest.EVENT_TYPE_UNDELETED);
2405:                    if (isListed()) {
2406:                        reindex();
2407:                    }
2408:                    String readAcl = isSecure() ? getCommunityId().getName()
2409:                            + ":" + RoleId.MEMBER_ROLE : "";
2410:                    secureSearchIndexForCommunityContent(readAcl);
2411:                }
2412:            }
2413:
2414:            private void addRole(CMCRolePrincipal role)
2415:                    throws CommunityException {
2416:
2417:                boolean supported = false;
2418:                try {
2419:                    supported = cmcNode.supportsRole(role);
2420:                } catch (CMCException ce) {
2421:                    throw new CommunityException(ce);
2422:                }
2423:
2424:                if (!supported) {
2425:                    throw new CommunityException(
2426:                            "unsupported role for this community, communityNode="
2427:                                    + cmcNode + ", role=" + role.toString());
2428:                }
2429:
2430:                try {
2431:                    cmcNode.addRole(role);
2432:                } catch (CMCException cmce) {
2433:                    throw new CommunityException(cmce);
2434:                }
2435:            }
2436:
2437:            private void removeRole(CMCRolePrincipal role)
2438:                    throws CommunityException {
2439:
2440:                boolean supported = false;
2441:                try {
2442:                    supported = cmcNode.supportsRemoveRole();
2443:                } catch (CMCException ce) {
2444:                    throw new CommunityException(ce);
2445:                }
2446:
2447:                if (!supported) {
2448:                    throw new CommunityException(
2449:                            "removing role is not supported for this community, communityNode="
2450:                                    + cmcNode);
2451:                }
2452:
2453:                try {
2454:                    cmcNode.removeRole(role);
2455:                } catch (CMCException cmce) {
2456:                    throw new CommunityException(cmce);
2457:                }
2458:            }
2459:
2460:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.