KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > dbobj > EventMail


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.services.dbobj;
66
67 import com.jcorporate.expresso.core.db.DBException;
68 import com.jcorporate.expresso.core.dbobj.RequestContext;
69 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
70 import com.jcorporate.expresso.core.dbobj.ValidValue;
71 import com.jcorporate.expresso.core.security.User;
72
73 import java.util.Vector JavaDoc;
74
75
76 /**
77  * EventMail objects tell who is to be notified when an event is triggered
78  *
79  * @author Michael Nash
80  * @version $Revision: 1.12 $ $Date: 2004/11/18 02:03:30 $
81  */

82 public class EventMail
83         extends SecuredDBObject {
84     /**
85      * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject
86      */

87     public EventMail()
88             throws DBException {
89         super();
90     } /* EventMail() */
91
92     /**
93      * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject
94      *
95      * @param theUser
96      * @throws DBException
97      */

98 // public EventMail(String theUser)
99
// throws DBException {
100
// super(theUser);
101
// } /* EventMail(String) */
102

103     /**
104      * @param uid the Expresso security user id
105      * @throws DBException upon initialization error
106      */

107     public EventMail(int uid)
108             throws DBException {
109         super(uid);
110     }
111
112     /**
113      * For using DBObjects within Controllers. Initializes based upon the current
114      * user and the requested db. [Of course this can be modified later]
115      *
116      * @param request - The controller request handed to you by the framework.
117      * @throws DBException upon initialization error
118      */

119     public EventMail(RequestContext request)
120             throws DBException {
121         super(request);
122     }
123
124     /**
125      * Extends the checkAllRefs method to check for valid User and Event
126      *
127      * @throws DBException If a referential integrity violation is found
128      */

129     protected void checkAllRefs()
130             throws DBException {
131         checkRef("Event", new Event(), "Invalid " + getString(getMetaData().getDescription("Event")));
132     } /* checkAllRefs() */
133
134
135     /**
136      * Override the method getValidValues to provide specific values for our
137      * multi-valued fields
138      *
139      * @param fieldName Name of the field for which values are requested
140      * @return Vector of ValidValue Value/description pairs for
141      * the valid values
142      * @throws DBException If the values cannot be retrieved
143      */

144     public synchronized Vector JavaDoc getValidValues(String JavaDoc fieldName)
145             throws DBException {
146         if (fieldName.equals("Success")) {
147             Vector JavaDoc myValues = new Vector JavaDoc(2);
148             myValues.addElement(new ValidValue("Y", "Yes"));
149             myValues.addElement(new ValidValue("N", "No"));
150
151             return myValues;
152         }
153
154         return super.getValidValues(fieldName);
155     } /* getValidValues(String) */
156
157
158     /**
159      * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject#setupFields
160      */

161     protected synchronized void setupFields()
162             throws DBException {
163         setTargetTable("EVENTMAIL");
164         setDescription("DBeventMail");
165         setCharset("ISO-8859-1");
166         addField("Event", "char", 30, false, "eventCode");
167         addField("ExpUid", "int", 0, false, "userId");
168         addVirtualField("LoginName", "char", 30, "loginName");
169         addField("Success", "char", 1, false, "userNotifiedOnSuccess");
170         addKey("Event");
171         addKey("ExpUid");
172         addKey("Success");
173         setStringFilter("Event", "stripFilter");
174         setMultiValued("Event");
175         setMultiValued("Success");
176         setLookupObject("Event",
177                 "com.jcorporate.expresso.services.dbobj.Event");
178         setLookupObject("ExpUid", "com.jcorporate.expresso.core.security.User");
179     } /* setupFields() */
180
181
182     /**
183      * Extend the usual getField method to return values for the virtual field
184      *
185      * @param fieldName the name of the field to retrieve the value.
186      * @return java.lang.String the field value
187      * @throws DBException upon initialization error
188      */

189     public String JavaDoc getField(String JavaDoc fieldName)
190             throws DBException {
191         if (fieldName.equals("LoginName")) {
192             User u = new User();
193             u.setUid(getFieldInt("ExpUid"));
194             u.setDataContext(this.getDataContext());
195
196             if (u.find()) {
197                 return u.getLoginName();
198             }
199
200             return "No such user";
201         }
202
203         return super.getField(fieldName);
204     }
205
206     /**
207      * @throws DBException
208      */

209     public synchronized void populateDefaultValues()
210             throws DBException {
211         int adminId = User.getAdminId(getDataContext());
212
213         //SYSERROR
214
EventMail oneMail = new EventMail();
215         oneMail.setDataContext(getDataContext());
216         oneMail.setField("Event", "SYSERROR");
217         oneMail.setField("ExpUid", adminId);
218         oneMail.setField("Success", "Y");
219
220         if (!oneMail.find()) {
221             oneMail.add();
222         }
223
224         oneMail.clear();
225         oneMail.setField("Event", "SYSERROR");
226         oneMail.setField("ExpUid", adminId);
227         oneMail.setField("Success", "N");
228
229         if (!oneMail.find()) {
230             oneMail.add();
231         }
232
233         //HEALTHCHECK
234
oneMail.clear();
235         oneMail.setField("Event", "HEALTH");
236         oneMail.setField("ExpUid", adminId);
237         oneMail.setField("Success", "Y");
238
239         if (!oneMail.find()) {
240             oneMail.add();
241         }
242
243         oneMail.clear();
244         oneMail.setField("Event", "HEALTH");
245         oneMail.setField("ExpUid", adminId);
246         oneMail.setField("Success", "N");
247
248         if (!oneMail.find()) {
249             oneMail.add();
250         }
251
252         //DOWNLOAD
253
oneMail.clear();
254         oneMail.setDataContext(getDataContext());
255         oneMail.setField("Event", "DOWNLOAD");
256         oneMail.setField("ExpUid", adminId);
257         oneMail.setField("Success", "Y");
258
259         if (!oneMail.find()) {
260             oneMail.add();
261         }
262
263         oneMail.clear();
264         oneMail.setDataContext(getDataContext());
265         oneMail.setField("Event", "DOWNLOAD");
266         oneMail.setField("ExpUid", adminId);
267         oneMail.setField("Success", "N");
268
269         if (!oneMail.find()) {
270             oneMail.add();
271         }
272
273         //REGISTER
274
oneMail.clear();
275         oneMail.setDataContext(getDataContext());
276         oneMail.setField("Event", "REGISTER");
277         oneMail.setField("ExpUid", adminId);
278         oneMail.setField("Success", "Y");
279
280         if (!oneMail.find()) {
281             oneMail.add();
282         }
283
284         oneMail.clear();
285         oneMail.setDataContext(getDataContext());
286         oneMail.setField("Event", "REGISTER");
287         oneMail.setField("ExpUid", adminId);
288         oneMail.setField("Success", "N");
289
290         if (!oneMail.find()) {
291             oneMail.add();
292         }
293     } /* populateDefaultValues() */
294
295
296 } /* EventMail */
297
298 /* EventMail */
Popular Tags