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.io.*;
010: import java.util.*;
011:
012: import com.sun.portal.search.admin.CSConfig;
013: import com.sun.portal.search.admin.cli.RunImportAgent;
014: import com.sun.portal.search.util.SearchConfig;
015: import com.sun.portal.search.admin.util.Task;
016: import com.sun.portal.search.admin.util.ScheduleFactory;
017:
018: import com.iplanet.jato.model.*;
019:
020: public class ScheduleModel extends DefaultModel implements
021: RetrievingModel, UpdatingModel {
022: public static final String FIELD_NAME = "FieldName";
023: public static final String FIELD_HOUR = "FieldHour";
024: public static final String FIELD_MIN = "FieldMin";
025: public static final String FIELD_COMMAND = "Command";
026: public static final String FIELD_DIR = "Dir";
027: public static final String FIELD_SUN = "Sun";
028: public static final String FIELD_MON = "Mon";
029: public static final String FIELD_TUE = "Tue";
030: public static final String FIELD_WED = "Wed";
031: public static final String FIELD_THU = "Thu";
032: public static final String FIELD_FRI = "Fri";
033: public static final String FIELD_SAT = "Sat";
034: private static final String[] WEEKDAYS_ARRAY = { FIELD_SUN,
035: FIELD_MON, FIELD_TUE, FIELD_WED, FIELD_THU, FIELD_FRI,
036: FIELD_SAT };
037:
038: public static final String hourLabel[] = { "00", "01", "02", "03",
039: "04", "05", "06", "07", "08", "09", "10", "11", "12", "13",
040: "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" };
041: public static final String hourValues[] = { "0", "1", "2", "3",
042: "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14",
043: "15", "16", "17", "18", "19", "20", "21", "22", "23" };
044: public static final String minValues[] = { "00", "10", "20", "30",
045: "40", "50" };
046:
047: protected String name = null;
048:
049: /**
050: * @param req The HttpServletRequest object passed to the super class.
051: * @param rbName The name of the resource bundle.
052: */
053: public ScheduleModel() {
054: super ();
055: }
056:
057: public ScheduleModel(String name) {
058: super (name);
059: }
060:
061: public void setName(String name) {
062: this .name = name;
063: }
064:
065: // Model execution methods
066: ////////////////////////////////////////////////////////////////////////////////
067:
068: /**
069: *
070: *
071: */
072: public Object execute(ModelExecutionContext context)
073: throws ModelControlException {
074: String operationName = null;
075: if (context != null)
076: operationName = context.getOperationName();
077: else
078: operationName = ModelExecutionContext.OPERATION_RETRIEVE;
079:
080: Object result = null;
081: if (operationName
082: .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
083: result = retrieve(context);
084: }
085: return result;
086: }
087:
088: /**
089: *
090: *
091: */
092: public Object update(ModelExecutionContext context)
093: throws ModelControlException {
094: Task task = newTaskObject();
095: //String cmd = (String)getValue(FIELD_COMMAND);
096: //CSDebug.logln("ScheduleModel.update(" + name + "," + cmd + ")");
097: task.init(name);
098: task.setValue(Task.MINUTES, (String) getValue(FIELD_MIN));
099: task.setValue(Task.HOURS, (String) getValue(FIELD_HOUR));
100: String dir = (String) getValue(FIELD_DIR);
101: String d = "";
102: if (((String) getValue(FIELD_SUN)).compareTo("true") == 0) {
103: d = d + "0,";
104: }
105: if (((String) getValue(FIELD_MON)).compareTo("true") == 0) {
106: d = d + "1,";
107: }
108: if (((String) getValue(FIELD_TUE)).compareTo("true") == 0) {
109: d = d + "2,";
110: }
111: if (((String) getValue(FIELD_WED)).compareTo("true") == 0) {
112: d = d + "3,";
113: }
114: if (((String) getValue(FIELD_THU)).compareTo("true") == 0) {
115: d = d + "4,";
116: }
117: if (((String) getValue(FIELD_FRI)).compareTo("true") == 0) {
118: d = d + "5,";
119: }
120: if (((String) getValue(FIELD_SAT)).compareTo("true") == 0) {
121: d = d + "6,";
122: }
123: if (d.trim().length() > 0) {
124: task.setValue(Task.DAYS_OF_WEEK, d.substring(0,
125: d.length() - 1));
126: task.Update();
127: } else {
128: task.Remove();
129: }
130: return null;
131: }
132:
133: /**
134: *
135: *
136: */
137: public Object retrieve(ModelExecutionContext context)
138: throws ModelControlException {
139: // Perform a dummy retrieve operation. We ignore the
140: // execution context for now.
141: clear();
142: if (name != null) {
143: Task task = newTaskObject();
144: task.init(name);
145: setValue(FIELD_NAME, name);
146: //setValue(FIELD_COMMAND, cmd);
147: String hrs = task.getValue(Task.HOURS);
148: String mins = task.getValue(Task.MINUTES);
149: if (hrs != null && mins != null) {
150: setValue(FIELD_HOUR, hrs);
151: setValue(FIELD_MIN, mins);
152: }
153:
154: String v = task.getValue(Task.DAYS_OF_WEEK);
155: if (v != null) {
156: StringTokenizer st = new StringTokenizer(v, ",");
157: while (st.hasMoreTokens()) {
158: String d = st.nextToken();
159: int ndx = Integer.parseInt(d);
160: try {
161: setValue(WEEKDAYS_ARRAY[ndx], "true");
162: } catch (Exception e) {
163: }
164: }
165: }
166: }
167: // Nothing useful to return
168: return null;
169: }
170:
171: private Task newTaskObject() {
172: try {
173: return ScheduleFactory.getNewTask();
174: } catch (Exception e) {
175: return null;
176: }
177: }
178:
179: }
|