Skip to content
Merged
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
Expand Up @@ -23,7 +23,10 @@
import org.slf4j.LoggerFactory;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

Expand Down Expand Up @@ -66,6 +69,20 @@ public static Date getDate(Object value) {
}
if (value instanceof Date) {
return (Date) value;
}
if (value instanceof Instant) {
return Date.from((Instant) value);
}
if (value instanceof OffsetDateTime) {
return Date.from(((OffsetDateTime) value).toInstant());
}
if (value instanceof ZonedDateTime) {
return Date.from(((ZonedDateTime) value).toInstant());
}
// LocalDateTime carries no timezone; treat as UTC per Unomi's server-side convention.
// Callers that need a specific zone should use ZonedDateTime or OffsetDateTime instead.
if (value instanceof LocalDateTime) {
return Date.from(((LocalDateTime) value).atZone(ZoneOffset.UTC).toInstant());
} else {
JavaDateFormatter formatter = new JavaDateFormatter("strict_date_optional_time||epoch_millis");
DateMathParser dateMathParser = new DateMathParser(formatter, DateTimeFormatter.ISO_DATE_TIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@
*/
public interface ConditionEvaluatorDispatcher {

/**
* Adds a new evaluator to the dispatcher.
*
* @param name the name of the evaluator
* @param evaluator the evaluator to add
*/
void addEvaluator(String name, ConditionEvaluator evaluator);

/**
* Removes an evaluator from the dispatcher.
*
* @param name the name of the evaluator to remove
*/
void removeEvaluator(String name);

/**
* Evaluates the provided {@link Condition} on the given {@link Item} using an empty context.
* This is a convenience overload equivalent to calling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.unomi.persistence.spi.conditions.evaluator.impl;

import org.apache.unomi.api.Item;
import org.apache.unomi.api.services.DefinitionsService;
import org.apache.unomi.api.conditions.Condition;
import org.apache.unomi.metrics.MetricAdapter;
import org.apache.unomi.metrics.MetricsService;
Expand Down Expand Up @@ -50,6 +51,7 @@ public class ConditionEvaluatorDispatcherImpl

private MetricsService metricsService;
private ScriptExecutor scriptExecutor;
private DefinitionsService definitionsService;

public ConditionEvaluatorDispatcherImpl() {
}
Expand All @@ -73,6 +75,24 @@ public void unbindEvaluator(ConditionEvaluator evaluator, Map<String, Object> pr
evaluators.remove((String) props.get("conditionEvaluatorId"));
}

public void setDefinitionsService(DefinitionsService definitionsService) {
this.definitionsService = definitionsService;
}

public void unsetDefinitionsService(DefinitionsService definitionsService) {
this.definitionsService = null;
}

@Override
public void addEvaluator(String name, ConditionEvaluator evaluator) {
evaluators.put(name, evaluator);
}

@Override
public void removeEvaluator(String name) {
evaluators.remove(name);
}

@Override
public boolean eval(Condition condition, Item item) {
return eval(condition, item, new HashMap<>());
Expand Down
10 changes: 8 additions & 2 deletions services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,14 @@

<!-- tests -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<scope>test</scope>
</dependency>

Expand Down
Loading
Loading