1 32 33 package com.knowgate.acl; 34 35 import java.util.StringTokenizer ; 36 import java.math.BigDecimal ; 37 38 import java.io.IOException ; 39 40 import java.sql.Connection ; 41 import java.sql.SQLException ; 42 import java.sql.CallableStatement ; 43 import java.sql.PreparedStatement ; 44 import java.sql.Statement ; 45 import java.sql.ResultSet ; 46 47 import com.knowgate.debug.DebugFile; 48 import com.knowgate.jdc.JDCConnection; 49 import com.knowgate.dataobjs.DB; 50 import com.knowgate.dataobjs.DBBind; 51 import com.knowgate.dataobjs.DBPersist; 52 import com.knowgate.dataobjs.DBSubset; 53 import com.knowgate.hipergate.Category; 54 55 import com.knowgate.misc.Gadgets; 56 57 62 63 public final class ACLUser extends DBPersist { 64 65 68 public ACLUser() { 69 super(DB.k_users, "ACLUser"); 70 } 71 72 78 79 public ACLUser(String sUserGUID) throws SQLException { 80 super(DB.k_users,"ACLUser"); 81 82 put(DB.gu_user, sUserGUID); 83 } 84 85 91 92 public ACLUser(JDCConnection oConn, String sUserGUID) throws SQLException { 93 super(DB.k_users,"ACLUser"); 94 95 Object aUser[] = { sUserGUID }; 96 97 load (oConn, aUser); 98 } 99 100 102 111 public DBSubset getAddresses(JDCConnection oConn) throws SQLException { 112 Object aUser[] = { get(DB.gu_user) }; 113 oAddresses = new DBSubset(DB.k_x_addr_user,DB.gu_address + "," + DB.ix_address + "," + DB.tp_location, DB.gu_user + "=?",10); 114 115 oAddresses.load (oConn, aUser); 116 return oAddresses; 117 } 118 119 121 127 public DBSubset getGroups(JDCConnection oConn) throws SQLException { 128 Object aUser[] = { get(DB.gu_user) }; 129 oGroups = new DBSubset(DB.k_x_group_user,DB.gu_acl_group,DB.gu_user + "=?",10); 130 131 oGroups.load (oConn, aUser); 132 return oGroups; 133 } 134 135 137 144 public int addToACLGroups(JDCConnection oConn, String sGroupList) throws SQLException { 145 146 if (DebugFile.trace) { 147 DebugFile.writeln("Begin ACLUser.addToACLGroups(Connection], " + sGroupList + ")"); 148 DebugFile.incIdent(); 149 } 150 151 Statement oStmt; 152 int iRetVal = 0; 153 StringTokenizer oStrTok = new StringTokenizer (sGroupList, ","); 154 String sIdGroup; 155 156 oStmt = oConn.createStatement(); 157 158 while (oStrTok.hasMoreElements()) { 159 sIdGroup = oStrTok.nextToken(); 160 161 if (DebugFile.trace) 162 DebugFile.writeln("Statement.executeUpdate(INSERT INTO " + DB.k_x_group_user + "(" + DB.gu_user + "," + DB.gu_acl_group + ") VALUES('" + getStringNull(DB.gu_user, "null") + "','" + sIdGroup + "')"); 163 164 iRetVal += oStmt.executeUpdate("INSERT INTO " + DB.k_x_group_user + "(" + DB.gu_user + "," + DB.gu_acl_group + ") VALUES('" + getString(DB.gu_user) + "','" + sIdGroup + "')"); 165 } 167 oStmt.close(); 168 169 if (DebugFile.trace) { 170 DebugFile.decIdent(); 171 DebugFile.writeln("End ACLUser.addToACLGroups() : " + String.valueOf(iRetVal)); 172 } 173 174 return iRetVal; 175 } 177 179 190 public boolean isDomainAdmin(JDCConnection oConn) throws SQLException , IllegalStateException { 191 PreparedStatement oStmt; 192 ResultSet oRSet; 193 boolean bAdmin; 194 195 if (DebugFile.trace) { 196 DebugFile.writeln("Begin ACLUser.sDomainAdmin(Connection])"); 197 DebugFile.incIdent(); 198 } 199 200 if (isNull(DB.id_domain)) { 201 if (DebugFile.trace) { 202 DebugFile.writeln("ERROR id_domain not set"); 203 DebugFile.decIdent(); 204 } 205 206 throw new IllegalStateException ("ACLUSer.isDomainAdmin() Property id_domain is not set"); 207 } 208 209 if (isNull(DB.gu_user)) { 210 if (DebugFile.trace) { 211 DebugFile.writeln("ERROR gu_user not set"); 212 DebugFile.decIdent(); 213 } 214 215 throw new IllegalStateException ("ACLUSer.isDomainAdmin() Property gu_user is not set"); 216 } 217 218 if (DebugFile.trace) 219 DebugFile.writeln("Connection.prepareStatement(SELECT NULL FROM " + DB.k_x_group_user + " x," + DB.k_domains + " d WHERE d." + DB.id_domain + "=" + String.valueOf(getInt(DB.id_domain)) + " AND x." + DB.gu_user + "='" + getString(DB.gu_user) + "'" + " AND x." + DB.gu_acl_group + "=d." + DB.gu_admins + ")"); 220 221 int iDomainId; 222 if (isNull(DB.id_domain)) 223 iDomainId = -1; 224 else 225 iDomainId = getInt(DB.id_domain); 226 227 oStmt = oConn.prepareStatement("SELECT NULL FROM " + DB.k_x_group_user + " x," + DB.k_domains + " d WHERE d." + DB.id_domain + "=?" + " AND x." + DB.gu_user + "=?" + " AND x." + DB.gu_acl_group + "=d." + DB.gu_admins, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 228 oStmt.setInt(1,iDomainId); 229 oStmt.setString(2,getStringNull(DB.gu_user,null)); 230 oRSet = oStmt.executeQuery(); 231 bAdmin = oRSet.next(); 232 oRSet.close(); 233 oStmt.close(); 234 235 if (!bAdmin) { 236 if (DebugFile.trace) 237 DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_owner + " FROM " + DB.k_domains + " WHERE " + DB.id_domain + "=" + String.valueOf(getInt(DB.id_domain)) + ")"); 238 239 oStmt = oConn.prepareStatement("SELECT " + DB.gu_owner + " FROM " + DB.k_domains + " WHERE " + DB.id_domain + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 240 oStmt.setInt(1,getInt(DB.id_domain)); 241 oRSet = oStmt.executeQuery(); 242 243 if (oRSet.next()) 244 if (null!=oRSet.getObject(1)) 245 bAdmin = oRSet.getString(1).equals(getString(DB.gu_user)); 246 else 247 bAdmin = false; 248 else 249 bAdmin = false; 250 251 oRSet.close(); 252 oStmt.close(); 253 } 254 255 if (DebugFile.trace) { 256 DebugFile.decIdent(); 257 DebugFile.writeln("End ACLUser.isDomainAdmin() : " + String.valueOf(bAdmin)); 258 } 259 260 return bAdmin; 261 } 263 265 275 public boolean store(JDCConnection oConn) throws SQLException { 276 boolean bRetVal; 277 Object oDomainId; 278 String NmWorkArea; 279 PreparedStatement oStmt; 280 ResultSet oRSet; 281 282 if (DebugFile.trace) { 283 DebugFile.writeln("Begin ACLUser.store([Connection])"); 284 DebugFile.incIdent(); 285 } 286 287 if (!AllVals.containsKey(DB.gu_user)) 288 put (DB.gu_user, Gadgets.generateUUID()); 289 290 if (!AllVals.containsKey(DB.dt_last_update)) 291 put (DB.dt_last_update, new java.sql.Timestamp (DBBind.getTime())); 292 293 if (!AllVals.containsKey(DB.len_quota)) 294 put (DB.len_quota, new BigDecimal (0d)); 295 296 if (!AllVals.containsKey(DB.max_quota)) 297 put (DB.max_quota, new BigDecimal (104857600d)); 298 299 if (AllVals.containsKey(DB.gu_workarea) && AllVals.containsKey(DB.id_domain)) { 300 if (!isNull(DB.gu_workarea)) { 301 302 if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.id_domain + "," + DB.nm_workarea + " FROM " + DB.k_workareas + " WHERE " + DB.gu_workarea + "='" + getString(DB.gu_workarea) + "')"); 303 304 oStmt = oConn.prepareStatement("SELECT " + DB.id_domain + "," + DB.nm_workarea + " FROM " + DB.k_workareas + " WHERE " + DB.gu_workarea + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 305 oStmt.setString(1, getString(DB.gu_workarea)); 306 oRSet = oStmt.executeQuery(); 307 if (oRSet.next()) { 308 oDomainId = oRSet.getObject(1); 309 NmWorkArea = oRSet.getString(2); 310 } 311 else { 312 oDomainId = null; 313 NmWorkArea = null; 314 } 315 oRSet.close(); 316 oStmt.close(); 317 318 if (null!=oDomainId) { 319 if (!oDomainId.toString().equals(get(DB.id_domain).toString())) 320 throw new SQLException ("ACLUSer.store() Integrity constraint violation: WorkArea " + NmWorkArea + " must belong to Domain " + oDomainId.toString() + " as User does but it belongs to " + oDomainId.toString(), "23000"); 321 } 323 } } 326 if (!Gadgets.checkEMail(getStringNull(DB.tx_main_email,"nobody@nodomain.com"))) { 327 if (DebugFile.trace) DebugFile.decIdent(); 328 throw new SQLException ("ACLUSer.store() Check constraint violation: e-mail address "+getString(DB.tx_main_email)+" does not have a valid syntax", "23000"); 329 } 330 331 if (!Gadgets.checkEMail(getStringNull(DB.tx_alt_email,"nobody@nodomain.com"))) { 332 if (DebugFile.trace) DebugFile.decIdent(); 333 throw new SQLException ("ACLUSer.store() Check constraint violation: e-mail address "+getString(DB.tx_alt_email)+" does not have a valid syntax", "23000"); 334 } 335 336 bRetVal = super.store(oConn); 337 338 if (DebugFile.trace) { 339 DebugFile.decIdent(); 340 DebugFile.writeln("End ACLUser.store() : " + String.valueOf(bRetVal)); 341 } 342 343 return bRetVal; 344 } 346 348 public boolean delete(JDCConnection oConn) throws SQLException { 349 try { 350 return ACLUser.delete(oConn, getString(DB.gu_user)); 351 } catch (IOException ioe) { 352 throw new SQLException ("IOException " + ioe.getMessage()); 353 } 354 } 356 358 364 public int clearACLGroups(JDCConnection oConn) throws SQLException { 365 366 if (DebugFile.trace) { 367 DebugFile.writeln("Begin ACLUser.clearACLGroups([Connection])"); 368 DebugFile.incIdent(); 369 } 370 371 int iRetVal; 372 373 Statement oStmt = oConn.createStatement(); 374 iRetVal = oStmt.executeUpdate("DELETE FROM " + DB.k_x_group_user + " WHERE " + DB.gu_user + "='" + getString(DB.gu_user) + "'"); 375 oStmt.close(); 376 377 if (DebugFile.trace) { 378 DebugFile.decIdent(); 379 DebugFile.writeln("End ACLGroup.clearACLGroups() : " + String.valueOf(iRetVal)); 380 } 381 382 return iRetVal; 383 } 385 387 394 395 public int removeFromACLGroup(JDCConnection oConn, String sIdGroup) throws SQLException { 396 397 if (DebugFile.trace) { 398 DebugFile.writeln("Begin ACLUser.removeFromACLGroup(Connection], " + sIdGroup + ")"); 399 DebugFile.incIdent(); 400 } 401 402 int iRetVal; 403 Statement oStmt = oConn.createStatement(); 404 405 if (DebugFile.trace) 406 DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_group_user + " WHERE " + DB.gu_user + "='" + getStringNull(DB.gu_user, "null") + "' AND " + DB.gu_acl_group + "='" + sIdGroup + "'"); 407 408 iRetVal = oStmt.executeUpdate("DELETE FROM " + DB.k_x_group_user + " WHERE " + DB.gu_user + "='" + getString(DB.gu_user) + "' AND " + DB.gu_acl_group + "='" + sIdGroup + "'"); 409 oStmt.close(); 410 411 if (DebugFile.trace) { 412 DebugFile.decIdent(); 413 DebugFile.writeln("End ACLUser.removeFromACLGroup() : " + String.valueOf(iRetVal)); 414 } 415 416 return iRetVal; 417 } 419 421 433 public String getMailRoot (JDCConnection oConn) throws SQLException { 434 PreparedStatement oStmt; 435 CallableStatement oCall; 436 ResultSet oRSet; 437 String sRetVal; 438 439 if (DebugFile.trace) { 440 DebugFile.writeln("Begin ACLUser.getMailRoot(Connection])"); 441 DebugFile.incIdent(); 442 } 443 444 switch (oConn.getDataBaseProduct()) { 445 446 case JDCConnection.DBMS_POSTGRESQL: 447 if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(SELECT k_sp_get_user_mailroot('"+getStringNull(DB.gu_user,"null")+"'))"); 448 oStmt = oConn.prepareStatement("SELECT k_sp_get_user_mailroot(?)"); 449 oStmt.setString(1, getString(DB.gu_user)); 450 oRSet = oStmt.executeQuery(); 451 if (oRSet.next()) 452 sRetVal = oRSet.getString(1); 453 else 454 sRetVal = null; 455 oRSet.close(); 456 oStmt.close(); 457 break; 458 default: 459 if (DebugFile.trace) DebugFile.writeln("Connection.prepareCall({ call k_sp_get_user_mailroot('"+getStringNull(DB.gu_user,"null")+"',?) }"); 460 oCall = oConn.prepareCall("{ call k_sp_get_user_mailroot(?,?) }"); 461 oCall.setString(1, getString(DB.gu_user)); 462 oCall.registerOutParameter(2, java.sql.Types.CHAR); 463 oCall.execute(); 464 sRetVal = oCall.getString(2); 465 oCall.close(); 466 break; 467 } 468 469 if (sRetVal==null) { 470 if (DebugFile.trace) DebugFile.writeln("user mail root not found creating new one..."); 471 ACLUser oMe = new ACLUser(); 472 if (oMe.load(oConn, new Object []{getString(DB.gu_user)})) { 473 if (!oMe.isNull(DB.gu_category)) { 474 ACLDomain oDom = new ACLDomain(oConn, oMe.getInt(DB.id_domain)); 475 476 Statement oInsr = oConn.createStatement(); 477 String sNewGUID = Gadgets.generateUUID(); 478 479 String sSQL = "INSERT INTO "+DB.k_categories+" ("+DB.gu_category+","+DB.gu_owner+","+DB.nm_category+","+DB.bo_active+","+DB.dt_modified+","+DB.nm_icon+","+DB.id_doc_status+","+DB.nm_icon2+") VALUES ('"+sNewGUID+"','"+oMe.getString(DB.gu_user)+"','"+oDom.getString(DB.nm_domain)+"_"+oMe.getString(DB.tx_nickname)+"_mail',1,NULL,'myemailc_16x16.gif',1,'myemailo_16x16.gif')"; 480 if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate("+sSQL+")"); 481 oInsr.executeUpdate(sSQL); 482 483 String [] aLabels = new String []{"en","es","fr","de","it","pt","ca","ja","cn","tw","fi","ru","pl","nl"}; 484 485 for (int l=0; l<aLabels.length; l++) 486 oInsr.executeUpdate("INSERT INTO "+DB.k_cat_labels+" ("+DB.gu_category+","+DB.id_language+","+DB.tr_category+","+DB.url_category+") VALUES ('"+sNewGUID+"','"+aLabels[l]+"','e-mail',NULL)"); 487 488 oInsr.executeUpdate("INSERT INTO "+DB.k_x_cat_user_acl+" ("+DB.gu_category+","+DB.gu_user+","+DB.acl_mask+") VALUES ('"+sNewGUID+"','"+oMe.getString(DB.gu_user)+"',2147483647)"); 489 490 if (!oMe.getString(DB.gu_user).equals(oDom.getString(DB.gu_owner))) 491 oInsr.executeUpdate("INSERT INTO "+DB.k_x_cat_user_acl+" ("+DB.gu_category+","+DB.gu_user+","+DB.acl_mask+") VALUES ('"+sNewGUID+"','"+oDom.getString(DB.gu_owner)+"',2147483647)"); 492 493 sSQL = "INSERT INTO "+DB.k_cat_tree+" ("+DB.gu_parent_cat+","+DB.gu_child_cat+") VALUES ('"+oMe.getString(DB.gu_category)+"','"+sNewGUID+"')"; 494 if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate("+sSQL+")"); 495 oInsr.executeUpdate(sSQL); 496 497 oInsr.close(); 498 sRetVal = sNewGUID; 499 } 500 else { 501 if (DebugFile.trace) DebugFile.writeln("user " + getString(DB.gu_user) + " has not home category"); 502 } 503 } 504 else { 505 if (DebugFile.trace) DebugFile.writeln("unable to load user " + getString(DB.gu_user)); 506 } 507 } 508 else 509 sRetVal = sRetVal.trim(); 510 511 if (DebugFile.trace) { 512 DebugFile.decIdent(); 513 DebugFile.writeln("End ACLUser.getMailRoot() : " + String.valueOf(sRetVal)); 514 } 515 516 return sRetVal; 517 } 519 521 535 536 public String getMailFolder (JDCConnection oConn, String sFolderName) 537 throws SQLException { 538 PreparedStatement oStmt; 539 CallableStatement oCall; 540 ResultSet oRSet; 541 String sRetVal; 542 543 if (DebugFile.trace) { 544 DebugFile.writeln("Begin ACLUser.getMailFolder([JDCConnection],"+sFolderName+")"); 545 DebugFile.incIdent(); 546 } 547 548 if (sFolderName==null) { 549 if (DebugFile.trace) DebugFile.decIdent(); 550 throw new NullPointerException ("ACLUser.getMailFolder() folder name cannot be null"); 551 } 552 if (sFolderName.length()==0) { 553 if (DebugFile.trace) DebugFile.decIdent(); 554 throw new NullPointerException ("ACLUser.getMailFolder() folder name cannot be an empty string"); 555 } 556 557 String sIcon1 = sFolderName.equalsIgnoreCase("inbox") ? "mailbox_16x16.gif" : "folderclosed_16x16.gif"; 558 String sIcon2 = sFolderName.equalsIgnoreCase("inbox") ? "mailbox_16x16.gif" : "folderopen_16x16.gif"; 559 560 switch (oConn.getDataBaseProduct()) { 561 562 case JDCConnection.DBMS_POSTGRESQL: 563 if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(SELECT k_sp_get_user_mailfolder('"+getStringNull(DB.gu_user,"null")+"','"+sFolderName+"')"); 564 565 oStmt = oConn.prepareStatement("SELECT k_sp_get_user_mailfolder(?,?)"); 566 oStmt.setString(1, getString(DB.gu_user)); 567 oStmt.setString(2, sFolderName); 568 oRSet = oStmt.executeQuery(); 569 if (oRSet.next()) 570 sRetVal = oRSet.getString(1); 571 else 572 sRetVal = null; 573 oRSet.close(); 574 oStmt.close(); 575 break; 576 default: 577 if (DebugFile.trace) DebugFile.writeln("Connection.prepareCall({ call k_sp_get_user_mailfolder('"+getStringNull(DB.gu_user,"null")+"','"+sFolderName+"',?)})"); 578 oCall = oConn.prepareCall("{ call k_sp_get_user_mailfolder(?,?,?) }"); 579 oCall.setString(1, getString(DB.gu_user)); 580 oCall.setString(2, sFolderName); 581 oCall.registerOutParameter(3, java.sql.Types.CHAR); 582 oCall.execute(); 583 sRetVal = oCall.getString(3); 584 oCall.close(); 585 break; 586 } 587 588 if (sRetVal==null) { 589 if (DebugFile.trace) DebugFile.writeln("Creating new mail folder " + sFolderName + " for user " + getStringNull(DB.gu_user,"null")); 590 ACLUser oMe = new ACLUser(); 591 if (oMe.load(oConn, new Object [] {getString(DB.gu_user)})) { 592 if (!oMe.isNull(DB.gu_category)) { 593 String sGuMailRoot = getMailRoot(oConn); 594 if (sGuMailRoot!=null) { 595 ACLDomain oDom = new ACLDomain(oConn, oMe.getInt(DB.id_domain)); 596 597 Statement oInsr = oConn.createStatement(); 598 String sNewGUID = Gadgets.generateUUID(); 599 600 String sSQL = "INSERT INTO "+DB.k_categories+" ("+DB.gu_category+","+DB.gu_owner+","+DB.nm_category+","+DB.bo_active+","+DB.dt_modified+","+DB.nm_icon+","+DB.id_doc_status+","+DB.nm_icon2+","+DB.len_size+") VALUES ('"+sNewGUID+"','"+oMe.getString(DB.gu_user)+"','"+oDom.getString(DB.nm_domain)+"_"+oMe.getString(DB.tx_nickname)+"_"+sFolderName+"',1,NULL,'"+sIcon1+"',1,'"+sIcon2+"',0)"; 601 602 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")"); 603 604 oInsr.executeUpdate(sSQL); 605 606 String [] aLabels = new String []{"en","es","fr","de","it","pt","ca","ja","cn","tw","fi","ru","pl","nl","xx"}; 607 608 for (int l=0; l<aLabels.length; l++) { 609 sSQL = "INSERT INTO "+DB.k_cat_labels+" ("+DB.gu_category+","+DB.id_language+","+DB.tr_category+","+DB.url_category+") VALUES ('"+sNewGUID+"','"+aLabels[l]+"','"+sFolderName.substring(0,1).toUpperCase()+sFolderName.substring(1).toLowerCase()+"',NULL)"; 610 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")"); 611 oInsr.executeUpdate(sSQL); 612 } 613 614 sSQL = "INSERT INTO "+DB.k_x_cat_user_acl+" ("+DB.gu_category+","+DB.gu_user+","+DB.acl_mask+") VALUES ('"+sNewGUID+"','"+oMe.getString(DB.gu_user)+"',2147483647)"; 615 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")"); 616 oInsr.executeUpdate(sSQL); 617 618 if (!oMe.getString(DB.gu_user).equals(oDom.getString(DB.gu_owner))) { 619 sSQL = "INSERT INTO "+DB.k_x_cat_user_acl+" ("+DB.gu_category+","+DB.gu_user+","+DB.acl_mask+") VALUES ('"+sNewGUID+"','"+oDom.getString(DB.gu_owner)+"',2147483647)"; 620 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")"); 621 oInsr.executeUpdate(sSQL); 622 } 623 624 sSQL = "INSERT INTO "+DB.k_cat_tree+" ("+DB.gu_parent_cat+","+DB.gu_child_cat+") VALUES ('"+sGuMailRoot+"','"+sNewGUID+"')"; 625 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(" + sSQL + ")"); 626 oInsr.executeUpdate(sSQL); 627 628 oInsr.close(); 629 630 Category oMailRoot = new Category(sGuMailRoot); 631 oMailRoot.expand(oConn); 632 sRetVal = sNewGUID; 633 } 634 } 635 } 636 else { 637 if (DebugFile.trace) DebugFile.writeln("user " + getStringNull(DB.gu_user,"null") + " does not exist"); 638 throw new SQLException ("User "+getStringNull(DB.gu_user,"null")+" not found", "02000", 0); 639 } 640 } 641 else 642 sRetVal = sRetVal.trim(); 643 644 if (DebugFile.trace) { 645 DebugFile.decIdent(); 646 DebugFile.writeln("End ACLUser.getMailFolder() : " + String.valueOf(sRetVal)); 647 } 648 649 return sRetVal; 650 } 652 654 663 public int getRolesForApplication(JDCConnection oConn, int iIdApp, String sGuWorkArea) 664 throws SQLException { 665 666 if (DebugFile.trace) { 667 DebugFile.writeln("Begin ACLUser.getRolesForApplication([JDCConnection],"+String.valueOf(iIdApp)+","+sGuWorkArea+")"); 668 DebugFile.incIdent(); 669 } 670 671 int iRolesBitMask = ACL.ROLE_NONE; 672 String sGuAdmins, sGuPowUsers, sGuUser, sGuGuest; 673 PreparedStatement oStmt = oConn.prepareStatement( 674 "SELECT "+DB.gu_admins+","+DB.gu_powusers+","+DB.gu_users+","+DB.gu_guests+ 675 " FROM "+DB.k_x_app_workarea+" WHERE "+DB.id_app+"=? AND "+DB.gu_workarea+"=?", 676 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 677 oStmt.setInt(1, iIdApp); 678 oStmt.setString(2, sGuWorkArea); 679 ResultSet oRSet = oStmt.executeQuery(); 680 boolean bFound = oRSet.next(); 681 if (bFound) { 682 sGuAdmins = oRSet.getString(1); 683 sGuPowUsers = oRSet.getString(2); 684 sGuUser = oRSet.getString(3); 685 sGuGuest = oRSet.getString(4); 686 } else { 687 sGuAdmins = sGuPowUsers = sGuUser = sGuGuest = null; 688 } 689 oRSet.close(); 690 oStmt.close(); 691 if (bFound) { 692 oStmt = oConn.prepareStatement( 693 "SELECT NULL FROM "+DB.k_x_group_user+" WHERE "+DB.gu_acl_group+"=? AND "+DB.gu_user+"='"+getString(DB.gu_user)+"'", 694 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 695 if (null!=sGuAdmins) { 696 oStmt.setString(1, sGuAdmins); 697 oRSet = oStmt.executeQuery(); 698 if (oRSet.next()) iRolesBitMask = ACL.ROLE_ADMIN; 699 oRSet.close(); 700 } 701 if (null!=sGuPowUsers) { 702 oStmt.setString(1, sGuPowUsers); 703 oRSet = oStmt.executeQuery(); 704 if (oRSet.next()) iRolesBitMask |= ACL.ROLE_POWERUSER; 705 oRSet.close(); 706 } 707 if (null!=sGuUser) { 708 oStmt.setString(1, sGuUser); 709 oRSet = oStmt.executeQuery(); 710 if (oRSet.next()) iRolesBitMask |= ACL.ROLE_USER; 711 oRSet.close(); 712 } 713 if (null!=sGuGuest) { 714 oStmt.setString(1, sGuGuest); 715 oRSet = oStmt.executeQuery(); 716 if (oRSet.next()) iRolesBitMask |= ACL.ROLE_GUEST; 717 oRSet.close(); 718 } 719 oStmt.close(); 720 } 722 if (DebugFile.trace) { 723 DebugFile.decIdent(); 724 DebugFile.writeln("End ACLUser.getRolesForApplication() : " + String.valueOf(iRolesBitMask)); 725 } 726 727 return iRolesBitMask; 728 } 730 732 741 public boolean isAdminForApplication(JDCConnection oConn, int iIdApp, String sGuWorkArea) 742 throws SQLException { 743 return ((getRolesForApplication(oConn, iIdApp, sGuWorkArea)&ACL.ROLE_ADMIN)!=0); 744 } 745 746 748 757 public boolean isPowerUserForApplication(JDCConnection oConn, int iIdApp, String sGuWorkArea) 758 throws SQLException { 759 return ((getRolesForApplication(oConn, iIdApp, sGuWorkArea)&ACL.ROLE_POWERUSER)!=0); 760 } 761 762 764 773 public boolean isUserForApplication(JDCConnection oConn, int iIdApp, String sGuWorkArea) 774 throws SQLException { 775 return ((getRolesForApplication(oConn, iIdApp, sGuWorkArea)&ACL.ROLE_USER)!=0); 776 } 777 778 780 789 public boolean isAdminForApplication(JDCConnection oConn, int iIdApp) 790 throws SQLException { 791 return ((getRolesForApplication(oConn, iIdApp, getString(DB.gu_workarea))&ACL.ROLE_ADMIN)!=0); 792 } 793 794 796 805 public boolean isPowerUserForApplication(JDCConnection oConn, int iIdApp) 806 throws SQLException { 807 return ((getRolesForApplication(oConn, iIdApp, getString(DB.gu_workarea))&ACL.ROLE_POWERUSER)!=0); 808 } 809 810 812 821 public boolean isUserForApplication(JDCConnection oConn, int iIdApp) 822 throws SQLException { 823 return ((getRolesForApplication(oConn, iIdApp, getString(DB.gu_workarea))&ACL.ROLE_USER)!=0); 824 } 825 826 828 837 public boolean isGuestForApplication(JDCConnection oConn, int iIdApp) 838 throws SQLException { 839 return ((getRolesForApplication(oConn, iIdApp, getString(DB.gu_workarea))&ACL.ROLE_GUEST)!=0); 840 } 841 842 844 847 855 public static String getIdFromEmail(JDCConnection oConn, String sUserEMail) throws SQLException { 856 String sRetVal; 857 PreparedStatement oStmt; 858 ResultSet oRSet; 859 860 switch (oConn.getDataBaseProduct()) { 861 862 case JDCConnection.DBMS_MYSQL: 863 case JDCConnection.DBMS_MSSQL: 864 case JDCConnection.DBMS_ORACLE: 865 sRetVal = DBPersist.getUIdFromName(oConn, null, sUserEMail, "k_get_user_from_email"); 866 break; 867 868 default: 869 if (DebugFile.trace) 870 DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.gu_user + " FROM " + DB.k_users + " WHERE " + DB.tx_main_email + "='" + sUserEMail + "')"); 871 872 oStmt = oConn.prepareStatement("SELECT " + DB.gu_user + " FROM " + DB.k_users + " WHERE " + DB.tx_main_email + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 873 oStmt.setString(1, sUserEMail); 874 oRSet = oStmt.executeQuery(); 875 if (oRSet.next()) 876 sRetVal = oRSet.getString(1); 877 else 878 sRetVal = null; 879 oRSet.close(); 880 oStmt.close(); 881 break; 882 883 } 885 return sRetVal; 886 } 888 890 897 898 public static String getEmailFromId(JDCConnection oConn, String sUserId) throws SQLException { 899 String sRetVal; 900 PreparedStatement oStmt; 901 ResultSet oRSet; 902 903 if (DebugFile.trace) 904 DebugFile.writeln("Connection.prepareStatement(SELECT " + DB.tx_main_email + " FROM " + DB.k_users + " WHERE " + DB.gu_user + "='" + sUserId + "')"); 905 906 oStmt = oConn.prepareStatement("SELECT " + DB.tx_main_email + " FROM " + DB.k_users + " WHERE " + DB.gu_user + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 907 oStmt.setString(1, sUserId); 908 oRSet = oStmt.executeQuery(); 909 if (oRSet.next()) 910 sRetVal = oRSet.getString(1); 911 else 912 sRetVal = null; 913 oRSet.close(); 914 oStmt.close(); 915 916 return sRetVal; 917 } 919 921 929 930 public static String getIdFromNick(Connection oConn, int iDomainId, String sUserNick) 931 throws SQLException { 932 String sRetVal; 933 PreparedStatement oStmt; 934 ResultSet oRSet; 935 936 oStmt = oConn.prepareStatement("SELECT " + DB.gu_user + " FROM " + DB.k_users + " WHERE " + DB.id_domain + "=? AND " + DB.tx_nickname + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 937 oStmt.setInt (1, iDomainId); 938 oStmt.setString(2, sUserNick); 939 oRSet = oStmt.executeQuery(); 940 if (oRSet.next()) 941 sRetVal = oRSet.getString(1); 942 else 943 sRetVal = null; 944 oRSet.close(); 945 oStmt.close(); 946 return sRetVal; 947 } 949 951 960 961 public static String getIdFromNick(JDCConnection oConn, int iDomainId, String sUserNick) 962 throws SQLException { 963 String sRetVal; 964 965 switch (oConn.getDataBaseProduct()) { 966 case JDCConnection.DBMS_MSSQL: 967 case JDCConnection.DBMS_ORACLE: 968 sRetVal = DBPersist.getUIdFromName(oConn, new Integer (iDomainId), sUserNick, "k_get_user_from_nick"); 969 break; 970 default: 971 sRetVal = getIdFromNick((Connection ) oConn, iDomainId, sUserNick); 972 } 973 return sRetVal; 974 } 976 978 986 987 public static boolean delete(JDCConnection oConn, String sUserGUID) throws SQLException ,IOException { 988 boolean bRetVal; 989 int iCats, iConts, iMsgs; 990 DBSubset oCats, oProds, oConts, oMsgs; 991 Statement oStmt; 992 PreparedStatement oPtmt; 993 ResultSet oRSet; 994 CallableStatement oCall; 995 996 if (DebugFile.trace) { 997 DebugFile.writeln("Begin ACLUser.delete([Connection], " + sUserGUID + ")"); 998 DebugFile.incIdent(); 999 } 1000 1001 1005 oPtmt = oConn.prepareStatement("SELECT "+DB.gu_user+" FROM "+DB.k_users+" WHERE "+DB.gu_user+"=?", 1006 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 1007 oPtmt.setString(1, sUserGUID); 1008 oRSet = oPtmt.executeQuery(); 1009 boolean bExists = oRSet.next(); 1010 oRSet.close(); 1011 oPtmt.close(); 1012 1013 if (!bExists) { 1014 if (DebugFile.trace) { 1015 DebugFile.writeln("user " + sUserGUID + " not found"); 1016 DebugFile.decIdent(); 1017 DebugFile.writeln("End ACLUser.delete() : false"); 1018 } 1019 return false; 1020 } 1021 1022 1025 if (DBBind.exists(oConn, DB.k_user_pwd, "U")) { 1026 oStmt = oConn.createStatement(); 1027 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_user_pwd + " WHERE " + DB.gu_user + "='" + sUserGUID + "')"); 1028 oStmt.executeUpdate("DELETE FROM " + DB.k_user_pwd + " WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1029 oStmt.close(); 1030 } 1031 1032 if (DBBind.exists(oConn, DB.k_user_mail, "U")) { 1033 oStmt = oConn.createStatement(); 1034 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_user_mail + " WHERE " + DB.gu_user + "='" + sUserGUID + "')"); 1035 oStmt.executeUpdate("DELETE FROM " + DB.k_user_mail + " WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1036 oStmt.close(); 1037 } 1038 1039 1040 if (DBBind.exists(oConn, DB.k_business_states, "U")) { 1041 oStmt = oConn.createStatement(); 1042 if (DebugFile.trace) 1043 DebugFile.writeln("UPDATE " + DB.k_business_states + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1044 oStmt.executeUpdate("UPDATE " + DB.k_business_states + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1045 oStmt.close(); 1046 } 1047 1048 1049 if (DBBind.exists(oConn, DB.k_pageset_answers, "U")) { 1050 oStmt = oConn.createStatement(); 1051 if (DebugFile.trace) 1052 DebugFile.writeln("UPDATE " + DB.k_pageset_answers + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1053 oStmt.executeUpdate("UPDATE " + DB.k_pageset_answers + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1054 oStmt.close(); 1055 } 1056 1057 1058 if (DBBind.exists(oConn, DB.k_evaluations, "U")) { 1059 oStmt = oConn.createStatement(); 1060 if (DebugFile.trace) 1061 DebugFile.writeln("UPDATE " + DB.k_evaluations + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1062 oStmt.executeUpdate("UPDATE " + DB.k_evaluations + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1063 oStmt.close(); 1064 } 1065 1066 1067 if (DBBind.exists(oConn, DB.k_absentisms, "U")) { 1068 oStmt = oConn.createStatement(); 1069 if (DebugFile.trace) 1070 DebugFile.writeln("UPDATE " + DB.k_absentisms + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1071 oStmt.executeUpdate("UPDATE " + DB.k_absentisms + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1072 oStmt.close(); 1073 } 1074 1075 1078 1081 1082 if (DBBind.exists(oConn, DB.k_inet_addrs, "U")) { 1083 oStmt = oConn.createStatement(); 1084 1085 if (DebugFile.trace) 1086 DebugFile.writeln("UPDATE " + DB.k_inet_addrs + " SET " + DB.gu_user + "=NULL WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1087 1088 oStmt.executeUpdate("UPDATE " + DB.k_inet_addrs + " SET " + DB.gu_user + "=NULL WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1089 1090 oStmt.close(); 1091 } 1092 1093 if (DBBind.exists(oConn, DB.k_x_portlet_user, "U")) { 1094 oStmt = oConn.createStatement(); 1095 1096 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_portlet_user + " WHERE " + DB.gu_user + "='" + sUserGUID + "')"); 1097 1098 oStmt.executeUpdate("DELETE FROM " + DB.k_x_portlet_user + " WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1099 1100 oStmt.close(); 1101 } 1102 1103 if (DBBind.exists(oConn, DB.k_images, "U")) { 1104 1105 oStmt = oConn.createStatement(); 1106 1107 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_images + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "')"); 1108 1109 oStmt.executeUpdate("UPDATE " + DB.k_images + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1110 1111 oStmt.close(); 1112 } 1113 1114 if (DBBind.exists(oConn, DB.k_bugs_lookup, "U")) { 1115 1116 oStmt = oConn.createStatement(); 1117 1118 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_bugs + " SET " + DB.nm_assigned + "=NULL WHERE " + DB.nm_assigned + "='" + sUserGUID + "')"); 1119 1120 oStmt.executeUpdate("UPDATE " + DB.k_bugs + " SET " + DB.nm_assigned + "=NULL WHERE " + DB.nm_assigned + "='" + sUserGUID + "'"); 1121 1122 oStmt.close(); 1123 1124 oStmt = oConn.createStatement(); 1125 1126 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_bugs_lookup + " WHERE " + DB.vl_lookup + "='" + sUserGUID + "')"); 1127 1128 oStmt.executeUpdate("DELETE FROM " + DB.k_bugs_lookup + " WHERE " + DB.vl_lookup + "='" + sUserGUID + "'"); 1129 1130 oStmt.close(); 1131 } 1132 1133 if (DBBind.exists(oConn, DB.k_x_duty_resource, "U")) { 1134 oStmt = oConn.createStatement(); 1135 1136 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_x_duty_resource + " WHERE " + DB.nm_resource + "='" + sUserGUID + "')"); 1137 1138 oStmt.executeUpdate("DELETE FROM " + DB.k_x_duty_resource + " WHERE " + DB.nm_resource + "='" + sUserGUID + "'"); 1139 1140 oStmt.close(); 1141 1142 oStmt = oConn.createStatement(); 1143 1144 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_duties_lookup + " WHERE " + DB.vl_lookup + "='" + sUserGUID + "')"); 1145 1146 oStmt.executeUpdate("DELETE FROM " + DB.k_duties_lookup + " WHERE " + DB.vl_lookup + "='" + sUserGUID + "'"); 1147 1148 oStmt.close(); 1149 } 1150 1151 1154 1157 if (DBBind.exists(oConn, DB.k_newsgroup_subscriptions, "U")) { 1158 oStmt = oConn.createStatement(); 1159 1160 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_newsgroup_subscriptions + " WHERE " + DB.gu_user + "='" + sUserGUID + "')"); 1161 1162 oStmt.executeUpdate("DELETE FROM " + DB.k_newsgroup_subscriptions + " WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1163 1164 oStmt.close(); 1165 } 1166 1167 1170 if (DBBind.exists(oConn, DB.k_newsmsgs, "U")) { 1171 oStmt = oConn.createStatement(); 1172 1173 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_newsmsgs + " SET " + DB.gu_validator + "=NULL WHERE " + DB.gu_validator + "='" + sUserGUID + "'"); 1175 1176 oStmt.executeUpdate("UPDATE " + DB.k_newsmsgs + " SET " + DB.gu_validator + "=NULL WHERE " + DB.gu_validator + "='" + sUserGUID + "'"); 1177 1178 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_newsmsgs + " WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.gu_product + " IS NULL"); 1180 1181 oStmt.executeUpdate("DELETE FROM " + DB.k_newsmsgs + " WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.gu_product + " IS NULL"); 1182 1183 oStmt.close(); 1184 1185 oMsgs = new DBSubset(DB.k_newsmsgs, DB.gu_msg, DB.gu_writer + "='" + sUserGUID + "'", 100); 1187 1188 iMsgs = oMsgs.load(oConn); 1189 1190 for (int m=0; m<iMsgs; m++) 1191 com.knowgate.forums.NewsMessage.delete(oConn, oMsgs.getString(0,m)); 1192 1193 oMsgs = null; 1194 } 1196 if (DBBind.exists(oConn, DB.k_member_address, "U")) { 1197 oStmt = oConn.createStatement(); 1198 1199 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_member_address + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "')"); 1200 1201 oStmt.executeUpdate("UPDATE " + DB.k_member_address + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1202 1203 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_member_address + " SET " + DB.gu_sales_man + "=NULL WHERE " + DB.gu_sales_man + "='" + sUserGUID + "')"); 1204 1205 oStmt.executeUpdate("UPDATE " + DB.k_member_address + " SET " + DB.gu_sales_man + "=NULL WHERE " + DB.gu_sales_man + "='" + sUserGUID + "'"); 1206 1207 oStmt.close(); 1208 } 1209 1210 if (DBBind.exists(oConn, DB.k_companies_recent, "U")) { 1211 oStmt = oConn.createStatement(); 1212 1213 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_companies_recent + " WHERE " + DB.gu_user + "='" + sUserGUID + "')"); 1214 1215 oStmt.executeUpdate("DELETE FROM " + DB.k_companies_recent + " WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1216 1217 oStmt.close(); 1218 } 1219 1220 if (DBBind.exists(oConn, DB.k_companies, "U")) { 1221 oStmt = oConn.createStatement(); 1222 1223 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_companies + " SET " + DB.gu_sales_man + "=NULL WHERE " + DB.gu_sales_man + "='" + sUserGUID + "')"); 1224 1225 oStmt.executeUpdate("UPDATE " + DB.k_companies + " SET " + DB.gu_sales_man + "=NULL WHERE " + DB.gu_sales_man + "='" + sUserGUID + "'"); 1226 1227 oStmt.close(); 1228 } 1229 1230 if (DBBind.exists(oConn, DB.k_contacts_recent, "U")) { 1231 oStmt = oConn.createStatement(); 1232 1233 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_contacts_recent + " WHERE " + DB.gu_user + "='" + sUserGUID + "')"); 1234 1235 oStmt.executeUpdate("DELETE FROM " + DB.k_contacts_recent + " WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1236 1237 oStmt.close(); 1238 } 1239 1240 if (DBBind.exists(oConn, DB.k_contacts, "U")) { 1241 oConts = new DBSubset(DB.k_contacts, DB.gu_contact, DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "<>0", 100); 1242 iConts = oConts.load(oConn); 1243 1244 for (int t=0; t<iConts; t++) 1245 com.knowgate.crm.Contact.delete(oConn, oConts.getString(0,t)); 1246 1247 oConts = null; 1248 1249 oStmt = oConn.createStatement(); 1250 1251 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_contacts + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "=0)"); 1252 1253 oStmt.executeUpdate("UPDATE " + DB.k_contacts + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "=0"); 1254 1255 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_contact_notes + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "')"); 1256 1257 oStmt.executeUpdate("UPDATE " + DB.k_contact_notes + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1258 1259 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_contact_attachs + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "')"); 1260 1261 oStmt.executeUpdate("UPDATE " + DB.k_contact_attachs + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "'"); 1262 1263 oStmt.close(); 1264 } 1265 1266 if (DBBind.exists(oConn, DB.k_oportunities, "U")) { 1267 oStmt = oConn.createStatement(); 1268 1269 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(DELETE FROM " + DB.k_oportunities + " WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "<>0)"); 1270 1271 oStmt.executeUpdate("DELETE FROM " + DB.k_oportunities + " WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "<>0"); 1272 1273 if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate(UPDATE " + DB.k_oportunities + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "=0)"); 1274 1275 oStmt.executeUpdate("UPDATE " + DB.k_oportunities + " SET " + DB.gu_writer + "=NULL WHERE " + DB.gu_writer + "='" + sUserGUID + "' AND " + DB.bo_private + "=0"); 1276 1277 oStmt.close(); 1278 } 1279 1280 if (DBBind.exists(oConn, DB.k_sales_men, "U")) { 1281 if (DebugFile.trace) DebugFile.writeln("Connection.prepareCall({ call k_sp_del_sales_man ('" + sUserGUID + "') })"); 1282 1283 oCall = oConn.prepareCall("{call k_sp_del_sales_man ('" + sUserGUID + "')}"); 1284 bRetVal = oCall.execute(); 1285 oCall.close(); 1286 } 1287 1288 if (DBBind.exists(oConn, DB.k_products, "U")) { 1289 oProds = new DBSubset(DB.k_products, DB.gu_product, DB.gu_owner + "='" + sUserGUID + "'", 100); 1290 int iProds = oProds.load(oConn); 1291 1292 for (int p=0; p<iProds; p++) 1293 new com.knowgate.hipergate.Product(oConn, oProds.getString(0, p)).delete(oConn); 1294 oProds = null; 1295 } 1297 if (DBBind.exists(oConn, DB.k_categories, "U")) { 1299 String sGuRootCat = null; 1300 oStmt = oConn.createStatement(); 1301 ResultSet oRCat = oStmt.executeQuery("SELECT " + DB.gu_category + " FROM " + DB.k_users + " WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1302 if (oRCat.next()) 1303 sGuRootCat = oRCat.getString(1); 1304 oRCat.close(); 1305 oStmt.close(); 1306 if (sGuRootCat!=null) { 1307 oStmt = oConn.createStatement(); 1308 oStmt.executeUpdate("UPDATE " + DB.k_users + " SET " + DB.gu_category + "=NULL WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1309 oStmt.close(); 1310 Category.delete(oConn, sGuRootCat); 1311 } 1312 1313 oCats = new DBSubset(DB.k_categories, DB.gu_category, DB.gu_owner + "=?", 10); 1314 iCats = oCats.load(oConn, new Object []{sUserGUID}); 1315 1316 for (int r=0; r<iCats; r++) 1317 Category.delete(oConn, oCats.getString(0,r)); 1318 1319 oCats = null; 1320 } 1322 if (DBBind.exists(oConn, DB.k_phone_calls, "U")) { 1323 oStmt = oConn.createStatement(); 1324 try { oStmt.setQueryTimeout(30); } catch (SQLException sqle) {} 1325 if (DebugFile.trace) DebugFile.writeln("Statement.execute(DELETE FROM " + DB.k_phone_calls + " WHERE " + DB.gu_user + "='" + sUserGUID + "' OR " + DB.gu_writer + "='" + sUserGUID + "')"); 1326 oStmt.executeUpdate("DELETE FROM " + DB.k_phone_calls + " WHERE " + DB.gu_user + "='" + sUserGUID + "' OR " + DB.gu_writer + "='" + sUserGUID + "'"); 1327 oStmt.close(); 1328 } 1330 if (DBBind.exists(oConn, DB.k_to_do, "U")) { 1331 oStmt = oConn.createStatement(); 1332 try { oStmt.setQueryTimeout(30); } catch (SQLException sqle) {} 1333 if (DebugFile.trace) DebugFile.writeln("Statement.execute(DELETE FROM " + DB.k_to_do + " WHERE " + DB.gu_user + "='" + sUserGUID + "')"); 1334 oStmt.executeUpdate("DELETE FROM " + DB.k_to_do + " WHERE " + DB.gu_user + "='" + sUserGUID + "'"); 1335 oStmt.close(); 1336 } 1338 if (DebugFile.trace) DebugFile.writeln("Connection.prepareCall({ call k_sp_del_user ('" + sUserGUID + "') })"); 1339 1340 oCall = oConn.prepareCall("{call k_sp_del_user ('" + sUserGUID + "')}"); 1341 bRetVal = oCall.execute(); 1342 oCall.close(); 1343 1344 if (DebugFile.trace) { 1345 DebugFile.decIdent(); 1346 DebugFile.writeln("End ACLUser.delete() : " + String.valueOf(bRetVal)); 1347 } 1348 1349 return bRetVal; 1350 } 1352 1354 1365 public static String create(JDCConnection oConn, Object [] Values) 1366 throws SQLException ,ClassCastException ,NullPointerException { 1367 1368 if (DebugFile.trace) { 1369 DebugFile.writeln("Begin ACLUser.create([Connection])"); 1370 DebugFile.incIdent(); 1371 } 1372 1373 ACLUser oUsr = new ACLUser(); 1374 1375 if (null==Values[0]) { 1376 if (DebugFile.trace) DebugFile.decIdent(); 1377 throw new NullPointerException ("ACLUSer.create() a domain identifier is required"); 1378 } 1379 if (Values[0].getClass().equals(Integer.TYPE)) { 1380 if (DebugFile.trace) DebugFile.decIdent(); 1381 throw new ClassCastException ("ACLUSer.create() the domain identifier must be an object of type Integer"); 1382 } 1383 1384 oUsr.put(DB.id_domain, Values[0]); 1385 oUsr.put(DB.tx_nickname, Values[1]); 1386 oUsr.put(DB.tx_pwd, Values[2]); 1387 oUsr.put(DB.bo_active, Values[3]); 1388 oUsr.put(DB.bo_searchable, Values[4]); 1389 oUsr.put(DB.bo_change_pwd, Values[5]); 1390 oUsr.put(DB.tx_main_email, Values[6]); 1391 oUsr.put(DB.tx_alt_email, Values[7]); 1392 oUsr.put(DB.nm_user, Values[8]); 1393 oUsr.put(DB.tx_surname1, Values[9]); 1394 if (Values.length>10) 1395 if (null!=Values[10]) oUsr.put(DB.tx_surname2, Values[10]); 1396 if (Values.length>11) 1397 if (null!=Values[11]) oUsr.put(DB.tx_challenge, Values[11]); 1398 if (Values.length>12) 1399 if (null!=Values[12]) oUsr.put(DB.tx_reply, Values[12]); 1400 if (Values.length>13) 1401 if (null!=Values[13]) oUsr.put(DB.nm_company, Values[13]); 1402 if (Values.length>14) 1403 if (null!=Values[14]) oUsr.put(DB.de_title, Values[14]); 1404 if (Values.length>15) 1405 if (null!=Values[15]) oUsr.put(DB.gu_workarea, Values[15]); 1406 if (Values.length>16) 1407 if (null!=Values[16]) oUsr.put(DB.tx_comments, Values[16]); 1408 1409 oUsr.store(oConn); 1410 1411 String sRetVal = oUsr.getString(DB.gu_user); 1412 1413 if (oConn.exists(DB.k_mime_msgs, "U")) { 1414 oUsr.getMailFolder(oConn, "inbox"); 1415 oUsr.getMailFolder(oConn, "outbox"); 1416 oUsr.getMailFolder(oConn, "drafts"); 1417 oUsr.getMailFolder(oConn, "deleted"); 1418 oUsr.getMailFolder(oConn, "sent"); 1419 oUsr.getMailFolder(oConn, "spam"); 1420 } 1421 1422 if (DebugFile.trace) { 1423 DebugFile.decIdent(); 1424 DebugFile.writeln("End ACLUser.create() : " + sRetVal); 1425 } 1426 return sRetVal; 1427 } 1429 1432 public static final short ClassId = 2; 1433 1434 1437 private DBSubset oAddresses; 1438 private DBSubset oGroups; 1439} 1440 | Popular Tags |