Search in sources :

Example 21 with RepositoryEntryToGroupRelation

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

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 22 with RepositoryEntryToGroupRelation

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

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 23 with RepositoryEntryToGroupRelation

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

the class RepositoryEntryRelationDAOTest method removeRelation_byGroup.

@Test
public void removeRelation_byGroup() {
    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 by group", "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());
    Assert.assertEquals(2, numOfRelations);
    dbInstance.commitAndCloseSession();
    List<Group> groups = Collections.singletonList(group.getBaseGroup());
    List<RepositoryEntryToGroupRelation> relations = repositoryEntryRelationDao.getRelations(groups);
    Assert.assertEquals(0, relations.size());
}
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 24 with RepositoryEntryToGroupRelation

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

the class RepositoryEntryRelationDAO method removeRelations.

/**
 * This will remove all relations from the repository entry,
 * the default one too.
 *
 * @param re
 * @return
 */
public int removeRelations(RepositoryEntryRef re) {
    EntityManager em = dbInstance.getCurrentEntityManager();
    List<RepositoryEntryToGroupRelation> rels = em.createNamedQuery("relationByRepositoryEntry", RepositoryEntryToGroupRelation.class).setParameter("repoKey", re.getKey()).getResultList();
    for (RepositoryEntryToGroupRelation rel : rels) {
        em.remove(rel);
    }
    return rels.size();
}
Also used : EntityManager(javax.persistence.EntityManager) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

Example 25 with RepositoryEntryToGroupRelation

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

the class RepositoryEntryRelationDAO method removeRelation.

public int removeRelation(Group group) {
    EntityManager em = dbInstance.getCurrentEntityManager();
    List<RepositoryEntryToGroupRelation> rels = em.createNamedQuery("relationByGroup", RepositoryEntryToGroupRelation.class).setParameter("groupKey", group.getKey()).getResultList();
    int count = 0;
    for (RepositoryEntryToGroupRelation rel : rels) {
        if (!rel.isDefaultGroup()) {
            em.remove(rel);
            count++;
        }
    }
    return count;
}
Also used : EntityManager(javax.persistence.EntityManager) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

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