Search in sources :

Example 1 with ICalendarEventRepository

use of com.axelor.apps.base.db.repo.ICalendarEventRepository in project axelor-open-suite by axelor.

the class ICalendarService method removeDeletedEventsInRange.

@Transactional
protected void removeDeletedEventsInRange(Set<String> allRemoteUids, ICalendar calendar, LocalDateTime startDate, LocalDateTime endDate) {
    QueryBuilder<ICalendarEvent> queryBuilder = QueryBuilder.of(ICalendarEvent.class);
    queryBuilder.add("self.uid NOT in (:uids)").bind("uids", allRemoteUids);
    queryBuilder.add("self.calendar = :calendar").bind("calendar", calendar);
    queryBuilder.add("self.archived = :archived OR self.archived IS NULL").bind("archived", false);
    if (startDate != null && endDate != null) {
        queryBuilder.add("self.startDateTime BETWEEN :start AND :end OR self.endDateTime BETWEEN :start AND :end").bind("start", startDate).bind("end", endDate);
    }
    ICalendarEventRepository repo = Beans.get(ICalendarEventRepository.class);
    for (ICalendarEvent event : queryBuilder.build().fetch()) {
        if (ICalendarRepository.ICAL_ONLY.equals(calendar.getSynchronizationSelect())) {
            repo.remove(event);
        } else {
            event.setArchived(true);
        }
    }
}
Also used : ICalendarEvent(com.axelor.apps.base.db.ICalendarEvent) ICalendarEventRepository(com.axelor.apps.base.db.repo.ICalendarEventRepository) Transactional(com.google.inject.persist.Transactional)

Aggregations

ICalendarEvent (com.axelor.apps.base.db.ICalendarEvent)1 ICalendarEventRepository (com.axelor.apps.base.db.repo.ICalendarEventRepository)1 Transactional (com.google.inject.persist.Transactional)1