IDEMPIERE-4279 Error on packout from the toolbar on certain windows (Table & Column, Window, Tab & Field) (#141)

This commit is contained in:
Carlos Ruiz 2020-06-30 14:04:50 +02:00 committed by GitHub
parent 6e2cf15fa9
commit e1c064b968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 110 additions and 195 deletions

View File

@ -2,7 +2,6 @@ package org.adempiere.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
@ -16,6 +15,7 @@ import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.compiere.model.MColumn;
import org.compiere.model.MLanguage;
import org.compiere.model.MTable;
import org.compiere.util.DB;
@ -87,7 +87,7 @@ public class CommonTranslationHandler extends AbstractElementHandler implements
PIPOContext ctx, Element element) throws SAXException{
String parentTable = tableName.substring(0, tableName.length()-4);
ArrayList<String> columns = getTranslatedColumns(parentTable);
ArrayList<String> columns = getTranslatedColumns(ctx, parentTable);
StringBuilder sql = new StringBuilder();
sql.append("INSERT INTO ")
.append(tableName)
@ -140,7 +140,7 @@ public class CommonTranslationHandler extends AbstractElementHandler implements
private void updateTranslation(String tableName, int parentID,
PIPOContext ctx, Element element) throws SAXException{
String parentTable = tableName.substring(0, tableName.length()-4);
ArrayList<String> columns = getTranslatedColumns(parentTable);
ArrayList<String> columns = getTranslatedColumns(ctx, parentTable);
StringBuilder buffer = new StringBuilder("UPDATE "+tableName+" SET ");
for (String columnName : columns) {
buffer.append(columnName).append("=?,");
@ -196,17 +196,18 @@ public class CommonTranslationHandler extends AbstractElementHandler implements
private void createTranslationTags(PIPOContext ctx, String parentTable,
int parentRecordID, TransformerHandler document) throws SAXException {
ArrayList<String> translatedColumns = getTranslatedColumns(parentTable);
ArrayList<String> translatedColumns = getTranslatedColumns(ctx, parentTable);
String sql =
"select "+cast(translatedColumns)+" from "+parentTable+"_trl where "+
parentTable+"_ID="+parentRecordID;
"SELECT "+cast(translatedColumns)+" FROM "+parentTable+"_Trl WHERE "+
parentTable+"_ID=?";
PreparedStatement pstm = null;
ResultSet rs = null;
try {
pstm = DB.prepareStatement(sql, null);
pstm = DB.prepareStatement(sql, getTrxName(ctx));
pstm.setInt(1, parentRecordID);
rs = pstm.executeQuery();
String elementName = parentTable + "_Trl";
@ -243,11 +244,12 @@ public class CommonTranslationHandler extends AbstractElementHandler implements
/**
*
* @param ctx
* @param parentTable
* @return
* @throws SAXException
*/
private ArrayList<String> getTranslatedColumns(String parentTable) throws SAXException {
private ArrayList<String> getTranslatedColumns(PIPOContext ctx, String parentTable) throws SAXException {
ArrayList<String> pipolColumns = cacheColumns.get(parentTable);
@ -256,27 +258,14 @@ public class CommonTranslationHandler extends AbstractElementHandler implements
}
ArrayList<String> 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 = null;
ResultSet rs = null;
try {
pstm = DB.prepareStatement(sql, null);
pstm.setString(1, parentTable);
rs = pstm.executeQuery();
while(rs.next()){
columns.add(rs.getString("columnName"));
MTable table = MTable.get(ctx.ctx, parentTable);
MColumn[] cols = table.getColumns(false);
for (MColumn col : cols) {
if (col.isTranslated()) {
columns.add(col.getColumnName());
}
} catch (SQLException e) {
e.printStackTrace();
throw new SAXException();
} finally {
DB.close(rs, pstm);
}
columns.add("AD_Language");
columns.add("IsActive");
columns.add("IsTranslated");

View File

@ -16,9 +16,6 @@
*****************************************************************************/
package org.adempiere.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
@ -31,7 +28,6 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.MReference;
@ -112,7 +108,7 @@ public class ReferenceElementHandler extends AbstractElementHandler {
AttributesImpl atts = new AttributesImpl();
MReference m_Reference = new MReference(ctx.ctx, Reference_id, getTrxName(ctx));
MReference m_Reference = MReference.get(ctx.ctx, Reference_id);
boolean createElement = isPackOutElement(ctx, m_Reference);
@ -130,36 +126,13 @@ public class ReferenceElementHandler extends AbstractElementHandler {
}
}
if (m_Reference.getValidationType().compareTo("L") == 0) {
String sql1 = "SELECT AD_REF_LIST_ID FROM AD_Ref_List WHERE AD_Reference_ID= "
+ Reference_id;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql1, getTrxName(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
createReferenceList(ctx, document, rs.getInt("AD_REF_LIST_ID"));
}
}
catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
if (e instanceof SAXException)
throw (SAXException) e;
else if (e instanceof SQLException)
throw new DatabaseAccessException("Failed to export Reference.", e);
else if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException("Failed to export Reference.", e);
} finally {
DB.close(rs, pstmt);
if (MReference.VALIDATIONTYPE_ListValidation.equals(m_Reference.getValidationType())) {
int[] rls = DB.getIDsEx(getTrxName(ctx), "SELECT AD_Ref_List_ID FROM AD_Ref_List WHERE AD_Reference_ID=?", Reference_id);
for (int rl : rls) {
createReferenceList(ctx, document, rl);
}
} else if (m_Reference.getValidationType().compareTo("T") == 0) {
} else if (MReference.VALIDATIONTYPE_TableValidation.equals(m_Reference.getValidationType())) {
createReferenceTable(ctx, document, Reference_id);
}

View File

@ -16,8 +16,6 @@
*****************************************************************************/
package org.adempiere.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.logging.Level;
@ -32,10 +30,10 @@ import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.compiere.model.I_AD_Ref_Table;
import org.compiere.model.MRefTable;
import org.compiere.model.MReference;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Ref_Table;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -102,47 +100,37 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
private void createReferenceTableBinding(PIPOContext ctx,
TransformerHandler document, int reference_ID) {
String sql = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID= "
+ reference_ID;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
rs = pstmt.executeQuery();
if (rs.next()) {
X_AD_Ref_Table refTable = new X_AD_Ref_Table(ctx.ctx, rs, getTrxName(ctx));
if (!isPackOutElement(ctx, refTable))
return;
MRefTable refTable = MRefTable.get(ctx.ctx, reference_ID);
if (!isPackOutElement(ctx, refTable))
return;
verifyPackOutRequirement(refTable);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", X_AD_Ref_Table.Table_Name, atts);
verifyPackOutRequirement(refTable);
if (reference_ID <= PackOut.MAX_OFFICIAL_ID)
{
PoExporter filler = new PoExporter(ctx,document,null);
filler.addString("AD_Reference_ID", Integer.toString(reference_ID), new AttributesImpl());
}
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", X_AD_Ref_Table.Table_Name, atts);
PoExporter filler = new PoExporter(ctx,document,refTable);
List<String > excludes = defaultExcludeList(X_AD_Ref_Table.Table_Name);
excludes.add("ad_display");
excludes.add("ad_key");
filler.export(excludes);
filler.addTableReference("AD_Display", "AD_Column", new AttributesImpl());
filler.addTableReference("AD_Key", "AD_Column", new AttributesImpl());
document.endElement("", "", X_AD_Ref_Table.Table_Name);
if (reference_ID <= PackOut.MAX_OFFICIAL_ID)
{
PoExporter filler = new PoExporter(ctx,document,null);
filler.addString("AD_Reference_ID", Integer.toString(reference_ID), new AttributesImpl());
}
PoExporter filler = new PoExporter(ctx,document,refTable);
List<String > excludes = defaultExcludeList(X_AD_Ref_Table.Table_Name);
excludes.add("ad_display");
excludes.add("ad_key");
filler.export(excludes);
filler.addTableReference("AD_Display", "AD_Column", new AttributesImpl());
filler.addTableReference("AD_Key", "AD_Column", new AttributesImpl());
document.endElement("", "", X_AD_Ref_Table.Table_Name);
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
throw new DatabaseAccessException("Failed to export Reference Table", e);
} finally {
DB.close(rs, pstmt);
}
}
@Override

View File

@ -16,8 +16,6 @@
*****************************************************************************/
package org.adempiere.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
@ -36,16 +34,17 @@ import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Table;
import org.compiere.model.MColumn;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable;
import org.compiere.model.MTableIndex;
import org.compiere.model.MViewComponent;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Column;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Table;
import org.compiere.process.DatabaseViewValidate;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Trx;
import org.xml.sax.SAXException;
@ -165,85 +164,67 @@ public class TableElementHandler extends AbstractElementHandler {
createTableBinding(ctx,document,m_Table);
}
String sql = "SELECT * FROM AD_Column WHERE AD_Table_ID = ? "
+ " ORDER BY IsKey DESC, AD_Column_ID"; // Export key column as the first one
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement (sql, getTrxName(ctx));
pstmt.setInt(1, AD_Table_ID);
rs = pstmt.executeQuery();
while (rs.next()){
List<MColumn> cols = new Query(ctx.ctx, MColumn.Table_Name, "AD_Table_ID=?", getTrxName(ctx))
.setParameters(AD_Table_ID)
.setOrderBy("IsKey DESC, AD_Column_ID") // Export key column as the first one
.list();
for (MColumn col : cols) {
ElementHandler handler = packOut.getHandler("AD_Element");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Column.COLUMNNAME_AD_Element_ID));
handler.packOut(packOut,document,null,col.getAD_Element_ID());
if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID)>0)
if (col.getAD_Reference_ID()>0)
{
handler = packOut.getHandler("AD_Reference");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID));
handler.packOut(packOut,document,null,col.getAD_Reference_ID());
}
if (rs.getInt("AD_Reference_Value_ID")>0)
if (col.getAD_Reference_Value_ID()>0)
{
handler = packOut.getHandler("AD_Reference");
handler.packOut(packOut,document,null,rs.getInt("AD_Reference_Value_ID"));
handler.packOut(packOut,document,null,col.getAD_Reference_Value_ID());
}
if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID)>0)
if (col.getAD_Process_ID()>0)
{
handler = packOut.getHandler("AD_Process");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID));
handler.packOut(packOut,document,null,col.getAD_Process_ID());
}
if (rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID)>0)
if (col.getAD_Val_Rule_ID()>0)
{
handler = packOut.getHandler("AD_Val_Rule");
handler.packOut(packOut,document,null,rs.getInt(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID));
handler.packOut(packOut,document,null,col.getAD_Val_Rule_ID());
}
createColumn(ctx, document, rs.getInt("AD_Column_ID"));
createColumn(ctx, document, col.getAD_Column_ID());
}
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
}
sql = "SELECT * FROM AD_TableIndex WHERE AD_Table_ID = ? ORDER BY AD_TableIndex_ID";
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement (sql, getTrxName(ctx));
pstmt.setInt(1, AD_Table_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
createTableIndex(ctx, document, rs.getInt(MTableIndex.COLUMNNAME_AD_TableIndex_ID));
try {
List<MTableIndex> tis = new Query(ctx.ctx, MTableIndex.Table_Name, "AD_Table_ID=?", getTrxName(ctx))
.setParameters(AD_Table_ID)
.setOrderBy("AD_TableIndex_ID")
.list();
for (MTableIndex ti : tis) {
createTableIndex(ctx, document, ti.getAD_TableIndex_ID());
}
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
}
sql = "SELECT * FROM AD_ViewComponent WHERE AD_Table_ID = ? ORDER BY SeqNo, AD_ViewComponent_ID";
pstmt = null;
rs = null;
try {
pstmt = DB.prepareStatement (sql, getTrxName(ctx));
pstmt.setInt(1, AD_Table_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
createViewComponent(ctx, document, rs.getInt(MViewComponent.COLUMNNAME_AD_ViewComponent_ID));
try {
List<MViewComponent> vcs = new Query(ctx.ctx, MViewComponent.Table_Name, "AD_Table_ID=?", getTrxName(ctx))
.setParameters(AD_Table_ID)
.setOrderBy("SeqNo, AD_ViewComponent_ID")
.list();
for (MViewComponent vc : vcs) {
createViewComponent(ctx, document, vc.getAD_ViewComponent_ID());
}
} catch (Exception e) {
throw new AdempiereException(e);
} finally {
DB.close(rs, pstmt);
}
if (createElement) {

View File

@ -16,31 +16,32 @@
*****************************************************************************/
package org.adempiere.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.DBException;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Exp_Detail;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_NextCondition;
import org.compiere.model.X_AD_WF_Node;
import org.compiere.model.X_AD_WF_NodeNext;
import org.compiere.model.X_AD_Workflow;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.wf.MWFNextCondition;
import org.compiere.wf.MWFNode;
import org.compiere.wf.MWFNodeNext;
import org.compiere.wf.MWorkflow;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -150,17 +151,14 @@ public class WorkflowElementHandler extends AbstractElementHandler {
if (ctx.packOut.isExported(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID+"|"+AD_Workflow_ID))
return;
PackOut packOut = ctx.packOut;
int ad_wf_nodenext_id = 0;
int ad_wf_nodenextcondition_id = 0;
AttributesImpl atts = new AttributesImpl();
MWorkflow m_Workflow = new MWorkflow(ctx.ctx,
AD_Workflow_ID, null);
MWorkflow m_Workflow = MWorkflow.get(ctx.ctx, AD_Workflow_ID);
boolean createElement = isPackOutElement(ctx, m_Workflow);
if (createElement) {
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow");
document.startElement("", "", I_AD_Workflow.Table_Name, atts);
document.startElement("", "", MWorkflow.Table_Name, atts);
createWorkflowBinding(ctx, document, m_Workflow);
packOut.getCtx().ctx.put("Table_Name",I_AD_Workflow.Table_Name);
@ -171,54 +169,40 @@ public class WorkflowElementHandler extends AbstractElementHandler {
}
}
String sql = "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID=? AND AD_Client_ID=?";
PreparedStatement pstmt = null;
PreparedStatement psNodeNext = null;
PreparedStatement psNCondition = null;
ResultSet rs = null;
ResultSet nodeNextrs = null;
ResultSet nodeNConditionrs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setInt(1, AD_Workflow_ID);
pstmt.setInt(2, Env.getAD_Client_ID(ctx.ctx));
// Generated workflowNodeNext(s) and
// workflowNodeNextCondition(s)
rs = pstmt.executeQuery();
while (rs.next()) {
int nodeId = rs.getInt("AD_WF_Node_ID");
List<MWFNode> wns = new Query(ctx.ctx, MWFNode.Table_Name, "AD_Workflow_ID=? AND AD_Client_ID=?", getTrxName(ctx))
.setParameters(AD_Workflow_ID, Env.getAD_Client_ID(ctx.ctx))
.list();
for (MWFNode wn : wns) {
int nodeId = wn.getAD_WF_Node_ID();
createNode(ctx, document, nodeId);
sql = "SELECT ad_wf_nodenext_id from ad_wf_nodenext WHERE ad_wf_node_id=? AND AD_Client_ID=?";
psNodeNext = DB.prepareStatement(sql, getTrxName(ctx));
psNodeNext.setInt(1, nodeId);
psNodeNext.setInt(2, Env.getAD_Client_ID(ctx.ctx));
nodeNextrs = psNodeNext.executeQuery();
while (nodeNextrs.next()){
ad_wf_nodenext_id = nodeNextrs.getInt("AD_WF_NodeNext_ID");
List<MWFNodeNext> wnns = new Query(ctx.ctx, MWFNodeNext.Table_Name, "AD_WF_Node_ID=? AND AD_Client_ID=?", getTrxName(ctx))
.setParameters(nodeId, Env.getAD_Client_ID(ctx.ctx))
.list();
for (MWFNodeNext wnn : wnns) {
int ad_wf_nodenext_id = wnn.getAD_WF_NodeNext_ID();
createNodeNext(ctx, document, ad_wf_nodenext_id);
sql = "SELECT ad_wf_nextcondition_id from ad_wf_nextcondition WHERE ad_wf_nodenext_id=? AND AD_Client_ID=?";
psNCondition = DB.prepareStatement(sql, getTrxName(ctx));
psNCondition.setInt(1, ad_wf_nodenext_id);
psNCondition.setInt(2, Env.getAD_Client_ID(ctx.ctx));
nodeNConditionrs = psNCondition.executeQuery();
while (nodeNConditionrs.next()) {
ad_wf_nodenextcondition_id= nodeNConditionrs.getInt("AD_WF_NextCondition_ID");
List<MWFNextCondition> wncs = new Query(ctx.ctx, MWFNextCondition.Table_Name, "AD_WF_NodeNext_ID=? AND AD_Client_ID=?", getTrxName(ctx))
.setParameters(ad_wf_nodenext_id, Env.getAD_Client_ID(ctx.ctx))
.list();
for (MWFNextCondition wnc : wncs) {
int ad_wf_nodenextcondition_id = wnc.getAD_WF_NextCondition_ID();
if (log.isLoggable(Level.INFO)) log.info("ad_wf_nodenextcondition_id: "+ String.valueOf(ad_wf_nodenextcondition_id));
createNodeNextCondition(ctx, document, ad_wf_nodenextcondition_id);
}
}
}
} catch (Exception e) {
throw new DBException(e);
} finally {
DB.close(rs, pstmt);
DB.close(nodeNextrs, psNodeNext);
DB.close(nodeNConditionrs,psNCondition);
if (createElement) {
document.endElement("", "", MWorkflow.Table_Name);
}
} catch (Exception e) {
throw new AdempiereException(e);
}
if (createElement) {
document.endElement("", "", MWorkflow.Table_Name);
}
}
private void createNodeNextCondition(PIPOContext ctx,