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