Search in sources :

Example 1 with LectureBlockToGroup

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;
}
Also used : Group(org.olat.basesecurity.Group) LectureBlockToGroup(org.olat.modules.lecture.LectureBlockToGroup) BusinessGroup(org.olat.group.BusinessGroup) LectureBlockToGroup(org.olat.modules.lecture.LectureBlockToGroup) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl)

Example 2 with LectureBlockToGroup

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());
}
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) LectureBlockToGroupImpl(org.olat.modules.lecture.model.LectureBlockToGroupImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl) Date(java.util.Date) Test(org.junit.Test)

Example 3 with LectureBlockToGroup

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());
}
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 4 with LectureBlockToGroup

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());
}
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) LectureBlockToGroupImpl(org.olat.modules.lecture.model.LectureBlockToGroupImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl) Date(java.util.Date) Test(org.junit.Test)

Example 5 with LectureBlockToGroup

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

Aggregations

Group (org.olat.basesecurity.Group)6 BusinessGroup (org.olat.group.BusinessGroup)6 LectureBlockToGroup (org.olat.modules.lecture.LectureBlockToGroup)6 LectureBlockImpl (org.olat.modules.lecture.model.LectureBlockImpl)6 Date (java.util.Date)4 Test (org.junit.Test)4 LectureBlock (org.olat.modules.lecture.LectureBlock)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 ArrayList (java.util.ArrayList)2 Identity (org.olat.core.id.Identity)2 LectureBlockToGroupImpl (org.olat.modules.lecture.model.LectureBlockToGroupImpl)2