Search in sources :

Example 31 with LectureBlockRollCall

use of org.olat.modules.lecture.LectureBlockRollCall in project OpenOLAT by OpenOLAT.

the class LectureBlockRollCallDAOTest method adaptLectures_removeAbsences.

@Test
public void adaptLectures_removeAbsences() {
    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());
    // adapt the number of lectures
    LectureBlockRollCall adaptedCall = lectureBlockRollCallDao.adaptLecture(lectureBlock, reloadRollCall, 2, id);
    dbInstance.commitAndCloseSession();
    // check absence
    Assert.assertEquals(2, adaptedCall.getLecturesAbsentNumber());
    List<Integer> absenceList = adaptedCall.getLecturesAbsentList();
    Assert.assertNotNull(absenceList);
    Assert.assertEquals(2, absenceList.size());
    Assert.assertEquals(0, absenceList.get(0).intValue());
    Assert.assertEquals(1, absenceList.get(1).intValue());
    // check attendee
    Assert.assertEquals(0, reloadRollCall.getLecturesAttendedNumber());
    List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
    Assert.assertNotNull(attendeeList);
    Assert.assertEquals(0, attendeeList.size());
}
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 32 with LectureBlockRollCall

use of org.olat.modules.lecture.LectureBlockRollCall in project OpenOLAT by OpenOLAT.

the class LectureBlockRollCallDAOTest method createAndLoadRollCall.

@Test
public void createAndLoadRollCall() {
    LectureBlock lectureBlock = createMinimalLectureBlock(2);
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
    dbInstance.commitAndCloseSession();
    LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, null);
    dbInstance.commitAndCloseSession();
    LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
    Assert.assertNotNull(reloadRollCall);
    Assert.assertNotNull(reloadRollCall.getKey());
    Assert.assertNotNull(reloadRollCall.getCreationDate());
    Assert.assertNotNull(reloadRollCall.getLastModified());
    Assert.assertEquals(rollCall, reloadRollCall);
    Assert.assertEquals(lectureBlock, reloadRollCall.getLectureBlock());
    Assert.assertEquals(id, reloadRollCall.getIdentity());
}
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 33 with LectureBlockRollCall

use of org.olat.modules.lecture.LectureBlockRollCall in project OpenOLAT by OpenOLAT.

the class LecturesBlockRollCallTest method getRollCallByKey.

@Test
public void getRollCallByKey() 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();
    // GET REST call
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("lectures").path("rollcalls").path(rollCall.getKey().toString()).build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    LectureBlockRollCallVO rollCallVo = conn.parse(response, LectureBlockRollCallVO.class);
    Assert.assertNotNull(rollCallVo);
    Assert.assertEquals(rollCall.getKey(), rollCallVo.getKey());
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCallVO(org.olat.modules.lecture.restapi.LectureBlockRollCallVO) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 34 with LectureBlockRollCall

use of org.olat.modules.lecture.LectureBlockRollCall in project OpenOLAT by OpenOLAT.

the class LecturesBlockPDFExport method getRows.

private Row[] getRows(List<Identity> rows, List<LectureBlockRollCall> rollCalls) {
    int numOfRows = rows.size();
    Map<Identity, LectureBlockRollCall> rollCallMap = new HashMap<>();
    for (LectureBlockRollCall rollCall : rollCalls) {
        rollCallMap.put(rollCall.getIdentity(), rollCall);
    }
    Row[] content = new Row[numOfRows];
    for (int i = 0; i < numOfRows; i++) {
        Identity row = rows.get(i);
        String fullname = getName(row);
        String comment = null;
        boolean authorised = false;
        boolean[] absences = new boolean[numOfLectures];
        Arrays.fill(absences, false);
        LectureBlockRollCall rollCall = rollCallMap.get(rows.get(i));
        if (rollCall != null) {
            if (rollCall.getLecturesAbsentList() != null) {
                List<Integer> absenceList = rollCall.getLecturesAbsentList();
                for (int j = 0; j < numOfLectures; j++) {
                    absences[j] = absenceList.contains(new Integer(j));
                }
            }
            if (rollCall.getAbsenceAuthorized() != null) {
                authorised = rollCall.getAbsenceAuthorized().booleanValue();
            }
            if (StringHelper.containsNonWhitespace(rollCall.getComment())) {
                comment = rollCall.getComment();
            }
        }
        content[i] = new Row(fullname, absences, authorised, comment);
    }
    return content;
}
Also used : HashMap(java.util.HashMap) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) Identity(org.olat.core.id.Identity)

Example 35 with LectureBlockRollCall

use of org.olat.modules.lecture.LectureBlockRollCall in project OpenOLAT by OpenOLAT.

the class LectureServiceImpl method adaptAll.

@Override
public void adaptAll(Identity author) {
    List<LectureBlock> lectureBlocks = lectureBlockDao.getLectureBlocks();
    for (LectureBlock lectureBlock : lectureBlocks) {
        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, author);
        }
        dbInstance.commitAndCloseSession();
    }
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall)

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