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

OO-4630: Respect maximum participants if counting free appointments

parent 909062e4
No related branches found
No related tags found
No related merge requests found
...@@ -186,9 +186,20 @@ class AppointmentDAO { ...@@ -186,9 +186,20 @@ class AppointmentDAO {
.map(t -> (Long)t.get(0)) .map(t -> (Long)t.get(0))
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
} }
private Predicate<? super Tuple> filterFreeOnly(boolean freeOnly) { private Predicate<Tuple> filterFreeOnly(boolean freeOnly) {
return t -> freeOnly? t.get(2) == null || ((Integer)t.get(2)).intValue() < ((Long)t.get(3)).intValue(): true; return t -> {
if (freeOnly) {
// no max participants
if (t.get(2) == null) {
return true;
}
Integer maxParticipants = (Integer)t.get(2);
Long count = (Long)t.get(3);
return count.intValue() < maxParticipants.intValue();
}
return true;
};
} }
Long loadAppointmentCount(AppointmentSearchParams params) { Long loadAppointmentCount(AppointmentSearchParams params) {
......
...@@ -276,16 +276,30 @@ public class AppointmentDAOTest extends OlatTestCase { ...@@ -276,16 +276,30 @@ public class AppointmentDAOTest extends OlatTestCase {
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry(); RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
Identity identity = JunitTestHelper.createAndPersistIdentityAsUser(random()); Identity identity = JunitTestHelper.createAndPersistIdentityAsUser(random());
String subIdent = JunitTestHelper.random(); String subIdent = JunitTestHelper.random();
Topic topic1 = topicDao.createTopic(entry, subIdent); Topic topic = topicDao.createTopic(entry, subIdent);
Topic topic2 = topicDao.createTopic(entry, subIdent);
Appointment appointment11 = sut.createAppointment(topic1); Appointment noLimitNoParticipations = sut.createAppointment(topic);
sut.createAppointment(topic1); Appointment noLimitWithParticipations = sut.createAppointment(topic);
Appointment appointment21 = sut.createAppointment(topic2); Appointment limitNoParticipations = sut.createAppointment(topic);
appointment21.setMaxParticipations(1); Appointment limitFull = sut.createAppointment(topic);
sut.saveAppointment(appointment21); Appointment limitNotFull = sut.createAppointment(topic);
participationDao.createParticipation(appointment11, identity); noLimitNoParticipations.setDetails("noLimitNoParticipations");
participationDao.createParticipation(appointment11, identity); sut.saveAppointment(noLimitNoParticipations);
participationDao.createParticipation(appointment21, identity); noLimitWithParticipations.setDetails("noLimitWithParticipations");
sut.saveAppointment(noLimitWithParticipations);
limitNoParticipations.setDetails("limitNoParticipations");
limitNoParticipations.setMaxParticipations(2);
sut.saveAppointment(limitNoParticipations);
limitFull.setDetails("limitFull");
limitFull.setMaxParticipations(1);
sut.saveAppointment(limitFull);
limitNotFull.setDetails("limitNotFull");
limitNotFull.setMaxParticipations(3);
sut.saveAppointment(limitNotFull);
participationDao.createParticipation(noLimitWithParticipations, identity);
participationDao.createParticipation(noLimitWithParticipations, identity);
participationDao.createParticipation(limitFull, identity);
participationDao.createParticipation(limitNotFull, identity);
dbInstance.commitAndCloseSession(); dbInstance.commitAndCloseSession();
AppointmentSearchParams params = new AppointmentSearchParams(); AppointmentSearchParams params = new AppointmentSearchParams();
...@@ -293,10 +307,7 @@ public class AppointmentDAOTest extends OlatTestCase { ...@@ -293,10 +307,7 @@ public class AppointmentDAOTest extends OlatTestCase {
params.setSubIdent(subIdent); params.setSubIdent(subIdent);
Map<Long, Long> appointmentCountByTopic = sut.loadTopicKeyToAppointmentCount(params, true); Map<Long, Long> appointmentCountByTopic = sut.loadTopicKeyToAppointmentCount(params, true);
SoftAssertions softly = new SoftAssertions(); assertThat(appointmentCountByTopic.get(topic.getKey())).isEqualTo(4);
softly.assertThat(appointmentCountByTopic.get(topic1.getKey())).isEqualTo(2);
softly.assertThat(appointmentCountByTopic.get(topic2.getKey())).isNull();
softly.assertAll();
} }
@Test @Test
......
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