Search in sources :

Example 61 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class RepositoryManagerTest method getLearningResourcesAsStudentWithGroups.

@Test
public void getLearningResourcesAsStudentWithGroups() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-stud-lb-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "studg", "tg", null, null, false, false, re);
    businessGroupRelationDao.addRole(id, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    List<RepositoryEntry> entries = repositoryManager.getLearningResourcesAsStudent(id, null, 0, -1);
    Assert.assertNotNull(entries);
    Assert.assertFalse(entries.isEmpty());
    Assert.assertTrue(entries.contains(re));
    Set<Long> duplicates = new HashSet<Long>();
    for (RepositoryEntry entry : entries) {
        Assert.assertTrue(duplicates.add(entry.getKey()));
        if (!entry.equals(re)) {
            Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS);
        }
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 62 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class RepositoryManagerTest method queryByTypeLimitAccess.

@Test
public void queryByTypeLimitAccess() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("qbtla-1-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry(true);
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "qbtla-1", "tg", null, null, false, false, re);
    businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    // check
    List<String> types = Collections.singletonList(re.getOlatResource().getResourceableTypeName());
    List<RepositoryEntry> entries = repositoryManager.queryByTypeLimitAccess(id, types, new Roles(false, false, false, false, false, false, false));
    Assert.assertNotNull(entries);
    Assert.assertFalse(entries.isEmpty());
    Assert.assertTrue(entries.contains(re));
    for (RepositoryEntry entry : entries) {
        if (!entry.equals(re)) {
            Assert.assertTrue(entry.getAccess() >= RepositoryEntry.ACC_USERS);
        }
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 63 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class RepositoryEntryMembershipProcessorTest method testRemoveCoach_withBusinessGroups.

@Test
public void testRemoveCoach_withBusinessGroups() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    // create a group with members
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
    repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(businessGroup, re);
    // create a publisher
    SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();
    // subscribe
    notificationManager.subscribe(owner, context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    notificationManager.subscribe(coach, context, publisherData);
    dbInstance.commitAndCloseSession();
    // remove member and coach as coach of the repo entry
    List<Identity> removeIdentities = new ArrayList<>(2);
    removeIdentities.add(member);
    removeIdentities.add(coach);
    repositoryManager.removeTutors(owner, removeIdentities, re, new MailPackage(false));
    // wait for the remove of subscription
    waitForCondition(new CheckUnsubscription(member, context, dbInstance, notificationManager), 5000);
    sleep(1000);
    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedMember = notificationManager.isSubscribed(member, context);
    Assert.assertFalse(subscribedMember);
    boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
    Assert.assertTrue(subscribedCoach);
    boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
    Assert.assertTrue(subscribedOwner);
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 64 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class RepositoryEntryRelationDAOTest method getMembers_follow.

@Test
public void getMembers_follow() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("member-1-");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("member-2-");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("member-3-");
    Identity id4 = JunitTestHelper.createAndPersistIdentityAsRndUser("member-4-");
    RepositoryEntry re1 = repositoryService.create("Rei Ayanami", "rel", "rel", null, null);
    RepositoryEntry re2 = repositoryService.create("Rei Ayanami (alt)", "rel", "rel", null, null);
    dbInstance.commit();
    repositoryEntryRelationDao.addRole(id1, re1, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(id2, re1, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(id3, re2, GroupRoles.participant.name());
    dbInstance.commit();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "group", "tg", null, null, true, false, re2);
    businessGroupRelationDao.addRole(id4, group, GroupRoles.coach.name());
    dbInstance.commit();
    List<RepositoryEntry> res = new ArrayList<>();
    res.add(re1);
    res.add(re2);
    // all members
    List<Identity> coaches = repositoryEntryRelationDao.getMembers(res, RepositoryEntryRelationType.both, GroupRoles.coach.name());
    Assert.assertNotNull(coaches);
    Assert.assertEquals(1, coaches.size());
    Assert.assertTrue(coaches.contains(id4));
    // participant
    List<Identity> participants = repositoryEntryRelationDao.getMembers(res, RepositoryEntryRelationType.defaultGroup, GroupRoles.participant.name());
    Assert.assertNotNull(participants);
    Assert.assertEquals(2, participants.size());
    Assert.assertTrue(participants.contains(id2));
    Assert.assertTrue(participants.contains(id3));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 65 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

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)

Aggregations

BusinessGroup (org.olat.group.BusinessGroup)1034 Test (org.junit.Test)536 Identity (org.olat.core.id.Identity)536 RepositoryEntry (org.olat.repository.RepositoryEntry)324 ArrayList (java.util.ArrayList)224 BusinessGroupService (org.olat.group.BusinessGroupService)116 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)84 BGArea (org.olat.group.area.BGArea)70 CollaborationTools (org.olat.collaboration.CollaborationTools)58 OLATResource (org.olat.resource.OLATResource)56 Date (java.util.Date)54 HashSet (java.util.HashSet)50 File (java.io.File)46 Path (javax.ws.rs.Path)42 Group (org.olat.basesecurity.Group)42 HashMap (java.util.HashMap)38 Roles (org.olat.core.id.Roles)38 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)38 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)38 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)38