Skip to content

Commit

Permalink
Merge pull request #1 from EdwinBetanc0urt/bugfix/infinity-loop-node-…
Browse files Browse the repository at this point in the history
…id-zero

fix: Infinity loop when `Node_ID` equal `0`.
  • Loading branch information
yamelsenih authored Jan 15, 2025
2 parents 11f38f1 + 105be2e commit 4e079bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void add(int queueId) {
queue.setProcessed(true);
queue.saveEx();
} catch (Throwable e) {
e.printStackTrace();
logger.warning(e.getLocalizedMessage());
}
}
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,30 +61,36 @@ public DictionaryDocument withEntity(PO entity) {
private List<TreeNodeReference> 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<Object> parameters = new ArrayList<Object>();
parameters.add(treeId);
parameters.add(parentId);
List<TreeNodeReference> nodeIds = new ArrayList<TreeNodeReference>();
List<TreeNodeReference> nodesList = new ArrayList<TreeNodeReference>();
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) {
Expand Down

0 comments on commit 4e079bd

Please sign in to comment.