Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.netgrif.application.engine.configuration;

import com.netgrif.application.engine.auth.service.interfaces.IUserService;
import com.netgrif.application.engine.auth.web.responsebodies.UserResourceAssembler;
import com.netgrif.application.engine.importer.service.Importer;
import com.netgrif.application.engine.pdf.generator.service.PdfDataHelper;
Expand All @@ -9,16 +10,21 @@
import com.netgrif.application.engine.pdf.generator.service.interfaces.IPdfDrawer;
import com.netgrif.application.engine.pdf.generator.service.interfaces.IPdfGenerator;
import com.netgrif.application.engine.petrinet.domain.dataset.logic.action.ActionDelegate;
import com.netgrif.application.engine.pfql.service.QueryLangEvaluator;
import com.netgrif.application.engine.workflow.domain.FileStorageConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;

@Configuration
@RequiredArgsConstructor
public class PrototypesConfiguration {

private final IUserService userService;

@Bean("importer")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public Importer importer() {
Expand Down Expand Up @@ -60,4 +66,11 @@ public IPdfDrawer pdfDrawer() {
public UserResourceAssembler userResourceAssembler() {
return new UserResourceAssembler();
}

@Bean("queryLangEvaluator")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(QueryLangEvaluator.class)
public QueryLangEvaluator queryLangEvaluator() {
return new QueryLangEvaluator(userService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.netgrif.application.engine.auth.domain.QUser;
import com.netgrif.application.engine.auth.service.interfaces.IUserService;
import com.netgrif.application.engine.petrinet.domain.QPetriNet;
import com.netgrif.application.engine.pfql.domain.antlr4.QueryLangBaseListener;

Check failure on line 7 in src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java

View workflow job for this annotation

GitHub Actions / Build

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist

Check failure on line 7 in src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java

View workflow job for this annotation

GitHub Actions / Test

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist
import com.netgrif.application.engine.pfql.domain.antlr4.QueryLangParser;

Check failure on line 8 in src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java

View workflow job for this annotation

GitHub Actions / Build

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist

Check failure on line 8 in src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java

View workflow job for this annotation

GitHub Actions / Test

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist
import com.netgrif.application.engine.pfql.domain.enums.ComparisonType;
import com.netgrif.application.engine.pfql.domain.enums.QueryType;
import com.netgrif.application.engine.workflow.domain.QCase;
Expand Down Expand Up @@ -38,30 +38,30 @@

public class QueryLangEvaluator extends QueryLangBaseListener {

private final ParseTreeProperty<String> elasticQuery = new ParseTreeProperty<>();
private final ParseTreeProperty<Predicate> mongoQuery = new ParseTreeProperty<>();
private final String elasticFuzzyMaxDistance = "AUTO";
protected final ParseTreeProperty<String> elasticQuery = new ParseTreeProperty<>();
protected final ParseTreeProperty<Predicate> mongoQuery = new ParseTreeProperty<>();
protected final String elasticFuzzyMaxDistance = "AUTO";

private final IUserService userService;
protected final IUserService userService;

@Getter
private QueryType resourceType;
protected QueryType resourceType;
@Getter
private Boolean multiple;
protected Boolean multiple;
@Getter
@Setter
private Boolean searchWithElastic = false;
protected Boolean searchWithElastic = false;
@Getter
private Predicate fullMongoQuery;
protected Predicate fullMongoQuery;
@Getter
private String fullElasticQuery;
protected String fullElasticQuery;
@Getter
@Setter
private Pageable pageable;
protected Pageable pageable;

private int pageNumber = 0;
private int pageSize = 20;
private final List<Sort.Order> sortOrders = new ArrayList<>();
protected int pageNumber = 0;
protected int pageSize = 20;
protected final List<Sort.Order> sortOrders = new ArrayList<>();

public QueryLangEvaluator(IUserService userService) {
this.userService = userService;
Expand All @@ -83,12 +83,12 @@
return mongoQuery.get(node);
}

private void processBasicExpression(ParseTree child, ParseTree current) {
protected void processBasicExpression(ParseTree child, ParseTree current) {
setMongoQuery(current, getMongoQuery(child));
setElasticQuery(current, getElasticQuery(child));
}

private void processOrExpression(List<ParseTree> children, ParseTree current) {
protected void processOrExpression(List<ParseTree> children, ParseTree current) {
List<Predicate> predicates = children.stream()
.map(this::getMongoQuery)
.filter(Objects::nonNull)
Expand All @@ -106,7 +106,7 @@
setElasticQuery(current, elasticQuery.isBlank() ? null : elasticQuery);
}

private void processAndExpression(List<ParseTree> children, ParseTree current) {
protected void processAndExpression(List<ParseTree> children, ParseTree current) {
List<Predicate> predicates = children.stream()
.map(this::getMongoQuery)
.filter(Objects::nonNull)
Expand All @@ -124,7 +124,7 @@
setElasticQuery(current, elasticQuery.isBlank() ? null : elasticQuery);
}

private void processConditionGroup(ParseTree child, ParseTree current, Boolean not, Boolean parenthesis) {
protected void processConditionGroup(ParseTree child, ParseTree current, Boolean not, Boolean parenthesis) {
Predicate predicate = getMongoQuery(child);
String elasticQuery = getElasticQuery(child);

Expand All @@ -146,7 +146,7 @@
setElasticQuery(current, elasticQuery);
}

private String handleStringComparisonWithPlaceholders(QueryLangParser.StringComparisonContext ctx) {
protected String handleStringComparisonWithPlaceholders(QueryLangParser.StringComparisonContext ctx) {
if (ctx.STRING() != null) {
return getStringValue(ctx.STRING().getText());
}
Expand All @@ -158,7 +158,7 @@
throw new IllegalArgumentException("Wrong or missing query value on string comparison");
}

private ObjectId handleObjectIdComparisonWithPlaceholders(QueryLangParser.ObjectIdComparisonContext ctx) {
protected ObjectId handleObjectIdComparisonWithPlaceholders(QueryLangParser.ObjectIdComparisonContext ctx) {
if (ctx.STRING() != null) {
return getObjectIdValue(ctx.STRING().getText());
}
Expand All @@ -170,7 +170,7 @@
throw new IllegalArgumentException("Wrong or missing query value on object id comparison");
}

private List<String> handleStringListComparison(QueryLangParser.StringListContext ctx) {
protected List<String> handleStringListComparison(QueryLangParser.StringListContext ctx) {
List<String> result = new ArrayList<>();

if (ctx.STRING() != null && !ctx.STRING().isEmpty()) {
Expand All @@ -187,7 +187,7 @@
return result;
}

private List<ObjectId> handleObjectIdListComparison(QueryLangParser.StringListContext ctx) {
protected List<ObjectId> handleObjectIdListComparison(QueryLangParser.StringListContext ctx) {
List<ObjectId> result = new ArrayList<>();

if (ctx.STRING() != null && !ctx.STRING().isEmpty()) {
Expand All @@ -207,7 +207,7 @@
return result;
}

private String handleLoggedUserStringAttribute(QueryLangParser.LoggedUserStringAttributeContext ctx) {
protected String handleLoggedUserStringAttribute(QueryLangParser.LoggedUserStringAttributeContext ctx) {
LoggedUser loggedUser = this.userService.getLoggedOrSystem().transformToLoggedUser();
if (ctx.LOGGED_USER_ID() != null) {
return loggedUser.getId();
Expand All @@ -222,7 +222,7 @@
}

/// returns pair, where the first element is left value and the second element is right value
private Pair<String, String> handleInRangeStringComparison(QueryLangParser.StringRangeContext ctx) {
protected Pair<String, String> handleInRangeStringComparison(QueryLangParser.StringRangeContext ctx) {
List<ParseTree> filteredChildren = ctx.children.stream()
.filter(node -> node instanceof TerminalNode && ((TerminalNode) node).getSymbol().getType() == QueryLangParser.STRING
|| node instanceof QueryLangParser.LoggedUserStringAttributeContext)
Expand Down Expand Up @@ -251,7 +251,7 @@
return Pair.of(left, right);
}

private String handleBooleanComparison(QueryLangParser.BooleanComparisonContext ctx) {
protected String handleBooleanComparison(QueryLangParser.BooleanComparisonContext ctx) {
if (ctx.BOOLEAN() != null) {
return ctx.BOOLEAN().getText();
}
Expand All @@ -263,15 +263,15 @@
throw new IllegalArgumentException("Wrong or missing query value on boolean comparison");
}

private Predicate getEmptyMongoQuery() {
protected Predicate getEmptyMongoQuery() {
return new BooleanBuilder();
}

private String getEmptyElasticQuery() {
protected String getEmptyElasticQuery() {
return "*";
}

private void handleNoneConditions() {
protected void handleNoneConditions() {
fullMongoQuery = getEmptyMongoQuery();
fullElasticQuery = getEmptyElasticQuery();
}
Expand Down Expand Up @@ -1882,7 +1882,7 @@
this.searchWithElastic = true;
}

private boolean shouldBeNotNull(QueryLangParser.NullComparisonContext ctx) {
protected boolean shouldBeNotNull(QueryLangParser.NullComparisonContext ctx) {
if (ctx == null) {
throw new IllegalArgumentException("Null comparison context must be provided");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.netgrif.application.engine.pfql.service.utils;

import com.netgrif.application.engine.auth.service.interfaces.IUserService;
import com.netgrif.application.engine.configuration.ApplicationContextProvider;
import com.netgrif.application.engine.elastic.service.ElasticsearchQuerySanitizer;
import com.netgrif.application.engine.petrinet.domain.QPetriNet;
import com.netgrif.application.engine.petrinet.domain.version.QVersion;
import com.netgrif.application.engine.petrinet.domain.version.Version;
import com.netgrif.application.engine.pfql.domain.antlr4.QueryLangBaseListener;

Check failure on line 8 in src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java

View workflow job for this annotation

GitHub Actions / Build

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist

Check failure on line 8 in src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java

View workflow job for this annotation

GitHub Actions / Test

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist
import com.netgrif.application.engine.pfql.domain.antlr4.QueryLangLexer;

Check failure on line 9 in src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java

View workflow job for this annotation

GitHub Actions / Build

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist

Check failure on line 9 in src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java

View workflow job for this annotation

GitHub Actions / Test

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist
import com.netgrif.application.engine.pfql.domain.antlr4.QueryLangParser;

Check failure on line 10 in src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java

View workflow job for this annotation

GitHub Actions / Build

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist

Check failure on line 10 in src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java

View workflow job for this annotation

GitHub Actions / Test

package com.netgrif.application.engine.pfql.domain.antlr4 does not exist
import com.netgrif.application.engine.pfql.domain.enums.ComparisonType;
import com.netgrif.application.engine.pfql.service.QueryLangErrorListener;
import com.netgrif.application.engine.pfql.service.QueryLangEvaluator;
Expand Down Expand Up @@ -174,8 +173,7 @@
return explainQueryInternal(walker, query, errorListener);
}

IUserService userService = (IUserService) ApplicationContextProvider.getBean(IUserService.class);
QueryLangEvaluator evaluator = new QueryLangEvaluator(userService);
QueryLangEvaluator evaluator = (QueryLangEvaluator) ApplicationContextProvider.getBean(QueryLangEvaluator.class);
walker.walk(evaluator, query);

return evaluator;
Expand Down
Loading