Search in sources :

Example 11 with BusinessGroupMembershipViewImpl

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

the class BusinessGroupDAOTest method getMembershipInfoInBusinessGroups.

@Test
public void getMembershipInfoInBusinessGroups() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("is-in-grp-" + UUID.randomUUID().toString());
    BusinessGroup group1 = businessGroupDao.createAndPersist(id, "is-in-grp-1", "is-in-grp-1-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "is-in-grp-2", "is-in-grp-2-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "is-in-grp-3", "is-in-grp-3-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.addRole(id, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id, group3, GroupRoles.waiting.name());
    dbInstance.commitAndCloseSession();
    List<Long> groupKeys = new ArrayList<Long>();
    groupKeys.add(group1.getKey());
    groupKeys.add(group2.getKey());
    groupKeys.add(group3.getKey());
    // check owner + attendee
    int countMembershipA = businessGroupDao.countMembershipInfoInBusinessGroups(id, groupKeys);
    Assert.assertEquals(3, countMembershipA);
    List<BusinessGroupMembershipViewImpl> memberships = businessGroupDao.getMembershipInfoInBusinessGroups(groupKeys, id);
    Assert.assertNotNull(memberships);
    Assert.assertEquals(3, memberships.size());
    int found = 0;
    for (BusinessGroupMembershipViewImpl membership : memberships) {
        Assert.assertNotNull(membership.getIdentityKey());
        Assert.assertNotNull(membership.getCreationDate());
        Assert.assertNotNull(membership.getLastModified());
        if (membership.getGroupKey() != null && group1.getKey().equals(membership.getGroupKey())) {
            found++;
        }
        if (membership.getGroupKey() != null && group2.getKey().equals(membership.getGroupKey())) {
            found++;
        }
        if (membership.getGroupKey() != null && group3.getKey().equals(membership.getGroupKey())) {
            found++;
        }
    }
    Assert.assertEquals(3, found);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BusinessGroupMembershipViewImpl(org.olat.group.model.BusinessGroupMembershipViewImpl) Test(org.junit.Test)

Example 12 with BusinessGroupMembershipViewImpl

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

the class BusinessGroupDAO method getMembershipInfoInBusinessGroups.

public List<BusinessGroupMembershipViewImpl> getMembershipInfoInBusinessGroups(Collection<Long> groupKeys, Identity... identity) {
    StringBuilder sb = new StringBuilder();
    sb.append("select membership from bgmembershipview as membership ");
    boolean and = false;
    if (identity != null && identity.length > 0) {
        and = and(sb, and);
        sb.append("membership.identityKey in (:identIds) ");
    }
    if (groupKeys != null && !groupKeys.isEmpty()) {
        and = and(sb, and);
        sb.append("membership.groupKey in (:groupKeys)");
    }
    TypedQuery<BusinessGroupMembershipViewImpl> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BusinessGroupMembershipViewImpl.class);
    if (identity != null && identity.length > 0) {
        List<Long> ids = new ArrayList<Long>(identity.length);
        for (Identity id : identity) {
            ids.add(id.getKey());
        }
        query.setParameter("identIds", ids);
    }
    if (groupKeys != null && !groupKeys.isEmpty()) {
        query.setParameter("groupKeys", groupKeys);
    }
    List<BusinessGroupMembershipViewImpl> res = query.getResultList();
    return res;
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BusinessGroupMembershipViewImpl(org.olat.group.model.BusinessGroupMembershipViewImpl)

Aggregations

BusinessGroupMembershipViewImpl (org.olat.group.model.BusinessGroupMembershipViewImpl)12 ArrayList (java.util.ArrayList)10 Identity (org.olat.core.id.Identity)10 BusinessGroup (org.olat.group.BusinessGroup)6 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 BusinessGroupMembershipImpl (org.olat.group.model.BusinessGroupMembershipImpl)2 IdentityGroupKey (org.olat.group.model.IdentityGroupKey)2 BusinessGroupModifiedEvent (org.olat.group.ui.edit.BusinessGroupModifiedEvent)2 RepositoryEntryRef (org.olat.repository.RepositoryEntryRef)2 OLATResource (org.olat.resource.OLATResource)2 ResourceReservation (org.olat.resource.accesscontrol.ResourceReservation)2