Remove VirtualPropertyReplacer (#2701)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -31,7 +31,6 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldExc
|
||||
import org.eclipse.hawkbit.repository.jpa.ql.Node.Comparison;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RsqlParser;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.legacy.SpecificationBuilderLegacy;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -75,6 +74,7 @@ import org.springframework.orm.jpa.vendor.Database;
|
||||
@Slf4j
|
||||
@Getter
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // singleton holder ensures static access to spring resources in some places
|
||||
public class QLSupport {
|
||||
|
||||
private static final QLSupport SINGLETON = new QLSupport();
|
||||
@@ -110,9 +110,9 @@ public class QLSupport {
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private QueryParser parser;
|
||||
private VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
private Database database;
|
||||
private EntityManager entityManager;
|
||||
private VirtualPropertyResolver virtualPropertyResolver;
|
||||
|
||||
/**
|
||||
* @return The holder singleton instance.
|
||||
@@ -126,11 +126,6 @@ public class QLSupport {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
void setVirtualPropertyReplacer(final VirtualPropertyReplacer virtualPropertyReplacer) {
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
void setDatabase(final JpaProperties jpaProperties) {
|
||||
database = jpaProperties.getDatabase();
|
||||
@@ -141,6 +136,11 @@ public class QLSupport {
|
||||
this.entityManager = entityManager;
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
void setVirtualPropertyResolver(final VirtualPropertyResolver virtualPropertyResolver) {
|
||||
this.virtualPropertyResolver = virtualPropertyResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a JPA {@link Specification} which corresponds with the given RSQL query. The specification can be used to filter for JPA entities
|
||||
* with the given RSQL query.
|
||||
@@ -157,7 +157,7 @@ public class QLSupport {
|
||||
return new SpecificationBuilder<T>(!caseInsensitiveDB && ignoreCase, database)
|
||||
.specification(parser.parse(caseInsensitiveDB || ignoreCase ? query.toLowerCase() : query, queryFieldType));
|
||||
} else {
|
||||
return new SpecificationBuilderLegacy<A, T>(queryFieldType, virtualPropertyReplacer, database).specification(query);
|
||||
return new SpecificationBuilderLegacy<A, T>(queryFieldType, virtualPropertyResolver, database).specification(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldExc
|
||||
import org.eclipse.hawkbit.repository.jpa.ql.Node.Comparison;
|
||||
import org.eclipse.hawkbit.repository.jpa.ql.Node.Comparison.Operator;
|
||||
import org.eclipse.hawkbit.repository.jpa.ql.Node.Logical;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.orm.jpa.vendor.Database;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -46,7 +46,7 @@ import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.QueryField;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.springframework.beans.SimpleTypeConverter;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.orm.jpa.vendor.Database;
|
||||
@@ -80,7 +80,7 @@ public class JpaQueryRsqlVisitor<A extends Enum<A> & QueryField, T> extends Abst
|
||||
private final Database database;
|
||||
private final boolean ensureIgnoreCase;
|
||||
private final Root<T> root;
|
||||
private final VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
private final VirtualPropertyResolver virtualPropertyResolver;
|
||||
private final SimpleTypeConverter simpleTypeConverter;
|
||||
|
||||
private int level;
|
||||
@@ -89,13 +89,13 @@ public class JpaQueryRsqlVisitor<A extends Enum<A> & QueryField, T> extends Abst
|
||||
|
||||
public JpaQueryRsqlVisitor(
|
||||
final Root<T> root, final CriteriaBuilder cb, final Class<A> enumType,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer, final Database database,
|
||||
final VirtualPropertyResolver virtualPropertyResolver, final Database database,
|
||||
final CriteriaQuery<?> query, final boolean ensureIgnoreCase) {
|
||||
super(enumType);
|
||||
this.root = root;
|
||||
this.cb = cb;
|
||||
this.query = query;
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
this.virtualPropertyResolver = virtualPropertyResolver;
|
||||
this.simpleTypeConverter = new SimpleTypeConverter();
|
||||
this.database = database;
|
||||
this.ensureIgnoreCase = ensureIgnoreCase;
|
||||
@@ -328,8 +328,8 @@ public class JpaQueryRsqlVisitor<A extends Enum<A> & QueryField, T> extends Abst
|
||||
|
||||
String value = values.get(0);
|
||||
// if lookup is available, replace macros ...
|
||||
if (virtualPropertyReplacer != null) {
|
||||
value = virtualPropertyReplacer.replace(value);
|
||||
if (virtualPropertyResolver != null) {
|
||||
value = virtualPropertyResolver.replace(value);
|
||||
}
|
||||
|
||||
final Predicate mapPredicate = mapToMapPredicate(fieldPath, queryPath);
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.eclipse.hawkbit.repository.QueryField;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.jpa.ql.SpecificationBuilder;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.springframework.orm.jpa.vendor.Database;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -73,7 +73,7 @@ public class JpaQueryRsqlVisitorG2<A extends Enum<A> & QueryField, T>
|
||||
private final CriteriaQuery<?> query;
|
||||
private final CriteriaBuilder cb;
|
||||
private final Database database;
|
||||
private final VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
private final VirtualPropertyResolver virtualPropertyResolver;
|
||||
private final boolean ensureIgnoreCase;
|
||||
|
||||
private final Map<String, Path<?>> attributeToPath = new HashMap<>();
|
||||
@@ -82,12 +82,12 @@ public class JpaQueryRsqlVisitorG2<A extends Enum<A> & QueryField, T>
|
||||
public JpaQueryRsqlVisitorG2(
|
||||
final Class<A> enumType,
|
||||
final Root<T> root, final CriteriaQuery<?> query, final CriteriaBuilder cb,
|
||||
final Database database, final VirtualPropertyReplacer virtualPropertyReplacer, final boolean ensureIgnoreCase) {
|
||||
final Database database, final VirtualPropertyResolver virtualPropertyResolver, final boolean ensureIgnoreCase) {
|
||||
super(enumType);
|
||||
this.root = root;
|
||||
this.cb = cb;
|
||||
this.query = query;
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
this.virtualPropertyResolver = virtualPropertyResolver;
|
||||
this.database = database;
|
||||
this.ensureIgnoreCase = ensureIgnoreCase;
|
||||
}
|
||||
@@ -266,7 +266,7 @@ public class JpaQueryRsqlVisitorG2<A extends Enum<A> & QueryField, T>
|
||||
private List<Object> getValues(final ComparisonNode node, final AbstractRSQLVisitor<A>.QueryPath queryPath, final Path<?> fieldPath) {
|
||||
final List<Object> values = node.getArguments().stream()
|
||||
// if lookup is available, replace macros ...
|
||||
.map(value -> virtualPropertyReplacer == null ? value : virtualPropertyReplacer.replace(value))
|
||||
.map(value -> virtualPropertyResolver == null ? value : virtualPropertyResolver.replace(value))
|
||||
// converts value to the correct type
|
||||
.map(value -> convertValueIfNecessary(node, queryPath.getEnumValue(), fieldPath, value))
|
||||
.toList();
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.eclipse.hawkbit.repository.QueryField;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.jpa.ql.SpecificationBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.ql.QLSupport;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.orm.jpa.vendor.Database;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -38,13 +38,13 @@ import org.springframework.util.CollectionUtils;
|
||||
public class SpecificationBuilderLegacy<A extends Enum<A> & QueryField, T> {
|
||||
|
||||
private final Class<A> rsqlQueryFieldType;
|
||||
private final VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
private final VirtualPropertyResolver virtualPropertyResolver;
|
||||
private final Database database;
|
||||
|
||||
public SpecificationBuilderLegacy(
|
||||
final Class<A> rsqlQueryFieldType, final VirtualPropertyReplacer virtualPropertyReplacer, final Database database) {
|
||||
final Class<A> rsqlQueryFieldType, final VirtualPropertyResolver virtualPropertyResolver, final Database database) {
|
||||
this.rsqlQueryFieldType = rsqlQueryFieldType;
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
this.virtualPropertyResolver = virtualPropertyResolver;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ public class SpecificationBuilderLegacy<A extends Enum<A> & QueryField, T> {
|
||||
final boolean ensureIgnoreCase = !qlSupport.isCaseInsensitiveDB() && qlSupport.isIgnoreCase();
|
||||
final RSQLVisitor<List<Predicate>, String> jpqQueryRSQLVisitor =
|
||||
qlSupport.getSpecBuilder() == LEGACY_G1
|
||||
? new JpaQueryRsqlVisitor<>(root, cb, rsqlQueryFieldType, virtualPropertyReplacer, database, query, ensureIgnoreCase)
|
||||
: new JpaQueryRsqlVisitorG2<>(rsqlQueryFieldType, root, query, cb, database, virtualPropertyReplacer, ensureIgnoreCase);
|
||||
? new JpaQueryRsqlVisitor<>(root, cb, rsqlQueryFieldType, virtualPropertyResolver, database, query, ensureIgnoreCase)
|
||||
: new JpaQueryRsqlVisitorG2<>(rsqlQueryFieldType, root, query, cb, database, virtualPropertyResolver, ensureIgnoreCase);
|
||||
final List<Predicate> accept = rootNode.accept(jpqQueryRSQLVisitor);
|
||||
|
||||
if (CollectionUtils.isEmpty(accept)) {
|
||||
|
||||
Reference in New Issue
Block a user