Search in sources :

Example 11 with LecturesBlockSearchParameters

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

the class LectureBlocksRootWebService method searchLectureBlocks.

/**
 * Return the lecture blocks of the specified course or repository entry.
 * @response.representation.200.qname {http://www.example.com}lectureBlocksVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc An array of lecture blocks
 * @response.representation.200.example {@link org.olat.modules.lecture.restapi.Examples#SAMPLE_LECTUREBLOCKVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param httpRequest The HTTP request
 * @return The lecture blocks
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response searchLectureBlocks(@QueryParam("date") String date, @Context HttpServletRequest httpRequest) {
    Roles roles = getRoles(httpRequest);
    if (!roles.isOLATAdmin()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    LecturesBlockSearchParameters searchParams = new LecturesBlockSearchParameters();
    if (date != null) {
        Date d = parseDate(date, Locale.ENGLISH);
        Date startDate = CalendarUtils.removeTime(d);
        Date endDate = CalendarUtils.endOfDay(d);
        searchParams.setStartDate(startDate);
        searchParams.setEndDate(endDate);
    }
    List<LectureBlock> blockList = CoreSpringFactory.getImpl(LectureService.class).getLectureBlocks(searchParams);
    List<LectureBlockVO> voList = new ArrayList<>(blockList.size());
    for (LectureBlock block : blockList) {
        voList.add(new LectureBlockVO(block, block.getEntry().getKey()));
    }
    LectureBlockVO[] voes = voList.toArray(new LectureBlockVO[voList.size()]);
    return Response.ok(voes).build();
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LecturesBlockSearchParameters(org.olat.modules.lecture.model.LecturesBlockSearchParameters) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) LectureService(org.olat.modules.lecture.LectureService) Date(java.util.Date) RestSecurityHelper.parseDate(org.olat.restapi.security.RestSecurityHelper.parseDate) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with LecturesBlockSearchParameters

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

the class LectureBlockDAOTest method loadByTeachers_searchString.

@Test
public void loadByTeachers_searchString() {
    Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-1");
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    LectureBlock lectureBlock = createMinimalLectureBlock(entry);
    dbInstance.commitAndCloseSession();
    lectureService.addTeacher(lectureBlock, teacher);
    dbInstance.commitAndCloseSession();
    // search lectures with the string
    LecturesBlockSearchParameters searchParams = new LecturesBlockSearchParameters();
    searchParams.setSearchString("lecturers");
    List<LectureBlock> blocks = lectureBlockDao.loadByTeacher(teacher, searchParams);
    Assert.assertNotNull(blocks);
    Assert.assertEquals(1, blocks.size());
    Assert.assertEquals(lectureBlock, blocks.get(0));
    // search lectures with a string which is not available to this teacher
    LecturesBlockSearchParameters searchNegativeParams = new LecturesBlockSearchParameters();
    searchNegativeParams.setSearchString("goodbye");
    List<LectureBlock> negativeBlocks = lectureBlockDao.loadByTeacher(teacher, searchNegativeParams);
    Assert.assertNotNull(negativeBlocks);
    Assert.assertEquals(0, negativeBlocks.size());
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LecturesBlockSearchParameters(org.olat.modules.lecture.model.LecturesBlockSearchParameters) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 13 with LecturesBlockSearchParameters

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

the class LectureBlockDAOTest method loadByTeachers_endDate.

@Test
public void loadByTeachers_endDate() {
    Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-3");
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    LectureBlock lectureBlock = createMinimalLectureBlock(entry);
    dbInstance.commitAndCloseSession();
    lectureService.addTeacher(lectureBlock, teacher);
    dbInstance.commitAndCloseSession();
    // search lectures with the string
    LecturesBlockSearchParameters searchNowParams = new LecturesBlockSearchParameters();
    Calendar now = Calendar.getInstance();
    now.add(Calendar.DATE, -1);
    searchNowParams.setEndDate(now.getTime());
    List<LectureBlock> blocks = lectureBlockDao.loadByTeacher(teacher, searchNowParams);
    Assert.assertNotNull(blocks);
    Assert.assertEquals(0, blocks.size());
    // search in future
    LecturesBlockSearchParameters searchFutureParams = new LecturesBlockSearchParameters();
    now.add(Calendar.DATE, 2);
    searchFutureParams.setEndDate(now.getTime());
    List<LectureBlock> futureBlocks = lectureBlockDao.loadByTeacher(teacher, searchFutureParams);
    Assert.assertNotNull(futureBlocks);
    Assert.assertEquals(1, futureBlocks.size());
    Assert.assertEquals(lectureBlock, futureBlocks.get(0));
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LecturesBlockSearchParameters(org.olat.modules.lecture.model.LecturesBlockSearchParameters) Calendar(java.util.Calendar) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 14 with LecturesBlockSearchParameters

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

the class LectureBlocksRootWebService method searchLectureBlocks.

/**
 * Return the lecture blocks of the specified course or repository entry.
 * @response.representation.200.qname {http://www.example.com}lectureBlocksVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc An array of lecture blocks
 * @response.representation.200.example {@link org.olat.modules.lecture.restapi.Examples#SAMPLE_LECTUREBLOCKVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param httpRequest The HTTP request
 * @return The lecture blocks
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response searchLectureBlocks(@QueryParam("date") String date, @Context HttpServletRequest httpRequest) {
    Roles roles = getRoles(httpRequest);
    if (!roles.isOLATAdmin()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    LecturesBlockSearchParameters searchParams = new LecturesBlockSearchParameters();
    if (date != null) {
        Date d = parseDate(date, Locale.ENGLISH);
        Date startDate = CalendarUtils.removeTime(d);
        Date endDate = CalendarUtils.endOfDay(d);
        searchParams.setStartDate(startDate);
        searchParams.setEndDate(endDate);
    }
    List<LectureBlock> blockList = CoreSpringFactory.getImpl(LectureService.class).getLectureBlocks(searchParams);
    List<LectureBlockVO> voList = new ArrayList<>(blockList.size());
    for (LectureBlock block : blockList) {
        voList.add(new LectureBlockVO(block, block.getEntry().getKey()));
    }
    LectureBlockVO[] voes = voList.toArray(new LectureBlockVO[voList.size()]);
    return Response.ok(voes).build();
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LecturesBlockSearchParameters(org.olat.modules.lecture.model.LecturesBlockSearchParameters) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) LectureService(org.olat.modules.lecture.LectureService) Date(java.util.Date) RestSecurityHelper.parseDate(org.olat.restapi.security.RestSecurityHelper.parseDate) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

LecturesBlockSearchParameters (org.olat.modules.lecture.model.LecturesBlockSearchParameters)14 LectureBlock (org.olat.modules.lecture.LectureBlock)12 Test (org.junit.Test)10 Identity (org.olat.core.id.Identity)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 Calendar (java.util.Calendar)6 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Roles (org.olat.core.id.Roles)2 LectureService (org.olat.modules.lecture.LectureService)2 RestSecurityHelper.getRoles (org.olat.restapi.security.RestSecurityHelper.getRoles)2 RestSecurityHelper.parseDate (org.olat.restapi.security.RestSecurityHelper.parseDate)2