001: /**
002: * Copyright 2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.console.communities;
013:
014: import java.util.*;
015: import java.util.logging.Level;
016: import java.io.*;
017: import java.text.*;
018:
019: import javax.faces.context.FacesContext;
020: import javax.faces.application.FacesMessage;
021: import javax.faces.component.UIComponent;
022: import javax.faces.validator.*;
023: import javax.faces.el.ValueBinding;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.management.*;
026:
027: import com.sun.web.ui.model.*;
028: import com.sun.web.ui.event.*;
029: import com.sun.web.ui.component.*;
030:
031: import com.sun.data.provider.*;
032: import com.sun.data.provider.impl.ObjectListDataProvider;
033:
034: import com.sun.cacao.agent.JmxClient;
035:
036: import com.sun.portal.admin.common.util.AdminClientUtil;
037: import com.sun.portal.admin.console.common.PSBaseBean;
038:
039: public class AddCommunityUserBean extends PSBaseBean {
040:
041: private String communityName = "";
042: private String communityUser = "";
043:
044: public AddCommunityUserBean() {
045: communityName = (String) getSessionAttribute("addcommunityuser.community.selected");
046: }
047:
048: public boolean getShowError() {
049: String value = (String) getSessionAttribute("addcommunityuser.showerror");
050: if (value == null || value.equals("false")) {
051: return false;
052: } else {
053: return true;
054: }
055: }
056:
057: public String getCommunityUser() {
058: return communityUser;
059: }
060:
061: public void setCommunityUser(String communityUser) {
062: this .communityUser = communityUser;
063: }
064:
065: public void validate(FacesContext fc, UIComponent component,
066: Object value) throws ValidatorException {
067: String id = component.getId();
068: if (id.equals("user")) {
069: String message = null;
070: try {
071: LinkedList path = new LinkedList();
072: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
073: path.addFirst("amobjsearch");
074: ObjectName on = AdminClientUtil
075: .getResourceMBeanObjectName(
076: AdminClientUtil.AMOBJECTSEARCH_MBEAN_TYPE,
077: path);
078: Object[] params = { value };
079: String[] signatures = { "java.lang.String" };
080: Boolean result = (Boolean) getMBeanServerConnection()
081: .invoke(on, "isValidDN", params, signatures);
082: if (result.booleanValue() == false) {
083: message = getLocalizedString("communities",
084: "communities.error.invaliduserdn");
085: }
086: } catch (Exception e) {
087: log(Level.SEVERE,
088: "EditCommunityBean.validate() : Exception ", e);
089: message = getLocalizedString("communities",
090: "communities.error.generalfault");
091: }
092: if (message != null) {
093: throw new ValidatorException(new FacesMessage(
094: FacesMessage.SEVERITY_ERROR,
095: getLocalizedString("communities",
096: "communities.error.error"), message));
097: }
098:
099: try {
100: LinkedList path = new LinkedList();
101: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
102: path
103: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
104: path.addFirst("CommunityManager");
105: ObjectName on = AdminClientUtil
106: .getResourceMBeanObjectName(
107: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE,
108: path);
109:
110: Object[] params = { communityName, value };
111: String[] signatures = { "java.lang.String",
112: "java.lang.String" };
113: Boolean result = (Boolean) getMBeanServerConnection()
114: .invoke(on, "isCommunityUser", params,
115: signatures);
116: if (result.booleanValue()) {
117: message = getLocalizedString("communities",
118: "communities.error.duplicateuser");
119: }
120: } catch (Exception e) {
121: log(Level.SEVERE,
122: "EditCommunityBean.validate() : Exception ", e);
123: message = getLocalizedString("communities",
124: "communities.error.generalfault");
125: }
126: if (message != null) {
127: throw new ValidatorException(new FacesMessage(
128: FacesMessage.SEVERITY_ERROR,
129: getLocalizedString("communities",
130: "communities.error.error"), message));
131: }
132: }
133: }
134:
135: public String add() {
136: try {
137: LinkedList path = new LinkedList();
138: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
139: path
140: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
141: path.addFirst("CommunityManager");
142: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
143: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
144:
145: Object[] params = { communityName, communityUser };
146: String[] signatures = { "java.lang.String",
147: "java.lang.String" };
148: getMBeanServerConnection().invoke(on, "addUser", params,
149: signatures);
150: setSessionAttribute("addcommunityuser.showerror", "false");
151: return "gotoCommunityUsersHome";
152: } catch (Exception e) {
153: log(Level.SEVERE,
154: "AddCommunityUserBean.add() : Exception ", e);
155: setSessionAttribute("addcommunityuser.showerror", "true");
156: return null;
157: }
158: }
159:
160: public String cancel() {
161: return "gotoCommunityUsersHome";
162: }
163:
164: }
|