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.search;
013:
014: import java.util.*;
015: import java.util.logging.Level;
016: import java.io.*;
017:
018: import javax.faces.context.FacesContext;
019: import javax.faces.application.FacesMessage;
020: import javax.faces.component.UIComponent;
021: import javax.faces.validator.*;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.management.*;
024:
025: import com.sun.web.ui.model.*;
026: import com.sun.web.ui.event.*;
027:
028: import com.sun.data.provider.*;
029: import com.sun.data.provider.impl.ObjectListDataProvider;
030:
031: import com.sun.cacao.agent.JmxClient;
032:
033: import com.sun.portal.admin.common.util.AdminClientUtil;
034: import com.sun.portal.admin.console.common.PSBaseBean;
035:
036: public class CreateImportAgentBean extends PSBaseBean implements
037: WizardEventListener {
038:
039: public String type = "localfile";
040: public String destinationDatabase = "";
041: public String inputFile = "";
042: public String nickName = "";
043: public String ssl = "false";
044: public String server = "";
045: public String port = "";
046: public String instance = "";
047: public String uri = "";
048: public String database = "";
049: public String user = "";
050: public String password = "";
051: public String query = "all";
052: public String scope = "";
053: public String viewAttributes = "";
054: public String viewHits = "";
055: public String timeOut = "";
056: public boolean showError = false;
057: public String message = "";
058:
059: public CreateImportAgentBean() {
060: }
061:
062: public boolean handleEvent(WizardEvent event) {
063: switch (event.getNavigationEvent()) {
064: case WizardEvent.FINISH:
065: createImportAgent();
066: break;
067: case WizardEvent.CANCEL:
068: case WizardEvent.CLOSE:
069: type = "localfile";
070: destinationDatabase = "";
071: inputFile = "";
072: nickName = "";
073: ssl = "false";
074: server = "";
075: port = "";
076: uri = "";
077: database = "";
078: user = "";
079: password = "";
080: query = "all";
081: scope = "";
082: viewAttributes = "";
083: viewHits = "";
084: timeOut = "";
085: break;
086: default:
087: break;
088: }
089: return true;
090: }
091:
092: public Option[] getAvailableTypes() {
093: Option[] options = new Option[2];
094: options[0] = new Option("localfile", getLocalizedString(
095: "search", "search.importagent.type.localfile"));
096: options[1] = new Option("remoteserver", getLocalizedString(
097: "search", "search.importagent.type.remoteserver"));
098: return options;
099: }
100:
101: public Option[] getAvailableBoolean() {
102: Option[] options = new Option[2];
103: options[0] = new Option("true", getLocalizedString("search",
104: "search.general.true"));
105: options[1] = new Option("false", getLocalizedString("search",
106: "search.general.false"));
107: return options;
108: }
109:
110: public Option[] getAvailableQueries() {
111: Option[] options = new Option[2];
112: options[0] = new Option("all", getLocalizedString("search",
113: "search.importagent.query.all"));
114: options[1] = new Option("search", getLocalizedString("search",
115: "search.importagent.query.search"));
116: return options;
117: }
118:
119: public String getType() {
120: return type;
121: }
122:
123: public void setType(String type) {
124: this .type = type;
125: }
126:
127: public String getDestinationDatabase() {
128: return destinationDatabase;
129: }
130:
131: public void setDestinationDatabase(String destinationDatabase) {
132: this .destinationDatabase = destinationDatabase;
133: }
134:
135: public String getInputFile() {
136: return inputFile;
137: }
138:
139: public void setInputFile(String inputFile) {
140: this .inputFile = inputFile;
141: }
142:
143: public String getNickName() {
144: return nickName;
145: }
146:
147: public void setNickName(String nickName) {
148: this .nickName = nickName;
149: }
150:
151: public String getSsl() {
152: return ssl;
153: }
154:
155: public void setSsl(String ssl) {
156: this .ssl = ssl;
157: }
158:
159: public String getServer() {
160: return server;
161: }
162:
163: public void setServer(String server) {
164: this .server = server;
165: }
166:
167: public String getPort() {
168: return port;
169: }
170:
171: public void setPort(String port) {
172: this .port = port;
173: }
174:
175: public String getUri() {
176: return uri;
177: }
178:
179: public void setUri(String uri) {
180: this .uri = uri;
181: }
182:
183: public String getDatabase() {
184: return database;
185: }
186:
187: public void setDatabase(String database) {
188: this .database = database;
189: }
190:
191: public String getUser() {
192: return user;
193: }
194:
195: public void setUser(String user) {
196: this .user = user;
197: }
198:
199: public String getPassword() {
200: return password;
201: }
202:
203: public void setPassword(String password) {
204: this .password = password;
205: }
206:
207: public String getQuery() {
208: return query;
209: }
210:
211: public void setQuery(String query) {
212: this .query = query;
213: }
214:
215: public String getQueryTextValue() {
216: return getLocalizedString("search", "search.importagent.query."
217: + query);
218: }
219:
220: public String getScope() {
221: return scope;
222: }
223:
224: public void setScope(String scope) {
225: this .scope = scope;
226: }
227:
228: public String getViewAttributes() {
229: return viewAttributes;
230: }
231:
232: public void setViewAttributes(String viewAttributes) {
233: this .viewAttributes = viewAttributes;
234: }
235:
236: public String getViewHits() {
237: return viewHits;
238: }
239:
240: public void setViewHits(String viewHits) {
241: this .viewHits = viewHits;
242: }
243:
244: public boolean getShowError() {
245: return showError;
246: }
247:
248: public void setShowError(boolean showError) {
249: }
250:
251: public String getMessage() {
252: return message;
253: }
254:
255: public void setMessage(String message) {
256: }
257:
258: public String getTimeOut() {
259: return timeOut;
260: }
261:
262: public void setTimeOut(String timeOut) {
263: this .timeOut = timeOut;
264: }
265:
266: public boolean isTransient() {
267: return false;
268: }
269:
270: public void setTransient(boolean flag) {
271: }
272:
273: public Object saveState(FacesContext fc) {
274: return null;
275: }
276:
277: public void restoreState(FacesContext fc, Object state) {
278: }
279:
280: public void validate(FacesContext fc, UIComponent component,
281: Object value) throws ValidatorException {
282: String id = component.getId();
283: if (id.equals("inputfile")) {
284: if (Validators.containsSpace((String) value)) {
285: throw new ValidatorException(new FacesMessage(
286: FacesMessage.SEVERITY_ERROR,
287: getLocalizedString("search",
288: "search.error.error"),
289: getLocalizedString("search",
290: "search.error.space")));
291: }
292: if (Validators.containsSpecialCharacters((String) value)) {
293: throw new ValidatorException(new FacesMessage(
294: FacesMessage.SEVERITY_ERROR,
295: getLocalizedString("search",
296: "search.error.error"),
297: getLocalizedString("search",
298: "search.error.specialcharacters")));
299: }
300: } else if (id.equals("nickname")) {
301: } else if (id.equals("server")) {
302: if (Validators.containsSpace((String) value)) {
303: throw new ValidatorException(new FacesMessage(
304: FacesMessage.SEVERITY_ERROR,
305: getLocalizedString("search",
306: "search.error.error"),
307: getLocalizedString("search",
308: "search.error.space")));
309: }
310: if (Validators.containsSpecialCharacters((String) value)) {
311: throw new ValidatorException(new FacesMessage(
312: FacesMessage.SEVERITY_ERROR,
313: getLocalizedString("search",
314: "search.error.error"),
315: getLocalizedString("search",
316: "search.error.specialcharacters")));
317: }
318: } else if (id.equals("port")) {
319: if (!Validators.isPort((String) value)) {
320: throw new ValidatorException(new FacesMessage(
321: FacesMessage.SEVERITY_ERROR,
322: getLocalizedString("search",
323: "search.error.error"),
324: getLocalizedString("search",
325: "search.error.port")));
326: }
327: } else if (id.equals("uri")) {
328: if (Validators.containsSpace((String) value)) {
329: throw new ValidatorException(new FacesMessage(
330: FacesMessage.SEVERITY_ERROR,
331: getLocalizedString("search",
332: "search.error.error"),
333: getLocalizedString("search",
334: "search.error.space")));
335: }
336: if (Validators.containsSpecialCharacters((String) value)) {
337: throw new ValidatorException(new FacesMessage(
338: FacesMessage.SEVERITY_ERROR,
339: getLocalizedString("search",
340: "search.error.error"),
341: getLocalizedString("search",
342: "search.error.specialcharacters")));
343: }
344: } else if (id.equals("database")) {
345: if (Validators.containsSpace((String) value)) {
346: throw new ValidatorException(new FacesMessage(
347: FacesMessage.SEVERITY_ERROR,
348: getLocalizedString("search",
349: "search.error.error"),
350: getLocalizedString("search",
351: "search.error.space")));
352: }
353: if (Validators.containsSpecialCharacters((String) value)) {
354: throw new ValidatorException(new FacesMessage(
355: FacesMessage.SEVERITY_ERROR,
356: getLocalizedString("search",
357: "search.error.error"),
358: getLocalizedString("search",
359: "search.error.specialcharacters")));
360: }
361: } else if (id.equals("user")) {
362: } else if (id.equals("password")) {
363: } else if (id.equals("scope")) {
364: } else if (id.equals("viewAttributes")) {
365: } else if (id.equals("viewHits")) {
366: if (!Validators.isNumber((String) value, true)) {
367: throw new ValidatorException(new FacesMessage(
368: FacesMessage.SEVERITY_ERROR,
369: getLocalizedString("search",
370: "search.error.error"),
371: getLocalizedString("search",
372: "search.error.positivenumber")));
373: }
374: } else if (id.equals("timeout")) {
375: if (!Validators.isNumber((String) value, true)) {
376: throw new ValidatorException(new FacesMessage(
377: FacesMessage.SEVERITY_ERROR,
378: getLocalizedString("search",
379: "search.error.error"),
380: getLocalizedString("search",
381: "search.error.positivenumber")));
382: }
383: }
384: }
385:
386: private void createImportAgent() {
387: try {
388: LinkedList path = new LinkedList();
389: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
390: path
391: .addFirst((String) getSessionAttribute("search.server.selected"));
392: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
393: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
394:
395: if (type.equals("localfile")) {
396: Object[] params = { inputFile, destinationDatabase };
397: String[] signatures = { "java.lang.String",
398: "java.lang.String" };
399: getMBeanServerConnection().invoke(on,
400: "createImportAgent", params, signatures);
401: } else {
402: Properties p = new Properties();
403: p.setProperty("nickname", nickName);
404: p.setProperty("character-set", "UTF-8");
405: p.setProperty("is-compass301x", (type
406: .equals("remotecompassserver")) ? "true"
407: : "false");
408: p.setProperty("is-ssl", ssl);
409: p.setProperty("server", server);
410: p.setProperty("port", port);
411: p.setProperty("instance", "instance");
412: p.setProperty("uri", uri);
413: p.setProperty("database", database);
414: p.setProperty("user", user);
415: p.setProperty("password", password);
416: p.setProperty("is-search-query", (query
417: .equals("search")) ? "true" : "false");
418: p.setProperty("scope", scope);
419: p.setProperty("view-attributes", viewAttributes);
420: p.setProperty("view-hits", viewHits);
421: p.setProperty("last-collection-time", "");
422: p.setProperty("timeout", timeOut);
423:
424: Object[] params = { p, destinationDatabase };
425: String[] signatures = { "java.util.Properties",
426: "java.lang.String" };
427: getMBeanServerConnection().invoke(on,
428: "createImportAgent", params, signatures);
429: }
430:
431: showError = false;
432: message = getLocalizedString("search",
433: "search.createimportagent.success");
434: } catch (Exception e) {
435: showError = true;
436: message = getLocalizedString("search",
437: "search.error.generalfault");
438: log(Level.SEVERE,
439: "CreateImportAgentBean.createImportAgent() ", e);
440: }
441: }
442:
443: }
|