Skip to content

Commit

Permalink
Merge pull request #3989 from Coduz/fix-forwardableEntities
Browse files Browse the repository at this point in the history
🐛 (commons): fixes resolution of CertificateQuery forwardable entities when scopeId is `null`
  • Loading branch information
Coduz authored Mar 11, 2024
2 parents e839014 + 873ec86 commit 7d57436
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ public KapuaQuery transformInheritedQuery(@NotNull KapuaForwardableEntityQuery q
query.setScopeId(KapuaId.ANY);
OrPredicate forwardableAncestorPreds = query.orPredicate();

for (KapuaId id : accountRelativeFinder.findParentIds(scopeId)) {
AndPredicate scopedForwardablePred = query.andPredicate(query.attributePredicate(KapuaEntityAttributes.SCOPE_ID, id));
scopedForwardablePred = scopedForwardablePred.and(query.attributePredicate(KapuaForwardableEntityAttributes.FORWARDABLE, true));
if (scopeId != null) {
for (KapuaId id : accountRelativeFinder.findParentIds(scopeId)) {
AndPredicate scopedForwardablePred = query.andPredicate(query.attributePredicate(KapuaEntityAttributes.SCOPE_ID, id));
scopedForwardablePred = scopedForwardablePred.and(query.attributePredicate(KapuaForwardableEntityAttributes.FORWARDABLE, true));

forwardableAncestorPreds = forwardableAncestorPreds.or(scopedForwardablePred);
}
// include the original scope (which doesn't need to be forwardable)
forwardableAncestorPreds = forwardableAncestorPreds.or(query.attributePredicate(KapuaEntityAttributes.SCOPE_ID, scopeId));
forwardableAncestorPreds = forwardableAncestorPreds.or(scopedForwardablePred);
}

// include the original scope (which doesn't need to be forwardable)
forwardableAncestorPreds = forwardableAncestorPreds.or(query.attributePredicate(KapuaEntityAttributes.SCOPE_ID, scopeId));

// Use the original query predicate AND the forwardable parent scopes
query.setPredicate(newPred.and(forwardableAncestorPreds));
// Use the original query predicate AND the forwardable parent scopes
query.setPredicate(newPred.and(forwardableAncestorPreds));
}

// Disable this option so that it does not get transformed again in case of subsequent calls to this function
query.setIncludeInherited(false);
Expand Down

0 comments on commit 7d57436

Please sign in to comment.