aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle2
-rw-r--r--src/main/java/org/traccar/model/Calendar.java24
-rw-r--r--src/main/java/org/traccar/schedule/TaskReports.java8
3 files changed, 14 insertions, 20 deletions
diff --git a/build.gradle b/build.gradle
index 48ca50c79..2619bdedb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -80,7 +80,7 @@ dependencies {
implementation "org.apache.velocity:velocity-engine-core:2.3"
implementation "org.apache.velocity.tools:velocity-tools-generic:3.1"
implementation "org.apache.commons:commons-collections4:4.4"
- implementation "org.mnode.ical4j:ical4j:3.2.18"
+ implementation "org.mnode.ical4j:ical4j:4.0.2"
implementation "org.locationtech.spatial4j:spatial4j:0.8"
implementation "org.locationtech.jts:jts-core:1.19.0"
implementation "net.java.dev.jna:jna-platform:5.14.0"
diff --git a/src/main/java/org/traccar/model/Calendar.java b/src/main/java/org/traccar/model/Calendar.java
index 76c9a2cc1..c1a570037 100644
--- a/src/main/java/org/traccar/model/Calendar.java
+++ b/src/main/java/org/traccar/model/Calendar.java
@@ -19,9 +19,6 @@ package org.traccar.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.ParserException;
-import net.fortuna.ical4j.filter.Filter;
-import net.fortuna.ical4j.filter.predicate.PeriodRule;
-import net.fortuna.ical4j.model.DateTime;
import net.fortuna.ical4j.model.Period;
import net.fortuna.ical4j.model.component.CalendarComponent;
import net.fortuna.ical4j.model.component.VEvent;
@@ -31,9 +28,8 @@ import org.traccar.storage.StorageName;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.time.Duration;
-import java.util.Collection;
+import java.time.Instant;
import java.util.Date;
-import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -70,23 +66,19 @@ public class Calendar extends ExtendedModel {
return calendar;
}
- private Collection<VEvent> findEvents(Date date) {
+ public Set<Period<Instant>> findPeriods(Date date) {
if (calendar != null) {
- var filter = new Filter<VEvent>(new PeriodRule<>(new Period(new DateTime(date), Duration.ZERO)));
- return filter.filter(calendar.getComponents(CalendarComponent.VEVENT));
+ var period = new Period<>(date.toInstant(), Duration.ZERO);
+ return calendar.<VEvent>getComponents(CalendarComponent.VEVENT).stream()
+ .flatMap(c -> c.<Instant>calculateRecurrenceSet(period).stream())
+ .collect(Collectors.toUnmodifiableSet());
} else {
- return List.of();
+ return Set.of();
}
}
- public Set<Period> findPeriods(Date date) {
- return findEvents(date).stream()
- .flatMap((e) -> e.calculateRecurrenceSet(new Period(new DateTime(date), Duration.ZERO)).stream())
- .collect(Collectors.toSet());
- }
-
public boolean checkMoment(Date date) {
- return !findEvents(date).isEmpty();
+ return !findPeriods(date).isEmpty();
}
}
diff --git a/src/main/java/org/traccar/schedule/TaskReports.java b/src/main/java/org/traccar/schedule/TaskReports.java
index 1b9b15749..32f6fea87 100644
--- a/src/main/java/org/traccar/schedule/TaskReports.java
+++ b/src/main/java/org/traccar/schedule/TaskReports.java
@@ -41,6 +41,8 @@ import org.traccar.storage.query.Condition;
import org.traccar.storage.query.Request;
import jakarta.inject.Inject;
+
+import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
@@ -83,12 +85,12 @@ public class TaskReports extends SingleScheduleTask {
var lastEvents = calendar.findPeriods(lastCheck);
var currentEvents = calendar.findPeriods(currentCheck);
- Set<Period> finishedEvents = new HashSet<>(lastEvents);
+ Set<Period<Instant>> finishedEvents = new HashSet<>(lastEvents);
finishedEvents.removeAll(currentEvents);
- for (Period period : finishedEvents) {
+ for (Period<Instant> period : finishedEvents) {
RequestScoper scope = ServletScopes.scopeRequest(Collections.emptyMap());
try (RequestScoper.CloseableScope ignored = scope.open()) {
- executeReport(report, period.getStart(), period.getEnd());
+ executeReport(report, Date.from(period.getStart()), Date.from(period.getEnd()));
}
}
}