0001: /*
0002: Copyright (C) 2003 Know Gate S.L. All rights reserved.
0003: C/Oņa, 107 1š2 28050 Madrid (Spain)
0004:
0005: Redistribution and use in source and binary forms, with or without
0006: modification, are permitted provided that the following conditions
0007: are met:
0008:
0009: 1. Redistributions of source code must retain the above copyright
0010: notice, this list of conditions and the following disclaimer.
0011:
0012: 2. The end-user documentation included with the redistribution,
0013: if any, must include the following acknowledgment:
0014: "This product includes software parts from hipergate
0015: (http://www.hipergate.org/)."
0016: Alternately, this acknowledgment may appear in the software itself,
0017: if and wherever such third-party acknowledgments normally appear.
0018:
0019: 3. The name hipergate must not be used to endorse or promote products
0020: derived from this software without prior written permission.
0021: Products derived from this software may not be called hipergate,
0022: nor may hipergate appear in their name, without prior written
0023: permission.
0024:
0025: This library is distributed in the hope that it will be useful,
0026: but WITHOUT ANY WARRANTY; without even the implied warranty of
0027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0028:
0029: You should have received a copy of hipergate License with this code;
0030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
0031: */
0032:
0033: package com.knowgate.acl;
0034:
0035: import java.util.StringTokenizer;
0036: import java.math.BigDecimal;
0037:
0038: import java.io.IOException;
0039:
0040: import java.sql.Connection;
0041: import java.sql.SQLException;
0042: import java.sql.CallableStatement;
0043: import java.sql.PreparedStatement;
0044: import java.sql.Statement;
0045: import java.sql.ResultSet;
0046:
0047: import com.knowgate.debug.DebugFile;
0048: import com.knowgate.jdc.JDCConnection;
0049: import com.knowgate.dataobjs.DB;
0050: import com.knowgate.dataobjs.DBBind;
0051: import com.knowgate.dataobjs.DBPersist;
0052: import com.knowgate.dataobjs.DBSubset;
0053: import com.knowgate.hipergate.Category;
0054:
0055: import com.knowgate.misc.Gadgets;
0056:
0057: /**
0058: * <p>Object mapping for k_users table registers</p>
0059: * @author Sergio Montoro Ten
0060: * @version 3.0
0061: */
0062:
0063: public final class ACLUser extends DBPersist {
0064:
0065: /**
0066: * Default constructor.
0067: */
0068: public ACLUser() {
0069: super (DB.k_users, "ACLUser");
0070: }
0071:
0072: /**
0073: * <p>Constructs ACLUser and set GUID</p>
0074: * Does not load any fields from database.
0075: * @param sUserGUID user Unique Identifier (gu_user field at k_users table)
0076: * @throws SQLException
0077: */
0078:
0079: public ACLUser(String sUserGUID) throws SQLException {
0080: super (DB.k_users, "ACLUser");
0081:
0082: put(DB.gu_user, sUserGUID);
0083: }
0084:
0085: /**
0086: * <p>Constructs ACLUser and load attributes from k_users table</p>
0087: * @param oConn Database Connection
0088: * @param sUserGUID user Unique Identifier (gu_user field at k_users table)
0089: * @throws SQLException
0090: */
0091:
0092: public ACLUser(JDCConnection oConn, String sUserGUID)
0093: throws SQLException {
0094: super (DB.k_users, "ACLUser");
0095:
0096: Object aUser[] = { sUserGUID };
0097:
0098: load(oConn, aUser);
0099: }
0100:
0101: // ----------------------------------------------------------
0102:
0103: /**
0104: * <p>Get Addresses associated with user at k_x_addr_user table.</p>
0105: * @param oConn Database Connection
0106: * @return A {@link DBSubset} with a 3 columns containing
0107: * Address Unique Identifier (gu_address), Address Ordinal Position (ix_address)
0108: * and Address Location Type (tp_location).
0109: * @throws SQLException
0110: * @see {@link Address}
0111: */
0112: public DBSubset getAddresses(JDCConnection oConn)
0113: throws SQLException {
0114: Object aUser[] = { get(DB.gu_user) };
0115: oAddresses = new DBSubset(DB.k_x_addr_user, DB.gu_address + ","
0116: + DB.ix_address + "," + DB.tp_location, DB.gu_user
0117: + "=?", 10);
0118:
0119: oAddresses.load(oConn, aUser);
0120: return oAddresses;
0121: }
0122:
0123: // ----------------------------------------------------------
0124:
0125: /**
0126: * </p>Get security role groups to witch this user belongs looking a k_x_group_user table.</p>
0127: * @param oConn Database Connection
0128: * @return A {@link DBSubset} with a 1 column containing each group unique identifier (gu_acl_group).
0129: * @throws SQLException
0130: */
0131: public DBSubset getGroups(JDCConnection oConn) throws SQLException {
0132: Object aUser[] = { get(DB.gu_user) };
0133: oGroups = new DBSubset(DB.k_x_group_user, DB.gu_acl_group,
0134: DB.gu_user + "=?", 10);
0135:
0136: oGroups.load(oConn, aUser);
0137: return oGroups;
0138: }
0139:
0140: // ----------------------------------------------------------
0141:
0142: /**
0143: * <p>Add User to Groups.</p>
0144: * <p>Insert new registers at k_x_group_user table.</p>
0145: * @param oConn Database Connection
0146: * @param sGroupList A string of comma delimited ACLGroup GUIDs to with this ACLUser must be added.
0147: * @throws SQLException May throw a primary key constraint violation is user already belongs to group.
0148: */
0149: public int addToACLGroups(JDCConnection oConn, String sGroupList)
0150: throws SQLException {
0151:
0152: if (DebugFile.trace) {
0153: DebugFile
0154: .writeln("Begin ACLUser.addToACLGroups(Connection], "
0155: + sGroupList + ")");
0156: DebugFile.incIdent();
0157: }
0158:
0159: Statement oStmt;
0160: int iRetVal = 0;
0161: StringTokenizer oStrTok = new StringTokenizer(sGroupList, ",");
0162: String sIdGroup;
0163:
0164: oStmt = oConn.createStatement();
0165:
0166: while (oStrTok.hasMoreElements()) {
0167: sIdGroup = oStrTok.nextToken();
0168:
0169: if (DebugFile.trace)
0170: DebugFile
0171: .writeln("Statement.executeUpdate(INSERT INTO "
0172: + DB.k_x_group_user + "(" + DB.gu_user
0173: + "," + DB.gu_acl_group + ") VALUES('"
0174: + getStringNull(DB.gu_user, "null")
0175: + "','" + sIdGroup + "')");
0176:
0177: iRetVal += oStmt.executeUpdate("INSERT INTO "
0178: + DB.k_x_group_user + "(" + DB.gu_user + ","
0179: + DB.gu_acl_group + ") VALUES('"
0180: + getString(DB.gu_user) + "','" + sIdGroup + "')");
0181: } // wend
0182:
0183: oStmt.close();
0184:
0185: if (DebugFile.trace) {
0186: DebugFile.decIdent();
0187: DebugFile.writeln("End ACLUser.addToACLGroups() : "
0188: + String.valueOf(iRetVal));
0189: }
0190:
0191: return iRetVal;
0192: } // addToACLGroups
0193:
0194: // ----------------------------------------------------------
0195:
0196: /**
0197: * <p>Find out is this user has administrator.</p>
0198: * <p>A user may have administrator priviledges in two ways:<br>
0199: * 1.- It can belong to the group gu_admins from k_domains table.<br>
0200: * 2.- Its user identifier may be the one at gu_owner field of k_domains table.<br></p>
0201: * <p>The domain owner is a special kind of administrator user that cannot be deleted from domain.</p>
0202: * @param oConn Database Connection
0203: * @return true is user has adminsitrator priviledges, false otherwise.
0204: * @throws IllegalStateException if id_domain or gu_user is not set
0205: * @throws SQLException
0206: */
0207: public boolean isDomainAdmin(JDCConnection oConn)
0208: throws SQLException, IllegalStateException {
0209: PreparedStatement oStmt;
0210: ResultSet oRSet;
0211: boolean bAdmin;
0212:
0213: if (DebugFile.trace) {
0214: DebugFile
0215: .writeln("Begin ACLUser.sDomainAdmin(Connection])");
0216: DebugFile.incIdent();
0217: }
0218:
0219: if (isNull(DB.id_domain)) {
0220: if (DebugFile.trace) {
0221: DebugFile.writeln("ERROR id_domain not set");
0222: DebugFile.decIdent();
0223: }
0224:
0225: throw new IllegalStateException(
0226: "ACLUSer.isDomainAdmin() Property id_domain is not set");
0227: }
0228:
0229: if (isNull(DB.gu_user)) {
0230: if (DebugFile.trace) {
0231: DebugFile.writeln("ERROR gu_user not set");
0232: DebugFile.decIdent();
0233: }
0234:
0235: throw new IllegalStateException(
0236: "ACLUSer.isDomainAdmin() Property gu_user is not set");
0237: }
0238:
0239: if (DebugFile.trace)
0240: DebugFile
0241: .writeln("Connection.prepareStatement(SELECT NULL FROM "
0242: + DB.k_x_group_user
0243: + " x,"
0244: + DB.k_domains
0245: + " d WHERE d."
0246: + DB.id_domain
0247: + "="
0248: + String.valueOf(getInt(DB.id_domain))
0249: + " AND x."
0250: + DB.gu_user
0251: + "='"
0252: + getString(DB.gu_user)
0253: + "'"
0254: + " AND x."
0255: + DB.gu_acl_group
0256: + "=d."
0257: + DB.gu_admins
0258: + ")");
0259:
0260: int iDomainId;
0261: if (isNull(DB.id_domain))
0262: iDomainId = -1;
0263: else
0264: iDomainId = getInt(DB.id_domain);
0265:
0266: oStmt = oConn.prepareStatement("SELECT NULL FROM "
0267: + DB.k_x_group_user + " x," + DB.k_domains
0268: + " d WHERE d." + DB.id_domain + "=?" + " AND x."
0269: + DB.gu_user + "=?" + " AND x." + DB.gu_acl_group
0270: + "=d." + DB.gu_admins, ResultSet.TYPE_FORWARD_ONLY,
0271: ResultSet.CONCUR_READ_ONLY);
0272: oStmt.setInt(1, iDomainId);
0273: oStmt.setString(2, getStringNull(DB.gu_user, null));
0274: oRSet = oStmt.executeQuery();
0275: bAdmin = oRSet.next();
0276: oRSet.close();
0277: oStmt.close();
0278:
0279: if (!bAdmin) {
0280: if (DebugFile.trace)
0281: DebugFile.writeln("Connection.prepareStatement(SELECT "
0282: + DB.gu_owner + " FROM " + DB.k_domains
0283: + " WHERE " + DB.id_domain + "="
0284: + String.valueOf(getInt(DB.id_domain)) + ")");
0285:
0286: oStmt = oConn.prepareStatement("SELECT " + DB.gu_owner
0287: + " FROM " + DB.k_domains + " WHERE "
0288: + DB.id_domain + "=?", ResultSet.TYPE_FORWARD_ONLY,
0289: ResultSet.CONCUR_READ_ONLY);
0290: oStmt.setInt(1, getInt(DB.id_domain));
0291: oRSet = oStmt.executeQuery();
0292:
0293: if (oRSet.next())
0294: if (null != oRSet.getObject(1))
0295: bAdmin = oRSet.getString(1).equals(
0296: getString(DB.gu_user));
0297: else
0298: bAdmin = false;
0299: else
0300: bAdmin = false;
0301:
0302: oRSet.close();
0303: oStmt.close();
0304: }
0305:
0306: if (DebugFile.trace) {
0307: DebugFile.decIdent();
0308: DebugFile.writeln("End ACLUser.isDomainAdmin() : "
0309: + String.valueOf(bAdmin));
0310: }
0311:
0312: return bAdmin;
0313: } // isDomainAdmin
0314:
0315: // ----------------------------------------------------------
0316:
0317: /**
0318: * <p>Store ACLUser</p>
0319: * If gu_user is not set then a new GUID is assigned.<br>
0320: * If dt_last_update is not set then current system date is assigned.<br>
0321: * If len_quota is not set then zero is assigned.<br>
0322: * If max_quota is not set then 100Mb assigned.<br>
0323: * Syntax for tx_main_email and tx_alt_email is verified if these fields are not null
0324: * @param oConn Database Connection
0325: * @throws SQLException
0326: */
0327: public boolean store(JDCConnection oConn) throws SQLException {
0328: boolean bRetVal;
0329: Object oDomainId;
0330: String NmWorkArea;
0331: PreparedStatement oStmt;
0332: ResultSet oRSet;
0333:
0334: if (DebugFile.trace) {
0335: DebugFile.writeln("Begin ACLUser.store([Connection])");
0336: DebugFile.incIdent();
0337: }
0338:
0339: if (!AllVals.containsKey(DB.gu_user))
0340: put(DB.gu_user, Gadgets.generateUUID());
0341:
0342: if (!AllVals.containsKey(DB.dt_last_update))
0343: put(DB.dt_last_update, new java.sql.Timestamp(DBBind
0344: .getTime()));
0345:
0346: if (!AllVals.containsKey(DB.len_quota))
0347: put(DB.len_quota, new BigDecimal(0d));
0348:
0349: if (!AllVals.containsKey(DB.max_quota))
0350: put(DB.max_quota, new BigDecimal(104857600d));
0351:
0352: if (AllVals.containsKey(DB.gu_workarea)
0353: && AllVals.containsKey(DB.id_domain)) {
0354: if (!isNull(DB.gu_workarea)) {
0355:
0356: if (DebugFile.trace)
0357: DebugFile
0358: .writeln("Connection.prepareStatement(SELECT "
0359: + DB.id_domain
0360: + ","
0361: + DB.nm_workarea
0362: + " FROM "
0363: + DB.k_workareas
0364: + " WHERE "
0365: + DB.gu_workarea
0366: + "='"
0367: + getString(DB.gu_workarea) + "')");
0368:
0369: oStmt = oConn.prepareStatement("SELECT " + DB.id_domain
0370: + "," + DB.nm_workarea + " FROM "
0371: + DB.k_workareas + " WHERE " + DB.gu_workarea
0372: + "=?", ResultSet.TYPE_FORWARD_ONLY,
0373: ResultSet.CONCUR_READ_ONLY);
0374: oStmt.setString(1, getString(DB.gu_workarea));
0375: oRSet = oStmt.executeQuery();
0376: if (oRSet.next()) {
0377: oDomainId = oRSet.getObject(1);
0378: NmWorkArea = oRSet.getString(2);
0379: } else {
0380: oDomainId = null;
0381: NmWorkArea = null;
0382: }
0383: oRSet.close();
0384: oStmt.close();
0385:
0386: if (null != oDomainId) {
0387: if (!oDomainId.toString().equals(
0388: get(DB.id_domain).toString()))
0389: throw new SQLException(
0390: "ACLUSer.store() Integrity constraint violation: WorkArea "
0391: + NmWorkArea
0392: + " must belong to Domain "
0393: + oDomainId.toString()
0394: + " as User does but it belongs to "
0395: + oDomainId.toString(), "23000");
0396: } // fi (null!=oDomainId)
0397:
0398: } // fi (null!=gu_workarea)
0399: } // fi (containsKey(DB.gu_workarea) && containsKey(DB.id_domain))
0400:
0401: if (!Gadgets.checkEMail(getStringNull(DB.tx_main_email,
0402: "nobody@nodomain.com"))) {
0403: if (DebugFile.trace)
0404: DebugFile.decIdent();
0405: throw new SQLException(
0406: "ACLUSer.store() Check constraint violation: e-mail address "
0407: + getString(DB.tx_main_email)
0408: + " does not have a valid syntax", "23000");
0409: }
0410:
0411: if (!Gadgets.checkEMail(getStringNull(DB.tx_alt_email,
0412: "nobody@nodomain.com"))) {
0413: if (DebugFile.trace)
0414: DebugFile.decIdent();
0415: throw new SQLException(
0416: "ACLUSer.store() Check constraint violation: e-mail address "
0417: + getString(DB.tx_alt_email)
0418: + " does not have a valid syntax", "23000");
0419: }
0420:
0421: bRetVal = super .store(oConn);
0422:
0423: if (DebugFile.trace) {
0424: DebugFile.decIdent();
0425: DebugFile.writeln("End ACLUser.store() : "
0426: + String.valueOf(bRetVal));
0427: }
0428:
0429: return bRetVal;
0430: } // store
0431:
0432: // ----------------------------------------------------------
0433:
0434: public boolean delete(JDCConnection oConn) throws SQLException {
0435: try {
0436: return ACLUser.delete(oConn, getString(DB.gu_user));
0437: } catch (IOException ioe) {
0438: throw new SQLException("IOException " + ioe.getMessage());
0439: }
0440: } // delete
0441:
0442: // ----------------------------------------------------------
0443:
0444: /**
0445: * <p>Remove user from all security role groups</p>
0446: * @param oConn Database Connection
0447: * @return Count of groups from witch user was removed.
0448: * @throws SQLException
0449: */
0450: public int clearACLGroups(JDCConnection oConn) throws SQLException {
0451:
0452: if (DebugFile.trace) {
0453: DebugFile
0454: .writeln("Begin ACLUser.clearACLGroups([Connection])");
0455: DebugFile.incIdent();
0456: }
0457:
0458: int iRetVal;
0459:
0460: Statement oStmt = oConn.createStatement();
0461: iRetVal = oStmt.executeUpdate("DELETE FROM "
0462: + DB.k_x_group_user + " WHERE " + DB.gu_user + "='"
0463: + getString(DB.gu_user) + "'");
0464: oStmt.close();
0465:
0466: if (DebugFile.trace) {
0467: DebugFile.decIdent();
0468: DebugFile.writeln("End ACLGroup.clearACLGroups() : "
0469: + String.valueOf(iRetVal));
0470: }
0471:
0472: return iRetVal;
0473: } // clearACLGroups
0474:
0475: // ----------------------------------------------------------
0476:
0477: /**
0478: * <p>Remove User from Group.</p>
0479: * <p>remove register from k_x_group_user table.</p>
0480: * @param oConn Database Connection
0481: * @param sIdGroup Group Unique Identifier.
0482: * @throws SQLException
0483: */
0484:
0485: public int removeFromACLGroup(JDCConnection oConn, String sIdGroup)
0486: throws SQLException {
0487:
0488: if (DebugFile.trace) {
0489: DebugFile
0490: .writeln("Begin ACLUser.removeFromACLGroup(Connection], "
0491: + sIdGroup + ")");
0492: DebugFile.incIdent();
0493: }
0494:
0495: int iRetVal;
0496: Statement oStmt = oConn.createStatement();
0497:
0498: if (DebugFile.trace)
0499: DebugFile.writeln("Statement.executeUpdate(DELETE FROM "
0500: + DB.k_x_group_user + " WHERE " + DB.gu_user + "='"
0501: + getStringNull(DB.gu_user, "null") + "' AND "
0502: + DB.gu_acl_group + "='" + sIdGroup + "'");
0503:
0504: iRetVal = oStmt.executeUpdate("DELETE FROM "
0505: + DB.k_x_group_user + " WHERE " + DB.gu_user + "='"
0506: + getString(DB.gu_user) + "' AND " + DB.gu_acl_group
0507: + "='" + sIdGroup + "'");
0508: oStmt.close();
0509:
0510: if (DebugFile.trace) {
0511: DebugFile.decIdent();
0512: DebugFile.writeln("End ACLUser.removeFromACLGroup() : "
0513: + String.valueOf(iRetVal));
0514: }
0515:
0516: return iRetVal;
0517: } // removeFromACLGroup
0518:
0519: // ---------------------------------------------------------------------------
0520:
0521: /**
0522: * <p>Get GUID of user mail root category</p>
0523: * The user mail root category is always named <i>DOMAIN</i>_<i>nickname</i>_mail
0524: * at nm_category field of k_categories.<br>
0525: * If there is no category named <i>DOMAIN</i>_<i>nickname</i>_mail but the
0526: * user has his gu_category field set at k_users table then this method tries
0527: * to create a new mail root category.
0528: * @param oConn Database Connection
0529: * @return a gu_category value from k_categories or <b>null</b> if this user
0530: * does not have a mail root category and a new one could not be created
0531: * @throws SQLException
0532: */
0533: public String getMailRoot(JDCConnection oConn) throws SQLException {
0534: PreparedStatement oStmt;
0535: CallableStatement oCall;
0536: ResultSet oRSet;
0537: String sRetVal;
0538:
0539: if (DebugFile.trace) {
0540: DebugFile.writeln("Begin ACLUser.getMailRoot(Connection])");
0541: DebugFile.incIdent();
0542: }
0543:
0544: switch (oConn.getDataBaseProduct()) {
0545:
0546: case JDCConnection.DBMS_POSTGRESQL:
0547: if (DebugFile.trace)
0548: DebugFile
0549: .writeln("Connection.prepareStatement(SELECT k_sp_get_user_mailroot('"
0550: + getStringNull(DB.gu_user, "null")
0551: + "'))");
0552: oStmt = oConn
0553: .prepareStatement("SELECT k_sp_get_user_mailroot(?)");
0554: oStmt.setString(1, getString(DB.gu_user));
0555: oRSet = oStmt.executeQuery();
0556: if (oRSet.next())
0557: sRetVal = oRSet.getString(1);
0558: else
0559: sRetVal = null;
0560: oRSet.close();
0561: oStmt.close();
0562: break;
0563: default:
0564: if (DebugFile.trace)
0565: DebugFile
0566: .writeln("Connection.prepareCall({ call k_sp_get_user_mailroot('"
0567: + getStringNull(DB.gu_user, "null")
0568: + "',?) }");
0569: oCall = oConn
0570: .prepareCall("{ call k_sp_get_user_mailroot(?,?) }");
0571: oCall.setString(1, getString(DB.gu_user));
0572: oCall.registerOutParameter(2, java.sql.Types.CHAR);
0573: oCall.execute();
0574: sRetVal = oCall.getString(2);
0575: oCall.close();
0576: break;
0577: }
0578:
0579: if (sRetVal == null) {
0580: if (DebugFile.trace)
0581: DebugFile
0582: .writeln("user mail root not found creating new one...");
0583: ACLUser oMe = new ACLUser();
0584: if (oMe.load(oConn, new Object[] { getString(DB.gu_user) })) {
0585: if (!oMe.isNull(DB.gu_category)) {
0586: ACLDomain oDom = new ACLDomain(oConn, oMe
0587: .getInt(DB.id_domain));
0588:
0589: Statement oInsr = oConn.createStatement();
0590: String sNewGUID = Gadgets.generateUUID();
0591:
0592: String sSQL = "INSERT INTO "
0593: + DB.k_categories
0594: + " ("
0595: + DB.gu_category
0596: + ","
0597: + DB.gu_owner
0598: + ","
0599: + DB.nm_category
0600: + ","
0601: + DB.bo_active
0602: + ","
0603: + DB.dt_modified
0604: + ","
0605: + DB.nm_icon
0606: + ","
0607: + DB.id_doc_status
0608: + ","
0609: + DB.nm_icon2
0610: + ") VALUES ('"
0611: + sNewGUID
0612: + "','"
0613: + oMe.getString(DB.gu_user)
0614: + "','"
0615: + oDom.getString(DB.nm_domain)
0616: + "_"
0617: + oMe.getString(DB.tx_nickname)
0618: + "_mail',1,NULL,'myemailc_16x16.gif',1,'myemailo_16x16.gif')";
0619: if (DebugFile.trace)
0620: DebugFile
0621: .writeln("PreparedStatement.executeUpdate("
0622: + sSQL + ")");
0623: oInsr.executeUpdate(sSQL);
0624:
0625: String[] aLabels = new String[] { "en", "es", "fr",
0626: "de", "it", "pt", "ca", "ja", "cn", "tw",
0627: "fi", "ru", "pl", "nl" };
0628:
0629: for (int l = 0; l < aLabels.length; l++)
0630: oInsr.executeUpdate("INSERT INTO "
0631: + DB.k_cat_labels + " ("
0632: + DB.gu_category + "," + DB.id_language
0633: + "," + DB.tr_category + ","
0634: + DB.url_category + ") VALUES ('"
0635: + sNewGUID + "','" + aLabels[l]
0636: + "','e-mail',NULL)");
0637:
0638: oInsr.executeUpdate("INSERT INTO "
0639: + DB.k_x_cat_user_acl + " ("
0640: + DB.gu_category + "," + DB.gu_user + ","
0641: + DB.acl_mask + ") VALUES ('" + sNewGUID
0642: + "','" + oMe.getString(DB.gu_user)
0643: + "',2147483647)");
0644:
0645: if (!oMe.getString(DB.gu_user).equals(
0646: oDom.getString(DB.gu_owner)))
0647: oInsr.executeUpdate("INSERT INTO "
0648: + DB.k_x_cat_user_acl + " ("
0649: + DB.gu_category + "," + DB.gu_user
0650: + "," + DB.acl_mask + ") VALUES ('"
0651: + sNewGUID + "','"
0652: + oDom.getString(DB.gu_owner)
0653: + "',2147483647)");
0654:
0655: sSQL = "INSERT INTO " + DB.k_cat_tree + " ("
0656: + DB.gu_parent_cat + "," + DB.gu_child_cat
0657: + ") VALUES ('"
0658: + oMe.getString(DB.gu_category) + "','"
0659: + sNewGUID + "')";
0660: if (DebugFile.trace)
0661: DebugFile
0662: .writeln("PreparedStatement.executeUpdate("
0663: + sSQL + ")");
0664: oInsr.executeUpdate(sSQL);
0665:
0666: oInsr.close();
0667: sRetVal = sNewGUID;
0668: } else {
0669: if (DebugFile.trace)
0670: DebugFile.writeln("user "
0671: + getString(DB.gu_user)
0672: + " has not home category");
0673: }
0674: } else {
0675: if (DebugFile.trace)
0676: DebugFile.writeln("unable to load user "
0677: + getString(DB.gu_user));
0678: }
0679: } else
0680: sRetVal = sRetVal.trim();
0681:
0682: if (DebugFile.trace) {
0683: DebugFile.decIdent();
0684: DebugFile.writeln("End ACLUser.getMailRoot() : "
0685: + String.valueOf(sRetVal));
0686: }
0687:
0688: return sRetVal;
0689: } // getMailRoot
0690:
0691: // ---------------------------------------------------------------------------
0692:
0693: /**
0694: * <p>Get GUID of user mail folder category</p>
0695: * The Inbox category is where messages downloaded from the mail server are cached by default.
0696: * The user mail inbox category is always named <i>DOMAIN</i>_<i>nickname</i>_inbox at nm_category field of k_categories.<br>
0697: * If there is no category named <i>DOMAIN</i>_<i>nickname</i>_inbox but the
0698: * user has a mail root category then this method tries to create a new mail
0699: * inbox category under mail root.<BR>
0700: * @param oConn Database Connection
0701: * @param sFolderName One of { "inbox", "drafts", "deleted", "sent", "spam" }
0702: * @return a gu_category value from k_categories or <b>null</b> if this user
0703: * does not have a mail inbox category and a new one could not be created
0704: * @throws SQLException
0705: * @throws NullPointerException if sFolderName is <b>null</b> or empty string
0706: */
0707:
0708: public String getMailFolder(JDCConnection oConn, String sFolderName)
0709: throws SQLException {
0710: PreparedStatement oStmt;
0711: CallableStatement oCall;
0712: ResultSet oRSet;
0713: String sRetVal;
0714:
0715: if (DebugFile.trace) {
0716: DebugFile
0717: .writeln("Begin ACLUser.getMailFolder([JDCConnection],"
0718: + sFolderName + ")");
0719: DebugFile.incIdent();
0720: }
0721:
0722: if (sFolderName == null) {
0723: if (DebugFile.trace)
0724: DebugFile.decIdent();
0725: throw new NullPointerException(
0726: "ACLUser.getMailFolder() folder name cannot be null");
0727: }
0728: if (sFolderName.length() == 0) {
0729: if (DebugFile.trace)
0730: DebugFile.decIdent();
0731: throw new NullPointerException(
0732: "ACLUser.getMailFolder() folder name cannot be an empty string");
0733: }
0734:
0735: String sIcon1 = sFolderName.equalsIgnoreCase("inbox") ? "mailbox_16x16.gif"
0736: : "folderclosed_16x16.gif";
0737: String sIcon2 = sFolderName.equalsIgnoreCase("inbox") ? "mailbox_16x16.gif"
0738: : "folderopen_16x16.gif";
0739:
0740: switch (oConn.getDataBaseProduct()) {
0741:
0742: case JDCConnection.DBMS_POSTGRESQL:
0743: if (DebugFile.trace)
0744: DebugFile
0745: .writeln("Connection.prepareStatement(SELECT k_sp_get_user_mailfolder('"
0746: + getStringNull(DB.gu_user, "null")
0747: + "','" + sFolderName + "')");
0748:
0749: oStmt = oConn
0750: .prepareStatement("SELECT k_sp_get_user_mailfolder(?,?)");
0751: oStmt.setString(1, getString(DB.gu_user));
0752: oStmt.setString(2, sFolderName);
0753: oRSet = oStmt.executeQuery();
0754: if (oRSet.next())
0755: sRetVal = oRSet.getString(1);
0756: else
0757: sRetVal = null;
0758: oRSet.close();
0759: oStmt.close();
0760: break;
0761: default:
0762: if (DebugFile.trace)
0763: DebugFile
0764: .writeln("Connection.prepareCall({ call k_sp_get_user_mailfolder('"
0765: + getStringNull(DB.gu_user, "null")
0766: + "','" + sFolderName + "',?)})");
0767: oCall = oConn
0768: .prepareCall("{ call k_sp_get_user_mailfolder(?,?,?) }");
0769: oCall.setString(1, getString(DB.gu_user));
0770: oCall.setString(2, sFolderName);
0771: oCall.registerOutParameter(3, java.sql.Types.CHAR);
0772: oCall.execute();
0773: sRetVal = oCall.getString(3);
0774: oCall.close();
0775: break;
0776: }
0777:
0778: if (sRetVal == null) {
0779: if (DebugFile.trace)
0780: DebugFile.writeln("Creating new mail folder "
0781: + sFolderName + " for user "
0782: + getStringNull(DB.gu_user, "null"));
0783: ACLUser oMe = new ACLUser();
0784: if (oMe.load(oConn, new Object[] { getString(DB.gu_user) })) {
0785: if (!oMe.isNull(DB.gu_category)) {
0786: String sGuMailRoot = getMailRoot(oConn);
0787: if (sGuMailRoot != null) {
0788: ACLDomain oDom = new ACLDomain(oConn, oMe
0789: .getInt(DB.id_domain));
0790:
0791: Statement oInsr = oConn.createStatement();
0792: String sNewGUID = Gadgets.generateUUID();
0793:
0794: String sSQL = "INSERT INTO " + DB.k_categories
0795: + " (" + DB.gu_category + ","
0796: + DB.gu_owner + "," + DB.nm_category
0797: + "," + DB.bo_active + ","
0798: + DB.dt_modified + "," + DB.nm_icon
0799: + "," + DB.id_doc_status + ","
0800: + DB.nm_icon2 + "," + DB.len_size
0801: + ") VALUES ('" + sNewGUID + "','"
0802: + oMe.getString(DB.gu_user) + "','"
0803: + oDom.getString(DB.nm_domain) + "_"
0804: + oMe.getString(DB.tx_nickname) + "_"
0805: + sFolderName + "',1,NULL,'" + sIcon1
0806: + "',1,'" + sIcon2 + "',0)";
0807:
0808: if (DebugFile.trace)
0809: DebugFile
0810: .writeln("Statement.executeUpdate("
0811: + sSQL + ")");
0812:
0813: oInsr.executeUpdate(sSQL);
0814:
0815: String[] aLabels = new String[] { "en", "es",
0816: "fr", "de", "it", "pt", "ca", "ja",
0817: "cn", "tw", "fi", "ru", "pl", "nl",
0818: "xx" };
0819:
0820: for (int l = 0; l < aLabels.length; l++) {
0821: sSQL = "INSERT INTO "
0822: + DB.k_cat_labels
0823: + " ("
0824: + DB.gu_category
0825: + ","
0826: + DB.id_language
0827: + ","
0828: + DB.tr_category
0829: + ","
0830: + DB.url_category
0831: + ") VALUES ('"
0832: + sNewGUID
0833: + "','"
0834: + aLabels[l]
0835: + "','"
0836: + sFolderName.substring(0, 1)
0837: .toUpperCase()
0838: + sFolderName.substring(1)
0839: .toLowerCase() + "',NULL)";
0840: if (DebugFile.trace)
0841: DebugFile
0842: .writeln("Statement.executeUpdate("
0843: + sSQL + ")");
0844: oInsr.executeUpdate(sSQL);
0845: }
0846:
0847: sSQL = "INSERT INTO " + DB.k_x_cat_user_acl
0848: + " (" + DB.gu_category + ","
0849: + DB.gu_user + "," + DB.acl_mask
0850: + ") VALUES ('" + sNewGUID + "','"
0851: + oMe.getString(DB.gu_user)
0852: + "',2147483647)";
0853: if (DebugFile.trace)
0854: DebugFile
0855: .writeln("Statement.executeUpdate("
0856: + sSQL + ")");
0857: oInsr.executeUpdate(sSQL);
0858:
0859: if (!oMe.getString(DB.gu_user).equals(
0860: oDom.getString(DB.gu_owner))) {
0861: sSQL = "INSERT INTO " + DB.k_x_cat_user_acl
0862: + " (" + DB.gu_category + ","
0863: + DB.gu_user + "," + DB.acl_mask
0864: + ") VALUES ('" + sNewGUID + "','"
0865: + oDom.getString(DB.gu_owner)
0866: + "',2147483647)";
0867: if (DebugFile.trace)
0868: DebugFile
0869: .writeln("Statement.executeUpdate("
0870: + sSQL + ")");
0871: oInsr.executeUpdate(sSQL);
0872: }
0873:
0874: sSQL = "INSERT INTO " + DB.k_cat_tree + " ("
0875: + DB.gu_parent_cat + ","
0876: + DB.gu_child_cat + ") VALUES ('"
0877: + sGuMailRoot + "','" + sNewGUID + "')";
0878: if (DebugFile.trace)
0879: DebugFile
0880: .writeln("Statement.executeUpdate("
0881: + sSQL + ")");
0882: oInsr.executeUpdate(sSQL);
0883:
0884: oInsr.close();
0885:
0886: Category oMailRoot = new Category(sGuMailRoot);
0887: oMailRoot.expand(oConn);
0888: sRetVal = sNewGUID;
0889: }
0890: }
0891: } else {
0892: if (DebugFile.trace)
0893: DebugFile.writeln("user "
0894: + getStringNull(DB.gu_user, "null")
0895: + " does not exist");
0896: throw new SQLException("User "
0897: + getStringNull(DB.gu_user, "null")
0898: + " not found", "02000", 0);
0899: }
0900: } else
0901: sRetVal = sRetVal.trim();
0902:
0903: if (DebugFile.trace) {
0904: DebugFile.decIdent();
0905: DebugFile.writeln("End ACLUser.getMailFolder() : "
0906: + String.valueOf(sRetVal));
0907: }
0908:
0909: return sRetVal;
0910: } // getMailFolder
0911:
0912: // ---------------------------------------------------------------------------
0913:
0914: /**
0915: * Get roles of this user for a given application and workarea
0916: * @param oConn JDCConnection
0917: * @param iIdApp int Id of application (from k_apps table)
0918: * @param sGuWorkArea String Guid of WorkArea (from k_workareas table)
0919: * @return int Any bitwise OR combination of { ACL.ROLE_ADMIN || ACL.ROLE_POWERUSER || ACL.ROLE_USER || ACL.ROLE_GUEST }
0920: * @throws SQLException
0921: * @since 3.0
0922: */
0923: public int getRolesForApplication(JDCConnection oConn, int iIdApp,
0924: String sGuWorkArea) throws SQLException {
0925:
0926: if (DebugFile.trace) {
0927: DebugFile
0928: .writeln("Begin ACLUser.getRolesForApplication([JDCConnection],"
0929: + String.valueOf(iIdApp)
0930: + ","
0931: + sGuWorkArea + ")");
0932: DebugFile.incIdent();
0933: }
0934:
0935: int iRolesBitMask = ACL.ROLE_NONE;
0936: String sGuAdmins, sGuPowUsers, sGuUser, sGuGuest;
0937: PreparedStatement oStmt = oConn
0938: .prepareStatement("SELECT " + DB.gu_admins + ","
0939: + DB.gu_powusers + "," + DB.gu_users + ","
0940: + DB.gu_guests + " FROM " + DB.k_x_app_workarea
0941: + " WHERE " + DB.id_app + "=? AND "
0942: + DB.gu_workarea + "=?",
0943: ResultSet.TYPE_FORWARD_ONLY,
0944: ResultSet.CONCUR_READ_ONLY);
0945: oStmt.setInt(1, iIdApp);
0946: oStmt.setString(2, sGuWorkArea);
0947: ResultSet oRSet = oStmt.executeQuery();
0948: boolean bFound = oRSet.next();
0949: if (bFound) {
0950: sGuAdmins = oRSet.getString(1);
0951: sGuPowUsers = oRSet.getString(2);
0952: sGuUser = oRSet.getString(3);
0953: sGuGuest = oRSet.getString(4);
0954: } else {
0955: sGuAdmins = sGuPowUsers = sGuUser = sGuGuest = null;
0956: }
0957: oRSet.close();
0958: oStmt.close();
0959: if (bFound) {
0960: oStmt = oConn.prepareStatement("SELECT NULL FROM "
0961: + DB.k_x_group_user + " WHERE " + DB.gu_acl_group
0962: + "=? AND " + DB.gu_user + "='"
0963: + getString(DB.gu_user) + "'",
0964: ResultSet.TYPE_FORWARD_ONLY,
0965: ResultSet.CONCUR_READ_ONLY);
0966: if (null != sGuAdmins) {
0967: oStmt.setString(1, sGuAdmins);
0968: oRSet = oStmt.executeQuery();
0969: if (oRSet.next())
0970: iRolesBitMask = ACL.ROLE_ADMIN;
0971: oRSet.close();
0972: }
0973: if (null != sGuPowUsers) {
0974: oStmt.setString(1, sGuPowUsers);
0975: oRSet = oStmt.executeQuery();
0976: if (oRSet.next())
0977: iRolesBitMask |= ACL.ROLE_POWERUSER;
0978: oRSet.close();
0979: }
0980: if (null != sGuUser) {
0981: oStmt.setString(1, sGuUser);
0982: oRSet = oStmt.executeQuery();
0983: if (oRSet.next())
0984: iRolesBitMask |= ACL.ROLE_USER;
0985: oRSet.close();
0986: }
0987: if (null != sGuGuest) {
0988: oStmt.setString(1, sGuGuest);
0989: oRSet = oStmt.executeQuery();
0990: if (oRSet.next())
0991: iRolesBitMask |= ACL.ROLE_GUEST;
0992: oRSet.close();
0993: }
0994: oStmt.close();
0995: } // fi (bFound)
0996:
0997: if (DebugFile.trace) {
0998: DebugFile.decIdent();
0999: DebugFile.writeln("End ACLUser.getRolesForApplication() : "
1000: + String.valueOf(iRolesBitMask));
1001: }
1002:
1003: return iRolesBitMask;
1004: } // getRolesForApplication
1005:
1006: // ---------------------------------------------------------------------------
1007:
1008: /**
1009: * Find out if this user has administrator role over given application and workarea
1010: * @param oConn JDCConnection
1011: * @param iIdApp int Id of application (from k_apps table)
1012: * @param sGuWorkArea String Guid of WorkArea (from k_workareas table)
1013: * @return boolean
1014: * @throws SQLException
1015: * @since 3.0
1016: */
1017: public boolean isAdminForApplication(JDCConnection oConn,
1018: int iIdApp, String sGuWorkArea) throws SQLException {
1019: return ((getRolesForApplication(oConn, iIdApp, sGuWorkArea) & ACL.ROLE_ADMIN) != 0);
1020: }
1021:
1022: // ---------------------------------------------------------------------------
1023:
1024: /**
1025: * Find out if this user has power user role over given application and workarea
1026: * @param oConn JDCConnection
1027: * @param iIdApp int Id of application (from k_apps table)
1028: * @param sGuWorkArea String Guid of WorkArea (from k_workareas table)
1029: * @return boolean
1030: * @throws SQLException
1031: * @since 3.0
1032: */
1033: public boolean isPowerUserForApplication(JDCConnection oConn,
1034: int iIdApp, String sGuWorkArea) throws SQLException {
1035: return ((getRolesForApplication(oConn, iIdApp, sGuWorkArea) & ACL.ROLE_POWERUSER) != 0);
1036: }
1037:
1038: // ---------------------------------------------------------------------------
1039:
1040: /**
1041: * Find out if this user has plain user role over given application and workarea
1042: * @param oConn JDCConnection
1043: * @param iIdApp int Id of application (from k_apps table)
1044: * @param sGuWorkArea String Guid of WorkArea (from k_workareas table)
1045: * @return boolean
1046: * @throws SQLException
1047: * @since 3.0
1048: */
1049: public boolean isUserForApplication(JDCConnection oConn,
1050: int iIdApp, String sGuWorkArea) throws SQLException {
1051: return ((getRolesForApplication(oConn, iIdApp, sGuWorkArea) & ACL.ROLE_USER) != 0);
1052: }
1053:
1054: // ---------------------------------------------------------------------------
1055:
1056: /**
1057: * Find out if this user has administrator role in his default workarea over given application
1058: * @param oConn JDCConnection
1059: * @param iIdApp int Id of application (from k_apps table)
1060: * @param sGuWorkArea String Guid of WorkArea (from k_workareas table)
1061: * @return boolean
1062: * @throws SQLException
1063: * @since 3.0
1064: */
1065: public boolean isAdminForApplication(JDCConnection oConn, int iIdApp)
1066: throws SQLException {
1067: return ((getRolesForApplication(oConn, iIdApp,
1068: getString(DB.gu_workarea)) & ACL.ROLE_ADMIN) != 0);
1069: }
1070:
1071: // ---------------------------------------------------------------------------
1072:
1073: /**
1074: * Find out if this user has power user role in his default workarea over given application
1075: * @param oConn JDCConnection
1076: * @param iIdApp int Id of application (from k_apps table)
1077: * @param sGuWorkArea String Guid of WorkArea (from k_workareas table)
1078: * @return boolean
1079: * @throws SQLException
1080: * @since 3.0
1081: */
1082: public boolean isPowerUserForApplication(JDCConnection oConn,
1083: int iIdApp) throws SQLException {
1084: return ((getRolesForApplication(oConn, iIdApp,
1085: getString(DB.gu_workarea)) & ACL.ROLE_POWERUSER) != 0);
1086: }
1087:
1088: // ---------------------------------------------------------------------------
1089:
1090: /**
1091: * Find out if this user has plain user role in his default workarea over given application
1092: * @param oConn JDCConnection
1093: * @param iIdApp int Id of application (from k_apps table)
1094: * @param sGuWorkArea String Guid of WorkArea (from k_workareas table)
1095: * @return boolean
1096: * @throws SQLException
1097: * @since 3.0
1098: */
1099: public boolean isUserForApplication(JDCConnection oConn, int iIdApp)
1100: throws SQLException {
1101: return ((getRolesForApplication(oConn, iIdApp,
1102: getString(DB.gu_workarea)) & ACL.ROLE_USER) != 0);
1103: }
1104:
1105: // ---------------------------------------------------------------------------
1106:
1107: /**
1108: * Find out if this user has guest role in his default workarea over given application
1109: * @param oConn JDCConnection
1110: * @param iIdApp int Id of application (from k_apps table)
1111: * @param sGuWorkArea String Guid of WorkArea (from k_workareas table)
1112: * @return boolean
1113: * @throws SQLException
1114: * @since 3.0
1115: */
1116: public boolean isGuestForApplication(JDCConnection oConn, int iIdApp)
1117: throws SQLException {
1118: return ((getRolesForApplication(oConn, iIdApp,
1119: getString(DB.gu_workarea)) & ACL.ROLE_GUEST) != 0);
1120: }
1121:
1122: // ---------------------------------------------------------------------------
1123:
1124: // ***************************************************************************
1125: // Static Methods
1126:
1127: /**
1128: * <p>Get User Unique Id. from its main e-mail address.</p>
1129: * <p>This method calls k_get_user_from_email stored procedure.</p>
1130: * @param oConn Database Connection
1131: * @param sUserEMail User main e-mail (tx_main_email from k_users table)
1132: * @return User Unique Id. or <b>null</b> if no user was found with such e-mail.
1133: * @throws SQLException
1134: */
1135: public static String getIdFromEmail(JDCConnection oConn,
1136: String sUserEMail) throws SQLException {
1137: String sRetVal;
1138: PreparedStatement oStmt;
1139: ResultSet oRSet;
1140:
1141: switch (oConn.getDataBaseProduct()) {
1142:
1143: case JDCConnection.DBMS_MYSQL:
1144: case JDCConnection.DBMS_MSSQL:
1145: case JDCConnection.DBMS_ORACLE:
1146: sRetVal = DBPersist.getUIdFromName(oConn, null, sUserEMail,
1147: "k_get_user_from_email");
1148: break;
1149:
1150: default:
1151: if (DebugFile.trace)
1152: DebugFile.writeln("Connection.prepareStatement(SELECT "
1153: + DB.gu_user + " FROM " + DB.k_users
1154: + " WHERE " + DB.tx_main_email + "='"
1155: + sUserEMail + "')");
1156:
1157: oStmt = oConn.prepareStatement("SELECT " + DB.gu_user
1158: + " FROM " + DB.k_users + " WHERE "
1159: + DB.tx_main_email + "=?",
1160: ResultSet.TYPE_FORWARD_ONLY,
1161: ResultSet.CONCUR_READ_ONLY);
1162: oStmt.setString(1, sUserEMail);
1163: oRSet = oStmt.executeQuery();
1164: if (oRSet.next())
1165: sRetVal = oRSet.getString(1);
1166: else
1167: sRetVal = null;
1168: oRSet.close();
1169: oStmt.close();
1170: break;
1171:
1172: } // end switch
1173:
1174: return sRetVal;
1175: } // getIdFromEmail
1176:
1177: // ----------------------------------------------------------
1178:
1179: /**
1180: * <p>Get User main e-mail from its GUID.</p>
1181: * @param oConn Database Connection
1182: * @param sUserId User GUID (gu_user from k_users table)
1183: * @return User tx_main_email or <b>null</b> if no user was found with such GUID.
1184: * @throws SQLException
1185: */
1186:
1187: public static String getEmailFromId(JDCConnection oConn,
1188: String sUserId) throws SQLException {
1189: String sRetVal;
1190: PreparedStatement oStmt;
1191: ResultSet oRSet;
1192:
1193: if (DebugFile.trace)
1194: DebugFile.writeln("Connection.prepareStatement(SELECT "
1195: + DB.tx_main_email + " FROM " + DB.k_users
1196: + " WHERE " + DB.gu_user + "='" + sUserId + "')");
1197:
1198: oStmt = oConn
1199: .prepareStatement("SELECT " + DB.tx_main_email
1200: + " FROM " + DB.k_users + " WHERE "
1201: + DB.gu_user + "=?",
1202: ResultSet.TYPE_FORWARD_ONLY,
1203: ResultSet.CONCUR_READ_ONLY);
1204: oStmt.setString(1, sUserId);
1205: oRSet = oStmt.executeQuery();
1206: if (oRSet.next())
1207: sRetVal = oRSet.getString(1);
1208: else
1209: sRetVal = null;
1210: oRSet.close();
1211: oStmt.close();
1212:
1213: return sRetVal;
1214: } // getEmailFromId
1215:
1216: // ----------------------------------------------------------
1217:
1218: /**
1219: * <p>Get User Unique Id. from its nickname.</p>
1220: * <p>This method executes a SQL query with a ResultSet</p>
1221: * @param oConn Database Connection
1222: * @param sUserEMail User nickname (tx_nickname from k_users table)
1223: * @return User Unique Id. or <b>null</b> if no user was found with such e-mail.
1224: * @throws SQLException
1225: */
1226:
1227: public static String getIdFromNick(Connection oConn, int iDomainId,
1228: String sUserNick) throws SQLException {
1229: String sRetVal;
1230: PreparedStatement oStmt;
1231: ResultSet oRSet;
1232:
1233: oStmt = oConn
1234: .prepareStatement("SELECT " + DB.gu_user + " FROM "
1235: + DB.k_users + " WHERE " + DB.id_domain
1236: + "=? AND " + DB.tx_nickname + "=?",
1237: ResultSet.TYPE_FORWARD_ONLY,
1238: ResultSet.CONCUR_READ_ONLY);
1239: oStmt.setInt(1, iDomainId);
1240: oStmt.setString(2, sUserNick);
1241: oRSet = oStmt.executeQuery();
1242: if (oRSet.next())
1243: sRetVal = oRSet.getString(1);
1244: else
1245: sRetVal = null;
1246: oRSet.close();
1247: oStmt.close();
1248: return sRetVal;
1249: } // getIdFromNick
1250:
1251: // ----------------------------------------------------------
1252:
1253: /**
1254: * <p>Get User Unique Id. from its nickname.</p>
1255: * <p>This method calls k_get_user_from_nick stored procedure.</p>
1256: * @param oConn Database Connection
1257: * @param sUserEMail User nickname (tx_nickname from k_users table)
1258: * @return User Unique Id. or <b>null</b> if no user was found with such e-mail.
1259: * @throws SQLException
1260: * @since 3.0
1261: */
1262:
1263: public static String getIdFromNick(JDCConnection oConn,
1264: int iDomainId, String sUserNick) throws SQLException {
1265: String sRetVal;
1266:
1267: switch (oConn.getDataBaseProduct()) {
1268: case JDCConnection.DBMS_MSSQL:
1269: case JDCConnection.DBMS_ORACLE:
1270: sRetVal = DBPersist.getUIdFromName(oConn, new Integer(
1271: iDomainId), sUserNick, "k_get_user_from_nick");
1272: break;
1273: default:
1274: sRetVal = getIdFromNick((Connection) oConn, iDomainId,
1275: sUserNick);
1276: }
1277: return sRetVal;
1278: } // getIdFromNick
1279:
1280: // ----------------------------------------------------------
1281:
1282: /**
1283: * <p>Delete User</p>
1284: * <p>Categories owned by this user are also deleted, but other data and references for user are not checked.</p>
1285: * @param oConn Database Connection
1286: * @param sUserGUID User Unique Identifier
1287: * @throws SQLException
1288: * @throws IOException
1289: */
1290:
1291: public static boolean delete(JDCConnection oConn, String sUserGUID)
1292: throws SQLException, IOException {
1293: boolean bRetVal;
1294: int iCats, iConts, iMsgs;
1295: DBSubset oCats, oProds, oConts, oMsgs;
1296: Statement oStmt;
1297: PreparedStatement oPtmt;
1298: ResultSet oRSet;
1299: CallableStatement oCall;
1300:
1301: if (DebugFile.trace) {
1302: DebugFile.writeln("Begin ACLUser.delete([Connection], "
1303: + sUserGUID + ")");
1304: DebugFile.incIdent();
1305: }
1306:
1307: // -----------------------------------------------------------------------------------
1308: // Verify that user exists before proceeding and, also, avoid deleting more registers
1309: // than should by a malicious inyection of SQL code at sUserGUID
1310:
1311: oPtmt = oConn
1312: .prepareStatement("SELECT " + DB.gu_user + " FROM "
1313: + DB.k_users + " WHERE " + DB.gu_user + "=?",
1314: ResultSet.TYPE_FORWARD_ONLY,
1315: ResultSet.CONCUR_READ_ONLY);
1316: oPtmt.setString(1, sUserGUID);
1317: oRSet = oPtmt.executeQuery();
1318: boolean bExists = oRSet.next();
1319: oRSet.close();
1320: oPtmt.close();
1321:
1322: if (!bExists) {
1323: if (DebugFile.trace) {
1324: DebugFile.writeln("user " + sUserGUID + " not found");
1325: DebugFile.decIdent();
1326: DebugFile.writeln("End ACLUser.delete() : false");
1327: }
1328: return false;
1329: }
1330:
1331: // ************
1332: // New for v3.0
1333:
1334: if (DBBind.exists(oConn, DB.k_user_pwd, "U")) {
1335: oStmt = oConn.createStatement();
1336: if (DebugFile.trace)
1337: DebugFile
1338: .writeln("Statement.executeUpdate(DELETE FROM "
1339: + DB.k_user_pwd + " WHERE "
1340: + DB.gu_user + "='" + sUserGUID + "')");
1341: oStmt.executeUpdate("DELETE FROM " + DB.k_user_pwd
1342: + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
1343: oStmt.close();
1344: }
1345:
1346: if (DBBind.exists(oConn, DB.k_user_mail, "U")) {
1347: oStmt = oConn.createStatement();
1348: if (DebugFile.trace)
1349: DebugFile
1350: .writeln("Statement.executeUpdate(DELETE FROM "
1351: + DB.k_user_mail + " WHERE "
1352: + DB.gu_user + "='" + sUserGUID + "')");
1353: oStmt.executeUpdate("DELETE FROM " + DB.k_user_mail
1354: + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
1355: oStmt.close();
1356: }
1357:
1358: /* Actualizar los estados de negocio creados por el usuario */
1359: if (DBBind.exists(oConn, DB.k_business_states, "U")) {
1360: oStmt = oConn.createStatement();
1361: if (DebugFile.trace)
1362: DebugFile.writeln("UPDATE " + DB.k_business_states
1363: + " SET " + DB.gu_writer + "=NULL WHERE "
1364: + DB.gu_writer + "='" + sUserGUID + "'");
1365: oStmt.executeUpdate("UPDATE " + DB.k_business_states
1366: + " SET " + DB.gu_writer + "=NULL WHERE "
1367: + DB.gu_writer + "='" + sUserGUID + "'");
1368: oStmt.close();
1369: }
1370:
1371: /* Borrar la referencia este usuario desde los cuestionarios que haya rellenado */
1372: if (DBBind.exists(oConn, DB.k_pageset_answers, "U")) {
1373: oStmt = oConn.createStatement();
1374: if (DebugFile.trace)
1375: DebugFile.writeln("UPDATE " + DB.k_pageset_answers
1376: + " SET " + DB.gu_writer + "=NULL WHERE "
1377: + DB.gu_writer + "='" + sUserGUID + "'");
1378: oStmt.executeUpdate("UPDATE " + DB.k_pageset_answers
1379: + " SET " + DB.gu_writer + "=NULL WHERE "
1380: + DB.gu_writer + "='" + sUserGUID + "'");
1381: oStmt.close();
1382: }
1383:
1384: /* Desasociar las evaluaciones */
1385: if (DBBind.exists(oConn, DB.k_evaluations, "U")) {
1386: oStmt = oConn.createStatement();
1387: if (DebugFile.trace)
1388: DebugFile.writeln("UPDATE " + DB.k_evaluations
1389: + " SET " + DB.gu_writer + "=NULL WHERE "
1390: + DB.gu_writer + "='" + sUserGUID + "'");
1391: oStmt.executeUpdate("UPDATE " + DB.k_evaluations + " SET "
1392: + DB.gu_writer + "=NULL WHERE " + DB.gu_writer
1393: + "='" + sUserGUID + "'");
1394: oStmt.close();
1395: }
1396:
1397: /* Desasociar los partes de absentismo */
1398: if (DBBind.exists(oConn, DB.k_absentisms, "U")) {
1399: oStmt = oConn.createStatement();
1400: if (DebugFile.trace)
1401: DebugFile.writeln("UPDATE " + DB.k_absentisms + " SET "
1402: + DB.gu_writer + "=NULL WHERE " + DB.gu_writer
1403: + "='" + sUserGUID + "'");
1404: oStmt.executeUpdate("UPDATE " + DB.k_absentisms + " SET "
1405: + DB.gu_writer + "=NULL WHERE " + DB.gu_writer
1406: + "='" + sUserGUID + "'");
1407: oStmt.close();
1408: }
1409:
1410: // End new for v2.2
1411: // ****************
1412:
1413: // ************
1414: // New for v2.1
1415:
1416: /* Desasociar los e-mails */
1417: if (DBBind.exists(oConn, DB.k_inet_addrs, "U")) {
1418: oStmt = oConn.createStatement();
1419:
1420: if (DebugFile.trace)
1421: DebugFile.writeln("UPDATE " + DB.k_inet_addrs + " SET "
1422: + DB.gu_user + "=NULL WHERE " + DB.gu_user
1423: + "='" + sUserGUID + "'");
1424:
1425: oStmt.executeUpdate("UPDATE " + DB.k_inet_addrs + " SET "
1426: + DB.gu_user + "=NULL WHERE " + DB.gu_user + "='"
1427: + sUserGUID + "'");
1428:
1429: oStmt.close();
1430: }
1431:
1432: if (DBBind.exists(oConn, DB.k_x_portlet_user, "U")) {
1433: oStmt = oConn.createStatement();
1434:
1435: if (DebugFile.trace)
1436: DebugFile
1437: .writeln("Statement.executeUpdate(DELETE FROM "
1438: + DB.k_x_portlet_user + " WHERE "
1439: + DB.gu_user + "='" + sUserGUID + "')");
1440:
1441: oStmt.executeUpdate("DELETE FROM " + DB.k_x_portlet_user
1442: + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
1443:
1444: oStmt.close();
1445: }
1446:
1447: if (DBBind.exists(oConn, DB.k_images, "U")) {
1448:
1449: oStmt = oConn.createStatement();
1450:
1451: if (DebugFile.trace)
1452: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1453: + DB.k_images + " SET " + DB.gu_writer
1454: + "=NULL WHERE " + DB.gu_writer + "='"
1455: + sUserGUID + "')");
1456:
1457: oStmt.executeUpdate("UPDATE " + DB.k_images + " SET "
1458: + DB.gu_writer + "=NULL WHERE " + DB.gu_writer
1459: + "='" + sUserGUID + "'");
1460:
1461: oStmt.close();
1462: }
1463:
1464: if (DBBind.exists(oConn, DB.k_bugs_lookup, "U")) {
1465:
1466: oStmt = oConn.createStatement();
1467:
1468: if (DebugFile.trace)
1469: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1470: + DB.k_bugs + " SET " + DB.nm_assigned
1471: + "=NULL WHERE " + DB.nm_assigned + "='"
1472: + sUserGUID + "')");
1473:
1474: oStmt.executeUpdate("UPDATE " + DB.k_bugs + " SET "
1475: + DB.nm_assigned + "=NULL WHERE " + DB.nm_assigned
1476: + "='" + sUserGUID + "'");
1477:
1478: oStmt.close();
1479:
1480: oStmt = oConn.createStatement();
1481:
1482: if (DebugFile.trace)
1483: DebugFile
1484: .writeln("Statement.executeUpdate(DELETE FROM "
1485: + DB.k_bugs_lookup + " WHERE "
1486: + DB.vl_lookup + "='" + sUserGUID
1487: + "')");
1488:
1489: oStmt
1490: .executeUpdate("DELETE FROM " + DB.k_bugs_lookup
1491: + " WHERE " + DB.vl_lookup + "='"
1492: + sUserGUID + "'");
1493:
1494: oStmt.close();
1495: }
1496:
1497: if (DBBind.exists(oConn, DB.k_x_duty_resource, "U")) {
1498: oStmt = oConn.createStatement();
1499:
1500: if (DebugFile.trace)
1501: DebugFile
1502: .writeln("Statement.executeUpdate(DELETE FROM "
1503: + DB.k_x_duty_resource + " WHERE "
1504: + DB.nm_resource + "='" + sUserGUID
1505: + "')");
1506:
1507: oStmt.executeUpdate("DELETE FROM " + DB.k_x_duty_resource
1508: + " WHERE " + DB.nm_resource + "='" + sUserGUID
1509: + "'");
1510:
1511: oStmt.close();
1512:
1513: oStmt = oConn.createStatement();
1514:
1515: if (DebugFile.trace)
1516: DebugFile
1517: .writeln("Statement.executeUpdate(DELETE FROM "
1518: + DB.k_duties_lookup + " WHERE "
1519: + DB.vl_lookup + "='" + sUserGUID
1520: + "')");
1521:
1522: oStmt
1523: .executeUpdate("DELETE FROM " + DB.k_duties_lookup
1524: + " WHERE " + DB.vl_lookup + "='"
1525: + sUserGUID + "'");
1526:
1527: oStmt.close();
1528: }
1529:
1530: // End new for v2.1
1531: // ****************
1532:
1533: // ************
1534: // New for v2.0
1535:
1536: if (DBBind.exists(oConn, DB.k_newsgroup_subscriptions, "U")) {
1537: oStmt = oConn.createStatement();
1538:
1539: if (DebugFile.trace)
1540: DebugFile
1541: .writeln("Statement.executeUpdate(DELETE FROM "
1542: + DB.k_newsgroup_subscriptions
1543: + " WHERE " + DB.gu_user + "='"
1544: + sUserGUID + "')");
1545:
1546: oStmt.executeUpdate("DELETE FROM "
1547: + DB.k_newsgroup_subscriptions + " WHERE "
1548: + DB.gu_user + "='" + sUserGUID + "'");
1549:
1550: oStmt.close();
1551: }
1552:
1553: // End new for v2.0
1554: // ****************
1555:
1556: if (DBBind.exists(oConn, DB.k_newsmsgs, "U")) {
1557: oStmt = oConn.createStatement();
1558:
1559: // Remove user GUID from messages he validated
1560: if (DebugFile.trace)
1561: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1562: + DB.k_newsmsgs + " SET " + DB.gu_validator
1563: + "=NULL WHERE " + DB.gu_validator + "='"
1564: + sUserGUID + "'");
1565:
1566: oStmt.executeUpdate("UPDATE " + DB.k_newsmsgs + " SET "
1567: + DB.gu_validator + "=NULL WHERE "
1568: + DB.gu_validator + "='" + sUserGUID + "'");
1569:
1570: // Delete forum messages written by this user without file attachments
1571: if (DebugFile.trace)
1572: DebugFile
1573: .writeln("Statement.executeUpdate(DELETE FROM "
1574: + DB.k_newsmsgs + " WHERE "
1575: + DB.gu_writer + "='" + sUserGUID
1576: + "' AND " + DB.gu_product + " IS NULL");
1577:
1578: oStmt.executeUpdate("DELETE FROM " + DB.k_newsmsgs
1579: + " WHERE " + DB.gu_writer + "='" + sUserGUID
1580: + "' AND " + DB.gu_product + " IS NULL");
1581:
1582: oStmt.close();
1583:
1584: // Delete forum messages written by this user with file attachments
1585: oMsgs = new DBSubset(DB.k_newsmsgs, DB.gu_msg, DB.gu_writer
1586: + "='" + sUserGUID + "'", 100);
1587:
1588: iMsgs = oMsgs.load(oConn);
1589:
1590: for (int m = 0; m < iMsgs; m++)
1591: com.knowgate.forums.NewsMessage.delete(oConn, oMsgs
1592: .getString(0, m));
1593:
1594: oMsgs = null;
1595: } // fi (exists(k_newsmsgs,))
1596:
1597: if (DBBind.exists(oConn, DB.k_member_address, "U")) {
1598: oStmt = oConn.createStatement();
1599:
1600: if (DebugFile.trace)
1601: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1602: + DB.k_member_address + " SET " + DB.gu_writer
1603: + "=NULL WHERE " + DB.gu_writer + "='"
1604: + sUserGUID + "')");
1605:
1606: oStmt.executeUpdate("UPDATE " + DB.k_member_address
1607: + " SET " + DB.gu_writer + "=NULL WHERE "
1608: + DB.gu_writer + "='" + sUserGUID + "'");
1609:
1610: if (DebugFile.trace)
1611: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1612: + DB.k_member_address + " SET "
1613: + DB.gu_sales_man + "=NULL WHERE "
1614: + DB.gu_sales_man + "='" + sUserGUID + "')");
1615:
1616: oStmt.executeUpdate("UPDATE " + DB.k_member_address
1617: + " SET " + DB.gu_sales_man + "=NULL WHERE "
1618: + DB.gu_sales_man + "='" + sUserGUID + "'");
1619:
1620: oStmt.close();
1621: }
1622:
1623: if (DBBind.exists(oConn, DB.k_companies_recent, "U")) {
1624: oStmt = oConn.createStatement();
1625:
1626: if (DebugFile.trace)
1627: DebugFile
1628: .writeln("Statement.executeUpdate(DELETE FROM "
1629: + DB.k_companies_recent + " WHERE "
1630: + DB.gu_user + "='" + sUserGUID + "')");
1631:
1632: oStmt.executeUpdate("DELETE FROM " + DB.k_companies_recent
1633: + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
1634:
1635: oStmt.close();
1636: }
1637:
1638: if (DBBind.exists(oConn, DB.k_companies, "U")) {
1639: oStmt = oConn.createStatement();
1640:
1641: if (DebugFile.trace)
1642: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1643: + DB.k_companies + " SET " + DB.gu_sales_man
1644: + "=NULL WHERE " + DB.gu_sales_man + "='"
1645: + sUserGUID + "')");
1646:
1647: oStmt.executeUpdate("UPDATE " + DB.k_companies + " SET "
1648: + DB.gu_sales_man + "=NULL WHERE "
1649: + DB.gu_sales_man + "='" + sUserGUID + "'");
1650:
1651: oStmt.close();
1652: }
1653:
1654: if (DBBind.exists(oConn, DB.k_contacts_recent, "U")) {
1655: oStmt = oConn.createStatement();
1656:
1657: if (DebugFile.trace)
1658: DebugFile
1659: .writeln("Statement.executeUpdate(DELETE FROM "
1660: + DB.k_contacts_recent + " WHERE "
1661: + DB.gu_user + "='" + sUserGUID + "')");
1662:
1663: oStmt.executeUpdate("DELETE FROM " + DB.k_contacts_recent
1664: + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
1665:
1666: oStmt.close();
1667: }
1668:
1669: if (DBBind.exists(oConn, DB.k_contacts, "U")) {
1670: oConts = new DBSubset(DB.k_contacts, DB.gu_contact,
1671: DB.gu_writer + "='" + sUserGUID + "' AND "
1672: + DB.bo_private + "<>0", 100);
1673: iConts = oConts.load(oConn);
1674:
1675: for (int t = 0; t < iConts; t++)
1676: com.knowgate.crm.Contact.delete(oConn, oConts
1677: .getString(0, t));
1678:
1679: oConts = null;
1680:
1681: oStmt = oConn.createStatement();
1682:
1683: if (DebugFile.trace)
1684: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1685: + DB.k_contacts + " SET " + DB.gu_writer
1686: + "=NULL WHERE " + DB.gu_writer + "='"
1687: + sUserGUID + "' AND " + DB.bo_private + "=0)");
1688:
1689: oStmt.executeUpdate("UPDATE " + DB.k_contacts + " SET "
1690: + DB.gu_writer + "=NULL WHERE " + DB.gu_writer
1691: + "='" + sUserGUID + "' AND " + DB.bo_private
1692: + "=0");
1693:
1694: if (DebugFile.trace)
1695: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1696: + DB.k_contact_notes + " SET " + DB.gu_writer
1697: + "=NULL WHERE " + DB.gu_writer + "='"
1698: + sUserGUID + "')");
1699:
1700: oStmt.executeUpdate("UPDATE " + DB.k_contact_notes
1701: + " SET " + DB.gu_writer + "=NULL WHERE "
1702: + DB.gu_writer + "='" + sUserGUID + "'");
1703:
1704: if (DebugFile.trace)
1705: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1706: + DB.k_contact_attachs + " SET " + DB.gu_writer
1707: + "=NULL WHERE " + DB.gu_writer + "='"
1708: + sUserGUID + "')");
1709:
1710: oStmt.executeUpdate("UPDATE " + DB.k_contact_attachs
1711: + " SET " + DB.gu_writer + "=NULL WHERE "
1712: + DB.gu_writer + "='" + sUserGUID + "'");
1713:
1714: oStmt.close();
1715: }
1716:
1717: if (DBBind.exists(oConn, DB.k_oportunities, "U")) {
1718: oStmt = oConn.createStatement();
1719:
1720: if (DebugFile.trace)
1721: DebugFile
1722: .writeln("Statement.executeUpdate(DELETE FROM "
1723: + DB.k_oportunities + " WHERE "
1724: + DB.gu_writer + "='" + sUserGUID
1725: + "' AND " + DB.bo_private + "<>0)");
1726:
1727: oStmt.executeUpdate("DELETE FROM " + DB.k_oportunities
1728: + " WHERE " + DB.gu_writer + "='" + sUserGUID
1729: + "' AND " + DB.bo_private + "<>0");
1730:
1731: if (DebugFile.trace)
1732: DebugFile.writeln("Statement.executeUpdate(UPDATE "
1733: + DB.k_oportunities + " SET " + DB.gu_writer
1734: + "=NULL WHERE " + DB.gu_writer + "='"
1735: + sUserGUID + "' AND " + DB.bo_private + "=0)");
1736:
1737: oStmt.executeUpdate("UPDATE " + DB.k_oportunities + " SET "
1738: + DB.gu_writer + "=NULL WHERE " + DB.gu_writer
1739: + "='" + sUserGUID + "' AND " + DB.bo_private
1740: + "=0");
1741:
1742: oStmt.close();
1743: }
1744:
1745: if (DBBind.exists(oConn, DB.k_sales_men, "U")) {
1746: if (DebugFile.trace)
1747: DebugFile
1748: .writeln("Connection.prepareCall({ call k_sp_del_sales_man ('"
1749: + sUserGUID + "') })");
1750:
1751: oCall = oConn.prepareCall("{call k_sp_del_sales_man ('"
1752: + sUserGUID + "')}");
1753: bRetVal = oCall.execute();
1754: oCall.close();
1755: }
1756:
1757: if (DBBind.exists(oConn, DB.k_products, "U")) {
1758: oProds = new DBSubset(DB.k_products, DB.gu_product,
1759: DB.gu_owner + "='" + sUserGUID + "'", 100);
1760: int iProds = oProds.load(oConn);
1761:
1762: for (int p = 0; p < iProds; p++)
1763: new com.knowgate.hipergate.Product(oConn, oProds
1764: .getString(0, p)).delete(oConn);
1765: oProds = null;
1766: } // fi (exists(DB.k_products))
1767:
1768: // Delete categories associated with user
1769: if (DBBind.exists(oConn, DB.k_categories, "U")) {
1770: String sGuRootCat = null;
1771: oStmt = oConn.createStatement();
1772: ResultSet oRCat = oStmt.executeQuery("SELECT "
1773: + DB.gu_category + " FROM " + DB.k_users
1774: + " WHERE " + DB.gu_user + "='" + sUserGUID + "'");
1775: if (oRCat.next())
1776: sGuRootCat = oRCat.getString(1);
1777: oRCat.close();
1778: oStmt.close();
1779: if (sGuRootCat != null) {
1780: oStmt = oConn.createStatement();
1781: oStmt.executeUpdate("UPDATE " + DB.k_users + " SET "
1782: + DB.gu_category + "=NULL WHERE " + DB.gu_user
1783: + "='" + sUserGUID + "'");
1784: oStmt.close();
1785: Category.delete(oConn, sGuRootCat);
1786: }
1787:
1788: oCats = new DBSubset(DB.k_categories, DB.gu_category,
1789: DB.gu_owner + "=?", 10);
1790: iCats = oCats.load(oConn, new Object[] { sUserGUID });
1791:
1792: for (int r = 0; r < iCats; r++)
1793: Category.delete(oConn, oCats.getString(0, r));
1794:
1795: oCats = null;
1796: } // fi (exists(oConn, DB.k_categories))
1797:
1798: if (DBBind.exists(oConn, DB.k_phone_calls, "U")) {
1799: oStmt = oConn.createStatement();
1800: try {
1801: oStmt.setQueryTimeout(30);
1802: } catch (SQLException sqle) {
1803: }
1804: if (DebugFile.trace)
1805: DebugFile.writeln("Statement.execute(DELETE FROM "
1806: + DB.k_phone_calls + " WHERE " + DB.gu_user
1807: + "='" + sUserGUID + "' OR " + DB.gu_writer
1808: + "='" + sUserGUID + "')");
1809: oStmt.executeUpdate("DELETE FROM " + DB.k_phone_calls
1810: + " WHERE " + DB.gu_user + "='" + sUserGUID
1811: + "' OR " + DB.gu_writer + "='" + sUserGUID + "'");
1812: oStmt.close();
1813: } // fi (exists(oConn, DB.k_phone_calls))
1814:
1815: if (DBBind.exists(oConn, DB.k_to_do, "U")) {
1816: oStmt = oConn.createStatement();
1817: try {
1818: oStmt.setQueryTimeout(30);
1819: } catch (SQLException sqle) {
1820: }
1821: if (DebugFile.trace)
1822: DebugFile.writeln("Statement.execute(DELETE FROM "
1823: + DB.k_to_do + " WHERE " + DB.gu_user + "='"
1824: + sUserGUID + "')");
1825: oStmt.executeUpdate("DELETE FROM " + DB.k_to_do + " WHERE "
1826: + DB.gu_user + "='" + sUserGUID + "'");
1827: oStmt.close();
1828: } // fi (exists(oConn, DB.k_to_do))
1829:
1830: if (DebugFile.trace)
1831: DebugFile
1832: .writeln("Connection.prepareCall({ call k_sp_del_user ('"
1833: + sUserGUID + "') })");
1834:
1835: oCall = oConn.prepareCall("{call k_sp_del_user ('" + sUserGUID
1836: + "')}");
1837: bRetVal = oCall.execute();
1838: oCall.close();
1839:
1840: if (DebugFile.trace) {
1841: DebugFile.decIdent();
1842: DebugFile.writeln("End ACLUser.delete() : "
1843: + String.valueOf(bRetVal));
1844: }
1845:
1846: return bRetVal;
1847: } // delete
1848:
1849: // ----------------------------------------------------------
1850:
1851: /**
1852: * <p>Shortcut for creating a new user</p>
1853: * @param oConn Database Connection
1854: * @param Values User fields, all required, must be in this order { (Integer)id_domain, (String)tx_nickname, (String)tx_pwd, (Short)bo_active, (Short)bo_searchable, (Short)bo_change_pwd, (String)tx_main_email, (String)tx_alt_email, (String)nm_user, (String)tx_surname1, (String)tx_surname2, (String)tx_challenge, (String)tx_reply, (String)nm_company, (String)de_title, (String)gu_workarea }<br>
1855: * Values up to and including tx_surname1 must be NOT NULL, values from tx_surname2 are required but may be null.
1856: * @return New User Unique Identifier
1857: * @throws SQLException
1858: * @throws ClassCastException
1859: * @throws NullPointerException
1860: * @deprecated Use standard put/store methods instead.
1861: */
1862: public static String create(JDCConnection oConn, Object[] Values)
1863: throws SQLException, ClassCastException,
1864: NullPointerException {
1865:
1866: if (DebugFile.trace) {
1867: DebugFile.writeln("Begin ACLUser.create([Connection])");
1868: DebugFile.incIdent();
1869: }
1870:
1871: ACLUser oUsr = new ACLUser();
1872:
1873: if (null == Values[0]) {
1874: if (DebugFile.trace)
1875: DebugFile.decIdent();
1876: throw new NullPointerException(
1877: "ACLUSer.create() a domain identifier is required");
1878: }
1879: if (Values[0].getClass().equals(Integer.TYPE)) {
1880: if (DebugFile.trace)
1881: DebugFile.decIdent();
1882: throw new ClassCastException(
1883: "ACLUSer.create() the domain identifier must be an object of type Integer");
1884: }
1885:
1886: oUsr.put(DB.id_domain, Values[0]);
1887: oUsr.put(DB.tx_nickname, Values[1]);
1888: oUsr.put(DB.tx_pwd, Values[2]);
1889: oUsr.put(DB.bo_active, Values[3]);
1890: oUsr.put(DB.bo_searchable, Values[4]);
1891: oUsr.put(DB.bo_change_pwd, Values[5]);
1892: oUsr.put(DB.tx_main_email, Values[6]);
1893: oUsr.put(DB.tx_alt_email, Values[7]);
1894: oUsr.put(DB.nm_user, Values[8]);
1895: oUsr.put(DB.tx_surname1, Values[9]);
1896: if (Values.length > 10)
1897: if (null != Values[10])
1898: oUsr.put(DB.tx_surname2, Values[10]);
1899: if (Values.length > 11)
1900: if (null != Values[11])
1901: oUsr.put(DB.tx_challenge, Values[11]);
1902: if (Values.length > 12)
1903: if (null != Values[12])
1904: oUsr.put(DB.tx_reply, Values[12]);
1905: if (Values.length > 13)
1906: if (null != Values[13])
1907: oUsr.put(DB.nm_company, Values[13]);
1908: if (Values.length > 14)
1909: if (null != Values[14])
1910: oUsr.put(DB.de_title, Values[14]);
1911: if (Values.length > 15)
1912: if (null != Values[15])
1913: oUsr.put(DB.gu_workarea, Values[15]);
1914: if (Values.length > 16)
1915: if (null != Values[16])
1916: oUsr.put(DB.tx_comments, Values[16]);
1917:
1918: oUsr.store(oConn);
1919:
1920: String sRetVal = oUsr.getString(DB.gu_user);
1921:
1922: if (oConn.exists(DB.k_mime_msgs, "U")) {
1923: oUsr.getMailFolder(oConn, "inbox");
1924: oUsr.getMailFolder(oConn, "outbox");
1925: oUsr.getMailFolder(oConn, "drafts");
1926: oUsr.getMailFolder(oConn, "deleted");
1927: oUsr.getMailFolder(oConn, "sent");
1928: oUsr.getMailFolder(oConn, "spam");
1929: }
1930:
1931: if (DebugFile.trace) {
1932: DebugFile.decIdent();
1933: DebugFile.writeln("End ACLUser.create() : " + sRetVal);
1934: }
1935: return sRetVal;
1936: } // create()
1937:
1938: // **********************************************************
1939: // Public Constants
1940:
1941: public static final short ClassId = 2;
1942:
1943: // **********************************************************
1944: // Private Variables
1945:
1946: private DBSubset oAddresses;
1947: private DBSubset oGroups;
1948: }
|