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.model;
007:
008: import java.lang.*;
009: import java.util.*;
010: import javax.servlet.http.HttpServletRequest;
011:
012: import com.sun.portal.search.util.SearchConfig;
013: import com.sun.portal.search.admin.CSConfig;
014: import com.sun.portal.search.admin.ImportConfig;
015:
016: import com.iplanet.jato.model.*;
017:
018: /**
019: * This class supports the MenuListView by providing the data in the
020: * format expected by the view.
021: */
022: public class ImportAgentModel extends DefaultModel implements
023: RetrievingModel, UpdatingModel {
024: public static final String FIELD_ID = "FieldID";
025: public static final String FIELD_IMAGE = "FieldImage";
026: public static final String FIELD_TYPE = "FieldType";
027: public static final String FIELD_NAME = "FieldName";
028: public static final String FIELD_CLEAR_TIME_STAMP = "ClearTimeStamp";
029: static final String FieldList[] = { ImportConfig.ID,
030: ImportConfig.AGENT_TYPE, ImportConfig.SRCFILE,
031: ImportConfig.SERVER_PORT, ImportConfig.INSTANCE_NAME,
032: ImportConfig.SEARCH_URI, ImportConfig.SEARCH_DB,
033: ImportConfig.LOCAL_DB, ImportConfig.IS_SSL,
034: ImportConfig.IS_COMPASS, ImportConfig.US_AUTH,
035: ImportConfig.USER, ImportConfig.PASSWORD,
036: ImportConfig.RDM_QUERY_LANGUAGE, ImportConfig.TIME_STAMP,
037: ImportConfig.SCOPE, ImportConfig.VIEW_ATTRIBUTES,
038: ImportConfig.VIEW_HITS, ImportConfig.NICKNAME,
039: ImportConfig.TIMEOUT, ImportConfig.CHARSET };
040: static final String UpdateFieldList[] = { ImportConfig.SRCFILE,
041: ImportConfig.USER, ImportConfig.PASSWORD,
042: ImportConfig.RDM_QUERY_LANGUAGE, ImportConfig.SCOPE,
043: ImportConfig.SEARCH_DB, ImportConfig.LOCAL_DB,
044: ImportConfig.VIEW_ATTRIBUTES, ImportConfig.VIEW_HITS,
045: ImportConfig.NICKNAME, ImportConfig.TIMEOUT,
046: ImportConfig.TIME_STAMP, ImportConfig.CHARSET };
047:
048: private String errorMsg = null;
049:
050: protected String id = null;
051:
052: public ImportAgentModel() {
053: super ();
054: }
055:
056: public ImportAgentModel(String name) {
057: super (name);
058: }
059:
060: public void setID(String importID) {
061: id = importID;
062: }
063:
064: public Object execute(ModelExecutionContext context)
065: throws ModelControlException {
066: String operationName = null;
067: if (context != null)
068: operationName = context.getOperationName();
069: else
070: operationName = ModelExecutionContext.OPERATION_RETRIEVE;
071:
072: Object result = null;
073: if (operationName
074: .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
075: result = retrieve(context);
076: }
077:
078: return result;
079: }
080:
081: public Object update(ModelExecutionContext context)
082: throws ModelControlException {
083: String value = null;
084: ImportConfig imp = null;
085: boolean isNew = false;
086: String id = (String) this .getValue(ImportConfig.ID);
087: if (id != null) {
088: imp = ImportConfig.getImportConfigByID(id);
089: }
090: if (imp == null) {
091: isNew = true;
092: imp = ImportConfig.newImportAgent();
093: imp.setValue(ImportConfig.ENABLE, "true");
094: imp.setValue(ImportConfig.DESTINATION_CSID, SearchConfig
095: .getSearchConfig().getValue(SearchConfig.CSID));
096: }
097: for (int i = 0; i < UpdateFieldList.length; i++) {
098: value = (String) getValue(UpdateFieldList[i]);
099: if (value != null && value.trim().length() > 0) {
100: imp.setValue(UpdateFieldList[i], value.trim());
101: } else {
102: imp.remove(UpdateFieldList[i]);
103: }
104: }
105: value = (String) this .getValue(ImportConfig.AGENT_TYPE);
106: if (value != null) {
107: if (value.compareTo(ImportConfig.TYPE_LOCALFILE) == 0) {
108: value = (String) this .getValue(ImportConfig.SRCFILE);
109: imp.setValue(ImportConfig.SRCFILE, value.trim());
110: imp.remove(ImportConfig.CSID);
111: } else {
112: value = (String) this .getValue(ImportConfig.IS_SSL);
113: String x_cata = null;
114: if (value.compareTo("true") == 0) {
115: x_cata = "x-catalogs://";
116: } else {
117: x_cata = "x-catalog://";
118: }
119: x_cata = x_cata
120: + (String) this
121: .getValue(ImportConfig.SERVER_PORT)
122: + "/"
123: + (String) this
124: .getValue(ImportConfig.INSTANCE_NAME);
125: imp.remove(ImportConfig.SRCFILE);
126: imp.setValue(ImportConfig.CSID, x_cata);
127: value = (String) this .getValue(ImportConfig.IS_COMPASS);
128: if (value.compareTo("false") == 0) {
129: value = (String) this
130: .getValue(ImportConfig.SEARCH_URI);
131: imp.setValue(ImportConfig.SEARCH_URI, value);
132: imp.remove(ImportConfig.USE_RDM_INCOMING);
133: } else {
134: imp.remove(ImportConfig.SEARCH_URI);
135: imp.setValue(ImportConfig.USE_RDM_INCOMING, "true");
136: value = (String) imp
137: .getValue(ImportConfig.RDM_QUERY_LANGUAGE);
138: if (value != null
139: && value != ImportConfig.QL_GATHERER) {
140: imp.setValue(ImportConfig.RDM_QUERY_LANGUAGE,
141: ImportConfig.QL_COMPASS);
142: }
143: }
144:
145: }
146: } else {
147: ImportConfig.DeleteImportConfigByID(imp.getID());
148: }
149: if (isNew) {
150: if (!ImportConfig.addImportAgent(imp)) {
151: errorMsg = "Duplicated";
152: return null;
153: }
154: }
155: ImportConfig.updateFile();
156: return null;
157: }
158:
159: public Object retrieve(ModelExecutionContext context)
160: throws ModelControlException {
161:
162: clear();
163: if (id != null || id.trim().length() > 0) {
164: ImportConfig imp = ImportConfig.getImportConfigByID(id);
165: if (imp != null) {
166: for (int i = 0; i < this .FieldList.length; i++) {
167: setValue(FieldList[i], imp.getValue(FieldList[i]));
168: }
169: }
170: } else {
171: //new importagent
172: setValue(ImportConfig.ID, id);
173: setValue(ImportConfig.AGENT_TYPE,
174: ImportConfig.TYPE_LOCALFILE);
175: }
176: // Nothing useful to return
177: return null;
178: }
179:
180: public String getErrorMsg() {
181: return errorMsg;
182: }
183:
184: }
|