001: package com.sun.portal.subscriptions.admin.mbeans.tasks;
002:
003: import java.util.*;
004: import java.util.logging.*;
005:
006: import com.sun.portal.fabric.common.GenericDSAMEAttributeHandler;
007: import com.sun.portal.admin.common.AttrOptionConstants;
008: import com.sun.portal.admin.common.PSMBeanException;
009: import com.sun.portal.admin.common.AttributeInfo;
010: import com.sun.portal.subscriptions.context.DSAMEMultiPortalConstants;
011: import com.sun.portal.subscriptions.context.DSAMEConstants;
012: import com.sun.portal.log.common.PortalLogger;
013:
014: public class SubscriptionsGetSetAttributeHandler extends
015: GenericDSAMEAttributeHandler {
016:
017: private static final String OPT_MP_ATTR_NAME = "mp-attribute-name";
018: private static final String OPT_MP_SERVICE_NAME = "mp-service-name";
019: private static final String ATTR_TYPE = "attribute-type";
020: private static final String TRUE_VALUE = "true";
021: private static final String FALSE_VALUE = "false";
022: private static final int SINGLE_COMMA_SEPERATED_STRING = 99;
023:
024: // Following is the list of supported subscriptions attributes for get/set/list
025:
026: // List of organization attributes
027: private static final String STARTPROFILER = "StartProfiler";
028: private static final String STOPPROFILER = "StopProfiler";
029: private static final String PROFILERSMTP = "ProfilerSMTP";
030: private static final String PROFILEREMAIL = "ProfilerEmail";
031: private static final String PROFILERPROVIDER = "ProfilerProvider";
032: private static final String PROFILERDEFAULTSEARCH = "ProfilerDefaultSearch";
033: private static final String PROFILERMAXHITS = "ProfilerMaxHits";
034:
035: // List of dynamic attributes
036: private static final String MAXCATEGORYSUBSCRIPTIONS = "MaxCategorySubscriptions";
037: private static final String MAXDISCUSSIONSUBSCRIPTIONS = "MaxDiscussionSubscriptions";
038: private static final String MAXSAVEDSEARCH = "MaxSavedSearch";
039:
040: // List of user attributes
041: private static final String CATEGORYSUBSCRIPTIONS = "CategorySubscriptions";
042: private static final String DISCUSSIONSUBSCRIPTIONS = "DiscussionSubscriptions";
043: private static final String SAVEDSEARCH = "SavedSearch";
044: private static final String PROFILERLASTRUN = "ProfilerLastRun";
045: private static final String PROFILERENABLED = "ProfilerEnabled";
046:
047: private DSAMEMultiPortalConstants dmpc = null;
048: private Map dynamicAttributesMap = new HashMap();
049: private Map orgAttributesMap = new HashMap();
050: private Map userAttributesMap = new HashMap();
051:
052: public void init(String component, String domainId, String portalId)
053: throws PSMBeanException {
054: super .init(component, domainId, portalId);
055:
056: DSAMEMultiPortalConstants.createInstance(portalId);
057: dmpc = DSAMEMultiPortalConstants.getInstance(portalId);
058: buildAttrMaps();
059: }
060:
061: private void buildAttrMaps() {
062: orgAttributesMap.put(STARTPROFILER, dmpc.ATTR_START_PROFILER);
063: orgAttributesMap.put(STOPPROFILER, dmpc.ATTR_STOP_PROFILER);
064: orgAttributesMap.put(PROFILERSMTP, dmpc.ATTR_PROFILER_SMTP);
065: orgAttributesMap.put(PROFILEREMAIL, dmpc.ATTR_PROFILER_EMAIL);
066: orgAttributesMap.put(PROFILERPROVIDER,
067: dmpc.ATTR_PROFILER_PROVIDER);
068: orgAttributesMap.put(PROFILERDEFAULTSEARCH,
069: dmpc.ATTR_PROFILER_DEFAULT_SEARCH);
070: orgAttributesMap.put(PROFILERMAXHITS,
071: dmpc.ATTR_PROFILER_MAX_HITS);
072:
073: dynamicAttributesMap.put(MAXCATEGORYSUBSCRIPTIONS,
074: dmpc.MP_ATTR_MAX_CATEGORY_SUBSCRIPTIONS);
075: dynamicAttributesMap.put(MAXDISCUSSIONSUBSCRIPTIONS,
076: dmpc.MP_ATTR_MAX_DISCUSSION_SUBSCRIPTIONS);
077: dynamicAttributesMap.put(MAXSAVEDSEARCH,
078: dmpc.MP_ATTR_MAX_SAVED_SEARCH);
079:
080: userAttributesMap.put(CATEGORYSUBSCRIPTIONS,
081: dmpc.MP_ATTR_CATEGORY_SUBSCRIPTIONS);
082: userAttributesMap.put(DISCUSSIONSUBSCRIPTIONS,
083: dmpc.MP_ATTR_DISCUSSION_SUBSCRIPTIONS);
084: userAttributesMap.put(SAVEDSEARCH, dmpc.MP_ATTR_SAVED_SEARCH);
085: userAttributesMap.put(PROFILERLASTRUN,
086: dmpc.MP_ATTR_PROFILER_LAST_RUN);
087: userAttributesMap.put(PROFILERENABLED,
088: dmpc.MP_ATTR_PROFILER_ENABLED);
089: }
090:
091: public String getComponentName(String userFriendlyName) {
092: return dmpc.MP_SUN_SUBSCRIPTION_SERVICE;
093: }
094:
095: public String getAttributeName(String userFriendlyName) {
096: String name = (String) orgAttributesMap.get(userFriendlyName);
097: if (name != null) {
098: return name;
099: }
100: name = (String) dynamicAttributesMap.get(userFriendlyName);
101: if (name != null) {
102: return name;
103: }
104: name = (String) userAttributesMap.get(userFriendlyName);
105: if (name != null) {
106: return name;
107: }
108: return "";
109: }
110:
111: private boolean isOrg(String name) {
112: if (orgAttributesMap.containsKey(name)) {
113: return true;
114: }
115: return false;
116: }
117:
118: private boolean isDynamic(String name) {
119: if (dynamicAttributesMap.containsKey(name)) {
120: return true;
121: }
122: return false;
123: }
124:
125: public void setAttribute(List values, Map optionsMap)
126: throws PSMBeanException {
127: String name = (String) optionsMap
128: .get(AttrOptionConstants.OPT_ATTR_NAME);
129: if (isOrg(name)) {
130: optionsMap.put(AttrOptionConstants.OPT_ORG, "true");
131: }
132: super .setAttribute(values, optionsMap);
133: }
134:
135: public void setAttributes(Map nameValues, Map optionsMap)
136: throws PSMBeanException {
137: Map orgAttrNameValueMap = new HashMap();
138: Map dymanicAttrNameValueMap = new HashMap();
139: Map userAttrNameValueMap = new HashMap();
140:
141: Set attrNames = (Set) optionsMap
142: .get(AttrOptionConstants.OPT_ATTR_NAMES);
143: Iterator i = attrNames.iterator();
144: while (i.hasNext()) {
145: String attrName = (String) i.next();
146: if (isOrg(attrName)) {
147: orgAttrNameValueMap.put(attrName, nameValues
148: .get(attrName));
149: } else if (isDynamic(attrName)) {
150: dymanicAttrNameValueMap.put(attrName, nameValues
151: .get(attrName));
152: } else {
153: userAttrNameValueMap.put(attrName, nameValues
154: .get(attrName));
155: }
156: }
157:
158: if (orgAttrNameValueMap.size() > 0) {
159: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
160: orgAttrNameValueMap.keySet());
161: optionsMap.put(AttrOptionConstants.OPT_ORG, TRUE_VALUE);
162: super .setAttributes(orgAttrNameValueMap, optionsMap);
163: }
164: if (dymanicAttrNameValueMap.size() > 0) {
165: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
166: dymanicAttrNameValueMap.keySet());
167: optionsMap.put(AttrOptionConstants.OPT_ORG, FALSE_VALUE);
168: super .setAttributes(dymanicAttrNameValueMap, optionsMap);
169: }
170: if (userAttrNameValueMap.size() > 0) {
171: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
172: userAttrNameValueMap.keySet());
173: optionsMap.put(AttrOptionConstants.OPT_ORG, FALSE_VALUE);
174: super .setAttributes(userAttrNameValueMap, optionsMap);
175: }
176: }
177:
178: public List getAttribute(Map optionsMap) throws PSMBeanException {
179: String name = (String) optionsMap
180: .get(AttrOptionConstants.OPT_ATTR_NAME);
181: if (isOrg(name)) {
182: optionsMap.put(AttrOptionConstants.OPT_ORG, "true");
183: }
184: return super .getAttribute(optionsMap);
185: }
186:
187: public Map getAttributes(Map optionsMap) throws PSMBeanException {
188: Map m = new HashMap();
189:
190: Set orgAttrSet = new HashSet();
191: Set dymanicAttrSet = new HashSet();
192: Set userAttrSet = new HashSet();
193:
194: Set attrNames = (Set) optionsMap
195: .get(AttrOptionConstants.OPT_ATTR_NAMES);
196: Iterator i = attrNames.iterator();
197: while (i.hasNext()) {
198: String attrName = (String) i.next();
199: if (isOrg(attrName)) {
200: orgAttrSet.add(attrName);
201: } else if (isDynamic(attrName)) {
202: dymanicAttrSet.add(attrName);
203: } else {
204: userAttrSet.add(attrName);
205: }
206: }
207:
208: if (orgAttrSet.size() > 0) {
209: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
210: orgAttrSet);
211: optionsMap.put(AttrOptionConstants.OPT_ORG, TRUE_VALUE);
212: m.putAll(super .getAttributes(optionsMap));
213: }
214: if (dymanicAttrSet.size() > 0) {
215: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
216: dymanicAttrSet);
217: optionsMap.put(AttrOptionConstants.OPT_ORG, FALSE_VALUE);
218: m.putAll(super .getAttributes(optionsMap));
219: }
220: if (userAttrSet.size() > 0) {
221: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES,
222: userAttrSet);
223: optionsMap.put(AttrOptionConstants.OPT_ORG, FALSE_VALUE);
224: m.putAll(super .getAttributes(optionsMap));
225: }
226:
227: return m;
228: }
229:
230: /**
231: * Overridden to provide component specific attribute information
232: * @param optionsMap
233: * @return java.uti.Map
234: * @throws PSMBeanException
235: */
236: public Map listAttributes(Map optionsMap) throws PSMBeanException {
237: Map attributeMap = new HashMap();
238:
239: attributeMap.put(STARTPROFILER, getAttributeInfoList(
240: AttributeInfo.SINGLE_STRING,
241: "psadmin.list.subscriptions.startprofiler.desc",
242: AttributeInfo.READ_WRITE, null));
243:
244: attributeMap.put(STOPPROFILER, getAttributeInfoList(
245: AttributeInfo.SINGLE_STRING,
246: "psadmin.list.subscriptions.stopprofiler.desc",
247: AttributeInfo.READ_WRITE, null));
248:
249: attributeMap.put(PROFILERSMTP, getAttributeInfoList(
250: AttributeInfo.SINGLE_STRING,
251: "psadmin.list.subscriptions.profilersmtp.desc",
252: AttributeInfo.READ_WRITE, null));
253:
254: attributeMap.put(PROFILEREMAIL, getAttributeInfoList(
255: AttributeInfo.SINGLE_STRING,
256: "psadmin.list.subscriptions.profileremail.desc",
257: AttributeInfo.READ_WRITE, null));
258:
259: attributeMap.put(PROFILERPROVIDER, getAttributeInfoList(
260: AttributeInfo.SINGLE_STRING,
261: "psadmin.list.subscriptions.profilerprovider.desc",
262: AttributeInfo.READ_WRITE, null));
263:
264: attributeMap
265: .put(
266: PROFILERDEFAULTSEARCH,
267: getAttributeInfoList(
268: AttributeInfo.SINGLE_STRING,
269: "psadmin.list.subscriptions.profilerdefaultsearch.desc",
270: AttributeInfo.READ_WRITE, null));
271:
272: attributeMap.put(PROFILERMAXHITS, getAttributeInfoList(
273: AttributeInfo.SINGLE_NUMERIC,
274: "psadmin.list.subscriptions.profilermaxhits.desc",
275: AttributeInfo.READ_WRITE, null));
276:
277: attributeMap
278: .put(
279: MAXCATEGORYSUBSCRIPTIONS,
280: getAttributeInfoList(
281: AttributeInfo.SINGLE_NUMERIC,
282: "psadmin.list.subscriptions.maxcategorysubscriptions.Desc",
283: AttributeInfo.READ_WRITE, null));
284:
285: attributeMap
286: .put(
287: MAXDISCUSSIONSUBSCRIPTIONS,
288: getAttributeInfoList(
289: AttributeInfo.SINGLE_NUMERIC,
290: "psadmin.list.subscriptions.maxdiscussionsubscriptions.desc",
291: AttributeInfo.READ_WRITE, null));
292:
293: attributeMap.put(MAXSAVEDSEARCH, getAttributeInfoList(
294: AttributeInfo.SINGLE_NUMERIC,
295: "psadmin.list.subscriptions.maxsavedsearch.desc",
296: AttributeInfo.READ_WRITE, null));
297:
298: attributeMap
299: .put(
300: CATEGORYSUBSCRIPTIONS,
301: getAttributeInfoList(
302: AttributeInfo.LIST_STRING,
303: "psadmin.list.subscriptions.categorysubscriptions.desc",
304: AttributeInfo.READ_WRITE, null));
305:
306: attributeMap
307: .put(
308: DISCUSSIONSUBSCRIPTIONS,
309: getAttributeInfoList(
310: AttributeInfo.LIST_STRING,
311: "psadmin.list.subscriptions.discussionsubscriptions.desc",
312: AttributeInfo.READ_WRITE, null));
313:
314: attributeMap.put(SAVEDSEARCH, getAttributeInfoList(
315: AttributeInfo.LIST_STRING,
316: "psadmin.list.subscriptions.savedsearch.desc",
317: AttributeInfo.READ_WRITE, null));
318:
319: attributeMap.put(PROFILERLASTRUN, getAttributeInfoList(
320: AttributeInfo.SINGLE_STRING,
321: "psadmin.list.subscriptions.profilerlastrun.desc",
322: AttributeInfo.READ_WRITE, null));
323:
324: attributeMap.put(PROFILERENABLED, getAttributeInfoList(
325: AttributeInfo.SINGLE_BOOLEAN,
326: "psadmin.list.subscriptions.profilerenabled.desc",
327: AttributeInfo.READ_WRITE, null));
328:
329: return attributeMap;
330: }
331:
332: /**
333: * Helper method for list command
334: * @param attributeType
335: * @param desc
336: * @param privilege
337: * @param exampleKey
338: * @return java.util.List
339: */
340: private List getAttributeInfoList(int attributeType, String desc,
341: int privilege, String exampleKey) {
342: List infoList = new ArrayList();
343: infoList.add(new Integer(attributeType));
344: infoList.add(desc);
345: infoList.add(new Integer(privilege));
346: infoList.add(exampleKey);
347: return infoList;
348: }
349:
350: }
|