Skip to content
Snippets Groups Projects
Commit abdae420 authored by uhensler's avatar uhensler
Browse files

OO-4630: Respect full day events when filtering by end date

parent 12b859e5
No related branches found
No related tags found
No related merge requests found
...@@ -119,21 +119,10 @@ public class AppointmentsPeekViewController extends BasicController { ...@@ -119,21 +119,10 @@ public class AppointmentsPeekViewController extends BasicController {
return null; return null;
} }
private Optional<Appointment> getNextAppointment(List<Appointment> loadedAppointments) { private Optional<Appointment> getNextAppointment(List<Appointment> appointments) {
List<Appointment> appointments = new ArrayList<>(loadedAppointments.size());
Date now = new Date(); Date now = new Date();
for (Appointment appointment: loadedAppointments) {
Date begin = appointment.getStart();
Date end = appointment.getEnd();
Date ajustedEnd = new Date(end.getTime());
if (DateUtils.isSameDate(begin, end) && DateUtils.isSameTime(begin, end)) {
ajustedEnd = DateUtils.setTime(ajustedEnd, 23, 59, 59);
}
if (now.before(ajustedEnd)) {
appointments.add(appointment);
}
}
Optional<Appointment> appointment = appointments.stream() Optional<Appointment> appointment = appointments.stream()
.filter(a -> appointmentsService.isEndAfter(a, now))
.sorted((a1, a2) -> a1.getStart().compareTo(a2.getStart())) .sorted((a1, a2) -> a1.getStart().compareTo(a2.getStart()))
.limit(1) .limit(1)
.findFirst(); .findFirst();
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package org.olat.modules.appointments; package org.olat.modules.appointments;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -101,6 +102,16 @@ public interface AppointmentsService { ...@@ -101,6 +102,16 @@ public interface AppointmentsService {
public void deleteAppointment(Appointment appointment); public void deleteAppointment(Appointment appointment);
/**
* Checks whether the end of the appointment is after the due date.
* It respects full day events.
*
* @param appointment
* @param dueDate
* @return
*/
public boolean isEndAfter(Appointment appointment, Date dueDate);
/** /**
* Gets the key of the topic and the according count of appointments. * Gets the key of the topic and the according count of appointments.
* *
......
...@@ -40,6 +40,7 @@ import org.olat.core.commons.services.notifications.NotificationsManager; ...@@ -40,6 +40,7 @@ import org.olat.core.commons.services.notifications.NotificationsManager;
import org.olat.core.commons.services.notifications.PublisherData; import org.olat.core.commons.services.notifications.PublisherData;
import org.olat.core.commons.services.notifications.SubscriptionContext; import org.olat.core.commons.services.notifications.SubscriptionContext;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.util.DateUtils;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
import org.olat.course.CourseFactory; import org.olat.course.CourseFactory;
import org.olat.course.ICourse; import org.olat.course.ICourse;
...@@ -434,6 +435,17 @@ public class AppointmentsServiceImpl implements AppointmentsService { ...@@ -434,6 +435,17 @@ public class AppointmentsServiceImpl implements AppointmentsService {
appointmentDao.delete(appointment); appointmentDao.delete(appointment);
} }
@Override
public boolean isEndAfter(Appointment appointment, Date dueDate) {
Date begin = appointment.getStart();
Date end = appointment.getEnd();
Date ajustedEnd = new Date(end.getTime());
if (DateUtils.isSameDate(begin, end) && DateUtils.isSameTime(begin, end)) {
ajustedEnd = DateUtils.setTime(ajustedEnd, 23, 59, 59);
}
return ajustedEnd.after(dueDate);
}
@Override @Override
public Map<Long, Long> getTopicKeyToAppointmentCount(AppointmentSearchParams params, boolean freeOnly) { public Map<Long, Long> getTopicKeyToAppointmentCount(AppointmentSearchParams params, boolean freeOnly) {
return appointmentDao.loadTopicKeyToAppointmentCount(params, freeOnly); return appointmentDao.loadTopicKeyToAppointmentCount(params, freeOnly);
......
...@@ -221,7 +221,7 @@ public class TopicsRunCoachController extends BasicController { ...@@ -221,7 +221,7 @@ public class TopicsRunCoachController extends BasicController {
} else { } else {
nextAppointment = appointments.stream() nextAppointment = appointments.stream()
.filter(a -> Appointment.Status.confirmed == a.getStatus()) .filter(a -> Appointment.Status.confirmed == a.getStatus())
.filter(a1 -> now.before(a1.getEnd())) .filter(a -> appointmentsService.isEndAfter(a, now))
.sorted((a1, a2) -> a1.getStart().compareTo(a2.getStart())) .sorted((a1, a2) -> a1.getStart().compareTo(a2.getStart()))
.findFirst(); .findFirst();
} }
......
...@@ -236,7 +236,7 @@ public class TopicsRunController extends BasicController implements Activateable ...@@ -236,7 +236,7 @@ public class TopicsRunController extends BasicController implements Activateable
Date now = new Date(); Date now = new Date();
Optional<Appointment> nextAppointment = myTopicParticipations.stream() Optional<Appointment> nextAppointment = myTopicParticipations.stream()
.map(Participation::getAppointment) .map(Participation::getAppointment)
.filter(a1 -> now.before(a1.getEnd())) .filter(a -> appointmentsService.isEndAfter(a, now))
.sorted((a1, a2) -> a1.getStart().compareTo(a2.getStart())) .sorted((a1, a2) -> a1.getStart().compareTo(a2.getStart()))
.findFirst(); .findFirst();
Appointment appointment = nextAppointment.isPresent() Appointment appointment = nextAppointment.isPresent()
......
...@@ -76,6 +76,25 @@ public class AppointmentsServiceTest extends OlatTestCase { ...@@ -76,6 +76,25 @@ public class AppointmentsServiceTest extends OlatTestCase {
organizerDelete); organizerDelete);
} }
@Test
public void shouldCheckEndAfterDueDate() {
Appointment appointment = sut.createUnsavedAppointment(null);
appointment.setStart(new GregorianCalendar(2020, 2, 3, 10, 0, 0).getTime());
appointment.setEnd(new GregorianCalendar(2020, 2, 3, 11, 0, 0).getTime());
assertThat(sut.isEndAfter(appointment, new GregorianCalendar(2020, 2, 3, 12, 0, 0).getTime())).isFalse();
appointment = sut.createUnsavedAppointment(null);
appointment.setStart(new GregorianCalendar(2020, 2, 3, 10, 0, 0).getTime());
appointment.setEnd(new GregorianCalendar(2020, 2, 3, 14, 0, 0).getTime());
assertThat(sut.isEndAfter(appointment, new GregorianCalendar(2020, 2, 3, 12, 0, 0).getTime())).isTrue();
// full day
appointment = sut.createUnsavedAppointment(null);
appointment.setStart(new GregorianCalendar(2020, 2, 3, 10, 0, 0).getTime());
appointment.setEnd(new GregorianCalendar(2020, 2, 3, 10, 0, 0).getTime());
assertThat(sut.isEndAfter(appointment, new GregorianCalendar(2020, 2, 3, 12, 0, 0).getTime())).isTrue();
}
@Test @Test
public void createParticipationShouldCreateParticiption() { public void createParticipationShouldCreateParticiption() {
Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("ap"); Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("ap");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment