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());
}
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();
}
}
}
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;
}
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);
}
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;
}
Aggregations