-
Notifications
You must be signed in to change notification settings - Fork 7
[NAE-2483] Action API Improvements #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Retoocs
wants to merge
11
commits into
release/6.6.0
Choose a base branch
from
NAE-2483
base: release/6.6.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
001f1a7
[NAE-2483] Action API Improvements
Retoocs d41475c
[NAE-2483] Action API Improvements
Retoocs 7640fe3
[NAE-2483] Action API Improvements
Retoocs 01d6bd7
[NAE-2483] Action API Improvements
Retoocs dca1b13
[NAE-2483] Action API Improvements
Retoocs 5dbc152
[NAE-2483] Action API Improvements
Retoocs 1446c82
[NAE-2483] Action API Improvements
Retoocs f50632e
[NAE-2483] Action API Improvements
Retoocs f829ab4
[NAE-2483] Action API Improvements
Retoocs eadfa75
[NAE-2483] Action API Improvements
Retoocs de0a96f
[NAE-2483] Action API Improvements
Retoocs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/main/java/com/netgrif/application/engine/pfql/service/AbstractResourceSearchService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package com.netgrif.application.engine.pfql.service; | ||
|
|
||
| import com.netgrif.application.engine.pfql.service.formatters.QueryLangPlaceholderHandler; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.data.domain.Page; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static com.netgrif.application.engine.pfql.service.utils.SearchUtils.*; | ||
| import static com.netgrif.application.engine.pfql.service.utils.SearchUtils.buildResourcePrefix; | ||
|
|
||
| /** | ||
| * Abstract base class for resource search services providing shared query pre-processing. | ||
| * <p> | ||
| * Handles common pre-processing steps: | ||
| * <ol> | ||
| * <li>Formatter bracket substitution – fills {@code {}} placeholders with provided arguments</li> | ||
| * <li>PFQL prefix check/injection – implemented individually by each subclass</li> | ||
| * </ol> | ||
| */ | ||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| public abstract class AbstractResourceSearchService<Resource> implements IResourceSearchService<Resource> { | ||
|
|
||
| protected final QueryLangPlaceholderHandler placeholderHandler; | ||
|
|
||
| /** | ||
| * Pre-processes the raw query string: fills {@code {}} placeholders and ensures a correct PFQL prefix. | ||
| * | ||
| * @param rawQuery the raw query string, possibly with {@code {}} placeholders | ||
| * @param isMulti if the prefix should address multiple resources | ||
| * @param args arguments to substitute into {@code {}} placeholders (in order) | ||
| * @return the fully pre-processed query string ready for evaluation | ||
| */ | ||
| protected String preProcess(String rawQuery, boolean isMulti, Object... args) { | ||
| String formatted = formatPlaceholders(rawQuery, placeholderHandler, args); | ||
| return ensurePrefix(formatted, isMulti); | ||
| } | ||
|
|
||
|
|
||
| protected abstract String ensurePrefix(String query, boolean isMulti); | ||
|
|
||
| protected abstract Resource doSearchOne(QueryLangEvaluator evaluator); | ||
|
|
||
| protected abstract Page<Resource> doSearchAll(QueryLangEvaluator evaluator); | ||
|
|
||
| protected abstract long doCount(QueryLangEvaluator evaluator); | ||
|
|
||
| protected abstract boolean doExists(QueryLangEvaluator evaluator); | ||
|
|
||
| /** | ||
| * Ensures the query string has the correct PFQL resource prefix. | ||
| * Each implementation defines which prefix is expected and how to inject it if missing. | ||
| * | ||
| * @param query the query string after placeholder substitution | ||
| * @param isMulti if the prefix should address multiple resources | ||
| * @param multiPrefixToken token of prefix to search multiple resources | ||
| * @param singlePrefixToken token of prefix to search single resource | ||
| * @return the query string with the correct prefix guaranteed | ||
| */ | ||
| protected String doEnsurePrefix(String query, boolean isMulti, int multiPrefixToken, int singlePrefixToken) { | ||
| if (query == null || hasResourcePrefix(query, List.of(multiPrefixToken, singlePrefixToken))) { | ||
| return query; | ||
| } | ||
| return buildResourcePrefix(isMulti ? multiPrefixToken : singlePrefixToken) + query; | ||
| } | ||
|
|
||
| @Override | ||
| public Resource searchOne(String queryString, Object... args) { | ||
| final String processedQuery = preProcess(queryString, false, args); | ||
| log.debug("Searching one with query: {}", processedQuery); | ||
| return searchOne(evaluateQuery(processedQuery)); | ||
| } | ||
|
|
||
| @Override | ||
| public Resource searchOne(QueryLangEvaluator evaluator) { | ||
| checkEvaluatorNotNull(evaluator); | ||
| checkEvaluatorIsSingle(evaluator); | ||
| checkEvaluatorResourceType(evaluator); | ||
| return doSearchOne(evaluator); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<Resource> searchAll(String queryString, Object... args) { | ||
| final String processedQuery = preProcess(queryString, true, args); | ||
| log.debug("Searching all with query: {}", processedQuery); | ||
| return searchAll(evaluateQuery(processedQuery)); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<Resource> searchAll(QueryLangEvaluator evaluator) { | ||
| checkEvaluatorNotNull(evaluator); | ||
| checkEvaluatorIsMultiple(evaluator); | ||
| checkEvaluatorResourceType(evaluator); | ||
| return doSearchAll(evaluator); | ||
| } | ||
|
|
||
| @Override | ||
| public long count(String queryString, Object... args) { | ||
| final String processedQuery = preProcess(queryString, true, args); | ||
| log.debug("Counting with query: {}", processedQuery); | ||
| return count(evaluateQuery(processedQuery)); | ||
| } | ||
|
|
||
| @Override | ||
| public long count(QueryLangEvaluator evaluator) { | ||
| checkEvaluatorNotNull(evaluator); | ||
| checkEvaluatorResourceType(evaluator); | ||
| return doCount(evaluator); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean exists(String queryString, Object... args) { | ||
| final String processedQuery = preProcess(queryString, false, args); | ||
| log.debug("Checking existence with query: {}", processedQuery); | ||
| return exists(evaluateQuery(processedQuery)); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean exists(QueryLangEvaluator evaluator) { | ||
| checkEvaluatorNotNull(evaluator); | ||
| checkEvaluatorResourceType(evaluator); | ||
| return doExists(evaluator); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.