/**
* Copyright 2005 Sun Microsystems, Inc. All
* rights reserved. Use of this product is subject
* to license terms. Federal Acquisitions:
* Commercial Software -- Government Users
* Subject to Standard License Terms and
* Conditions.
*
* Sun, Sun Microsystems, the Sun logo, and Sun ONE
* are trademarks or registered trademarks of Sun Microsystems,
* Inc. in the United States and other countries.
*/
package com.sun.portal.admin.console.subscriptions;
import java.util.*;
import java.util.logging.Level;
import java.io.*;
import javax.faces.context.FacesContext;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.event.*;
import javax.faces.validator.*;
import javax.faces.el.ValueBinding;
import javax.servlet.http.HttpServletRequest;
import javax.management.*;
import com.sun.web.ui.model.*;
import com.sun.web.ui.event.*;
import com.sun.web.ui.component.*;
import com.sun.data.provider.*;
import com.sun.data.provider.impl.ObjectListDataProvider;
import com.sun.cacao.agent.JmxClient;
import com.sun.portal.admin.common.AttrOptionConstants;
import com.sun.portal.admin.common.util.*;
import com.sun.portal.admin.console.common.PSBaseBean;
public class AttributesBean extends PSBaseBean {
public static final String COMPONENT = "subscriptions";
// List of organization attributes
private static final String STARTPROFILER = "StartProfiler";
private static final String STOPPROFILER = "StopProfiler";
private static final String PROFILERSMTP = "ProfilerSMTP";
private static final String PROFILEREMAIL = "ProfilerEmail";
private static final String PROFILERPROVIDER = "ProfilerProvider";
private static final String PROFILERDEFAULTSEARCH = "ProfilerDefaultSearch";
private static final String PROFILERMAXHITS = "ProfilerMaxHits";
// List of dynamic attributes
private static final String MAXCATEGORYSUBSCRIPTIONS = "MaxCategorySubscriptions";
private static final String MAXDISCUSSIONSUBSCRIPTIONS = "MaxDiscussionSubscriptions";
private static final String MAXSAVEDSEARCH = "MaxSavedSearch";
// List of user attributes
private static final String CATEGORYSUBSCRIPTIONS = "CategorySubscriptions";
private static final String DISCUSSIONSUBSCRIPTIONS = "DiscussionSubscriptions";
private static final String SAVEDSEARCH = "SavedSearch";
private static final String PROFILERLASTRUN = "ProfilerLastRun";
private static final String PROFILERENABLED = "ProfilerEnabled";
private HashSet globalAttributes = null;
private HashSet orgAttributes = null;
private HashSet roleAttributes = null;
private HashSet userAttributes = null;
private HashMap globalAttributeValues = null;
private HashMap orgAttributeValues = null;
private HashMap roleAttributeValues = null;
private HashMap userAttributeValues = null;
private String lastDN = null;
public AttributesBean() {
globalAttributes = new HashSet();
globalAttributes.add(MAXCATEGORYSUBSCRIPTIONS);
globalAttributes.add(MAXDISCUSSIONSUBSCRIPTIONS);
globalAttributes.add(MAXSAVEDSEARCH);
orgAttributes = new HashSet();
orgAttributes.add(STARTPROFILER);
orgAttributes.add(STOPPROFILER);
orgAttributes.add(PROFILERSMTP);
orgAttributes.add(PROFILEREMAIL);
orgAttributes.add(PROFILERPROVIDER);
orgAttributes.add(PROFILERDEFAULTSEARCH);
orgAttributes.add(PROFILERMAXHITS);
orgAttributes.add(MAXCATEGORYSUBSCRIPTIONS);
orgAttributes.add(MAXDISCUSSIONSUBSCRIPTIONS);
orgAttributes.add(MAXSAVEDSEARCH);
roleAttributes = new HashSet();
roleAttributes.add(MAXCATEGORYSUBSCRIPTIONS);
roleAttributes.add(MAXDISCUSSIONSUBSCRIPTIONS);
roleAttributes.add(MAXSAVEDSEARCH);
userAttributes = new HashSet();
userAttributes.add(CATEGORYSUBSCRIPTIONS);
userAttributes.add(DISCUSSIONSUBSCRIPTIONS);
userAttributes.add(SAVEDSEARCH);
userAttributes.add(PROFILERLASTRUN);
userAttributes.add(PROFILERENABLED);
lastDN = "";
}
public boolean getShowError() {
retrieveAttributeValues(false);
String value = (String)getSessionAttribute("subscriptions.showerror");
if (value == null || value.equals("false")) {
return false;
} else {
return true;
}
}
public Option[] getAvailableBoolean() {
Option[] options = new Option[2];
options[0] = new Option("enabled", getLocalizedString("subscriptions", "subscriptions.general.enabled"));
options[1] = new Option("disabled", getLocalizedString("subscriptions", "subscriptions.general.disabled"));
return options;
}
public String[] getStartProfiler() {
return new String[0];
}
public void setStartProfiler(String[] values) {
}
public boolean isRenderStartProfiler() {
return false;
}
public String[] getStopProfiler() {
return new String[0];
}
public void setStopProfiler(String[] values) {
}
public boolean isRenderStopProfiler() {
return false;
}
public String getProfilerSMTP() {
if (isOrgDN((String)getCurrentDN())) {
retrieveAttributeValues(true);
return retrieveValue(orgAttributeValues, PROFILERSMTP);
} else {
return "";
}
}
public void setProfilerSMTP(String value) {
if (isOrgDN((String)getCurrentDN())) {
storeValue(orgAttributeValues, PROFILERSMTP, value);
}
}
public boolean isRenderProfilerSMTP() {
if (isOrgDN((String)getCurrentDN())) {
return true;
} else {
return false;
}
}
public String getProfilerEmail() {
if (isOrgDN((String)getCurrentDN())) {
retrieveAttributeValues(true);
return retrieveValue(orgAttributeValues, PROFILEREMAIL);
} else {
return "";
}
}
public void setProfilerEmail(String value) {
if (isOrgDN((String)getCurrentDN())) {
storeValue(orgAttributeValues, PROFILEREMAIL, value);
}
}
public boolean isRenderProfilerEmail() {
if (isOrgDN((String)getCurrentDN())) {
return true;
} else {
return false;
}
}
public String getProfilerProvider() {
if (isOrgDN((String)getCurrentDN())) {
retrieveAttributeValues(true);
return retrieveValue(orgAttributeValues, PROFILERPROVIDER);
} else {
return "";
}
}
public void setProfilerProvider(String value) {
if (isOrgDN((String)getCurrentDN())) {
storeValue(orgAttributeValues, PROFILERPROVIDER, value);
}
}
public boolean isRenderProfilerProvider() {
if (isOrgDN((String)getCurrentDN())) {
return true;
} else {
return false;
}
}
public String getProfilerDefaultSearch() {
if (isOrgDN((String)getCurrentDN())) {
retrieveAttributeValues(true);
return retrieveValue(orgAttributeValues, PROFILERDEFAULTSEARCH);
} else {
return "";
}
}
public void setProfilerDefaultSearch(String value) {
if (isOrgDN((String)getCurrentDN())) {
storeValue(orgAttributeValues, PROFILERDEFAULTSEARCH, value);
}
}
public boolean isRenderProfilerDefaultSearch() {
if (isOrgDN((String)getCurrentDN())) {
return true;
} else {
return false;
}
}
public String getProfilerMaxHits() {
if (isOrgDN((String)getCurrentDN())) {
retrieveAttributeValues(true);
return retrieveValue(orgAttributeValues, PROFILERMAXHITS);
} else {
return "";
}
}
public void setProfilerMaxHits(String value) {
if (isOrgDN((String)getCurrentDN())) {
storeValue(orgAttributeValues, PROFILERMAXHITS, value);
}
}
public boolean isRenderProfilerMaxHits() {
if (isOrgDN((String)getCurrentDN())) {
return true;
} else {
return false;
}
}
public String getMaxCategorySubscriptions() {
String currentDN = (String)getCurrentDN();
if (isGlobalDN(currentDN)) {
retrieveAttributeValues(true);
return retrieveValue(globalAttributeValues, MAXCATEGORYSUBSCRIPTIONS);
} else if (isOrgDN(currentDN)) {
retrieveAttributeValues(true);
return retrieveValue(orgAttributeValues, MAXCATEGORYSUBSCRIPTIONS);
} else if (isRoleDN(currentDN)) {
retrieveAttributeValues(true);
return retrieveValue(roleAttributeValues, MAXCATEGORYSUBSCRIPTIONS);
} else {
return "";
}
}
public void setMaxCategorySubscriptions(String value) {
String currentDN = (String)getCurrentDN();
if (isGlobalDN(currentDN)) {
storeValue(globalAttributeValues, MAXCATEGORYSUBSCRIPTIONS, value);
} else if (isOrgDN(currentDN)) {
storeValue(orgAttributeValues, MAXCATEGORYSUBSCRIPTIONS, value);
} else if (isRoleDN(currentDN)) {
storeValue(roleAttributeValues, MAXCATEGORYSUBSCRIPTIONS, value);
}
}
public boolean isRenderMaxCategorySubscriptions() {
String currentDN = (String)getCurrentDN();
if (isGlobalDN(currentDN) || isOrgDN(currentDN) || isRoleDN(currentDN)) {
return true;
} else {
return false;
}
}
public String getMaxDiscussionSubscriptions() {
String currentDN = (String)getCurrentDN();
if (isGlobalDN(currentDN)) {
retrieveAttributeValues(true);
return retrieveValue(globalAttributeValues, MAXDISCUSSIONSUBSCRIPTIONS);
} else if (isOrgDN(currentDN)) {
retrieveAttributeValues(true);
return retrieveValue(orgAttributeValues, MAXDISCUSSIONSUBSCRIPTIONS);
} else if (isRoleDN(currentDN)) {
retrieveAttributeValues(true);
return retrieveValue(roleAttributeValues, MAXDISCUSSIONSUBSCRIPTIONS);
} else {
return "";
}
}
public void setMaxDiscussionSubscriptions(String value) {
String currentDN = (String)getCurrentDN();
if (isGlobalDN(currentDN)) {
storeValue(globalAttributeValues, MAXDISCUSSIONSUBSCRIPTIONS, value);
} else if (isOrgDN(currentDN)) {
storeValue(orgAttributeValues, MAXDISCUSSIONSUBSCRIPTIONS, value);
} else if (isRoleDN(currentDN)) {
storeValue(roleAttributeValues, MAXDISCUSSIONSUBSCRIPTIONS, value);
}
}
public boolean isRenderMaxDiscussionSubscriptions() {
String currentDN = (String)getCurrentDN();
if (isGlobalDN(currentDN) || isOrgDN(currentDN) || isRoleDN(currentDN)) {
return true;
} else {
return false;
}
}
public String getMaxSavedSearch() {
String currentDN = (String)getCurrentDN();
if (isGlobalDN(currentDN)) {
retrieveAttributeValues(true);
return retrieveValue(globalAttributeValues, MAXSAVEDSEARCH);
} else if (isOrgDN(currentDN)) {
retrieveAttributeValues(true);
return retrieveValue(orgAttributeValues, MAXSAVEDSEARCH);
} else if (isRoleDN(currentDN)) {
retrieveAttributeValues(true);
return retrieveValue(roleAttributeValues, MAXSAVEDSEARCH);
} else {
return "";
}
}
public void setMaxSavedSearch(String value) {
String currentDN = (String)getCurrentDN();
if (isGlobalDN(currentDN)) {
storeValue(globalAttributeValues, MAXSAVEDSEARCH, value);
} else if (isOrgDN(currentDN)) {
storeValue(orgAttributeValues, MAXSAVEDSEARCH, value);
} else if (isRoleDN(currentDN)) {
storeValue(roleAttributeValues, MAXSAVEDSEARCH, value);
}
}
public boolean isRenderMaxSavedSearch() {
String currentDN = (String)getCurrentDN();
if (isGlobalDN(currentDN) || isOrgDN(currentDN) || isRoleDN(currentDN)) {
return true;
} else {
return false;
}
}
public String[] getCategorySubscriptions() {
if (isUserDN((String)getCurrentDN())) {
retrieveAttributeValues(true);
return retrieveValues(userAttributeValues, CATEGORYSUBSCRIPTIONS);
} else {
return new String[0];
}
}
public void setCategorySubscriptions(String[] values) {
if (isUserDN((String)getCurrentDN())) {
storeValues(userAttributeValues, CATEGORYSUBSCRIPTIONS, values);
}
}
public boolean isRenderCategorySubscriptions() {
if (isUserDN((String)getCurrentDN())) {
return true;
} else {
return false;
}
}
public String[] getDiscussionSubscriptions() {
if (isUserDN((String)getCurrentDN())) {
retrieveAttributeValues(true);
return retrieveValues(userAttributeValues, DISCUSSIONSUBSCRIPTIONS);
} else {
return new String[0];
}
}
public void setDiscussionSubscriptions(String[] values) {
if (isUserDN((String)getCurrentDN())) {
storeValues(userAttributeValues, DISCUSSIONSUBSCRIPTIONS, values);
}
}
public boolean isRenderDiscussionSubscriptions() {
if (isUserDN((String)getCurrentDN())) {
return true;
} else {
return false;
}
}
public String[] getSavedSearch() {
if (isUserDN((String)getCurrentDN())) {
retrieveAttributeValues(true);
return retrieveValues(userAttributeValues, SAVEDSEARCH);
} else {
return new String[0];
}
}
public void setSavedSearch(String[] values) {
if (isUserDN((String)getCurrentDN())) {
storeValues(userAttributeValues, SAVEDSEARCH, values);
}
}
public boolean isRenderSavedSearch() {
if (isUserDN((String)getCurrentDN())) {
return true;
} else {
return false;
}
}
public String getProfilerLastRun() {
return "";
}
public void setProfilerLastRun(String value) {
}
public boolean isRenderProfilerLastRun() {
return false;
}
public String getProfilerEnabled() {
if (isUserDN((String)getCurrentDN())) {
retrieveAttributeValues(true);
String value = retrieveValue(userAttributeValues, PROFILERENABLED);
return (value.equals("true")) ? "enabled" : "disabled";
} else {
return "disabled";
}
}
public void setProfilerEnabled(String value) {
if (isUserDN((String)getCurrentDN())) {
storeValue(userAttributeValues, PROFILERENABLED, (value.equals("enabled")) ? "true" : "false");
}
}
public boolean isRenderProfilerEnabled() {
if (isUserDN((String)getCurrentDN())) {
return true;
} else {
return false;
}
}
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
String id = component.getId();
if (id.equals("profilermaxhits")) {
if (!isValidPositiveInteger((String)value)) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, getLocalizedString("subscriptions", "subscriptions.error.error"), getLocalizedString("subscriptions", "subscriptions.error.positiveinteger")));
}
} else if (id.equals("maxcategorysubscriptions")) {
if (!isValidPositiveInteger((String)value)) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, getLocalizedString("subscriptions", "subscriptions.error.error"), getLocalizedString("subscriptions", "subscriptions.error.positiveinteger")));
}
} else if (id.equals("maxdiscussionsubscriptions")) {
if (!isValidPositiveInteger((String)value)) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, getLocalizedString("subscriptions", "subscriptions.error.error"), getLocalizedString("subscriptions", "subscriptions.error.positiveinteger")));
}
} else if (id.equals("maxsavedsearch")) {
if (!isValidPositiveInteger((String)value)) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, getLocalizedString("subscriptions", "subscriptions.error.error"), getLocalizedString("subscriptions", "subscriptions.error.positiveinteger")));
}
}
}
public String save() {
String currentDN = (String)getCurrentDN();
try {
Object[] params = new Object[2];
Map optionsMap = new HashMap();
optionsMap.put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
if (isGlobalDN(currentDN)) {
optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, globalAttributes);
params[0] = globalAttributeValues;
} else if (isOrgDN(currentDN)) {
optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, orgAttributes);
optionsMap.put(AttrOptionConstants.OPT_DN, currentDN);
params[0] = orgAttributeValues;
} else if (isRoleDN(currentDN)) {
optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, roleAttributes);
optionsMap.put(AttrOptionConstants.OPT_DN, currentDN);
params[0] = roleAttributeValues;
} else if (isUserDN(currentDN)) {
optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, userAttributes);
optionsMap.put(AttrOptionConstants.OPT_DN, currentDN);
params[0] = userAttributeValues;
}
params[1] = optionsMap;
String[] signature = {"java.util.Map", "java.util.Map"};
ObjectName on = AdminUtil.getPortalMBeanObjectName(getDomain(), (String)getSessionAttribute(ATTR_SELECTED_PORTAL));
getMBeanServerConnection().invoke(on, "setAttributes", params, signature);
setSessionAttribute("subscriptions.showerror", "false");
} catch (Exception e) {
log(Level.SEVERE, "AttributesBean.save()", e);
setSessionAttribute("subscriptions.showerror", "true");
}
lastDN = "";
return "reload";
}
public String reset() {
lastDN = "";
return "reload";
}
private void retrieveAttributeValues(boolean save) {
String currentDN = (String)getCurrentDN();
if (!currentDN.equals(lastDN)) {
try {
Map optionsMap = new HashMap();
optionsMap.put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
if (isGlobalDN(currentDN)) {
optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, globalAttributes);
} else if (isOrgDN(currentDN)) {
optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, orgAttributes);
optionsMap.put(AttrOptionConstants.OPT_DN, currentDN);
} else if (isRoleDN(currentDN)) {
optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, roleAttributes);
optionsMap.put(AttrOptionConstants.OPT_DN, currentDN);
} else if (isUserDN(currentDN)) {
optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, userAttributes);
optionsMap.put(AttrOptionConstants.OPT_DN, currentDN);
}
Object[] params = {optionsMap};
String[] signature = {"java.util.Map"};
ObjectName on = AdminUtil.getPortalMBeanObjectName(getDomain(), (String)getSessionAttribute(ATTR_SELECTED_PORTAL));
Map m = (Map)getMBeanServerConnection().invoke(on, "getAttributes", params, signature);
globalAttributeValues = new HashMap();
orgAttributeValues = new HashMap();
roleAttributeValues = new HashMap();
userAttributeValues = new HashMap();
if (isGlobalDN(currentDN)) {
initValue(m, globalAttributeValues, MAXCATEGORYSUBSCRIPTIONS);
initValue(m, globalAttributeValues, MAXDISCUSSIONSUBSCRIPTIONS);
initValue(m, globalAttributeValues, MAXSAVEDSEARCH);
} else if (isOrgDN(currentDN)) {
initValue(m, orgAttributeValues, STARTPROFILER);
initValue(m, orgAttributeValues, STOPPROFILER);
initValue(m, orgAttributeValues, PROFILERSMTP);
initValue(m, orgAttributeValues, PROFILEREMAIL);
initValue(m, orgAttributeValues, PROFILERPROVIDER);
initValue(m, orgAttributeValues, PROFILERDEFAULTSEARCH);
initValue(m, orgAttributeValues, PROFILERMAXHITS);
initValue(m, orgAttributeValues, MAXCATEGORYSUBSCRIPTIONS);
initValue(m, orgAttributeValues, MAXDISCUSSIONSUBSCRIPTIONS);
initValue(m, orgAttributeValues, MAXSAVEDSEARCH);
} else if (isRoleDN(currentDN)) {
initValue(m, roleAttributeValues, MAXCATEGORYSUBSCRIPTIONS);
initValue(m, roleAttributeValues, MAXDISCUSSIONSUBSCRIPTIONS);
initValue(m, roleAttributeValues, MAXSAVEDSEARCH);
} else if (isUserDN(currentDN)) {
initValue(m, userAttributeValues, CATEGORYSUBSCRIPTIONS);
initValue(m, userAttributeValues, DISCUSSIONSUBSCRIPTIONS);
initValue(m, userAttributeValues, SAVEDSEARCH);
initValue(m, userAttributeValues, PROFILERLASTRUN);
initValue(m, userAttributeValues, PROFILERENABLED);
}
setSessionAttribute("subscriptions.showerror", "false");
} catch (Exception e) {
log(Level.SEVERE, "AttributesBean.retrieveAttributeValues()", e);
setSessionAttribute("subscriptions.showerror", "true");
}
if (save) {
lastDN = currentDN;
}
}
}
private void initValue(Map srcMap, Map destMap, String key) {
if (srcMap.containsKey(key)) {
List values = (List)srcMap.get(key);
if (!values.isEmpty()) {
destMap.put(key, values);
} else {
ArrayList al = new ArrayList();
al.add("");
destMap.put(key, al);
}
} else {
ArrayList al = new ArrayList();
al.add("");
destMap.put(key, al);
}
}
private String retrieveValue(Map map, String key) {
String inError = (String)getSessionAttribute("subscriptions.showerror");
if ((inError == null || inError.equals("false")) && (map != null && map.containsKey(key))) {
List l = (List)map.get(key);
if (!l.isEmpty()) {
return (String)l.get(0);
} else {
return "";
}
} else {
return "";
}
}
private String[] retrieveValues(Map map, String key) {
String inError = (String)getSessionAttribute("subscriptions.showerror");
if ((inError == null || inError.equals("false")) && (map != null && map.containsKey(key))) {
List l = (List)map.get(key);
int size = l.size();
if (size == 0) {
return new String[0];
} else if (size == 1) {
String value = (String)l.get(0);
if (value.equals("")) {
return new String[0];
} else {
String[] values = new String[1];
values[0] = value;
return values;
}
} else {
String[] values = new String[size];
for (int index = 0; index < size; index++) {
values[index] = (String)l.get(index);
}
return values;
}
} else {
return new String[0];
}
}
private void storeValue(Map map, String key, String value) {
String inError = (String)getSessionAttribute("subscriptions.showerror");
if ((inError == null || inError.equals("false")) && map != null) {
ArrayList al = new ArrayList();
al.add(value);
map.put(key, al);
}
}
private void storeValues(Map map, String key, String[] values) {
String inError = (String)getSessionAttribute("subscriptions.showerror");
if ((inError == null || inError.equals("false")) && map != null) {
ArrayList al = new ArrayList();
if (values.length != 1 || !values[0].equals("")) {
for (int index = 0; index < values.length; al.add(values[index++]));
}
map.put(key, al);
}
}
private boolean isValidPositiveInteger(String value) {
if (value.equals("")) {
return true;
}
try {
int number = Integer.parseInt(value);
if (number < 0) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
}
|