[ 1761780 ] Packout create many duplicate element

[ 1786994 ] 2Pack can handle translations now
[ 1793972 ] 2Pack &FieldGroup
This commit is contained in:
Heng Sin Low 2008-03-17 05:49:31 +00:00
parent 6a83f4a282
commit 34dea236ee
19 changed files with 1048 additions and 8 deletions

View File

@ -76,16 +76,24 @@ public abstract class AbstractElementHandler implements ElementHandler {
*/
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{
String recordLayout;
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 = "Type:"+objectType + " - Name:"+objectName + " - ID:"+objectID +" - Action:"+objectStatus+" - Success";
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.toCharArray(),0,recordLayout.length());
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
hd_document.endElement("","","Success");
//hd_documemt.endElement("","","Successfull");
@ -122,9 +130,17 @@ public abstract class AbstractElementHandler implements ElementHandler {
else{
String PK_Status = "Completed with errors";
hd_document.startElement("","","Failure",attsOut);
recordLayout = "Type:"+objectType + " - Name:"+tableName + " - ID:"+objectID +" - Action:"+objectStatus+" - Failure";
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.toCharArray(),0,recordLayout.length());
hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length());
//hd_documemt.endElement("","","Success");
hd_document.endElement("","","Failure");
@ -423,4 +439,15 @@ public abstract class AbstractElementHandler implements ElementHandler {
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"));
}
}

View File

@ -0,0 +1,109 @@
package org.adempiere.pipo;
import org.compiere.model.PO;
import org.xml.sax.helpers.AttributesImpl;
public class AttributeFiller {
private AttributesImpl atts = null;
private PO po = null;
/**
* Will clear attributes !!!
* @param _atts
*/
public AttributeFiller(AttributesImpl attributes){
attributes.clear();
atts = attributes;
po = null;
}
/**
* Will clear attributes !!!
* @param _atts
*/
public AttributeFiller(AttributesImpl attributes, PO poToAutoFill){
attributes.clear();
atts = attributes;
po = poToAutoFill;
}
/**
*
* @param name
* @param value
*/
public void addUnchecked(String name, String value){
atts.addAttribute("", "", name, "CDATA", value);
}
/**
*
* @param name
* @param stringValue
*/
public void addString(String name, String stringValue){
atts.addAttribute("", "", name, "CDATA", stringValue != null ? stringValue : "");
}
/**
*
* @param name
* @param boolValue
*/
public void addBoolean(String name, boolean boolValue){
atts.addAttribute("", "", name, "CDATA", boolValue == true ? "true" : "false");
}
/**
*
* @param name
* @param stringValue
*/
public void add(String columnName){
Object value = po.get_Value(columnName);
if(value == null){
atts.addAttribute("", "", columnName, "CDATA", "");
return;
}
if(value instanceof String){
atts.addAttribute("", "", columnName, "CDATA", (String)value);
}else if(value instanceof Boolean) {
atts.addAttribute("", "", columnName, "CDATA", (Boolean)value == true ? "true" : "false");
}else{
throw new IllegalArgumentException("Add you own type implemantation here.");
}
}
/**
*
*
*/
public void addIsActive(){
atts.addAttribute("", "", "IsActive", "CDATA", (Boolean)po.isActive() == true ? "true" : "false");
}
/**
*
* @return
*/
public AttributesImpl getAttributes(){
return atts;
}
}

View File

@ -18,6 +18,8 @@ package org.adempiere.pipo;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import org.adempiere.pipo.exception.DatabaseAccessException;
@ -33,6 +35,8 @@ public class IDFinder {
private static CLogger log = CLogger.getCLogger(IDFinder.class);
private static Map<String, Integer>idCache = new HashMap<String, Integer>();
/**
* Get ID from Name for a table.
* TODO: substitute with PO.getAllIDs
@ -45,6 +49,19 @@ public class IDFinder {
*/
public static int get_ID (String tableName, String name, int AD_Client_ID, String trxName) {
int id = 0;
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".Name=")
.append(name);
if (!tableName.startsWith("AD_"))
key.append(" and AD_Client_ID=").append(AD_Client_ID);
//check cache
if (idCache.containsKey(key.toString()))
return idCache.get(key.toString());
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
@ -69,6 +86,10 @@ public class IDFinder {
log.info ("get_ID:"+e);
throw new DatabaseAccessException(e);
}
//keep in cache
idCache.put(key.toString(), id);
return id;
}
@ -83,6 +104,21 @@ public class IDFinder {
*/
public static int get_IDWithColumn (String tableName, String columnName, Object value, int AD_Client_ID, String trxName) {
int id = 0;
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".")
.append(columnName)
.append("=")
.append(value.toString());
if (!tableName.startsWith("AD_"))
key.append(" and AD_Client_ID=").append(AD_Client_ID);
//check cache
if (idCache.containsKey(key.toString()))
return idCache.get(key.toString());
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
@ -90,7 +126,6 @@ public class IDFinder {
.append(" where ")
.append(columnName)
.append(" = ?");
//StringBuffer sqlC = new StringBuffer ("select "+tableName+"_ID from "+tableName+" where "+columnName+"="+value.toString());
if (!tableName.startsWith("AD_"))
sqlB = sqlB.append(" and AD_Client_ID=?");
@ -104,6 +139,8 @@ public class IDFinder {
pstmt.setString(1, (String)value);
else if (value instanceof Integer)
pstmt.setInt(1, ((Integer)value).intValue());
else
pstmt.setObject(1, value);
if (!tableName.startsWith("AD_"))
pstmt.setInt(2, AD_Client_ID);
@ -118,6 +155,10 @@ public class IDFinder {
log.info ("get_IDWithColumn:"+e);
throw new DatabaseAccessException(e);
}
//update cache
idCache.put(key.toString(), id);
return id;
}
@ -132,6 +173,20 @@ public class IDFinder {
*/
public static int get_IDWithMaster (String tableName, String name, String tableNameMaster, String nameMaster, String trxName) {
int id = 0;
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".Name=")
.append(name)
.append(" and ")
.append(tableNameMaster)
.append(".Name=")
.append(nameMaster);
//check cache
if (idCache.containsKey(key.toString()))
return idCache.get(key.toString());
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
@ -154,11 +209,14 @@ public class IDFinder {
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e) {
} catch (Exception e) {
log.info ("get_IDWithMaster:"+e);
throw new DatabaseAccessException(e);
}
//update cache
idCache.put(key.toString(), id);
return id;
}
@ -174,6 +232,13 @@ public class IDFinder {
public static int get_IDWithMasterAndColumn (String tableName, String columnName, String name, String tableNameMaster, int masterID, String trxName) {
int id = 0;
//check cache
String key = tableName + "." + columnName + "=" + name + tableNameMaster + "=" + masterID;
if (idCache.containsKey(key))
return idCache.get(key);
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
@ -193,7 +258,9 @@ public class IDFinder {
pstmt.setInt(2, masterID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
id = rs.getInt(1);
}
rs.close();
pstmt.close();
pstmt = null;
@ -202,6 +269,10 @@ public class IDFinder {
log.info ("get_IDWithMasterAndColumn:"+e);
throw new DatabaseAccessException(e);
}
//update cache
idCache.put(key, id);
return id;
}
@ -216,6 +287,23 @@ public class IDFinder {
*/
public static int get_IDWithMaster (String tableName, String name, String tableNameMaster, int masterID, String trxName) {
int id = 0;
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".Name=")
.append(name)
.append(" and ")
.append(tableNameMaster)
.append(".")
.append(tableNameMaster)
.append("_ID=")
.append(masterID);
//check cache
if (idCache.containsKey(key.toString()))
return idCache.get(key.toString());
StringBuffer sqlB = new StringBuffer ("select ")
.append(tableName)
.append("_ID from ")
@ -239,6 +327,10 @@ public class IDFinder {
log.info ("get_IDWithMasterID:"+e);
throw new DatabaseAccessException(e);
}
//update cache
idCache.put(key.toString(), id);
return id;
}
@ -253,6 +345,19 @@ public class IDFinder {
*/
public static int getIDbyName (String tableName, String name, int AD_Client_ID, String trxName) {
int id = 0;
//construct cache key
StringBuffer key = new StringBuffer();
key.append(tableName)
.append(".Name=")
.append(name);
if (!tableName.startsWith("AD_"))
key.append(" AND AD_Client_ID=").append(AD_Client_ID);
//check cache
if (idCache.containsKey(key.toString()))
return idCache.get(key.toString());
StringBuffer sql = new StringBuffer("SELECT ")
.append(tableName)
.append("_ID ")
@ -278,6 +383,10 @@ public class IDFinder {
log.log(Level.SEVERE, "getIDbyName:"+e);
throw new DatabaseAccessException(e);
}
//update cache
idCache.put(key.toString(), id);
return id;
}
}

View File

@ -44,12 +44,15 @@ import javax.xml.transform.TransformerConfigurationException;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.adempiere.pipo.handler.AdElementHandler;
import org.adempiere.pipo.handler.CodeSnipitElementHandler;
import org.adempiere.pipo.handler.ColumnElementHandler;
import org.adempiere.pipo.handler.CommonTranslationHandler;
import org.adempiere.pipo.handler.DataElementHandler;
import org.adempiere.pipo.handler.DistFileElementHandler;
import org.adempiere.pipo.handler.DynValRuleElementHandler;
import org.adempiere.pipo.handler.FieldElementHandler;
import org.adempiere.pipo.handler.FieldGroupElementHandler;
import org.adempiere.pipo.handler.FormAccessElementHandler;
import org.adempiere.pipo.handler.FormElementHandler;
import org.adempiere.pipo.handler.ImpFormatElementHandler;
@ -229,6 +232,9 @@ public class PackInHandler extends DefaultHandler {
handlers.put("reference", new ReferenceElementHandler());
handlers.put("referencelist", new ReferenceListElementHandler());
handlers.put("referencetable", new ReferenceTableElementHandler());
handlers.put("fieldgroup", new FieldGroupElementHandler());
handlers.put("element", new AdElementHandler());
handlers.put("trl", new CommonTranslationHandler());
}
/**
@ -722,6 +728,7 @@ public class PackInHandler extends DefaultHandler {
}
}
throw new RuntimeException("Failed to resolve dependency for " + count + " elements.");
//System.err.println("Failed to resolve dependency for " + count + " elements.");
}
}

View File

@ -30,10 +30,13 @@ import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.adempiere.pipo.CreateZipFile;
import org.adempiere.pipo.handler.AdElementHandler;
import org.adempiere.pipo.handler.CodeSnipitElementHandler;
import org.adempiere.pipo.handler.CommonTranslationHandler;
import org.adempiere.pipo.handler.DataElementHandler;
import org.adempiere.pipo.handler.DistFileElementHandler;
import org.adempiere.pipo.handler.DynValRuleElementHandler;
import org.adempiere.pipo.handler.FieldGroupElementHandler;
import org.adempiere.pipo.handler.FormElementHandler;
import org.adempiere.pipo.handler.ImpFormatElementHandler;
import org.adempiere.pipo.handler.MenuElementHandler;
@ -48,6 +51,8 @@ import org.adempiere.pipo.handler.TableElementHandler;
import org.adempiere.pipo.handler.TaskElementHandler;
import org.adempiere.pipo.handler.WindowElementHandler;
import org.adempiere.pipo.handler.WorkflowElementHandler;
import org.compiere.model.X_AD_Element;
import org.compiere.model.X_AD_FieldGroup;
import org.compiere.model.X_AD_Package_Exp;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Reference;
@ -100,6 +105,9 @@ public class PackOut extends SvrProcess
PrintFormatElementHandler printFormatHandler = new PrintFormatElementHandler();
DistFileElementHandler distFileHandler = new DistFileElementHandler();
ReferenceElementHandler referenceHandler = new ReferenceElementHandler();
FieldGroupElementHandler fieldGroupHandler = new FieldGroupElementHandler();
AdElementHandler adElementHandler = new AdElementHandler();
CommonTranslationHandler translationHandler = new CommonTranslationHandler();
/**
* Prepare - e.g., get Parameters.
@ -722,6 +730,55 @@ public class PackOut extends SvrProcess
getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID);
}
/**
*
* @param FieldGroup_id
* @param packOutDocument
* @throws SAXException
*/
public void createFieldGroupElement (int FieldGroup_id, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID, FieldGroup_id);
fieldGroupHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID);
}
/**
*
* @param Reference_id
* @param packOutDocument
* @throws SAXException
*/
public void createAdElement (int Ad_Element_id, TransformerHandler packOutDocument) throws SAXException
{
Env.setContext(getCtx(), X_AD_Element.COLUMNNAME_AD_Element_ID, Ad_Element_id);
adElementHandler.create(getCtx(), packOutDocument);
getCtx().remove(X_AD_Element.COLUMNNAME_AD_Element_ID);
}
/**
*
* @param parentTableName
* @param parentID
* @param packOutDocument
* @throws SAXException
*/
public void createTranslations (String parentTableName, int parentID, TransformerHandler packOutDocument) throws SAXException
{
if("true".equals(getCtx().getProperty("isHandleTranslations"))){
Env.setContext(getCtx(), CommonTranslationHandler.CONTEXT_KEY__PARENT_TABLE,
parentTableName);
Env.setContext(getCtx(), CommonTranslationHandler.CONTEXT_KEY__PARENT_RECORD_ID,
parentID);
translationHandler.create(getCtx(), packOutDocument);
getCtx().remove(CommonTranslationHandler.CONTEXT_KEY__PARENT_TABLE);
getCtx().remove(CommonTranslationHandler.CONTEXT_KEY__PARENT_RECORD_ID);
}
}
public void copyFile (String sourceName, String copyName ) {
InputStream source; // Stream for reading from the source file.
OutputStream copy; // Stream for writing the copy.

View File

@ -0,0 +1,36 @@
package org.adempiere.pipo;
import org.compiere.model.PO;
import org.xml.sax.Attributes;
public class PoFiller{
PO po = null;
Attributes atts = null;
public PoFiller(PO po, Attributes atts){
this.po = po;
this.atts = atts;
}
public void setString(String columnName){
String value = atts.getValue(columnName);
value = "".equals(value) ? null : value;
po.set_ValueOfColumn(columnName, value);
}
public void setBoolean(String columnName){
String value = atts.getValue(columnName);
boolean bool = "true".equals(value) ? true : false;
po.set_ValueOfColumn(columnName, bool);
}
}

View File

@ -0,0 +1,165 @@
/******************************************************************************
* 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.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.AttributeFiller;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.PoFiller;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_Element;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class AdElementHandler extends AbstractElementHandler {
private List<Integer> processedElements = new ArrayList<Integer>();
private final String AD_ELEMENT = "AD_Element";
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("ColumnName"));
String entitytype = atts.getValue("EntityType");
String ColumnName = atts.getValue("ColumnName");
if (isProcessElement(ctx, entitytype)) {
int id = get_IDWithColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName);
X_AD_Element m_AdElement = new X_AD_Element(ctx, id,
getTrxName(ctx));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, AD_ELEMENT, m_AdElement);
Object_Status = "Update";
if (processedElements.contains(id)) {
element.skip = true;
return;
}
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
PoFiller pf = new PoFiller(m_AdElement, atts);
pf.setBoolean("IsActive");
pf.setString(X_AD_Element.COLUMNNAME_ColumnName);
pf.setString(X_AD_Element.COLUMNNAME_Description);
pf.setString(X_AD_Element.COLUMNNAME_EntityType);
pf.setString(X_AD_Element.COLUMNNAME_Help);
pf.setString(X_AD_Element.COLUMNNAME_Name);
pf.setString(X_AD_Element.COLUMNNAME_PrintName);
pf.setString(X_AD_Element.COLUMNNAME_PO_Description);
pf.setString(X_AD_Element.COLUMNNAME_PO_Name);
pf.setString(X_AD_Element.COLUMNNAME_PO_Help);
pf.setString(X_AD_Element.COLUMNNAME_PO_PrintName);
if (m_AdElement.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_AdElement.getName(), "Reference",
m_AdElement.get_ID(), AD_Backup_ID, Object_Status,
AD_ELEMENT, get_IDWithColumn(ctx, "AD_Table",
"TableName", AD_ELEMENT));
element.recordId = m_AdElement.getAD_Element_ID();
processedElements.add(m_AdElement.getAD_Element_ID());
} else {
record_log(ctx, 0, m_AdElement.getName(), "Reference",
m_AdElement.get_ID(), AD_Backup_ID, Object_Status,
AD_ELEMENT, get_IDWithColumn(ctx, "AD_Table",
"TableName", AD_ELEMENT));
throw new POSaveFailedException("Reference");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int adElement_id = Env.getContextAsInt(ctx,
X_AD_Element.COLUMNNAME_AD_Element_ID);
if (processedElements.contains(adElement_id))
return;
processedElements.add(adElement_id);
X_AD_Element m_AdElement = new X_AD_Element(ctx, adElement_id, null);
AttributesImpl atts = new AttributesImpl();
createAdElementBinding(atts, m_AdElement);
document.startElement("", "", "element", atts);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
packOut.createTranslations(X_AD_Element.Table_Name,
m_AdElement.get_ID(), document);
document.endElement("", "", "element");
}
private AttributesImpl createAdElementBinding(AttributesImpl atts,
X_AD_Element m_AdElement) {
AttributeFiller filler = new AttributeFiller(atts, m_AdElement);
filler.add("IsActive");
filler.add(X_AD_Element.COLUMNNAME_ColumnName);
filler.add(X_AD_Element.COLUMNNAME_Description);
filler.add(X_AD_Element.COLUMNNAME_EntityType);
filler.add(X_AD_Element.COLUMNNAME_Help);
filler.add(X_AD_Element.COLUMNNAME_Name);
filler.add(X_AD_Element.COLUMNNAME_PrintName);
filler.add(X_AD_Element.COLUMNNAME_PO_Description);
filler.add(X_AD_Element.COLUMNNAME_PO_Name);
filler.add(X_AD_Element.COLUMNNAME_PO_Help);
filler.add(X_AD_Element.COLUMNNAME_PO_PrintName);
return atts;
}
}

View File

@ -0,0 +1,316 @@
package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.AttributeFiller;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.ElementHandler;
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 CommonTranslationHandler extends AbstractElementHandler implements ElementHandler{
public static final String CONTEXT_KEY__PARENT_TABLE = "currentParentTableForTranslation";
public static final String CONTEXT_KEY__PARENT_RECORD_ID = "currentParentTableRecordID_ForTranslation";
public static final String SPECIAL_ATRRIBUTE__TABLE_NAME = "ParentTable";
private HashMap<String, ArrayList<String>> cached_PIPO_ColumnsByTable = new HashMap<String, ArrayList<String>>();//Key: table name. Value: set of PIPO columns
public void startElement(Properties ctx, Element element) throws SAXException {
if(! isHandleTranslations(ctx)){
return;//translation import option is disabled
}
if(element.parent.skip){
return;
}
if(element.parent.defer){
element.defer = true;
return;
}
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
int parentID = element.parent.recordId;
if(parentID ==0)
throw new SAXException();
String parentTable = atts.getValue(SPECIAL_ATRRIBUTE__TABLE_NAME);
String language = atts.getValue("AD_Language");
log.info(elementValue+" "+parentTable+" "+atts.getValue("Name"));
if(isRecordExists(parentTable, parentID, language, ctx)){
updateTranslation(parentTable, parentID, ctx, atts);
}else{
insertTranslation(parentTable, parentID, ctx, atts);
}
}
private boolean isRecordExists(String parentTable, int parentID,
String language, Properties ctx) {
String sql =
"select ad_client_id from "+parentTable +"_trl where "+
parentTable+"_ID="+parentID+" and ad_language = '"+language+"'";
if(DB.getSQLValue(getTrxName(ctx), sql) == -1){
return false;
}else{
return true;
}
}
private void insertTranslation(String parentTable, int parentID,
Properties ctx, Attributes atts) throws SAXException{
ArrayList<String> pipoColumns = getExportableColumns(parentTable);
StringBuffer sql = new StringBuffer(
"insert into "+parentTable+"_trl ("+parentTable+"_ID, "+
" ad_client_ID, ad_org_id, CreatedBy, UpdatedBy, "+cast(pipoColumns)+
") values ( ?, ?, ?, ?, ? ");
for (int i = 0; i<pipoColumns.size(); i++) {
sql.append(",?");
}
sql.append(")");
PreparedStatement pstm = DB.prepareStatement(sql.toString(), getTrxName(ctx));
try {
pstm.setInt(1, parentID);
pstm.setInt(2, 0);
pstm.setInt(3, 0);
pstm.setInt(4, 0);
pstm.setInt(5, 0);
int i = 5;
for (String columnName : pipoColumns) {
i++;
String value = atts.getValue(columnName);
if(columnName.equalsIgnoreCase("IsActive") ||
columnName.equalsIgnoreCase("IsTranslated")){
value = "true".equals(value) ? "Y" : "N";
}
pstm.setString(i, value);
}
if(pstm.executeUpdate()<0){
throw new SAXException();
}
pstm.close();
} catch (Exception e) {
e.printStackTrace();
throw new SAXException();
}
}
private void updateTranslation(String parentTable, int parentID,
Properties ctx, Attributes atts) throws SAXException{
ArrayList<String> pipoColumns = getExportableColumns(parentTable);
StringBuffer sqlBuf = new StringBuffer("update "+parentTable+"_trl set ");
for (String columnName : pipoColumns) {
sqlBuf.append(columnName).append("=?,");
}
String sql = sqlBuf.substring(0, sqlBuf.length()-1);
sql += " where ad_language = '"+atts.getValue("AD_Language")+
"' and "+parentTable+"_ID="+parentID;
try {
PreparedStatement pstm = DB.prepareStatement(sql,
getTrxName(ctx));
int i=0;
for (String columnName : pipoColumns) {
String value = atts.getValue(columnName);
i++;
if(columnName.equalsIgnoreCase("IsActive") ||
columnName.equalsIgnoreCase("IsTranslated")){
value = "true".equals(value) ? "Y" : "N";
}
pstm.setString(i, value);
}
if(pstm.executeUpdate()<0){
throw new SAXException();
}
pstm.close();
} catch (Exception e) {
e.printStackTrace();
throw new SAXException();
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document) throws SAXException {
String parenTableName = Env.getContext(ctx, CONTEXT_KEY__PARENT_TABLE);
int parentRecordID = Env.getContextAsInt(ctx, CONTEXT_KEY__PARENT_RECORD_ID);
createTranslationTags(parenTableName, parentRecordID, document);
}
private void createTranslationTags(String parentTable,
int parentRecordID, TransformerHandler document) throws SAXException {
ArrayList<String> exportableColumns = getExportableColumns(parentTable);
String sql =
"select "+cast(exportableColumns)+" from "+parentTable+"_trl where "+
parentTable+"_ID="+parentRecordID;
PreparedStatement pstm = DB.prepareStatement(sql, null);
try {
ResultSet rs = pstm.executeQuery();
while(rs.next()){
AttributesImpl atts = getAttsForOneTrlRow(exportableColumns, rs);
atts.addAttribute("", "", SPECIAL_ATRRIBUTE__TABLE_NAME, "CDATA", parentTable);
document.startElement("", "", "trl", atts);
document.endElement("", "", "trl");
}
rs.close();
pstm.close();
} catch (Exception e) {
e.printStackTrace();
throw new SAXException();
}
}
private AttributesImpl getAttsForOneTrlRow(ArrayList<String> exportableColumns,
ResultSet rs) throws Exception {
AttributesImpl atts = new AttributesImpl();
AttributeFiller af = new AttributeFiller(atts);
for (String columnName : exportableColumns) {
if(columnName.equalsIgnoreCase("IsActive")||
columnName.equalsIgnoreCase("IsTranslated")){
af.addBoolean(columnName, rs.getString(columnName).equalsIgnoreCase("Y"));
}else{
af.addString(columnName, rs.getString(columnName));
}
}
return atts;
}
/**
*
* @param parentTable
* @return
* @throws SAXException
*/
@SuppressWarnings("unchecked")
private ArrayList<String> getExportableColumns(String parentTable) throws SAXException {
Object pipolColumns = cached_PIPO_ColumnsByTable.get(parentTable);
if(pipolColumns != null){
return (ArrayList<String>)pipolColumns;
}
ArrayList<String> new_PIPO_Columns = new ArrayList<String>();
String sql = "select * from ad_column where ad_table_id = " +
"(select ad_table_id from ad_table where tableName = ?)" +
"and isTranslated='Y'";
PreparedStatement pstm = DB.prepareStatement(sql, null);
try {
pstm.setString(1, parentTable);
ResultSet rs = pstm.executeQuery();
while(rs.next()){
new_PIPO_Columns.add(rs.getString("columnName"));
}
pstm.close();
rs.close();
} catch (SQLException e) {
e.printStackTrace();
throw new SAXException();
}
new_PIPO_Columns.add("AD_Language");
new_PIPO_Columns.add("IsActive");
new_PIPO_Columns.add("IsTranslated");
//Putting in cache
cached_PIPO_ColumnsByTable.put(parentTable, new_PIPO_Columns);
return (ArrayList<String>)new_PIPO_Columns;
}
private String cast(ArrayList<String> arg){
return arg.toString().substring(1, arg.toString().length()-1);
}
}

View File

@ -24,6 +24,7 @@ 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;
@ -188,6 +189,13 @@ public class FieldElementHandler extends AbstractElementHandler {
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);
}
document.startElement("", "", "field", atts);
document.endElement("", "", "field");
}

View File

@ -0,0 +1,145 @@
/******************************************************************************
* 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): Igor G. - progerpro@gmail.com
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo.AbstractElementHandler;
import org.adempiere.pipo.AttributeFiller;
import org.adempiere.pipo.Element;
import org.adempiere.pipo.PackOut;
import org.adempiere.pipo.PoFiller;
import org.adempiere.pipo.exception.POSaveFailedException;
import org.compiere.model.X_AD_FieldGroup;
import org.compiere.util.Env;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class FieldGroupElementHandler extends AbstractElementHandler {
private List<Integer> processedFieldGroups = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
int AD_Backup_ID = -1;
String Object_Status = null;
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("Name");
if (isProcessElement(ctx, entitytype)) {
int id = get_IDWithColumn(ctx, X_AD_FieldGroup.Table_Name, X_AD_FieldGroup.COLUMNNAME_Name, name);
X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx, id,
getTrxName(ctx));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, X_AD_FieldGroup.Table_Name, fieldGroup);
Object_Status = "Update";
if (processedFieldGroups.contains(id)) {
element.skip = true;
return;
}
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
PoFiller pf = new PoFiller(fieldGroup, atts);
pf.setBoolean("IsActive");
pf.setString(X_AD_FieldGroup.COLUMNNAME_Name);
pf.setString(X_AD_FieldGroup.COLUMNNAME_EntityType);
if (fieldGroup.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, fieldGroup.getName(), "Reference",
fieldGroup.get_ID(), AD_Backup_ID, Object_Status,
X_AD_FieldGroup.Table_Name, get_IDWithColumn(ctx, "AD_Table",
"TableName", X_AD_FieldGroup.Table_Name));
element.recordId = fieldGroup.getAD_FieldGroup_ID();
processedFieldGroups.add(fieldGroup.getAD_FieldGroup_ID());
} else {
record_log(ctx, 0, fieldGroup.getName(), "Reference",
fieldGroup.get_ID(), AD_Backup_ID, Object_Status,
X_AD_FieldGroup.Table_Name, get_IDWithColumn(ctx, "AD_Table",
"TableName", X_AD_FieldGroup.Table_Name));
throw new POSaveFailedException("Reference");
}
} else {
element.skip = true;
}
}
public void endElement(Properties ctx, Element element) throws SAXException {
}
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int fieldGroup_id = Env.getContextAsInt(ctx,
X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID);
if (processedFieldGroups.contains(fieldGroup_id))
return;
processedFieldGroups.add(fieldGroup_id);
X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx, fieldGroup_id, null);
AttributesImpl atts = new AttributesImpl();
createAdElementBinding(atts, fieldGroup);
document.startElement("", "", "fieldgroup", atts);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
packOut.createTranslations(X_AD_FieldGroup.Table_Name,
fieldGroup.get_ID(), document);
document.endElement("", "", "fieldgroup");
}
private AttributesImpl createAdElementBinding(AttributesImpl atts,
X_AD_FieldGroup fieldGroup) {
AttributeFiller filler = new AttributeFiller(atts, fieldGroup);
filler.add("IsActive");
filler.add(X_AD_FieldGroup.COLUMNNAME_Name);
filler.add(X_AD_FieldGroup.COLUMNNAME_EntityType);
return atts;
}
}

View File

@ -16,6 +16,8 @@
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
@ -33,6 +35,8 @@ import org.xml.sax.helpers.AttributesImpl;
public class FormElementHandler extends AbstractElementHandler {
private List<Integer> forms = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
@ -80,6 +84,9 @@ public class FormElementHandler extends AbstractElementHandler {
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Form_ID = Env.getContextAsInt(ctx, "AD_Form_ID");
if (forms.contains(AD_Form_ID)) return;
forms.add(AD_Form_ID);
X_AD_Form m_Form = new X_AD_Form (ctx, AD_Form_ID, null);
AttributesImpl atts = new AttributesImpl();
createFormBinding(atts,m_Form);

View File

@ -18,6 +18,8 @@ package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -40,6 +42,8 @@ public class ImpFormatElementHandler extends AbstractElementHandler {
private ImpFormatRowElementHandler rowHandler = new ImpFormatRowElementHandler();
private List<Integer> formats = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
@ -99,6 +103,10 @@ public class ImpFormatElementHandler extends AbstractElementHandler {
throws SAXException {
int import_id = Env.getContextAsInt(ctx,
X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID);
if (formats.contains(import_id))
return;
formats.add(import_id);
AttributesImpl atts = new AttributesImpl();
X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, import_id, null);
atts = createImpFormatBinding(atts, m_ImpFormat);

View File

@ -18,6 +18,8 @@ package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -37,6 +39,8 @@ import org.xml.sax.helpers.AttributesImpl;
public class MessageElementHandler extends AbstractElementHandler {
private List<Integer> messages = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
@ -82,6 +86,9 @@ public class MessageElementHandler extends AbstractElementHandler {
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Message_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID);
if (messages.contains(AD_Message_ID))
return;
messages.add(AD_Message_ID);
String sql = "SELECT value FROM AD_Message WHERE AD_Message_ID= " + AD_Message_ID;
AttributesImpl atts = new AttributesImpl();
PreparedStatement pstmt = null;

View File

@ -20,6 +20,8 @@ package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -43,6 +45,8 @@ public class PrintFormatElementHandler extends AbstractElementHandler {
private PrintFormatItemElementHandler itemHandler = new PrintFormatItemElementHandler();
private List<Integer> formats = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
@ -178,6 +182,10 @@ public class PrintFormatElementHandler extends AbstractElementHandler {
throws SAXException {
int AD_PrintFormat_ID = Env.getContextAsInt(ctx,
X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID);
if (formats.contains(AD_PrintFormat_ID))
return;
formats.add(AD_PrintFormat_ID);
AttributesImpl atts = new AttributesImpl();
String sql = null;
sql = "SELECT AD_PrintFormat_ID "

View File

@ -19,6 +19,8 @@ package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -41,6 +43,8 @@ import org.xml.sax.helpers.AttributesImpl;
public class ProcessElementHandler extends AbstractElementHandler {
private ProcessParaElementHandler paraHandler = new ProcessParaElementHandler();
private List<Integer> processes = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
@ -161,6 +165,9 @@ public class ProcessElementHandler extends AbstractElementHandler {
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Process_ID = Env.getContextAsInt(ctx, "AD_Process_ID");
if (processes.contains(AD_Process_ID))
return;
processes.add(AD_Process_ID);
PackOut packOut = (PackOut) ctx.get("PackOutProcess");
String sqlW = "SELECT AD_Process_ID FROM AD_PROCESS WHERE AD_PROCESS_ID = "
+ AD_Process_ID;

View File

@ -19,6 +19,8 @@ package org.adempiere.pipo.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -42,6 +44,8 @@ public class ReportViewElementHandler extends AbstractElementHandler {
private ReportViewColElementHandler columnHandler = new ReportViewColElementHandler();
private List<Integer> views = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
@ -114,6 +118,10 @@ public class ReportViewElementHandler extends AbstractElementHandler {
throws SAXException {
PackOut packOut = (PackOut) ctx.get("PackOutProcess");
int AD_ReportView_ID = Env.getContextAsInt(ctx, "AD_ReportView_ID");
if (views.contains(AD_ReportView_ID))
return;
views.add(AD_ReportView_ID);
String sql = "SELECT * FROM AD_ReportView WHERE AD_ReportView_ID= "
+ AD_ReportView_ID;
PreparedStatement pstmt = null;

View File

@ -19,6 +19,8 @@ package org.adempiere.pipo.handler;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
@ -45,6 +47,8 @@ import org.xml.sax.helpers.AttributesImpl;
public class RoleElementHandler extends AbstractElementHandler {
private List<Integer> roles = new ArrayList<Integer>();
private OrgRoleElementHandler orgHandler = new OrgRoleElementHandler();
private ProcessAccessElementHandler processHandler = new ProcessAccessElementHandler();
private UserRoleElementHandler userHandler = new UserRoleElementHandler();
@ -196,6 +200,9 @@ public class RoleElementHandler extends AbstractElementHandler {
throws SAXException {
int Role_id = Env.getContextAsInt(ctx,
X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID);
if (roles.contains(Role_id))
return;
roles.add(Role_id);
X_AD_Role m_Role = new X_AD_Role(ctx, Role_id, null);
AttributesImpl atts = new AttributesImpl();
createRoleBinding(atts, m_Role);

View File

@ -161,6 +161,8 @@ public class TableElementHandler extends AbstractElementHandler {
while (rs1.next()){
packOut.createAdElement(rs1.getInt("AD_Element_ID"), document);
if (rs1.getInt("AD_Reference_ID")>0)
packOut.createReference (rs1.getInt("AD_Reference_ID"), document);

View File

@ -16,6 +16,8 @@
*****************************************************************************/
package org.adempiere.pipo.handler;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
@ -33,6 +35,8 @@ import org.xml.sax.helpers.AttributesImpl;
public class TaskElementHandler extends AbstractElementHandler {
private List<Integer> tasks = new ArrayList<Integer>();
public void startElement(Properties ctx, Element element)
throws SAXException {
String elementValue = element.getElementValue();
@ -83,6 +87,9 @@ public class TaskElementHandler extends AbstractElementHandler {
public void create(Properties ctx, TransformerHandler document)
throws SAXException {
int AD_Task_ID = Env.getContextAsInt(ctx, "AD_Task_ID");
if (tasks.contains(AD_Task_ID))
return;
tasks.add(AD_Task_ID);
X_AD_Task m_Task = new X_AD_Task(ctx, AD_Task_ID, null);
AttributesImpl atts = new AttributesImpl();
createTaskBinding(atts, m_Task);