001: /* ====================================================================
002: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003: *
004: * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by Jcorporate Ltd.
021: * (http://www.jcorporate.com/)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. "Jcorporate" and product names such as "Expresso" must
026: * not be used to endorse or promote products derived from this
027: * software without prior written permission. For written permission,
028: * please contact info@jcorporate.com.
029: *
030: * 5. Products derived from this software may not be called "Expresso",
031: * or other Jcorporate product names; nor may "Expresso" or other
032: * Jcorporate product names appear in their name, without prior
033: * written permission of Jcorporate Ltd.
034: *
035: * 6. No product derived from this software may compete in the same
036: * market space, i.e. framework, without prior written permission
037: * of Jcorporate Ltd. For written permission, please contact
038: * partners@jcorporate.com.
039: *
040: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051: * SUCH DAMAGE.
052: * ====================================================================
053: *
054: * This software consists of voluntary contributions made by many
055: * individuals on behalf of the Jcorporate Ltd. Contributions back
056: * to the project(s) are encouraged when you make modifications.
057: * Please send them to support@jcorporate.com. For more information
058: * on Jcorporate Ltd. and its products, please see
059: * <http://www.jcorporate.com/>.
060: *
061: * Portions of this software are based upon other open source
062: * products and are subject to their respective licenses.
063: */
064:
065: package com.jcorporate.expresso.ext.dbobj;
066:
067: import com.jcorporate.expresso.core.db.DBConnection;
068: import com.jcorporate.expresso.core.db.DBException;
069: import com.jcorporate.expresso.core.db.exception.DBRecordNotFoundException;
070: import com.jcorporate.expresso.core.dbobj.RequestContext;
071: import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
072: import com.jcorporate.expresso.core.dbobj.ValidValue;
073: import com.jcorporate.expresso.core.misc.DateTime;
074: import com.jcorporate.expresso.core.misc.EventHandler;
075: import com.jcorporate.expresso.core.misc.StringUtil;
076: import com.jcorporate.expresso.core.security.User;
077: import com.jcorporate.expresso.kernel.util.FastStringBuffer;
078:
079: import java.util.Iterator;
080: import java.util.Vector;
081:
082: /**
083: * Extention to the normal user object to record some additional information
084: *
085: * @author Michael Nash
086: */
087: public class RegisteredUser extends
088: com.jcorporate.expresso.services.dbobj.RegistrationDBObject {
089:
090: /**
091: * Constructor
092: */
093: public RegisteredUser() throws DBException {
094: } /* RegisteredUser() */
095:
096: /**
097: * Constructor
098: *
099: * @param myConnection an already allocated DBConnection
100: */
101: public RegisteredUser(DBConnection myConnection) throws DBException {
102: super (myConnection);
103: } /* RegisteredUser(DBConnection) */
104:
105: /**
106: * Use over (String) constructor. Initializes the object in the context
107: * of the user who's uid belongs to the parameter.
108: *
109: * @param uid the Uid of the user context
110: * @throws DBException if there's an initialization problem
111: */
112: public RegisteredUser(int uid) throws DBException {
113: super (uid);
114: }
115:
116: /**
117: * For using DBObjects within Controllers. Initializes based upon the current
118: * user and the requested db. [Of course this can be modified later]
119: *
120: * @param request - The controller request handed to you by the framework.
121: * @throws DBException upon error
122: */
123: public RegisteredUser(RequestContext request) throws DBException {
124: super (request);
125: }
126:
127: /**
128: * @throws DBException
129: */
130: public void add() throws DBException {
131: setField("AddedOn", DateTime.getDateTimeForDB(this
132: .getDataContext()));
133: setField("UpdatedOn", DateTime.getDateTimeForDB(this
134: .getDataContext()));
135: super .add();
136: sendNotice("New Registration:");
137: }
138:
139: /**
140: * Sends a registration notice to the user.
141: *
142: * @param topic
143: */
144: private void sendNotice(String topic) throws DBException {
145: FastStringBuffer theMessage = new FastStringBuffer(512);
146:
147: theMessage.append(topic);
148: theMessage.append("\n\n");
149: User theUser = new User();
150: theUser.setDataContext(this .getDataContext());
151: theUser.setUid(getFieldInt("ExpUid"));
152: theUser.retrieve();
153: theMessage.append("Login Name:" + theUser.getLoginName()
154: + "\n\n");
155:
156: String oneField = null;
157:
158: for (Iterator ef = this .getMetaData().getFieldListArray()
159: .iterator(); ef.hasNext();) {
160: oneField = (String) ef.next();
161: theMessage.append(getString(getMetaData().getDescription(
162: oneField))
163: + ":" + getField(oneField) + "\n");
164: }
165:
166: EventHandler.Event(getDataContext(), "REGISTER", theMessage
167: .toString(), true);
168: } /* add() */
169:
170: /**
171: * @param fieldName the name of the field to retrieve
172: * @return a field as a String
173: * @throws DBException upon error
174: */
175: public String getField(String fieldName) throws DBException {
176: if (fieldName.equalsIgnoreCase("UserEMail")) {
177: User myUser = new User();
178: myUser.setDataContext(this .getDataContext());
179:
180: if (StringUtil.notNull(getField("ExpUid")).equals("")) {
181: return null;
182: }
183:
184: myUser.setUid(getField("ExpUid"));
185:
186: try {
187: myUser.retrieve();
188:
189: return myUser.getEmail();
190: } catch (DBRecordNotFoundException de) {
191: return "No Such User";
192: }
193: } else if (fieldName.equals("LoginName")) {
194: User u = new User();
195: u.setUid(getFieldInt("ExpUid"));
196: u.setDataContext(this .getDataContext());
197:
198: if (u.find()) {
199: return u.getLoginName();
200: }
201:
202: return "No such user";
203: }
204:
205: return super .getField(fieldName);
206: } /* getField(String) */
207:
208: /**
209: * @param fieldName the name of the field to retrieve the valid values for
210: * @return java.util.Vector of ValidValue objects
211: * @throws DBException upon error
212: */
213: public Vector getValidValues(String fieldName) throws DBException {
214: if (fieldName.equals("Employees")) {
215: Vector h = new Vector(5);
216: h.addElement(new ValidValue("0", "1 - 10"));
217: h.addElement(new ValidValue("A", "11 - 49"));
218: h.addElement(new ValidValue("1", "50 - 100"));
219: h.addElement(new ValidValue("2", "101-500"));
220: h.addElement(new ValidValue("3", "501-1000"));
221: h.addElement(new ValidValue("4", "1001-10,000"));
222: h.addElement(new ValidValue("5", "More than 10,000"));
223:
224: return h;
225: } else if (fieldName.equals("Industry")) {
226: Vector h = new Vector(24);
227: h.addElement(new ValidValue("01", "Aerospace"));
228: h.addElement(new ValidValue("03", "Education"));
229: h.addElement(new ValidValue("04",
230: "Engineering/Architecture"));
231: h.addElement(new ValidValue("FINANCIAL",
232: "Financial Services/Banking"));
233: h.addElement(new ValidValue("05",
234: "Finance/Accounting/Banking"));
235: h.addElement(new ValidValue("06", "Government"));
236: h
237: .addElement(new ValidValue("HEALTH",
238: "Healthcare/Medical"));
239: h.addElement(new ValidValue("MANUF", "Manufacturing"));
240: h.addElement(new ValidValue("09", "Marketing/PR"));
241: h.addElement(new ValidValue("10",
242: "Process Industries (mine/farm/const.)"));
243: h.addElement(new ValidValue("11",
244: "Publishing/Electronic Publishing"));
245: h.addElement(new ValidValue("12",
246: "Research & Development"));
247: h.addElement(new ValidValue("RETAIL",
248: "Retailer/Distributor/Wholesaler"));
249: h
250: .addElement(new ValidValue("TELECOM",
251: "Telecommunications"));
252: h.addElement(new ValidValue("15", "Transportation"));
253: h.addElement(new ValidValue("16", "Utilities"));
254: h.addElement(new ValidValue("17",
255: "Custom Development/Consulting"));
256: h.addElement(new ValidValue("SOFTWARE", "Software"));
257: h.addElement(new ValidValue("23",
258: "Systems Integrator/VAR/OEM"));
259: h.addElement(new ValidValue("CONSULT", "Consulting"));
260: h.addElement(new ValidValue("OTHER",
261: "Other (Specify in Comment)"));
262:
263: return h;
264: } else if (fieldName.equals("JobTitle")) {
265: Vector h = new Vector();
266: h.addElement(new ValidValue("01", "Corporate Management"));
267: h.addElement(new ValidValue("02", "Other Management"));
268: h.addElement(new ValidValue("03",
269: "IS/MIS/Technical Management"));
270: h
271: .addElement(new ValidValue("04",
272: "IS/MIS/Technical Staff"));
273: h.addElement(new ValidValue("05",
274: "Internet/Web Management, Staff"));
275: h.addElement(new ValidValue("06", "Consultant"));
276: h.addElement(new ValidValue("07", "Educator/Trainer"));
277: h.addElement(new ValidValue("08", "Student"));
278: h.addElement(new ValidValue("09", "Developer"));
279: h
280: .addElement(new ValidValue("10",
281: "Independent Contractor"));
282:
283: return h;
284: } else if (fieldName.equals("Country")) {
285: ISOCountryCodes countries = new ISOCountryCodes(
286: SecuredDBObject.SYSTEM_ACCOUNT);
287: countries.setDataContext(this .getDataContext());
288: Vector v = countries.getValues();
289: return v;
290: }
291:
292: return super .getValidValues(fieldName);
293: } /* getValidValues(String) */
294:
295: /**
296: * @param subject subject of the email message
297: * @param message The message to send
298: * @throws DBException upon error
299: */
300: public void notify(String subject, String message)
301: throws DBException {
302: User myUser = new User();
303: myUser.setDataContext(this .getDataContext());
304: myUser.setUid(this .getField("ExpUid"));
305: if (!myUser.find()) {
306: throw new DBException("Unable to locate user: "
307: + this .getField("ExpUid"));
308: }
309:
310: myUser.notify(subject, message);
311: } /* notify(String, String) */
312:
313: /**
314: * @throws DBException upon error
315: * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject#setupFields
316: */
317: public void setupFields() throws DBException {
318: setTargetTable("USERREGISTER");
319: setDescription("DBuserRegister");
320: setCharset("ISO-8859-1");
321: addField("ExpUid", "int", 0, false, "userId");
322: addVirtualField("LoginName", "char", 30, "loginName");
323: addField("FirstName", "varchar", 30, false, "firstName");
324: addField("LastName", "varchar", 80, false, "lastName");
325: addField("FullName", "varchar", 80, true, "yourName");
326: addField("CompanyName", "varchar", 30, true, "orgName");
327: addField("URL", "varchar", 255, true, "url");
328: addField("Address", "text", 0, false, "address");
329: addField("City", "varchar", 40, false, "city");
330: addField("StateProvince", "varchar", 40, false, "stateProvince");
331: addField("PostalCode", "varchar", 15, true, "postalZip");
332: addField("Country", "varchar", 40, false, "country");
333: setDefaultValue("Country", "US");
334: addField("UserComment", "text", 0, true, "userComment");
335: addField("Industry", "char", 10, false, "industry");
336: setDefaultValue("Industry", "17");
337: addField("Employees", "char", 1, false, "employees");
338: setDefaultValue("Employees", "0");
339: addField("JobTitle", "char", 2, true, "jobTitle");
340: addField("Subscribe", "char", 1, true, "subscribeToListServ");
341: setDefaultValue("Subscribe", "Y");
342: this .getMetaData().setAttribute("Subscribe", "checkbox", "Y");
343: addField("Contributing", "char", 1, true, "contributing");
344: setDefaultValue("Contributing", "N");
345: this .getMetaData()
346: .setAttribute("Contributing", "checkbox", "Y");
347: addField("Projects", "char", 1, true, "projectNotifications");
348: this .getMetaData().setAttribute("Projects", "checkbox", "Y");
349: setDefaultValue("Projects", "Y");
350: addField("IsActive", "char", 1, true, "active");
351: this .getMetaData().setAttribute("IsActive", "checkbox", "Y");
352: addField("InternalComment", "text", 0, true, "internalComment");
353: addField("AddedOn", "datetime", 0, true, "addedOn");
354: addField("UpdatedOn", "datetime", 0, true, "updatedOn");
355: addField("EmailPrivate", "char", 1, true, "keepEmailPrivate");
356: addField("Occupation", "text", 0, true, "occupation");
357: addField("Location", "text", 0, true, "location");
358: addField("Expertise", "text", 0, true, "expertise");
359: addField("Contributions", "text", 0, true, "contributions");
360: addField("OtherProjects", "text", 0, true, "otherProjects");
361: addField("Phone", "varchar", 80, true, "phone");
362: addField("Testimonial", "text", 0, true, "testimonial");
363: addField("IPAddress", "varchar", 30, true, "ipAddress");
364: setReadOnly("IPAddress");
365: setReadOnly("UpdatedOn");
366: setReadOnly("AddedOn");
367:
368: //For all the other fields, the default of standard filter is fine.
369: //Saves on typing :-)
370: addVirtualField("UserEMail", "varchar", 80, "EMail Address");
371: setLookupObject("ExpUid",
372: "com.jcorporate.expresso.core.security.User");
373: addKey("ExpUid");
374: setMultiValued("JobTitle");
375: setMultiValued("Industry");
376: setMultiValued("Employees");
377: setMultiValued("Country");
378: } /* setupFields() */
379:
380: /**
381: * Updates the registered user
382: *
383: * @throws DBException upon error
384: */
385: public void update() throws DBException {
386: setField("UpdatedOn", DateTime.getDateTimeForDB(this
387: .getDataContext()));
388: super .update();
389: sendNotice("Updated Registration:");
390: } /* update() */
391:
392: } /* RegisteredUser */
|