From 105be2e9ea1a616194f21f6a11107bf332fe1f62 Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Wed, 15 Jan 2025 11:29:28 -0400 Subject: [PATCH] fix: Infinity loop when `Node_ID` equal `0`. --- .../util/queue/ApplicationDictionary.java | 2 ++ .../util/support/documents/MenuTree.java | 23 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/kafka/src/main/java/base/org/spin/eca56/util/queue/ApplicationDictionary.java b/kafka/src/main/java/base/org/spin/eca56/util/queue/ApplicationDictionary.java index 8e375519a..b552f21ad 100644 --- a/kafka/src/main/java/base/org/spin/eca56/util/queue/ApplicationDictionary.java +++ b/kafka/src/main/java/base/org/spin/eca56/util/queue/ApplicationDictionary.java @@ -64,6 +64,7 @@ public void add(int queueId) { queue.setProcessed(true); queue.saveEx(); } catch (Throwable e) { + e.printStackTrace(); logger.warning(e.getLocalizedMessage()); } } @@ -92,6 +93,7 @@ public void send(int queueId) { if(documentByLanguage != null) { sender.send(documentByLanguage, documentByLanguage.getChannel()); } + // TODO: Skip with `AD_Tree` and `AD_Role` getLanguages().forEach(languageId -> { MLanguage language = new MLanguage(getContext(), languageId, getTransactionName()); IGenericDictionaryDocument aloneDocument = getDocumentManager(entity, language.getAD_Language()); diff --git a/kafka/src/main/java/base/org/spin/eca56/util/support/documents/MenuTree.java b/kafka/src/main/java/base/org/spin/eca56/util/support/documents/MenuTree.java index d78f82df8..c5c97bc47 100644 --- a/kafka/src/main/java/base/org/spin/eca56/util/support/documents/MenuTree.java +++ b/kafka/src/main/java/base/org/spin/eca56/util/support/documents/MenuTree.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; +import org.adempiere.core.domains.models.I_AD_TreeNodeMM; import org.adempiere.exceptions.AdempiereException; import org.compiere.model.MTree; import org.compiere.model.PO; @@ -60,30 +61,36 @@ public DictionaryDocument withEntity(PO entity) { private List getChildren(int treeId, int parentId) { String tableName = MTree.getNodeTableName(MTree.TREETYPE_Menu); final String sql = "SELECT tn.Node_ID, tn.SeqNo " - + "FROM " + tableName + " tn " - + "WHERE tn.AD_Tree_ID = ? " - + "AND COALESCE(tn.Parent_ID, 0) = ?" + + "FROM " + tableName + " tn " + + "WHERE tn.Node_ID > 0 " + + "AND tn.AD_Tree_ID = ? " + + "AND COALESCE(tn.Parent_ID, 0) = ?" ; List parameters = new ArrayList(); parameters.add(treeId); parameters.add(parentId); - List nodeIds = new ArrayList(); + List nodesList = new ArrayList(); DB.runResultSet(null, sql, parameters, resulset -> { while (resulset.next()) { - nodeIds.add(TreeNodeReference.newInstance() + TreeNodeReference treeNode = TreeNodeReference.newInstance() .withNodeId( - resulset.getInt("Node_ID") + resulset.getInt( + I_AD_TreeNodeMM.COLUMNNAME_Node_ID + ) ) .withParentId(parentId) .withSequence( - resulset.getInt("SeqNo")) + resulset.getInt( + I_AD_TreeNodeMM.COLUMNNAME_SeqNo + ) ) ; + nodesList.add(treeNode); } }).onFailure(throwable -> { throw new AdempiereException(throwable); }); - return nodeIds; + return nodesList; } public MenuTree withNode(MTree tree) {