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