Remove VirtualPropertyReplacer (#2701)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-09-26 17:17:38 +03:00
committed by GitHub
parent 1954fbe829
commit 1919af4a9d
9 changed files with 28 additions and 67 deletions

View File

@@ -1,32 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository.rsql;
import java.io.Serializable;
/**
* Implementations map a placeholder to the associated value.
* <p>
* This is used in context of string replacement.
*
* @deprecated Since 0.10.0, used only in deprecated specification builders
*/
@Deprecated(since = "0.10.0", forRemoval = true)
@FunctionalInterface
public interface VirtualPropertyReplacer extends Serializable {
/**
* Looks up a placeholders and replaces them
*
* @param input the input string in which virtual properties should be replaced
* @return the result of the replacement
*/
String replace(String input);
}

View File

@@ -33,7 +33,7 @@ import org.eclipse.hawkbit.repository.TimestampCalculator;
* and pollingOverdueInterval are retrieved from tenant-specific system configuration.</li>
* </ul>
*/
public class VirtualPropertyResolver implements VirtualPropertyReplacer {
public class VirtualPropertyResolver {
@Serial
private static final long serialVersionUID = 1L;
@@ -42,7 +42,6 @@ public class VirtualPropertyResolver implements VirtualPropertyReplacer {
StringLookupFactory.builder().get().functionStringLookup(VirtualPropertyResolver::lookup),
StringSubstitutor.DEFAULT_PREFIX, StringSubstitutor.DEFAULT_SUFFIX, StringSubstitutor.DEFAULT_ESCAPE);
@Override
public String replace(final String input) {
return STRING_SUBSTITUTOR.replace(input);
}

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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();

View File

@@ -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)) {

View File

@@ -98,7 +98,6 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder;
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
@@ -521,7 +520,7 @@ public class JpaRepositoryConfiguration {
@Bean
@ConditionalOnMissingBean
public VirtualPropertyResolver virtualPropertyReplacer() {
public VirtualPropertyResolver virtualPropertyResolver() {
return new VirtualPropertyResolver();
}

View File

@@ -28,7 +28,6 @@ import org.eclipse.hawkbit.repository.RolloutApprovalStrategy;
import org.eclipse.hawkbit.repository.RolloutStatusCache;
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
import org.eclipse.hawkbit.repository.test.util.RolloutTestApprovalStrategy;
import org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch;
@@ -187,11 +186,8 @@ public class TestConfiguration implements AsyncConfigurer {
return new SpringSecurityAuditorAware();
}
/**
* @return returns a VirtualPropertyReplacer
*/
@Bean
VirtualPropertyReplacer virtualPropertyReplacer() {
VirtualPropertyResolver virtualPropertyResolver() {
return new VirtualPropertyResolver();
}