Optimized implementation of VirtualPropertyReplacer.

Added auto configuration for VirtualPropertyResolver.

Signed-off-by: Dominik Herbst <dominik.herbst@bosch-si.com>
This commit is contained in:
Dominik Herbst
2016-09-28 13:54:54 +02:00
parent 9265f17e19
commit b1d9930d94
18 changed files with 106 additions and 76 deletions

View File

@@ -54,7 +54,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyLookup;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
@@ -136,7 +136,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
private SystemSecurityContext systemSecurityContext;
@Autowired
private VirtualPropertyLookup virtualPropertyLookup;
private VirtualPropertyReplacer virtualPropertyReplacer;
@Override
@Transactional(isolation = Isolation.READ_COMMITTED)
@@ -609,7 +609,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
}
private Specification<JpaAction> createSpecificationFor(final Target target, final String rsqlParam) {
final Specification<JpaAction> spec = RSQLUtility.parse(rsqlParam, ActionFields.class, virtualPropertyLookup);
final Specification<JpaAction> spec = RSQLUtility.parse(rsqlParam, ActionFields.class, virtualPropertyReplacer);
return (root, query, cb) -> cb.and(spec.toPredicate(root, query, cb),
cb.equal(root.get(JpaAction_.target), target));
}

View File

@@ -42,7 +42,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyLookup;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetTypeSpecification;
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
@@ -109,7 +109,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
private TenantAware tenantAware;
@Autowired
private VirtualPropertyLookup virtualPropertyLookup;
private VirtualPropertyReplacer virtualPropertyReplacer;
@Override
public DistributionSet findDistributionSetByIdWithDetails(final Long distid) {
@@ -283,7 +283,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
public Page<DistributionSetType> findDistributionSetTypesAll(final String rsqlParam, final Pageable pageable) {
final Specification<JpaDistributionSetType> spec = RSQLUtility.parse(rsqlParam,
DistributionSetTypeFields.class, virtualPropertyLookup);
DistributionSetTypeFields.class, virtualPropertyReplacer);
return convertDsTPage(distributionSetTypeRepository.findAll(spec, pageable));
}
@@ -350,7 +350,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
final Boolean deleted) {
final Specification<JpaDistributionSet> spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
final List<Specification<JpaDistributionSet>> specList = new ArrayList<>(2);
if (deleted != null) {
@@ -562,7 +562,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
final String rsqlParam, final Pageable pageable) {
final Specification<JpaDistributionSetMetadata> spec = RSQLUtility.parse(rsqlParam,
DistributionSetMetadataFields.class, virtualPropertyLookup);
DistributionSetMetadataFields.class, virtualPropertyReplacer);
return convertMdPage(
distributionSetMetadataRepository

View File

@@ -33,7 +33,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup;
import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup_;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyLookup;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus;
@@ -72,7 +72,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
private EntityManager entityManager;
@Autowired
private VirtualPropertyLookup virtualPropertyLookup;
private VirtualPropertyReplacer virtualPropertyReplacer;
@Override
public RolloutGroup findRolloutGroupById(final Long rolloutGroupId) {
@@ -97,7 +97,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
final Pageable pageable) {
final Specification<JpaRolloutGroup> specification = RSQLUtility.parse(rsqlParam, RolloutGroupFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
return convertPage(
rolloutGroupRepository
@@ -151,7 +151,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
final Pageable pageable) {
final Specification<JpaTarget> rsqlSpecification = RSQLUtility.parse(rsqlParam, TargetFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
return convertTPage(targetRepository.findAll((root, query, criteriaBuilder) -> {
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = root.join(JpaTarget_.rolloutTargetGroup);

View File

@@ -32,7 +32,7 @@ import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup;
import org.eclipse.hawkbit.repository.jpa.rollout.condition.RolloutGroupActionEvaluator;
import org.eclipse.hawkbit.repository.jpa.rollout.condition.RolloutGroupConditionEvaluator;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyLookup;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -116,7 +116,7 @@ public class JpaRolloutManagement implements RolloutManagement {
private CacheWriteNotify cacheWriteNotify;
@Autowired
private VirtualPropertyLookup virtualPropertyLookup;
private VirtualPropertyReplacer virtualPropertyReplacer;
@Autowired
@Qualifier("asyncExecutor")
@@ -155,7 +155,7 @@ public class JpaRolloutManagement implements RolloutManagement {
public Page<Rollout> findAllWithDetailedStatusByPredicate(final String rsqlParam, final Pageable pageable) {
final Specification<JpaRollout> specification = RSQLUtility.parse(rsqlParam, RolloutFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
final Page<JpaRollout> findAll = rolloutRepository.findAll(specification, pageable);
setRolloutStatusDetails(findAll);

View File

@@ -45,7 +45,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyLookup;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification;
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule;
@@ -108,7 +108,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
private ArtifactManagement artifactManagement;
@Autowired
private VirtualPropertyLookup virtualPropertyLookup;
private VirtualPropertyReplacer virtualPropertyReplacer;
@Override
@Modifying
@@ -317,7 +317,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
public Page<SoftwareModule> findSoftwareModulesByPredicate(final String rsqlParam, final Pageable pageable) {
final Specification<JpaSoftwareModule> spec = RSQLUtility.parse(rsqlParam, SoftwareModuleFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
return convertSmPage(softwareModuleRepository.findAll(spec, pageable), pageable);
}
@@ -326,7 +326,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
public Page<SoftwareModuleType> findSoftwareModuleTypesAll(final String rsqlParam, final Pageable pageable) {
final Specification<JpaSoftwareModuleType> spec = RSQLUtility.parse(rsqlParam, SoftwareModuleTypeFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
return convertSmTPage(softwareModuleTypeRepository.findAll(spec, pageable), pageable);
}
@@ -612,7 +612,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
final String rsqlParam, final Pageable pageable) {
final Specification<JpaSoftwareModuleMetadata> spec = RSQLUtility.parse(rsqlParam,
SoftwareModuleMetadataFields.class, virtualPropertyLookup);
SoftwareModuleMetadataFields.class, virtualPropertyReplacer);
return convertSmMdPage(
softwareModuleMetadataRepository
.findAll(

View File

@@ -30,7 +30,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyLookup;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.tenancy.TenantAware;
@@ -76,7 +76,7 @@ public class JpaTagManagement implements TagManagement {
private AfterTransactionCommitExecutor afterCommit;
@Autowired
private VirtualPropertyLookup virtualPropertyLookup;
private VirtualPropertyReplacer virtualPropertyReplacer;
@Override
public TargetTag findTargetTag(final String name) {
@@ -151,7 +151,7 @@ public class JpaTagManagement implements TagManagement {
@Override
public Page<TargetTag> findAllTargetTags(final String rsqlParam, final Pageable pageable) {
final Specification<JpaTargetTag> spec = RSQLUtility.parse(rsqlParam, TagFields.class, virtualPropertyLookup);
final Specification<JpaTargetTag> spec = RSQLUtility.parse(rsqlParam, TagFields.class, virtualPropertyReplacer);
return convertTPage(targetTagRepository.findAll(spec, pageable), pageable);
}
@@ -285,7 +285,7 @@ public class JpaTagManagement implements TagManagement {
@Override
public Page<DistributionSetTag> findAllDistributionSetTags(final String rsqlParam, final Pageable pageable) {
final Specification<JpaDistributionSetTag> spec = RSQLUtility.parse(rsqlParam, TagFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
return convertDsPage(distributionSetTagRepository.findAll(spec, pageable), pageable);
}

View File

@@ -16,7 +16,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyLookup;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
import org.eclipse.hawkbit.repository.jpa.specifications.TargetFilterQuerySpecification;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
@@ -46,7 +46,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
private TargetFilterQueryRepository targetFilterQueryRepository;
@Autowired
private VirtualPropertyLookup virtualPropertyLookup;
private VirtualPropertyReplacer virtualPropertyReplacer;
@Override
@Modifying
@@ -115,7 +115,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Override
public boolean verifyTargetFilterQuerySyntax(final String query) {
RSQLUtility.parse(query, TargetFields.class, virtualPropertyLookup);
RSQLUtility.parse(query, TargetFields.class, virtualPropertyReplacer);
return true;
}

View File

@@ -42,7 +42,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyLookup;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
import org.eclipse.hawkbit.repository.model.Target;
@@ -105,7 +105,7 @@ public class JpaTargetManagement implements TargetManagement {
private AfterTransactionCommitExecutor afterCommit;
@Autowired
private VirtualPropertyLookup virtualPropertyLookup;
private VirtualPropertyReplacer virtualPropertyReplacer;
@Override
public Target findTargetByControllerID(final String controllerId) {
@@ -158,13 +158,13 @@ public class JpaTargetManagement implements TargetManagement {
@Override
public Slice<Target> findTargetsAll(final TargetFilterQuery targetFilterQuery, final Pageable pageable) {
return findTargetsBySpec(
RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class, virtualPropertyLookup),
RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class, virtualPropertyReplacer),
pageable);
}
@Override
public Page<Target> findTargetsAll(final String targetFilterQuery, final Pageable pageable) {
return findTargetsBySpec(RSQLUtility.parse(targetFilterQuery, TargetFields.class, virtualPropertyLookup),
return findTargetsBySpec(RSQLUtility.parse(targetFilterQuery, TargetFields.class, virtualPropertyReplacer),
pageable);
}
@@ -233,7 +233,7 @@ public class JpaTargetManagement implements TargetManagement {
final Pageable pageReq) {
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
return convertPage(
targetRepository
@@ -262,7 +262,7 @@ public class JpaTargetManagement implements TargetManagement {
final Pageable pageable) {
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
return convertPage(
targetRepository
@@ -566,7 +566,7 @@ public class JpaTargetManagement implements TargetManagement {
final CriteriaQuery<Object[]> multiselect = query.multiselect(targetRoot.get(JpaTarget_.id),
targetRoot.get(JpaTarget_.controllerId), targetRoot.get(JpaTarget_.name), targetRoot.get(sortProperty));
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class, virtualPropertyLookup);
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class, virtualPropertyReplacer);
final Predicate[] specificationsForMultiSelect = specificationsToPredicate(Lists.newArrayList(spec), targetRoot,
multiselect, cb);
@@ -645,14 +645,14 @@ public class JpaTargetManagement implements TargetManagement {
@Override
public Long countTargetByTargetFilterQuery(final TargetFilterQuery targetFilterQuery) {
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
return targetRepository.count(specs);
}
@Override
public Long countTargetByTargetFilterQuery(final String targetFilterQuery) {
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
virtualPropertyLookup);
virtualPropertyReplacer);
return targetRepository.count(specs);
}

View File

@@ -1,57 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa;
import java.time.Duration;
import java.time.Instant;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.springframework.stereotype.Service;
/**
* Service that calculates non-persistent timestamps , e.g. the point a time a
* target is declared as overdue.<br>
* Therefore tenant specific configuration may be considered.
*
*/
@Service
public class TimestampCalculator {
/**
* Calculates the overdue timestamp (<em>overdue_ts</em>) based on the
* current timestamp and the intervals for polling and poll-overdue:
* <p>
* <em>overdue_ts = now_ts - pollingInterval -
* pollingOverdueInterval</em>;<br>
* <em>pollingInterval</em> and <em>pollingOverdueInterval</em> are
* retrieved from tenant-specific system configuration.
*
* @return <em>overdue_ts</em> in milliseconds since Unix epoch as long
* value
*/
public long calculateOverdueTimestamp() {
return Instant.now().toEpochMilli() - getDurationForKey(TenantConfigurationKey.POLLING_TIME_INTERVAL).toMillis()
- getDurationForKey(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL).toMillis();
}
private Duration getDurationForKey(TenantConfigurationKey key) {
return DurationHelper.formattedStringToDuration(getRawStringForKey(key));
}
private String getRawStringForKey(TenantConfigurationKey key) {
return getTenantConfigurationManagement().getConfigurationValue(key, String.class).getValue();
}
protected TenantConfigurationManagement getTenantConfigurationManagement() {
return TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement();
}
}

View File

@@ -1,44 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa.model.helper;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.springframework.beans.factory.annotation.Autowired;
/**
* A singleton bean which holds {@link TenantConfigurationManagement} service
* and makes it accessible to beans which are not managed by spring, e.g. JPA
* entities.
*/
public final class TenantConfigurationManagementHolder {
private static final TenantConfigurationManagementHolder INSTANCE = new TenantConfigurationManagementHolder();
@Autowired
private TenantConfigurationManagement tenantConfiguration;
private TenantConfigurationManagementHolder() {
}
/**
* @return the singleton {@link TenantConfigurationManagementHolder}
* instance
*/
public static TenantConfigurationManagementHolder getInstance() {
return INSTANCE;
}
/**
* @return the {@link TenantConfigurationManagement} service
*/
public TenantConfigurationManagement getTenantConfigurationManagement() {
return tenantConfiguration;
}
}

View File

@@ -26,11 +26,11 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.text.StrLookup;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.eclipse.hawkbit.repository.FieldNameProvider;
import org.eclipse.hawkbit.repository.FieldValueConverter;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.SimpleTypeConverter;
@@ -99,7 +99,7 @@ public final class RSQLUtility {
* @param fieldNameProvider
* the enum class type which implements the
* {@link FieldNameProvider}
* @param virtualPropertyLookup
* @param virtualPropertyReplacer
* holds the logic how the known macros have to be resolved; may
* be <code>null</code>
* @return an specification which can be used with JPA
@@ -110,8 +110,8 @@ public final class RSQLUtility {
* if the RSQL syntax is wrong
*/
public static <A extends Enum<A> & FieldNameProvider, T> Specification<T> parse(final String rsql,
final Class<A> fieldNameProvider, VirtualPropertyLookup virtualPropertyLookup) {
return new RSQLSpecification<>(rsql.toLowerCase(), fieldNameProvider, virtualPropertyLookup);
final Class<A> fieldNameProvider, VirtualPropertyReplacer virtualPropertyReplacer) {
return new RSQLSpecification<>(rsql.toLowerCase(), fieldNameProvider, virtualPropertyReplacer);
}
/**
@@ -142,13 +142,13 @@ public final class RSQLUtility {
private final String rsql;
private final Class<A> enumType;
private final VirtualPropertyLookup virtualPropertyLookup;
private final VirtualPropertyReplacer virtualPropertyReplacer;
private RSQLSpecification(final String rsql, final Class<A> enumType,
VirtualPropertyLookup virtualPropertyLookup) {
VirtualPropertyReplacer virtualPropertyReplacer) {
this.rsql = rsql;
this.enumType = enumType;
this.virtualPropertyLookup = virtualPropertyLookup;
this.virtualPropertyReplacer = virtualPropertyReplacer;
}
@Override
@@ -157,7 +157,7 @@ public final class RSQLUtility {
final Node rootNode = parseRsql(rsql);
final JpqQueryRSQLVisitor<A, T> jpqQueryRSQLVisitor = new JpqQueryRSQLVisitor<>(root, cb, enumType,
virtualPropertyLookup);
virtualPropertyReplacer);
final List<Predicate> accept = rootNode.<List<Predicate>, String> accept(jpqQueryRSQLVisitor);
if (accept != null && !accept.isEmpty()) {
@@ -187,19 +187,16 @@ public final class RSQLUtility {
private final Root<T> root;
private final CriteriaBuilder cb;
private final Class<A> enumType;
private final StrSubstitutor substitutor;
private final VirtualPropertyReplacer virtualPropertyReplacer;
private final SimpleTypeConverter simpleTypeConverter;
private JpqQueryRSQLVisitor(final Root<T> root, final CriteriaBuilder cb, final Class<A> enumType,
VirtualPropertyLookup virtualPropertyLookup) {
VirtualPropertyReplacer virtualPropertyReplacer) {
this.root = root;
this.cb = cb;
this.enumType = enumType;
this.substitutor = (virtualPropertyLookup != null && virtualPropertyLookup instanceof StrLookup)
? new StrSubstitutor((StrLookup)virtualPropertyLookup, StrSubstitutor.DEFAULT_PREFIX,
StrSubstitutor.DEFAULT_SUFFIX, StrSubstitutor.DEFAULT_ESCAPE)
: null;
this.virtualPropertyReplacer = virtualPropertyReplacer;
simpleTypeConverter = new SimpleTypeConverter();
}
@@ -446,8 +443,8 @@ public final class RSQLUtility {
final String value;
// if lookup is available, replace macros ...
if (substitutor != null) {
value = substitutor.replace(values.get(0));
if (virtualPropertyReplacer != null) {
value = virtualPropertyReplacer.replace(values.get(0));
} else {
value = values.get(0);
}

View File

@@ -1,28 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
/**
* Implementations map a placeholder to the associated value.
* <p>
* This is used in context of string replacement.
*/
@FunctionalInterface
public interface VirtualPropertyLookup {
/**
* Looks up a placeholder to the associated value.
*
* @param placeholder
* the virtual property that should be resolved by a value
* @return the value for the placeholder; may be <code>null</code> if no
* value could be found for the given placeholder;
*/
String lookup(String placeholder);
}

View File

@@ -1,65 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
import java.time.Instant;
import org.apache.commons.lang3.text.StrLookup;
import org.eclipse.hawkbit.repository.jpa.TimestampCalculator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Adds macro capabilities to RSQL expressions that are used to filter for
* targets.
* <p>
* Some (virtual) properties do not have a representation in the database (in
* general these properties are time-related, or more explicitly, they deal with
* time intervals).<br>
* Such a virtual property needs to be calculated on Java-side before it may be
* used in a target filter query that is passed to the database. Therefore a
* placeholder is used in the RSQL expression that is expanded in the
* {@link RSQLUtility}.
* <p>
* A virtual property may either be a system value like the current date (aka
* <em>now_ts</em>) or a value derived from (tenant-specific) system
* configuration (e.g. <em>overdue_ts</em>).
* <p>
* Known values are:<br>
* <ul>
* <li><em>now_ts</em>: maps to system UTC time in milliseconds since Unix epoch
* as long value</li>
* <li><em>overdue_ts</em>: is a calculated value: <em>overdue_ts = now_ts -
* pollingInterval - pollingOverdueInterval</em>; pollingInterval and
* pollingOverdueInterval are retrieved from tenant-specific system
* configuration.</li>
* </ul>
*/
@Component
public class VirtualPropertyResolver extends StrLookup<String> implements VirtualPropertyLookup {
@Autowired
private TimestampCalculator timestampCalculator;
@Override
public String lookup(String rhs) {
String resolved = null;
if ("now_ts".equalsIgnoreCase(rhs)) {
resolved = String.valueOf(Instant.now().toEpochMilli());
} else if ("overdue_ts".equalsIgnoreCase(rhs)) {
resolved = String.valueOf(getTimestampCalculator().calculateOverdueTimestamp());
}
return resolved;
}
TimestampCalculator getTimestampCalculator() {
return timestampCalculator;
}
}

View File

@@ -30,6 +30,7 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldExc
import org.eclipse.hawkbit.repository.jpa.TimestampCalculator;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -321,7 +322,7 @@ public class RSQLUtilityTest {
eq(overduePropPlaceholder));
}
public VirtualPropertyLookup setupMacroLookup() {
public VirtualPropertyReplacer setupMacroLookup() {
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class))
.thenReturn(TEST_POLLING_TIME_INTERVAL);
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class))

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.junit.Assert.*;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.time.Instant;