From d3931bdf3cadafa57ea82882fff4f428396281e7 Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Wed, 24 Jul 2024 19:22:11 -0400 Subject: [PATCH] feat: Add `internal_id` on Tree Node. --- .../util/support/documents/MenuTree.java | 32 +++++++++++-------- .../support/documents/TreeNodeReference.java | 12 +++---- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/spin/eca56/util/support/documents/MenuTree.java b/src/main/java/org/spin/eca56/util/support/documents/MenuTree.java index df15169..4f28a7a 100644 --- a/src/main/java/org/spin/eca56/util/support/documents/MenuTree.java +++ b/src/main/java/org/spin/eca56/util/support/documents/MenuTree.java @@ -36,26 +36,27 @@ public class MenuTree extends DictionaryDocument { public static final String CHANNEL = "menu_tree"; public static final String KEY = "new"; - + @Override public String getKey() { return KEY; } - + private Map convertNode(TreeNodeReference node) { Map detail = new HashMap<>(); detail.put("node_id", node.getNodeId()); + detail.put("internal_id", node.getNodeId()); detail.put("parent_id", node.getParentId()); detail.put("sequence", node.getSequence()); return detail; } - + @Override public DictionaryDocument withEntity(PO entity) { MTree tree = (MTree) entity; return withNode(tree); } - + private List getChildren(int treeId, int parentId) { String tableName = MTree.getNodeTableName(MTree.TREETYPE_Menu); final String sql = "SELECT tn.Node_ID, tn.SeqNo " @@ -69,17 +70,21 @@ private List getChildren(int treeId, int parentId) { DB.runResultSet(null, sql, parameters, resulset -> { while (resulset.next()) { nodeIds.add(TreeNodeReference.newInstance() - .withNodeId(resulset.getInt("Node_ID")) - .withParentId(parentId) - .withSequence(resulset.getInt("SeqNo"))); + .withNodeId( + resulset.getInt("Node_ID") + ) + .withParentId(parentId) + .withSequence( + resulset.getInt("SeqNo")) + ) + ; } }).onFailure(throwable -> { throw new AdempiereException(throwable); }); return nodeIds; } - - + public MenuTree withNode(MTree tree) { List children = getChildren(tree.getAD_Tree_ID(), 0); Map documentDetail = convertNode(TreeNodeReference.newInstance()); @@ -97,7 +102,7 @@ public MenuTree withNode(MTree tree) { putDocument(documentDetail); return this; } - + /** * Add children to menu * @param context @@ -115,11 +120,11 @@ private void addChildren(int treeId, TreeNodeReference node, Map }); parent.put("children", childrenAsMap); } - + private MenuTree() { super(); } - + /** * Default instance * @return @@ -127,7 +132,7 @@ private MenuTree() { public static MenuTree newInstance() { return new MenuTree(); } - + @Override public String getLanguage() { return null; @@ -137,4 +142,5 @@ public String getLanguage() { public String getChannel() { return CHANNEL; } + } diff --git a/src/main/java/org/spin/eca56/util/support/documents/TreeNodeReference.java b/src/main/java/org/spin/eca56/util/support/documents/TreeNodeReference.java index ab514f9..93a8723 100644 --- a/src/main/java/org/spin/eca56/util/support/documents/TreeNodeReference.java +++ b/src/main/java/org/spin/eca56/util/support/documents/TreeNodeReference.java @@ -25,36 +25,34 @@ public class TreeNodeReference { private int nodeId; private int parentId; private int sequence; - + public static TreeNodeReference newInstance() { return new TreeNodeReference(); } - + public int getNodeId() { return nodeId; } - public TreeNodeReference withNodeId(int nodeId) { this.nodeId = nodeId; return this; } - + public int getParentId() { return parentId; } - public TreeNodeReference withParentId(int parentId) { this.parentId = parentId; return this; } - + public int getSequence() { return sequence; } - public TreeNodeReference withSequence(int sequence) { this.sequence = sequence; return this; } + }