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


001:        package com.sun.portal.community.test.provider;
002:
003:        import com.sun.portal.providers.*;
004:        import com.sun.portal.desktop.*;
005:        import java.util.*;
006:        import javax.servlet.http.*;
007:        import java.io.*;
008:        import com.sun.portal.community.*;
009:        import com.sun.portal.community.TemplateTokens;
010:        import java.security.ProviderException;
011:        import com.iplanet.sso.SSOTokenManager;
012:        import com.iplanet.sso.SSOToken;
013:        import com.iplanet.sso.SSOException;
014:
015:        public class CommunityMgmntTestProvider extends ProfileProviderAdapter
016:                implements  TemplateTokens {
017:            public StringBuffer getContent(HttpServletRequest request,
018:                    HttpServletResponse response) throws ProviderException {
019:                HttpServletRequest oreq = RequestThreadLocalizer.getRequest();
020:                HttpServletResponse ores = RequestThreadLocalizer.getResponse();
021:
022:                CommunityBaseHandler cbh = new CommunityBaseHandler(oreq, ores);
023:
024:                StringBuffer b = new StringBuffer();
025:                b.append("<pre>");
026:                String cmd = request.getParameter("cmd");
027:
028:                try {
029:                    if (cmd == null) {
030:                        throw new NullPointerException("null cmd");
031:                    } else if (cmd.equals("create")) {
032:                        String number = request.getParameter("n");
033:                        int totalcommunities = Integer.parseInt(number);
034:                        String template = request.getParameter("template");
035:                        if (template == null) {
036:                            template = "2column";
037:                        }
038:                        testCreate(oreq, ores, b, totalcommunities, template,
039:                                cbh);
040:                    } else if (cmd.equals("remove")) {
041:                        String number = request.getParameter("n");
042:                        int n = Integer.parseInt(number);
043:                        testRemove(oreq, ores, b, n, cbh);
044:                    } else if (cmd.equals("enable")) {
045:                        String number = request.getParameter("n");
046:                        int n = Integer.parseInt(number);
047:                        testEnable(oreq, ores, b, n, cbh);
048:                    } else if (cmd.equals("disable")) {
049:                        String number = request.getParameter("n");
050:                        int n = Integer.parseInt(number);
051:                        testDisable(oreq, ores, b, n, cbh);
052:                    } else if (cmd.equals("delete")) {
053:                        String number = request.getParameter("n");
054:                        int n = Integer.parseInt(number);
055:                        testDelete(oreq, ores, b, n, cbh);
056:                    } else if (cmd.equals("undelete")) {
057:                        String number = request.getParameter("n");
058:                        int n = Integer.parseInt(number);
059:                        testUndelete(oreq, ores, b, n, cbh);
060:                    } else if (cmd.equals("addusers")) {
061:                        String number = request.getParameter("n");
062:                        int n = Integer.parseInt(number);
063:                        String joins = request.getParameter("j");
064:                        int j = Integer.parseInt(joins);
065:                        String suffix = request.getParameter("usersuffix");
066:                        if (suffix == null) {
067:                            suffix = ",ou=People,o=CommunitySample,dc=red,dc=iplanet,dc=com";
068:                        }
069:                        String filename = request.getParameter("userfile");
070:                        testAddUsers(oreq, ores, b, n, j, suffix, filename);
071:                    } else if (cmd.equals("provision")) {
072:                        String channelName = request.getParameter("name");
073:                        String cidString = request.getParameter("cid");
074:                        testProvision(oreq, ores, channelName, cidString, cbh);
075:                    } else if (cmd.equals("unprovision")) {
076:                        String channelName = request.getParameter("name");
077:                        String cidString = request.getParameter("cid");
078:                        testUnprovision(oreq, ores, channelName, cidString);
079:                    } else if (cmd.equals("getmembership")) {
080:                        testGetMembership(oreq, ores, b, false);
081:                    } else if (cmd.equals("getallmembership")) {
082:                        testGetMembership(oreq, ores, b, true);
083:                    } else if (cmd.equals("hasrole")) {
084:                        String number = request.getParameter("n");
085:                        int n = Integer.parseInt(number);
086:                        testHasRole(oreq, ores, b, n, false);
087:                    } else if (cmd.equals("hasroleall")) {
088:                        String number = request.getParameter("n");
089:                        int n = Integer.parseInt(number);
090:                        testHasRole(oreq, ores, b, n, true);
091:                    } else if (cmd.equals("roletransition")) {
092:                        String suffix = request.getParameter("usersuffix");
093:                        if (suffix == null) {
094:                            suffix = ",ou=People,o=CommunitySample,dc=red,dc=iplanet,dc=com";
095:                        }
096:                        String filename = request.getParameter("userfile");
097:                        testRoleTransition(oreq, ores, b, suffix, filename);
098:                    } else if (cmd.equals("communityListTransition")) {
099:                        String communityName = request
100:                                .getParameter("communityName");
101:                        testCommunityListTransition(oreq, ores, b,
102:                                communityName);
103:                    } else if (cmd.equals("communitySecureTransition")) {
104:                        String communityName = request
105:                                .getParameter("communityId");
106:                        testCommunitySecureTransition(oreq, ores, b,
107:                                communityName);
108:                    } else if (cmd.equals("communityMembershipTransition")) {
109:                        String communityName = request
110:                                .getParameter("communityName");
111:                        testCommunityMembershipTransition(oreq, ores, b,
112:                                communityName);
113:                    } else if (cmd.equals("communityAttributeChanges")) {
114:                        String communityName = request
115:                                .getParameter("communityName");
116:                        testCommunityAtrributeChanges(oreq, ores, b,
117:                                communityName);
118:                    } else if (cmd.equals("nop")) {
119:                        // nothing
120:                    } else {
121:                        throw new Exception("unknown command: " + cmd);
122:                    }
123:                } catch (Throwable t) {
124:                    StringBuffer err = new StringBuffer();
125:                    err.append("<pre>\n");
126:                    err.append(t.getMessage());
127:                    err.append("\n");
128:                    StringWriter xx = new StringWriter();
129:                    t.printStackTrace(new PrintWriter(xx));
130:                    t.printStackTrace();
131:                    err.append(xx.toString());
132:                    err.append("\n</pre>\n");
133:
134:                    return err;
135:                }
136:
137:                b.append("</pre>");
138:                return b;
139:            }
140:
141:            private void testProvision(HttpServletRequest req,
142:                    HttpServletResponse res, String channelName,
143:                    String cidString, CommunityBaseHandler cbh)
144:                    throws Exception {
145:                CommunityId cid = new CommunityId(cidString);
146:                Community c = CommunityFactory.getInstance().getCommunity(req,
147:                        res, getSSOToken(req), cid);
148:                Map tokenMapping = getTokenMapping(req, res, cid,
149:                        "community management test provider", cbh);
150:
151:                //c.provisionService("2column", tokenMapping, channelName);
152:            }
153:
154:            private void testUnprovision(HttpServletRequest req,
155:                    HttpServletResponse res, String channelName,
156:                    String cidString) throws Exception {
157:                CommunityId cid = new CommunityId(cidString);
158:                Community c = CommunityFactory.getInstance().getCommunity(req,
159:                        res, getSSOToken(req), cid);
160:
161:                //c.unprovisionService(channelName);
162:            }
163:
164:            private void testGetMembership(HttpServletRequest req,
165:                    HttpServletResponse res, StringBuffer b, boolean allRoles)
166:                    throws Exception {
167:                CommunityUser user = CommunityFactory.getInstance()
168:                        .getCommunityUser(req);
169:                if (allRoles) {
170:                    b.append("all membership: " + user.getMembership(true));
171:                } else {
172:                    b.append("membership: " + user.getMembership());
173:                }
174:            }
175:
176:            private void testHasRole(HttpServletRequest req,
177:                    HttpServletResponse res, StringBuffer b, int n,
178:                    boolean allRoles) throws Exception {
179:                CommunityUser user = CommunityFactory.getInstance()
180:                        .getCommunityUser(req);
181:                for (int i = 0; i < n; i++) {
182:                    CommunityId id = new CommunityId("jdo", "community" + i);
183:                    for (Iterator it = RoleId.ALL_ROLES.iterator(); it
184:                            .hasNext();) {
185:                        RoleId rid = (RoleId) it.next();
186:                        if (allRoles) {
187:                            b.append("hasRole(" + id + ", " + rid.toString()
188:                                    + ") = " + user.hasRole(id, rid, true)
189:                                    + "<br/>\n");
190:                        } else {
191:                            b.append("hasRole(" + id + ", " + rid.toString()
192:                                    + ") = " + user.hasRole(id, rid)
193:                                    + "<br/>\n");
194:                        }
195:                    }
196:                    b.append("<br/>\n");
197:                }
198:            }
199:
200:            private void testAddUsers(HttpServletRequest request,
201:                    HttpServletResponse response, StringBuffer b, int n, int j,
202:                    String userSuffix, String userListFile) throws Exception {
203:                CommunityManager cm = getCommunityManager(request, response);
204:                List userList = readUsers(userListFile);
205:
206:                Random random = new Random(System.currentTimeMillis());
207:                for (Iterator iter = userList.iterator(); iter.hasNext();) {
208:                    String uid = (String) iter.next();
209:                    uid = "uid=" + uid + userSuffix;
210:                    for (int i = 0; i < j; i++) {
211:                        int cn = random.nextInt(n);
212:                        CommunityId id = new CommunityId("jdo", "community"
213:                                + cn);
214:                        Community community = CommunityFactory.getInstance()
215:                                .getCommunity(request, response,
216:                                        getSSOToken(request), id);
217:                        try {
218:                            community.addMember(uid);
219:                        } catch (CommunityException ce) {
220:                            b.append("user: " + uid
221:                                    + " could not be added to community: " + id
222:                                    + " it may be a duplicate<br/>\n");
223:                        }
224:                    }
225:                }
226:                b.append("added users to n=" + n + " communities");
227:            }
228:
229:            private void testCommunityListTransition(
230:                    HttpServletRequest request, HttpServletResponse response,
231:                    StringBuffer b, String communityName) throws Exception {
232:                CommunityId id = new CommunityId("jdo", communityName);
233:                Community community = CommunityFactory.getInstance()
234:                        .getCommunity(request, response, getSSOToken(request),
235:                                id);
236:                boolean listed = community.isListed();
237:                b.append(id + ":listed restricted:" + listed);
238:                community.setListed(!listed);
239:                b.append(id + ":listed toggled to:" + !listed);
240:                boolean newlisted = community.isListed();
241:                if (newlisted != listed) {
242:                    b.append(id + ":listed switched successfully\n");
243:                } else {
244:                    b.append(id + ":listed switched failed\n");
245:                }
246:
247:            }
248:
249:            private void testCommunitySecureTransition(
250:                    HttpServletRequest request, HttpServletResponse response,
251:                    StringBuffer b, String communityName) throws Exception {
252:
253:                CommunityId id = new CommunityId("jdo", communityName);
254:                Community community = CommunityFactory.getInstance()
255:                        .getCommunity(request, response, getSSOToken(request),
256:                                id);
257:                boolean secure = community.isSecure();
258:                b.append(id + ":secure restricted:" + secure);
259:                community.setSecure(!secure);
260:                b.append(id + ":secure toggled to:" + !secure);
261:                boolean newsecure = community.isSecure();
262:                if (newsecure != secure) {
263:                    b.append(id + ":secure switched successfully\n");
264:                } else {
265:                    b.append(id + ":secure switched failed\n");
266:                }
267:
268:            }
269:
270:            private void testCommunityMembershipTransition(
271:                    HttpServletRequest request, HttpServletResponse response,
272:                    StringBuffer b, String communityName) throws Exception {
273:                CommunityId id = new CommunityId("jdo", communityName);
274:                Community community = CommunityFactory.getInstance()
275:                        .getCommunity(request, response, getSSOToken(request),
276:                                id);
277:                boolean membership = community.isMembershipRestricted();
278:                b.append(id + ":membership restricted:" + membership);
279:                community.setMembershipRestricted(!membership);
280:                b.append(id + ":membership toggled to:" + !membership);
281:                boolean newmembership = community.isMembershipRestricted();
282:                if (newmembership != membership) {
283:                    b.append(id + ":membership switched successfully\n");
284:                } else {
285:                    b.append(id + ":membership switched failed\n");
286:                }
287:            }
288:
289:            private void testCommunityAtrributeChanges(
290:                    HttpServletRequest request, HttpServletResponse response,
291:                    StringBuffer b, String communityName) throws Exception {
292:                CommunityId id = new CommunityId("jdo", communityName);
293:                Community community = CommunityFactory.getInstance()
294:                        .getCommunity(request, response, getSSOToken(request),
295:                                id);
296:                //
297:                // test description
298:                //
299:
300:                String description = community.getDescription();
301:                b.append(id + ":oldDescription:" + description + "\n");
302:
303:                community.setDescription("updatedDescription");
304:                b.append(id + ":description changed to:"
305:                        + "updatedDescription\n");
306:                description = community.getDescription();
307:                if (description.equals("updatedDescription")) {
308:                    b.append(id + ":description set successfully\n");
309:                } else {
310:                    b.append(id + ":description set failed\n");
311:                }
312:
313:                //
314:                // test category
315:                //
316:
317:                String category = community.getCategory();
318:                b.append(id + ":oldcategory:" + category + "\n");
319:
320:                community.setCategory("External:Ads");
321:                b.append(id + ":category changed to:" + "External:Ads\n");
322:                category = community.getCategory();
323:                if (category.equals("External:Ads")) {
324:                    b.append(id + ":category set successfully\n");
325:                } else {
326:                    b.append(id + ":category set failed\n");
327:                }
328:
329:            }
330:
331:            private void testRoleTransition(HttpServletRequest request,
332:                    HttpServletResponse response, StringBuffer b,
333:                    String userSuffix, String userListFile) throws Exception {
334:                CommunityManager cm = getCommunityManager(request, response);
335:                List userList = readUsers(userListFile);
336:                // Select one user from the list and we'll run the normal tests using it
337:
338:                Iterator iter = userList.iterator();
339:                String uid = (String) iter.next();
340:                uid = "uid=" + uid + userSuffix;
341:
342:                //
343:                // Get the community handle
344:                //
345:                CommunityId id = new CommunityId("jdo", "community0");
346:                Community community = CommunityFactory.getInstance()
347:                        .getCommunity(request, response, getSSOToken(request),
348:                                id);
349:
350:                //
351:                // 
352:                try {
353:
354:                    CommunityUser user = CommunityFactory.getInstance()
355:                            .getCommunityUser(request, uid);
356:                    // test inviting
357:                    String testAction = "invite";
358:                    community.inviteUser(uid, "");
359:                    if (user.hasRole(id, RoleId.INVITED_ROLE)) {
360:                        b.append(testAction + " passed for uid:" + uid
361:                                + ": community" + id.toString() + "\n");
362:                    } else {
363:                        b.append(testAction + " failed for uid:" + uid
364:                                + ": community" + id.toString() + "\n");
365:                        return;
366:                    }
367:
368:                    // test inviting
369:                    testAction = "approval";
370:                    community.acceptInvitation(uid);
371:                    if (!user.hasRole(id, RoleId.INVITED_ROLE)
372:                            && user.hasRole(id, RoleId.MEMBER_ROLE)) {
373:                        b.append(testAction + " passed for uid:" + uid
374:                                + ": community" + id.toString() + "\n");
375:                    } else {
376:                        b.append(testAction + " failed for uid:" + uid
377:                                + ": community" + id.toString() + "\n");
378:                        return;
379:                    }
380:
381:                    testAction = "Ban";
382:                    community.banUser(uid);
383:                    if (user.hasRole(id, RoleId.MEMBER_ROLE)
384:                            && user.hasRole(id, RoleId.BANNED_ROLE)) {
385:                        b.append(testAction + " passed for uid:" + uid
386:                                + ": community" + id.toString() + "\n");
387:                    } else {
388:                        b.append(testAction + " failed for uid:" + uid
389:                                + ": community" + id.toString() + "\n");
390:                        return;
391:                    }
392:
393:                    // test unbanning of an banned member
394:
395:                    testAction = "unban";
396:                    community.unbanUser(uid);
397:                    if (user.hasRole(id, RoleId.MEMBER_ROLE)
398:                            && !user.hasRole(id, RoleId.BANNED_ROLE)) {
399:                        b.append(testAction + " passed for uid:" + uid
400:                                + ": community" + id.toString() + "\n");
401:                    } else {
402:                        b.append(testAction + " failed for uid:" + uid
403:                                + ": community" + id.toString() + "\n");
404:                        return;
405:                    }
406:
407:                    // remove the user
408:                    testAction = "remove";
409:                    community.removeUser(uid, RoleId.MEMBER_ROLE);
410:                    if (!user.hasRole(id, RoleId.MEMBER_ROLE)) {
411:                        b.append(testAction + " passed for uid:" + uid
412:                                + ": community" + id.toString() + "\n");
413:                    } else {
414:                        b.append(testAction + " failed for uid:" + uid
415:                                + ": community" + id.toString() + "\n");
416:                        return;
417:                    }
418:
419:                    testAction = "requestmembership";
420:                    community.requestMembership(uid);
421:                    if (user.hasRole(id, RoleId.PENDING_ROLE)) {
422:                        b.append(testAction + " passed for uid:" + uid
423:                                + ": community" + id.toString() + "\n");
424:                    } else {
425:                        b.append(testAction + " failed for uid:" + uid
426:                                + ": community" + id.toString() + "\n");
427:                        return;
428:                    }
429:
430:                    testAction = "accept membership request";
431:                    community.approveMembershipRequest(uid);
432:                    if (!user.hasRole(id, RoleId.PENDING_ROLE)
433:                            && user.hasRole(id, RoleId.MEMBER_ROLE)) {
434:                        b.append(testAction + " passed for uid:" + uid
435:                                + ": community" + id.toString() + "\n");
436:                    } else {
437:                        b.append(testAction + " failed for uid:" + uid
438:                                + ": community" + id.toString() + "\n");
439:                        return;
440:                    }
441:
442:                    testAction = "reject membership request of a regular member";
443:                    try {
444:                        community.rejectMembershipRequest(uid);
445:                        // didn't throw an exception'
446:                        b.append(testAction + " failed for uid:" + uid
447:                                + ": community" + id.toString() + "\n");
448:                        return;
449:
450:                    } catch (CommunityException ex) {
451:                        if (ex instanceof  RoleAssignmentException) {
452:                            b.append(testAction + " passed for uid:" + uid
453:                                    + ": community" + id.toString() + "\n");
454:                        } else {
455:                            throw ex;
456:                        }
457:
458:                    }
459:
460:                } catch (CommunityException ce) {
461:                    b.append("user: " + uid
462:                            + " could not be added to community: " + id
463:                            + "<br/>\n");
464:                }
465:
466:            }
467:
468:            //
469:            // Read users from a file
470:            //
471:            protected List readUsers(String filename) throws IOException {
472:                BufferedReader br = null;
473:                StringBuffer buf = new StringBuffer();
474:                List userList = new ArrayList();
475:
476:                try {
477:                    File f = new File(filename);
478:                    InputStream is = new FileInputStream(f);
479:                    InputStreamReader r = new InputStreamReader(is);
480:                    br = new BufferedReader(r);
481:
482:                    String line = null;
483:                    while ((line = br.readLine()) != null) {
484:                        userList.add(line);
485:                    }
486:                } finally {
487:                    if (br != null) {
488:                        br.close();
489:                    }
490:                }
491:
492:                return userList;
493:            }
494:
495:            //
496:            // create n communities
497:            //
498:            private void testCreate(HttpServletRequest request,
499:                    HttpServletResponse response, StringBuffer b,
500:                    int totalCommunities, String template,
501:                    CommunityBaseHandler cbh) throws Exception {
502:                CommunityManager cm = getCommunityManager(request, response);
503:
504:                for (int i = 0; i < totalCommunities; i++) {
505:                    CommunityId id = new CommunityId("jdo", "community" + i);
506:                    if (!cm.existsCommunity(id)) {
507:                        cm.createCommunity(id, "2column",
508:                                "External:Announcements", "desc" + "Community"
509:                                        + i, false, false, true);
510:
511:                    } else {
512:                        b.append("community: " + id
513:                                + " already exists, skipping<br/>\n");
514:                    }
515:                }
516:                b.append("created communites: n=" + totalCommunities
517:                        + "<br/>\n");
518:            }
519:
520:            private Map getTokenMapping(HttpServletRequest request,
521:                    HttpServletResponse response, CommunityId communityId,
522:                    String desc, CommunityBaseHandler cbh) throws Exception {
523:                //
524:                // build token mapping
525:                // priority should be: owner > member > visitor
526:                // leaving some room btwn roles in case we add more roles later
527:                //
528:
529:                CommunityManager cmgr = getCommunityManager(request, response);
530:                Map tokenMappings = new HashMap();
531:                Properties tokenMapping = new Properties();
532:
533:                tokenMapping.setProperty(TOKEN_COMMUNITY_NAME, communityId
534:                        .getName());
535:                tokenMapping.setProperty(TOKEN_COMMUNITY_ID, communityId
536:                        .toString());
537:                tokenMapping.setProperty(TOKEN_PORTAL_ID, cbh.getPortalId());
538:                tokenMapping.setProperty(TOKEN_COMMUNITY_DESCRIPTION, desc);
539:                tokenMapping.setProperty(TOKEN_COMMUNITY_CONTAINER,
540:                        new CommunityContainerName(communityId).toString());
541:                tokenMapping.setProperty(TOKEN_COMMUNITY_DP_PRIORITY, Integer
542:                        .toString(cbh.getDpPriorityBase()));
543:                tokenMapping.setProperty(TOKEN_COMMUNITY_SEARCH_URL, cmgr
544:                        .getSearchUrl());
545:                tokenMapping.setProperty(TOKEN_COMMUNITY_CONTENTS_SEARCH_DB,
546:                        cmgr.getContentsSearchDb(communityId));
547:                tokenMapping.setProperty(TOKEN_COMMUNITY_DISCUSSIONS_SEARCH_DB,
548:                        cmgr.getDiscussionsSearchDb(communityId));
549:
550:                tokenMappings.put(RoleId.VISITOR_ROLE.toString(), tokenMapping);
551:
552:                tokenMapping = (Properties) tokenMapping.clone();
553:                tokenMapping.setProperty(TOKEN_COMMUNITY_DP_PRIORITY, Integer
554:                        .toString(cbh.getDpPriorityBase() + 5));
555:                tokenMappings.put(RoleId.MEMBER_ROLE.toString(), tokenMapping);
556:
557:                tokenMapping = (Properties) tokenMapping.clone();
558:                tokenMapping.setProperty(TOKEN_COMMUNITY_DP_PRIORITY, Integer
559:                        .toString(cbh.getDpPriorityBase() + 10));
560:                tokenMappings.put(RoleId.OWNER_ROLE.toString(), tokenMapping);
561:
562:                return tokenMappings;
563:            }
564:
565:            private void testRemove(HttpServletRequest request,
566:                    HttpServletResponse response, StringBuffer b, int n,
567:                    CommunityBaseHandler cbh) throws Exception {
568:                CommunityManager cm = getCommunityManager(request, response);
569:                for (int i = 0; i < n; i++) {
570:                    CommunityId id = new CommunityId("jdo", "community" + i);
571:                    try {
572:                        cm.destroyCommunity(id);
573:                    } catch (CommunityDoesNotExistException cdnee) {
574:                        b.append("community: " + id
575:                                + " did not exist, skipping<br/>\n");
576:                    } catch (CommunityServiceException cse) {
577:                        b
578:                                .append("error removing community: "
579:                                        + id
580:                                        + ", could not unprovision one or more services:<br/>"
581:                                        + cse.getMessage() + "<br/>\n");
582:                    }
583:                }
584:                b.append("removed communites: n=" + n + "<br/>\n");
585:            }
586:
587:            private void testDisable(HttpServletRequest request,
588:                    HttpServletResponse response, StringBuffer b, int n,
589:                    CommunityBaseHandler cbh) throws Exception {
590:                for (int i = 0; i < n; i++) {
591:                    CommunityId id = new CommunityId("jdo", "community" + i);
592:                    Community c = CommunityFactory.getInstance().getCommunity(
593:                            request, response, getSSOToken(request), id);
594:                    try {
595:                        b.append("community" + i + " is currently "
596:                                + (c.isDisabled() ? "disabled." : "enabled.")
597:                                + "  disabling...<br/>\n");
598:                        c.setDisabled(true);
599:                    } catch (CommunityException ce) {
600:                        b.append("error disabling community: " + id + ":<br/>"
601:                                + ce.getMessage() + "<br/>\n");
602:                    }
603:                }
604:                b.append("disabled communites: n=" + n + "<br/>\n");
605:            }
606:
607:            private void testEnable(HttpServletRequest request,
608:                    HttpServletResponse response, StringBuffer b, int n,
609:                    CommunityBaseHandler cbh) throws Exception {
610:                for (int i = 0; i < n; i++) {
611:                    CommunityId id = new CommunityId("jdo", "community" + i);
612:                    Community c = CommunityFactory.getInstance().getCommunity(
613:                            request, response, getSSOToken(request), id);
614:                    try {
615:                        b.append("community" + i + " is currently "
616:                                + (c.isDisabled() ? "disabled." : "enabled.")
617:                                + "  enabling...<br/>\n");
618:                        c.setDisabled(false);
619:                    } catch (CommunityException ce) {
620:                        b.append("error undeleting community: " + id + ":<br/>"
621:                                + ce.getMessage() + "<br/>\n");
622:                    }
623:                }
624:                b.append("enabled communites: n=" + n + "<br/>\n");
625:            }
626:
627:            private void testDelete(HttpServletRequest request,
628:                    HttpServletResponse response, StringBuffer b, int n,
629:                    CommunityBaseHandler cbh) throws Exception {
630:                for (int i = 0; i < n; i++) {
631:                    CommunityId id = new CommunityId("jdo", "community" + i);
632:                    Community c = CommunityFactory.getInstance().getCommunity(
633:                            request, response, getSSOToken(request), id);
634:                    try {
635:                        b.append("community" + i + " is currently "
636:                                + (c.isDeleted() ? "deleted." : "available.")
637:                                + "  deleting...<br/>\n");
638:                        c.setDeleted(true);
639:                    } catch (CommunityException ce) {
640:                        b.append("error deleting community: " + id + ":<br/>"
641:                                + ce.getMessage() + "<br/>\n");
642:                    }
643:                }
644:                b.append("deleted communites: n=" + n + "<br/>\n");
645:            }
646:
647:            private void testUndelete(HttpServletRequest request,
648:                    HttpServletResponse response, StringBuffer b, int n,
649:                    CommunityBaseHandler cbh) throws Exception {
650:                for (int i = 0; i < n; i++) {
651:                    CommunityId id = new CommunityId("jdo", "community" + i);
652:                    Community c = CommunityFactory.getInstance().getCommunity(
653:                            request, response, getSSOToken(request), id);
654:                    try {
655:                        b.append("community" + i + " is currently "
656:                                + (c.isDeleted() ? "deleted." : "available.")
657:                                + "  undeleting...<br/>\n");
658:                        c.setDeleted(false);
659:                    } catch (CommunityException ce) {
660:                        b.append("error undeleting community: " + id + ":<br/>"
661:                                + ce.getMessage() + "<br/>\n");
662:                    }
663:                }
664:                b.append("undeleted communites: n=" + n + "<br/>\n");
665:            }
666:
667:            protected CommunityManager getCommunityManager(
668:                    HttpServletRequest req, HttpServletResponse res)
669:                    throws Exception {
670:                CommunityManager cm = null;
671:                try {
672:                    cm = CommunityFactory.getInstance().getCommunityManager(
673:                            req, res);
674:                } catch (CommunityException ce) {
675:                    throw new Exception(ce);
676:                }
677:
678:                return cm;
679:            }
680:
681:            private String getUserName(String uid, String domain) {
682:                return "uid=" + uid + ",ou=People," + domain;
683:            }
684:
685:            private SSOToken getSSOToken(HttpServletRequest request)
686:                    throws CommunityException {
687:                SSOToken ssoToken = null;
688:                try {
689:                    SSOTokenManager ssoTokenMgr = SSOTokenManager.getInstance();
690:                    ssoToken = ssoTokenMgr.createSSOToken(request);
691:                    if (ssoToken == null) {
692:                        throw new RuntimeException(
693:                                "Expecting a request with SSOToken");
694:                    }
695:                    return ssoToken;
696:                } catch (SSOException se) {
697:                    throw new CommunityException(
698:                            "CommunityBaseHandler.init(): failed to create ssoToken.",
699:                            se);
700:                }
701:            }
702:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.