001: /**
002: * $Id: CMCNodeImpl.java,v 1.2 2005/07/25 23:02:36 jtb Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.community.mc.impl.am.global;
014:
015: import com.iplanet.am.sdk.AMException;
016: import com.iplanet.am.sdk.AMFilteredRole;
017: import com.iplanet.am.sdk.AMObject;
018: import com.iplanet.am.sdk.AMOrganization;
019: import com.iplanet.am.sdk.AMRole;
020: import com.iplanet.sso.SSOException;
021: import com.sun.portal.community.mc.CMCException;
022: import com.sun.portal.community.mc.CMCNode;
023: import com.sun.portal.community.mc.CMCPrincipal;
024: import com.sun.portal.community.mc.ConfigTable;
025: import com.sun.portal.community.mc.ConfigTable.ConfigKey;
026: import com.sun.portal.community.mc.CMCRolePrincipal;
027: import com.sun.portal.community.mc.impl.am.CMCNodeImplBase;
028: import java.util.HashSet;
029: import java.util.Iterator;
030: import java.util.Properties;
031: import java.util.Set;
032: import java.io.UnsupportedEncodingException;
033:
034: /**
035: * AM global community node contributor.
036: */
037: public class CMCNodeImpl extends CMCNodeImplBase implements CMCNode {
038: public void init(Properties p, CMCPrincipal cp) throws CMCException {
039: super .init(p, cp);
040:
041: String name = getCMCPrincipal().getName();
042: if (!name.equals(GLOBAL_NAME)) {
043: throw new CMCException("name must be global name: " + name);
044: }
045: }
046:
047: public static String getStaticType() {
048: return "am-global";
049: }
050:
051: public String getType() {
052: return getStaticType();
053: }
054:
055: public Set getUsers() throws CMCException {
056: Set users = new HashSet();
057:
058: try {
059: Set topOrgDns = adminConnection.getTopLevelOrganizations();
060: for (Iterator i = topOrgDns.iterator(); i.hasNext();) {
061: String orgDn = (String) i.next();
062: // we arbitrarily choose 10 levels deep
063: // this method should all users in the system
064: users.addAll(getOrganizationUsers(orgDn, 10));
065: }
066: } catch (AMException ame) {
067: throw new CMCException(ame);
068: } catch (SSOException ssoe) {
069: throw new CMCException(ssoe);
070: }
071:
072: return users;
073: }
074:
075: public boolean exists() throws CMCException {
076: // global node always exists
077: return true;
078: }
079:
080: public ConfigTable getDPDocuments() throws CMCException {
081: ConfigTable dpDocuments = getGlobalDPDocuments();
082: return dpDocuments;
083: }
084:
085: public ConfigTable getDPDocumentsLastModified() throws CMCException {
086: ConfigTable lastModifieds = getGlobalDPDocumentsLastModified();
087: return lastModifieds;
088: }
089:
090: private ConfigTable getGlobalDPDocuments() {
091: ConfigTable dpDocuments = new ConfigTable();
092: String dpString = getGlobalStringAttribute(dmpc.ATTR_DP_DOCUMENT);
093: byte[] dp;
094: try {
095: dp = dpString.getBytes("UTF-8");
096: } catch (UnsupportedEncodingException uee) {
097: throw new Error("UTF-8 encoding not supported");
098: }
099:
100: if (dp != null && dp.length > 0) {
101: ConfigKey ck = new ConfigKey(getCMCPrincipal(),
102: CMCRolePrincipal.MEMBER_ROLE);
103: dpDocuments.put(ck, dp);
104: }
105: return dpDocuments;
106: }
107:
108: private ConfigTable getGlobalDPDocumentsLastModified() {
109: ConfigTable lastModifieds = new ConfigTable();
110: String lm = getGlobalStringAttribute(dmpc.ATTR_DP_LAST_MODIFIED);
111: if (lm != null && lm.length() > 0) {
112: Long lastModified;
113: try {
114: lastModified = Long.valueOf(lm);
115: } catch (NumberFormatException nfe) {
116: lastModified = new Long(-1);
117: }
118: ConfigKey ck = new ConfigKey(getCMCPrincipal(),
119: CMCRolePrincipal.MEMBER_ROLE);
120: lastModifieds.put(ck, lastModified);
121: }
122:
123: return lastModifieds;
124: }
125: }
|