Search in sources :

Example 6 with LectureBlockRollCall

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

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

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

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

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

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

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

the class TeacherRollCallController method loadModel.

private void loadModel() {
    List<LectureBlockRollCall> rollCalls = lectureService.getRollCalls(lectureBlock);
    Map<Identity, LectureBlockRollCall> rollCallMap = new HashMap<>();
    for (LectureBlockRollCall rollCall : rollCalls) {
        rollCallMap.put(rollCall.getIdentity(), rollCall);
    }
    List<TeacherRollCallRow> rows = new ArrayList<>(participants.size());
    for (Identity participant : participants) {
        LectureBlockRollCall rollCall = rollCallMap.get(participant);
        rows.add(forgeRow(participant, rollCall));
    }
    tableModel.setObjects(rows);
    tableEl.reset(false, false, true);
}
Also used : HashMap(java.util.HashMap) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 10 with LectureBlockRollCall

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

the class TeacherRollCallController method doReason.

private void doReason(TeacherRollCallRow row, String reason) {
    LectureBlockRollCall rollCall = row.getRollCall();
    String before = lectureService.toAuditXml(rollCall);
    if (rollCall == null) {
        row.getAuthorizedAbsence().select(onKeys[0], true);
        rollCall = lectureService.getOrCreateRollCall(row.getIdentity(), lectureBlock, true, reason);
        lectureService.auditLog(LectureBlockAuditLog.Action.createRollCall, before, lectureService.toAuditXml(rollCall), reason, lectureBlock, rollCall, lectureBlock.getEntry(), row.getIdentity(), getIdentity());
    } else {
        rollCall.setAbsenceReason(reason);
        rollCall = lectureService.updateRollCall(rollCall);
        lectureService.auditLog(LectureBlockAuditLog.Action.updateRollCall, before, lectureService.toAuditXml(rollCall), reason, lectureBlock, rollCall, lectureBlock.getEntry(), row.getIdentity(), getIdentity());
    }
    row.setRollCall(rollCall);
}
Also used : 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