Search in sources :

Example 16 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.

the class RepositoryEntryRelationDAOTest method removeRelation_specificOne.

@Test
public void removeRelation_specificOne() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-member-lc-" + UUID.randomUUID().toString());
    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "remove relation", "tg", null, null, false, false, re1);
    businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name());
    businessGroupService.addResourceTo(group, re2);
    dbInstance.commitAndCloseSession();
    int numOfRelations = repositoryEntryRelationDao.removeRelation(group.getBaseGroup(), re2);
    Assert.assertEquals(1, numOfRelations);
    dbInstance.commitAndCloseSession();
    List<Group> groups = Collections.singletonList(group.getBaseGroup());
    List<RepositoryEntryToGroupRelation> relations = repositoryEntryRelationDao.getRelations(groups);
    Assert.assertEquals(1, relations.size());
    RepositoryEntry relationRe1 = relations.get(0).getEntry();
    Assert.assertNotNull(relationRe1);
    Assert.assertEquals(re1, relationRe1);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation) Test(org.junit.Test)

Example 17 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.

the class RepositoryEntryRelationDAOTest method removeRelations_repositoryEntrySide.

@Test
public void removeRelations_repositoryEntrySide() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-member-lc-" + UUID.randomUUID().toString());
    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "remove all relations", "tg", null, null, false, false, re1);
    businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name());
    businessGroupService.addResourceTo(group, re2);
    dbInstance.commitAndCloseSession();
    int numOfRelations = repositoryEntryRelationDao.removeRelations(re2);
    // default relation + relation to group
    Assert.assertEquals(2, numOfRelations);
    dbInstance.commitAndCloseSession();
    List<Group> groups = Collections.singletonList(group.getBaseGroup());
    List<RepositoryEntryToGroupRelation> relations = repositoryEntryRelationDao.getRelations(groups);
    Assert.assertEquals(1, relations.size());
    RepositoryEntry relationRe1 = relations.get(0).getEntry();
    Assert.assertNotNull(relationRe1);
    Assert.assertEquals(re1, relationRe1);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation) Test(org.junit.Test)

Example 18 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.

the class RepositoryEntryRelationDAOTest method getRelations.

@Test
public void getRelations() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-member-lc-" + UUID.randomUUID().toString());
    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "get relations", "tg", null, null, false, false, re1);
    businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name());
    businessGroupService.addResourceTo(group, re2);
    dbInstance.commitAndCloseSession();
    // get the relations from the business group's base group to the 2 repository entries
    List<Group> groups = Collections.singletonList(group.getBaseGroup());
    List<RepositoryEntryToGroupRelation> relations = repositoryEntryRelationDao.getRelations(groups);
    Assert.assertNotNull(relations);
    Assert.assertEquals(2, relations.size());
    Assert.assertTrue(relations.get(0).getEntry().equals(re1) || relations.get(0).getEntry().equals(re2));
    Assert.assertTrue(relations.get(1).getEntry().equals(re1) || relations.get(1).getEntry().equals(re2));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation) Test(org.junit.Test)

Example 19 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.

the class BusinessGroupServiceImpl method addResourcesTo.

@Override
public void addResourcesTo(List<BusinessGroup> groups, List<RepositoryEntry> resources) {
    if (groups == null || groups.isEmpty())
        return;
    if (resources == null || resources.isEmpty())
        return;
    List<Group> baseGroupKeys = new ArrayList<Group>();
    for (BusinessGroup group : groups) {
        baseGroupKeys.add(group.getBaseGroup());
    }
    // check for duplicate entries
    List<RepositoryEntryToGroupRelation> relations = repositoryEntryRelationDao.getRelations(baseGroupKeys);
    for (BusinessGroup group : groups) {
        // reload the base group to prevent lazy loading exception
        Group baseGroup = businessGroupRelationDAO.getGroup(group);
        if (baseGroup == null) {
            continue;
        }
        for (RepositoryEntry re : resources) {
            boolean found = false;
            for (RepositoryEntryToGroupRelation relation : relations) {
                if (relation.getGroup().equals(baseGroup) && relation.getEntry().equals(re)) {
                    found = true;
                }
            }
            if (!found) {
                repositoryEntryRelationDao.createRelation(baseGroup, re);
            }
        }
    }
}
Also used : Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) BusinessGroup(org.olat.group.BusinessGroup) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

Example 20 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project openolat by klemens.

the class RepositoryEntryRelationDAOTest method getRelations.

@Test
public void getRelations() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-member-lc-" + UUID.randomUUID().toString());
    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "get relations", "tg", null, null, false, false, re1);
    businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name());
    businessGroupService.addResourceTo(group, re2);
    dbInstance.commitAndCloseSession();
    // get the relations from the business group's base group to the 2 repository entries
    List<Group> groups = Collections.singletonList(group.getBaseGroup());
    List<RepositoryEntryToGroupRelation> relations = repositoryEntryRelationDao.getRelations(groups);
    Assert.assertNotNull(relations);
    Assert.assertEquals(2, relations.size());
    Assert.assertTrue(relations.get(0).getEntry().equals(re1) || relations.get(0).getEntry().equals(re2));
    Assert.assertTrue(relations.get(1).getEntry().equals(re1) || relations.get(1).getEntry().equals(re2));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation) Test(org.junit.Test)

Aggregations

RepositoryEntryToGroupRelation (org.olat.repository.model.RepositoryEntryToGroupRelation)28 RepositoryEntry (org.olat.repository.RepositoryEntry)16 Group (org.olat.basesecurity.Group)12 Date (java.util.Date)10 BusinessGroup (org.olat.group.BusinessGroup)10 Test (org.junit.Test)8 Identity (org.olat.core.id.Identity)8 EntityManager (javax.persistence.EntityManager)6 Calendar (java.util.Calendar)4 GroupMembershipImpl (org.olat.basesecurity.model.GroupMembershipImpl)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 RepositoryEntryStatistics (org.olat.repository.model.RepositoryEntryStatistics)2