Refactoring

- organize imports
- improve indentation
This commit is contained in:
Carlos Ruiz 2008-10-10 03:55:11 +00:00
parent 02ef1da08c
commit 67e4671e36
1 changed files with 255 additions and 246 deletions

View File

@ -17,11 +17,20 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.process; package org.compiere.process;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.logging.*; import java.sql.ResultSet;
import org.compiere.model.*; import java.sql.SQLException;
import org.compiere.util.*; import java.sql.Timestamp;
import java.util.logging.Level;
import org.compiere.model.MBPartner;
import org.compiere.model.MBPartnerLocation;
import org.compiere.model.MContactInterest;
import org.compiere.model.MLocation;
import org.compiere.model.MUser;
import org.compiere.model.X_I_BPartner;
import org.compiere.util.DB;
/** /**
* Import BPartners from I_BPartner * Import BPartners from I_BPartner
@ -61,7 +70,7 @@ public class ImportBPartner extends SvrProcess
/** /**
* Perrform process. * Perform process.
* @return Message * @return Message
* @throws Exception * @throws Exception
*/ */
@ -77,47 +86,47 @@ public class ImportBPartner extends SvrProcess
if (m_deleteOldImported) if (m_deleteOldImported)
{ {
sql = new StringBuffer ("DELETE I_BPartner " sql = new StringBuffer ("DELETE I_BPartner "
+ "WHERE I_IsImported='Y'").append(clientCheck); + "WHERE I_IsImported='Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Delete Old Impored =" + no); log.fine("Delete Old Impored =" + no);
} }
// Set Client, Org, IsActive, Created/Updated // Set Client, Org, IsActive, Created/Updated
sql = new StringBuffer ("UPDATE I_BPartner " sql = new StringBuffer ("UPDATE I_BPartner "
+ "SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append(")," + "SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),"
+ " AD_Org_ID = COALESCE (AD_Org_ID, 0)," + " AD_Org_ID = COALESCE (AD_Org_ID, 0),"
+ " IsActive = COALESCE (IsActive, 'Y')," + " IsActive = COALESCE (IsActive, 'Y'),"
+ " Created = COALESCE (Created, SysDate)," + " Created = COALESCE (Created, SysDate),"
+ " CreatedBy = COALESCE (CreatedBy, 0)," + " CreatedBy = COALESCE (CreatedBy, 0),"
+ " Updated = COALESCE (Updated, SysDate)," + " Updated = COALESCE (Updated, SysDate),"
+ " UpdatedBy = COALESCE (UpdatedBy, 0)," + " UpdatedBy = COALESCE (UpdatedBy, 0),"
+ " I_ErrorMsg = ' '," + " I_ErrorMsg = ' ',"
+ " I_IsImported = 'N' " + " I_IsImported = 'N' "
+ "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Reset=" + no); log.fine("Reset=" + no);
// Set BP_Group // Set BP_Group
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET GroupValue=(SELECT MAX(Value) FROM C_BP_Group g WHERE g.IsDefault='Y'" + "SET GroupValue=(SELECT MAX(Value) FROM C_BP_Group g WHERE g.IsDefault='Y'"
+ " AND g.AD_Client_ID=i.AD_Client_ID) "); + " AND g.AD_Client_ID=i.AD_Client_ID) ");
sql.append("WHERE GroupValue IS NULL AND C_BP_Group_ID IS NULL" sql.append("WHERE GroupValue IS NULL AND C_BP_Group_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Group Default=" + no); log.fine("Set Group Default=" + no);
// //
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET C_BP_Group_ID=(SELECT C_BP_Group_ID FROM C_BP_Group g" + "SET C_BP_Group_ID=(SELECT C_BP_Group_ID FROM C_BP_Group g"
+ " WHERE i.GroupValue=g.Value AND g.AD_Client_ID=i.AD_Client_ID) " + " WHERE i.GroupValue=g.Value AND g.AD_Client_ID=i.AD_Client_ID) "
+ "WHERE C_BP_Group_ID IS NULL" + "WHERE C_BP_Group_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Group=" + no); log.fine("Set Group=" + no);
// //
sql = new StringBuffer ("UPDATE I_BPartner " sql = new StringBuffer ("UPDATE I_BPartner "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Group, ' " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Group, ' "
+ "WHERE C_BP_Group_ID IS NULL" + "WHERE C_BP_Group_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid Group=" + no); log.config("Invalid Group=" + no);
@ -130,124 +139,124 @@ public class ImportBPartner extends SvrProcess
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Country Default=" + no); log.fine("Set Country Default=" + no);
**/ **/
// //
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET C_Country_ID=(SELECT C_Country_ID FROM C_Country c" + "SET C_Country_ID=(SELECT C_Country_ID FROM C_Country c"
+ " WHERE i.CountryCode=c.CountryCode AND c.AD_Client_ID IN (0, i.AD_Client_ID)) " + " WHERE i.CountryCode=c.CountryCode AND c.AD_Client_ID IN (0, i.AD_Client_ID)) "
+ "WHERE C_Country_ID IS NULL" + "WHERE C_Country_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Country=" + no); log.fine("Set Country=" + no);
// //
sql = new StringBuffer ("UPDATE I_BPartner " sql = new StringBuffer ("UPDATE I_BPartner "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Country, ' " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Country, ' "
+ "WHERE C_Country_ID IS NULL AND (City IS NOT NULL OR Address1 IS NOT NULL)" + "WHERE C_Country_ID IS NULL AND (City IS NOT NULL OR Address1 IS NOT NULL)"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid Country=" + no); log.config("Invalid Country=" + no);
// Set Region // Set Region
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "Set RegionName=(SELECT MAX(Name) FROM C_Region r" + "Set RegionName=(SELECT MAX(Name) FROM C_Region r"
+ " WHERE r.IsDefault='Y' AND r.C_Country_ID=i.C_Country_ID" + " WHERE r.IsDefault='Y' AND r.C_Country_ID=i.C_Country_ID"
+ " AND r.AD_Client_ID IN (0, i.AD_Client_ID)) " ); + " AND r.AD_Client_ID IN (0, i.AD_Client_ID)) " );
sql.append("WHERE RegionName IS NULL AND C_Region_ID IS NULL" sql.append("WHERE RegionName IS NULL AND C_Region_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Region Default=" + no); log.fine("Set Region Default=" + no);
// //
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "Set C_Region_ID=(SELECT C_Region_ID FROM C_Region r" + "Set C_Region_ID=(SELECT C_Region_ID FROM C_Region r"
+ " WHERE r.Name=i.RegionName AND r.C_Country_ID=i.C_Country_ID" + " WHERE r.Name=i.RegionName AND r.C_Country_ID=i.C_Country_ID"
+ " AND r.AD_Client_ID IN (0, i.AD_Client_ID)) " + " AND r.AD_Client_ID IN (0, i.AD_Client_ID)) "
+ "WHERE C_Region_ID IS NULL" + "WHERE C_Region_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Region=" + no); log.fine("Set Region=" + no);
// //
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Region, ' " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Region, ' "
+ "WHERE C_Region_ID IS NULL " + "WHERE C_Region_ID IS NULL "
+ " AND EXISTS (SELECT * FROM C_Country c" + " AND EXISTS (SELECT * FROM C_Country c"
+ " WHERE c.C_Country_ID=i.C_Country_ID AND c.HasRegion='Y')" + " WHERE c.C_Country_ID=i.C_Country_ID AND c.HasRegion='Y')"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid Region=" + no); log.config("Invalid Region=" + no);
// Set Greeting // Set Greeting
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET C_Greeting_ID=(SELECT C_Greeting_ID FROM C_Greeting g" + "SET C_Greeting_ID=(SELECT C_Greeting_ID FROM C_Greeting g"
+ " WHERE i.BPContactGreeting=g.Name AND g.AD_Client_ID IN (0, i.AD_Client_ID)) " + " WHERE i.BPContactGreeting=g.Name AND g.AD_Client_ID IN (0, i.AD_Client_ID)) "
+ "WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL" + "WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Greeting=" + no); log.fine("Set Greeting=" + no);
// //
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Greeting, ' " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Greeting, ' "
+ "WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL" + "WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Invalid Greeting=" + no); log.config("Invalid Greeting=" + no);
// Existing User ? // Existing User ?
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET (C_BPartner_ID,AD_User_ID)=" + "SET (C_BPartner_ID,AD_User_ID)="
+ "(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u " + "(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u "
+ "WHERE i.EMail=u.EMail AND u.AD_Client_ID=i.AD_Client_ID) " + "WHERE i.EMail=u.EMail AND u.AD_Client_ID=i.AD_Client_ID) "
+ "WHERE i.EMail IS NOT NULL AND I_IsImported='N'").append(clientCheck); + "WHERE i.EMail IS NOT NULL AND I_IsImported='N'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Found EMail User=" + no); log.fine("Found EMail User=" + no);
// Existing BPartner ? Match Value // Existing BPartner ? Match Value
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner p" + "SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner p"
+ " WHERE i.Value=p.Value AND p.AD_Client_ID=i.AD_Client_ID) " + " WHERE i.Value=p.Value AND p.AD_Client_ID=i.AD_Client_ID) "
+ "WHERE C_BPartner_ID IS NULL AND Value IS NOT NULL" + "WHERE C_BPartner_ID IS NULL AND Value IS NOT NULL"
+ " AND I_IsImported='N'").append(clientCheck); + " AND I_IsImported='N'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Found BPartner=" + no); log.fine("Found BPartner=" + no);
// Existing Contact ? Match Name // Existing Contact ? Match Name
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET AD_User_ID=(SELECT AD_User_ID FROM AD_User c" + "SET AD_User_ID=(SELECT AD_User_ID FROM AD_User c"
+ " WHERE i.ContactName=c.Name AND i.C_BPartner_ID=c.C_BPartner_ID AND c.AD_Client_ID=i.AD_Client_ID) " + " WHERE i.ContactName=c.Name AND i.C_BPartner_ID=c.C_BPartner_ID AND c.AD_Client_ID=i.AD_Client_ID) "
+ "WHERE C_BPartner_ID IS NOT NULL AND AD_User_ID IS NULL AND ContactName IS NOT NULL" + "WHERE C_BPartner_ID IS NOT NULL AND AD_User_ID IS NULL AND ContactName IS NOT NULL"
+ " AND I_IsImported='N'").append(clientCheck); + " AND I_IsImported='N'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Found Contact=" + no); log.fine("Found Contact=" + no);
// Existing Location ? Exact Match // Existing Location ? Exact Match
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET C_BPartner_Location_ID=(SELECT C_BPartner_Location_ID" + "SET C_BPartner_Location_ID=(SELECT C_BPartner_Location_ID"
+ " FROM C_BPartner_Location bpl INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)" + " FROM C_BPartner_Location bpl INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)"
+ " WHERE i.C_BPartner_ID=bpl.C_BPartner_ID AND bpl.AD_Client_ID=i.AD_Client_ID" + " WHERE i.C_BPartner_ID=bpl.C_BPartner_ID AND bpl.AD_Client_ID=i.AD_Client_ID"
+ " AND DUMP(i.Address1)=DUMP(l.Address1) AND DUMP(i.Address2)=DUMP(l.Address2)" + " AND DUMP(i.Address1)=DUMP(l.Address1) AND DUMP(i.Address2)=DUMP(l.Address2)"
+ " AND DUMP(i.City)=DUMP(l.City) AND DUMP(i.Postal)=DUMP(l.Postal) AND DUMP(i.Postal_Add)=DUMP(l.Postal_Add)" + " AND DUMP(i.City)=DUMP(l.City) AND DUMP(i.Postal)=DUMP(l.Postal) AND DUMP(i.Postal_Add)=DUMP(l.Postal_Add)"
+ " AND i.C_Region_ID=l.C_Region_ID AND i.C_Country_ID=l.C_Country_ID) " + " AND i.C_Region_ID=l.C_Region_ID AND i.C_Country_ID=l.C_Country_ID) "
+ "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL" + "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL"
+ " AND I_IsImported='N'").append(clientCheck); + " AND I_IsImported='N'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Found Location=" + no); log.fine("Found Location=" + no);
// Interest Area // Interest Area
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET R_InterestArea_ID=(SELECT R_InterestArea_ID FROM R_InterestArea ia " + "SET R_InterestArea_ID=(SELECT R_InterestArea_ID FROM R_InterestArea ia "
+ "WHERE i.InterestAreaName=ia.Name AND ia.AD_Client_ID=i.AD_Client_ID) " + "WHERE i.InterestAreaName=ia.Name AND ia.AD_Client_ID=i.AD_Client_ID) "
+ "WHERE R_InterestArea_ID IS NULL AND InterestAreaName IS NOT NULL" + "WHERE R_InterestArea_ID IS NULL AND InterestAreaName IS NOT NULL"
+ " AND I_IsImported='N'").append(clientCheck); + " AND I_IsImported='N'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Interest Area=" + no); log.fine("Set Interest Area=" + no);
// Value is mandatory error // Value is mandatory error
sql = new StringBuffer ("UPDATE I_BPartner " sql = new StringBuffer ("UPDATE I_BPartner "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Value is mandatory, ' " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Value is mandatory, ' "
+ "WHERE Value IS NULL " + "WHERE Value IS NULL "
+ " AND I_IsImported<>'Y'").append(clientCheck); + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.config("Value is mandatory=" + no); log.config("Value is mandatory=" + no);
commit(); commit();
// ------------------------------------------------------------------- // -------------------------------------------------------------------
int noInsert = 0; int noInsert = 0;
@ -255,7 +264,7 @@ public class ImportBPartner extends SvrProcess
// Go through Records // Go through Records
sql = new StringBuffer ("SELECT * FROM I_BPartner " sql = new StringBuffer ("SELECT * FROM I_BPartner "
+ "WHERE I_IsImported='N'").append(clientCheck); + "WHERE I_IsImported='N'").append(clientCheck);
// gody: 20070113 - Order so the same values are consecutive. // gody: 20070113 - Order so the same values are consecutive.
sql.append(" ORDER BY Value, I_BPartner_ID"); sql.append(" ORDER BY Value, I_BPartner_ID");
try try
@ -269,7 +278,7 @@ public class ImportBPartner extends SvrProcess
String Old_BPValue = "" ; String Old_BPValue = "" ;
MBPartner bp = null; MBPartner bp = null;
MBPartnerLocation bpl = null; MBPartnerLocation bpl = null;
while (rs.next()) while (rs.next())
{ {
// Remember Value - only first occurance of the value is BP // Remember Value - only first occurance of the value is BP
@ -277,145 +286,145 @@ public class ImportBPartner extends SvrProcess
X_I_BPartner impBP = new X_I_BPartner (getCtx(), rs, get_TrxName()); X_I_BPartner impBP = new X_I_BPartner (getCtx(), rs, get_TrxName());
log.fine("I_BPartner_ID=" + impBP.getI_BPartner_ID() log.fine("I_BPartner_ID=" + impBP.getI_BPartner_ID()
+ ", C_BPartner_ID=" + impBP.getC_BPartner_ID() + ", C_BPartner_ID=" + impBP.getC_BPartner_ID()
+ ", C_BPartner_Location_ID=" + impBP.getC_BPartner_Location_ID() + ", C_BPartner_Location_ID=" + impBP.getC_BPartner_Location_ID()
+ ", AD_User_ID=" + impBP.getAD_User_ID()); + ", AD_User_ID=" + impBP.getAD_User_ID());
if ( ! New_BPValue.equals(Old_BPValue)) { if ( ! New_BPValue.equals(Old_BPValue)) {
// **** Create/Update BPartner **** // **** Create/Update BPartner ****
bp = null; bp = null;
if (impBP.getC_BPartner_ID() == 0) // Insert new BPartner if (impBP.getC_BPartner_ID() == 0) // Insert new BPartner
{
bp = new MBPartner(impBP);
if (bp.save())
{ {
impBP.setC_BPartner_ID(bp.getC_BPartner_ID()); bp = new MBPartner(impBP);
log.finest("Insert BPartner - " + bp.getC_BPartner_ID()); if (bp.save())
noInsert++; {
} impBP.setC_BPartner_ID(bp.getC_BPartner_ID());
else log.finest("Insert BPartner - " + bp.getC_BPartner_ID());
{ noInsert++;
sql = new StringBuffer ("UPDATE I_BPartner i " }
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") else
{
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.append("'Cannot Insert BPartner, ' ") .append("'Cannot Insert BPartner, ' ")
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
DB.executeUpdate(sql.toString(), get_TrxName()); DB.executeUpdate(sql.toString(), get_TrxName());
continue; continue;
}
} }
} else // Update existing BPartner
else // Update existing BPartner
{
bp = new MBPartner(getCtx(), impBP.getC_BPartner_ID(), get_TrxName());
// if (impBP.getValue() != null) // not to overwite
// bp.setValue(impBP.getValue());
if (impBP.getName() != null)
{ {
bp.setName(impBP.getName()); bp = new MBPartner(getCtx(), impBP.getC_BPartner_ID(), get_TrxName());
bp.setName2(impBP.getName2()); // if (impBP.getValue() != null) // not to overwite
} // bp.setValue(impBP.getValue());
if (impBP.getDUNS() != null) if (impBP.getName() != null)
bp.setDUNS(impBP.getDUNS()); {
if (impBP.getTaxID() != null) bp.setName(impBP.getName());
bp.setTaxID(impBP.getTaxID()); bp.setName2(impBP.getName2());
if (impBP.getNAICS() != null) }
bp.setNAICS(impBP.getNAICS()); if (impBP.getDUNS() != null)
if (impBP.getDescription() != null) bp.setDUNS(impBP.getDUNS());
bp.setDescription(impBP.getDescription()); if (impBP.getTaxID() != null)
if (impBP.getC_BP_Group_ID() != 0) bp.setTaxID(impBP.getTaxID());
bp.setC_BP_Group_ID(impBP.getC_BP_Group_ID()); if (impBP.getNAICS() != null)
// bp.setNAICS(impBP.getNAICS());
if (bp.save()) if (impBP.getDescription() != null)
{ bp.setDescription(impBP.getDescription());
log.finest("Update BPartner - " + bp.getC_BPartner_ID()); if (impBP.getC_BP_Group_ID() != 0)
noUpdate++; bp.setC_BP_Group_ID(impBP.getC_BP_Group_ID());
} //
else if (bp.save())
{ {
sql = new StringBuffer ("UPDATE I_BPartner i " log.finest("Update BPartner - " + bp.getC_BPartner_ID());
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") noUpdate++;
}
else
{
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.append("'Cannot Update BPartner, ' ") .append("'Cannot Update BPartner, ' ")
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
DB.executeUpdate(sql.toString(), get_TrxName()); DB.executeUpdate(sql.toString(), get_TrxName());
continue; continue;
}
} }
}
// **** Create/Update BPartner Location **** // **** Create/Update BPartner Location ****
bpl = null; bpl = null;
if (impBP.getC_BPartner_Location_ID() != 0) // Update Location if (impBP.getC_BPartner_Location_ID() != 0) // Update Location
{
bpl = new MBPartnerLocation(getCtx(), impBP.getC_BPartner_Location_ID(), get_TrxName());
MLocation location = new MLocation(getCtx(), bpl.getC_Location_ID(), get_TrxName());
location.setC_Country_ID(impBP.getC_Country_ID());
location.setC_Region_ID(impBP.getC_Region_ID());
location.setCity(impBP.getCity());
location.setAddress1(impBP.getAddress1());
location.setAddress2(impBP.getAddress2());
location.setPostal(impBP.getPostal());
location.setPostal_Add(impBP.getPostal_Add());
if (!location.save())
log.warning("Location not updated");
else
bpl.setC_Location_ID(location.getC_Location_ID());
if (impBP.getPhone() != null)
bpl.setPhone(impBP.getPhone());
if (impBP.getPhone2() != null)
bpl.setPhone2(impBP.getPhone2());
if (impBP.getFax() != null)
bpl.setFax(impBP.getFax());
bpl.save();
}
else // New Location
if (impBP.getC_Country_ID() != 0
&& impBP.getAddress1() != null
&& impBP.getCity() != null)
{
MLocation location = new MLocation(getCtx(), impBP.getC_Country_ID(),
impBP.getC_Region_ID(), impBP.getCity(), get_TrxName());
location.setAddress1(impBP.getAddress1());
location.setAddress2(impBP.getAddress2());
location.setPostal(impBP.getPostal());
location.setPostal_Add(impBP.getPostal_Add());
if (location.save())
log.finest("Insert Location - " + location.getC_Location_ID());
else
{ {
rollback(); bpl = new MBPartnerLocation(getCtx(), impBP.getC_BPartner_Location_ID(), get_TrxName());
noInsert--; MLocation location = new MLocation(getCtx(), bpl.getC_Location_ID(), get_TrxName());
sql = new StringBuffer ("UPDATE I_BPartner i " location.setC_Country_ID(impBP.getC_Country_ID());
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") location.setC_Region_ID(impBP.getC_Region_ID());
.append("'Cannot Insert Location, ' ") location.setCity(impBP.getCity());
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); location.setAddress1(impBP.getAddress1());
DB.executeUpdate(sql.toString(), get_TrxName()); location.setAddress2(impBP.getAddress2());
continue; location.setPostal(impBP.getPostal());
} location.setPostal_Add(impBP.getPostal_Add());
// if (!location.save())
bpl = new MBPartnerLocation (bp); log.warning("Location not updated");
bpl.setC_Location_ID(location.getC_Location_ID()); else
bpl.setPhone(impBP.getPhone()); bpl.setC_Location_ID(location.getC_Location_ID());
bpl.setPhone2(impBP.getPhone2()); if (impBP.getPhone() != null)
bpl.setFax(impBP.getFax()); bpl.setPhone(impBP.getPhone());
if (bpl.save()) if (impBP.getPhone2() != null)
{ bpl.setPhone2(impBP.getPhone2());
log.finest("Insert BP Location - " + bpl.getC_BPartner_Location_ID()); if (impBP.getFax() != null)
impBP.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID()); bpl.setFax(impBP.getFax());
} bpl.save();
else
{
rollback();
noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.append("'Cannot Insert BPLocation, ' ")
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
DB.executeUpdate(sql.toString(), get_TrxName());
continue;
} }
else // New Location
if (impBP.getC_Country_ID() != 0
&& impBP.getAddress1() != null
&& impBP.getCity() != null)
{
MLocation location = new MLocation(getCtx(), impBP.getC_Country_ID(),
impBP.getC_Region_ID(), impBP.getCity(), get_TrxName());
location.setAddress1(impBP.getAddress1());
location.setAddress2(impBP.getAddress2());
location.setPostal(impBP.getPostal());
location.setPostal_Add(impBP.getPostal_Add());
if (location.save())
log.finest("Insert Location - " + location.getC_Location_ID());
else
{
rollback();
noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.append("'Cannot Insert Location, ' ")
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
DB.executeUpdate(sql.toString(), get_TrxName());
continue;
}
//
bpl = new MBPartnerLocation (bp);
bpl.setC_Location_ID(location.getC_Location_ID());
bpl.setPhone(impBP.getPhone());
bpl.setPhone2(impBP.getPhone2());
bpl.setFax(impBP.getFax());
if (bpl.save())
{
log.finest("Insert BP Location - " + bpl.getC_BPartner_Location_ID());
impBP.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID());
}
else
{
rollback();
noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.append("'Cannot Insert BPLocation, ' ")
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
DB.executeUpdate(sql.toString(), get_TrxName());
continue;
}
}
} }
}
Old_BPValue = New_BPValue ; Old_BPValue = New_BPValue ;
// **** Create/Update Contact **** // **** Create/Update Contact ****
@ -430,9 +439,9 @@ public class ImportBPartner extends SvrProcess
rollback(); rollback();
noInsert--; noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.append("'BP of User <> BP, ' ") .append("'BP of User <> BP, ' ")
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
DB.executeUpdate(sql.toString(), get_TrxName()); DB.executeUpdate(sql.toString(), get_TrxName());
continue; continue;
} }
@ -469,57 +478,57 @@ public class ImportBPartner extends SvrProcess
rollback(); rollback();
noInsert--; noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i " sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.append("'Cannot Update BP Contact, ' ") .append("'Cannot Update BP Contact, ' ")
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
DB.executeUpdate(sql.toString(), get_TrxName()); DB.executeUpdate(sql.toString(), get_TrxName());
continue; continue;
} }
} }
else // New Contact else // New Contact
if (impBP.getContactName() != null || impBP.getEMail() != null) if (impBP.getContactName() != null || impBP.getEMail() != null)
{
user = new MUser (bp);
if (impBP.getC_Greeting_ID() != 0)
user.setC_Greeting_ID(impBP.getC_Greeting_ID());
String name = impBP.getContactName();
if (name == null || name.length() == 0)
name = impBP.getEMail();
user.setName(name);
user.setTitle(impBP.getTitle());
user.setDescription(impBP.getContactDescription());
user.setComments(impBP.getComments());
user.setPhone(impBP.getPhone());
user.setPhone2(impBP.getPhone2());
user.setFax(impBP.getFax());
user.setEMail(impBP.getEMail());
user.setBirthday(impBP.getBirthday());
if (bpl != null)
user.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID());
if (user.save())
{ {
log.finest("Insert BP Contact - " + user.getAD_User_ID()); user = new MUser (bp);
impBP.setAD_User_ID(user.getAD_User_ID()); if (impBP.getC_Greeting_ID() != 0)
} user.setC_Greeting_ID(impBP.getC_Greeting_ID());
else String name = impBP.getContactName();
{ if (name == null || name.length() == 0)
rollback(); name = impBP.getEMail();
noInsert--; user.setName(name);
sql = new StringBuffer ("UPDATE I_BPartner i " user.setTitle(impBP.getTitle());
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") user.setDescription(impBP.getContactDescription());
user.setComments(impBP.getComments());
user.setPhone(impBP.getPhone());
user.setPhone2(impBP.getPhone2());
user.setFax(impBP.getFax());
user.setEMail(impBP.getEMail());
user.setBirthday(impBP.getBirthday());
if (bpl != null)
user.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID());
if (user.save())
{
log.finest("Insert BP Contact - " + user.getAD_User_ID());
impBP.setAD_User_ID(user.getAD_User_ID());
}
else
{
rollback();
noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.append("'Cannot Insert BPContact, ' ") .append("'Cannot Insert BPContact, ' ")
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
DB.executeUpdate(sql.toString(), get_TrxName()); DB.executeUpdate(sql.toString(), get_TrxName());
continue; continue;
}
} }
}
// Interest Area // Interest Area
if (impBP.getR_InterestArea_ID() != 0 && user != null) if (impBP.getR_InterestArea_ID() != 0 && user != null)
{ {
MContactInterest ci = MContactInterest.get(getCtx(), MContactInterest ci = MContactInterest.get(getCtx(),
impBP.getR_InterestArea_ID(), user.getAD_User_ID(), impBP.getR_InterestArea_ID(), user.getAD_User_ID(),
true, get_TrxName()); true, get_TrxName());
ci.save(); // don't subscribe or re-activate ci.save(); // don't subscribe or re-activate
} }
// //
@ -540,8 +549,8 @@ public class ImportBPartner extends SvrProcess
// Set Error to indicator to not imported // Set Error to indicator to not imported
sql = new StringBuffer ("UPDATE I_BPartner " sql = new StringBuffer ("UPDATE I_BPartner "
+ "SET I_IsImported='N', Updated=SysDate " + "SET I_IsImported='N', Updated=SysDate "
+ "WHERE I_IsImported<>'Y'").append(clientCheck); + "WHERE I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
addLog (0, null, new BigDecimal (no), "@Errors@"); addLog (0, null, new BigDecimal (no), "@Errors@");
addLog (0, null, new BigDecimal (noInsert), "@C_BPartner_ID@: @Inserted@"); addLog (0, null, new BigDecimal (noInsert), "@C_BPartner_ID@: @Inserted@");