001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin;
007:
008: import java.io.*;
009: import java.net.*;
010: import java.util.Properties;
011: import java.util.Enumeration;
012: import java.util.Date;
013: import java.util.logging.Logger;
014: import java.util.logging.Level;
015: import java.text.DateFormat;
016:
017: import com.sun.portal.search.util.SearchConfig;
018: import com.sun.portal.search.db.SToken;
019: import com.sun.portal.search.admin.util.DBUtil;
020:
021: import javax.servlet.http.HttpServletRequest;
022: import javax.servlet.*;
023: import javax.servlet.http.*;
024:
025: import com.iplanet.sso.SSOTokenManager;
026: import com.iplanet.sso.SSOToken;
027: import com.iplanet.sso.SSOException;
028: import com.iplanet.sso.SSOTokenID;
029:
030: import com.iplanet.jato.Log;
031: import com.iplanet.jato.RequestContext;
032: import com.iplanet.jato.RequestHandler;
033: import com.iplanet.jato.model.Model;
034: import com.iplanet.jato.model.DefaultModel;
035: import com.iplanet.jato.model.DatasetModel;
036: import com.iplanet.jato.ModelManager;
037:
038: import com.iplanet.jato.view.event.DisplayEvent;
039: import com.iplanet.jato.view.event.ChildDisplayEvent;
040: import com.iplanet.jato.view.event.RequestInvocationEvent;
041: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
042:
043: import com.iplanet.jato.view.html.StaticTextField;
044: import com.iplanet.jato.view.html.TextField;
045: import com.iplanet.jato.view.html.Button;
046: import com.iplanet.jato.view.html.HREF;
047: import com.iplanet.jato.view.html.HiddenField;
048:
049: import com.iplanet.jato.view.View;
050: import com.iplanet.jato.view.ViewBean;
051: import com.iplanet.jato.view.ViewBeanBase;
052: import com.iplanet.jato.view.TiledView;
053: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
054:
055: import com.iplanet.jato.ViewBeanManager;
056:
057: import com.iplanet.am.console.components.view.html.IPlanetButton;
058:
059: import com.iplanet.jato.model.ModelControlException;
060:
061: import com.sun.portal.search.admin.model.DbStatModelImpl;
062: import com.sun.portal.log.common.PortalLogger;
063:
064: /**
065: * Tiled View that represents the DbStat per server
066: *
067: *
068: */
069: public class DbStatListDBView extends RequestHandlingTiledViewBase
070: implements TiledView, RequestHandler {
071:
072: // Create a logger for this class
073: private static Logger debugLogger = PortalLogger
074: .getLogger(DbStatListDBView.class);
075:
076: /**
077: *
078: *
079: */
080: public DbStatListDBView(View parent, String name) {
081: super (parent, name);
082:
083: try {
084: // We set the primary model *class* here instead of setting
085: // the actual model instance via setPrimaryModel(). Thus, the
086: // model isn't created unnecessarily just because this view is
087: // instantiated.
088: setPrimaryModel((DatasetModel) getDefaultModel());
089: registerChildren();
090: } catch (Exception e) {
091: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
092: .getMessage());
093: }
094: }
095:
096: /**
097: *
098: *
099: */
100: protected void registerChildren() {
101: registerChild(DB_NAME, StaticTextField.class);
102: registerChild(HIDDEN_DB_NAME, HiddenField.class);
103: registerChild(DB_STAT_ONFILE_STATUS, StaticTextField.class);
104: registerChild(DB_STAT_NB_RD, StaticTextField.class);
105: registerChild(DB_STAT_NB_SERVER, StaticTextField.class);
106: registerChild(DB_STAT_LIST_SERVER, DbStatListServerView.class);
107: registerChild(DB_STAT_LIST_PROTOCOL,
108: DbStatListProtocolView.class);
109: registerChild(DB_STAT_LAST_UPDATED, StaticTextField.class);
110: registerChild(DB_STAT_REFRESH, IPlanetButton.class);
111: }
112:
113: /**
114: *
115: *
116: */
117: protected View createChild(String name) {
118: if (name.equals(DB_NAME)) {
119: return new StaticTextField(this , DB_NAME, DB_NAME);
120: }
121: if (name.equals(HIDDEN_DB_NAME)) {
122: return new HiddenField(this , HIDDEN_DB_NAME, "");
123: }
124: if (name.equals(DB_STAT_ONFILE_STATUS)) {
125: return new StaticTextField(this , DB_STAT_ONFILE_STATUS,
126: DB_STAT_ONFILE_STATUS);
127: }
128: if (name.equals(DB_STAT_NB_RD)) {
129: return new StaticTextField(this , DB_STAT_NB_RD,
130: DB_STAT_NB_RD);
131: }
132: if (name.equals(DB_STAT_NB_SERVER)) {
133: return new StaticTextField(this , DB_STAT_NB_SERVER,
134: DB_STAT_NB_SERVER);
135: }
136: if (name.equals(DB_STAT_LIST_SERVER)) {
137: return new DbStatListServerView(this , DB_STAT_LIST_SERVER);
138: }
139: if (name.equals(DB_STAT_LIST_PROTOCOL)) {
140: return new DbStatListProtocolView(this ,
141: DB_STAT_LIST_PROTOCOL);
142: }
143: if (name.equals(DB_STAT_LAST_UPDATED)) {
144: return new StaticTextField(this , DB_STAT_LAST_UPDATED,
145: DB_STAT_LAST_UPDATED);
146: }
147: if (name.equals(DB_STAT_REFRESH)) {
148: DbStatViewBean pvb = (DbStatViewBean) getParentViewBean();
149: String btnLabel;
150: if (pvb != null) {
151: btnLabel = pvb.getLocalizedString("db.stat.refreshBtn");
152: } else {
153: btnLabel = "Refresh";
154: }
155: View child = new IPlanetButton(this , DB_STAT_REFRESH,
156: btnLabel);
157: return child;
158: }
159: debugLogger.log(Level.INFO, "PSSH_CSPSA0002", name);
160: throw new IllegalArgumentException("Invalid child name ["
161: + name + "]");
162: }
163:
164: /**
165: *
166: *
167: */
168: public void beginDisplay(DisplayEvent event)
169: throws ModelControlException {
170: super .beginDisplay(event);
171: resetTileIndex();
172: updateModel();
173: }
174:
175: private void updateModel() throws ModelControlException {
176: DefaultModel model = (DefaultModel) getPrimaryModel();
177: try {
178: // clear Model
179: model.clear();
180:
181: // do update the DB list from Root DB
182: String[] dbNames = DBUtil.getDBStringArray(CSConfig
183: .getServerRoot());
184: for (int i = 0; i < dbNames.length; i++) {
185: model.appendRow();
186: model.setValue(DB_NAME, dbNames[i]);
187: //initialize the database model
188: if (getDbStatModel(dbNames[i]) == null) {
189: debugLogger.log(Level.FINER, "PSSH_CSPSA0026",
190: dbNames[i]);
191: }
192: }
193:
194: // setting the number of tiles
195: getPrimaryModel().setSize(dbNames.length);
196: } catch (Exception e) {
197: debugLogger.info("PSSH_CSPSA0027");
198: getPrimaryModel().setSize(0);
199: }
200: }
201:
202: public boolean nextTile() throws ModelControlException {
203: boolean movedToRow = super .nextTile();
204: if (movedToRow) {
205: String currentDbName = (String) ((DefaultModel) getPrimaryModel())
206: .getValue(DB_NAME);
207: DbStatViewBean pvb = (DbStatViewBean) getParentViewBean();
208: if (currentDbName == null) {
209: currentDbName = SearchConfig
210: .getValue(SearchConfig.DBNAME);
211: }
212: DbStatModelImpl dbModel = getDbStatModel(currentDbName);
213:
214: setDisplayFieldValue(HIDDEN_DB_NAME, currentDbName);
215: setDisplayFieldValue(DB_NAME, currentDbName);
216: setDisplayFieldValue(DB_STAT_NB_RD, dbModel.getTotalNbRd());
217: setDisplayFieldValue(DB_STAT_NB_SERVER, dbModel
218: .getTotalNbServer());
219: Date lastUpdated = dbModel.getLastUpdated();
220: DateFormat df = DateFormat.getDateTimeInstance(
221: DateFormat.LONG, DateFormat.LONG, pvb
222: .getUserLocale());
223: try {
224: setDisplayFieldValue(DB_STAT_LAST_UPDATED, df
225: .format(lastUpdated));
226: } catch (Exception e) {
227: debugLogger.log(Level.INFO, "PSSH_CSPSA0028", e
228: .getMessage());
229: setDisplayFieldValue(DB_STAT_LAST_UPDATED, lastUpdated
230: .toString());
231: }
232: if (dbModel.isOld()) {
233: setDisplayFieldValue(DB_STAT_ONFILE_STATUS, pvb
234: .getLocalizedString("db.stat.outDated"));
235: ((IPlanetButton) getChild(DB_STAT_REFRESH,
236: getTileIndex())).setEnable(true);
237: } else {
238: setDisplayFieldValue(DB_STAT_ONFILE_STATUS, pvb
239: .getLocalizedString("db.stat.upToDate"));
240: ((IPlanetButton) getChild(DB_STAT_REFRESH,
241: getTileIndex())).setEnable(false);
242: }
243: }
244: return movedToRow;
245: }
246:
247: /*
248: * return's the current tile Database model
249: */
250: DbStatModelImpl getDbStatModel() {
251: return getDbStatModel((String) getPrimaryModel().getValue(
252: DbStatListDBView.DB_NAME));
253: }
254:
255: /*
256: *
257: */
258: private DbStatModelImpl getDbStatModel(String dbName) {
259: DbStatModelImpl dbModel = null;
260: try {
261: HttpSession session = getRequestContext().getRequest()
262: .getSession();
263: dbModel = (DbStatModelImpl) session.getAttribute(dbName);
264: if (dbModel == null) {
265: // initianalyzing model and adding it to the session
266: dbModel = new DbStatModelImpl(dbName);
267: session.setAttribute(dbName, dbModel);
268: }
269: return dbModel;
270: } catch (Exception e) {
271: debugLogger.log(Level.INFO, "PSSH_CSPSA0029", new String[] {
272: dbName, e.getMessage() });
273: return dbModel;
274: }
275: }
276:
277: ////////////////////////////////////////////////////////////////////////////
278: // Event handling methods
279: ////////////////////////////////////////////////////////////////////////////
280:
281: /**
282: * handles the Refresh of onFile Db Stat
283: */
284: public void handleDbStatRefreshRequest(RequestInvocationEvent event) {
285: try {
286: String[] dbNames = DBUtil.getDBStringArray(CSConfig
287: .getServerRoot());
288: DbStatModelImpl dbModel = getDbStatModel(dbNames[((TiledViewRequestInvocationEvent) event)
289: .getTileNumber()]);
290: if (dbModel.isOld()) {
291: dbModel.retrieve(false);
292: }
293: } catch (Exception e) {
294: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
295: .getMessage());
296: }
297: getParentViewBean().forwardTo(getRequestContext());
298: }
299:
300: ////////////////////////////////////////////////////////////////////////////
301: // Class variables
302: ////////////////////////////////////////////////////////////////////////////
303:
304: public static final String DB_NAME = "DatabaseName";
305: public static final String HIDDEN_DB_NAME = "HiddenDatabaseName";
306: public static final String DB_STAT_ONFILE_STATUS = "onFileAnalysisStatus";
307: public static final String DB_STAT_NB_RD = "DbStatNbRd";
308: public static final String DB_STAT_NB_SERVER = "DbStatNbServer";
309: public static final String DB_STAT_LIST_SERVER = "DbStatListServerView";
310: public static final String DB_STAT_LIST_PROTOCOL = "DbStatListProtocolView";
311: public static final String DB_STAT_LAST_UPDATED = "DbStatLastUpdated";
312: public static final String DB_STAT_REFRESH = "DbStatRefresh";
313:
314: ////////////////////////////////////////////////////////////////////////////
315: // Instance variables
316: ////////////////////////////////////////////////////////////////////////////
317: }
|