FR-1976008 - 2Pack can replicate Data with FK integrity
Changes done by Low Heng Sin
This commit is contained in:
parent
8ee2df3af6
commit
d0649726f5
|
@ -1,452 +1,456 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
|
||||
* 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 *
|
||||
* 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 *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* 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., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*
|
||||
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com *
|
||||
* Contributor(s): Low Heng Sin hengsin@avantz.com *
|
||||
*****************************************************************************/
|
||||
package org.adempiere.pipo;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.transform.sax.TransformerHandler;
|
||||
|
||||
import org.compiere.model.PO;
|
||||
import org.compiere.model.POInfo;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
public abstract class AbstractElementHandler implements ElementHandler {
|
||||
|
||||
protected CLogger log = CLogger.getCLogger("PackIn");
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table.
|
||||
* TODO: substitute with PO.getAllIDs
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
*
|
||||
*/
|
||||
public int get_ID (Properties ctx, String tableName, String name) {
|
||||
return IDFinder.get_ID(tableName, name, getClientId(ctx), getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from column value for a table.
|
||||
*
|
||||
* @param tableName
|
||||
* @param columName
|
||||
* @param name
|
||||
*/
|
||||
public int get_IDWithColumn (Properties ctx, String tableName, String columnName, Object value) {
|
||||
return IDFinder.get_IDWithColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write results to log and records in history table
|
||||
*
|
||||
* @param success
|
||||
* @param tableName
|
||||
* @param objectType
|
||||
* @param objectID
|
||||
* @param objectStatus
|
||||
* @throws SAXException
|
||||
*
|
||||
*/
|
||||
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{
|
||||
StringBuffer recordLayout = new StringBuffer();
|
||||
int id = 0;
|
||||
TransformerHandler hd_document = getLogDocument(ctx);
|
||||
AttributesImpl attsOut = new AttributesImpl();
|
||||
if (success == 1){
|
||||
//hd_documemt.startElement("","","Successfull",attsOut);
|
||||
recordLayout.append("Type:")
|
||||
.append(objectType)
|
||||
.append(" - Name:")
|
||||
.append(objectName)
|
||||
.append(" - ID:")
|
||||
.append(objectID)
|
||||
.append(" - Action:")
|
||||
.append(objectStatus)
|
||||
.append(" - Success");
|
||||
|
||||
hd_document.startElement("","","Success",attsOut);
|
||||
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
|
||||
hd_document.endElement("","","Success");
|
||||
//hd_documemt.endElement("","","Successfull");
|
||||
|
||||
//String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL";
|
||||
//int id = DB.getSQLValue(m_trxName, sql2)+1;
|
||||
|
||||
id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx));
|
||||
|
||||
StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail")
|
||||
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
|
||||
.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( "VALUES(" )
|
||||
.append( " "+ Env.getAD_Client_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_Org_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", " + id )
|
||||
.append( ", " + getPackageImpId(ctx) )
|
||||
.append( ", '" + objectType )
|
||||
.append( "', '" + objectName )
|
||||
.append( "', '" + objectStatus )
|
||||
.append( "', 'Success'" )
|
||||
.append( ", "+objectID )
|
||||
.append( ", "+objectIDBackup )
|
||||
.append( ", '"+tableName )
|
||||
.append( "', "+AD_Table_ID )
|
||||
.append(")");
|
||||
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
|
||||
if (no == -1)
|
||||
log.info("Insert to import detail failed");
|
||||
|
||||
}
|
||||
else{
|
||||
String PK_Status = "Completed with errors";
|
||||
hd_document.startElement("","","Failure",attsOut);
|
||||
recordLayout.append("Type:")
|
||||
.append(objectType)
|
||||
.append(" - Name:")
|
||||
.append(tableName)
|
||||
.append(" - ID:")
|
||||
.append(objectID)
|
||||
.append(" - Action:")
|
||||
.append(objectStatus)
|
||||
.append(" - Failure");
|
||||
//hd_documemt.startElement("","","Success",attsOut);
|
||||
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
|
||||
//hd_documemt.endElement("","","Success");
|
||||
hd_document.endElement("","","Failure");
|
||||
|
||||
//String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL";
|
||||
//int id = DB.getSQLValue(m_trxName,sql2)+1;
|
||||
|
||||
id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx));
|
||||
|
||||
StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail")
|
||||
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
|
||||
.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( "VALUES(" )
|
||||
.append( " "+ Env.getAD_Client_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_Org_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", " + id )
|
||||
.append( ", " + getPackageImpId(ctx) )
|
||||
.append( ", '" + objectType )
|
||||
.append( "', '" + objectName )
|
||||
.append( "', '" + objectStatus )
|
||||
.append( "', 'Failure'" )
|
||||
.append( ", "+objectID )
|
||||
.append( ", "+objectIDBackup )
|
||||
.append( ", '"+tableName )
|
||||
.append( "', "+AD_Table_ID )
|
||||
.append( ")");
|
||||
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
|
||||
if (no == -1)
|
||||
log.info("Insert to import detail failed");
|
||||
}
|
||||
|
||||
String Object_Status = "Status not set";
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table with a Master reference.
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
* @param tableNameMaster
|
||||
* @param nameMaster
|
||||
*/
|
||||
public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, String nameMaster) {
|
||||
return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, nameMaster, getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table with a Master reference.
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
* @param tableNameMaster
|
||||
* @param nameMaster
|
||||
*/
|
||||
|
||||
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,
|
||||
getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table with a Master reference ID.
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
* @param tableNameMaster
|
||||
* @param masterID
|
||||
*/
|
||||
public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, int masterID) {
|
||||
return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, masterID, getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table.
|
||||
* TODO: substitute with PO.getAllIDs
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
*/
|
||||
public int getIDbyName (Properties ctx, String tableName, String name) {
|
||||
return IDFinder.getIDbyName(tableName, name, getClientId(ctx), getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
POInfo poInfo = POInfo.getPOInfo(ctx, tableID, getTrxName(ctx));
|
||||
for (int i = 0; i < poInfo.getColumnCount(); i++){
|
||||
String colName = poInfo.getColumnName(i);
|
||||
colValue=null;
|
||||
|
||||
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+"'");
|
||||
int referenceID = DB.getSQLValue(getTrxName(ctx),sqlD.toString());
|
||||
|
||||
idBackup = DB.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
|
||||
|
||||
sqlD = new StringBuffer("SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL");
|
||||
int idDetail = DB.getSQLValue(getTrxName(ctx),sqlD.toString())+1;
|
||||
|
||||
if (referenceID == 10 || referenceID == 14 || referenceID == 34 || referenceID == 17)
|
||||
if (from.get_Value(i)!= null)
|
||||
colValue = from.get_Value(i).toString().replaceAll("'","''");
|
||||
else if (referenceID == 20|| referenceID == 28)
|
||||
if (from.get_Value(i)!= null)
|
||||
colValue = from.get_Value(i).toString().replaceAll("'","''");
|
||||
else
|
||||
;//Ignore
|
||||
|
||||
StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Backup")
|
||||
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
|
||||
.append( "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," )
|
||||
.append( " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" )
|
||||
.append( "VALUES(" )
|
||||
.append( " "+ Env.getAD_Client_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_Org_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", " + idBackup )
|
||||
.append( ", " + idDetail )
|
||||
.append( ", " + getPackageImpId(ctx) )
|
||||
.append( ", " + tableID )
|
||||
.append( ", " + (columnID == -1 ? "null" : columnID) )
|
||||
.append( ", " + (referenceID == -1 ? "null" : referenceID) )
|
||||
.append( ", '" + (colValue != null ? colValue : from.get_Value(i)) )
|
||||
.append( "')");
|
||||
|
||||
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
|
||||
if (no == -1)
|
||||
log.info("Insert to import backup failed");
|
||||
//}
|
||||
}
|
||||
return idBackup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open input file for processing
|
||||
*
|
||||
* @param String file with path
|
||||
*
|
||||
*/
|
||||
public FileInputStream OpenInputfile (String filePath) {
|
||||
|
||||
FileInputStream fileTarget = null;
|
||||
|
||||
try {
|
||||
fileTarget = new FileInputStream(filePath);
|
||||
}
|
||||
catch (FileNotFoundException e ) {
|
||||
System.out.println("File not found: " + filePath);
|
||||
|
||||
return null;
|
||||
}
|
||||
return fileTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open output file for processing
|
||||
*
|
||||
* @param String file with path
|
||||
*
|
||||
*/
|
||||
public OutputStream OpenOutputfile (String filePath) {
|
||||
|
||||
OutputStream fileTarget = null;
|
||||
|
||||
try {
|
||||
fileTarget = new FileOutputStream(filePath);
|
||||
}
|
||||
catch (FileNotFoundException e ) {
|
||||
System.out.println("File not found: " + filePath);
|
||||
|
||||
return null;
|
||||
}
|
||||
return fileTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copyfile
|
||||
*
|
||||
* @param String file with path
|
||||
*
|
||||
*/
|
||||
public int copyFile (InputStream source,OutputStream target) {
|
||||
|
||||
int byteCount = 0;
|
||||
int success = 0;
|
||||
try {
|
||||
while (true) {
|
||||
int data = source.read();
|
||||
if (data < 0)
|
||||
break;
|
||||
target.write(data);
|
||||
byteCount++;
|
||||
}
|
||||
source.close();
|
||||
target.close();
|
||||
//System.out.println("Successfully copied " + byteCount + " bytes.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("Error occurred while copying. "+ byteCount + " bytes copied.");
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
|
||||
success = -1;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client id
|
||||
* @param ctx
|
||||
* @return int
|
||||
*/
|
||||
protected int getClientId(Properties ctx) {
|
||||
return Env.getContextAsInt(ctx, "AD_Client_ID");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AD_Package_Imp_ID
|
||||
* @param ctx
|
||||
* @return int
|
||||
*/
|
||||
protected int getPackageImpId(Properties ctx) {
|
||||
return Env.getContextAsInt(ctx, "AD_Package_Imp_ID");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get update system maintained dictionary flag
|
||||
* @param ctx
|
||||
* @return update mode
|
||||
*/
|
||||
protected String getUpdateMode(Properties ctx) {
|
||||
return Env.getContext(ctx, "UpdateMode");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current transaction name
|
||||
* @param ctx
|
||||
* @return transaction name
|
||||
*/
|
||||
protected String getTrxName(Properties ctx) {
|
||||
return Env.getContext(ctx, "TrxName");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get share document
|
||||
* @param ctx
|
||||
* @return TransformerHandler
|
||||
*/
|
||||
protected TransformerHandler getLogDocument(Properties ctx) {
|
||||
return (TransformerHandler)ctx.get("LogDocument");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ctx
|
||||
* @return package directory
|
||||
*/
|
||||
protected String getPackageDirectory(Properties ctx) {
|
||||
return Env.getContext(ctx, "PackageDirectory");
|
||||
}
|
||||
|
||||
/**
|
||||
* Process element by entity type and user setting.
|
||||
* @param ctx
|
||||
* @param entityType
|
||||
* @return boolean
|
||||
*/
|
||||
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
|
||||
*/
|
||||
protected String getStringValue(Attributes atts, String qName) {
|
||||
String s = atts.getValue(qName);
|
||||
return ("".equals(s) ? null : s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns option - Is export-import of AD translations is needed
|
||||
* @param ctx
|
||||
* @param entityType
|
||||
* @return boolean
|
||||
*/
|
||||
protected boolean isHandleTranslations(Properties ctx) {
|
||||
|
||||
return "true".equalsIgnoreCase(Env.getContext(ctx, "isHandleTranslations"));
|
||||
}
|
||||
}
|
||||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
|
||||
* 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 *
|
||||
* 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 *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* 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., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*
|
||||
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com *
|
||||
* Contributor(s): Low Heng Sin hengsin@avantz.com *
|
||||
*****************************************************************************/
|
||||
package org.adempiere.pipo;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.transform.sax.TransformerHandler;
|
||||
|
||||
import org.compiere.model.PO;
|
||||
import org.compiere.model.POInfo;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
public abstract class AbstractElementHandler implements ElementHandler {
|
||||
|
||||
protected CLogger log = CLogger.getCLogger("PackIn");
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table.
|
||||
* TODO: substitute with PO.getAllIDs
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
*
|
||||
*/
|
||||
public int get_ID (Properties ctx, String tableName, String name) {
|
||||
return IDFinder.get_ID(tableName, name, getClientId(ctx), getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from column value for a table.
|
||||
*
|
||||
* @param tableName
|
||||
* @param columName
|
||||
* @param name
|
||||
*/
|
||||
public int get_IDWithColumn (Properties ctx, String tableName, String columnName, Object value) {
|
||||
return IDFinder.get_IDWithColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write results to log and records in history table
|
||||
*
|
||||
* @param success
|
||||
* @param tableName
|
||||
* @param objectType
|
||||
* @param objectID
|
||||
* @param objectStatus
|
||||
* @throws SAXException
|
||||
*
|
||||
*/
|
||||
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{
|
||||
StringBuffer recordLayout = new StringBuffer();
|
||||
int id = 0;
|
||||
TransformerHandler hd_document = getLogDocument(ctx);
|
||||
AttributesImpl attsOut = new AttributesImpl();
|
||||
if (success == 1){
|
||||
//hd_documemt.startElement("","","Successfull",attsOut);
|
||||
recordLayout.append("Type:")
|
||||
.append(objectType)
|
||||
.append(" - Name:")
|
||||
.append(objectName)
|
||||
.append(" - ID:")
|
||||
.append(objectID)
|
||||
.append(" - Action:")
|
||||
.append(objectStatus)
|
||||
.append(" - Success");
|
||||
|
||||
hd_document.startElement("","","Success",attsOut);
|
||||
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
|
||||
hd_document.endElement("","","Success");
|
||||
//hd_documemt.endElement("","","Successfull");
|
||||
|
||||
//String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL";
|
||||
//int id = DB.getSQLValue(m_trxName, sql2)+1;
|
||||
|
||||
id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx));
|
||||
|
||||
StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail")
|
||||
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
|
||||
.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( "VALUES(" )
|
||||
.append( " ?")
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?")
|
||||
.append(")");
|
||||
Object[] param = new Object[] { Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx), Env.getAD_User_ID(ctx), Env.getAD_User_ID(ctx),
|
||||
id, getPackageImpId(ctx) , objectType, objectName, objectStatus, "Success", objectID, objectIDBackup, tableName,
|
||||
AD_Table_ID
|
||||
};
|
||||
int no = DB.executeUpdate (sqlB.toString(), param, true, getTrxName(ctx));
|
||||
if (no == -1)
|
||||
log.info("Insert to import detail failed");
|
||||
|
||||
}
|
||||
else{
|
||||
String PK_Status = "Completed with errors";
|
||||
hd_document.startElement("","","Failure",attsOut);
|
||||
recordLayout.append("Type:")
|
||||
.append(objectType)
|
||||
.append(" - Name:")
|
||||
.append(tableName)
|
||||
.append(" - ID:")
|
||||
.append(objectID)
|
||||
.append(" - Action:")
|
||||
.append(objectStatus)
|
||||
.append(" - Failure");
|
||||
//hd_documemt.startElement("","","Success",attsOut);
|
||||
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
|
||||
//hd_documemt.endElement("","","Success");
|
||||
hd_document.endElement("","","Failure");
|
||||
|
||||
//String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL";
|
||||
//int id = DB.getSQLValue(m_trxName,sql2)+1;
|
||||
|
||||
id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx));
|
||||
|
||||
StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail")
|
||||
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
|
||||
.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( "VALUES(" )
|
||||
.append( " "+ Env.getAD_Client_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_Org_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", " + id )
|
||||
.append( ", " + getPackageImpId(ctx) )
|
||||
.append( ", '" + objectType )
|
||||
.append( "', '" + objectName )
|
||||
.append( "', '" + objectStatus )
|
||||
.append( "', 'Failure'" )
|
||||
.append( ", "+objectID )
|
||||
.append( ", "+objectIDBackup )
|
||||
.append( ", '"+tableName )
|
||||
.append( "', "+AD_Table_ID )
|
||||
.append( ")");
|
||||
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
|
||||
if (no == -1)
|
||||
log.info("Insert to import detail failed");
|
||||
}
|
||||
|
||||
String Object_Status = "Status not set";
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table with a Master reference.
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
* @param tableNameMaster
|
||||
* @param nameMaster
|
||||
*/
|
||||
public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, String nameMaster) {
|
||||
return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, nameMaster, getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table with a Master reference.
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
* @param tableNameMaster
|
||||
* @param nameMaster
|
||||
*/
|
||||
|
||||
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,
|
||||
getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table with a Master reference ID.
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
* @param tableNameMaster
|
||||
* @param masterID
|
||||
*/
|
||||
public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, int masterID) {
|
||||
return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, masterID, getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID from Name for a table.
|
||||
* TODO: substitute with PO.getAllIDs
|
||||
*
|
||||
* @param tableName
|
||||
* @param name
|
||||
*/
|
||||
public int getIDbyName (Properties ctx, String tableName, String name) {
|
||||
return IDFinder.getIDbyName(tableName, name, getClientId(ctx), getTrxName(ctx));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
POInfo poInfo = POInfo.getPOInfo(ctx, tableID, getTrxName(ctx));
|
||||
for (int i = 0; i < poInfo.getColumnCount(); i++){
|
||||
String colName = poInfo.getColumnName(i);
|
||||
colValue=null;
|
||||
|
||||
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+"'");
|
||||
int referenceID = DB.getSQLValue(getTrxName(ctx),sqlD.toString());
|
||||
|
||||
idBackup = DB.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx));
|
||||
|
||||
sqlD = new StringBuffer("SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL");
|
||||
int idDetail = DB.getSQLValue(getTrxName(ctx),sqlD.toString())+1;
|
||||
|
||||
if (referenceID == 10 || referenceID == 14 || referenceID == 34 || referenceID == 17)
|
||||
if (from.get_Value(i)!= null)
|
||||
colValue = from.get_Value(i).toString().replaceAll("'","''");
|
||||
else if (referenceID == 20|| referenceID == 28)
|
||||
if (from.get_Value(i)!= null)
|
||||
colValue = from.get_Value(i).toString().replaceAll("'","''");
|
||||
else
|
||||
;//Ignore
|
||||
|
||||
StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Backup")
|
||||
.append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " )
|
||||
.append( "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," )
|
||||
.append( " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" )
|
||||
.append( "VALUES(" )
|
||||
.append( " "+ Env.getAD_Client_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_Org_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", " + idBackup )
|
||||
.append( ", " + idDetail )
|
||||
.append( ", " + getPackageImpId(ctx) )
|
||||
.append( ", " + tableID )
|
||||
.append( ", " + (columnID == -1 ? "null" : columnID) )
|
||||
.append( ", " + (referenceID == -1 ? "null" : referenceID) )
|
||||
.append( ", '" + (colValue != null ? colValue : from.get_Value(i)) )
|
||||
.append( "')");
|
||||
|
||||
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
|
||||
if (no == -1)
|
||||
log.info("Insert to import backup failed");
|
||||
//}
|
||||
}
|
||||
return idBackup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open input file for processing
|
||||
*
|
||||
* @param String file with path
|
||||
*
|
||||
*/
|
||||
public FileInputStream OpenInputfile (String filePath) {
|
||||
|
||||
FileInputStream fileTarget = null;
|
||||
|
||||
try {
|
||||
fileTarget = new FileInputStream(filePath);
|
||||
}
|
||||
catch (FileNotFoundException e ) {
|
||||
System.out.println("File not found: " + filePath);
|
||||
|
||||
return null;
|
||||
}
|
||||
return fileTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open output file for processing
|
||||
*
|
||||
* @param String file with path
|
||||
*
|
||||
*/
|
||||
public OutputStream OpenOutputfile (String filePath) {
|
||||
|
||||
OutputStream fileTarget = null;
|
||||
|
||||
try {
|
||||
fileTarget = new FileOutputStream(filePath);
|
||||
}
|
||||
catch (FileNotFoundException e ) {
|
||||
System.out.println("File not found: " + filePath);
|
||||
|
||||
return null;
|
||||
}
|
||||
return fileTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copyfile
|
||||
*
|
||||
* @param String file with path
|
||||
*
|
||||
*/
|
||||
public int copyFile (InputStream source,OutputStream target) {
|
||||
|
||||
int byteCount = 0;
|
||||
int success = 0;
|
||||
try {
|
||||
while (true) {
|
||||
int data = source.read();
|
||||
if (data < 0)
|
||||
break;
|
||||
target.write(data);
|
||||
byteCount++;
|
||||
}
|
||||
source.close();
|
||||
target.close();
|
||||
//System.out.println("Successfully copied " + byteCount + " bytes.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("Error occurred while copying. "+ byteCount + " bytes copied.");
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
|
||||
success = -1;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client id
|
||||
* @param ctx
|
||||
* @return int
|
||||
*/
|
||||
protected int getClientId(Properties ctx) {
|
||||
return Env.getContextAsInt(ctx, "AD_Client_ID");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AD_Package_Imp_ID
|
||||
* @param ctx
|
||||
* @return int
|
||||
*/
|
||||
protected int getPackageImpId(Properties ctx) {
|
||||
return Env.getContextAsInt(ctx, "AD_Package_Imp_ID");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get update system maintained dictionary flag
|
||||
* @param ctx
|
||||
* @return update mode
|
||||
*/
|
||||
protected String getUpdateMode(Properties ctx) {
|
||||
return Env.getContext(ctx, "UpdateMode");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current transaction name
|
||||
* @param ctx
|
||||
* @return transaction name
|
||||
*/
|
||||
protected String getTrxName(Properties ctx) {
|
||||
return Env.getContext(ctx, "TrxName");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get share document
|
||||
* @param ctx
|
||||
* @return TransformerHandler
|
||||
*/
|
||||
protected TransformerHandler getLogDocument(Properties ctx) {
|
||||
return (TransformerHandler)ctx.get("LogDocument");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ctx
|
||||
* @return package directory
|
||||
*/
|
||||
protected String getPackageDirectory(Properties ctx) {
|
||||
return Env.getContext(ctx, "PackageDirectory");
|
||||
}
|
||||
|
||||
/**
|
||||
* Process element by entity type and user setting.
|
||||
* @param ctx
|
||||
* @param entityType
|
||||
* @return boolean
|
||||
*/
|
||||
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
|
||||
*/
|
||||
protected String getStringValue(Attributes atts, String qName) {
|
||||
String s = atts.getValue(qName);
|
||||
return ("".equals(s) ? null : s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns option - Is export-import of AD translations is needed
|
||||
* @param ctx
|
||||
* @param entityType
|
||||
* @return boolean
|
||||
*/
|
||||
protected boolean isHandleTranslations(Properties ctx) {
|
||||
|
||||
return "true".equalsIgnoreCase(Env.getContext(ctx, "isHandleTranslations"));
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,8 +23,7 @@ import java.sql.ResultSetMetaData;
|
|||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
@ -38,11 +37,18 @@ import org.adempiere.pipo.exception.POSaveFailedException;
|
|||
import org.compiere.model.POInfo;
|
||||
import org.compiere.model.X_AD_Package_Exp_Detail;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robert Klein.
|
||||
* @author Low Heng Sin
|
||||
*
|
||||
*/
|
||||
public class DataElementHandler extends AbstractElementHandler {
|
||||
|
||||
private GenericPO genericPO = null;
|
||||
|
@ -93,41 +99,41 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
public void startElement(Properties ctx, Element element) throws SAXException {
|
||||
String elementValue = element.getElementValue();
|
||||
Attributes atts = element.attributes;
|
||||
log.info(elementValue+" "+atts.getValue("name"));
|
||||
String d_rowname = atts.getValue("name");
|
||||
|
||||
// name can be null if there are keyXname attributes.
|
||||
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 {
|
||||
log.info(elementValue+" "+atts.getValue("name"));
|
||||
|
||||
// use keyXname and lookupkeyXname if available
|
||||
if (atts.getValue("key1name") != null && atts.getValue("key1name").trim().length() > 0)
|
||||
{
|
||||
String sql = "select * from "+d_tablename;
|
||||
String whereand = " where";
|
||||
String CURRENT_KEY = "key1name";
|
||||
if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) {
|
||||
sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY);
|
||||
whereand = " and";
|
||||
|
||||
List<String>params = new ArrayList<String>();
|
||||
int keyIndex = 1;
|
||||
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("")) {
|
||||
sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY);
|
||||
whereand = " and";
|
||||
|
||||
if (getClientId(ctx) > 0) {
|
||||
sql = sql + whereand + " " + d_tablename + ".AD_Client_ID in (0, " + getClientId(ctx) + ")";
|
||||
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
|
||||
try {
|
||||
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();
|
||||
if (rs.next()) {
|
||||
|
@ -143,20 +149,23 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
pstmt.close();
|
||||
pstmt = null;
|
||||
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) {
|
||||
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
|
||||
if (getClientId(ctx) > 0 && genericPO.getAD_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));
|
||||
}
|
||||
}
|
||||
}
|
||||
genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx));
|
||||
}
|
||||
|
||||
public void endElement(Properties ctx, Element element) throws SAXException {
|
||||
|
@ -224,6 +211,10 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
String columnName = atts.getValue("name");
|
||||
int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename);
|
||||
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 = ?");
|
||||
String isUpdateable = DB.getSQLValueString(getTrxName(ctx), sql.toString(),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") &&
|
||||
isUpdateable.equals("Y") &&
|
||||
(!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")
|
||||
|| atts.getValue("class").equals("List")|| atts.getValue("class").equals("Yes-No")
|
||||
|| atts.getValue("class").equals("Button")
|
||||
|| 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")
|
||||
|| 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")
|
||||
|| 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("Color)")|| atts.getValue("class").equals("Search")
|
||||
|| 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")) {
|
||||
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")
|
||||
|| 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
|
||||
} else { // value is null
|
||||
if (atts.getValue("lookupname") != null && !"".equals(atts.getValue("lookupname"))) {
|
||||
// globalqss - bring support from XML2AD to lookupname
|
||||
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"))));
|
||||
} 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)
|
||||
throws SAXException {
|
||||
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);
|
||||
while (rs.next()){
|
||||
atts.clear();
|
||||
int key1 = 0;
|
||||
int keyIndex = 0;
|
||||
String nameatts = "";
|
||||
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 "
|
||||
+ "WHERE isIdentifier = '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) && key1 == 0 ){
|
||||
atts.addAttribute("","","key1name","CDATA",cName);
|
||||
atts.addAttribute("","","lookupkey1name","CDATA",""+rs.getObject(col_Name));
|
||||
key1 = 1;
|
||||
if (cName.toUpperCase().equals(col_Name)){
|
||||
keyIndex++;
|
||||
atts.addAttribute("","","key" + keyIndex + "name","CDATA",cName);
|
||||
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);
|
||||
if ( key1 == 0 ){
|
||||
if ( keyIndex == 0 ){
|
||||
atts.addAttribute("","","key1name","CDATA","");
|
||||
atts.addAttribute("","","lookupkey1name","CDATA","");
|
||||
key1 = 1;
|
||||
keyIndex++;
|
||||
}
|
||||
if ( key1 == 1 ){
|
||||
if ( keyIndex == 1 ){
|
||||
atts.addAttribute("","","key2name","CDATA","");
|
||||
atts.addAttribute("","","lookupkey2name","CDATA","");
|
||||
}
|
||||
|
@ -333,11 +351,12 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
for (i=1 ;i <= columns;i++){
|
||||
atts.clear();
|
||||
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 "
|
||||
+ "Where Upper(A.columnname) = ? 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;
|
||||
try
|
||||
{
|
||||
|
@ -350,11 +369,50 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
atts.clear();
|
||||
atts.addAttribute("","","name","CDATA", rs1.getString("ColumnName"));
|
||||
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")&&
|
||||
!rs1.getString("ColumnName").equals("Updated")&&!rs1.getString("ColumnName").equals("UpdatedBy")){
|
||||
document.startElement("","","dcolumn",atts);
|
||||
|
@ -384,5 +442,95 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,325 +1,330 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
|
||||
* 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 *
|
||||
* 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 *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* 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., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*
|
||||
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
|
||||
* Contributor(s): Low Heng Sin hengsin@avantz.com
|
||||
*****************************************************************************/
|
||||
package org.adempiere.pipo.handler;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.xml.transform.sax.TransformerHandler;
|
||||
|
||||
import org.adempiere.pipo.AbstractElementHandler;
|
||||
import org.adempiere.pipo.Element;
|
||||
import org.adempiere.pipo.PackIn;
|
||||
import org.adempiere.pipo.PackOut;
|
||||
import org.adempiere.pipo.exception.POSaveFailedException;
|
||||
import org.compiere.model.MField;
|
||||
import org.compiere.model.X_AD_Field;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
public class FieldElementHandler extends AbstractElementHandler {
|
||||
|
||||
public void startElement(Properties ctx, Element element)
|
||||
throws SAXException {
|
||||
PackIn packIn = (PackIn)ctx.get("PackInProcess");
|
||||
String elementValue = element.getElementValue();
|
||||
Attributes atts = element.attributes;
|
||||
log.info(elementValue + " " + atts.getValue("Name"));
|
||||
String entitytype = atts.getValue("EntityType");
|
||||
if (isProcessElement(ctx, entitytype)) {
|
||||
if (element.parent != null && element.parent.getElementValue().equals("tab") &&
|
||||
element.parent.defer) {
|
||||
element.defer = true;
|
||||
return;
|
||||
}
|
||||
String name = atts.getValue("Name");
|
||||
String tabname = atts.getValue("ADTabNameID");
|
||||
String colname = atts.getValue("ADColumnNameID");
|
||||
String tableName = atts.getValue("ADTableNameID");
|
||||
int tableid = packIn.getTableId(tableName);
|
||||
if (tableid <= 0) {
|
||||
tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
|
||||
if (tableid > 0)
|
||||
packIn.addTable(tableName, tableid);
|
||||
}
|
||||
if (tableid <= 0) {
|
||||
element.defer = true;
|
||||
return;
|
||||
}
|
||||
int windowid = get_ID(ctx, "AD_Window", atts
|
||||
.getValue("ADWindowNameID"));
|
||||
if (windowid <= 0) {
|
||||
element.defer = true;
|
||||
return;
|
||||
}
|
||||
int columnid = packIn.getColumnId(tableName, colname);
|
||||
if (columnid <= 0) {
|
||||
columnid = get_IDWithMasterAndColumn(ctx, "AD_Column",
|
||||
"ColumnName", colname, "AD_Table", tableid);
|
||||
if (columnid > 0)
|
||||
packIn.addColumn(tableName, colname, columnid);
|
||||
}
|
||||
if (columnid <= 0) {
|
||||
element.defer = true;
|
||||
return;
|
||||
}
|
||||
int tabid = 0;
|
||||
if (element.parent != null && element.parent.getElementValue().equals("tab") &&
|
||||
element.parent.recordId > 0) {
|
||||
tabid = element.parent.recordId;
|
||||
} else {
|
||||
StringBuffer sqlB = new StringBuffer(
|
||||
"select AD_Tab_ID from AD_Tab where AD_Window_ID = "
|
||||
+ windowid).append(" and Name = '" + tabname + "'")
|
||||
.append(" and AD_Table_ID = ?");
|
||||
tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
|
||||
tableid);
|
||||
if (element.parent != null && element.parent.getElementValue().equals("tab") && tabid > 0) {
|
||||
element.parent.recordId = tabid;
|
||||
}
|
||||
}
|
||||
if (tabid > 0) {
|
||||
StringBuffer sqlB = new StringBuffer(
|
||||
"select AD_Field_ID from AD_Field where AD_Column_ID = ")
|
||||
.append(columnid)
|
||||
.append(" and AD_Tab_ID = ?");
|
||||
int id = DB
|
||||
.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
|
||||
MField m_Field = new MField(ctx, id, getTrxName(ctx));
|
||||
int AD_Backup_ID = -1;
|
||||
String Object_Status = null;
|
||||
if (id > 0) {
|
||||
AD_Backup_ID = copyRecord(ctx, "AD_Field", m_Field);
|
||||
Object_Status = "Update";
|
||||
} else {
|
||||
Object_Status = "New";
|
||||
AD_Backup_ID = 0;
|
||||
}
|
||||
m_Field.setName(atts.getValue("Name"));
|
||||
m_Field.setAD_Column_ID(columnid);
|
||||
name = atts.getValue("ADFieldGroupNameID");
|
||||
id = get_IDWithColumn(ctx, "AD_FieldGroup", "Name", name);
|
||||
m_Field.setAD_FieldGroup_ID(id);
|
||||
m_Field.setAD_Tab_ID(tabid);
|
||||
m_Field.setEntityType(atts.getValue("EntityType"));
|
||||
m_Field.setIsSameLine(Boolean
|
||||
.valueOf(atts.getValue("SameLine")).booleanValue());
|
||||
m_Field.setIsCentrallyMaintained(Boolean.valueOf(
|
||||
atts.getValue("isCentrallyMaintained")).booleanValue());
|
||||
m_Field.setIsDisplayed(Boolean.valueOf(
|
||||
atts.getValue("Displayed")).booleanValue());
|
||||
// m_Field.setIsEncrypted(Boolean.valueOf(atts.getValue("isEncrypted")).booleanValue());
|
||||
m_Field.setIsFieldOnly(Boolean.valueOf(
|
||||
atts.getValue("isFieldOnly")).booleanValue());
|
||||
m_Field.setIsHeading(Boolean
|
||||
.valueOf(atts.getValue("isHeading")).booleanValue());
|
||||
m_Field.setIsReadOnly(Boolean.valueOf(
|
||||
atts.getValue("isReadOnly")).booleanValue());
|
||||
m_Field.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
|
||||
m_Field.setDisplayLength(Integer.parseInt(atts
|
||||
.getValue("DisplayLength")));
|
||||
m_Field.setDescription(getStringValue(atts, "Description"));
|
||||
m_Field.setHelp(getStringValue(atts, "Help"));
|
||||
m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean
|
||||
.valueOf(atts.getValue("isActive")).booleanValue()
|
||||
: true);
|
||||
String sortNo = getStringValue(atts, "SortNo");
|
||||
if (sortNo != null)
|
||||
m_Field.setSortNo(new BigDecimal(sortNo));
|
||||
m_Field.setDisplayLogic(getStringValue(atts, "DisplayLogic"));
|
||||
|
||||
String Name = atts.getValue("ADReferenceNameID");
|
||||
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
|
||||
m_Field.setAD_Reference_ID(id);
|
||||
|
||||
Name = atts.getValue("ADValRuleNameID");
|
||||
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
|
||||
m_Field.setAD_Val_Rule_ID(id);
|
||||
Name = atts.getValue("ADReferenceNameValueID");
|
||||
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
|
||||
m_Field.setAD_Reference_Value_ID(id);
|
||||
m_Field.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
|
||||
|
||||
if (m_Field.save(getTrxName(ctx)) == true) {
|
||||
record_log(ctx, 1, m_Field.getName(), "Field", m_Field
|
||||
.get_ID(), AD_Backup_ID, Object_Status, "AD_Field",
|
||||
get_IDWithColumn(ctx, "AD_Table", "TableName",
|
||||
"AD_Field"));
|
||||
element.recordId = m_Field.getAD_Field_ID();
|
||||
} else {
|
||||
record_log(ctx, 0, m_Field.getName(), "Field", m_Field
|
||||
.get_ID(), AD_Backup_ID, Object_Status, "AD_Field",
|
||||
get_IDWithColumn(ctx, "AD_Table", "TableName",
|
||||
"AD_Field"));
|
||||
throw new POSaveFailedException("Failed to save field definition.");
|
||||
}
|
||||
} else {
|
||||
element.defer = true;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
element.skip = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(Properties ctx, Element element) throws SAXException {
|
||||
}
|
||||
|
||||
public void create(Properties ctx, TransformerHandler document)
|
||||
throws SAXException {
|
||||
int AD_Field_ID = Env.getContextAsInt(ctx,
|
||||
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();
|
||||
createFieldBinding(atts, m_Field);
|
||||
|
||||
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
|
||||
|
||||
if(m_Field.getAD_FieldGroup_ID() > 0){
|
||||
packOut.createFieldGroupElement(m_Field.getAD_FieldGroup_ID(), document);
|
||||
}
|
||||
|
||||
if(m_Field.getAD_Reference_ID() > 0) {
|
||||
packOut.createReference(m_Field.getAD_Reference_ID(), document);
|
||||
}
|
||||
|
||||
if (m_Field.getAD_Reference_Value_ID() > 0) {
|
||||
packOut.createReference(m_Field.getAD_Reference_Value_ID(), document);
|
||||
}
|
||||
|
||||
if (m_Field.getAD_Val_Rule_ID() > 0) {
|
||||
packOut.createDynamicRuleValidation(m_Field.getAD_Val_Rule_ID(), document);
|
||||
}
|
||||
|
||||
document.startElement("", "", "field", atts);
|
||||
document.endElement("", "", "field");
|
||||
}
|
||||
|
||||
private AttributesImpl createFieldBinding(AttributesImpl atts,
|
||||
X_AD_Field m_Field) {
|
||||
String sql = null;
|
||||
String name = null;
|
||||
atts.clear();
|
||||
if (m_Field.getAD_Column_ID() > 0) {
|
||||
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field.getAD_Column_ID());
|
||||
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
|
||||
|
||||
if (m_Field.getAD_Column_ID() > 0) {
|
||||
sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
|
||||
int idTable = DB.getSQLValue(null, sql, m_Field.getAD_Column_ID());
|
||||
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, idTable);
|
||||
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
|
||||
if (m_Field.getAD_FieldGroup_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_FieldGroup WHERE AD_FieldGroup_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field
|
||||
.getAD_FieldGroup_ID());
|
||||
atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", "");
|
||||
|
||||
if (m_Field.getAD_Field_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Field WHERE AD_Field_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field.getAD_Field_ID());
|
||||
atts.addAttribute("", "", "ADFieldNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADFieldNameID", "CDATA", "");
|
||||
|
||||
if (m_Field.getAD_Tab_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field.getAD_Tab_ID());
|
||||
atts.addAttribute("", "", "ADTabNameID", "CDATA", name);
|
||||
sql = "SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?";
|
||||
int windowid = DB.getSQLValue(null, sql, m_Field.getAD_Tab_ID());
|
||||
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, windowid);
|
||||
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADTabNameID", "CDATA", "");
|
||||
|
||||
atts.addAttribute("", "", "EntityType", "CDATA", (m_Field
|
||||
.getEntityType() != null ? m_Field.getEntityType() : ""));
|
||||
atts.addAttribute("", "", "Name", "CDATA",
|
||||
(m_Field.getName() != null ? m_Field.getName() : ""));
|
||||
atts.addAttribute("", "", "SameLine", "CDATA",
|
||||
(m_Field.isSameLine() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", (m_Field
|
||||
.isCentrallyMaintained() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "Displayed", "CDATA",
|
||||
(m_Field.isDisplayed() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isActive", "CDATA",
|
||||
(m_Field.isActive() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isEncrypted", "CDATA", (m_Field
|
||||
.isEncrypted() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isFieldOnly", "CDATA", (m_Field
|
||||
.isFieldOnly() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isHeading", "CDATA",
|
||||
(m_Field.isHeading() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isReadOnly", "CDATA",
|
||||
(m_Field.isReadOnly() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "SeqNo", "CDATA", "" + (m_Field.getSeqNo()));
|
||||
atts.addAttribute("", "", "DisplayLength", "CDATA",
|
||||
(m_Field.getDisplayLength() > 0 ? ""
|
||||
+ m_Field.getDisplayLength() : "0"));
|
||||
atts.addAttribute("", "", "Description", "CDATA", (m_Field
|
||||
.getDescription() != null ? m_Field.getDescription() : ""));
|
||||
atts.addAttribute("", "", "Help", "CDATA",
|
||||
(m_Field.getHelp() != null ? m_Field.getHelp() : ""));
|
||||
atts.addAttribute("", "", "SortNo", "CDATA",
|
||||
(m_Field.getSortNo() != null ? m_Field.getSortNo().toString()
|
||||
: ""));
|
||||
atts.addAttribute("", "", "DisplayLogic", "CDATA", (m_Field
|
||||
.getDisplayLogic() != null ? m_Field.getDisplayLogic() : ""));
|
||||
atts.addAttribute("", "", "ObscureType", "CDATA", (m_Field
|
||||
.getObscureType() != null ? m_Field.getObscureType() : ""));
|
||||
|
||||
atts.addAttribute("", "", "InfoFactoryClass", "CDATA", (m_Field.getInfoFactoryClass() != null
|
||||
? m_Field.getInfoFactoryClass() : ""));
|
||||
|
||||
if (m_Field.getAD_Reference_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field
|
||||
.getAD_Reference_ID());
|
||||
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", "");
|
||||
if (m_Field.getAD_Reference_Value_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field
|
||||
.getAD_Reference_Value_ID());
|
||||
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", "");
|
||||
if (m_Field.getAD_Val_Rule_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?";
|
||||
name = DB
|
||||
.getSQLValueString(null, sql, m_Field.getAD_Val_Rule_ID());
|
||||
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", "");
|
||||
|
||||
return atts;
|
||||
}
|
||||
}
|
||||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. *
|
||||
* 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 *
|
||||
* 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 *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* 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., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*
|
||||
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
|
||||
* Contributor(s): Low Heng Sin hengsin@avantz.com
|
||||
*****************************************************************************/
|
||||
package org.adempiere.pipo.handler;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.xml.transform.sax.TransformerHandler;
|
||||
|
||||
import org.adempiere.pipo.AbstractElementHandler;
|
||||
import org.adempiere.pipo.Element;
|
||||
import org.adempiere.pipo.PackIn;
|
||||
import org.adempiere.pipo.PackOut;
|
||||
import org.adempiere.pipo.exception.POSaveFailedException;
|
||||
import org.compiere.model.MField;
|
||||
import org.compiere.model.X_AD_Field;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
public class FieldElementHandler extends AbstractElementHandler {
|
||||
|
||||
public void startElement(Properties ctx, Element element)
|
||||
throws SAXException {
|
||||
PackIn packIn = (PackIn)ctx.get("PackInProcess");
|
||||
String elementValue = element.getElementValue();
|
||||
Attributes atts = element.attributes;
|
||||
log.info(elementValue + " " + atts.getValue("Name"));
|
||||
String entitytype = atts.getValue("EntityType");
|
||||
if (isProcessElement(ctx, entitytype)) {
|
||||
if (element.parent != null && element.parent.getElementValue().equals("tab") &&
|
||||
element.parent.defer) {
|
||||
element.defer = true;
|
||||
element.unresolved = element.parent.unresolved;
|
||||
return;
|
||||
}
|
||||
String name = atts.getValue("Name");
|
||||
String tabname = atts.getValue("ADTabNameID");
|
||||
String colname = atts.getValue("ADColumnNameID");
|
||||
String tableName = atts.getValue("ADTableNameID");
|
||||
int tableid = packIn.getTableId(tableName);
|
||||
if (tableid <= 0) {
|
||||
tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
|
||||
if (tableid > 0)
|
||||
packIn.addTable(tableName, tableid);
|
||||
}
|
||||
if (tableid <= 0) {
|
||||
element.unresolved = "AD_Table=" + tableName;
|
||||
element.defer = true;
|
||||
return;
|
||||
}
|
||||
int windowid = get_ID(ctx, "AD_Window", atts
|
||||
.getValue("ADWindowNameID"));
|
||||
if (windowid <= 0) {
|
||||
element.defer = true;
|
||||
element.unresolved = "AD_Window=" + atts.getValue("ADWindowNameID");
|
||||
return;
|
||||
}
|
||||
int columnid = packIn.getColumnId(tableName, colname);
|
||||
if (columnid <= 0) {
|
||||
columnid = get_IDWithMasterAndColumn(ctx, "AD_Column",
|
||||
"ColumnName", colname, "AD_Table", tableid);
|
||||
if (columnid > 0)
|
||||
packIn.addColumn(tableName, colname, columnid);
|
||||
}
|
||||
if (columnid <= 0) {
|
||||
element.defer = true;
|
||||
element.unresolved = "AD_Column"+ colname;
|
||||
return;
|
||||
}
|
||||
int tabid = 0;
|
||||
if (element.parent != null && element.parent.getElementValue().equals("tab") &&
|
||||
element.parent.recordId > 0) {
|
||||
tabid = element.parent.recordId;
|
||||
} else {
|
||||
StringBuffer sqlB = new StringBuffer(
|
||||
"select AD_Tab_ID from AD_Tab where AD_Window_ID = "
|
||||
+ windowid).append(" and Name = '" + tabname + "'")
|
||||
.append(" and AD_Table_ID = ?");
|
||||
tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(),
|
||||
tableid);
|
||||
if (element.parent != null && element.parent.getElementValue().equals("tab") && tabid > 0) {
|
||||
element.parent.recordId = tabid;
|
||||
}
|
||||
}
|
||||
if (tabid > 0) {
|
||||
StringBuffer sqlB = new StringBuffer(
|
||||
"select AD_Field_ID from AD_Field where AD_Column_ID = ")
|
||||
.append(columnid)
|
||||
.append(" and AD_Tab_ID = ?");
|
||||
int id = DB
|
||||
.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
|
||||
MField m_Field = new MField(ctx, id, getTrxName(ctx));
|
||||
int AD_Backup_ID = -1;
|
||||
String Object_Status = null;
|
||||
if (id > 0) {
|
||||
AD_Backup_ID = copyRecord(ctx, "AD_Field", m_Field);
|
||||
Object_Status = "Update";
|
||||
} else {
|
||||
Object_Status = "New";
|
||||
AD_Backup_ID = 0;
|
||||
}
|
||||
m_Field.setName(atts.getValue("Name"));
|
||||
m_Field.setAD_Column_ID(columnid);
|
||||
name = atts.getValue("ADFieldGroupNameID");
|
||||
id = get_IDWithColumn(ctx, "AD_FieldGroup", "Name", name);
|
||||
m_Field.setAD_FieldGroup_ID(id);
|
||||
m_Field.setAD_Tab_ID(tabid);
|
||||
m_Field.setEntityType(atts.getValue("EntityType"));
|
||||
m_Field.setIsSameLine(Boolean
|
||||
.valueOf(atts.getValue("SameLine")).booleanValue());
|
||||
m_Field.setIsCentrallyMaintained(Boolean.valueOf(
|
||||
atts.getValue("isCentrallyMaintained")).booleanValue());
|
||||
m_Field.setIsDisplayed(Boolean.valueOf(
|
||||
atts.getValue("Displayed")).booleanValue());
|
||||
// m_Field.setIsEncrypted(Boolean.valueOf(atts.getValue("isEncrypted")).booleanValue());
|
||||
m_Field.setIsFieldOnly(Boolean.valueOf(
|
||||
atts.getValue("isFieldOnly")).booleanValue());
|
||||
m_Field.setIsHeading(Boolean
|
||||
.valueOf(atts.getValue("isHeading")).booleanValue());
|
||||
m_Field.setIsReadOnly(Boolean.valueOf(
|
||||
atts.getValue("isReadOnly")).booleanValue());
|
||||
m_Field.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
|
||||
m_Field.setDisplayLength(Integer.parseInt(atts
|
||||
.getValue("DisplayLength")));
|
||||
m_Field.setDescription(getStringValue(atts, "Description"));
|
||||
m_Field.setHelp(getStringValue(atts, "Help"));
|
||||
m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean
|
||||
.valueOf(atts.getValue("isActive")).booleanValue()
|
||||
: true);
|
||||
String sortNo = getStringValue(atts, "SortNo");
|
||||
if (sortNo != null)
|
||||
m_Field.setSortNo(new BigDecimal(sortNo));
|
||||
m_Field.setDisplayLogic(getStringValue(atts, "DisplayLogic"));
|
||||
|
||||
String Name = atts.getValue("ADReferenceNameID");
|
||||
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
|
||||
m_Field.setAD_Reference_ID(id);
|
||||
|
||||
Name = atts.getValue("ADValRuleNameID");
|
||||
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
|
||||
m_Field.setAD_Val_Rule_ID(id);
|
||||
Name = atts.getValue("ADReferenceNameValueID");
|
||||
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
|
||||
m_Field.setAD_Reference_Value_ID(id);
|
||||
m_Field.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
|
||||
|
||||
if (m_Field.save(getTrxName(ctx)) == true) {
|
||||
record_log(ctx, 1, m_Field.getName(), "Field", m_Field
|
||||
.get_ID(), AD_Backup_ID, Object_Status, "AD_Field",
|
||||
get_IDWithColumn(ctx, "AD_Table", "TableName",
|
||||
"AD_Field"));
|
||||
element.recordId = m_Field.getAD_Field_ID();
|
||||
} else {
|
||||
record_log(ctx, 0, m_Field.getName(), "Field", m_Field
|
||||
.get_ID(), AD_Backup_ID, Object_Status, "AD_Field",
|
||||
get_IDWithColumn(ctx, "AD_Table", "TableName",
|
||||
"AD_Field"));
|
||||
throw new POSaveFailedException("Failed to save field definition.");
|
||||
}
|
||||
} else {
|
||||
element.defer = true;
|
||||
element.unresolved = "AD_Tab=" + tabname;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
element.skip = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(Properties ctx, Element element) throws SAXException {
|
||||
}
|
||||
|
||||
public void create(Properties ctx, TransformerHandler document)
|
||||
throws SAXException {
|
||||
int AD_Field_ID = Env.getContextAsInt(ctx,
|
||||
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();
|
||||
createFieldBinding(atts, m_Field);
|
||||
|
||||
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
|
||||
|
||||
if(m_Field.getAD_FieldGroup_ID() > 0){
|
||||
packOut.createFieldGroupElement(m_Field.getAD_FieldGroup_ID(), document);
|
||||
}
|
||||
|
||||
if(m_Field.getAD_Reference_ID() > 0) {
|
||||
packOut.createReference(m_Field.getAD_Reference_ID(), document);
|
||||
}
|
||||
|
||||
if (m_Field.getAD_Reference_Value_ID() > 0) {
|
||||
packOut.createReference(m_Field.getAD_Reference_Value_ID(), document);
|
||||
}
|
||||
|
||||
if (m_Field.getAD_Val_Rule_ID() > 0) {
|
||||
packOut.createDynamicRuleValidation(m_Field.getAD_Val_Rule_ID(), document);
|
||||
}
|
||||
|
||||
document.startElement("", "", "field", atts);
|
||||
document.endElement("", "", "field");
|
||||
}
|
||||
|
||||
private AttributesImpl createFieldBinding(AttributesImpl atts,
|
||||
X_AD_Field m_Field) {
|
||||
String sql = null;
|
||||
String name = null;
|
||||
atts.clear();
|
||||
if (m_Field.getAD_Column_ID() > 0) {
|
||||
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field.getAD_Column_ID());
|
||||
atts.addAttribute("", "", "ADColumnNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADColumnNameID", "CDATA", "");
|
||||
|
||||
if (m_Field.getAD_Column_ID() > 0) {
|
||||
sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
|
||||
int idTable = DB.getSQLValue(null, sql, m_Field.getAD_Column_ID());
|
||||
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, idTable);
|
||||
atts.addAttribute("", "", "ADTableNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADTableNameID", "CDATA", "");
|
||||
if (m_Field.getAD_FieldGroup_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_FieldGroup WHERE AD_FieldGroup_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field
|
||||
.getAD_FieldGroup_ID());
|
||||
atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", "");
|
||||
|
||||
if (m_Field.getAD_Field_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Field WHERE AD_Field_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field.getAD_Field_ID());
|
||||
atts.addAttribute("", "", "ADFieldNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADFieldNameID", "CDATA", "");
|
||||
|
||||
if (m_Field.getAD_Tab_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field.getAD_Tab_ID());
|
||||
atts.addAttribute("", "", "ADTabNameID", "CDATA", name);
|
||||
sql = "SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?";
|
||||
int windowid = DB.getSQLValue(null, sql, m_Field.getAD_Tab_ID());
|
||||
sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, windowid);
|
||||
atts.addAttribute("", "", "ADWindowNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADTabNameID", "CDATA", "");
|
||||
|
||||
atts.addAttribute("", "", "EntityType", "CDATA", (m_Field
|
||||
.getEntityType() != null ? m_Field.getEntityType() : ""));
|
||||
atts.addAttribute("", "", "Name", "CDATA",
|
||||
(m_Field.getName() != null ? m_Field.getName() : ""));
|
||||
atts.addAttribute("", "", "SameLine", "CDATA",
|
||||
(m_Field.isSameLine() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", (m_Field
|
||||
.isCentrallyMaintained() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "Displayed", "CDATA",
|
||||
(m_Field.isDisplayed() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isActive", "CDATA",
|
||||
(m_Field.isActive() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isEncrypted", "CDATA", (m_Field
|
||||
.isEncrypted() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isFieldOnly", "CDATA", (m_Field
|
||||
.isFieldOnly() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isHeading", "CDATA",
|
||||
(m_Field.isHeading() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "isReadOnly", "CDATA",
|
||||
(m_Field.isReadOnly() == true ? "true" : "false"));
|
||||
atts.addAttribute("", "", "SeqNo", "CDATA", "" + (m_Field.getSeqNo()));
|
||||
atts.addAttribute("", "", "DisplayLength", "CDATA",
|
||||
(m_Field.getDisplayLength() > 0 ? ""
|
||||
+ m_Field.getDisplayLength() : "0"));
|
||||
atts.addAttribute("", "", "Description", "CDATA", (m_Field
|
||||
.getDescription() != null ? m_Field.getDescription() : ""));
|
||||
atts.addAttribute("", "", "Help", "CDATA",
|
||||
(m_Field.getHelp() != null ? m_Field.getHelp() : ""));
|
||||
atts.addAttribute("", "", "SortNo", "CDATA",
|
||||
(m_Field.getSortNo() != null ? m_Field.getSortNo().toString()
|
||||
: ""));
|
||||
atts.addAttribute("", "", "DisplayLogic", "CDATA", (m_Field
|
||||
.getDisplayLogic() != null ? m_Field.getDisplayLogic() : ""));
|
||||
atts.addAttribute("", "", "ObscureType", "CDATA", (m_Field
|
||||
.getObscureType() != null ? m_Field.getObscureType() : ""));
|
||||
|
||||
atts.addAttribute("", "", "InfoFactoryClass", "CDATA", (m_Field.getInfoFactoryClass() != null
|
||||
? m_Field.getInfoFactoryClass() : ""));
|
||||
|
||||
if (m_Field.getAD_Reference_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field
|
||||
.getAD_Reference_ID());
|
||||
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADReferenceNameID", "CDATA", "");
|
||||
if (m_Field.getAD_Reference_Value_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?";
|
||||
name = DB.getSQLValueString(null, sql, m_Field
|
||||
.getAD_Reference_Value_ID());
|
||||
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", "");
|
||||
if (m_Field.getAD_Val_Rule_ID() > 0) {
|
||||
sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?";
|
||||
name = DB
|
||||
.getSQLValueString(null, sql, m_Field.getAD_Val_Rule_ID());
|
||||
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name);
|
||||
} else
|
||||
atts.addAttribute("", "", "ADValRuleNameID", "CDATA", "");
|
||||
|
||||
return atts;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
;
|
||||
|
|
@ -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')
|
||||
;
|
||||
|
Loading…
Reference in New Issue