001: /**
002: * Copyright 2002 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: *
013: */package com.sun.portal.app.sharedevents.models;
014:
015: import java.util.*;
016: import java.util.logging.*;
017:
018: import com.sun.comclient.calendar.*;
019: import com.sun.portal.app.sharedevents.util.AppUtils;
020: import com.sun.portal.app.sharedevents.util.SharedConstants;
021: import com.sun.portal.log.common.PortalLogger;
022:
023: /**
024: * EventsListModel class provides an interface to a set of events. This
025: * model is useful for event management and processing a set of events.
026: * <br>
027: * The EventsListModel provides all means of access machanisms such as
028: * fetch a set of events, load the fetched events or given events and
029: * manage events such as update or delete a bunch of events.
030: * <p>
031: * It provides following execute contexts for event lists
032: * <br><code>LOAD_EVENT_CONTEXT</code></b> -- fetches set of events
033: * <p>
034: * <p>
035: * @author Sai
036: * <p>
037: */
038: public class EventsListModel {
039: private transient ArrayList _events = null;
040: private transient ArrayList _calids = null;
041: private transient DateTime _start = null;
042: private transient DateTime _end = null;
043: private transient boolean _searchMode = false;
044: private transient DateTime _selectedDate = null;
045: private transient String viewCtx = null;
046: private transient String searchText = null;
047:
048: private CalendarBaseModel cbm = null;
049: private HashMap calids = null;
050:
051: //// Definitions, fields and data structures for set of tasks
052:
053: private String CLASS_NAME = "EventsListModel";
054:
055: private static Logger logger = PortalLogger
056: .getLogger(EventsListModel.class);
057:
058: public EventsListModel() {
059: logger.entering(CLASS_NAME, "EventsListModel()");
060: logger.exiting(CLASS_NAME, "EventsListModel()");
061: }
062:
063: public EventsListModel(String name) {
064: logger.entering(CLASS_NAME, "EventsListModel(" + name + ")");
065: logger.exiting(CLASS_NAME, "EventsListModel(" + name + ")");
066: }
067:
068: /**
069: * Gets the events that are being used in next load context.
070: * <p>
071: * @return List of events that are being used in next load context
072: * <p>
073: */
074: public ArrayList getEvents() {
075: return this ._events;
076: }
077:
078: /**
079: * Sets the events to be loaded in next load context.
080: * <p>
081: * @param events List of events to be loaded in next load context
082: * <p>
083: */
084: public void setEvents(ArrayList events) {
085: this ._events = events;
086: }
087:
088: /*
089: * Can be used by the caller to set the start Date & Time
090: */
091: public void setContextStartDt(DateTime dt) {
092: _start = dt;
093: }
094:
095: /*
096: * Can be used by the caller to set the end Date & Time
097: */
098: public void setContextEndDt(DateTime dt) {
099: _end = dt;
100: }
101:
102: public void setViewContext(String viewContext) {
103: viewCtx = viewContext;
104: }
105:
106: public void setSearchMode(boolean value) {
107: _searchMode = value;
108: }
109:
110: public void setSearchFilter(String value) {
111: searchText = value;
112: }
113:
114: ////// Model contexts
115:
116: /**
117: * Provides support for event list execute operations.
118: * <p>
119: * Following are the suppported event list execute contexts.
120: * <br><code>LOAD_EVENT_CONTEXT</code></b> -- Use this context to load a set of events
121: * <p>
122: * In case if context passed is 'null' then the default event list execute
123: * context executed is LOAD_EVENT_CONTEXT.
124: * <p>
125: */
126: public void execute(String context) throws Exception {
127:
128: String opName = null;
129:
130: if (null != context) {
131: opName = context;
132: } else {
133: opName = SharedConstants.LOAD_EVENTS_CONTEXT;
134: }
135:
136: if (opName.equals(SharedConstants.LOAD_EVENTS_CONTEXT)) {
137: try {
138: fetchEvents();
139: } catch (Exception e1) {
140: throw e1;
141: }
142: } else {
143:
144: throw new Exception("Invalid Execution context");
145: }
146:
147: }
148:
149: private void fetchEvents() throws Exception {
150: logger.entering(CLASS_NAME, "fetchEvents()");
151:
152: // Reset the event Data
153: _events = null;
154:
155: cbm = getCalendarBaseModel();
156:
157: try {
158:
159: if (null == viewCtx) {
160: viewCtx = SharedConstants.VIEW_CTX_DAY;
161: }
162:
163: cbm.removeAllCalids();
164:
165: String calid = null;
166: try {
167: calid = AppUtils.getTargetCalendarId();
168: } catch (Exception e1) {
169: logger.log(Level.SEVERE,
170: "Failed to obtain Calendar ID: "
171: + e1.getMessage());
172: throw e1;
173: }
174:
175: cbm.addCalid(calid);
176:
177: if (_searchMode) {
178:
179: if (logger.isLoggable(Level.FINE)) {
180: logger.log(Level.FINE,
181: "In searchMode: Searching the events....");
182: }
183:
184: // Set the filter if exists
185: if ((null != searchText)
186: && (false == searchText.trim().equals(""))) {
187:
188: // Searching for events using search_string in entire events data using filter (ALL=*str*)
189:
190: String filter = "ALL=" + searchText;
191: cbm.setComponentSearchFilter(filter);
192: cbm.setComponentSearchOption(0);
193:
194: if (logger.isLoggable(Level.FINE)) {
195: logger.log(Level.FINE, "Filter set to: "
196: + filter);
197: }
198:
199: }
200:
201: cbm.execute(SharedConstants.SEARCH_EVENTS_CONTEXT);
202: _events = cbm.getAllEvents();
203:
204: } else {
205:
206: // Set start and end dates if and only if it is non-search mode.
207: cbm.setStartTime(_start);
208: cbm.setEndTime(_end);
209:
210: if (logger.isLoggable(Level.FINE)) {
211: logger.log(Level.FINE, "Fetching the events ....");
212: logger.log(Level.FINE, "viewCtx: " + viewCtx);
213: logger.log(Level.FINE, "start: "
214: + _start.toISOString());
215: logger
216: .log(Level.FINE, "end: "
217: + _end.toISOString());
218: }
219:
220: String ctx = SharedConstants.FETCH_EVENTS_CONTEXT;
221:
222: cbm.execute(ctx);
223: _events = cbm.getAllEvents();
224:
225: }
226: } catch (Exception e2) {
227: logger.log(Level.SEVERE,
228: "Exception while fetching events: " + e2);
229: throw e2;
230: }
231:
232: logger.exiting(CLASS_NAME, "fetchEvents()");
233:
234: }
235:
236: private CalendarBaseModel getCalendarBaseModel() {
237: return new CalendarBaseModel("eventsListModel");
238:
239: }
240:
241: }
|