001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.getc
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * any nuclear facility.
035: */
036: package com.sun.portal.community.mc.impl.am;
037:
038: import com.sun.portal.community.mc.CMCException;
039: import com.sun.portal.community.mc.CMCPrincipal;
040: import com.sun.portal.community.mc.CMCNode;
041: import com.sun.portal.community.mc.ConfigTable.ConfigKey;
042: import com.sun.portal.community.mc.CMCRolePrincipal;
043: import com.sun.portal.community.mc.CMCFactory;
044: import com.sun.portal.community.mc.CMCNodeManager;
045: import java.util.Iterator;
046: import java.util.Properties;
047: import java.util.Set;
048: import java.util.Map;
049: import java.util.HashMap;
050: import java.util.Collections;
051: import com.iplanet.am.sdk.AMUser;
052: import com.iplanet.am.sdk.AMRole;
053: import com.iplanet.am.sdk.AMFilteredRole;
054: import com.iplanet.am.sdk.AMOrganization;
055: import com.iplanet.sso.SSOException;
056: import com.iplanet.am.sdk.AMException;
057: import com.iplanet.am.util.SystemProperties;
058: import java.util.regex.Pattern;
059:
060: /**
061: * AM community node manager contributor, base class
062: *
063: * This class is extended by all AM community node manager
064: * contributors.
065: */
066: public abstract class CMCNodeManagerImplBase extends CMCImplBase
067: implements CMCNodeManager {
068:
069: public void init(Properties p) throws CMCException {
070: // nothing
071: }
072:
073: //
074: // the two get*Count() methods are suboptimal. they find the answer
075: // using brute-force: they get the users calling getUsers() and then
076: // count the results.
077: //
078: // this most likely could be optimized. however, since these are only
079: // implemented for completeness, we leave this for the future
080: //
081:
082: public Map getUserCounts(Set communityPrincipals)
083: throws CMCException {
084: communityPrincipals = filterPrincipals(communityPrincipals);
085: Map counts = new HashMap();
086:
087: for (Iterator i = communityPrincipals.iterator(); i.hasNext();) {
088: CMCPrincipal cmcp = (CMCPrincipal) i.next();
089: CMCNode cmcn = CMCFactory.getInstance().getCMCNode(cmcp);
090: counts.put(cmcp, new Integer(cmcn.getUsers().size()));
091: }
092:
093: return counts;
094: }
095:
096: public Map getRoleUserCounts(Set communityPrincipals,
097: Set rolePrincipals) throws CMCException {
098: communityPrincipals = filterPrincipals(communityPrincipals);
099: Map counts = new HashMap();
100:
101: for (Iterator i = communityPrincipals.iterator(); i.hasNext();) {
102: CMCPrincipal cmcp = (CMCPrincipal) i.next();
103: for (Iterator j = rolePrincipals.iterator(); j.hasNext();) {
104: CMCRolePrincipal cmcrp = (CMCRolePrincipal) j.next();
105: ConfigKey ck = new ConfigKey(cmcp, cmcrp);
106: CMCNode cmcn = CMCFactory.getInstance()
107: .getCMCNode(cmcp);
108: counts.put(ck, new Integer(cmcn.getUsers(
109: Collections.singleton(cmcrp)).size()));
110: }
111: }
112:
113: return counts;
114: }
115:
116: public Set match(Pattern p, boolean nameOnly) throws CMCException {
117: // NOT IMPLEMENTED
118: return Collections.EMPTY_SET;
119: }
120:
121: }
|