Overdue target filter based on makro resolution of placeholders
Signed-off-by: Marcel Mager (INST-IOT/ESB) <Marcel.Mager@bosch-si.com>
This commit is contained in:
@@ -52,6 +52,7 @@ import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyMakroResolver;
|
||||
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
@@ -162,7 +163,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return the singleton instance of the
|
||||
* {@link AfterTransactionCommitExecutorHolder}
|
||||
*/
|
||||
@@ -225,7 +226,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaSystemManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link SystemManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -236,7 +237,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaReportManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link ReportManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -247,7 +248,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaDistributionSetManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link DistributionSetManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -258,7 +259,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaTenantStatsManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link TenantStatsManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -271,7 +272,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaTenantConfigurationManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link TenantConfigurationManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -282,7 +283,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaTenantConfigurationManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link TenantConfigurationManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -293,7 +294,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaTargetFilterQueryManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link TargetFilterQueryManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -304,7 +305,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaTagManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link TagManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -315,7 +316,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaSoftwareManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link SoftwareManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -326,7 +327,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaRolloutManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link RolloutManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -337,7 +338,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaRolloutGroupManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link RolloutGroupManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -348,7 +349,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaDeploymentManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link DeploymentManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -359,7 +360,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaControllerManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link ControllerManagement}
|
||||
*/
|
||||
@Bean
|
||||
@@ -370,7 +371,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaArtifactManagement} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link ArtifactManagement}
|
||||
*/
|
||||
|
||||
@@ -382,7 +383,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* {@link JpaEntityFactory} bean.
|
||||
*
|
||||
*
|
||||
* @return a new {@link EntityFactory}
|
||||
*/
|
||||
@Bean
|
||||
@@ -390,4 +391,15 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
public EntityFactory entityFactory() {
|
||||
return new JpaEntityFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link VirtualPropertyMakroResolver} bean.
|
||||
*
|
||||
* @return a new {@link VirtualPropertyMakroResolver}
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public VirtualPropertyMakroResolver virtualPropertyMakroResolver() {
|
||||
return new VirtualPropertyMakroResolver();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +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.VirtualPropertyMakroResolver;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetFilterQuerySpecification;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
@@ -44,6 +45,9 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
@Autowired
|
||||
private TargetFilterQueryRepository targetFilterQueryRepository;
|
||||
|
||||
@Autowired
|
||||
private VirtualPropertyMakroResolver virtualPropMakroResolver;
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@@ -111,7 +115,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
|
||||
@Override
|
||||
public boolean verifyTargetFilterQuerySyntax(final String query) {
|
||||
RSQLUtility.parse(query, TargetFields.class);
|
||||
RSQLUtility.parse(query, TargetFields.class, virtualPropMakroResolver);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,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.VirtualPropertyMakroResolver;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -102,6 +103,9 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Autowired
|
||||
private AfterTransactionCommitExecutor afterCommit;
|
||||
|
||||
@Autowired
|
||||
private VirtualPropertyMakroResolver virtualPropMakroResolver;
|
||||
|
||||
@Override
|
||||
public Target findTargetByControllerID(final String controllerId) {
|
||||
return targetRepository.findByControllerId(controllerId);
|
||||
@@ -152,12 +156,15 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Slice<Target> findTargetsAll(final TargetFilterQuery targetFilterQuery, final Pageable pageable) {
|
||||
return findTargetsBySpec(RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class), pageable);
|
||||
return findTargetsBySpec(
|
||||
RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class, virtualPropMakroResolver),
|
||||
pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findTargetsAll(final String targetFilterQuery, final Pageable pageable) {
|
||||
return findTargetsBySpec(RSQLUtility.parse(targetFilterQuery, TargetFields.class), pageable);
|
||||
return findTargetsBySpec(RSQLUtility.parse(targetFilterQuery, TargetFields.class, virtualPropMakroResolver),
|
||||
pageable);
|
||||
}
|
||||
|
||||
private Page<Target> findTargetsBySpec(final Specification<JpaTarget> spec, final Pageable pageable) {
|
||||
@@ -224,7 +231,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public Page<Target> findTargetByAssignedDistributionSet(final Long distributionSetID, final String rsqlParam,
|
||||
final Pageable pageReq) {
|
||||
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class);
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class,
|
||||
virtualPropMakroResolver);
|
||||
|
||||
return convertPage(
|
||||
targetRepository
|
||||
@@ -252,7 +260,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public Page<Target> findTargetByInstalledDistributionSet(final Long distributionSetId, final String rsqlParam,
|
||||
final Pageable pageable) {
|
||||
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class);
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class,
|
||||
virtualPropMakroResolver);
|
||||
|
||||
return convertPage(
|
||||
targetRepository
|
||||
@@ -544,7 +553,8 @@ 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);
|
||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class,
|
||||
virtualPropMakroResolver);
|
||||
final List<Specification<JpaTarget>> specList = new ArrayList<>();
|
||||
specList.add(spec);
|
||||
|
||||
@@ -627,13 +637,15 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Long countTargetByTargetFilterQuery(final TargetFilterQuery targetFilterQuery) {
|
||||
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class);
|
||||
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class,
|
||||
virtualPropMakroResolver);
|
||||
return targetRepository.count(specs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countTargetByTargetFilterQuery(final String targetFilterQuery) {
|
||||
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class);
|
||||
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
|
||||
virtualPropMakroResolver);
|
||||
return targetRepository.count(specs);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ import javax.persistence.criteria.Path;
|
||||
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;
|
||||
@@ -47,9 +49,8 @@ import cz.jirutka.rsql.parser.ast.RSQLOperators;
|
||||
import cz.jirutka.rsql.parser.ast.RSQLVisitor;
|
||||
|
||||
/**
|
||||
* A utility class which is able to parse RSQL strings into an spring data
|
||||
* {@link Specification} which then can be enhanced sql queries to filter
|
||||
* entities. RSQL parser library: https://github.com/jirutka/rsql-parser
|
||||
* A utility class which is able to parse RSQL strings into an spring data {@link Specification} which then can be
|
||||
* enhanced sql queries to filter entities. RSQL parser library: https://github.com/jirutka/rsql-parser
|
||||
*
|
||||
* <ul>
|
||||
* <li>Equal to : ==</li>
|
||||
@@ -59,16 +60,24 @@ import cz.jirutka.rsql.parser.ast.RSQLVisitor;
|
||||
* <li>Greater than operator : =gt= or ></li>
|
||||
* <li>Greater than or equal to : =ge= or >=</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Examples of RSQL expressions in both FIQL-like and alternative notation:
|
||||
* <ul>
|
||||
* <li>version==2.0.0</li>
|
||||
* <li>name==targetId1;description==plugAndPlay</li>
|
||||
* <li>name==targetId1 and description==plugAndPlay</li>
|
||||
* <li>name==targetId1;description==plugAndPlay</li>
|
||||
* <li>name==targetId1 and description==plugAndPlay</li>
|
||||
* <li>name==targetId1,description==plugAndPlay,updateStatus==UNKNOWN</li>
|
||||
* <li>name==targetId1 or description==plugAndPlay or updateStatus==UNKNOWN</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* There is also a mechanism that allows to refer to known makros that can resolved by an optional {@link StrLookup}
|
||||
* (cp. {@link VirtualPropertyMakroResolver}).<br>
|
||||
* An example that queries for all overdue targets using the ${OVERDUE_TS} placeholder introduced by
|
||||
* {@link VirtualPropertyMakroResolver} looks like this:<br>
|
||||
* <em>lastControllerRequestAt=le=${OVERDUE_TS}</em><br>
|
||||
* It is possible to escape a makro expression by using a second '$': $${OVERDUE_TS} would prevent the ${OVERDUE_TS}
|
||||
* token from being expanded.
|
||||
*
|
||||
*/
|
||||
public final class RSQLUtility {
|
||||
|
||||
@@ -99,7 +108,28 @@ public final class RSQLUtility {
|
||||
*/
|
||||
public static <A extends Enum<A> & FieldNameProvider, T> Specification<T> parse(final String rsql,
|
||||
final Class<A> fieldNameProvider) {
|
||||
return new RSQLSpecification<>(rsql.toLowerCase(), fieldNameProvider);
|
||||
return new RSQLSpecification<>(rsql.toLowerCase(), fieldNameProvider, new VirtualPropertyMakroResolver());
|
||||
}
|
||||
|
||||
/**
|
||||
* parses an RSQL valid string into an JPA {@link Specification} which then can be used to filter for JPA entities
|
||||
* with the given RSQL query.
|
||||
*
|
||||
* @param rsql
|
||||
* the rsql query
|
||||
* @param fieldNameProvider
|
||||
* the enum class type which implements the {@link FieldNameProvider}
|
||||
* @param makroLookup
|
||||
* holds the logic how the known makros have to be resolved; may be <code>null</code>
|
||||
* @return an specification which can be used with JPA
|
||||
* @throws RSQLParameterUnsupportedFieldException
|
||||
* if a field in the RSQL string is used but not provided by the given {@code fieldNameProvider}
|
||||
* @throws RSQLParameterSyntaxException
|
||||
* if the RSQL syntax is wrong
|
||||
*/
|
||||
public static <A extends Enum<A> & FieldNameProvider, T> Specification<T> parse(final String rsql,
|
||||
final Class<A> fieldNameProvider, StrLookup<String> makroLookup) {
|
||||
return new RSQLSpecification<>(rsql.toLowerCase(), fieldNameProvider, makroLookup);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,10 +160,12 @@ public final class RSQLUtility {
|
||||
|
||||
private final String rsql;
|
||||
private final Class<A> enumType;
|
||||
private final StrLookup<String> makroLookup;
|
||||
|
||||
private RSQLSpecification(final String rsql, final Class<A> enumType) {
|
||||
private RSQLSpecification(final String rsql, final Class<A> enumType, StrLookup<String> makroLookup) {
|
||||
this.rsql = rsql;
|
||||
this.enumType = enumType;
|
||||
this.makroLookup = makroLookup;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,7 +173,8 @@ public final class RSQLUtility {
|
||||
|
||||
final Node rootNode = parseRsql(rsql);
|
||||
|
||||
final JpqQueryRSQLVisitor<A, T> jpqQueryRSQLVisitor = new JpqQueryRSQLVisitor<>(root, cb, enumType);
|
||||
final JpqQueryRSQLVisitor<A, T> jpqQueryRSQLVisitor = new JpqQueryRSQLVisitor<>(root, cb, enumType,
|
||||
makroLookup);
|
||||
final List<Predicate> accept = rootNode.<List<Predicate>, String> accept(jpqQueryRSQLVisitor);
|
||||
|
||||
if (accept != null && !accept.isEmpty()) {
|
||||
@@ -171,13 +204,19 @@ public final class RSQLUtility {
|
||||
private final Root<T> root;
|
||||
private final CriteriaBuilder cb;
|
||||
private final Class<A> enumType;
|
||||
private final StrLookup<String> makroLookup;
|
||||
private final StrSubstitutor substitutor;
|
||||
|
||||
private final SimpleTypeConverter simpleTypeConverter;
|
||||
|
||||
private JpqQueryRSQLVisitor(final Root<T> root, final CriteriaBuilder cb, final Class<A> enumType) {
|
||||
private JpqQueryRSQLVisitor(final Root<T> root, final CriteriaBuilder cb, final Class<A> enumType,
|
||||
StrLookup<String> makroLookup) {
|
||||
this.root = root;
|
||||
this.cb = cb;
|
||||
this.enumType = enumType;
|
||||
this.makroLookup = makroLookup;
|
||||
this.substitutor = new StrSubstitutor(makroLookup, StrSubstitutor.DEFAULT_PREFIX,
|
||||
StrSubstitutor.DEFAULT_SUFFIX, StrSubstitutor.DEFAULT_ESCAPE);
|
||||
simpleTypeConverter = new SimpleTypeConverter();
|
||||
}
|
||||
|
||||
@@ -425,7 +464,14 @@ public final class RSQLUtility {
|
||||
// enums. The JPA API
|
||||
// cannot handle object types for greaterThan etc methods.
|
||||
final Object transformedValue = transformedValues.get(0);
|
||||
final String value = values.get(0);
|
||||
|
||||
final String value;
|
||||
if (makroLookup != null) { // if substitutor is available, replace makros ...
|
||||
value = substitutor.replace(values.get(0));
|
||||
} else {
|
||||
value = values.get(0);
|
||||
}
|
||||
|
||||
final List<Predicate> singleList = new ArrayList<>();
|
||||
|
||||
final Predicate mapPredicate = mapToMapPredicate(node, fieldPath, enumField);
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Copyright (c) 2016 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.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.apache.commons.lang3.text.StrLookup;
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Adds makro 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} by a {@link StrSubstitutor}. This {@link StrSubstitutor} is configured with an instance of
|
||||
* {@link VirtualPropertyMakroResolver} to resolve the known makros.
|
||||
* <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>
|
||||
*
|
||||
*/
|
||||
public class VirtualPropertyMakroResolver extends StrLookup<String> {
|
||||
|
||||
@Override
|
||||
public String lookup(String rhs) {
|
||||
String resolved = null;
|
||||
|
||||
if ("now_ts".equals(rhs.toLowerCase())) {
|
||||
resolved = String.valueOf(Instant.now().toEpochMilli());
|
||||
} else if ("overdue_ts".equals(rhs.toLowerCase())) {
|
||||
resolved = String.valueOf(Instant.now().toEpochMilli() //
|
||||
- getDurationForKey(TenantConfigurationKey.POLLING_TIME_INTERVAL).toMillis() //
|
||||
- getDurationForKey(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL).toMillis());
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
private Duration getDurationForKey(TenantConfigurationKey key) {
|
||||
return DurationHelper.formattedStringToDuration(getRawStringForKey(key));
|
||||
}
|
||||
|
||||
private String getRawStringForKey(TenantConfigurationKey key) {
|
||||
return getTenantConfigurationManagement().getConfigurationValue(key, String.class).getValue();
|
||||
}
|
||||
|
||||
TenantConfigurationManagement getTenantConfigurationManagement() {
|
||||
return TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user