Search in sources :

Example 26 with LectureBlock

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

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

the class LecturesBlockRollCallTest method createMinimalLectureBlock.

private LectureBlock createMinimalLectureBlock(int numOfLectures) {
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    LectureBlock lectureBlock = lectureBlockDao.createLectureBlock(entry);
    lectureBlock.setStartDate(new Date());
    lectureBlock.setEndDate(new Date());
    lectureBlock.setTitle("Hello REST lecturers");
    lectureBlock.setPlannedLecturesNumber(numOfLectures);
    lectureBlock.setEffectiveLecturesNumber(numOfLectures);
    return lectureBlockDao.update(lectureBlock);
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date)

Example 28 with LectureBlock

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

the class LecturesBlocksTest method putLecturesBlock_autoclosed.

/**
 * Check that the done and autoclosed status are set.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void putLecturesBlock_autoclosed() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence", "Course with absence", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    String externalId = UUID.randomUUID().toString();
    LectureBlockVO lectureBlockVo = new LectureBlockVO();
    lectureBlockVo.setTitle("A block to close");
    lectureBlockVo.setDescription("A description");
    lectureBlockVo.setManagedFlagsString("all");
    lectureBlockVo.setPlannedLectures(4);
    lectureBlockVo.setExternalId(externalId);
    lectureBlockVo.setStartDate(new Date());
    lectureBlockVo.setEndDate(new Date());
    lectureBlockVo.setStatus("done");
    lectureBlockVo.setRollCallStatus("autoclosed");
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, lectureBlockVo);
    HttpResponse response = conn.execute(method);
    // check the response
    Assertions.assertThat(response.getStatusLine().getStatusCode()).isIn(200, 201);
    LectureBlockVO blockVo = conn.parse(response.getEntity().getContent(), LectureBlockVO.class);
    Assert.assertNotNull(blockVo);
    // check the database
    LectureBlock dbBlock = lectureService.getLectureBlock(new LectureBlockRefImpl(blockVo.getKey()));
    Assert.assertNotNull(dbBlock);
    Assert.assertEquals("A block to close", dbBlock.getTitle());
    Assert.assertEquals("A description", dbBlock.getDescription());
    Assert.assertEquals("all", dbBlock.getManagedFlagsString());
    Assert.assertEquals(4, dbBlock.getPlannedLecturesNumber());
    Assert.assertEquals(externalId, dbBlock.getExternalId());
    Assert.assertNotNull(dbBlock.getStartDate());
    Assert.assertNotNull(dbBlock.getEndDate());
    Assert.assertEquals(LectureBlockStatus.done, dbBlock.getStatus());
    Assert.assertEquals(LectureRollCallStatus.autoclosed, dbBlock.getRollCallStatus());
}
Also used : LectureBlockVO(org.olat.modules.lecture.restapi.LectureBlockVO) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) Date(java.util.Date) HttpPut(org.apache.http.client.methods.HttpPut) CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRefImpl(org.olat.modules.lecture.model.LectureBlockRefImpl) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 29 with LectureBlock

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

the class LecturesBlocksTest method deleteLectureBlock.

@Test
public void deleteLectureBlock() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence config", "Course with absence configuration", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    LectureBlock block = createLectureBlock(entry);
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").path(block.getKey().toString()).build();
    HttpDelete method = conn.createDelete(uri, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    // check the response
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    LectureBlock deletedBlock = lectureService.getLectureBlock(block);
    Assert.assertNull(deletedBlock);
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 30 with LectureBlock

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

the class LecturesBlocksTest method getLecturesBlock_course.

/**
 * Get the list of lecture block through the course.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void getLecturesBlock_course() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence", "Course with absence", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    LectureBlock block = createLectureBlock(entry);
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course.getResourceableId().toString()).path("lectureblocks").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    List<LectureBlockVO> voList = parseLectureBlockArray(response.getEntity().getContent());
    Assert.assertNotNull(voList);
    Assert.assertEquals(1, voList.size());
    LectureBlockVO blockVo = voList.get(0);
    Assert.assertEquals(block.getKey(), blockVo.getKey());
    Assert.assertEquals(entry.getKey(), blockVo.getRepoEntryKey());
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) HttpGet(org.apache.http.client.methods.HttpGet) LectureBlockVO(org.olat.modules.lecture.restapi.LectureBlockVO) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Aggregations

LectureBlock (org.olat.modules.lecture.LectureBlock)232 Identity (org.olat.core.id.Identity)132 Test (org.junit.Test)116 RepositoryEntry (org.olat.repository.RepositoryEntry)98 Date (java.util.Date)64 LectureBlockRollCall (org.olat.modules.lecture.LectureBlockRollCall)42 URI (java.net.URI)30 ArrayList (java.util.ArrayList)30 HttpResponse (org.apache.http.HttpResponse)30 Group (org.olat.basesecurity.Group)30 Calendar (java.util.Calendar)26 ICourse (org.olat.course.ICourse)24 BusinessGroup (org.olat.group.BusinessGroup)24 CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)24 LectureBlockToGroup (org.olat.modules.lecture.LectureBlockToGroup)22 RepositoryEntryLectureConfiguration (org.olat.modules.lecture.RepositoryEntryLectureConfiguration)20 LecturesBlockSearchParameters (org.olat.modules.lecture.model.LecturesBlockSearchParameters)16 List (java.util.List)14 HttpGet (org.apache.http.client.methods.HttpGet)14 LectureBlockToTeacher (org.olat.modules.lecture.model.LectureBlockToTeacher)14