Skip to content

Conversation

Kovy95
Copy link
Contributor

@Kovy95 Kovy95 commented Aug 7, 2025

Description

  • optimize queries for elastic and mongo for cases and tasks

Implements NAE-2161

Dependencies

none

Third party dependencies

No new dependencies were introduced

Blocking Pull requests

There are no dependencies on other PR

How Has Been This Tested?

manually

Test Configuration

Name Tested on
OS linuxmint 21
Runtime java 21
Dependency Manager Maven 3.9.9
Framework version Spring Boot 3.4.4
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

  • Chores

    • Updated project version from 7.0.0-SNAPSHOT to 7.0.0-RC5 across all modules.
  • Refactor

    • Improved performance and maintainability of Elasticsearch query building, resulting in more efficient search operations and streamlined internal logic. No changes to public APIs or user-facing features.

@Kovy95 Kovy95 self-assigned this Aug 7, 2025
Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

The changes update the Maven parent and project versions from 7.0.0-SNAPSHOT to 7.0.0-RC5 across multiple modules. Additionally, several Java service classes are refactored to optimize and unify query construction, replacing manual Boolean query assembly with more efficient and idiomatic use of Elasticsearch's terms queries and predicate tree utilities.

Changes

Cohort / File(s) Change Summary
Maven Version Updates
pom.xml, application-engine/pom.xml, nae-object-library/pom.xml, nae-spring-core-adapter/pom.xml, nae-user-ce/pom.xml, nae-user-common/pom.xml
Updated parent and project versions from 7.0.0-SNAPSHOT to 7.0.0-RC5. No other dependency or configuration changes were made.
ElasticCaseService Query Refactor
application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseService.java
Refactored query-building methods to use Elasticsearch TermsQueryField and QueryBuilders.terms for constructing "terms" queries, replacing manual Boolean query assembly. Improved code style and simplified logic for empty checks and return statements. No changes to method signatures.
ElasticTaskService Query Refactor
application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticTaskService.java
Replaced manual loops adding individual term queries with single terms queries using TermsQueryField. Simplified empty checks and consolidated logic for process and group queries. No changes to public method signatures.
ElasticViewPermissionService Query Refactor
application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticViewPermissionService.java
Streamlined Elasticsearch BoolQuery construction using builder pattern and TermsQueryField. Consolidated multiple single-term queries into single terms queries, simplified positive/negative user and role query methods, and refactored helper methods for union and set-minus operations. No changes to public interfaces.
CaseSearchService Predicate Refactor
application-engine/src/main/java/com/netgrif/application/engine/workflow/service/CaseSearchService.java
Replaced manual predicate combination with calls to a utility method constructPredicateTree, simplifying the logic for combining predicates in several methods. No changes to method signatures or exported entities.

Sequence Diagram(s)

sequenceDiagram
    participant Service as Service Method (e.g., buildPetriNetQuery)
    participant QueryBuilder as QueryBuilders / TermsQueryField
    participant ES as Elasticsearch

    Service->>QueryBuilder: Collect identifiers/IDs into TermsQueryField
    Service->>QueryBuilder: Build terms query with QueryBuilders.terms
    QueryBuilder-->>Service: Return terms query
    Service->>ES: Add terms query to BoolQuery and execute
    ES-->>Service: Return query result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Suggested labels

improvement

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch NAE-2161

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot added the improvement A change that improves on an existing feature label Aug 7, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (4)
nae-user-ce/pom.xml (1)

6-10: Same concern as in nae-user-common/pom.xml – parent version bump requires the artifact to be published.

application-engine/pom.xml (1)

6-10: Same concern as in nae-user-common/pom.xml – parent version bump requires the artifact to be published.

nae-object-library/pom.xml (1)

7-11: Same concern as in nae-user-common/pom.xml – parent version bump requires the artifact to be published.

nae-spring-core-adapter/pom.xml (1)

7-11: Same concern as in nae-user-common/pom.xml – parent version bump requires the artifact to be published.

🧹 Nitpick comments (1)
application-engine/src/main/java/com/netgrif/application/engine/workflow/service/CaseSearchService.java (1)

347-348: Remove unnecessary cast to List.

The explicit cast is redundant since collect(Collectors.toList()) already returns a List.

-            List<Predicate> expressions = (List<Predicate>) ((ArrayList) query).stream().filter(q -> q instanceof String).map(q -> caseIdString((String) q)).collect(Collectors.toList());
+            List<Predicate> expressions = ((ArrayList) query).stream().filter(q -> q instanceof String).map(q -> caseIdString((String) q)).collect(Collectors.toList());
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee37ab4 and bbb920e.

📒 Files selected for processing (10)
  • application-engine/pom.xml (1 hunks)
  • application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseService.java (8 hunks)
  • application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticTaskService.java (3 hunks)
  • application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticViewPermissionService.java (3 hunks)
  • application-engine/src/main/java/com/netgrif/application/engine/workflow/service/CaseSearchService.java (3 hunks)
  • nae-object-library/pom.xml (1 hunks)
  • nae-spring-core-adapter/pom.xml (1 hunks)
  • nae-user-ce/pom.xml (1 hunks)
  • nae-user-common/pom.xml (1 hunks)
  • pom.xml (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: in the netgrif application engine, the domain realm class (com.netgrif.application.engine.objects.au...
Learnt from: renczesstefan
PR: netgrif/application-engine#329
File: nae-user-ce/src/main/java/com/netgrif/application/engine/auth/service/RealmServiceImpl.java:39-39
Timestamp: 2025-07-31T08:05:21.587Z
Learning: In the Netgrif Application Engine, the domain Realm class (com.netgrif.application.engine.objects.auth.domain.Realm) is abstract and cannot be instantiated. The concrete implementation is in the adapter package (com.netgrif.application.engine.adapter.spring.auth.domain.Realm) which extends the abstract domain class. Services must instantiate the concrete adapter class and cast it when saving to repositories that accept the abstract domain type.

Applied to files:

  • nae-spring-core-adapter/pom.xml
📚 Learning: in elasticpetrinetservice class, petrinetservice is properly initialized using @lazy setter injectio...
Learnt from: tuplle
PR: netgrif/application-engine#331
File: application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticPetriNetService.java:45-46
Timestamp: 2025-07-29T17:19:18.300Z
Learning: In ElasticPetriNetService class, petriNetService is properly initialized using Lazy setter injection rather than constructor injection. This pattern with Lazy Autowired setter methods is commonly used in Spring to resolve circular dependencies and is a valid alternative to constructor injection.

Applied to files:

  • application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseService.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (9)
nae-user-common/pom.xml (1)

6-10: Confirm Parent POM 7.0.0-RC5 Availability

We attempted to resolve the parent POM with mvn dependency:get, but Maven isn’t installed in this environment. Please ensure that com.netgrif:application-engine-parent:7.0.0-RC5 is published to your Nexus or Maven Central before running CI, as all downstream modules will fail at the validate phase otherwise.

Location:

  • nae-user-common/pom.xml lines 6–10

You can manually verify its availability by running:

mvn -q dependency:get \
  -Dartifact=com.netgrif:application-engine-parent:7.0.0-RC5:pom \
  -Dtransitive=false

(The command should exit with status 0 and no “Could not find artifact” message.)

pom.xml (1)

9-9: Version update to release candidate looks good.

The version change from 7.0.0-SNAPSHOT to 7.0.0-RC5 appropriately moves the project towards a release candidate phase.

application-engine/src/main/java/com/netgrif/application/engine/workflow/service/CaseSearchService.java (1)

145-146: constructPredicateTree is properly defined and inherited
The constructPredicateTree method is implemented in MongoSearchService (application-engine/src/main/java/com/netgrif/application/engine/workflow/service/MongoSearchService.java) and is accessible to CaseSearchService via inheritance. No further changes are needed.

application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticTaskService.java (2)

359-366: Good optimization using terms query.

The refactoring from multiple term queries to a single terms query helps prevent maxClauseCount errors and improves query performance.


455-462: Consistent refactoring with proper empty check.

Good use of isEmpty() instead of size() == 0 and consistent application of the terms query pattern.

application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseService.java (2)

225-250: Excellent refactoring with duplicate prevention.

Good use of HashSet to eliminate duplicates before creating the terms queries. The empty checks ensure no unnecessary queries are added.


460-460: Good simplification of query structure.

Removing the unnecessary BoolQuery wrapper makes the code cleaner and more direct.

application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticViewPermissionService.java (2)

55-59: Consistent optimization pattern applied.

Good application of the TermsQueryField pattern to consolidate multiple role queries into a single terms query, helping prevent maxClauseCount errors.


100-104: Good explicit configuration of union behavior.

Setting minimumShouldMatch("1") explicitly clarifies that at least one of the should clauses must match, which is the correct semantics for a union operation.

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 7, 2025
tuplle
tuplle previously approved these changes Aug 20, 2025
Retoocs
Retoocs previously approved these changes Aug 20, 2025
machacjozef
machacjozef previously approved these changes Aug 20, 2025
@machacjozef machacjozef dismissed stale reviews from Retoocs, tuplle, coderabbitai[bot], and themself via 670dd19 August 20, 2025 15:11
@machacjozef machacjozef merged commit 1e30f80 into release/7.0.0-rev6 Aug 20, 2025
6 of 7 checks passed
@machacjozef machacjozef deleted the NAE-2161 branch August 20, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement A change that improves on an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants