use of org.olat.modules.lecture.LectureBlockToGroup in project OpenOLAT by OpenOLAT.
the class LectureServiceImpl method save.
@Override
public LectureBlock save(LectureBlock lectureBlock, List<Group> groups) {
LectureBlockImpl block = (LectureBlockImpl) lectureBlockDao.update(lectureBlock);
if (groups != null) {
List<LectureBlockToGroup> lectureToGroups = lectureBlockToGroupDao.getLectureBlockToGroups(block);
for (Group group : groups) {
boolean found = false;
for (LectureBlockToGroup lectureToGroup : lectureToGroups) {
if (lectureToGroup.getGroup().equals(group)) {
found = true;
break;
}
}
if (!found) {
LectureBlockToGroup blockToGroup = lectureBlockToGroupDao.createAndPersist(block, group);
lectureToGroups.add(blockToGroup);
}
}
for (Iterator<LectureBlockToGroup> lectureToGroupIt = lectureToGroups.iterator(); lectureToGroupIt.hasNext(); ) {
LectureBlockToGroup lectureBlockToGroup = lectureToGroupIt.next();
if (!groups.contains(lectureBlockToGroup.getGroup())) {
lectureBlockToGroupDao.remove(lectureBlockToGroup);
}
}
}
block.getTeacherGroup().getKey();
return block;
}
use of org.olat.modules.lecture.LectureBlockToGroup in project OpenOLAT by OpenOLAT.
the class LectureBlockDAOTest method addGroup.
@Test
public void addGroup() {
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
LectureBlock lectureBlock = lectureBlockDao.createLectureBlock(entry);
lectureBlock.setStartDate(new Date());
lectureBlock.setEndDate(new Date());
lectureBlock.setTitle("Hello lecturers");
lectureBlock = lectureBlockDao.update(lectureBlock);
dbInstance.commitAndCloseSession();
Group defGroup = repositoryEntryRelationDao.getDefaultGroup(entry);
lectureBlockDao.addGroupToLectureBlock(lectureBlock, defGroup);
dbInstance.commitAndCloseSession();
LectureBlockImpl reloadedLectureBlock = (LectureBlockImpl) lectureBlockDao.loadByKey(lectureBlock.getKey());
Set<LectureBlockToGroup> blockToGroupSet = reloadedLectureBlock.getGroups();
Assert.assertNotNull(blockToGroupSet);
Assert.assertEquals(1, blockToGroupSet.size());
LectureBlockToGroupImpl defBlockToGroup = (LectureBlockToGroupImpl) blockToGroupSet.iterator().next();
Assert.assertEquals(defGroup, defBlockToGroup.getGroup());
Assert.assertEquals(lectureBlock, defBlockToGroup.getLectureBlock());
}
use of org.olat.modules.lecture.LectureBlockToGroup 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.LectureBlockToGroup in project openolat by klemens.
the class LectureBlockDAOTest method addGroup.
@Test
public void addGroup() {
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
LectureBlock lectureBlock = lectureBlockDao.createLectureBlock(entry);
lectureBlock.setStartDate(new Date());
lectureBlock.setEndDate(new Date());
lectureBlock.setTitle("Hello lecturers");
lectureBlock = lectureBlockDao.update(lectureBlock);
dbInstance.commitAndCloseSession();
Group defGroup = repositoryEntryRelationDao.getDefaultGroup(entry);
lectureBlockDao.addGroupToLectureBlock(lectureBlock, defGroup);
dbInstance.commitAndCloseSession();
LectureBlockImpl reloadedLectureBlock = (LectureBlockImpl) lectureBlockDao.loadByKey(lectureBlock.getKey());
Set<LectureBlockToGroup> blockToGroupSet = reloadedLectureBlock.getGroups();
Assert.assertNotNull(blockToGroupSet);
Assert.assertEquals(1, blockToGroupSet.size());
LectureBlockToGroupImpl defBlockToGroup = (LectureBlockToGroupImpl) blockToGroupSet.iterator().next();
Assert.assertEquals(defGroup, defBlockToGroup.getGroup());
Assert.assertEquals(lectureBlock, defBlockToGroup.getLectureBlock());
}
use of org.olat.modules.lecture.LectureBlockToGroup in project openolat by klemens.
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());
}
Aggregations