FR-1976008 - 2Pack can replicate Data with FK integrity

Changes done by Low Heng Sin
This commit is contained in:
Redhuan D. Oon 2009-02-04 10:19:59 +00:00
parent 8ee2df3af6
commit d0649726f5
6 changed files with 1935 additions and 1718 deletions

View File

@ -1,452 +1,456 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* *
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com * * Copyright (C) 2005 Robert Klein. robeklein@hotmail.com *
* Contributor(s): Low Heng Sin hengsin@avantz.com * * Contributor(s): Low Heng Sin hengsin@avantz.com *
*****************************************************************************/ *****************************************************************************/
package org.adempiere.pipo; package org.adempiere.pipo;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.sax.TransformerHandler;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.POInfo; import org.compiere.model.POInfo;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
public abstract class AbstractElementHandler implements ElementHandler { public abstract class AbstractElementHandler implements ElementHandler {
protected CLogger log = CLogger.getCLogger("PackIn"); protected CLogger log = CLogger.getCLogger("PackIn");
/** /**
* Get ID from Name for a table. * Get ID from Name for a table.
* TODO: substitute with PO.getAllIDs * TODO: substitute with PO.getAllIDs
* *
* @param tableName * @param tableName
* @param name * @param name
* *
*/ */
public int get_ID (Properties ctx, String tableName, String name) { public int get_ID (Properties ctx, String tableName, String name) {
return IDFinder.get_ID(tableName, name, getClientId(ctx), getTrxName(ctx)); return IDFinder.get_ID(tableName, name, getClientId(ctx), getTrxName(ctx));
} }
/** /**
* Get ID from column value for a table. * Get ID from column value for a table.
* *
* @param tableName * @param tableName
* @param columName * @param columName
* @param name * @param name
*/ */
public int get_IDWithColumn (Properties ctx, String tableName, String columnName, Object value) { public int get_IDWithColumn (Properties ctx, String tableName, String columnName, Object value) {
return IDFinder.get_IDWithColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx)); return IDFinder.get_IDWithColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx));
} }
/** /**
* Write results to log and records in history table * Write results to log and records in history table
* *
* @param success * @param success
* @param tableName * @param tableName
* @param objectType * @param objectType
* @param objectID * @param objectID
* @param objectStatus * @param objectStatus
* @throws SAXException * @throws SAXException
* *
*/ */
public int record_log (Properties ctx, int success, String objectName,String objectType, int objectID, public int record_log (Properties ctx, int success, String objectName,String objectType, int objectID,
int objectIDBackup, String objectStatus, String tableName, int AD_Table_ID) throws SAXException{ int objectIDBackup, String objectStatus, String tableName, int AD_Table_ID) throws SAXException{
StringBuffer recordLayout = new StringBuffer(); StringBuffer recordLayout = new StringBuffer();
int id = 0; int id = 0;
TransformerHandler hd_document = getLogDocument(ctx); TransformerHandler hd_document = getLogDocument(ctx);
AttributesImpl attsOut = new AttributesImpl(); AttributesImpl attsOut = new AttributesImpl();
if (success == 1){ if (success == 1){
//hd_documemt.startElement("","","Successfull",attsOut); //hd_documemt.startElement("","","Successfull",attsOut);
recordLayout.append("Type:") recordLayout.append("Type:")
.append(objectType) .append(objectType)
.append(" - Name:") .append(" - Name:")
.append(objectName) .append(objectName)
.append(" - ID:") .append(" - ID:")
.append(objectID) .append(objectID)
.append(" - Action:") .append(" - Action:")
.append(objectStatus) .append(objectStatus)
.append(" - Success"); .append(" - Success");
hd_document.startElement("","","Success",attsOut); hd_document.startElement("","","Success",attsOut);
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length()); hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
hd_document.endElement("","","Success"); hd_document.endElement("","","Success");
//hd_documemt.endElement("","","Successfull"); //hd_documemt.endElement("","","Successfull");
//String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"; //String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL";
//int id = DB.getSQLValue(m_trxName, sql2)+1; //int id = DB.getSQLValue(m_trxName, sql2)+1;
id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx)); id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx));
StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail") StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail")
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," ) .append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," )
.append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" ) .append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" )
.append( "VALUES(" ) .append( "VALUES(" )
.append( " "+ Env.getAD_Client_ID(ctx) ) .append( " ?")
.append( ", "+ Env.getAD_Org_ID(ctx) ) .append( ", ?" )
.append( ", "+ Env.getAD_User_ID(ctx) ) .append( ", ?" )
.append( ", "+ Env.getAD_User_ID(ctx) ) .append( ", ?" )
.append( ", " + id ) .append( ", ?" )
.append( ", " + getPackageImpId(ctx) ) .append( ", ?" )
.append( ", '" + objectType ) .append( ", ?" )
.append( "', '" + objectName ) .append( ", ?" )
.append( "', '" + objectStatus ) .append( ", ?" )
.append( "', 'Success'" ) .append( ", ?" )
.append( ", "+objectID ) .append( ", ?" )
.append( ", "+objectIDBackup ) .append( ", ?" )
.append( ", '"+tableName ) .append( ", ?" )
.append( "', "+AD_Table_ID ) .append( ", ?")
.append(")"); .append(")");
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); Object[] param = new Object[] { Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx), Env.getAD_User_ID(ctx), Env.getAD_User_ID(ctx),
if (no == -1) id, getPackageImpId(ctx) , objectType, objectName, objectStatus, "Success", objectID, objectIDBackup, tableName,
log.info("Insert to import detail failed"); AD_Table_ID
};
} int no = DB.executeUpdate (sqlB.toString(), param, true, getTrxName(ctx));
else{ if (no == -1)
String PK_Status = "Completed with errors"; log.info("Insert to import detail failed");
hd_document.startElement("","","Failure",attsOut);
recordLayout.append("Type:") }
.append(objectType) else{
.append(" - Name:") String PK_Status = "Completed with errors";
.append(tableName) hd_document.startElement("","","Failure",attsOut);
.append(" - ID:") recordLayout.append("Type:")
.append(objectID) .append(objectType)
.append(" - Action:") .append(" - Name:")
.append(objectStatus) .append(tableName)
.append(" - Failure"); .append(" - ID:")
//hd_documemt.startElement("","","Success",attsOut); .append(objectID)
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length()); .append(" - Action:")
//hd_documemt.endElement("","","Success"); .append(objectStatus)
hd_document.endElement("","","Failure"); .append(" - Failure");
//hd_documemt.startElement("","","Success",attsOut);
//String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"; hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
//int id = DB.getSQLValue(m_trxName,sql2)+1; //hd_documemt.endElement("","","Success");
hd_document.endElement("","","Failure");
id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx));
//String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL";
StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail") //int id = DB.getSQLValue(m_trxName,sql2)+1;
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," ) id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx));
.append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" )
.append( "VALUES(" ) StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail")
.append( " "+ Env.getAD_Client_ID(ctx) ) .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( ", "+ Env.getAD_Org_ID(ctx) ) .append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," )
.append( ", "+ Env.getAD_User_ID(ctx) ) .append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" )
.append( ", "+ Env.getAD_User_ID(ctx) ) .append( "VALUES(" )
.append( ", " + id ) .append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", " + getPackageImpId(ctx) ) .append( ", "+ Env.getAD_Org_ID(ctx) )
.append( ", '" + objectType ) .append( ", "+ Env.getAD_User_ID(ctx) )
.append( "', '" + objectName ) .append( ", "+ Env.getAD_User_ID(ctx) )
.append( "', '" + objectStatus ) .append( ", " + id )
.append( "', 'Failure'" ) .append( ", " + getPackageImpId(ctx) )
.append( ", "+objectID ) .append( ", '" + objectType )
.append( ", "+objectIDBackup ) .append( "', '" + objectName )
.append( ", '"+tableName ) .append( "', '" + objectStatus )
.append( "', "+AD_Table_ID ) .append( "', 'Failure'" )
.append( ")"); .append( ", "+objectID )
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); .append( ", "+objectIDBackup )
if (no == -1) .append( ", '"+tableName )
log.info("Insert to import detail failed"); .append( "', "+AD_Table_ID )
} .append( ")");
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
String Object_Status = "Status not set"; if (no == -1)
return id; log.info("Insert to import detail failed");
} }
/** String Object_Status = "Status not set";
* Get ID from Name for a table with a Master reference. return id;
* }
* @param tableName
* @param name /**
* @param tableNameMaster * Get ID from Name for a table with a Master reference.
* @param nameMaster *
*/ * @param tableName
public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, String nameMaster) { * @param name
return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, nameMaster, getTrxName(ctx)); * @param tableNameMaster
} * @param nameMaster
*/
/** public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, String nameMaster) {
* Get ID from Name for a table with a Master reference. return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, nameMaster, getTrxName(ctx));
* }
* @param tableName
* @param name /**
* @param tableNameMaster * Get ID from Name for a table with a Master reference.
* @param nameMaster *
*/ * @param tableName
* @param name
public int get_IDWithMasterAndColumn (Properties ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID) { * @param tableNameMaster
return IDFinder.get_IDWithMasterAndColumn(tableName, columnName, name, tableNameMaster, masterID, * @param nameMaster
getTrxName(ctx)); */
}
public int get_IDWithMasterAndColumn (Properties ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID) {
/** return IDFinder.get_IDWithMasterAndColumn(tableName, columnName, name, tableNameMaster, masterID,
* Get ID from Name for a table with a Master reference ID. getTrxName(ctx));
* }
* @param tableName
* @param name /**
* @param tableNameMaster * Get ID from Name for a table with a Master reference ID.
* @param masterID *
*/ * @param tableName
public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, int masterID) { * @param name
return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, masterID, getTrxName(ctx)); * @param tableNameMaster
} * @param masterID
*/
/** public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, int masterID) {
* Get ID from Name for a table. return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, masterID, getTrxName(ctx));
* TODO: substitute with PO.getAllIDs }
*
* @param tableName /**
* @param name * Get ID from Name for a table.
*/ * TODO: substitute with PO.getAllIDs
public int getIDbyName (Properties ctx, String tableName, String name) { *
return IDFinder.getIDbyName(tableName, name, getClientId(ctx), getTrxName(ctx)); * @param tableName
} * @param name
*/
/** public int getIDbyName (Properties ctx, String tableName, String name) {
* Make backup copy of record. return IDFinder.getIDbyName(tableName, name, getClientId(ctx), getTrxName(ctx));
* }
* @param tablename
* /**
* * Make backup copy of record.
* *
*/ * @param tablename
public int copyRecord(Properties ctx, String tableName,PO from){ *
// Create new record *
int idBackup = 0; *
String colValue=null; */
int tableID = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName); public int copyRecord(Properties ctx, String tableName,PO from){
POInfo poInfo = POInfo.getPOInfo(ctx, tableID, getTrxName(ctx)); // Create new record
for (int i = 0; i < poInfo.getColumnCount(); i++){ int idBackup = 0;
String colName = poInfo.getColumnName(i); String colValue=null;
colValue=null; int tableID = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
POInfo poInfo = POInfo.getPOInfo(ctx, tableID, getTrxName(ctx));
int columnID =get_IDWithMasterAndColumn (ctx, "AD_Column", "ColumnName", poInfo.getColumnName(i), "AD_Table", tableID); for (int i = 0; i < poInfo.getColumnCount(); i++){
StringBuffer sqlD = new StringBuffer("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = '"+columnID+"'"); String colName = poInfo.getColumnName(i);
int referenceID = DB.getSQLValue(getTrxName(ctx),sqlD.toString()); colValue=null;
idBackup = DB.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx)); int columnID =get_IDWithMasterAndColumn (ctx, "AD_Column", "ColumnName", poInfo.getColumnName(i), "AD_Table", tableID);
StringBuffer sqlD = new StringBuffer("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = '"+columnID+"'");
sqlD = new StringBuffer("SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"); int referenceID = DB.getSQLValue(getTrxName(ctx),sqlD.toString());
int idDetail = DB.getSQLValue(getTrxName(ctx),sqlD.toString())+1;
idBackup = DB.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
if (referenceID == 10 || referenceID == 14 || referenceID == 34 || referenceID == 17)
if (from.get_Value(i)!= null) sqlD = new StringBuffer("SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL");
colValue = from.get_Value(i).toString().replaceAll("'","''"); int idDetail = DB.getSQLValue(getTrxName(ctx),sqlD.toString())+1;
else if (referenceID == 20|| referenceID == 28)
if (from.get_Value(i)!= null) if (referenceID == 10 || referenceID == 14 || referenceID == 34 || referenceID == 17)
colValue = from.get_Value(i).toString().replaceAll("'","''"); if (from.get_Value(i)!= null)
else colValue = from.get_Value(i).toString().replaceAll("'","''");
;//Ignore else if (referenceID == 20|| referenceID == 28)
if (from.get_Value(i)!= null)
StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Backup") colValue = from.get_Value(i).toString().replaceAll("'","''");
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) else
.append( "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," ) ;//Ignore
.append( " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" )
.append( "VALUES(" ) StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Backup")
.append( " "+ Env.getAD_Client_ID(ctx) ) .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
.append( ", "+ Env.getAD_Org_ID(ctx) ) .append( "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," )
.append( ", "+ Env.getAD_User_ID(ctx) ) .append( " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" )
.append( ", "+ Env.getAD_User_ID(ctx) ) .append( "VALUES(" )
.append( ", " + idBackup ) .append( " "+ Env.getAD_Client_ID(ctx) )
.append( ", " + idDetail ) .append( ", "+ Env.getAD_Org_ID(ctx) )
.append( ", " + getPackageImpId(ctx) ) .append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + tableID ) .append( ", "+ Env.getAD_User_ID(ctx) )
.append( ", " + (columnID == -1 ? "null" : columnID) ) .append( ", " + idBackup )
.append( ", " + (referenceID == -1 ? "null" : referenceID) ) .append( ", " + idDetail )
.append( ", '" + (colValue != null ? colValue : from.get_Value(i)) ) .append( ", " + getPackageImpId(ctx) )
.append( "')"); .append( ", " + tableID )
.append( ", " + (columnID == -1 ? "null" : columnID) )
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); .append( ", " + (referenceID == -1 ? "null" : referenceID) )
if (no == -1) .append( ", '" + (colValue != null ? colValue : from.get_Value(i)) )
log.info("Insert to import backup failed"); .append( "')");
//}
} int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
return idBackup; if (no == -1)
} log.info("Insert to import backup failed");
//}
/** }
* Open input file for processing return idBackup;
* }
* @param String file with path
* /**
*/ * Open input file for processing
public FileInputStream OpenInputfile (String filePath) { *
* @param String file with path
FileInputStream fileTarget = null; *
*/
try { public FileInputStream OpenInputfile (String filePath) {
fileTarget = new FileInputStream(filePath);
} FileInputStream fileTarget = null;
catch (FileNotFoundException e ) {
System.out.println("File not found: " + filePath); try {
fileTarget = new FileInputStream(filePath);
return null; }
} catch (FileNotFoundException e ) {
return fileTarget; System.out.println("File not found: " + filePath);
}
return null;
/** }
* Open output file for processing return fileTarget;
* }
* @param String file with path
* /**
*/ * Open output file for processing
public OutputStream OpenOutputfile (String filePath) { *
* @param String file with path
OutputStream fileTarget = null; *
*/
try { public OutputStream OpenOutputfile (String filePath) {
fileTarget = new FileOutputStream(filePath);
} OutputStream fileTarget = null;
catch (FileNotFoundException e ) {
System.out.println("File not found: " + filePath); try {
fileTarget = new FileOutputStream(filePath);
return null; }
} catch (FileNotFoundException e ) {
return fileTarget; System.out.println("File not found: " + filePath);
}
return null;
/** }
* Copyfile return fileTarget;
* }
* @param String file with path
* /**
*/ * Copyfile
public int copyFile (InputStream source,OutputStream target) { *
* @param String file with path
int byteCount = 0; *
int success = 0; */
try { public int copyFile (InputStream source,OutputStream target) {
while (true) {
int data = source.read(); int byteCount = 0;
if (data < 0) int success = 0;
break; try {
target.write(data); while (true) {
byteCount++; int data = source.read();
} if (data < 0)
source.close(); break;
target.close(); target.write(data);
//System.out.println("Successfully copied " + byteCount + " bytes."); byteCount++;
} }
catch (Exception e) { source.close();
System.out.println("Error occurred while copying. "+ byteCount + " bytes copied."); target.close();
log.log(Level.SEVERE, e.getLocalizedMessage(), e); //System.out.println("Successfully copied " + byteCount + " bytes.");
}
success = -1; catch (Exception e) {
} System.out.println("Error occurred while copying. "+ byteCount + " bytes copied.");
return success; log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
success = -1;
/** }
* Get client id return success;
* @param ctx }
* @return int
*/ /**
protected int getClientId(Properties ctx) { * Get client id
return Env.getContextAsInt(ctx, "AD_Client_ID"); * @param ctx
} * @return int
*/
/** protected int getClientId(Properties ctx) {
* Get AD_Package_Imp_ID return Env.getContextAsInt(ctx, "AD_Client_ID");
* @param ctx }
* @return int
*/ /**
protected int getPackageImpId(Properties ctx) { * Get AD_Package_Imp_ID
return Env.getContextAsInt(ctx, "AD_Package_Imp_ID"); * @param ctx
} * @return int
*/
/** protected int getPackageImpId(Properties ctx) {
* Get update system maintained dictionary flag return Env.getContextAsInt(ctx, "AD_Package_Imp_ID");
* @param ctx }
* @return update mode
*/ /**
protected String getUpdateMode(Properties ctx) { * Get update system maintained dictionary flag
return Env.getContext(ctx, "UpdateMode"); * @param ctx
} * @return update mode
*/
/** protected String getUpdateMode(Properties ctx) {
* Get current transaction name return Env.getContext(ctx, "UpdateMode");
* @param ctx }
* @return transaction name
*/ /**
protected String getTrxName(Properties ctx) { * Get current transaction name
return Env.getContext(ctx, "TrxName"); * @param ctx
} * @return transaction name
*/
/** protected String getTrxName(Properties ctx) {
* Get share document return Env.getContext(ctx, "TrxName");
* @param ctx }
* @return TransformerHandler
*/ /**
protected TransformerHandler getLogDocument(Properties ctx) { * Get share document
return (TransformerHandler)ctx.get("LogDocument"); * @param ctx
} * @return TransformerHandler
*/
/** protected TransformerHandler getLogDocument(Properties ctx) {
* @param ctx return (TransformerHandler)ctx.get("LogDocument");
* @return package directory }
*/
protected String getPackageDirectory(Properties ctx) { /**
return Env.getContext(ctx, "PackageDirectory"); * @param ctx
} * @return package directory
*/
/** protected String getPackageDirectory(Properties ctx) {
* Process element by entity type and user setting. return Env.getContext(ctx, "PackageDirectory");
* @param ctx }
* @param entityType
* @return boolean /**
*/ * Process element by entity type and user setting.
protected boolean isProcessElement(Properties ctx, String entityType) { * @param ctx
if ("D".equals(entityType) || "C".equals(entityType)) { * @param entityType
return "true".equalsIgnoreCase(getUpdateMode(ctx)); * @return boolean
} else { */
return true; protected boolean isProcessElement(Properties ctx, String entityType) {
} if ("D".equals(entityType) || "C".equals(entityType)) {
} return "true".equalsIgnoreCase(getUpdateMode(ctx));
} else {
/** return true;
* return null for empty string (""). }
* @param atts }
* @param qName
* @return string value /**
*/ * return null for empty string ("").
protected String getStringValue(Attributes atts, String qName) { * @param atts
String s = atts.getValue(qName); * @param qName
return ("".equals(s) ? null : s); * @return string value
} */
protected String getStringValue(Attributes atts, String qName) {
/** String s = atts.getValue(qName);
* Returns option - Is export-import of AD translations is needed return ("".equals(s) ? null : s);
* @param ctx }
* @param entityType
* @return boolean /**
*/ * Returns option - Is export-import of AD translations is needed
protected boolean isHandleTranslations(Properties ctx) { * @param ctx
* @param entityType
return "true".equalsIgnoreCase(Env.getContext(ctx, "isHandleTranslations")); * @return boolean
} */
} protected boolean isHandleTranslations(Properties ctx) {
return "true".equalsIgnoreCase(Env.getContext(ctx, "isHandleTranslations"));
}
}

File diff suppressed because it is too large Load Diff

View File

@ -23,8 +23,7 @@ import java.sql.ResultSetMetaData;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.List;
import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
@ -38,11 +37,18 @@ import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.POInfo; import org.compiere.model.POInfo;
import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
/**
*
* @author Robert Klein.
* @author Low Heng Sin
*
*/
public class DataElementHandler extends AbstractElementHandler { public class DataElementHandler extends AbstractElementHandler {
private GenericPO genericPO = null; private GenericPO genericPO = null;
@ -93,41 +99,41 @@ public class DataElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException { public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue(); String elementValue = element.getElementValue();
Attributes atts = element.attributes; Attributes atts = element.attributes;
log.info(elementValue+" "+atts.getValue("name")); log.info(elementValue+" "+atts.getValue("name"));
String d_rowname = atts.getValue("name");
// use keyXname and lookupkeyXname if available
// name can be null if there are keyXname attributes. if (atts.getValue("key1name") != null && atts.getValue("key1name").trim().length() > 0)
if (!d_rowname.equals("")){ {
int id = get_ID(ctx, d_tablename, d_rowname);
genericPO = new GenericPO(d_tablename, ctx, id, getTrxName(ctx));
if (id > 0){
AD_Backup_ID = copyRecord(ctx,d_tablename,genericPO);
objectStatus = "Update";
}
else{
objectStatus = "New";
AD_Backup_ID =0;
}
}
// keyXname and lookupkeyXname.
else {
String sql = "select * from "+d_tablename; String sql = "select * from "+d_tablename;
String whereand = " where"; String whereand = " where";
String CURRENT_KEY = "key1name";
if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) { List<String>params = new ArrayList<String>();
sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); int keyIndex = 1;
whereand = " and"; while (true) {
String currentKey = "key" + keyIndex + "name";
if (atts.getValue(currentKey) != null && !atts.getValue(currentKey).equals("")) {
params.add(atts.getValue("lookup"+currentKey));
sql = sql+whereand+" "+atts.getValue(currentKey)+"=?";
whereand = " and";
keyIndex++;
} else {
break;
}
} }
CURRENT_KEY = "key2name";
if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) { if (getClientId(ctx) > 0) {
sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); sql = sql + whereand + " " + d_tablename + ".AD_Client_ID in (0, " + getClientId(ctx) + ")";
whereand = " and"; sql = sql + " Order by " + d_tablename + ".AD_Client_ID Desc";
} else {
sql = sql + whereand + " " + d_tablename + ".AD_Client_ID = 0";
} }
if (whereand.equals(" where"))
log.warning("no name or keyXname attribute defined.");
// Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value // Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value
try { try {
PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx)); PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx));
for (int i = 0; i < params.size(); i++) {
pstmt.setString(i+1, params.get(i));
}
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
@ -143,20 +149,23 @@ public class DataElementHandler extends AbstractElementHandler {
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
objectStatus = "New"; objectStatus = "New";
// set keyXname. }
CURRENT_KEY = "key1name";
if (!atts.getValue(CURRENT_KEY).equals("")) {
genericPO.set_ValueOfColumn(atts.getValue(CURRENT_KEY), atts.getValue("lookup"+CURRENT_KEY));
}
CURRENT_KEY = "key2name";
if (!atts.getValue(CURRENT_KEY).equals("")) {
genericPO.set_ValueOfColumn(atts.getValue(CURRENT_KEY), atts.getValue("lookup"+CURRENT_KEY));
}
}
} }
catch (Exception e) { catch (Exception e) {
log.warning ("keyXname attribute. init from rs error."+e); log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
} else {
//fallback to name attribute
String nameAttribute = atts.getValue("name");
int id = get_ID(ctx, d_tablename, nameAttribute);
genericPO = new GenericPO(d_tablename, ctx, id, getTrxName(ctx));
if (id > 0){
AD_Backup_ID = copyRecord(ctx,d_tablename,genericPO);
objectStatus = "Update";
}
else{
objectStatus = "New";
AD_Backup_ID =0;
} }
} }
@ -171,29 +180,7 @@ public class DataElementHandler extends AbstractElementHandler {
} }
// globalqss: set AD_Client_ID to the client setted in adempieredata // globalqss: set AD_Client_ID to the client setted in adempieredata
if (getClientId(ctx) > 0 && genericPO.getAD_Client_ID() != getClientId(ctx)) if (getClientId(ctx) > 0 && genericPO.getAD_Client_ID() != getClientId(ctx))
genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx)); genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx));
// if new. TODO: no defaults for keyXname.
if (!d_rowname.equals("") && ((Integer)(genericPO.get_Value(d_tablename+"_ID"))).intValue() == 0) {
log.info("new genericPO, table: "+d_tablename+" name:"+d_rowname);
genericPO.set_ValueOfColumn("Name", d_rowname);
// Set defaults.
//TODO: get defaults from configuration
HashMap defaults = new HashMap();
HashMap thisDefault = (HashMap)defaults.get(d_tablename);
if (thisDefault != null) {
Iterator iter = thisDefault.values().iterator();
ArrayList thisValue = null;
while (iter.hasNext()) {
thisValue = (ArrayList)iter.next();
if (((String)(thisValue.get(2))).equals("String"))
genericPO.set_ValueOfColumn((String)thisValue.get(0), (String)thisValue.get(1));
else if (((String)(thisValue.get(2))).equals("Integer"))
genericPO.set_ValueOfColumn((String)thisValue.get(0), Integer.valueOf((String)thisValue.get(1)));
else if (((String)(thisValue.get(2))).equals("Boolean"))
genericPO.set_ValueOfColumn((String)thisValue.get(0), new Boolean(((String)thisValue.get(1)).equals("true") ? true : false));
}
}
}
} }
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
@ -224,6 +211,10 @@ public class DataElementHandler extends AbstractElementHandler {
String columnName = atts.getValue("name"); String columnName = atts.getValue("name");
int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename); int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename);
int id =get_IDWithMasterAndColumn (ctx,"AD_Column", "ColumnName", columnName, "AD_Table", tableid); int id =get_IDWithMasterAndColumn (ctx,"AD_Column", "ColumnName", columnName, "AD_Table", tableid);
if (id <= 0) {
log.log(Level.WARNING, "Column not found in AD_Column, TableName=" + d_tablename + " ColumnName=" + columnName);
return;
}
StringBuffer sql = new StringBuffer ("SELECT IsUpdateable FROM AD_column WHERE AD_Column_ID = ?"); StringBuffer sql = new StringBuffer ("SELECT IsUpdateable FROM AD_column WHERE AD_Column_ID = ?");
String isUpdateable = DB.getSQLValueString(getTrxName(ctx), sql.toString(),id); String isUpdateable = DB.getSQLValueString(getTrxName(ctx), sql.toString(),id);
sql = new StringBuffer ("SELECT IsKey FROM AD_column WHERE AD_Column_ID = ?"); sql = new StringBuffer ("SELECT IsKey FROM AD_column WHERE AD_Column_ID = ?");
@ -231,36 +222,43 @@ public class DataElementHandler extends AbstractElementHandler {
if (("New".equals(objectStatus)) || (isKey.equals("N") && if (("New".equals(objectStatus)) || (isKey.equals("N") &&
isUpdateable.equals("Y") && isUpdateable.equals("Y") &&
(!atts.getValue("name").equals("CreatedBy")||!atts.getValue("name").equals("UpdatedBy")))) { (!atts.getValue("name").equals("CreatedBy")||!atts.getValue("name").equals("UpdatedBy")))) {
if (atts.getValue("value") != null && !atts.getValue("value").equals("null")) { String value = atts.getValue("value");
if (value != null && !value.equals("null") && value.trim().length() > 0) {
if (atts.getValue("class").equals("String") || atts.getValue("class").equals("Text") if (atts.getValue("class").equals("String") || atts.getValue("class").equals("Text")
|| atts.getValue("class").equals("List")|| atts.getValue("class").equals("Yes-No") || atts.getValue("class").equals("List")|| atts.getValue("class").equals("Yes-No")
|| atts.getValue("class").equals("Button") || atts.getValue("class").equals("Button")
|| atts.getValue("class").equals("Memo")|| atts.getValue("class").equals("Text Long")) { || atts.getValue("class").equals("Memo")|| atts.getValue("class").equals("Text Long")) {
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), atts.getValue("value").toString()); genericPO.set_ValueOfColumn(atts.getValue("name"), value);
} }
else if (atts.getValue("class").equals("Number") || atts.getValue("class").equals("Amount") else if (atts.getValue("class").equals("Number") || atts.getValue("class").equals("Amount")
|| atts.getValue("class").equals("Quantity")|| atts.getValue("class").equals("Costs+Prices")){ || atts.getValue("class").equals("Quantity")|| atts.getValue("class").equals("Costs+Prices")){
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), new BigDecimal(atts.getValue("value"))); genericPO.set_ValueOfColumn(atts.getValue("name"), new BigDecimal(value));
} }
else if (atts.getValue("class").equals("Integer") || atts.getValue("class").equals("ID") else if (atts.getValue("class").equals("Integer") || atts.getValue("class").equals("ID")
|| atts.getValue("class").equals("Table Direct")|| atts.getValue("class").equals("Table") || atts.getValue("class").equals("Table Direct")|| atts.getValue("class").equals("Table")
|| atts.getValue("class").equals("Location (Address)")|| atts.getValue("class").equals("Account") || atts.getValue("class").equals("Location (Address)")|| atts.getValue("class").equals("Account")
|| atts.getValue("class").equals("Color)")|| atts.getValue("class").equals("Search") || atts.getValue("class").equals("Color)")|| atts.getValue("class").equals("Search")
|| atts.getValue("class").equals("Locator (WH)")|| atts.getValue("class").equals("Product Attribute")) { || atts.getValue("class").equals("Locator (WH)")|| atts.getValue("class").equals("Product Attribute")) {
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), Integer.valueOf(atts.getValue("value"))); genericPO.set_ValueOfColumn(atts.getValue("name"), Integer.valueOf(value));
} }
else if (atts.getValue("class").equals("Boolean")) { else if (atts.getValue("class").equals("Boolean")) {
genericPO.set_ValueOfColumn(atts.getValue("name"), new Boolean(atts.getValue("value").equals("true") ? true : false)); genericPO.set_ValueOfColumn(atts.getValue("name"), new Boolean(value.equals("true") ? true : false));
} }
else if (atts.getValue("class").equals("Date") || atts.getValue("class").equals("Date+Time") else if (atts.getValue("class").equals("Date") || atts.getValue("class").equals("Date+Time")
|| atts.getValue("class").equals("Time")) { || atts.getValue("class").equals("Time")) {
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), Timestamp.valueOf(atts.getValue("value"))); genericPO.set_ValueOfColumn(atts.getValue("name"), Timestamp.valueOf(value));
}//Binary, Radio, RowID, Image not supported }//Binary, Radio, RowID, Image not supported
} else { // value is null } else { // value is null
if (atts.getValue("lookupname") != null && !"".equals(atts.getValue("lookupname"))) { if (atts.getValue("lookupname") != null && !"".equals(atts.getValue("lookupname"))) {
// globalqss - bring support from XML2AD to lookupname // globalqss - bring support from XML2AD to lookupname
String m_tablename = atts.getValue("name").substring(0, atts.getValue("name").length()-3); String m_tablename = atts.getValue("name").substring(0, atts.getValue("name").length()-3);
genericPO.set_ValueOfColumn(atts.getValue("name"), new Integer(getIDbyName(ctx, m_tablename, atts.getValue("lookupname")))); genericPO.set_ValueOfColumn(atts.getValue("name"), new Integer(getIDbyName(ctx, m_tablename, atts.getValue("lookupname"))));
} else if ( atts.getValue("sql") != null && atts.getValue("sql").trim().length() > 0) {
String idSql = atts.getValue("sql");
idSql = idSql.replace("@AD_Client_ID@", Integer.toString(getClientId(ctx)));
int result = DB.getSQLValue(getTrxName(ctx), idSql);
if (result >= 0)
genericPO.set_ValueOfColumn(atts.getValue("name"), result);
} }
} }
} }
@ -275,6 +273,10 @@ public class DataElementHandler extends AbstractElementHandler {
} }
/**
* @param ctx
* @param document
*/
public void create(Properties ctx, TransformerHandler document) public void create(Properties ctx, TransformerHandler document)
throws SAXException { throws SAXException {
String sql = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); String sql = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
@ -295,37 +297,53 @@ public class DataElementHandler extends AbstractElementHandler {
document.startElement("","","dtable",atts); document.startElement("","","dtable",atts);
while (rs.next()){ while (rs.next()){
atts.clear(); atts.clear();
int key1 = 0; int keyIndex = 0;
String nameatts = ""; String nameatts = "";
for (i=1 ;i <= columns;i++){ for (i=1 ;i <= columns;i++){
col_Name = meta.getColumnName(i).toUpperCase(); col_Name = meta.getColumnName(i).toUpperCase();
if (col_Name.equals("NAME") && rs.getObject("name") != null) if (col_Name.equals("NAME") && rs.getObject("name") != null)
nameatts = ""+rs.getObject("name"); nameatts = ""+rs.getObject("name");
String sql2 = "SELECT ColumnName FROM AD_Column " String sql2 = "SELECT ColumnName FROM AD_Column "
+ "WHERE isKey = 'Y' AND " + "WHERE isIdentifier = 'Y' AND "
+ "AD_Table_ID = ? AND " + "AD_Table_ID = ? AND "
+ "Upper(ColumnName)= '"+col_Name+"'"; + "Upper(ColumnName)= '"+col_Name+"'";
String cName = DB.getSQLValueString(null,sql2,table_id); String cName = DB.getSQLValueString(null,sql2,table_id);
if (cName != null){ if (cName != null){
if (cName.toUpperCase().equals(col_Name) && key1 == 0 ){ if (cName.toUpperCase().equals(col_Name)){
atts.addAttribute("","","key1name","CDATA",cName); keyIndex++;
atts.addAttribute("","","lookupkey1name","CDATA",""+rs.getObject(col_Name)); atts.addAttribute("","","key" + keyIndex + "name","CDATA",cName);
key1 = 1; atts.addAttribute("","","lookupkey" + keyIndex + "name","CDATA",""+rs.getObject(col_Name));
} }
else if (cName.toUpperCase().equals(col_Name) && key1 == 1 ){ }
atts.addAttribute("","","key2name","CDATA",cName); }
atts.addAttribute("","","lookupkey2name","CDATA",""+rs.getObject(col_Name));
key1 = 2; //fall back to Id
if (keyIndex == 0) {
for (i=1 ;i <= columns;i++){
col_Name = meta.getColumnName(i).toUpperCase();
if (col_Name.equals("NAME") && rs.getObject("name") != null)
nameatts = ""+rs.getObject("name");
String sql2 = "SELECT ColumnName FROM AD_Column "
+ "WHERE isKey = 'Y' AND "
+ "AD_Table_ID = ? AND "
+ "Upper(ColumnName)= '"+col_Name+"'";
String cName = DB.getSQLValueString(null,sql2,table_id);
if (cName != null){
if (cName.toUpperCase().equals(col_Name)){
keyIndex++;
atts.addAttribute("","","key" + keyIndex + "name","CDATA",cName);
atts.addAttribute("","","lookupkey" + keyIndex + "name","CDATA",""+rs.getObject(col_Name));
}
} }
} }
} }
atts.addAttribute("","","name","CDATA",nameatts); atts.addAttribute("","","name","CDATA",nameatts);
if ( key1 == 0 ){ if ( keyIndex == 0 ){
atts.addAttribute("","","key1name","CDATA",""); atts.addAttribute("","","key1name","CDATA","");
atts.addAttribute("","","lookupkey1name","CDATA",""); atts.addAttribute("","","lookupkey1name","CDATA","");
key1 = 1; keyIndex++;
} }
if ( key1 == 1 ){ if ( keyIndex == 1 ){
atts.addAttribute("","","key2name","CDATA",""); atts.addAttribute("","","key2name","CDATA","");
atts.addAttribute("","","lookupkey2name","CDATA",""); atts.addAttribute("","","lookupkey2name","CDATA","");
} }
@ -333,11 +351,12 @@ public class DataElementHandler extends AbstractElementHandler {
for (i=1 ;i <= columns;i++){ for (i=1 ;i <= columns;i++){
atts.clear(); atts.clear();
col_Name = meta.getColumnName(i).toUpperCase(); col_Name = meta.getColumnName(i).toUpperCase();
String sql2 = "Select A.ColumnName, B.Name " String sql2 = "Select A.ColumnName, B.Name, A.AD_Reference_ID, A.AD_Reference_Value_ID "
+ "From AD_Column A, AD_Reference B " + "From AD_Column A, AD_Reference B "
+ "Where Upper(A.columnname) = ? and " + "Where Upper(A.columnname) = ? and "
+ "A.AD_TABLE_ID = ? and " + "A.AD_TABLE_ID = ? and "
+ "A.AD_Reference_ID = B.AD_Reference_ID"; + "A.AD_Reference_ID = B.AD_Reference_ID "
+ "AND A.ColumnName != 'AD_Client_ID' ";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try try
{ {
@ -350,11 +369,50 @@ public class DataElementHandler extends AbstractElementHandler {
atts.clear(); atts.clear();
atts.addAttribute("","","name","CDATA", rs1.getString("ColumnName")); atts.addAttribute("","","name","CDATA", rs1.getString("ColumnName"));
atts.addAttribute("","","class","CDATA", rs1.getString("Name")); atts.addAttribute("","","class","CDATA", rs1.getString("Name"));
if (rs1.getString("Name").equals("Date")||rs1.getString("Name").equals("Date+Time")||rs1.getString("Name").equals("Time"))
atts.addAttribute("","","value","CDATA", "" + rs.getTimestamp(i));
else
atts.addAttribute("","","value","CDATA", "" + rs.getObject(i));
//rs1.getString("ColumnName") : NAME / VALUE
//rs1.getString("Name") : STRING
//rs1.getString("AD_Reference_ID") : number (table/table direct/ search)
//rs1.getString("AD_Reference_Value_ID") : number (null when type is table direct)
if (rs1.getInt("AD_Reference_ID") == DisplayType.Table || rs1.getInt("AD_Reference_ID") == DisplayType.Search
|| rs1.getInt("AD_Reference_ID") == DisplayType.TableDir ){
String tableName = "";
if (rs1.getInt("AD_Reference_ID") == DisplayType.TableDir){
//if rs1.getString("ColumnName") = C_EDIFORMAT_ID, tablename = C_EDIFORMAT
tableName = rs1.getString("ColumnName").substring(0,rs1.getString("ColumnName").length()-3);
}else{
//ad_ref_table.ad_reference_id = ad_reference_value_id
int referenceId = rs1.getInt("AD_Reference_Value_ID");
if (referenceId != 0)
tableName = getTableNameFromReferenceId(referenceId);
else
tableName = rs1.getString("ColumnName").substring(0,rs1.getString("ColumnName").length()-3);
}
if (rs.getObject(i) == null)
atts.addAttribute("","","value","CDATA", "");
else{
String insertSql = getSqlFromTableName(tableName,Integer.parseInt(rs.getObject(i).toString()),ctx);
String parentSql = getParentSql(tableName,ctx,Integer.parseInt(rs.getObject(i).toString()));
if (!parentSql.equals(""))
insertSql = insertSql + parentSql;
insertSql = insertSql + " Order By " + tableName + ".AD_Client_ID Desc ";
atts.addAttribute("","","value","CDATA", "");
atts.addAttribute("", "", "sql", "CDATA", insertSql);
}
} else {
if (rs1.getString("Name").equals("Date")||rs1.getString("Name").equals("Date+Time")||rs1.getString("Name").equals("Time"))
atts.addAttribute("","","value","CDATA", "" + rs.getTimestamp(i));
else
atts.addAttribute("","","value","CDATA", "" + rs.getObject(i));
}
if (!rs1.getString("ColumnName").equals("Created")&&!rs1.getString("ColumnName").equals("CreatedBy")&& if (!rs1.getString("ColumnName").equals("Created")&&!rs1.getString("ColumnName").equals("CreatedBy")&&
!rs1.getString("ColumnName").equals("Updated")&&!rs1.getString("ColumnName").equals("UpdatedBy")){ !rs1.getString("ColumnName").equals("Updated")&&!rs1.getString("ColumnName").equals("UpdatedBy")){
document.startElement("","","dcolumn",atts); document.startElement("","","dcolumn",atts);
@ -384,5 +442,95 @@ public class DataElementHandler extends AbstractElementHandler {
document.endElement("","","data"); document.endElement("","","data");
} }
private String getTableNameFromReferenceId(int referenceId){
String tableName = "";
String sql = " SELECT t.TableName FROM AD_Table T, AD_Ref_Table R "
+" WHERE T.AD_Table_ID=R.AD_Table_ID AND R.AD_Reference_ID=? ";
tableName= DB.getSQLValueString(null,sql,referenceId);
return tableName;
}
private String getSqlFromTableName(String tableName, int id, Properties ctx) throws Exception{
String result = null;
String sql = "SELECT count(a.ad_table_id) FROM ad_table a INNER JOIN ad_column b ON (a.ad_table_id = b.ad_table_id) "
+ "AND a.tablename = '" + tableName + "' AND UPPER(b.columnname) = 'VALUE'";
int count = DB.getSQLValue(null, sql);
String insertSqlValue = count <= 0
? ( "SELECT Name FROM "+tableName+" WHERE "+tableName+"_ID=?" )
: ( "SELECT Value FROM "+tableName+" WHERE "+tableName+"_ID=?" );
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
pstmt = DB.prepareStatement(insertSqlValue, getTrxName(ctx));
pstmt.setInt(1, id);
rs = pstmt.executeQuery();
if (rs.next()){
if (count <= 0)
result = "SELECT " +tableName+"_ID FROM "+tableName+" WHERE Name='"+rs.getString(1)+"'";
else
result = "SELECT " +tableName+"_ID FROM "+tableName+" WHERE Value='"+rs.getString(1)+"'";
result = result + " AND " + tableName + ".AD_Client_ID IN ( @AD_Client_ID@ , 0 )";
}
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
} finally {
DB.close(rs, pstmt);
}
return result;
}
private String getParentSql(String tableName, Properties ctx, int recordId) throws Exception{
String parentSql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
String sql = "SELECT A.ColumnName, A.AD_Reference_ID, A.AD_Reference_Value_ID "
+ "FROM AD_Column A, AD_Table T "
+ "Where A.AD_TABLE_ID = T.AD_Table_ID AND A.IsParent = 'Y' "
+ "AND UPPER(T.TableName)=? "
+ "AND A.ColumnName != 'AD_Client_ID' ";
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setString(1,tableName.toUpperCase());
rs = pstmt.executeQuery();
while(rs.next()){
if (rs.getInt("AD_Reference_ID") == DisplayType.Table || rs.getInt("AD_Reference_ID") == DisplayType.Search || rs.getInt("AD_Reference_ID") == DisplayType.TableDir){
String parentTableName = "";
if (rs.getInt("AD_Reference_ID") == DisplayType.TableDir){
//if rs1.getString("ColumnName") = C_EDIFORMAT_ID, tablename = C_EDIFORMAT
parentTableName = rs.getString("ColumnName").substring(0,rs.getString("ColumnName").length()-3);
}else{
//ad_ref_table.ad_reference_id = ad_reference_value_id
int referenceId = rs.getInt("AD_Reference_Value_ID");
parentTableName = getTableNameFromReferenceId(referenceId);
}
String parentIdSql = "SELECT "+parentTableName+"_ID FROM "+tableName+" WHERE "+tableName+"_ID = "+recordId;
int parentRecordId = DB.getSQLValue(null, parentIdSql);
parentSql = " AND "+rs.getString("ColumnName")+ " IN (" +getParentSql(parentTableName, ctx, parentRecordId)+")";
parentSql = parentSql + " AND " + tableName + ".AD_Client_ID IN ( @AD_Client_ID@ , 0 )";
}
}
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
} finally{
DB.close(rs, pstmt);
}
return parentSql;
}
} }

View File

@ -1,325 +1,330 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published * * under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope * * by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. * * See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* *
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com * Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* Contributor(s): Low Heng Sin hengsin@avantz.com * Contributor(s): Low Heng Sin hengsin@avantz.com
*****************************************************************************/ *****************************************************************************/
package org.adempiere.pipo.handler; package org.adempiere.pipo.handler;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Properties; import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler; import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.Element; import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackIn; import org.adempiere.pipo.PackIn;
import org.adempiere.pipo.PackOut; import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.exception.POSaveFailedException; import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.MField; import org.compiere.model.MField;
import org.compiere.model.X_AD_Field; import org.compiere.model.X_AD_Field;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
public class FieldElementHandler extends AbstractElementHandler { public class FieldElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
PackIn packIn = (PackIn)ctx.get("PackInProcess"); PackIn packIn = (PackIn)ctx.get("PackInProcess");
String elementValue = element.getElementValue(); String elementValue = element.getElementValue();
Attributes atts = element.attributes; Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("Name")); log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType"); String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("tab") && if (element.parent != null && element.parent.getElementValue().equals("tab") &&
element.parent.defer) { element.parent.defer) {
element.defer = true; element.defer = true;
return; element.unresolved = element.parent.unresolved;
} return;
String name = atts.getValue("Name"); }
String tabname = atts.getValue("ADTabNameID"); String name = atts.getValue("Name");
String colname = atts.getValue("ADColumnNameID"); String tabname = atts.getValue("ADTabNameID");
String tableName = atts.getValue("ADTableNameID"); String colname = atts.getValue("ADColumnNameID");
int tableid = packIn.getTableId(tableName); String tableName = atts.getValue("ADTableNameID");
if (tableid <= 0) { int tableid = packIn.getTableId(tableName);
tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName); if (tableid <= 0) {
if (tableid > 0) tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
packIn.addTable(tableName, tableid); if (tableid > 0)
} packIn.addTable(tableName, tableid);
if (tableid <= 0) { }
element.defer = true; if (tableid <= 0) {
return; element.unresolved = "AD_Table=" + tableName;
} element.defer = true;
int windowid = get_ID(ctx, "AD_Window", atts return;
.getValue("ADWindowNameID")); }
if (windowid <= 0) { int windowid = get_ID(ctx, "AD_Window", atts
element.defer = true; .getValue("ADWindowNameID"));
return; if (windowid <= 0) {
} element.defer = true;
int columnid = packIn.getColumnId(tableName, colname); element.unresolved = "AD_Window=" + atts.getValue("ADWindowNameID");
if (columnid <= 0) { return;
columnid = get_IDWithMasterAndColumn(ctx, "AD_Column", }
"ColumnName", colname, "AD_Table", tableid); int columnid = packIn.getColumnId(tableName, colname);
if (columnid > 0) if (columnid <= 0) {
packIn.addColumn(tableName, colname, columnid); columnid = get_IDWithMasterAndColumn(ctx, "AD_Column",
} "ColumnName", colname, "AD_Table", tableid);
if (columnid <= 0) { if (columnid > 0)
element.defer = true; packIn.addColumn(tableName, colname, columnid);
return; }
} if (columnid <= 0) {
int tabid = 0; element.defer = true;
if (element.parent != null && element.parent.getElementValue().equals("tab") && element.unresolved = "AD_Column"+ colname;
element.parent.recordId > 0) { return;
tabid = element.parent.recordId; }
} else { int tabid = 0;
StringBuffer sqlB = new StringBuffer( if (element.parent != null && element.parent.getElementValue().equals("tab") &&
"select AD_Tab_ID from AD_Tab where AD_Window_ID = " element.parent.recordId > 0) {
+ windowid).append(" and Name = '" + tabname + "'") tabid = element.parent.recordId;
.append(" and AD_Table_ID = ?"); } else {
tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), StringBuffer sqlB = new StringBuffer(
tableid); "select AD_Tab_ID from AD_Tab where AD_Window_ID = "
if (element.parent != null && element.parent.getElementValue().equals("tab") && tabid > 0) { + windowid).append(" and Name = '" + tabname + "'")
element.parent.recordId = tabid; .append(" and AD_Table_ID = ?");
} tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
} tableid);
if (tabid > 0) { if (element.parent != null && element.parent.getElementValue().equals("tab") && tabid > 0) {
StringBuffer sqlB = new StringBuffer( element.parent.recordId = tabid;
"select AD_Field_ID from AD_Field where AD_Column_ID = ") }
.append(columnid) }
.append(" and AD_Tab_ID = ?"); if (tabid > 0) {
int id = DB StringBuffer sqlB = new StringBuffer(
.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid); "select AD_Field_ID from AD_Field where AD_Column_ID = ")
MField m_Field = new MField(ctx, id, getTrxName(ctx)); .append(columnid)
int AD_Backup_ID = -1; .append(" and AD_Tab_ID = ?");
String Object_Status = null; int id = DB
if (id > 0) { .getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
AD_Backup_ID = copyRecord(ctx, "AD_Field", m_Field); MField m_Field = new MField(ctx, id, getTrxName(ctx));
Object_Status = "Update"; int AD_Backup_ID = -1;
} else { String Object_Status = null;
Object_Status = "New"; if (id > 0) {
AD_Backup_ID = 0; AD_Backup_ID = copyRecord(ctx, "AD_Field", m_Field);
} Object_Status = "Update";
m_Field.setName(atts.getValue("Name")); } else {
m_Field.setAD_Column_ID(columnid); Object_Status = "New";
name = atts.getValue("ADFieldGroupNameID"); AD_Backup_ID = 0;
id = get_IDWithColumn(ctx, "AD_FieldGroup", "Name", name); }
m_Field.setAD_FieldGroup_ID(id); m_Field.setName(atts.getValue("Name"));
m_Field.setAD_Tab_ID(tabid); m_Field.setAD_Column_ID(columnid);
m_Field.setEntityType(atts.getValue("EntityType")); name = atts.getValue("ADFieldGroupNameID");
m_Field.setIsSameLine(Boolean id = get_IDWithColumn(ctx, "AD_FieldGroup", "Name", name);
.valueOf(atts.getValue("SameLine")).booleanValue()); m_Field.setAD_FieldGroup_ID(id);
m_Field.setIsCentrallyMaintained(Boolean.valueOf( m_Field.setAD_Tab_ID(tabid);
atts.getValue("isCentrallyMaintained")).booleanValue()); m_Field.setEntityType(atts.getValue("EntityType"));
m_Field.setIsDisplayed(Boolean.valueOf( m_Field.setIsSameLine(Boolean
atts.getValue("Displayed")).booleanValue()); .valueOf(atts.getValue("SameLine")).booleanValue());
// m_Field.setIsEncrypted(Boolean.valueOf(atts.getValue("isEncrypted")).booleanValue()); m_Field.setIsCentrallyMaintained(Boolean.valueOf(
m_Field.setIsFieldOnly(Boolean.valueOf( atts.getValue("isCentrallyMaintained")).booleanValue());
atts.getValue("isFieldOnly")).booleanValue()); m_Field.setIsDisplayed(Boolean.valueOf(
m_Field.setIsHeading(Boolean atts.getValue("Displayed")).booleanValue());
.valueOf(atts.getValue("isHeading")).booleanValue()); // m_Field.setIsEncrypted(Boolean.valueOf(atts.getValue("isEncrypted")).booleanValue());
m_Field.setIsReadOnly(Boolean.valueOf( m_Field.setIsFieldOnly(Boolean.valueOf(
atts.getValue("isReadOnly")).booleanValue()); atts.getValue("isFieldOnly")).booleanValue());
m_Field.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); m_Field.setIsHeading(Boolean
m_Field.setDisplayLength(Integer.parseInt(atts .valueOf(atts.getValue("isHeading")).booleanValue());
.getValue("DisplayLength"))); m_Field.setIsReadOnly(Boolean.valueOf(
m_Field.setDescription(getStringValue(atts, "Description")); atts.getValue("isReadOnly")).booleanValue());
m_Field.setHelp(getStringValue(atts, "Help")); m_Field.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean m_Field.setDisplayLength(Integer.parseInt(atts
.valueOf(atts.getValue("isActive")).booleanValue() .getValue("DisplayLength")));
: true); m_Field.setDescription(getStringValue(atts, "Description"));
String sortNo = getStringValue(atts, "SortNo"); m_Field.setHelp(getStringValue(atts, "Help"));
if (sortNo != null) m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean
m_Field.setSortNo(new BigDecimal(sortNo)); .valueOf(atts.getValue("isActive")).booleanValue()
m_Field.setDisplayLogic(getStringValue(atts, "DisplayLogic")); : true);
String sortNo = getStringValue(atts, "SortNo");
String Name = atts.getValue("ADReferenceNameID"); if (sortNo != null)
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name); m_Field.setSortNo(new BigDecimal(sortNo));
m_Field.setAD_Reference_ID(id); m_Field.setDisplayLogic(getStringValue(atts, "DisplayLogic"));
Name = atts.getValue("ADValRuleNameID"); String Name = atts.getValue("ADReferenceNameID");
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name); id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
m_Field.setAD_Val_Rule_ID(id); m_Field.setAD_Reference_ID(id);
Name = atts.getValue("ADReferenceNameValueID");
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name); Name = atts.getValue("ADValRuleNameID");
m_Field.setAD_Reference_Value_ID(id); id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
m_Field.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass")); m_Field.setAD_Val_Rule_ID(id);
Name = atts.getValue("ADReferenceNameValueID");
if (m_Field.save(getTrxName(ctx)) == true) { id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
record_log(ctx, 1, m_Field.getName(), "Field", m_Field m_Field.setAD_Reference_Value_ID(id);
.get_ID(), AD_Backup_ID, Object_Status, "AD_Field", m_Field.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
get_IDWithColumn(ctx, "AD_Table", "TableName",
"AD_Field")); if (m_Field.save(getTrxName(ctx)) == true) {
element.recordId = m_Field.getAD_Field_ID(); record_log(ctx, 1, m_Field.getName(), "Field", m_Field
} else { .get_ID(), AD_Backup_ID, Object_Status, "AD_Field",
record_log(ctx, 0, m_Field.getName(), "Field", m_Field get_IDWithColumn(ctx, "AD_Table", "TableName",
.get_ID(), AD_Backup_ID, Object_Status, "AD_Field", "AD_Field"));
get_IDWithColumn(ctx, "AD_Table", "TableName", element.recordId = m_Field.getAD_Field_ID();
"AD_Field")); } else {
throw new POSaveFailedException("Failed to save field definition."); record_log(ctx, 0, m_Field.getName(), "Field", m_Field
} .get_ID(), AD_Backup_ID, Object_Status, "AD_Field",
} else { get_IDWithColumn(ctx, "AD_Table", "TableName",
element.defer = true; "AD_Field"));
return; throw new POSaveFailedException("Failed to save field definition.");
} }
} else { } else {
element.skip = true; element.defer = true;
} element.unresolved = "AD_Tab=" + tabname;
} return;
}
public void endElement(Properties ctx, Element element) throws SAXException { } else {
} element.skip = true;
}
public void create(Properties ctx, TransformerHandler document) }
throws SAXException {
int AD_Field_ID = Env.getContextAsInt(ctx, public void endElement(Properties ctx, Element element) throws SAXException {
X_AD_Field.COLUMNNAME_AD_Field_ID); }
X_AD_Field m_Field = new X_AD_Field(ctx, AD_Field_ID, null);
AttributesImpl atts = new AttributesImpl(); public void create(Properties ctx, TransformerHandler document)
createFieldBinding(atts, m_Field); throws SAXException {
int AD_Field_ID = Env.getContextAsInt(ctx,
PackOut packOut = (PackOut)ctx.get("PackOutProcess"); X_AD_Field.COLUMNNAME_AD_Field_ID);
X_AD_Field m_Field = new X_AD_Field(ctx, AD_Field_ID, null);
if(m_Field.getAD_FieldGroup_ID() > 0){ AttributesImpl atts = new AttributesImpl();
packOut.createFieldGroupElement(m_Field.getAD_FieldGroup_ID(), document); createFieldBinding(atts, m_Field);
}
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
if(m_Field.getAD_Reference_ID() > 0) {
packOut.createReference(m_Field.getAD_Reference_ID(), document); if(m_Field.getAD_FieldGroup_ID() > 0){
} packOut.createFieldGroupElement(m_Field.getAD_FieldGroup_ID(), document);
}
if (m_Field.getAD_Reference_Value_ID() > 0) {
packOut.createReference(m_Field.getAD_Reference_Value_ID(), document); if(m_Field.getAD_Reference_ID() > 0) {
} packOut.createReference(m_Field.getAD_Reference_ID(), document);
}
if (m_Field.getAD_Val_Rule_ID() > 0) {
packOut.createDynamicRuleValidation(m_Field.getAD_Val_Rule_ID(), document); if (m_Field.getAD_Reference_Value_ID() > 0) {
} packOut.createReference(m_Field.getAD_Reference_Value_ID(), document);
}
document.startElement("", "", "field", atts);
document.endElement("", "", "field"); if (m_Field.getAD_Val_Rule_ID() > 0) {
} packOut.createDynamicRuleValidation(m_Field.getAD_Val_Rule_ID(), document);
}
private AttributesImpl createFieldBinding(AttributesImpl atts,
X_AD_Field m_Field) { document.startElement("", "", "field", atts);
String sql = null; document.endElement("", "", "field");
String name = null; }
atts.clear();
if (m_Field.getAD_Column_ID() > 0) { private AttributesImpl createFieldBinding(AttributesImpl atts,
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; X_AD_Field m_Field) {
name = DB.getSQLValueString(null, sql, m_Field.getAD_Column_ID()); String sql = null;
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name); String name = null;
} else atts.clear();
atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); if (m_Field.getAD_Column_ID() > 0) {
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
if (m_Field.getAD_Column_ID() > 0) { name = DB.getSQLValueString(null, sql, m_Field.getAD_Column_ID());
sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
int idTable = DB.getSQLValue(null, sql, m_Field.getAD_Column_ID()); } else
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
name = DB.getSQLValueString(null, sql, idTable);
atts.addAttribute("", "", "ADTableNameID", "CDATA", name); if (m_Field.getAD_Column_ID() > 0) {
} else sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); int idTable = DB.getSQLValue(null, sql, m_Field.getAD_Column_ID());
if (m_Field.getAD_FieldGroup_ID() > 0) { sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
sql = "SELECT Name FROM AD_FieldGroup WHERE AD_FieldGroup_ID=?"; name = DB.getSQLValueString(null, sql, idTable);
name = DB.getSQLValueString(null, sql, m_Field atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
.getAD_FieldGroup_ID()); } else
atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", name); atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
} else if (m_Field.getAD_FieldGroup_ID() > 0) {
atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", ""); sql = "SELECT Name FROM AD_FieldGroup WHERE AD_FieldGroup_ID=?";
name = DB.getSQLValueString(null, sql, m_Field
if (m_Field.getAD_Field_ID() > 0) { .getAD_FieldGroup_ID());
sql = "SELECT Name FROM AD_Field WHERE AD_Field_ID=?"; atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", name);
name = DB.getSQLValueString(null, sql, m_Field.getAD_Field_ID()); } else
atts.addAttribute("", "", "ADFieldNameID", "CDATA", name); atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", "");
} else
atts.addAttribute("", "", "ADFieldNameID", "CDATA", ""); if (m_Field.getAD_Field_ID() > 0) {
sql = "SELECT Name FROM AD_Field WHERE AD_Field_ID=?";
if (m_Field.getAD_Tab_ID() > 0) { name = DB.getSQLValueString(null, sql, m_Field.getAD_Field_ID());
sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?"; atts.addAttribute("", "", "ADFieldNameID", "CDATA", name);
name = DB.getSQLValueString(null, sql, m_Field.getAD_Tab_ID()); } else
atts.addAttribute("", "", "ADTabNameID", "CDATA", name); atts.addAttribute("", "", "ADFieldNameID", "CDATA", "");
sql = "SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?";
int windowid = DB.getSQLValue(null, sql, m_Field.getAD_Tab_ID()); if (m_Field.getAD_Tab_ID() > 0) {
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?";
name = DB.getSQLValueString(null, sql, windowid); name = DB.getSQLValueString(null, sql, m_Field.getAD_Tab_ID());
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name); atts.addAttribute("", "", "ADTabNameID", "CDATA", name);
} else sql = "SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?";
atts.addAttribute("", "", "ADTabNameID", "CDATA", ""); int windowid = DB.getSQLValue(null, sql, m_Field.getAD_Tab_ID());
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
atts.addAttribute("", "", "EntityType", "CDATA", (m_Field name = DB.getSQLValueString(null, sql, windowid);
.getEntityType() != null ? m_Field.getEntityType() : "")); atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
atts.addAttribute("", "", "Name", "CDATA", } else
(m_Field.getName() != null ? m_Field.getName() : "")); atts.addAttribute("", "", "ADTabNameID", "CDATA", "");
atts.addAttribute("", "", "SameLine", "CDATA",
(m_Field.isSameLine() == true ? "true" : "false")); atts.addAttribute("", "", "EntityType", "CDATA", (m_Field
atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", (m_Field .getEntityType() != null ? m_Field.getEntityType() : ""));
.isCentrallyMaintained() == true ? "true" : "false")); atts.addAttribute("", "", "Name", "CDATA",
atts.addAttribute("", "", "Displayed", "CDATA", (m_Field.getName() != null ? m_Field.getName() : ""));
(m_Field.isDisplayed() == true ? "true" : "false")); atts.addAttribute("", "", "SameLine", "CDATA",
atts.addAttribute("", "", "isActive", "CDATA", (m_Field.isSameLine() == true ? "true" : "false"));
(m_Field.isActive() == true ? "true" : "false")); atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", (m_Field
atts.addAttribute("", "", "isEncrypted", "CDATA", (m_Field .isCentrallyMaintained() == true ? "true" : "false"));
.isEncrypted() == true ? "true" : "false")); atts.addAttribute("", "", "Displayed", "CDATA",
atts.addAttribute("", "", "isFieldOnly", "CDATA", (m_Field (m_Field.isDisplayed() == true ? "true" : "false"));
.isFieldOnly() == true ? "true" : "false")); atts.addAttribute("", "", "isActive", "CDATA",
atts.addAttribute("", "", "isHeading", "CDATA", (m_Field.isActive() == true ? "true" : "false"));
(m_Field.isHeading() == true ? "true" : "false")); atts.addAttribute("", "", "isEncrypted", "CDATA", (m_Field
atts.addAttribute("", "", "isReadOnly", "CDATA", .isEncrypted() == true ? "true" : "false"));
(m_Field.isReadOnly() == true ? "true" : "false")); atts.addAttribute("", "", "isFieldOnly", "CDATA", (m_Field
atts.addAttribute("", "", "SeqNo", "CDATA", "" + (m_Field.getSeqNo())); .isFieldOnly() == true ? "true" : "false"));
atts.addAttribute("", "", "DisplayLength", "CDATA", atts.addAttribute("", "", "isHeading", "CDATA",
(m_Field.getDisplayLength() > 0 ? "" (m_Field.isHeading() == true ? "true" : "false"));
+ m_Field.getDisplayLength() : "0")); atts.addAttribute("", "", "isReadOnly", "CDATA",
atts.addAttribute("", "", "Description", "CDATA", (m_Field (m_Field.isReadOnly() == true ? "true" : "false"));
.getDescription() != null ? m_Field.getDescription() : "")); atts.addAttribute("", "", "SeqNo", "CDATA", "" + (m_Field.getSeqNo()));
atts.addAttribute("", "", "Help", "CDATA", atts.addAttribute("", "", "DisplayLength", "CDATA",
(m_Field.getHelp() != null ? m_Field.getHelp() : "")); (m_Field.getDisplayLength() > 0 ? ""
atts.addAttribute("", "", "SortNo", "CDATA", + m_Field.getDisplayLength() : "0"));
(m_Field.getSortNo() != null ? m_Field.getSortNo().toString() atts.addAttribute("", "", "Description", "CDATA", (m_Field
: "")); .getDescription() != null ? m_Field.getDescription() : ""));
atts.addAttribute("", "", "DisplayLogic", "CDATA", (m_Field atts.addAttribute("", "", "Help", "CDATA",
.getDisplayLogic() != null ? m_Field.getDisplayLogic() : "")); (m_Field.getHelp() != null ? m_Field.getHelp() : ""));
atts.addAttribute("", "", "ObscureType", "CDATA", (m_Field atts.addAttribute("", "", "SortNo", "CDATA",
.getObscureType() != null ? m_Field.getObscureType() : "")); (m_Field.getSortNo() != null ? m_Field.getSortNo().toString()
: ""));
atts.addAttribute("", "", "InfoFactoryClass", "CDATA", (m_Field.getInfoFactoryClass() != null atts.addAttribute("", "", "DisplayLogic", "CDATA", (m_Field
? m_Field.getInfoFactoryClass() : "")); .getDisplayLogic() != null ? m_Field.getDisplayLogic() : ""));
atts.addAttribute("", "", "ObscureType", "CDATA", (m_Field
if (m_Field.getAD_Reference_ID() > 0) { .getObscureType() != null ? m_Field.getObscureType() : ""));
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
name = DB.getSQLValueString(null, sql, m_Field atts.addAttribute("", "", "InfoFactoryClass", "CDATA", (m_Field.getInfoFactoryClass() != null
.getAD_Reference_ID()); ? m_Field.getInfoFactoryClass() : ""));
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name);
} else if (m_Field.getAD_Reference_ID() > 0) {
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", ""); sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
if (m_Field.getAD_Reference_Value_ID() > 0) { name = DB.getSQLValueString(null, sql, m_Field
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; .getAD_Reference_ID());
name = DB.getSQLValueString(null, sql, m_Field atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name);
.getAD_Reference_Value_ID()); } else
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", name); atts.addAttribute("", "", "ADReferenceNameID", "CDATA", "");
} else if (m_Field.getAD_Reference_Value_ID() > 0) {
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", ""); sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
if (m_Field.getAD_Val_Rule_ID() > 0) { name = DB.getSQLValueString(null, sql, m_Field
sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?"; .getAD_Reference_Value_ID());
name = DB atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", name);
.getSQLValueString(null, sql, m_Field.getAD_Val_Rule_ID()); } else
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name); atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", "");
} else if (m_Field.getAD_Val_Rule_ID() > 0) {
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", ""); sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?";
name = DB
return atts; .getSQLValueString(null, sql, m_Field.getAD_Val_Rule_ID());
} atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name);
} } else
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", "");
return atts;
}
}

View File

@ -0,0 +1,30 @@
-- Aug 6, 2008 10:39:44 AM SGT
-- Packin to any client
UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2008-08-06 10:39:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50008
;
-- Aug 6, 2008 10:39:57 AM SGT
-- Packin to any client
UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2008-08-06 10:39:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50003
;
-- Aug 6, 2008 10:40:31 AM SGT
-- Packin to any client
DELETE FROM AD_Window_Access WHERE AD_Role_ID=102
;
-- Aug 6, 2008 10:40:32 AM SGT
-- Packin to any client
INSERT INTO AD_Window_Access (AD_Window_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT w.AD_Window_ID, 102,11,0,'Y', SysDate,100, SysDate,100,'Y' FROM AD_Window w INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID) INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) WHERE t.SeqNo=(SELECT MIN(SeqNo) FROM AD_Tab xt WHERE xt.AD_Window_ID=w.AD_Window_ID)AND tt.AccessLevel IN ('7','6','3','2','1')
;
-- Aug 6, 2008 10:40:32 AM SGT
-- Packin to any client
DELETE FROM AD_Process_Access WHERE AD_Role_ID=102
;
-- Aug 6, 2008 10:40:32 AM SGT
-- Packin to any client
INSERT INTO AD_Process_Access (AD_Process_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT p.AD_Process_ID, 102,11,0,'Y', SysDate,100, SysDate,100,'Y' FROM AD_Process p WHERE AccessLevel IN ('7','6','3','2','1')
;

View File

@ -0,0 +1,30 @@
-- Aug 6, 2008 10:39:44 AM SGT
-- Packin to any client
UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2008-08-06 10:39:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50008
;
-- Aug 6, 2008 10:39:57 AM SGT
-- Packin to any client
UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2008-08-06 10:39:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50003
;
-- Aug 6, 2008 10:40:32 AM SGT
-- Packin to any client
DELETE FROM AD_Window_Access WHERE AD_Role_ID=102
;
-- Aug 6, 2008 10:40:32 AM SGT
-- Packin to any client
INSERT INTO AD_Window_Access (AD_Window_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT w.AD_Window_ID, 102,11,0,'Y', CURRENT_TIMESTAMP,100, CURRENT_TIMESTAMP,100,'Y' FROM AD_Window w INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID) INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) WHERE t.SeqNo=(SELECT MIN(SeqNo) FROM AD_Tab xt WHERE xt.AD_Window_ID=w.AD_Window_ID)AND tt.AccessLevel IN ('7','6','3','2','1')
;
-- Aug 6, 2008 10:40:32 AM SGT
-- Packin to any client
DELETE FROM AD_Process_Access WHERE AD_Role_ID=102
;
-- Aug 6, 2008 10:40:32 AM SGT
-- Packin to any client
INSERT INTO AD_Process_Access (AD_Process_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT p.AD_Process_ID, 102,11,0,'Y', CURRENT_TIMESTAMP,100, CURRENT_TIMESTAMP,100,'Y' FROM AD_Process p WHERE AccessLevel IN ('7','6','3','2','1')
;