/**
* @see org.olat.group.context.BGContextManager#isIdentityInBGContext(org.olat.core.id.Identity,
* org.olat.group.context.BGContext, boolean, boolean)
*/
public boolean isIdentityInBGContext(Identity identity, BGContext bgContext, boolean asOwner, boolean asParticipant) {
DB db = DBFactory.getInstance();
StringBuilder q = new StringBuilder();
q.append(" select count(grp) from" + " org.olat.group.BusinessGroupImpl as grp,"
+ " org.olat.basesecurity.SecurityGroupMembershipImpl as secgmemb where grp.groupContext = :context" + " and ");
// restricting where clause for participants
String partRestr = "(grp.partipiciantGroup = secgmemb.securityGroup and secgmemb.identity = :id) ";
// restricting where clause for owners
String ownRestr = "(grp.ownerGroup = secgmemb.securityGroup and secgmemb.identity = :id)";
if (asParticipant && asOwner) {
q.append("(").append(partRestr).append(" or ").append(ownRestr).append(")");
} else if (asParticipant && !asOwner) {
q.append(partRestr);
} else if (!asParticipant && asOwner) {
q.append(ownRestr);
} else {
throw new AssertException("illegal arguments: at leas one of asOwner or asParticipant must be true");
}
DBQuery query = db.createQuery(q.toString());
query.setEntity("id", identity);
query.setEntity("context", bgContext);
query.setCacheable(true);
List result = query.list();