Search in sources :

Example 1 with LectureBlockRollCallSearchParameters

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

the class LectureBlockRollCallWebService method getRollCalls.

/**
 * Return a list lecture block roll call.
 *
 * @response.representation.200.qname {http://www.example.com}lectureBlockRollCallVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc A lecture block roll call
 * @response.representation.200.example {@link org.olat.modules.lecture.restapi.Examples#SAMPLE_LECTUREBLOCKROLLCALLVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param closed If true, the status of the block is done or the status of the roll call is closed or auto closed
 * @param hasAbsence If true, the roll call has an absence
 * @param hasSupervisorNotificationDate If true, the roll call has a supervisor notification date set
 * @param httpRequest  The HTTP request
 * @return The roll calls
 */
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getRollCalls(@QueryParam("closed") Boolean closed, @QueryParam("hasAbsence") Boolean hasAbsence, @QueryParam("hasSupervisorNotificationDate") Boolean hasSupervisorNotificationDate, @QueryParam("lectureBlockKey") Long lectureBlockKey, @Context HttpServletRequest httpRequest) {
    Roles roles = getRoles(httpRequest);
    if (!roles.isOLATAdmin()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    LectureService lectureService = CoreSpringFactory.getImpl(LectureService.class);
    LectureBlockRollCallSearchParameters searchParams = new LectureBlockRollCallSearchParameters();
    if (hasAbsence != null) {
        searchParams.setHasAbsence(hasAbsence);
    }
    if (hasSupervisorNotificationDate != null) {
        searchParams.setHasSupervisorNotificationDate(hasSupervisorNotificationDate);
    }
    if (closed != null) {
        searchParams.setClosed(closed);
    }
    if (lectureBlockKey != null) {
        searchParams.setLectureBlockKey(lectureBlockKey);
    }
    List<LectureBlockRollCall> rollCalls = lectureService.getRollCalls(searchParams);
    List<LectureBlockRollCallVO> voList = new ArrayList<>(rollCalls.size());
    for (LectureBlockRollCall rollCall : rollCalls) {
        voList.add(new LectureBlockRollCallVO(rollCall));
    }
    LectureBlockRollCallVO[] voes = voList.toArray(new LectureBlockRollCallVO[voList.size()]);
    return Response.ok(voes).build();
}
Also used : LectureBlockRollCallSearchParameters(org.olat.modules.lecture.LectureBlockRollCallSearchParameters) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) LectureService(org.olat.modules.lecture.LectureService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with LectureBlockRollCallSearchParameters

use of org.olat.modules.lecture.LectureBlockRollCallSearchParameters 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 3 with LectureBlockRollCallSearchParameters

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

the class LectureBlockRollCallDAOTest method getRollCalls_searchParams_True.

@Test
public void getRollCalls_searchParams_True() {
    // 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();
    {
        // only absences
        LectureBlockRollCallSearchParameters searchParams = new LectureBlockRollCallSearchParameters();
        searchParams.setHasAbsence(Boolean.TRUE);
        List<LectureBlockRollCall> rollCalls = lectureBlockRollCallDao.getRollCalls(searchParams);
        Assert.assertFalse(rollCalls.contains(rollCall1));
        Assert.assertTrue(rollCalls.contains(rollCall2));
        Assert.assertTrue(rollCalls.contains(rollCall3));
        Assert.assertFalse(rollCalls.contains(rollCall4));
    }
    {
        // only with supervisor date
        LectureBlockRollCallSearchParameters searchParams = new LectureBlockRollCallSearchParameters();
        searchParams.setHasSupervisorNotificationDate(Boolean.TRUE);
        List<LectureBlockRollCall> rollCalls = lectureBlockRollCallDao.getRollCalls(searchParams);
        Assert.assertFalse(rollCalls.contains(rollCall1));
        Assert.assertTrue(rollCalls.contains(rollCall2));
        Assert.assertFalse(rollCalls.contains(rollCall3));
        Assert.assertFalse(rollCalls.contains(rollCall4));
    }
    {
        // only closed
        LectureBlockRollCallSearchParameters searchParams = new LectureBlockRollCallSearchParameters();
        searchParams.setClosed(Boolean.TRUE);
        List<LectureBlockRollCall> rollCalls = lectureBlockRollCallDao.getRollCalls(searchParams);
        Assert.assertTrue(rollCalls.contains(rollCall1));
        Assert.assertTrue(rollCalls.contains(rollCall2));
        Assert.assertFalse(rollCalls.contains(rollCall3));
        Assert.assertFalse(rollCalls.contains(rollCall4));
    }
    {
        // only with supervisor date
        LectureBlockRollCallSearchParameters searchParams = new LectureBlockRollCallSearchParameters();
        searchParams.setClosed(Boolean.TRUE);
        searchParams.setHasAbsence(Boolean.TRUE);
        searchParams.setHasSupervisorNotificationDate(Boolean.TRUE);
        List<LectureBlockRollCall> rollCalls = lectureBlockRollCallDao.getRollCalls(searchParams);
        Assert.assertFalse(rollCalls.contains(rollCall1));
        Assert.assertTrue(rollCalls.contains(rollCall2));
        Assert.assertFalse(rollCalls.contains(rollCall3));
        Assert.assertFalse(rollCalls.contains(rollCall4));
    }
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCallSearchParameters(org.olat.modules.lecture.LectureBlockRollCallSearchParameters) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) List(java.util.List) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 4 with LectureBlockRollCallSearchParameters

use of org.olat.modules.lecture.LectureBlockRollCallSearchParameters 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 5 with LectureBlockRollCallSearchParameters

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

the class LectureBlockRollCallWebService method updateLectureBlockRollCall.

private Response updateLectureBlockRollCall(LectureBlockRollCallVO rollCallVo, HttpServletRequest httpRequest) {
    Roles roles = getRoles(httpRequest);
    if (!roles.isOLATAdmin()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    if (rollCallVo.getKey() == null) {
        return Response.serverError().status(Status.BAD_REQUEST).build();
    }
    LectureService lectureService = CoreSpringFactory.getImpl(LectureService.class);
    LectureBlockRollCallSearchParameters searchParams = new LectureBlockRollCallSearchParameters();
    searchParams.setRollCallKey(rollCallVo.getKey());
    List<LectureBlockRollCall> rollCalls = lectureService.getRollCalls(searchParams);
    if (rollCalls.size() == 1) {
        LectureBlockRollCall rollCall = rollCalls.get(0);
        rollCall.setAbsenceSupervisorNotificationDate(rollCallVo.getAbsenceSupervisorNotificationDate());
        if (rollCallVo.getAbsenceReason() != null) {
            rollCall.setAbsenceReason(rollCallVo.getAbsenceReason());
        }
        if (rollCallVo.getComment() != null) {
            rollCall.setComment(rollCallVo.getComment());
        }
        rollCall = lectureService.updateRollCall(rollCall);
        LectureBlockRollCallVO vo = new LectureBlockRollCallVO(rollCall);
        return Response.ok(vo).build();
    }
    return Response.serverError().status(Status.NOT_FOUND).build();
}
Also used : LectureBlockRollCallSearchParameters(org.olat.modules.lecture.LectureBlockRollCallSearchParameters) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) LectureService(org.olat.modules.lecture.LectureService)

Aggregations

LectureBlockRollCall (org.olat.modules.lecture.LectureBlockRollCall)12 LectureBlockRollCallSearchParameters (org.olat.modules.lecture.LectureBlockRollCallSearchParameters)12 Date (java.util.Date)6 Test (org.junit.Test)6 Identity (org.olat.core.id.Identity)6 Roles (org.olat.core.id.Roles)6 LectureBlock (org.olat.modules.lecture.LectureBlock)6 LectureService (org.olat.modules.lecture.LectureService)6 RestSecurityHelper.getRoles (org.olat.restapi.security.RestSecurityHelper.getRoles)6 List (java.util.List)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 HttpResponse (org.apache.http.HttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2 LectureBlockRollCallVO (org.olat.modules.lecture.restapi.LectureBlockRollCallVO)2