Search in sources :

Example 16 with LectureBlockRollCall

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());
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 17 with LectureBlockRollCall

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());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) LectureBlockRollCallVO(org.olat.modules.lecture.restapi.LectureBlockRollCallVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Date(java.util.Date) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCallSearchParameters(org.olat.modules.lecture.LectureBlockRollCallSearchParameters) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 18 with LectureBlockRollCall

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());
}
Also used : LectureBlockAndRollCall(org.olat.modules.lecture.model.LectureBlockAndRollCall) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall)

Example 19 with LectureBlockRollCall

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);
    }
}
Also used : LectureRollCallStatus(org.olat.modules.lecture.LectureRollCallStatus) LectureBlockStatus(org.olat.modules.lecture.LectureBlockStatus) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall)

Example 20 with LectureBlockRollCall

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;
}
Also used : LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl)

Aggregations

LectureBlockRollCall (org.olat.modules.lecture.LectureBlockRollCall)64 LectureBlock (org.olat.modules.lecture.LectureBlock)40 Identity (org.olat.core.id.Identity)36 Test (org.junit.Test)26 LectureBlockRollCallSearchParameters (org.olat.modules.lecture.LectureBlockRollCallSearchParameters)16 Date (java.util.Date)14 ArrayList (java.util.ArrayList)12 List (java.util.List)10 LectureService (org.olat.modules.lecture.LectureService)10 HashMap (java.util.HashMap)8 IOException (java.io.IOException)6 URI (java.net.URI)6 Collectors (java.util.stream.Collectors)6 HttpResponse (org.apache.http.HttpResponse)6 LectureBlockRollCallVO (org.olat.modules.lecture.restapi.LectureBlockRollCallVO)6 LectureBlockStatus (org.olat.modules.lecture.LectureBlockStatus)5 LectureRollCallStatus (org.olat.modules.lecture.LectureRollCallStatus)5 Map (java.util.Map)4 Roles (org.olat.core.id.Roles)4 LectureBlockAndRollCall (org.olat.modules.lecture.model.LectureBlockAndRollCall)4