use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.
the class LectureBlockRollCallDAOTest method removeLectures.
@Test
public void removeLectures() {
LectureBlock lectureBlock = createMinimalLectureBlock(4);
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
dbInstance.commitAndCloseSession();
List<Integer> absences = Arrays.asList(0, 1, 2, 3);
LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
dbInstance.commitAndCloseSession();
LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
Assert.assertNotNull(reloadRollCall);
Assert.assertEquals(4, reloadRollCall.getLecturesAbsentNumber());
List<Integer> removedAbsences = Arrays.asList(1, 2);
lectureBlockRollCallDao.removeLecture(lectureBlock, reloadRollCall, removedAbsences);
dbInstance.commitAndCloseSession();
// check absence
Assert.assertEquals(2, reloadRollCall.getLecturesAbsentNumber());
List<Integer> absenceList = reloadRollCall.getLecturesAbsentList();
Assert.assertNotNull(absenceList);
Assert.assertEquals(2, absenceList.size());
Assert.assertEquals(0, absenceList.get(0).intValue());
Assert.assertEquals(3, absenceList.get(1).intValue());
// check attendee
Assert.assertEquals(2, reloadRollCall.getLecturesAttendedNumber());
List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
Assert.assertNotNull(attendeeList);
Assert.assertEquals(2, attendeeList.size());
Assert.assertEquals(1, attendeeList.get(0).intValue());
Assert.assertEquals(2, attendeeList.get(1).intValue());
}
use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.
the class LecturesBlockRollCallTest method getAndUpdateSupervisorDate.
@Test
public void getAndUpdateSupervisorDate() throws IOException, URISyntaxException {
// a closed lecture block
LectureBlock lectureBlock = createMinimalLectureBlock(3);
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
dbInstance.commit();
List<Integer> absences = Arrays.asList(1, 2);
LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
dbInstance.commitAndCloseSession();
// POST REST call
LectureBlockRollCallVO rollCallVo = new LectureBlockRollCallVO();
rollCallVo.setKey(rollCall.getKey());
rollCallVo.setLecturesAbsentNumber(rollCall.getLecturesAbsentNumber());
rollCallVo.setLecturesAttendedNumber(rollCall.getLecturesAttendedNumber());
rollCallVo.setComment(rollCall.getComment());
rollCallVo.setAbsenceReason(rollCall.getAbsenceReason());
rollCallVo.setAbsenceAuthorized(rollCall.getAbsenceAuthorized());
rollCallVo.setAbsenceSupervisorNotificationDate(new Date());
rollCallVo.setIdentityKey(id.getKey());
rollCallVo.setLectureBlockKey(lectureBlock.getKey());
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("lectures").path("rollcalls").build();
HttpPost postMethod = conn.createPost(uri, MediaType.APPLICATION_JSON);
conn.addJsonEntity(postMethod, rollCallVo);
HttpResponse response = conn.execute(postMethod);
// check the response
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
LectureBlockRollCallVO updatedRollCallVo = conn.parse(response, LectureBlockRollCallVO.class);
Assert.assertNotNull(updatedRollCallVo);
Assert.assertEquals(rollCall.getKey(), updatedRollCallVo.getKey());
Assert.assertNotNull(updatedRollCallVo.getAbsenceSupervisorNotificationDate());
// reload the roll call from the database
LectureBlockRollCallSearchParameters searchParams = new LectureBlockRollCallSearchParameters();
searchParams.setRollCallKey(rollCall.getKey());
List<LectureBlockRollCall> rollCalls = lectureBlockRollCallDao.getRollCalls(searchParams);
Assert.assertNotNull(rollCalls);
Assert.assertEquals(1, rollCalls.size());
LectureBlockRollCall updatedRollCall = rollCalls.get(0);
Assert.assertEquals(rollCall, updatedRollCall);
Assert.assertNotNull(updatedRollCall.getAbsenceSupervisorNotificationDate());
}
use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.
the class LectureBlockRollCallDAO method getParticipantLectureBlockAndRollCalls.
public List<LectureBlockAndRollCall> getParticipantLectureBlockAndRollCalls(RepositoryEntryRef entry, IdentityRef identity, String teacherSeaparator) {
StringBuilder sb = new StringBuilder();
sb.append("select block, call, re.displayname").append(" from lectureblock block").append(" inner join block.entry re").append(" inner join block.groups blockToGroup").append(" inner join blockToGroup.group bGroup").append(" inner join bGroup.members membership").append(" inner join lectureparticipantsummary as summary on (summary.identity.key=membership.identity.key and summary.entry.key=block.entry.key)").append(" left join lectureblockrollcall as call on (call.identity.key=membership.identity.key and call.lectureBlock.key=block.key)").append(" where membership.identity.key=:identityKey and membership.role='").append(GroupRoles.participant.name()).append("'").append(" and block.entry.key=:repoEntryKey and block.endDate>=summary.firstAdmissionDate");
List<Object[]> rawObjects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", identity.getKey()).setParameter("repoEntryKey", entry.getKey()).getResultList();
Map<Long, LectureBlockAndRollCall> blockToRollCallMap = new HashMap<>();
for (Object[] objects : rawObjects) {
int pos = 0;
LectureBlock block = (LectureBlock) objects[pos++];
LectureBlockRollCall rollCall = (LectureBlockRollCall) objects[pos++];
String displayname = (String) objects[pos++];
blockToRollCallMap.put(block.getKey(), new LectureBlockAndRollCall(displayname, block, rollCall));
}
appendCoaches(entry, blockToRollCallMap, teacherSeaparator);
return new ArrayList<>(blockToRollCallMap.values());
}
use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.
the class LectureServiceImpl method adaptRollCalls.
@Override
public void adaptRollCalls(LectureBlock lectureBlock) {
LectureBlockStatus status = lectureBlock.getStatus();
LectureRollCallStatus rollCallStatus = lectureBlock.getRollCallStatus();
if (status == LectureBlockStatus.done || rollCallStatus == LectureRollCallStatus.closed || rollCallStatus == LectureRollCallStatus.autoclosed) {
log.warn("Try to adapt roll call of a closed lecture block: " + lectureBlock.getKey());
return;
}
List<LectureBlockRollCall> rollCallList = lectureBlockRollCallDao.getRollCalls(lectureBlock);
for (LectureBlockRollCall rollCall : rollCallList) {
int numOfLectures = lectureBlock.getEffectiveLecturesNumber();
if (numOfLectures <= 0 && lectureBlock.getStatus() != LectureBlockStatus.cancelled) {
numOfLectures = lectureBlock.getPlannedLecturesNumber();
}
lectureBlockRollCallDao.adaptLecture(lectureBlock, rollCall, numOfLectures, null);
}
}
use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.
the class LectureServiceImpl method close.
@Override
public LectureBlock close(LectureBlock lectureBlock, Identity author) {
lectureBlock.setStatus(LectureBlockStatus.done);
lectureBlock.setRollCallStatus(LectureRollCallStatus.closed);
LectureBlockImpl block = (LectureBlockImpl) lectureBlockDao.update(lectureBlock);
int numOfLectures = block.getEffectiveLecturesNumber();
if (numOfLectures <= 0 && block.getStatus() != LectureBlockStatus.cancelled) {
numOfLectures = block.getPlannedLecturesNumber();
}
List<LectureBlockRollCall> rollCallList = lectureBlockRollCallDao.getRollCalls(lectureBlock);
for (LectureBlockRollCall rollCall : rollCallList) {
lectureBlockRollCallDao.adaptLecture(block, rollCall, numOfLectures, author);
}
dbInstance.commit();
recalculateSummary(block.getEntry());
return block;
}
Aggregations