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: 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 EditImportAgentBean extends PSBaseBean {
040:
041: public String destinationDatabase = "";
042: public String inputFile = "";
043: public String inputFileExists = "";
044: public String nickName = "";
045: public String characterSet = "";
046: public String ssl = "false";
047: public String server = "";
048: public String port = "";
049: public String instance = "";
050: public String uri = "";
051: public String database = "";
052: public String user = "";
053: public String password = "";
054: public String query = "";
055: public String scope = "";
056: public String viewAttributes = "";
057: public String viewHits = "";
058: public String lastCollectionTime = "";
059: public String timeOut = "";
060:
061: public EditImportAgentBean() {
062: try {
063: LinkedList path = new LinkedList();
064: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
065: path
066: .addFirst((String) getSessionAttribute("search.server.selected"));
067: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
068: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
069:
070: Object[] params = {
071: (String) getSessionAttribute("search.importagent.selected"),
072: new ArrayList() };
073: String[] signatures = { "java.lang.String",
074: "java.util.List" };
075: Properties p = (Properties) getMBeanServerConnection()
076: .invoke(on, "getImportAgent", params, signatures);
077: destinationDatabase = getValue(p, "destination-database");
078: inputFile = getValue(p, "input-file");
079: inputFileExists = getValue(p, "input-file-exists");
080: nickName = getValue(p, "nickname");
081: characterSet = getValue(p, "character-set");
082: ssl = getValue(p, "is-ssl");
083: server = getValue(p, "server");
084: port = getValue(p, "port");
085: instance = getValue(p, "instance");
086: uri = getValue(p, "uri");
087: database = getValue(p, "database");
088: user = getValue(p, "user");
089: password = getValue(p, "password");
090: String isSearchQuery = getValue(p, "is-search-query");
091: scope = getValue(p, "scope");
092: viewAttributes = getValue(p, "view-attributes");
093: viewHits = getValue(p, "view-hits");
094: lastCollectionTime = getValue(p, "last-collection-time");
095: timeOut = getValue(p, "timeout");
096:
097: if (isSearchQuery.equals("true")) {
098: query = "search";
099: } else if (!lastCollectionTime.equals("")) {
100: query = "incremental";
101: } else {
102: query = "all";
103: }
104: } catch (Exception e) {
105: log(
106: Level.SEVERE,
107: "EditImportAgentBean.EditImportAgentBean() : Exception ",
108: e);
109: }
110: }
111:
112: public boolean getShowError() {
113: String value = (String) getSessionAttribute("search.editimportagent.showerror");
114: if (value == null || value.equals("false")) {
115: return false;
116: } else {
117: return true;
118: }
119: }
120:
121: public String getPageTitle() {
122: MessageFormat mf = new MessageFormat("");
123: mf.applyPattern(getLocalizedString("search",
124: "search.editimportagent.pagetitle"));
125: return mf
126: .format(new Object[] { (!nickName.equals("")) ? nickName
127: : inputFile });
128: }
129:
130: public Option[] getAvailableBoolean() {
131: Option[] options = new Option[2];
132: options[0] = new Option("true", getLocalizedString("search",
133: "search.general.true"));
134: options[1] = new Option("false", getLocalizedString("search",
135: "search.general.false"));
136: return options;
137: }
138:
139: public Option[] getAvailableQueries() {
140: Option[] options = new Option[3];
141: options[0] = new Option("all", getLocalizedString("search",
142: "search.importagent.query.all"));
143: options[1] = new Option("incremental", getLocalizedString(
144: "search", "search.importagent.query.incremental"));
145: options[2] = new Option("search", getLocalizedString("search",
146: "search.importagent.query.search"));
147: return options;
148: }
149:
150: public String getDestinationDatabase() {
151: return destinationDatabase;
152: }
153:
154: public void setDestinationDatabase(String destinationDatabase) {
155: this .destinationDatabase = destinationDatabase;
156: }
157:
158: public String getInputFile() {
159: return inputFile;
160: }
161:
162: public void setInputFile(String inputFile) {
163: this .inputFile = inputFile;
164: }
165:
166: public boolean getInputFileMissing() {
167: return (inputFileExists.equals("false")) ? true : false;
168: }
169:
170: public String getNickName() {
171: return nickName;
172: }
173:
174: public void setNickName(String nickName) {
175: this .nickName = nickName;
176: }
177:
178: public String getSsl() {
179: return ssl;
180: }
181:
182: public void setSsl(String ssl) {
183: this .ssl = ssl;
184: }
185:
186: public String getServer() {
187: return server;
188: }
189:
190: public void setServer(String server) {
191: this .server = server;
192: }
193:
194: public String getPort() {
195: return port;
196: }
197:
198: public void setPort(String port) {
199: this .port = port;
200: }
201:
202: public String getUri() {
203: return uri;
204: }
205:
206: public void setUri(String uri) {
207: this .uri = uri;
208: }
209:
210: public String getDatabase() {
211: return database;
212: }
213:
214: public void setDatabase(String database) {
215: this .database = database;
216: }
217:
218: public String getUser() {
219: return user;
220: }
221:
222: public void setUser(String user) {
223: this .user = user;
224: }
225:
226: public String getPassword() {
227: return password;
228: }
229:
230: public void setPassword(String password) {
231: this .password = password;
232: }
233:
234: public String getQuery() {
235: return query;
236: }
237:
238: public void setQuery(String query) {
239: this .query = query;
240: }
241:
242: public String getScope() {
243: return scope;
244: }
245:
246: public void setScope(String scope) {
247: this .scope = scope;
248: }
249:
250: public String getViewAttributes() {
251: return viewAttributes;
252: }
253:
254: public void setViewAttributes(String viewAttributes) {
255: this .viewAttributes = viewAttributes;
256: }
257:
258: public String getViewHits() {
259: return viewHits;
260: }
261:
262: public void setViewHits(String viewHits) {
263: this .viewHits = viewHits;
264: }
265:
266: public String getLastCollectionTime() {
267: return lastCollectionTime;
268: }
269:
270: public void setLastCollectionTime(String lastCollectionTime) {
271: this .lastCollectionTime = lastCollectionTime;
272: }
273:
274: public String getTimeOut() {
275: return timeOut;
276: }
277:
278: public void setTimeOut(String timeOut) {
279: this .timeOut = timeOut;
280: }
281:
282: public void validate(FacesContext fc, UIComponent component,
283: Object value) throws ValidatorException {
284: String id = component.getId();
285: if (id.equals("inputfile")) {
286: if (Validators.containsSpace((String) value)) {
287: throw new ValidatorException(new FacesMessage(
288: FacesMessage.SEVERITY_ERROR,
289: getLocalizedString("search",
290: "search.error.error"),
291: getLocalizedString("search",
292: "search.error.space")));
293: }
294: if (Validators.containsSpecialCharacters((String) value)) {
295: throw new ValidatorException(new FacesMessage(
296: FacesMessage.SEVERITY_ERROR,
297: getLocalizedString("search",
298: "search.error.error"),
299: getLocalizedString("search",
300: "search.error.specialcharacters")));
301: }
302: } else if (id.equals("nickname")) {
303: } else if (id.equals("server")) {
304: if (Validators.containsSpace((String) value)) {
305: throw new ValidatorException(new FacesMessage(
306: FacesMessage.SEVERITY_ERROR,
307: getLocalizedString("search",
308: "search.error.error"),
309: getLocalizedString("search",
310: "search.error.space")));
311: }
312: if (Validators.containsSpecialCharacters((String) value)) {
313: throw new ValidatorException(new FacesMessage(
314: FacesMessage.SEVERITY_ERROR,
315: getLocalizedString("search",
316: "search.error.error"),
317: getLocalizedString("search",
318: "search.error.specialcharacters")));
319: }
320: } else if (id.equals("port")) {
321: if (!Validators.isPort((String) value)) {
322: throw new ValidatorException(new FacesMessage(
323: FacesMessage.SEVERITY_ERROR,
324: getLocalizedString("search",
325: "search.error.error"),
326: getLocalizedString("search",
327: "search.error.port")));
328: }
329: } else if (id.equals("uri")) {
330: if (Validators.containsSpace((String) value)) {
331: throw new ValidatorException(new FacesMessage(
332: FacesMessage.SEVERITY_ERROR,
333: getLocalizedString("search",
334: "search.error.error"),
335: getLocalizedString("search",
336: "search.error.space")));
337: }
338: if (Validators.containsSpecialCharacters((String) value)) {
339: throw new ValidatorException(new FacesMessage(
340: FacesMessage.SEVERITY_ERROR,
341: getLocalizedString("search",
342: "search.error.error"),
343: getLocalizedString("search",
344: "search.error.specialcharacters")));
345: }
346: } else if (id.equals("database")) {
347: if (Validators.containsSpace((String) value)) {
348: throw new ValidatorException(new FacesMessage(
349: FacesMessage.SEVERITY_ERROR,
350: getLocalizedString("search",
351: "search.error.error"),
352: getLocalizedString("search",
353: "search.error.space")));
354: }
355: if (Validators.containsSpecialCharacters((String) value)) {
356: throw new ValidatorException(new FacesMessage(
357: FacesMessage.SEVERITY_ERROR,
358: getLocalizedString("search",
359: "search.error.error"),
360: getLocalizedString("search",
361: "search.error.specialcharacters")));
362: }
363: } else if (id.equals("user")) {
364: } else if (id.equals("password")) {
365: } else if (id.equals("scope")) {
366: } else if (id.equals("viewAttributes")) {
367: } else if (id.equals("viewHits")) {
368: if (!Validators.isNumber((String) value, true)) {
369: throw new ValidatorException(new FacesMessage(
370: FacesMessage.SEVERITY_ERROR,
371: getLocalizedString("search",
372: "search.error.error"),
373: getLocalizedString("search",
374: "search.error.positivenumber")));
375: }
376: } else if (id.equals("timeout")) {
377: if (!Validators.isNumber((String) value, true)) {
378: throw new ValidatorException(new FacesMessage(
379: FacesMessage.SEVERITY_ERROR,
380: getLocalizedString("search",
381: "search.error.error"),
382: getLocalizedString("search",
383: "search.error.positivenumber")));
384: }
385: }
386: }
387:
388: public String save1() {
389: try {
390: LinkedList path = new LinkedList();
391: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
392: path
393: .addFirst((String) getSessionAttribute("search.server.selected"));
394: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
395: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
396:
397: Object[] params = {
398: (String) getSessionAttribute("search.importagent.selected"),
399: inputFile, destinationDatabase };
400: String[] signatures = { "java.lang.String",
401: "java.lang.String", "java.lang.String" };
402: getMBeanServerConnection().invoke(on, "editImportAgent",
403: params, signatures);
404:
405: setSessionAttribute("search.editimportagent.showerror",
406: "false");
407: return "gotoDatabaseImportAgentsHome";
408: } catch (Exception e) {
409: log(Level.SEVERE,
410: "EditImportAgentBean.save1() : Exception ", e);
411: setSessionAttribute("search.editimportagent.showerror",
412: "true");
413: return null;
414: }
415: }
416:
417: public String save2() {
418: try {
419: LinkedList path = new LinkedList();
420: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
421: path
422: .addFirst((String) getSessionAttribute("search.server.selected"));
423: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
424: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
425:
426: Properties p = new Properties();
427: p.setProperty("nickname", nickName);
428: p.setProperty("character-set", characterSet);
429: p.setProperty("is-compass301x", "false");
430: p.setProperty("is-ssl", ssl);
431: p.setProperty("server", server);
432: p.setProperty("port", port);
433: p.setProperty("instance", instance);
434: p.setProperty("uri", uri);
435: p.setProperty("database", database);
436: p.setProperty("user", user);
437: p.setProperty("password", password);
438: p.setProperty("is-search-query",
439: (query.equals("search")) ? "true" : "false");
440: p.setProperty("scope", scope);
441: p.setProperty("view-attributes", viewAttributes);
442: p.setProperty("view-hits", viewHits);
443: p.setProperty("last-collection-time", (query
444: .equals("increment")) ? lastCollectionTime : "");
445: p.setProperty("timeout", timeOut);
446:
447: Object[] params = {
448: (String) getSessionAttribute("search.importagent.selected"),
449: p, destinationDatabase };
450: String[] signatures = { "java.lang.String",
451: "java.util.Properties", "java.lang.String" };
452: getMBeanServerConnection().invoke(on, "editImportAgent",
453: params, signatures);
454:
455: setSessionAttribute("search.editimportagent.showerror",
456: "false");
457: return "gotoDatabaseImportAgentsHome";
458: } catch (Exception e) {
459: log(Level.SEVERE,
460: "EditImportAgentBean.save2() : Exception ", e);
461: setSessionAttribute("search.editimportagent.showerror",
462: "true");
463: return null;
464: }
465: }
466:
467: public String cancel() {
468: setSessionAttribute("search.editimportagent.showerror", "false");
469: return "gotoDatabaseImportAgentsHome";
470: }
471:
472: private String getValue(Properties p, String key) {
473: if (p.containsKey(key)) {
474: return p.getProperty(key);
475: } else {
476: return "";
477: }
478: }
479:
480: }
|