Search in sources :

Example 56 with LectureBlockRollCall

use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.

the class LectureBlockRollCallDAOTest method createAndPersistRollCall.

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

use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.

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 58 with LectureBlockRollCall

use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.

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 59 with LectureBlockRollCall

use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.

the class LecturesBlockRollCallTest method getRollCalls_searchParams_True.

@Test
public void getRollCalls_searchParams_True() throws IOException, URISyntaxException {
    // an open lecture block
    LectureBlock openLectureBlock = createMinimalLectureBlock(3);
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-2");
    dbInstance.commitAndCloseSession();
    // a closed lecture block
    LectureBlock closedLectureBlock = createMinimalLectureBlock(3);
    dbInstance.commitAndCloseSession();
    closedLectureBlock.setStatus(LectureBlockStatus.done);
    closedLectureBlock.setRollCallStatus(LectureRollCallStatus.closed);
    lectureBlockDao.update(closedLectureBlock);
    List<Integer> absences = Arrays.asList(1, 2);
    LectureBlockRollCall rollCall1 = lectureBlockRollCallDao.createAndPersistRollCall(closedLectureBlock, id1, null, null, null, Collections.emptyList());
    LectureBlockRollCall rollCall2 = lectureBlockRollCallDao.createAndPersistRollCall(closedLectureBlock, id2, null, null, null, absences);
    LectureBlockRollCall rollCall3 = lectureBlockRollCallDao.createAndPersistRollCall(openLectureBlock, id1, null, null, null, absences);
    LectureBlockRollCall rollCall4 = lectureBlockRollCallDao.createAndPersistRollCall(openLectureBlock, id2, null, null, null, Collections.emptyList());
    dbInstance.commit();
    rollCall2.setAbsenceSupervisorNotificationDate(new Date());
    rollCall2 = lectureBlockRollCallDao.update(rollCall2);
    dbInstance.commitAndCloseSession();
    // REST call
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("lectures").path("rollcalls").queryParam("hasAbsences", "true").queryParam("closed", "true").queryParam("hasSupervisorNotificationDate", "true").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    List<LectureBlockRollCallVO> voList = parseLectureBlockRollCallArray(response.getEntity().getContent());
    Assert.assertNotNull(voList);
    // check the return values
    List<Long> rollCallVoKeys = voList.stream().map(vo -> vo.getKey()).collect(Collectors.toList());
    Assert.assertFalse(rollCallVoKeys.contains(rollCall1.getKey()));
    Assert.assertTrue(rollCallVoKeys.contains(rollCall2.getKey()));
    Assert.assertFalse(rollCallVoKeys.contains(rollCall3.getKey()));
    Assert.assertFalse(rollCallVoKeys.contains(rollCall4.getKey()));
    // check that roll call 2 has a date
    boolean found = false;
    for (LectureBlockRollCallVO vo : voList) {
        if (vo.getKey().equals(rollCall2.getKey()) && vo.getAbsenceSupervisorNotificationDate() != null) {
            found = true;
        }
    }
    Assert.assertTrue(found);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Arrays(java.util.Arrays) LectureBlockRollCallSearchParameters(org.olat.modules.lecture.LectureBlockRollCallSearchParameters) Date(java.util.Date) LectureBlockDAO(org.olat.modules.lecture.manager.LectureBlockDAO) URISyntaxException(java.net.URISyntaxException) Autowired(org.springframework.beans.factory.annotation.Autowired) RepositoryEntry(org.olat.repository.RepositoryEntry) MediaType(javax.ws.rs.core.MediaType) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) LectureBlockStatus(org.olat.modules.lecture.LectureBlockStatus) LectureBlock(org.olat.modules.lecture.LectureBlock) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) JunitTestHelper(org.olat.test.JunitTestHelper) List(java.util.List) LectureBlockRollCallVO(org.olat.modules.lecture.restapi.LectureBlockRollCallVO) HttpGet(org.apache.http.client.methods.HttpGet) DB(org.olat.core.commons.persistence.DB) TypeReference(org.codehaus.jackson.type.TypeReference) Identity(org.olat.core.id.Identity) LectureBlockRollCallDAO(org.olat.modules.lecture.manager.LectureBlockRollCallDAO) HttpResponse(org.apache.http.HttpResponse) Assert(org.junit.Assert) LectureRollCallStatus(org.olat.modules.lecture.LectureRollCallStatus) Collections(java.util.Collections) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) InputStream(java.io.InputStream) OlatJerseyTestCase(org.olat.test.OlatJerseyTestCase) LectureBlockRollCallVO(org.olat.modules.lecture.restapi.LectureBlockRollCallVO) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Date(java.util.Date) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 60 with LectureBlockRollCall

use of org.olat.modules.lecture.LectureBlockRollCall in project openolat by klemens.

the class LectureBlockExport method addContent.

private void addContent(OpenXMLWorksheet exportSheet) {
    List<Identity> participants = lectureService.getParticipants(lectureBlock);
    List<LectureBlockRollCall> rollCalls = lectureService.getRollCalls(lectureBlock);
    Map<Identity, LectureBlockRollCall> participantToRollCallMap = rollCalls.stream().collect(Collectors.toMap(r -> r.getIdentity(), r -> r));
    for (Identity participant : participants) {
        Row row = exportSheet.newRow();
        int pos = 0;
        if (isAdministrativeUser) {
            row.addCell(pos++, participant.getName());
        }
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            if (userPropertyHandler == null)
                continue;
            String val = userPropertyHandler.getUserProperty(participant.getUser(), translator.getLocale());
            row.addCell(pos++, val);
        }
        LectureBlockRollCall rollCall = participantToRollCallMap.get(participant);
        if (rollCall != null) {
            List<Integer> absentList = rollCall.getLecturesAbsentList();
            for (int i = 0; i < lectureBlock.getPlannedLecturesNumber(); i++) {
                String val = absentList.contains(i) ? "x" : null;
                row.addCell(pos++, val);
            }
            if (authorizedAbsenceEnabled && rollCall.getAbsenceAuthorized() != null && rollCall.getAbsenceAuthorized().booleanValue()) {
                row.addCell(pos++, "x");
                row.addCell(pos++, rollCall.getAbsenceReason());
            }
        }
    }
}
Also used : OutputStream(java.io.OutputStream) Formatter(org.olat.core.util.Formatter) Translator(org.olat.core.gui.translator.Translator) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) LectureBlock(org.olat.modules.lecture.LectureBlock) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) Date(java.util.Date) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) CoreSpringFactory(org.olat.core.CoreSpringFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) UserManager(org.olat.user.UserManager) LectureService(org.olat.modules.lecture.LectureService) List(java.util.List) ParticipantListRepositoryController(org.olat.modules.lecture.ui.ParticipantListRepositoryController) Identity(org.olat.core.id.Identity) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Map(java.util.Map) StringHelper(org.olat.core.util.StringHelper) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) OLog(org.olat.core.logging.OLog) Tracing(org.olat.core.logging.Tracing) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

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