Skip to content
Snippets Groups Projects
Commit 681ebaac authored by srosse's avatar srosse
Browse files

OO-4150: absence category are not mandatory

parent 3db03716
No related branches found
No related tags found
No related merge requests found
......@@ -208,7 +208,7 @@ public class AbsenceNoticeDAO {
public List<AbsenceNoticeInfos> search(AbsenceNoticeSearchParameters searchParams, boolean absenceDefaultAuthorized) {
QueryBuilder sb = new QueryBuilder(512);
sb.append("select notice from absencenotice as notice")
.append(" inner join fetch notice.absenceCategory as category")
.append(" left join fetch notice.absenceCategory as category")
.append(" inner join fetch notice.identity as aIdent")
.append(" inner join fetch aIdent.user as aUser");
if(!searchParams.getTypes().isEmpty()) {
......
......@@ -211,17 +211,59 @@ public class AbsenceNoticeDAOTest extends OlatTestCase {
Assert.assertTrue(collisions.isEmpty());
}
/**
* Search absences
*/
@Test
public void searchAbsenceNotice() {
Date now = new Date();
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("absent-3");
Date start = CalendarUtils.startOfDay(new Date());
Date end = CalendarUtils.endOfDay(new Date());
Date start = CalendarUtils.startOfDay(now);
Date end = CalendarUtils.endOfDay(now);
AbsenceNotice notice = absenceNoticeDao.createAbsenceNotice(identity, AbsenceNoticeType.absence, AbsenceNoticeTarget.allentries,
start, end, null, null, null, null, null);
dbInstance.commitAndCloseSession();
AbsenceNoticeSearchParameters searchParams = new AbsenceNoticeSearchParameters();
List<AbsenceNoticeInfos> foundNotices = absenceNoticeDao.search(searchParams, true);
Assert.assertNotNull(foundNotices);
Assert.assertFalse(foundNotices.isEmpty());
long count = foundNotices.stream()
.filter(n -> notice.equals(n.getAbsenceNotice())).count();
Assert.assertEquals(1, count);
}
/**
* Search the absence of a participant
*/
@Test
public void searchAbsenceNotice_allentries() {
Date now = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(now);
cal.set(Calendar.HOUR_OF_DAY, 10);
Date startLecture = cal.getTime();
cal.set(Calendar.HOUR_OF_DAY, 14);
Date endLecture = cal.getTime();
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("absent-3");
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
LectureBlock lectureBlock = createMinimalLectureBlock(entry, startLecture, endLecture);
// create the participant's relation (lecture block use repo entry group, participant is participant in this group)
repositoryEntryRelationDao.addRole(identity, entry, GroupRoles.participant.name());
Group defGroup = repositoryEntryRelationDao.getDefaultGroup(lectureBlock.getEntry());
lectureBlockDao.addGroupToLectureBlock(lectureBlock, defGroup);
dbInstance.commit();
Date start = CalendarUtils.startOfDay(now);
Date end = CalendarUtils.endOfDay(now);
AbsenceNotice notice = absenceNoticeDao.createAbsenceNotice(identity, AbsenceNoticeType.absence, AbsenceNoticeTarget.allentries,
start, end, null, null, null, null, null);
dbInstance.commitAndCloseSession();
AbsenceNoticeSearchParameters searchParams = new AbsenceNoticeSearchParameters();
searchParams.setParticipant(identity);
List<AbsenceNoticeInfos> foundNotices = absenceNoticeDao.search(searchParams, true);
Assert.assertNotNull(foundNotices);
Assert.assertFalse(foundNotices.isEmpty());
......
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