IDEMPIERE-4859 PackOut with AD_Menu (AD_TreeNodeMM) (FHCA-1374) (#757)

* IDEMPIERE-4859 PackOut with AD_Menu (AD_TreeNodeMM) (FHCA-1374)

* IDEMPIERE-4859 PackOut with AD_Menu (AD_TreeNodeMM) (FHCA-1374)
This commit is contained in:
Carlos Ruiz 2021-07-02 12:09:50 +02:00 committed by GitHub
parent fbc4feaf08
commit 90af0eb806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 50 deletions

View File

@ -20,17 +20,18 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.DBException; import org.adempiere.exceptions.DBException;
import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.ElementHandler; import org.adempiere.pipo2.ElementHandler;
import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils; import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Form; import org.compiere.model.I_AD_Form;
@ -105,20 +106,26 @@ public class MenuElementHandler extends AbstractElementHandler {
parentId = ReferenceUtils.resolveReference(ctx.ctx, parentElement, getTrxName(ctx)); parentId = ReferenceUtils.resolveReference(ctx.ctx, parentElement, getTrxName(ctx));
} }
StringBuilder updateSQL = null; String strSeqNo = getStringValue(element, "SeqNo");
int seqNo = 0;
if (strSeqNo != null)
seqNo = Integer.valueOf(strSeqNo);
int AD_Tree_ID = getDefaultMenuTreeId(); int AD_Tree_ID = getDefaultMenuTreeId();
String sql = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = "+AD_Tree_ID
+ " AND Node_ID = " + mMenu.getAD_Menu_ID(); final String updateSeqNo = "UPDATE AD_TREENODEMM SET SeqNo=SeqNo+1 WHERE Parent_ID=? AND SeqNo>=? AND AD_Tree_ID=?";
int countRecords = DB.getSQLValue(getTrxName(ctx), sql);
final String sql1 = "SELECT COUNT(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID=? AND Node_ID=?";
int countRecords = DB.getSQLValueEx(getTrxName(ctx), sql1, AD_Tree_ID, mMenu.getAD_Menu_ID());
if (countRecords > 0) { if (countRecords > 0) {
sql = "select * from AD_TREENODEMM where AD_Tree_ID = "+AD_Tree_ID+" and " int oldseqNo = 0;
+ " Node_ID =?"; final String sql2 = "SELECT * FROM AD_TREENODEMM WHERE AD_Tree_ID=? AND Node_ID=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pstmt = DB.prepareStatement(sql, pstmt = DB.prepareStatement(sql2, getTrxName(ctx));
getTrxName(ctx)); pstmt.setInt(1, AD_Tree_ID);
pstmt.setInt(1, mMenu.getAD_Menu_ID()); pstmt.setInt(2, mMenu.getAD_Menu_ID());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
@ -130,10 +137,10 @@ public class MenuElementHandler extends AbstractElementHandler {
for (int q = 1; q <= columns; q++) { for (int q = 1; q <= columns; q++) {
String colName = meta.getColumnName(q).toUpperCase(); String colName = meta.getColumnName(q).toUpperCase();
sql = "SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = ? AND AD_Table_ID = ?"; final String sql3 = "SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = ? AND AD_Table_ID = ?";
int columnID = DB.getSQLValue(getTrxName(ctx), sql, colName, tableID); int columnID = DB.getSQLValueEx(getTrxName(ctx), sql3, colName, tableID);
sql = "SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?"; final String sql4 = "SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?";
int referenceID = DB.getSQLValue(getTrxName(ctx), sql, columnID); int referenceID = DB.getSQLValueEx(getTrxName(ctx), sql4, columnID);
Object obj = rs.getObject(q); Object obj = rs.getObject(q);
colValue = obj == null ? "" : obj.toString(); colValue = obj == null ? "" : obj.toString();
X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx.ctx, 0, getTrxName(ctx)); X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx.ctx, 0, getTrxName(ctx));
@ -145,7 +152,9 @@ public class MenuElementHandler extends AbstractElementHandler {
backup.setColValue(colValue); backup.setColValue(colValue);
backup.saveEx(); backup.saveEx();
} }
oldseqNo = rs.getInt("SeqNo");
if (rs.wasNull())
oldseqNo = seqNo;
} }
} catch (Exception e) { } catch (Exception e) {
@ -153,25 +162,19 @@ public class MenuElementHandler extends AbstractElementHandler {
} finally { } finally {
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
if (seqNo != oldseqNo)
updateSQL = new StringBuilder("UPDATE AD_TREENODEMM ").append( DB.executeUpdateEx(updateSeqNo, new Object[] {parentId, seqNo, AD_Tree_ID}, getTrxName(ctx));
"SET Parent_ID = " + parentId).append( final String updateSQL = "UPDATE AD_TREENODEMM SET Parent_ID=?, SeqNo=? WHERE AD_Tree_ID=? AND Node_ID=?";
" , SeqNo = " + getStringValue(element, "SeqNo")).append( DB.executeUpdateEx(updateSQL, new Object[] {parentId, seqNo, AD_Tree_ID, mMenu.getAD_Menu_ID()}, getTrxName(ctx));
" WHERE AD_Tree_ID = "+AD_Tree_ID).append(
" AND Node_ID = " + mMenu.getAD_Menu_ID());
} else { } else {
updateSQL = new StringBuilder("INSERT INTO AD_TREENODEMM").append( DB.executeUpdateEx(updateSeqNo, new Object[] {parentId, seqNo, AD_Tree_ID}, getTrxName(ctx));
"(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append( final String insertSQL = "INSERT INTO AD_TREENODEMM (AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy,Parent_ID, SeqNo, AD_Tree_ID, Node_ID, AD_TREENODEMM_UU) VALUES(0,0,0,0,?,?,?,?,?)";
"Parent_ID, SeqNo, AD_Tree_ID, Node_ID)").append( DB.executeUpdateEx(insertSQL, new Object[] {parentId, seqNo, AD_Tree_ID, mMenu.getAD_Menu_ID(), UUID.randomUUID().toString()}, getTrxName(ctx));
"VALUES(0, 0, 0, 0, ").append(
parentId + "," + getStringValue(element, "SeqNo") + ", "+AD_Tree_ID+", "
+ mMenu.getAD_Menu_ID() + ")");
} }
DB.executeUpdate(updateSQL.toString(), getTrxName(ctx));
} }
private int getDefaultMenuTreeId() { private int getDefaultMenuTreeId() {
return DB.getSQLValue(null, "SELECT AD_Tree_ID FROM AD_Tree WHERE TreeType='MM' AND AD_Client_ID=0 ORDER BY IsDefault DESC, AD_Tree_ID"); return DB.getSQLValueEx(null, "SELECT AD_Tree_ID FROM AD_Tree WHERE TreeType='MM' AND AD_Client_ID=0 ORDER BY IsDefault DESC, AD_Tree_ID");
} }
public void endElement(PIPOContext ctx, Element element) throws SAXException { public void endElement(PIPOContext ctx, Element element) throws SAXException {
@ -211,13 +214,13 @@ public class MenuElementHandler extends AbstractElementHandler {
PoExporter filler = new PoExporter(ctx, document, m_Menu); PoExporter filler = new PoExporter(ctx, document, m_Menu);
List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name);
int AD_Tree_ID = getDefaultMenuTreeId(); int AD_Tree_ID = getDefaultMenuTreeId();
String sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = "+AD_Tree_ID+" and Node_ID=?"; final String sql1 = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID=? AND Node_ID=?";
int id = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID()); int id = DB.getSQLValueEx(null, sql1, AD_Tree_ID, m_Menu.getAD_Menu_ID());
if (id > 0) { if (id > 0) {
filler.addTableReference("Parent_ID", "AD_Menu", id, new AttributesImpl()); filler.addTableReference("Parent_ID", "AD_Menu", id, new AttributesImpl());
} }
sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = "+AD_Tree_ID+" and Node_ID=?"; final String sql2 = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID=? AND Node_ID=?";
int seqNo = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID()); int seqNo = DB.getSQLValueEx(null, sql2, AD_Tree_ID, m_Menu.getAD_Menu_ID());
filler.addString("SeqNo", Integer.toString(seqNo), new AttributesImpl()); filler.addString("SeqNo", Integer.toString(seqNo), new AttributesImpl());
if (m_Menu.getAD_Menu_ID() <= PackOut.MAX_OFFICIAL_ID) if (m_Menu.getAD_Menu_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.addString("AD_Menu_ID", Integer.toString(m_Menu.getAD_Menu_ID()), new AttributesImpl()); filler.addString("AD_Menu_ID", Integer.toString(m_Menu.getAD_Menu_ID()), new AttributesImpl());
@ -228,18 +231,18 @@ public class MenuElementHandler extends AbstractElementHandler {
private void createApplication(PIPOContext ctx, TransformerHandler document, private void createApplication(PIPOContext ctx, TransformerHandler document,
int AD_Menu_ID) throws SAXException { int AD_Menu_ID) throws SAXException {
PackOut packOut = ctx.packOut; PackOut packOut = ctx.packOut;
String sql = null;
int AD_Tree_ID = getDefaultMenuTreeId(); int AD_Tree_ID = getDefaultMenuTreeId();
sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " final String sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, "
+ "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID, B.AD_INFOWINDOW_ID " + "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID, B.AD_INFOWINDOW_ID "
+ "FROM AD_TreeNodeMM A, AD_Menu B " + "FROM AD_TreeNodeMM A, AD_Menu B "
+ "WHERE A.Node_ID = " + "WHERE A.Node_ID=? AND A.Node_ID = B.AD_Menu_ID AND A.AD_Tree_ID=?";
+ AD_Menu_ID + " AND A.Node_ID = B.AD_Menu_ID" + " AND A.AD_Tree_ID="+AD_Tree_ID;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx)); pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setInt(1, AD_Menu_ID);
pstmt.setInt(2, AD_Tree_ID);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
@ -310,18 +313,18 @@ public class MenuElementHandler extends AbstractElementHandler {
public void createModule(PIPOContext ctx, TransformerHandler document, public void createModule(PIPOContext ctx, TransformerHandler document,
int menu_id) throws SAXException { int menu_id) throws SAXException {
PackOut packOut = ctx.packOut; PackOut packOut = ctx.packOut;
String sql = null;
int AD_Tree_ID = getDefaultMenuTreeId(); int AD_Tree_ID = getDefaultMenuTreeId();
sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " final String sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, "
+ "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID, B.AD_INFOWINDOW_ID " + "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID, B.AD_INFOWINDOW_ID "
+ "FROM AD_TreeNodeMM A, AD_Menu B " + "FROM AD_TreeNodeMM A, AD_Menu B "
+ "WHERE A.Parent_ID = " + "WHERE A.Parent_ID=? AND A.Node_ID = B.AD_Menu_ID AND A.AD_Tree_ID=?";
+ menu_id + " AND A.Node_ID = B.AD_Menu_ID" + " AND A.AD_Tree_ID="+AD_Tree_ID;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx)); pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setInt(1, menu_id);
pstmt.setInt(2, AD_Tree_ID);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
// Menu tag Start. // Menu tag Start.
@ -390,11 +393,3 @@ public class MenuElementHandler extends AbstractElementHandler {
packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID); packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID);
} }
} }