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