Search in sources :

Example 1 with LectureBlockRefImpl

use of org.olat.modules.lecture.model.LectureBlockRefImpl 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 2 with LectureBlockRefImpl

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

the class LecturesBlocksTest method putLecturesBlock_repository.

@Test
public void putLecturesBlock_repository() 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("New block");
    lectureBlockVo.setDescription("A little description");
    lectureBlockVo.setComment("A comment");
    lectureBlockVo.setLocation("The secret location");
    lectureBlockVo.setManagedFlagsString("all");
    lectureBlockVo.setPreparation("Lot of");
    lectureBlockVo.setPlannedLectures(4);
    lectureBlockVo.setExternalId(externalId);
    lectureBlockVo.setStartDate(new Date());
    lectureBlockVo.setEndDate(new Date());
    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);
    Assert.assertEquals(entry.getKey(), blockVo.getRepoEntryKey());
    Assert.assertEquals("New block", blockVo.getTitle());
    Assert.assertEquals("A little description", blockVo.getDescription());
    Assert.assertEquals("A comment", blockVo.getComment());
    Assert.assertEquals("The secret location", blockVo.getLocation());
    Assert.assertEquals("all", blockVo.getManagedFlagsString());
    Assert.assertEquals(4, blockVo.getPlannedLectures());
    Assert.assertEquals(externalId, blockVo.getExternalId());
    Assert.assertNotNull(blockVo.getStartDate());
    Assert.assertNotNull(blockVo.getEndDate());
    // check the database
    LectureBlock dbBlock = lectureService.getLectureBlock(new LectureBlockRefImpl(blockVo.getKey()));
    Assert.assertNotNull(dbBlock);
    Assert.assertEquals("New block", dbBlock.getTitle());
    Assert.assertEquals("A little description", dbBlock.getDescription());
    Assert.assertEquals("A comment", dbBlock.getComment());
    Assert.assertEquals("The secret location", dbBlock.getLocation());
    Assert.assertEquals("all", dbBlock.getManagedFlagsString());
    Assert.assertEquals(4, dbBlock.getPlannedLecturesNumber());
    Assert.assertEquals(externalId, dbBlock.getExternalId());
    Assert.assertNotNull(dbBlock.getStartDate());
    Assert.assertNotNull(dbBlock.getEndDate());
}
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 3 with LectureBlockRefImpl

use of org.olat.modules.lecture.model.LectureBlockRefImpl in project OpenOLAT by OpenOLAT.

the class LecturesBlocksTest method putLecturesBlock_repository.

@Test
public void putLecturesBlock_repository() 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("New block");
    lectureBlockVo.setDescription("A little description");
    lectureBlockVo.setComment("A comment");
    lectureBlockVo.setLocation("The secret location");
    lectureBlockVo.setManagedFlagsString("all");
    lectureBlockVo.setPreparation("Lot of");
    lectureBlockVo.setPlannedLectures(4);
    lectureBlockVo.setExternalId(externalId);
    lectureBlockVo.setStartDate(new Date());
    lectureBlockVo.setEndDate(new Date());
    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);
    Assert.assertEquals(entry.getKey(), blockVo.getRepoEntryKey());
    Assert.assertEquals("New block", blockVo.getTitle());
    Assert.assertEquals("A little description", blockVo.getDescription());
    Assert.assertEquals("A comment", blockVo.getComment());
    Assert.assertEquals("The secret location", blockVo.getLocation());
    Assert.assertEquals("all", blockVo.getManagedFlagsString());
    Assert.assertEquals(4, blockVo.getPlannedLectures());
    Assert.assertEquals(externalId, blockVo.getExternalId());
    Assert.assertNotNull(blockVo.getStartDate());
    Assert.assertNotNull(blockVo.getEndDate());
    // check the database
    LectureBlock dbBlock = lectureService.getLectureBlock(new LectureBlockRefImpl(blockVo.getKey()));
    Assert.assertNotNull(dbBlock);
    Assert.assertEquals("New block", dbBlock.getTitle());
    Assert.assertEquals("A little description", dbBlock.getDescription());
    Assert.assertEquals("A comment", dbBlock.getComment());
    Assert.assertEquals("The secret location", dbBlock.getLocation());
    Assert.assertEquals("all", dbBlock.getManagedFlagsString());
    Assert.assertEquals(4, dbBlock.getPlannedLecturesNumber());
    Assert.assertEquals(externalId, dbBlock.getExternalId());
    Assert.assertNotNull(dbBlock.getStartDate());
    Assert.assertNotNull(dbBlock.getEndDate());
}
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 4 with LectureBlockRefImpl

use of org.olat.modules.lecture.model.LectureBlockRefImpl in project OpenOLAT by OpenOLAT.

the class LectureBlocksWebService method getLectureBlockWebService.

/**
 * To get the web service for a specific lecture block.
 * @param lectureBlockKey The primary key of the lecture block
 * @param httpRequest The HTTP request
 * @return The web service for a single lecture block.
 */
@Path("{lectureBlockKey}")
public LectureBlockWebService getLectureBlockWebService(@PathParam("lectureBlockKey") Long lectureBlockKey, @Context HttpServletRequest httpRequest) {
    Roles roles = getRoles(httpRequest);
    if (!roles.isOLATAdmin()) {
        return null;
    }
    LectureBlock lectureBlock = lectureService.getLectureBlock(new LectureBlockRefImpl(lectureBlockKey));
    if (lectureBlock == null || !lectureBlock.getEntry().equals(entry)) {
        return null;
    }
    return new LectureBlockWebService(lectureBlock, entry, lectureService);
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRefImpl(org.olat.modules.lecture.model.LectureBlockRefImpl) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) Path(javax.ws.rs.Path)

Example 5 with LectureBlockRefImpl

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

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)

Aggregations

LectureBlock (org.olat.modules.lecture.LectureBlock)6 LectureBlockRefImpl (org.olat.modules.lecture.model.LectureBlockRefImpl)6 URI (java.net.URI)4 Date (java.util.Date)4 HttpResponse (org.apache.http.HttpResponse)4 HttpPut (org.apache.http.client.methods.HttpPut)4 Test (org.junit.Test)4 Identity (org.olat.core.id.Identity)4 ICourse (org.olat.course.ICourse)4 LectureBlockVO (org.olat.modules.lecture.restapi.LectureBlockVO)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)4 Path (javax.ws.rs.Path)2 Roles (org.olat.core.id.Roles)2 RestSecurityHelper.getRoles (org.olat.restapi.security.RestSecurityHelper.getRoles)2