Search in sources :

Example 11 with LectureBlockImpl

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

the class LectureServiceTest method deleteBusinessGroupWithLectures.

@Test
public void deleteBusinessGroupWithLectures() {
    // prepare a course with a business group
    Identity coachGroup = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-grp");
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    // add business group
    BusinessGroup group = businessGroupService.createBusinessGroup(coachGroup, "For lectures", "tg", null, null, false, false, entry);
    businessGroupService.addResourceTo(group, entry);
    dbInstance.commit();
    // create a lecture block
    LectureBlock lectureBlock = lectureService.createLectureBlock(entry);
    lectureBlock.setStartDate(new Date());
    lectureBlock.setEndDate(new Date());
    lectureBlock.setTitle("Hello lecturers");
    lectureBlock.setPlannedLecturesNumber(4);
    List<Group> groups = new ArrayList<>();
    groups.add(group.getBaseGroup());
    Group defGroup = repositoryService.getDefaultGroup(entry);
    groups.add(defGroup);
    LectureBlock block = lectureService.save(lectureBlock, groups);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(block);
    // delete the group
    businessGroupService.deleteBusinessGroup(group);
    dbInstance.commitAndCloseSession();
    // retrieve lecture block
    List<LectureBlock> blocks = lectureService.getLectureBlocks(entry);
    Assert.assertNotNull(blocks);
    Assert.assertEquals(1, blocks.size());
    LectureBlock reloadedBlock = blocks.get(0);
    Assert.assertNotNull(reloadedBlock);
    // check that the group associate with the repository entry is there
    Set<LectureBlockToGroup> lectureBlockToGroups = ((LectureBlockImpl) reloadedBlock).getGroups();
    Assert.assertNotNull(lectureBlockToGroups);
    Assert.assertEquals(1, lectureBlockToGroups.size());
    LectureBlockToGroup lectureBlockToGroup = lectureBlockToGroups.iterator().next();
    Assert.assertEquals(defGroup, lectureBlockToGroup.getGroup());
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) Group(org.olat.basesecurity.Group) LectureBlockToGroup(org.olat.modules.lecture.LectureBlockToGroup) BusinessGroup(org.olat.group.BusinessGroup) LectureBlockToGroup(org.olat.modules.lecture.LectureBlockToGroup) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl) Date(java.util.Date) Test(org.junit.Test)

Example 12 with LectureBlockImpl

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

the class LectureServiceImpl method autoCloseRollCall.

@Override
public void autoCloseRollCall() {
    int period = lectureModule.getRollCallAutoClosePeriod();
    if (period > 0) {
        Date now = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(now);
        cal.add(Calendar.DATE, -period);
        Date endDate = cal.getTime();
        List<LectureBlockImpl> blocks = lectureBlockDao.loadOpenBlocksBefore(endDate);
        for (LectureBlockImpl block : blocks) {
            autoClose(block);
            dbInstance.commitAndCloseSession();
        }
    }
}
Also used : Calendar(java.util.Calendar) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl) Date(java.util.Date)

Example 13 with LectureBlockImpl

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

the class LectureServiceImpl method cancel.

@Override
public LectureBlock cancel(LectureBlock lectureBlock) {
    lectureBlock.setStatus(LectureBlockStatus.cancelled);
    lectureBlock.setRollCallStatus(LectureRollCallStatus.closed);
    lectureBlock.setEffectiveLecturesNumber(0);
    LectureBlockImpl block = (LectureBlockImpl) lectureBlockDao.update(lectureBlock);
    dbInstance.commit();
    recalculateSummary(block.getEntry());
    return block;
}
Also used : LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl)

Example 14 with LectureBlockImpl

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

the class LectureServiceImpl method removeTeacher.

@Override
public void removeTeacher(LectureBlock lectureBlock, Identity teacher) {
    LectureBlockImpl block = (LectureBlockImpl) lectureBlock;
    groupDao.removeMembership(block.getTeacherGroup(), teacher);
}
Also used : LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl)

Example 15 with LectureBlockImpl

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

the class LectureBlockDAO method update.

public LectureBlock update(LectureBlock block) {
    if (block.getKey() == null) {
        ((LectureBlockImpl) block).setTeacherGroup(groupDao.createGroup());
        dbInstance.getCurrentEntityManager().persist(block);
    } else {
        block.setLastModified(new Date());
        block = dbInstance.getCurrentEntityManager().merge(block);
    }
    return block;
}
Also used : LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl) Date(java.util.Date)

Aggregations

LectureBlockImpl (org.olat.modules.lecture.model.LectureBlockImpl)22 Date (java.util.Date)12 Group (org.olat.basesecurity.Group)8 BusinessGroup (org.olat.group.BusinessGroup)8 LectureBlockToGroup (org.olat.modules.lecture.LectureBlockToGroup)8 ArrayList (java.util.ArrayList)4 Calendar (java.util.Calendar)4 Test (org.junit.Test)4 Identity (org.olat.core.id.Identity)4 LectureBlock (org.olat.modules.lecture.LectureBlock)4 LectureBlockRollCall (org.olat.modules.lecture.LectureBlockRollCall)4 LectureBlockToGroupImpl (org.olat.modules.lecture.model.LectureBlockToGroupImpl)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 File (java.io.File)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2