Skip to content

Commit

Permalink
feat: Add internal_id on Tree Node.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Jul 24, 2024
1 parent 80e7a55 commit d3931bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
32 changes: 19 additions & 13 deletions src/main/java/org/spin/eca56/util/support/documents/MenuTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> convertNode(TreeNodeReference node) {
Map<String, Object> 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<TreeNodeReference> getChildren(int treeId, int parentId) {
String tableName = MTree.getNodeTableName(MTree.TREETYPE_Menu);
final String sql = "SELECT tn.Node_ID, tn.SeqNo "
Expand All @@ -69,17 +70,21 @@ private List<TreeNodeReference> 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<TreeNodeReference> children = getChildren(tree.getAD_Tree_ID(), 0);
Map<String, Object> documentDetail = convertNode(TreeNodeReference.newInstance());
Expand All @@ -97,7 +102,7 @@ public MenuTree withNode(MTree tree) {
putDocument(documentDetail);
return this;
}

/**
* Add children to menu
* @param context
Expand All @@ -115,19 +120,19 @@ private void addChildren(int treeId, TreeNodeReference node, Map<String, Object>
});
parent.put("children", childrenAsMap);
}

private MenuTree() {
super();
}

/**
* Default instance
* @return
*/
public static MenuTree newInstance() {
return new MenuTree();
}

@Override
public String getLanguage() {
return null;
Expand All @@ -137,4 +142,5 @@ public String getLanguage() {
public String getChannel() {
return CHANNEL;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit d3931bd

Please sign in to comment.