Skip to content

[NAE-2460] PFQL placeholder support#461

Open
Retoocs wants to merge 5 commits into
release/6.5.0from
NAE-2460
Open

[NAE-2460] PFQL placeholder support#461
Retoocs wants to merge 5 commits into
release/6.5.0from
NAE-2460

Conversation

@Retoocs

@Retoocs Retoocs commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

Added placeholders loggedUser.id, loggedUser.username, loggedUser.fullName and loggedUser.anonymous. The placeholders can be used:

  • anywhere in string comparisons (also in list, in range) (expect .anonymous)
  • anywhere in boolean comparisons (only .anonymous)
  • anywhere in object id comparisons (only .id)

Implements NAE-2460

Dependencies

No new dependencies were introduced

Third party dependencies

No new dependencies were introduced

Blocking Pull requests

There are no dependencies on other PR

How Has Been This Tested?

By unit test: QueryLangTest

Test Configuration

Name Tested on
OS Ubuntu 24.04.1 LTS
Runtime Java 11
Dependency Manager Maven 3.6.3
Framework version Spring Boot 2.7.8
Run parameters
Other configuration

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes have been checked, personally or remotely, with @...
  • I have commented my code, particularly in hard-to-understand areas
  • I have resolved all conflicts with the target branch of the PR
  • I have updated and synced my code with the target branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes:
    • Lint test
    • Unit tests
    • Integration tests
  • I have checked my contribution with code analysis tools:
  • I have made corresponding changes to the documentation:
    • Developer documentation
    • User Guides
    • Migration Guides

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added support for “logged user” placeholders in PFQL queries (ID, full name, username, and anonymous status), including within comparisons, lists, and ranges.
  • Bug Fixes

    • PFQL query generation now resolves logged-user placeholders into concrete values correctly for both MongoDB and Elastic conditions.
    • Improved handling of logged-anonymous comparisons.
  • Tests

    • Enabled and expanded coverage for logged-user placeholder behavior across MongoDB and Elastic, including added negative validation cases.

Retoocs added 2 commits July 8, 2026 18:06
- add LoggedUser placeholder to PFQL
- update tests
- add todo
@Retoocs Retoocs self-assigned this Jul 9, 2026
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Retoocs, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0efdcc67-ce58-4d1d-9010-294a4b9f57a8

📥 Commits

Reviewing files that changed from the base of the PR and between 757be9f and 088f68e.

📒 Files selected for processing (1)
  • src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java

Walkthrough

This PR adds PFQL support for loggedUser.* placeholders in grammar and query evaluation. QueryLangEvaluator resolves these values through IUserService, SearchUtils passes the service in, and tests are updated for MongoDB and Elastic expectations plus invalid placeholder cases.

Changes

PFQL loggedUser placeholder support

Layer / File(s) Summary
Grammar rules for loggedUser placeholders
src/main/java/com/netgrif/application/engine/pfql/domain/antlr4/QueryLang.g4
Adds logged-user placeholder tokens and grammar rules, and allows them in comparison, list, and range expressions.
Evaluator helpers and constructor
src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java
Adds IUserService injection and placeholder-aware helper methods for strings, IDs, booleans, lists, and ranges.
Evaluator exit handlers using resolved values
src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java
Updates the query listener methods to use resolved placeholder values instead of raw token text across ID and process-related comparisons.
Evaluator field and data value handlers
src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java
Updates surname, email, data, and task query handlers to use the new placeholder-aware value resolution.
Wiring and query assertions
src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java, src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java
Wires IUserService into evaluator construction and updates query tests for logged-user values and failure cases.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: new feature, Medium

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.47% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding PFQL placeholder support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Retoocs Retoocs marked this pull request as ready for review July 9, 2026 07:16
@coderabbitai coderabbitai Bot added improvement A change that improves on an existing feature Medium new feature A change that introduces new functionality labels Jul 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java`:
- Around line 189-203: handleObjectIdListComparison currently adds the logged
user id once for any loggedUser.* entries, which incorrectly treats all
placeholders as the same value. Update the StringListContext handling so each
ctx.loggedUserStringAttribute() element is resolved individually using its own
attribute and converted through getObjectIdValue, instead of always using
loggedUser.getId(). Make sure the logic in QueryLangEvaluator distinguishes
loggedUser.id from other logged user attributes and rejects unsupported non-id
attributes in this ObjectId comparison path.
- Around line 220-235: The stringRange endpoint resolution in
handleInRangeStringComparison is using indexed token accessors that can swap
left/right sides and bypass logged-user placeholder parsing. Update this method
to iterate ctx.children in order, resolve each endpoint by its actual node type,
and route loggedUserStringAttribute nodes through
handleLoggedUserStringAttribute(...) instead of using getText(). Ensure mixed
literal/placeholder ranges preserve the original endpoint order.

In `@src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java`:
- Around line 908-916: The `case: id in (...)` behavior is inconsistent between
Mongo and Elastic because `handleObjectIdListComparison()` in the query handling
path normalizes every `loggedUser.*` token to the user ID, while the Elastic
query builder preserves `loggedUser.username` and `loggedUser.fullName` values;
update the Elastic-side handling to match the Mongo normalization, or centralize
the normalization so both backends resolve `id` list comparisons the same way in
`QueryLangTest`-covered behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d3d81d01-9a1c-499b-b54c-e099c00f8af3

📥 Commits

Reviewing files that changed from the base of the PR and between 49e9ed6 and a212caa.

📒 Files selected for processing (4)
  • src/main/java/com/netgrif/application/engine/pfql/domain/antlr4/QueryLang.g4
  • src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java
  • src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java
  • src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java

Comment thread src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java Outdated
@coderabbitai coderabbitai Bot removed the improvement A change that improves on an existing feature label Jul 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java`:
- Around line 326-330: Add coverage for range comparisons that use loggedUser
placeholders so the evaluator path is exercised in both Mongo and Elastic tests.
Update the relevant query language tests around the existing comparison cases to
include a query like a range using loggedUser.username or loggedUser.fullName,
and assert the resolved user value is used rather than the raw token text. Use
QueryLangEvaluator.handleInRangeStringComparison and the loggedUser.* handling
methods as the key symbols to locate the fix and ensure the tests fail until the
placeholder is properly resolved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3e583106-22da-4008-9375-5eade5f9eabd

📥 Commits

Reviewing files that changed from the base of the PR and between a212caa and e078a99.

📒 Files selected for processing (2)
  • src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java
  • src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java

Retoocs added 2 commits July 9, 2026 12:14
- fix QueryLangEvaluator.handleInRangeStringComparison

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java (1)

857-858: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Derive the Elastic process-id list from resolved ObjectIds.

Line 858 reintroduces non-ObjectId placeholders into the Elastic query even though Line 857 filters object-id semantics via handleObjectIdListComparison(...). For example, processId in (loggedUser.id, loggedUser.username) resolves Mongo to only the user id, but Elastic gets both the id and username. Mirror exitIdList and derive the string list from objectIdList.

🐛 Proposed fix
         boolean not = ctx.inListStringComparison().NOT() != null;
         List<ObjectId> objectIdList = handleObjectIdListComparison(ctx.inListStringComparison().stringList());
-        List<String> stringList = handleStringListComparison(ctx.inListStringComparison().stringList());
+        List<String> stringList = objectIdList.stream().map(ObjectId::toString).collect(Collectors.toList());
 
         setMongoQuery(ctx, buildObjectIdPredicateInList(qObjectId, objectIdList, not));
         setElasticQuery(ctx, buildElasticQueryInList("processId", stringList, not));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java`
around lines 857 - 858, The Elastic process-id list is being built from the raw
string list instead of the resolved ObjectIds, so placeholders that don’t map to
an ObjectId slip back into the query. In QueryLangEvaluator, update the in-list
handling around handleObjectIdListComparison(...) to derive the String list from
objectIdList, mirroring exitIdList, and ensure only the resolved ids are used
for the Elastic query path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java`:
- Around line 857-858: The Elastic process-id list is being built from the raw
string list instead of the resolved ObjectIds, so placeholders that don’t map to
an ObjectId slip back into the query. In QueryLangEvaluator, update the in-list
handling around handleObjectIdListComparison(...) to derive the String list from
objectIdList, mirroring exitIdList, and ensure only the resolved ids are used
for the Elastic query path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 047b2eeb-204e-494b-9b86-ab1bb5bf019c

📥 Commits

Reviewing files that changed from the base of the PR and between e078a99 and 757be9f.

📒 Files selected for processing (2)
  • src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java
  • src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Medium new feature A change that introduces new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants