Search in sources :

Example 6 with BGRepositoryEntryRelation

use of org.olat.group.model.BGRepositoryEntryRelation in project OpenOLAT by OpenOLAT.

the class GroupSearchController method doSearchGroups.

/**
 * Perform a search for the given search value in the search result providers
 * and clear any GUI errors that might be on the page
 *
 * @param searchValue
 * @param ureq
 */
private void doSearchGroups(String searchValue) {
    if (StringHelper.containsNonWhitespace(searchValue)) {
        SearchBusinessGroupParams param1s = new SearchBusinessGroupParams();
        param1s.setNameOrDesc(searchValue);
        Set<BusinessGroup> dedupGroups = new HashSet<>();
        List<BusinessGroup> group1s = businessGroupService.findBusinessGroups(param1s, null, 0, -1);
        filterGroups(group1s, dedupGroups);
        SearchBusinessGroupParams param2s = new SearchBusinessGroupParams();
        param2s.setCourseTitle(searchValue);
        List<BusinessGroup> group2s = businessGroupService.findBusinessGroups(param2s, null, 0, -1);
        filterGroups(group2s, dedupGroups);
        List<BusinessGroup> groups = new ArrayList<BusinessGroup>(group1s.size() + group2s.size());
        groups.addAll(group1s);
        groups.addAll(group2s);
        List<Long> groupKeysWithRelations = PersistenceHelper.toKeys(groups);
        List<BGRepositoryEntryRelation> resources = businessGroupService.findRelationToRepositoryEntries(groupKeysWithRelations, 0, -1);
        List<GroupWrapper> groupWrappers = new ArrayList<GroupWrapper>();
        for (BusinessGroup group : groups) {
            StringBuilder sb = new StringBuilder();
            for (BGRepositoryEntryRelation resource : resources) {
                if (resource.getGroupKey().equals(group.getKey())) {
                    if (sb.length() > 0)
                        sb.append(", ");
                    sb.append(resource.getRepositoryEntryDisplayName());
                }
            }
            GroupWrapper wrapper = new GroupWrapper(group, sb.toString());
            wrapper.setTutor(createSelection("tutor_" + group.getKey()));
            wrapper.setParticipant(createSelection("participant_" + group.getKey()));
            groupWrappers.add(wrapper);
        }
        table.reset();
        tableDataModel.setObjects(groupWrappers);
        errorComp.clearError();
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) BGRepositoryEntryRelation(org.olat.group.model.BGRepositoryEntryRelation) HashSet(java.util.HashSet)

Example 7 with BGRepositoryEntryRelation

use of org.olat.group.model.BGRepositoryEntryRelation in project OpenOLAT by OpenOLAT.

the class BusinessGroupMembershipProcessor method processIdentityRemoved.

private void processIdentityRemoved(Long groupKey, Long identityKey) {
    IdentityRef identityRef = new IdentityRefImpl(identityKey);
    BusinessGroupRef groupRef = new BusinessGroupRefImpl(groupKey);
    if (!businessGroupRelationDao.hasAnyRole(identityRef, groupRef)) {
        infoMessageManager.updateInfoMessagesOfIdentity(groupRef, identityRef);
        notificationsManager.unsubscribeAllForIdentityAndResId(identityRef, groupRef.getKey());
        List<BGRepositoryEntryRelation> relations = businessGroupRelationDao.findRelationToRepositoryEntries(Collections.singletonList(groupKey), 0, -1);
        for (BGRepositoryEntryRelation relation : relations) {
            Long repositoryEntryKey = relation.getRepositoryEntryKey();
            RepositoryEntryRef entryRef = new RepositoryEntryRefImpl(repositoryEntryKey);
            List<String> remaingRoles = repositoryEntryRelationDao.getRoles(identityRef, entryRef);
            if (remaingRoles.isEmpty()) {
                OLATResource resource = repositoryManager.lookupRepositoryEntryResource(entryRef.getKey());
                notificationsManager.unsubscribeAllForIdentityAndResId(identityRef, resource.getResourceableId());
            }
        }
    }
}
Also used : IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) BusinessGroupRef(org.olat.group.BusinessGroupRef) IdentityRef(org.olat.basesecurity.IdentityRef) RepositoryEntryRefImpl(org.olat.repository.model.RepositoryEntryRefImpl) OLATResource(org.olat.resource.OLATResource) BusinessGroupRefImpl(org.olat.group.model.BusinessGroupRefImpl) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef) BGRepositoryEntryRelation(org.olat.group.model.BGRepositoryEntryRelation)

Example 8 with BGRepositoryEntryRelation

use of org.olat.group.model.BGRepositoryEntryRelation in project openolat by klemens.

the class BusinessGroupRelationDAOTest method findRelationToRepositoryEntries.

@Test
public void findRelationToRepositoryEntries() {
    // create 3 entries and 1 group
    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re3 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupDao.createAndPersist(null, "rel-repo", "rel-repo-desc", 0, 10, true, false, false, false, false);
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.addRelationToResource(group, re1);
    businessGroupRelationDao.addRelationToResource(group, re2);
    businessGroupRelationDao.addRelationToResource(group, re3);
    dbInstance.commitAndCloseSession();
    // check with empty list of groups
    List<BGRepositoryEntryRelation> emptyRelations = businessGroupRelationDao.findRelationToRepositoryEntries(Collections.<Long>emptyList(), 0, -1);
    Assert.assertNotNull(emptyRelations);
    Assert.assertEquals(0, emptyRelations.size());
    // check with the group
    List<BGRepositoryEntryRelation> relations = businessGroupRelationDao.findRelationToRepositoryEntries(Collections.singletonList(group.getKey()), 0, -1);
    Assert.assertNotNull(relations);
    Assert.assertEquals(3, relations.size());
    int count = 0;
    for (BGRepositoryEntryRelation relation : relations) {
        if (relation.getRepositoryEntryKey().equals(re1.getKey()) || relation.getRepositoryEntryKey().equals(re2.getKey()) || relation.getRepositoryEntryKey().equals(re3.getKey())) {
            count++;
        }
    }
    Assert.assertEquals(3, count);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) BGRepositoryEntryRelation(org.olat.group.model.BGRepositoryEntryRelation) Test(org.junit.Test)

Aggregations

BGRepositoryEntryRelation (org.olat.group.model.BGRepositoryEntryRelation)8 ArrayList (java.util.ArrayList)4 BusinessGroup (org.olat.group.BusinessGroup)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Test (org.junit.Test)2 IdentityRef (org.olat.basesecurity.IdentityRef)2 IdentityRefImpl (org.olat.basesecurity.model.IdentityRefImpl)2 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)2 BusinessGroupRef (org.olat.group.BusinessGroupRef)2 BusinessGroupShort (org.olat.group.BusinessGroupShort)2 BusinessGroupRefImpl (org.olat.group.model.BusinessGroupRefImpl)2 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)2 RepositoryEntryRef (org.olat.repository.RepositoryEntryRef)2 RepositoryEntryMembership (org.olat.repository.model.RepositoryEntryMembership)2 RepositoryEntryRefImpl (org.olat.repository.model.RepositoryEntryRefImpl)2 OLATResource (org.olat.resource.OLATResource)2