From 8cb7ac3f59834133c403d8e6fae8765705896a99 Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Wed, 4 Jul 2012 13:54:33 +0200
Subject: [PATCH] OO-291:  enhance the main search function for groups, add
 search in waiting list, add search of public group, add unit tests

---
 .../SystemRegistrationManager.java            |   2 +-
 .../groups/GroupSearchResultProvider.java     |   2 +-
 .../PersistingCourseGroupManager.java         |  16 +--
 .../org/olat/group/BusinessGroupService.java  |   6 +-
 .../group/GroupfoldersWebDAVMergeSource.java  |  12 +-
 .../group/manager/BusinessGroupArchiver.java  |   2 +-
 .../olat/group/manager/BusinessGroupDAO.java  |  65 ++++++----
 .../manager/BusinessGroupServiceImpl.java     |  18 ++-
 .../model/SearchBusinessGroupParams.java      |  69 ++++++++++-
 .../group/ui/area/BGAreaEditController.java   |   2 +-
 .../olat/group/ui/main/BGMainController.java  |   8 +-
 .../group/ui/main/BGSearchController.java     |  39 ++++--
 .../ui/main/BusinessGroupListController.java  |  63 ++++++++--
 .../org/olat/group/ui/main/SearchEvent.java   |  11 +-
 .../ui/main/_i18n/LocalStrings_de.properties  |   1 +
 .../ui/management/BGManagementController.java |   4 +-
 .../portlet/GroupsPortletRunController.java   |   7 +-
 .../ui/wizard/MemberListWizardController.java |   2 +-
 .../org/olat/home/HomeCalendarController.java |  12 +-
 .../SmackInstantMessagingImpl.java            |   2 +-
 .../fo/restapi/MyForumsWebService.java        |   4 +-
 .../ui/structel/EPShareListController.java    |   4 +-
 .../controllers/RepositoryMainController.java |   4 +-
 .../resource/accesscontrol/ACUIFactory.java   |   3 +-
 .../manager/ACFrontendManager.java            |   3 +-
 .../manager/ACMethodManagerImpl.java          |   7 +-
 .../accesscontrol/ui/AccessController.java    |  34 ++++++
 .../ui/AccessListController.java              |  16 ++-
 .../group/LearningGroupWebService.java        |   4 +-
 .../olat/restapi/group/MyGroupWebService.java |  14 +--
 .../restapi/user/UserFoldersWebService.java   |   4 +-
 .../database/mysql/alter_8_1_x_to_8_2_0.sql   |   3 +
 .../olat/group/test/BusinessGroupDAOTest.java | 112 +++++++++++++++---
 .../test/BusinessGroupImportExportTest.java   |   8 +-
 .../test/BusinessGroupRelationDAOTest.java    |   9 +-
 .../group/test/BusinessGroupServiceTest.java  |  18 +--
 36 files changed, 440 insertions(+), 150 deletions(-)
 create mode 100644 src/main/java/org/olat/resource/accesscontrol/ui/AccessController.java

diff --git a/src/main/java/org/olat/admin/registration/SystemRegistrationManager.java b/src/main/java/org/olat/admin/registration/SystemRegistrationManager.java
index a4864764e14..fb96fb4d1de 100644
--- a/src/main/java/org/olat/admin/registration/SystemRegistrationManager.java
+++ b/src/main/java/org/olat/admin/registration/SystemRegistrationManager.java
@@ -304,7 +304,7 @@ public class SystemRegistrationManager extends BasicManager implements Initializ
 		
 		// Groups
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-		int groups = businessGroupService.countBusinessGroups(params, null, false, false, null);
+		int groups = businessGroupService.countBusinessGroups(params, null);
 		msgProperties.put("buddyGroups", String.valueOf(groups));
 		msgProperties.put("learningGroups", String.valueOf(groups));
 		msgProperties.put("rightGroups", String.valueOf(groups));
diff --git a/src/main/java/org/olat/admin/user/groups/GroupSearchResultProvider.java b/src/main/java/org/olat/admin/user/groups/GroupSearchResultProvider.java
index 03af2beaf0d..90f11943b20 100644
--- a/src/main/java/org/olat/admin/user/groups/GroupSearchResultProvider.java
+++ b/src/main/java/org/olat/admin/user/groups/GroupSearchResultProvider.java
@@ -108,7 +108,7 @@ public class GroupSearchResultProvider implements ResultMapProvider {
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.addTypes(typeFilter);
 		params.setNameOrDesc('%' + searchValue + '%');
-		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, null, false, false, null, 0, -1);
+		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, null, 0, -1);
 		for (BusinessGroup group : groups) {			
 			if (group.getOwnerGroup() != null && group.getPartipiciantGroup() != null) {
 				List<RepositoryEntry> repoEntries = businessGroupService.findRepositoryEntries(groups, 0, -1);
diff --git a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java
index 31750133046..193596e18a0 100644
--- a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java
+++ b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java
@@ -185,7 +185,7 @@ public class PersistingCourseGroupManager extends BasicManager implements Course
 	 */
 	public List<BusinessGroup> getAllLearningGroupsFromAllContexts() {
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-		return businessGroupService.findBusinessGroups(params, null, false, false, courseResource, 0, -1);
+		return businessGroupService.findBusinessGroups(params, courseResource, 0, -1);
 	}
 
 	/**
@@ -194,7 +194,7 @@ public class PersistingCourseGroupManager extends BasicManager implements Course
 	public List<BusinessGroup> getLearningGroupsFromAllContexts(String groupName) {
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setExactName(groupName);
-		return businessGroupService.findBusinessGroups(params, null, false, false, courseResource, 0, -1);
+		return businessGroupService.findBusinessGroups(params, courseResource, 0, -1);
 	}
 
 	/**
@@ -229,8 +229,8 @@ public class PersistingCourseGroupManager extends BasicManager implements Course
 	 *      java.lang.String)
 	 */
 	public List<BusinessGroup> getParticipatingLearningGroupsFromAllContexts(Identity identity, String groupName) {
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-		return businessGroupService.findBusinessGroups(params, identity, false, true, courseResource, 0, -1);
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, false, true);
+		return businessGroupService.findBusinessGroups(params, courseResource, 0, -1);
 	}
 
 	/**
@@ -247,9 +247,9 @@ public class PersistingCourseGroupManager extends BasicManager implements Course
 	 */
 	@Override
 	public List<BusinessGroup> getOwnedLearningGroupsFromAllContexts(Identity identity) {
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
 		List<BusinessGroup> allGroups =
-				businessGroupService.findBusinessGroups(params, identity, true, false, courseResource, 0, -1);
+				businessGroupService.findBusinessGroups(params, courseResource, 0, -1);
 		return allGroups;
 	}
 
@@ -258,9 +258,9 @@ public class PersistingCourseGroupManager extends BasicManager implements Course
 	 */
 	@Override
 	public List<BusinessGroup> getParticipatingLearningGroupsFromAllContexts(Identity identity) {
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, false, true);
 		List<BusinessGroup> allGroups =
-				businessGroupService.findBusinessGroups(params, identity, false, true, courseResource, 0, -1);
+				businessGroupService.findBusinessGroups(params, courseResource, 0, -1);
 		return allGroups;
 	}
 
diff --git a/src/main/java/org/olat/group/BusinessGroupService.java b/src/main/java/org/olat/group/BusinessGroupService.java
index 9c8fe2edf75..e00e8f76a82 100644
--- a/src/main/java/org/olat/group/BusinessGroupService.java
+++ b/src/main/java/org/olat/group/BusinessGroupService.java
@@ -248,11 +248,9 @@ public interface BusinessGroupService {
 	 */
 	public List<BusinessGroup> findBusinessGroupsWithWaitingListAttendedBy(Identity identity,OLATResource resource);
 	
-	public int countBusinessGroups(SearchBusinessGroupParams params, Identity identity,
-			boolean ownedById, boolean attendedById, OLATResource resource);
+	public int countBusinessGroups(SearchBusinessGroupParams params, OLATResource resource);
 	
-	public List<BusinessGroup> findBusinessGroups(SearchBusinessGroupParams params, Identity identity,
-			boolean ownedById, boolean attendedById, OLATResource resource, int firstResult, int maxResults);
+	public List<BusinessGroup> findBusinessGroups(SearchBusinessGroupParams params, OLATResource resource, int firstResult, int maxResults);
 	
 	//check
 	public boolean checkIfOneOrMoreNameExists(Set<String> names, OLATResource resource); 
diff --git a/src/main/java/org/olat/group/GroupfoldersWebDAVMergeSource.java b/src/main/java/org/olat/group/GroupfoldersWebDAVMergeSource.java
index 00bc4b6f170..4d2ffa2a3ff 100644
--- a/src/main/java/org/olat/group/GroupfoldersWebDAVMergeSource.java
+++ b/src/main/java/org/olat/group/GroupfoldersWebDAVMergeSource.java
@@ -116,10 +116,10 @@ class GroupfoldersWebDAVMergeSource extends MergeSource {
 		
 		String childName = VFSManager.extractChild(path);
 
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, true);
 		params.addTools(CollaborationTools.TOOL_FOLDER);
 		BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
-		List<BusinessGroup> groups = bgs.findBusinessGroups(params, identity, true, true, null, 0, -1);
+		List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
 		Set<String> addedGroupNames = new HashSet<String>();
 		for(BusinessGroup group:groups) {
 			String name = nameIdentifier(group, addedGroupNames);
@@ -146,13 +146,15 @@ class GroupfoldersWebDAVMergeSource extends MergeSource {
 		Set<Long> addedGroupKeys = new HashSet<Long>();
 		Set<String> addedGroupNames = new HashSet<String>();
 		
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
 		params.addTools(CollaborationTools.TOOL_FOLDER);
-		List<BusinessGroup> tutorGroups = bgs.findBusinessGroups(params, identity, true, false, null, 0, -1);
+		List<BusinessGroup> tutorGroups = bgs.findBusinessGroups(params, null, 0, -1);
 		for (BusinessGroup group : tutorGroups) {
 			addContainer(group, addedGroupKeys, addedGroupNames, true);
 		}
-		List<BusinessGroup> participantsGroups = bgs.findBusinessGroups(params, identity, false, true, null, 0, -1);
+
+		SearchBusinessGroupParams paramsParticipants = new SearchBusinessGroupParams(identity, false, true);
+		List<BusinessGroup> participantsGroups = bgs.findBusinessGroups(paramsParticipants, null, 0, -1);
 		for (BusinessGroup group : participantsGroups) {
 			addContainer(group, addedGroupKeys, addedGroupNames, false);
 		}
diff --git a/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java b/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java
index bdab7b06ba6..72b2ee7f972 100644
--- a/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java
+++ b/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java
@@ -309,7 +309,7 @@ public class BusinessGroupArchiver {
 		List<Member> participants = new ArrayList<Member>();
 		List<Member> waitings = new ArrayList<Member>();
 				
-		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, null, false, false, resource, 0, -1);
+		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
 		for (BusinessGroup group: groups) {
 			if (groupList.contains(group)) { //rely on the equals() method of the BusinessGroup impl			
 				if(group.getOwnerGroup()!=null) {
diff --git a/src/main/java/org/olat/group/manager/BusinessGroupDAO.java b/src/main/java/org/olat/group/manager/BusinessGroupDAO.java
index 51a5ffbdc5b..f6ff713dfe6 100644
--- a/src/main/java/org/olat/group/manager/BusinessGroupDAO.java
+++ b/src/main/java/org/olat/group/manager/BusinessGroupDAO.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import javax.persistence.EntityManager;
@@ -50,6 +51,7 @@ import org.olat.group.model.SearchBusinessGroupParams;
 import org.olat.properties.Property;
 import org.olat.resource.OLATResource;
 import org.olat.resource.OLATResourceManager;
+import org.olat.resource.accesscontrol.model.OfferImpl;
 import org.olat.user.UserImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -354,17 +356,15 @@ public class BusinessGroupDAO {
 		return groups;
 	}
 	
-	public int countBusinessGroups(SearchBusinessGroupParams params, Identity identity,
-			boolean ownedById, boolean attendedById, OLATResource resource) {
-		TypedQuery<Number> query = createFindDBQuery(params, identity, ownedById, attendedById, resource, Number.class);
+	public int countBusinessGroups(SearchBusinessGroupParams params, OLATResource resource) {
+		TypedQuery<Number> query = createFindDBQuery(params, resource, Number.class);
 
 		Number count = query.getSingleResult();
 		return count.intValue();
 	}
 	
-	public List<BusinessGroup> findBusinessGroups(SearchBusinessGroupParams params, Identity identity,
-			boolean ownedById, boolean attendedById, OLATResource resource, int firstResult, int maxResults) {
-		TypedQuery<BusinessGroup> query = createFindDBQuery(params, identity, ownedById, attendedById, resource, BusinessGroup.class);
+	public List<BusinessGroup> findBusinessGroups(SearchBusinessGroupParams params, OLATResource resource, int firstResult, int maxResults) {
+		TypedQuery<BusinessGroup> query = createFindDBQuery(params, resource, BusinessGroup.class);
 		query.setFirstResult(firstResult);
 		if(maxResults > 0) {
 			query.setMaxResults(maxResults);
@@ -373,8 +373,7 @@ public class BusinessGroupDAO {
 		return groups;
 	}
 	
-	private <T> TypedQuery<T> createFindDBQuery(SearchBusinessGroupParams params, Identity identity,
-			boolean ownedById, boolean attendedById, OLATResource resource, Class<T> resultClass) {
+	private <T> TypedQuery<T> createFindDBQuery(SearchBusinessGroupParams params, OLATResource resource, Class<T> resultClass) {
 		StringBuilder query = new StringBuilder();
 		if(BusinessGroup.class.equals(resultClass)) {
 			query.append("select distinct(bgi) from ");
@@ -383,7 +382,7 @@ public class BusinessGroupDAO {
 		}
 		query.append(org.olat.group.BusinessGroupImpl.class.getName()).append(" as bgi ");
 
-		if(StringHelper.containsNonWhitespace(params.getOwner())) {
+		if(StringHelper.containsNonWhitespace(params.getOwnerName())) {
 			//implicit joins
 			query.append(", ").append(SecurityGroupMembershipImpl.class.getName()).append(" as sgmi ")
 				   .append(", ").append(IdentityImpl.class.getName()).append(" identity")
@@ -396,13 +395,14 @@ public class BusinessGroupDAO {
 			     .append("inner join fetch bgi.waitingGroup waitingGroup ")
 			     .append("inner join fetch bgi.resource bgResource ");
 		} else {
-			query.append("inner join bgi.ownerGroup ownerGroup ");
-			query.append("inner join bgi.partipiciantGroup participantGroup ");
-			query.append("inner join bgi.waitingGroup waitingGroup ");
+			query.append("inner join bgi.ownerGroup ownerGroup ")
+			     .append("inner join bgi.partipiciantGroup participantGroup ")
+			     .append("inner join bgi.waitingGroup waitingGroup ")
+	         .append("inner join bgi.resource bgResource ");
 		}
 
 		boolean where = false;
-		if(StringHelper.containsNonWhitespace(params.getOwner())) {
+		if(StringHelper.containsNonWhitespace(params.getOwnerName())) {
 			where = true;
 			query.append(" where ownerGroup = sgmi.securityGroup")
 				   .append(" and sgmi.identity = identity ")
@@ -434,23 +434,41 @@ public class BusinessGroupDAO {
 			query.append("bgi.type in (:types)");
 		}
 		
-		if(ownedById || attendedById) {
+		if(params.isOwner() || params.isAttendee() || params.isWaiting()) {
 			where = where(query, where);
+			boolean subOr = false;
 			query.append('(');
-			if(ownedById) {
+			if(params.isOwner()) {
+				subOr = or(query, subOr);
 				query.append("ownerGroup.key in (select ownerMemberShip.securityGroup.key from ").append(SecurityGroupMembershipImpl.class.getName()).append(" ownerMemberShip ")
 				     .append(" where ownerMemberShip.identity.key=:identId ")
 				     .append(")");
 			}
-			if(attendedById) {
-				if(ownedById) query.append(" or ");
+			if(params.isAttendee()) {
+				subOr = or(query, subOr);
 				query.append(" participantGroup.key in (select partMembership.securityGroup.key from ").append(SecurityGroupMembershipImpl.class.getName()).append(" as partMembership ")
 				     .append("  where partMembership.identity.key=:identId")
 				     .append(" )");
 			}
+			if(params.isWaiting()) {
+				subOr = or(query, subOr);
+				query.append(" waitingGroup.key in (select waitMembership.securityGroup.key from ").append(SecurityGroupMembershipImpl.class.getName()).append(" as waitMembership ")
+				     .append("  where waitMembership.identity.key=:identId")
+				     .append(" )");
+			}
 			query.append(')');
 		}
 		
+		if(params.isPublicGroup()) {
+			where = where(query, where);
+	    query.append(" bgResource.key in (")
+	         .append("   select offer.resource.key from ").append(OfferImpl.class.getName()).append(" offer ")
+	         .append("     where offer.valid=true")
+	         .append("     and (offer.validFrom is null or offer.validFrom<=:atDate)")
+					 .append("     and (offer.validTo is null or offer.validTo>=:atDate)")
+					 .append(" )");
+		}
+		
 		if(StringHelper.containsNonWhitespace(params.getNameOrDesc())) {
 			where = where(query, where);
 			query.append("(");
@@ -484,10 +502,15 @@ public class BusinessGroupDAO {
 			query.append(" order by bgi.name,bgi.key");
 		}
 		
+		System.out.println(query.toString());
+		
 		TypedQuery<T> dbq = dbInstance.getCurrentEntityManager().createQuery(query.toString(), resultClass);
 		//add parameters
-		if(ownedById || attendedById) {
-			dbq.setParameter("identId", identity.getKey().longValue());
+		if(params.isOwner() || params.isAttendee() || params.isWaiting()) {
+			dbq.setParameter("identId", params.getIdentity().getKey());
+		}
+		if(params.isPublicGroup()) {
+			dbq.setParameter("atDate", new Date(), TemporalType.TIMESTAMP);
 		}
 		if(params.getKey() != null) {
 			dbq.setParameter("id", params.getKey());
@@ -502,8 +525,8 @@ public class BusinessGroupDAO {
 		if(params.getTools() != null && !params.getTools().isEmpty()) {
 			dbq.setParameter("tools", params.getTools());
 		}
-		if(StringHelper.containsNonWhitespace(params.getOwner())) {
-			dbq.setParameter("owner", makeFuzzyQueryString(params.getOwner()));
+		if(StringHelper.containsNonWhitespace(params.getOwnerName())) {
+			dbq.setParameter("owner", makeFuzzyQueryString(params.getOwnerName()));
 		}
 		if(StringHelper.containsNonWhitespace(params.getNameOrDesc())) {
 			dbq.setParameter("search", makeFuzzyQueryString(params.getNameOrDesc()));
diff --git a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java
index 0ef4ea6727d..a378abfeab4 100644
--- a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java
+++ b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java
@@ -436,15 +436,15 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD
 	@Override
 	@Transactional(readOnly=true)
 	public List<BusinessGroup> findBusinessGroupsOwnedBy(Identity identity, OLATResource resource) {
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-		return businessGroupDAO.findBusinessGroups(params, identity, true, false, resource, 0, -1);
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
+		return businessGroupDAO.findBusinessGroups(params, resource, 0, -1);
 	}
 	
 	@Override
 	@Transactional(readOnly=true)
 	public List<BusinessGroup> findBusinessGroupsAttendedBy(Identity identity, OLATResource resource) {
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-		return businessGroupDAO.findBusinessGroups(params, identity, false, true, resource, 0, -1);
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, false, true);
+		return businessGroupDAO.findBusinessGroups(params, resource, 0, -1);
 	}
 	
 	@Override
@@ -454,22 +454,20 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD
 	
 	@Override
 	@Transactional(readOnly=true)
-	public int countBusinessGroups(SearchBusinessGroupParams params, Identity identity,
-			boolean ownedById, boolean attendedById, OLATResource resource) {
+	public int countBusinessGroups(SearchBusinessGroupParams params, OLATResource resource) {
 		if(params == null) {
 			params = new SearchBusinessGroupParams();
 		}
-		return businessGroupDAO.countBusinessGroups(params, identity, ownedById, attendedById, resource);
+		return businessGroupDAO.countBusinessGroups(params, resource);
 	}
 
 	@Override
 	@Transactional(readOnly=true)
-	public List<BusinessGroup> findBusinessGroups(SearchBusinessGroupParams params, Identity identity,
-			boolean ownedById, boolean attendedById, OLATResource resource, int firstResult, int maxResults) {
+	public List<BusinessGroup> findBusinessGroups(SearchBusinessGroupParams params, OLATResource resource, int firstResult, int maxResults) {
 		if(params == null) {
 			params = new SearchBusinessGroupParams();
 		}
-		return businessGroupDAO.findBusinessGroups(params, identity, ownedById, attendedById, resource, firstResult, maxResults);
+		return businessGroupDAO.findBusinessGroups(params, resource, firstResult, maxResults);
 	}
 
 	@Override
diff --git a/src/main/java/org/olat/group/model/SearchBusinessGroupParams.java b/src/main/java/org/olat/group/model/SearchBusinessGroupParams.java
index 1d20dd2cd51..b54ad164d3d 100644
--- a/src/main/java/org/olat/group/model/SearchBusinessGroupParams.java
+++ b/src/main/java/org/olat/group/model/SearchBusinessGroupParams.java
@@ -22,6 +22,8 @@ package org.olat.group.model;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.olat.core.id.Identity;
+
 /**
  * 
  * Description:<br>
@@ -40,7 +42,24 @@ public class SearchBusinessGroupParams {
 	private String name;
 	private String exactName;
 	private String description;
-	private String owner;
+	private String ownerName;
+	
+	private Identity identity;
+	private boolean owner;
+	private boolean attendee;
+	private boolean waiting;
+	private boolean publicGroup;
+	
+	public SearchBusinessGroupParams() {
+		//
+	}
+	
+	public SearchBusinessGroupParams(Identity identity, boolean owner, boolean attendee) {
+		this.identity = identity;
+		this.owner = owner;
+		this.attendee = attendee;
+	}
+
 	
 	public List<String> getTypes() {
 		return types;
@@ -108,12 +127,12 @@ public class SearchBusinessGroupParams {
 		this.description = description;
 	}
 
-	public String getOwner() {
-		return owner;
+	public String getOwnerName() {
+		return ownerName;
 	}
 
-	public void setOwner(String owner) {
-		this.owner = owner;
+	public void setOwnerName(String ownerName) {
+		this.ownerName = ownerName;
 	}
 
 	public String getNameOrDesc() {
@@ -123,4 +142,44 @@ public class SearchBusinessGroupParams {
 	public void setNameOrDesc(String nameOrDesc) {
 		this.nameOrDesc = nameOrDesc;
 	}
+
+	public Identity getIdentity() {
+		return identity;
+	}
+
+	public void setIdentity(Identity identity) {
+		this.identity = identity;
+	}
+
+	public boolean isOwner() {
+		return owner;
+	}
+
+	public void setOwner(boolean owner) {
+		this.owner = owner;
+	}
+
+	public boolean isAttendee() {
+		return attendee;
+	}
+
+	public void setAttendee(boolean attendee) {
+		this.attendee = attendee;
+	}
+
+	public boolean isWaiting() {
+		return waiting;
+	}
+
+	public void setWaiting(boolean waiting) {
+		this.waiting = waiting;
+	}
+
+	public boolean isPublicGroup() {
+		return publicGroup;
+	}
+
+	public void setPublicGroup(boolean publicGroup) {
+		this.publicGroup = publicGroup;
+	}
 }
diff --git a/src/main/java/org/olat/group/ui/area/BGAreaEditController.java b/src/main/java/org/olat/group/ui/area/BGAreaEditController.java
index 66a194d06a6..d96d26adf83 100644
--- a/src/main/java/org/olat/group/ui/area/BGAreaEditController.java
+++ b/src/main/java/org/olat/group/ui/area/BGAreaEditController.java
@@ -128,7 +128,7 @@ public class BGAreaEditController extends BasicController {
 		groupsTabVC = createVelocityContainer("groupstab");
 		tabbedPane.addTab(translate("tab.groups"), groupsTabVC);
 
-		allGroups = businessGroupService.findBusinessGroups(null, null, false, false, resource, 0, -1);
+		allGroups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
 		inAreaGroups = areaManager.findBusinessGroupsOfArea(area);
 		groupsDataModel = new GroupsToAreaDataModel(allGroups, inAreaGroups);
 
diff --git a/src/main/java/org/olat/group/ui/main/BGMainController.java b/src/main/java/org/olat/group/ui/main/BGMainController.java
index d4aae9bd7b0..b6ea817df64 100644
--- a/src/main/java/org/olat/group/ui/main/BGMainController.java
+++ b/src/main/java/org/olat/group/ui/main/BGMainController.java
@@ -684,8 +684,8 @@ public class BGMainController extends MainLayoutBasicController implements Activ
 	 */
 	 //fxdiff VCRP-1,2: access control of resources
 	private void updateGroupList() {
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, getIdentity(), true, true, null, 0, -1);
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(getIdentity(), true, true);
+		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, null, 0, -1);
 
 		List<BGTableItem> wrapped = new ArrayList<BGTableItem>();
 		for (BusinessGroup group:groups) {
@@ -726,8 +726,8 @@ public class BGMainController extends MainLayoutBasicController implements Activ
 			params.setKey(id);
 			params.setName(name);
 			params.setDescription(description);
-			params.setOwner(owner);
-			groups = businessGroupService.findBusinessGroups(params, null, false, false, null, 0, -1);
+			params.setOwnerName(owner);
+			groups = businessGroupService.findBusinessGroups(params, null, 0, -1);
 		}
 
 		List<BGTableItem> wrapped = new ArrayList<BGTableItem>();
diff --git a/src/main/java/org/olat/group/ui/main/BGSearchController.java b/src/main/java/org/olat/group/ui/main/BGSearchController.java
index 5a6060ac450..9e4b7e54b2b 100644
--- a/src/main/java/org/olat/group/ui/main/BGSearchController.java
+++ b/src/main/java/org/olat/group/ui/main/BGSearchController.java
@@ -23,13 +23,12 @@ package org.olat.group.ui.main;
 import org.olat.core.gui.UserRequest;
 import org.olat.core.gui.components.form.flexible.FormItem;
 import org.olat.core.gui.components.form.flexible.FormItemContainer;
-import org.olat.core.gui.components.form.flexible.elements.FormLink;
 import org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement;
 import org.olat.core.gui.components.form.flexible.elements.TextElement;
 import org.olat.core.gui.components.form.flexible.impl.FormBasicController;
 import org.olat.core.gui.components.form.flexible.impl.FormEvent;
 import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
-import org.olat.core.gui.components.link.Link;
+import org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit;
 import org.olat.core.gui.control.Controller;
 import org.olat.core.gui.control.Event;
 import org.olat.core.gui.control.WindowControl;
@@ -50,10 +49,11 @@ public class BGSearchController extends FormBasicController{
 	private TextElement displayName;
 	private TextElement owner;
 	private TextElement description;
-	private FormLink searchButton;
+	private FormSubmit searchButton;
 	private MultipleSelectionElement attendeeEl;
 	private MultipleSelectionElement ownerEl;
 	private MultipleSelectionElement waitingEl;
+	private MultipleSelectionElement publicEl;
 	
 	private String limitUsername;
 	private boolean isAdmin;
@@ -112,12 +112,13 @@ public class BGSearchController extends FormBasicController{
 		
 		String[] waitingValues = new String[]{ translate("search.waiting") };
 		waitingEl = uifactory.addCheckboxesVertical("search.waiting", rightContainer, new String[]{"waiting"}, waitingValues, null, 1);
-		
-		
-		
+
+		String[] publicValues = new String[]{ translate("search.public") };
+		publicEl = uifactory.addCheckboxesVertical("search.public", rightContainer, new String[]{"public"}, publicValues, null, 1);
+
 		FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
 		formLayout.add(buttonLayout);
-		searchButton = uifactory.addFormLink("search", buttonLayout, Link.BUTTON);
+		searchButton = uifactory.addFormSubmitButton("search", "search", buttonLayout);
 	}
 
 	@Override
@@ -168,7 +169,7 @@ public class BGSearchController extends FormBasicController{
 	@Override
 	protected boolean validateFormLogic(UserRequest ureq) {
 		boolean allOk = true;
-		if (isEmpty())	{
+		if (!isAdmin && isEmpty())	{
 			showWarning("cif.error.allempty", null);
 			allOk &= false;
 		}
@@ -184,12 +185,31 @@ public class BGSearchController extends FormBasicController{
 				}
 			}
 		}
+		
+		if(!isAdmin) {
+			boolean owner = ownerEl.isAtLeastSelected(1);
+			boolean attendee = attendeeEl.isAtLeastSelected(1);
+			boolean publicGroups = publicEl.isAtLeastSelected(1);
+			if(!owner && !attendee && !publicGroups) {
+				publicEl.select("public", true);
+			}	
+		}
 		return allOk && super.validateFormLogic(ureq);
 	}
 
 	@Override
 	protected void formOK (UserRequest ureq) {
-		fireEvent (ureq, Event.DONE_EVENT); 
+		SearchEvent e = new SearchEvent();
+		e.setId(getId());
+		e.setName(getName());
+		e.setDescription(getDescription());
+		e.setOwnerName(getOwner());
+		e.setOwner(ownerEl.isAtLeastSelected(1));
+		e.setAttendee(attendeeEl.isAtLeastSelected(1));
+		e.setWaiting(waitingEl.isAtLeastSelected(1));
+		e.setPublicGroups(publicEl.isAtLeastSelected(1));
+		fireEvent (ureq, e);
+		fireEvent(ureq, Event.DONE_EVENT);
 	}
 	
 	@Override
@@ -203,6 +223,7 @@ public class BGSearchController extends FormBasicController{
 			e.setOwner(ownerEl.isAtLeastSelected(1));
 			e.setAttendee(attendeeEl.isAtLeastSelected(1));
 			e.setWaiting(waitingEl.isAtLeastSelected(1));
+			e.setPublicGroups(publicEl.isAtLeastSelected(1));
 			fireEvent(ureq, e);
 			fireEvent(ureq, Event.DONE_EVENT);
 		}
diff --git a/src/main/java/org/olat/group/ui/main/BusinessGroupListController.java b/src/main/java/org/olat/group/ui/main/BusinessGroupListController.java
index cc5e219c409..9c481b2dda4 100644
--- a/src/main/java/org/olat/group/ui/main/BusinessGroupListController.java
+++ b/src/main/java/org/olat/group/ui/main/BusinessGroupListController.java
@@ -1,3 +1,22 @@
+/**
+ * <a href="http://www.openolat.org">
+ * OpenOLAT - Online Learning and Training</a><br>
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); <br>
+ * you may not use this file except in compliance with the License.<br>
+ * You may obtain a copy of the License at the
+ * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
+ * <p>
+ * Unless required by applicable law or agreed to in writing,<br>
+ * software distributed under the License is distributed on an "AS IS" BASIS, <br>
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
+ * See the License for the specific language governing permissions and <br>
+ * limitations under the License.
+ * <p>
+ * Initial code contributed and copyrighted by<br>
+ * frentix GmbH, http://www.frentix.com
+ * <p>
+ */
 package org.olat.group.ui.main;
 
 import java.util.ArrayList;
@@ -97,11 +116,11 @@ public class BusinessGroupListController extends BasicController {
 		groupListCtr.addColumnDescriptor(false, new CustomRenderColumnDescriptor("table.header.resources", 5, null, getLocale(),  ColumnDescriptor.ALIGNMENT_LEFT, resourcesRenderer));
 		groupListCtr.addColumnDescriptor(false, new BooleanColumnDescriptor("table.header.leave", 3, TABLE_ACTION_LEAVE, translate("table.header.leave"), null));
 		if(admin) {
-			groupListCtr.addColumnDescriptor(false, new BooleanColumnDescriptor("table.header.delete", 4, TABLE_ACTION_DELETE, translate("table.header.delete"), null));
+			groupListCtr.addColumnDescriptor(new BooleanColumnDescriptor("table.header.delete", 4, TABLE_ACTION_DELETE, translate("table.header.delete"), null));
 		}
-		groupListCtr.addColumnDescriptor(false, new DefaultColumnDescriptor("table.header.ac", 7, TABLE_ACTION_ACCESS, getLocale()));
+		groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.header.ac", 7, TABLE_ACTION_ACCESS, getLocale()));
 
-		groupListModel = new BusinessGroupTableModelWithType(new ArrayList<BGTableItem>(), getTranslator(), 7);
+		groupListModel = new BusinessGroupTableModelWithType(new ArrayList<BGTableItem>(), getTranslator(), admin ? 7 : 6);
 		groupListCtr.setTableDataModel(groupListModel);
 
 		mainVC.put("searchPanel", searchController.getInitialComponent());
@@ -159,7 +178,7 @@ public class BusinessGroupListController extends BasicController {
 					leaveDialogBox = activateYesNoDialog(ureq, null, translate("dialog.modal.bg.leave.text", businessGroup.getName()), leaveDialogBox);
 					leaveDialogBox.setUserObject(businessGroup);
 				} else if (actionid.equals(TABLE_ACTION_ACCESS)) {
-					//handleAccess(ureq);
+					doLaunch(ureq, businessGroup);
 				}
 			}
 		} else if (source == deleteDialogBox) {
@@ -178,6 +197,11 @@ public class BusinessGroupListController extends BasicController {
 		super.event(ureq, source, event);
 	}
 	
+	private void doLaunch(UserRequest ureq, BusinessGroup group) {
+		String businessPath = "[BusinessGroup:" + group.getKey() + "]";
+		NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
+	}
+	
 	/**
 	 * Removes user from the group as owner and participant. If
 	 * no other owner are found the user won't be removed from the owner group
@@ -235,28 +259,47 @@ public class BusinessGroupListController extends BasicController {
 	}
 	
 	private void doSearch(SearchEvent event) {
+		long start = isLogDebugEnabled() ? System.currentTimeMillis() : 0;
+
 		List<BGTableItem> items = search(event);
 		groupListModel.setEntries(items);
 		groupListCtr.modelChanged();
+		
+		if(isLogDebugEnabled()) {
+			logDebug("Group search takes (ms): " + (System.currentTimeMillis() - start), null);
+		}
 	}
 
 	private List<BGTableItem> search(SearchEvent event) {
 		Long id = event.getId();
 		String name = event.getName();
 		String description = event.getDescription();
-		String owner = event.getOwnerName();
+		String ownerName = event.getOwnerName();
 		
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setKey(id);
 		params.setName(StringHelper.containsNonWhitespace(name) ? name : null);
 		params.setDescription(StringHelper.containsNonWhitespace(description) ? description : null);
-		params.setOwner(StringHelper.containsNonWhitespace(owner) ? owner : null);
+		params.setOwnerName(StringHelper.containsNonWhitespace(ownerName) ? ownerName : null);
+		params.setOwner(event.isOwner());
+		params.setAttendee(event.isAttendee());
+		params.setWaiting(event.isWaiting());
+		params.setPublicGroup(event.isPublicGroups());
+		params.setIdentity(getIdentity());
 		
-		Identity me = null;
-		if(event.isAttendee() || event.isOwner()) {
-			me = getIdentity();
+		//security
+		List<BusinessGroup> groups;
+		if(admin) {
+			if(event.isAttendee() || event.isOwner()) {
+				params.setIdentity(getIdentity());
+			}
+			groups = businessGroupService.findBusinessGroups(params, null, 0, -1);
+		} else {
+			if(!event.isAttendee() && !event.isOwner() && !event.isWaiting() && !event.isPublicGroups()) {
+				params.setPublicGroup(true);
+			}
+			groups = businessGroupService.findBusinessGroups(params, null, 0, -1);
 		}
-		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, me, event.isOwner(), event.isAttendee(), null, 0, -1);
 		
 		List<Long> groupsWithMembership = businessGroupService.isIdentityInBusinessGroups(getIdentity(), groups);
 		Set<Long> memberships = new HashSet<Long>(groupsWithMembership);
diff --git a/src/main/java/org/olat/group/ui/main/SearchEvent.java b/src/main/java/org/olat/group/ui/main/SearchEvent.java
index 905bc602d97..560b06bb640 100644
--- a/src/main/java/org/olat/group/ui/main/SearchEvent.java
+++ b/src/main/java/org/olat/group/ui/main/SearchEvent.java
@@ -17,6 +17,7 @@ public class SearchEvent extends Event {
 	private boolean owner;
 	private boolean attendee;
 	private boolean waiting;
+	public boolean publicGroups;
 	
 	public SearchEvent() {
 		super("search");
@@ -77,6 +78,12 @@ public class SearchEvent extends Event {
 	public void setWaiting(boolean waiting) {
 		this.waiting = waiting;
 	}
-	
-	
+
+	public boolean isPublicGroups() {
+		return publicGroups;
+	}
+
+	public void setPublicGroups(boolean publicGroups) {
+		this.publicGroups = publicGroups;
+	}
 }
diff --git a/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties
index b4cc5dba783..ec1a74d70d0 100644
--- a/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties
+++ b/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties
@@ -37,6 +37,7 @@ search.generic=Suchmaske
 search.attendee=Attendee
 search.owner=Owner
 search.waiting=Waiting
+search.public=Public group
 
 cif.displayname=Name
 cif.description=Beschreibung
diff --git a/src/main/java/org/olat/group/ui/management/BGManagementController.java b/src/main/java/org/olat/group/ui/management/BGManagementController.java
index 612fd66fa84..dba89129d1c 100644
--- a/src/main/java/org/olat/group/ui/management/BGManagementController.java
+++ b/src/main/java/org/olat/group/ui/management/BGManagementController.java
@@ -811,7 +811,7 @@ public class BGManagementController extends MainLayoutBasicController implements
 	private void doOverview(UserRequest ureq) {
 		setMainContent(overviewVC);
 		
-		int numOfGroups = businessGroupService.countBusinessGroups(null, null, false, false, resource);
+		int numOfGroups = businessGroupService.countBusinessGroups(null, resource);
 		int numOfParticipants = businessGroupService.countMembersOf(resource, false, true);
 		int numOfOwners = businessGroupService.countMembersOf(resource, true, false);
 		
@@ -953,7 +953,7 @@ public class BGManagementController extends MainLayoutBasicController implements
 			// area
 			List<BusinessGroup> groups;
 			if (currentAreaFilter == null) {
-				groups = businessGroupService.findBusinessGroups(null, null, false, false, resource, 0, -1);
+				groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
 			} else {
 				groups = areaManager.findBusinessGroupsOfArea(currentAreaFilter); // filtered
 				// groups
diff --git a/src/main/java/org/olat/group/ui/portlet/GroupsPortletRunController.java b/src/main/java/org/olat/group/ui/portlet/GroupsPortletRunController.java
index 634186a9de4..2924d680aa3 100644
--- a/src/main/java/org/olat/group/ui/portlet/GroupsPortletRunController.java
+++ b/src/main/java/org/olat/group/ui/portlet/GroupsPortletRunController.java
@@ -62,6 +62,7 @@ import org.olat.core.util.filter.FilterFactory;
 import org.olat.core.util.resource.OresHelper;
 import org.olat.group.BusinessGroup;
 import org.olat.group.BusinessGroupService;
+import org.olat.group.model.SearchBusinessGroupParams;
 import org.olat.group.site.GroupsSite;
 import org.olat.group.ui.BGControllerFactory;
 import org.olat.group.ui.edit.BusinessGroupModifiedEvent;
@@ -143,7 +144,8 @@ public class GroupsPortletRunController extends AbstractPortletRunController imp
 	 * @return the PortletEntry list.
 	 */
 	private List<PortletEntry> getAllPortletEntries() {
-		groupList = businessGroupService.findBusinessGroups(null, identity, true, true, null, 0, -1);
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, true);
+		groupList = businessGroupService.findBusinessGroups(params, null, 0, -1);
 		List<PortletEntry> entries = convertBusinessGroupToPortletEntryList(groupList);
 		return entries;
 	}
@@ -159,7 +161,8 @@ public class GroupsPortletRunController extends AbstractPortletRunController imp
 	
 	protected void reloadModel(SortingCriteria sortingCriteria) {
 		if (sortingCriteria.getSortingType() == SortingCriteria.AUTO_SORTING) {
-			groupList = businessGroupService.findBusinessGroups(null, identity, true, true, null, 0, -1);
+			SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, true);
+			groupList = businessGroupService.findBusinessGroups(params, null, 0, -1);
 			groupList = getSortedList(groupList, sortingCriteria);
 
 			List<PortletEntry> entries = convertBusinessGroupToPortletEntryList(groupList);
diff --git a/src/main/java/org/olat/group/ui/wizard/MemberListWizardController.java b/src/main/java/org/olat/group/ui/wizard/MemberListWizardController.java
index dae420751b0..1f1e93ca31c 100644
--- a/src/main/java/org/olat/group/ui/wizard/MemberListWizardController.java
+++ b/src/main/java/org/olat/group/ui/wizard/MemberListWizardController.java
@@ -222,7 +222,7 @@ public class MemberListWizardController extends BasicController {
 	private GenericObjectArrayTableDataModel getGroupOrAreaChoiceTableDataModel(OLATResource resource) {
 		List<Object[]> objectArrays = new ArrayList<Object[]>();
 		if (GROUPS_MEMBERS.equals(wizardType)) {
-			List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, null, false, false, resource, 0, -1);
+			List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
 			Collections.sort(groups, new Comparator<BusinessGroup>() {
 				@Override
 				public int compare(BusinessGroup g1, BusinessGroup g2) {
diff --git a/src/main/java/org/olat/home/HomeCalendarController.java b/src/main/java/org/olat/home/HomeCalendarController.java
index c7967f77adc..c4fced238f1 100644
--- a/src/main/java/org/olat/home/HomeCalendarController.java
+++ b/src/main/java/org/olat/home/HomeCalendarController.java
@@ -135,15 +135,19 @@ public class HomeCalendarController extends BasicController implements Activatea
 		// get group calendars
 		BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
 
-		SearchBusinessGroupParams groupParams = new SearchBusinessGroupParams();
+		SearchBusinessGroupParams groupParams = new SearchBusinessGroupParams(ureq.getIdentity(), true, false);
 		groupParams.addTools(CollaborationTools.TOOL_CALENDAR);
-		List<BusinessGroup> ownerGroups = bgs.findBusinessGroups(groupParams, ureq.getIdentity(), true, false, null, 0, -1);
+		List<BusinessGroup> ownerGroups = bgs.findBusinessGroups(groupParams, null, 0, -1);
 		addCalendars(ureq, ownerGroups, true, calendars);
-		List<BusinessGroup> attendedGroups = bgs.findBusinessGroups(groupParams, ureq.getIdentity(), false, true, null, 0, -1);
+		
+		SearchBusinessGroupParams groupParams2 = new SearchBusinessGroupParams(ureq.getIdentity(), false, true);
+		groupParams2.addTools(CollaborationTools.TOOL_CALENDAR);
+		List<BusinessGroup> attendedGroups = bgs.findBusinessGroups(groupParams2, null, 0, -1);
 		for (Iterator<BusinessGroup> ownerGroupsIterator = ownerGroups.iterator(); ownerGroupsIterator.hasNext();) {
 			BusinessGroup ownerGroup = ownerGroupsIterator.next();
-			if (attendedGroups.contains(ownerGroup))
+			if (attendedGroups.contains(ownerGroup)) {
 				attendedGroups.remove(ownerGroup);
+			}
 		}
 		addCalendars(ureq, attendedGroups, false, calendars);
 		
diff --git a/src/main/java/org/olat/instantMessaging/SmackInstantMessagingImpl.java b/src/main/java/org/olat/instantMessaging/SmackInstantMessagingImpl.java
index b98f019f389..121c42caa5e 100644
--- a/src/main/java/org/olat/instantMessaging/SmackInstantMessagingImpl.java
+++ b/src/main/java/org/olat/instantMessaging/SmackInstantMessagingImpl.java
@@ -349,7 +349,7 @@ public class SmackInstantMessagingImpl extends LogDelegator implements InstantMe
 		Set<Long> checkedIdentities = new HashSet<Long>();
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		do {
-			groups = businessGroupService.findBusinessGroups(params, null, false, false, null, counter, GROUP_BATCH_SIZE);
+			groups = businessGroupService.findBusinessGroups(params, null, counter, GROUP_BATCH_SIZE);
 			for (BusinessGroup group:groups) {
 				if (!syncLearn) {
 					String groupID = InstantMessagingModule.getAdapter().createChatRoomString(group);
diff --git a/src/main/java/org/olat/modules/fo/restapi/MyForumsWebService.java b/src/main/java/org/olat/modules/fo/restapi/MyForumsWebService.java
index 7bce2df6420..02190ee338d 100644
--- a/src/main/java/org/olat/modules/fo/restapi/MyForumsWebService.java
+++ b/src/main/java/org/olat/modules/fo/restapi/MyForumsWebService.java
@@ -214,9 +214,9 @@ public class MyForumsWebService {
 		
 		//start found forums in groups
 		BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
 		params.addTools(CollaborationTools.TOOL_FORUM);
-		List<BusinessGroup> groups = bgs.findBusinessGroups(params, retrievedUser, true, true, null, 0, -1);
+		List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
 		//list forum keys
 		List<Long> groupIds = new ArrayList<Long>();
 		Map<Long,BusinessGroup> groupsMap = new HashMap<Long,BusinessGroup>();
diff --git a/src/main/java/org/olat/portfolio/ui/structel/EPShareListController.java b/src/main/java/org/olat/portfolio/ui/structel/EPShareListController.java
index 5bf92bd385b..9b4c2ba8472 100644
--- a/src/main/java/org/olat/portfolio/ui/structel/EPShareListController.java
+++ b/src/main/java/org/olat/portfolio/ui/structel/EPShareListController.java
@@ -70,6 +70,7 @@ import org.olat.core.util.mail.MailContextImpl;
 import org.olat.core.util.mail.MailHelper;
 import org.olat.group.BusinessGroup;
 import org.olat.group.BusinessGroupService;
+import org.olat.group.model.SearchBusinessGroupParams;
 import org.olat.portfolio.manager.EPFrontendManager;
 import org.olat.portfolio.manager.EPMapPolicy;
 import org.olat.portfolio.manager.EPMapPolicy.Type;
@@ -606,7 +607,8 @@ public class EPShareListController extends FormBasicController {
 		
 		public GroupMapperProvider() {
 			if(groupList.isEmpty()) {
-				groupList.addAll(businessGroupService.findBusinessGroups(null, getIdentity(), true, true, null, 0, -1));
+				SearchBusinessGroupParams params = new SearchBusinessGroupParams(getIdentity(), true, true);
+				groupList.addAll(businessGroupService.findBusinessGroups(params, null, 0, -1));
 			}
 		}
 
diff --git a/src/main/java/org/olat/repository/controllers/RepositoryMainController.java b/src/main/java/org/olat/repository/controllers/RepositoryMainController.java
index 710a34ef838..184c1133095 100644
--- a/src/main/java/org/olat/repository/controllers/RepositoryMainController.java
+++ b/src/main/java/org/olat/repository/controllers/RepositoryMainController.java
@@ -284,8 +284,8 @@ public class RepositoryMainController extends MainLayoutBasicController implemen
 		if (repoPortletOn) {
 			rootNode.addChild(new GenericTreeNode(translate("search.mycourses.student"), "search.mycourses.student"));
 			// for authors or users with group rights also show the teacher portlet
-			SearchBusinessGroupParams rightParams = new SearchBusinessGroupParams();
-			if (bIsAuthor || businessGroupService.countBusinessGroups(rightParams, getIdentity(), true, false, null) > 0) {
+			SearchBusinessGroupParams rightParams = new SearchBusinessGroupParams(getIdentity(), true, false);
+			if (bIsAuthor || businessGroupService.countBusinessGroups(rightParams, null) > 0) {
 				rootNode.addChild(new GenericTreeNode(translate("search.mycourses.teacher"), "search.mycourses.teacher"));
 			}
 		}
diff --git a/src/main/java/org/olat/resource/accesscontrol/ACUIFactory.java b/src/main/java/org/olat/resource/accesscontrol/ACUIFactory.java
index 50fe0da06c5..ab083c31316 100644
--- a/src/main/java/org/olat/resource/accesscontrol/ACUIFactory.java
+++ b/src/main/java/org/olat/resource/accesscontrol/ACUIFactory.java
@@ -30,6 +30,7 @@ import org.olat.resource.OLATResource;
 import org.olat.resource.accesscontrol.method.AccessMethodHandler;
 import org.olat.resource.accesscontrol.model.OfferAccess;
 import org.olat.resource.accesscontrol.ui.AbstractConfigurationMethodController;
+import org.olat.resource.accesscontrol.ui.AccessController;
 import org.olat.resource.accesscontrol.ui.AccessListController;
 import org.olat.resource.accesscontrol.ui.OrdersAdminController;
 import org.olat.resource.accesscontrol.ui.OrdersController;
@@ -46,7 +47,7 @@ import org.olat.resource.accesscontrol.ui.OrdersController;
  */
 public class ACUIFactory {
 
-	public static Controller createAccessController(UserRequest ureq, WindowControl wControl, List<OfferAccess> links) {
+	public static AccessController createAccessController(UserRequest ureq, WindowControl wControl, List<OfferAccess> links) {
 		// Always use multi list for layouting purpose
 		AccessListController multiAccessCtrl = new AccessListController(ureq, wControl, links);
 		return multiAccessCtrl;
diff --git a/src/main/java/org/olat/resource/accesscontrol/manager/ACFrontendManager.java b/src/main/java/org/olat/resource/accesscontrol/manager/ACFrontendManager.java
index 271ad8367e8..383c78088a1 100644
--- a/src/main/java/org/olat/resource/accesscontrol/manager/ACFrontendManager.java
+++ b/src/main/java/org/olat/resource/accesscontrol/manager/ACFrontendManager.java
@@ -280,8 +280,7 @@ public class ACFrontendManager extends BasicManager {
 	 * @return The list of OfferAccess objects that represent available access methods
 	 */
 	public List<OfferAccess> getAccessMethodForBusinessGroup(BusinessGroup group, boolean valid, Date atDate) {
-		OLATResource resource = OLATResourceManager.getInstance().findResourceable(group);
-		List<Offer> offers = accessManager.findOfferByResource(resource, valid, atDate);
+		List<Offer> offers = accessManager.findOfferByResource(group.getResource(), valid, atDate);
 		if(offers.isEmpty()) {
 			return Collections.<OfferAccess>emptyList();
 		}
diff --git a/src/main/java/org/olat/resource/accesscontrol/manager/ACMethodManagerImpl.java b/src/main/java/org/olat/resource/accesscontrol/manager/ACMethodManagerImpl.java
index 51d96203b6c..ce5701476bd 100644
--- a/src/main/java/org/olat/resource/accesscontrol/manager/ACMethodManagerImpl.java
+++ b/src/main/java/org/olat/resource/accesscontrol/manager/ACMethodManagerImpl.java
@@ -251,13 +251,12 @@ public class ACMethodManagerImpl extends BasicManager implements ACMethodManager
 
 		StringBuilder sb = new StringBuilder();
 		sb.append("select access.method, group.key, offer.price from ").append(OfferAccessImpl.class.getName()).append(" access, ")
-			.append(BusinessGroupImpl.class.getName()).append(" group, ")
-			.append(OLATResourceImpl.class.getName()).append(" gResource")
+			.append(BusinessGroupImpl.class.getName()).append(" group ")
 			.append(" inner join access.offer offer")
-			.append(" inner join offer.resource oResource")
 			.append(" where access.valid=").append(valid)
 			.append(" and offer.valid=").append(valid)
-			.append(" and group.key=gResource.resId and gResource.resName='BusinessGroup' and oResource.key=gResource.key");
+			.append(" and group.resource.key=offer.resource.key");
+
 		if(atDate != null) {
 			sb.append(" and (offer.validFrom is null or offer.validFrom<=:atDate)")
 				.append(" and (offer.validTo is null or offer.validTo>=:atDate)");
diff --git a/src/main/java/org/olat/resource/accesscontrol/ui/AccessController.java b/src/main/java/org/olat/resource/accesscontrol/ui/AccessController.java
new file mode 100644
index 00000000000..6eaab9fc77b
--- /dev/null
+++ b/src/main/java/org/olat/resource/accesscontrol/ui/AccessController.java
@@ -0,0 +1,34 @@
+/**
+ * <a href="http://www.openolat.org">
+ * OpenOLAT - Online Learning and Training</a><br>
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); <br>
+ * you may not use this file except in compliance with the License.<br>
+ * You may obtain a copy of the License at the
+ * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
+ * <p>
+ * Unless required by applicable law or agreed to in writing,<br>
+ * software distributed under the License is distributed on an "AS IS" BASIS, <br>
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
+ * See the License for the specific language governing permissions and <br>
+ * limitations under the License.
+ * <p>
+ * Initial code contributed and copyrighted by<br>
+ * frentix GmbH, http://www.frentix.com
+ * <p>
+ */
+package org.olat.resource.accesscontrol.ui;
+
+import org.olat.core.gui.control.Controller;
+
+/**
+ * 
+ * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
+ */
+public interface AccessController extends Controller {
+	
+	public Object getUserObject();
+	
+	public void setUserObject(Object obj);
+
+}
diff --git a/src/main/java/org/olat/resource/accesscontrol/ui/AccessListController.java b/src/main/java/org/olat/resource/accesscontrol/ui/AccessListController.java
index 971107406f9..b0aa9c5635e 100644
--- a/src/main/java/org/olat/resource/accesscontrol/ui/AccessListController.java
+++ b/src/main/java/org/olat/resource/accesscontrol/ui/AccessListController.java
@@ -33,7 +33,6 @@ import org.olat.core.gui.control.WindowControl;
 import org.olat.core.gui.control.controller.BasicController;
 import org.olat.core.util.StringHelper;
 import org.olat.resource.accesscontrol.AccessControlModule;
-import org.olat.resource.accesscontrol.manager.ACFrontendManager;
 import org.olat.resource.accesscontrol.method.AccessMethodHandler;
 import org.olat.resource.accesscontrol.model.OfferAccess;
 
@@ -47,21 +46,18 @@ import org.olat.resource.accesscontrol.model.OfferAccess;
  * Initial Date:  27 avr. 2011 <br>
  * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
  */
-public class AccessListController extends BasicController {
+public class AccessListController extends BasicController implements AccessController {
 	
 	private final VelocityContainer mainVC;
 	private final List<Controller> accessCtrls = new ArrayList<Controller>();
 	
 	private final AccessControlModule acModule;
-	private final ACFrontendManager acFrontendManager;
-
-
+	private Object userObject;
 
 	public AccessListController(UserRequest ureq, WindowControl wControl, List<OfferAccess> links) {
 		super(ureq, wControl);
 		
 		acModule = (AccessControlModule)CoreSpringFactory.getBean("acModule");
-		acFrontendManager = (ACFrontendManager)CoreSpringFactory.getBean("acFrontendManager");
 		
 		mainVC = createVelocityContainer("access_method_list");
 		
@@ -87,6 +83,14 @@ public class AccessListController extends BasicController {
 		//
 	}
 
+	public Object getUserObject() {
+		return userObject;
+	}
+
+	public void setUserObject(Object userObject) {
+		this.userObject = userObject;
+	}
+
 	@Override
 	protected void event(UserRequest ureq, Controller source, Event event) {
 		if(accessCtrls.contains(source)) {
diff --git a/src/main/java/org/olat/restapi/group/LearningGroupWebService.java b/src/main/java/org/olat/restapi/group/LearningGroupWebService.java
index cf73834ab71..f2054fc176f 100644
--- a/src/main/java/org/olat/restapi/group/LearningGroupWebService.java
+++ b/src/main/java/org/olat/restapi/group/LearningGroupWebService.java
@@ -133,8 +133,8 @@ public class LearningGroupWebService {
 			groups = bgs.loadAllBusinessGroups();
 		} else {
 			Identity identity = RestSecurityHelper.getIdentity(request);
-			SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-			groups = bgs.findBusinessGroups(params, identity, true, true, null, 0, -1);
+			SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, true);
+			groups = bgs.findBusinessGroups(params, null, 0, -1);
 		}
 		
 		int count = 0;
diff --git a/src/main/java/org/olat/restapi/group/MyGroupWebService.java b/src/main/java/org/olat/restapi/group/MyGroupWebService.java
index 8e82f0fc68f..a6d420e2ee6 100644
--- a/src/main/java/org/olat/restapi/group/MyGroupWebService.java
+++ b/src/main/java/org/olat/restapi/group/MyGroupWebService.java
@@ -82,11 +82,11 @@ public class MyGroupWebService {
 
 		BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
 		
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
 		List<BusinessGroup> groups;
 		if(MediaTypeVariants.isPaged(httpRequest, request)) {
-			int totalCount = bgs.countBusinessGroups(params, retrievedUser, true, true, null);
-			groups = bgs.findBusinessGroups(params, retrievedUser, true, true, null, start, limit);
+			int totalCount = bgs.countBusinessGroups(params, null);
+			groups = bgs.findBusinessGroups(params, null, start, limit);
 			
 			int count = 0;
 			GroupVO[] groupVOs = new GroupVO[groups.size()];
@@ -98,7 +98,7 @@ public class MyGroupWebService {
 			voes.setTotalCount(totalCount);
 			return Response.ok(voes).build();
 		} else {
-			groups = bgs.findBusinessGroups(params, retrievedUser, true, true, null, 0, -1);
+			groups = bgs.findBusinessGroups(params, null, 0, -1);
 			
 			int count = 0;
 			GroupVO[] groupVOs = new GroupVO[groups.size()];
@@ -131,11 +131,11 @@ public class MyGroupWebService {
 
 		BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
 		
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
 		List<BusinessGroup> groups;
 		if(MediaTypeVariants.isPaged(httpRequest, request)) {
-			int totalCount = bgs.countBusinessGroups(params, retrievedUser, true, true, null);
-			groups = bgs.findBusinessGroups(params, retrievedUser, true, true, null, start, limit);
+			int totalCount = bgs.countBusinessGroups(params, null);
+			groups = bgs.findBusinessGroups(params, null, start, limit);
 			
 			int count = 0;
 			GroupInfoVO[] groupVOs = new GroupInfoVO[groups.size()];
diff --git a/src/main/java/org/olat/restapi/user/UserFoldersWebService.java b/src/main/java/org/olat/restapi/user/UserFoldersWebService.java
index 721b004f95c..51dc799eea8 100644
--- a/src/main/java/org/olat/restapi/user/UserFoldersWebService.java
+++ b/src/main/java/org/olat/restapi/user/UserFoldersWebService.java
@@ -244,9 +244,9 @@ public class UserFoldersWebService {
 		
 		//start found forums in groups
 		BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
 		params.addTools(CollaborationTools.TOOL_FOLDER);
-		List<BusinessGroup> groups = bgs.findBusinessGroups(params, retrievedUser, true, true, null, 0, -1);
+		List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
 		for(BusinessGroup group:groups) {
 			CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
 			VFSContainer container = tools.getSecuredFolder(group, null, retrievedUser, false);
diff --git a/src/main/resources/database/mysql/alter_8_1_x_to_8_2_0.sql b/src/main/resources/database/mysql/alter_8_1_x_to_8_2_0.sql
index 228c77e3130..ea1f9a0fb97 100644
--- a/src/main/resources/database/mysql/alter_8_1_x_to_8_2_0.sql
+++ b/src/main/resources/database/mysql/alter_8_1_x_to_8_2_0.sql
@@ -12,6 +12,9 @@ alter table o_gp_business_to_resource add constraint idx_bgp_to_rsrc_group forei
 
 -- groups
 alter table o_gp_business add column fk_resource bigint unique default null;
+alter table o_gp_business add constraint idx_bgp_rsrc foreign key (fk_resource) references o_olatresource (resource_id);
+alter table o_gp_business add constraint idx_bgp_waiting foreign key (fk_waitinggroup) references o_bs_secgroup (id);
+
 
 -- area
 alter table o_gp_bgarea modify groupcontext_fk bigint;
diff --git a/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java b/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java
index 3624b967a16..0c1ff93e010 100644
--- a/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java
+++ b/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java
@@ -19,8 +19,11 @@
  */
 package org.olat.group.test;
 
+import static org.junit.Assert.assertNotNull;
+
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 import java.util.UUID;
 
@@ -39,6 +42,8 @@ import org.olat.group.manager.BusinessGroupDAO;
 import org.olat.group.manager.BusinessGroupPropertyDAO;
 import org.olat.group.model.SearchBusinessGroupParams;
 import org.olat.properties.Property;
+import org.olat.resource.accesscontrol.manager.ACFrontendManager;
+import org.olat.resource.accesscontrol.model.Offer;
 import org.olat.test.JunitTestHelper;
 import org.olat.test.OlatTestCase;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -59,7 +64,8 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 	private BaseSecurity securityManager;
 	@Autowired
 	private BusinessGroupPropertyDAO businessGroupPropertyManager;
-
+	@Autowired
+	private ACFrontendManager acFrontendManager;
 	
 	@After
 	public void tearDown() throws Exception {
@@ -489,7 +495,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		dbInstance.commitAndCloseSession();
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams(); 
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertTrue(groups.size() >= 2);
 		Assert.assertTrue(groups.contains(group1));
@@ -497,7 +503,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 
 		dbInstance.commit();
 
-		List<BusinessGroup> groupLimit = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, 1);
+		List<BusinessGroup> groupLimit = businessGroupDao.findBusinessGroups(params, null, 0, 1);
 		Assert.assertNotNull(groupLimit);
 		Assert.assertEquals(1, groupLimit.size());
 	}
@@ -512,7 +518,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setExactName(exactName);
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(1, groups.size() );
 		Assert.assertTrue(groups.contains(group1));
@@ -530,7 +536,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setName(name);
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(2, groups.size() );
 		Assert.assertTrue(groups.contains(group1));
@@ -548,7 +554,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setName("*" + name + "*");
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(3, groups.size() );
 		Assert.assertTrue(groups.contains(group1));
@@ -566,7 +572,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setDescription(name);
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(1, groups.size() );
 		Assert.assertTrue(groups.contains(group1));
@@ -584,7 +590,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setDescription("*" + name + "*");
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(3, groups.size() );
 		Assert.assertTrue(groups.contains(group1));
@@ -602,7 +608,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setNameOrDesc(name);
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(2, groups.size() );
 		Assert.assertTrue(groups.contains(group1));
@@ -620,7 +626,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setNameOrDesc("*" + name + "*");
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(3, groups.size() );
 		Assert.assertTrue(groups.contains(group1));
@@ -642,8 +648,8 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		dbInstance.commitAndCloseSession();
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-		params.setOwner(name);
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		params.setOwnerName(name);
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(2, groups.size() );
 		Assert.assertTrue(groups.contains(group1));
@@ -664,8 +670,8 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		dbInstance.commitAndCloseSession();
 
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-		params.setOwner("*" + name + "*");
-		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, false, false, null, 0, -1);
+		params.setOwnerName("*" + name + "*");
+		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(3, groups.size() );
 		Assert.assertTrue(groups.contains(group1));
@@ -673,6 +679,84 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(groups.contains(group3));
 	}
 	
+	@Test
+	public void findBusinessGroupsByIdentity() {
+		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();
+
+		securityManager.addIdentityToSecurityGroup(id, group2.getPartipiciantGroup());
+		securityManager.addIdentityToSecurityGroup(id, group3.getWaitingGroup());
+		dbInstance.commitAndCloseSession();
+
+		//check owner
+		SearchBusinessGroupParams paramsOwner = new SearchBusinessGroupParams();
+		paramsOwner.setIdentity(id);
+		paramsOwner.setOwner(true);
+		List<BusinessGroup> ownedGroups = businessGroupDao.findBusinessGroups(paramsOwner, null, 0, 0);
+		Assert.assertNotNull(ownedGroups);
+		Assert.assertEquals(1, ownedGroups.size());
+		Assert.assertTrue(ownedGroups.contains(group1));
+		
+		//check attendee
+		SearchBusinessGroupParams paramsAttendee = new SearchBusinessGroupParams();
+		paramsAttendee.setIdentity(id);
+		paramsAttendee.setAttendee(true);
+		List<BusinessGroup> attendeeGroups = businessGroupDao.findBusinessGroups(paramsAttendee, null, 0, 0);
+		Assert.assertNotNull(attendeeGroups);
+		Assert.assertEquals(1, attendeeGroups.size());
+		Assert.assertTrue(attendeeGroups.contains(group2));
+
+		//check waiting
+		SearchBusinessGroupParams paramsWaiting = new SearchBusinessGroupParams();
+		paramsWaiting.setIdentity(id);
+		paramsWaiting.setWaiting(true);
+		List<BusinessGroup> waitingGroups = businessGroupDao.findBusinessGroups(paramsWaiting, null, 0, 0);
+		Assert.assertNotNull(waitingGroups);
+		Assert.assertEquals(1, waitingGroups.size());
+		Assert.assertTrue(waitingGroups.contains(group3));
+		
+		//check all
+		SearchBusinessGroupParams paramsAll = new SearchBusinessGroupParams();
+		paramsAll.setIdentity(id);
+		paramsAll.setOwner(true);
+		paramsAll.setAttendee(true);
+		paramsAll.setWaiting(true);
+		List<BusinessGroup> allGroups = businessGroupDao.findBusinessGroups(paramsAll, null, 0, 0);
+		Assert.assertNotNull(allGroups);
+		Assert.assertEquals(3, allGroups.size());
+		Assert.assertTrue(allGroups.contains(group1));
+		Assert.assertTrue(allGroups.contains(group2));
+		Assert.assertTrue(allGroups.contains(group3));
+	}
+	
+	@Test
+	public void findPublicGroups() {
+		//create a group with an access control
+		BusinessGroup group = businessGroupDao.createAndPersist(null, "access-grp-1", "access-grp-1-desc", 0, 5, true, false, true, false, false);
+		//create and save an offer
+		Offer offer = acFrontendManager.createOffer(group.getResource(), "TestBGWorkflow");
+		assertNotNull(offer);
+		acFrontendManager.save(offer);
+			
+		dbInstance.commitAndCloseSession();
+			
+		//retrieve the offer
+		SearchBusinessGroupParams paramsAll = new SearchBusinessGroupParams();
+		paramsAll.setPublicGroup(true);
+		List<BusinessGroup> accessGroups = businessGroupDao.findBusinessGroups(paramsAll, null, 0, 0);
+		Assert.assertNotNull(accessGroups);
+		Assert.assertTrue(accessGroups.size() >= 1);
+		Assert.assertTrue(accessGroups.contains(group));
+		
+		for(BusinessGroup accessGroup:accessGroups) {
+			List<Offer> offers = acFrontendManager.findOfferByResource(accessGroup.getResource(), true, new Date());
+			Assert.assertNotNull(offers);
+			Assert.assertFalse(offers.isEmpty());
+		}
+	}
 	
 	@Test
 	public void isIdentityInBusinessGroups() {
diff --git a/src/test/java/org/olat/group/test/BusinessGroupImportExportTest.java b/src/test/java/org/olat/group/test/BusinessGroupImportExportTest.java
index cbf8e478e5f..8550ed3cd1b 100644
--- a/src/test/java/org/olat/group/test/BusinessGroupImportExportTest.java
+++ b/src/test/java/org/olat/group/test/BusinessGroupImportExportTest.java
@@ -72,14 +72,14 @@ public class BusinessGroupImportExportTest extends OlatTestCase {
 		dbInstance.commitAndCloseSession();	
 		
 		//check if all three groups are imported
-		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, null, false, false, resource, 0, -1);
+		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(3, groups.size());
 		
 		//get first group (members true, true, false) (no collaboration tools)
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setExactName("Export group 1");
-		List<BusinessGroup> group1List = businessGroupService.findBusinessGroups(params, null, false, false, resource, 0, -1);
+		List<BusinessGroup> group1List = businessGroupService.findBusinessGroups(params, resource, 0, -1);
 		Assert.assertNotNull(group1List);
 		Assert.assertEquals(1, group1List.size());
 		//check settings of the first group
@@ -107,7 +107,7 @@ public class BusinessGroupImportExportTest extends OlatTestCase {
 
 		//get third group (members true, true, true) (all collaboration tools)
 		params.setExactName("Export group 3");
-		List<BusinessGroup> group3List = businessGroupService.findBusinessGroups(params, null, false, false, resource, 0, -1);
+		List<BusinessGroup> group3List = businessGroupService.findBusinessGroups(params, resource, 0, -1);
 		Assert.assertNotNull(group3List);
 		Assert.assertEquals(1, group3List.size());
 		//check settings of the first group
@@ -146,7 +146,7 @@ public class BusinessGroupImportExportTest extends OlatTestCase {
 		dbInstance.commitAndCloseSession();
 		
 		//check if all three groups are imported
-		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, null, false, false, resource, 0, -1);
+		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
 		Assert.assertNotNull(groups);
 		Assert.assertEquals(3, groups.size());
 		
diff --git a/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java b/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java
index bcdbf18c03c..7a52997213a 100644
--- a/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java
+++ b/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java
@@ -540,18 +540,19 @@ public class BusinessGroupRelationDAOTest extends OlatTestCase {
 		
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		//check resource 1
-		int count1_1 = businessGroupDao.countBusinessGroups(params, null, false, false, resource1);
+		int count1_1 = businessGroupDao.countBusinessGroups(params, resource1);
 		Assert.assertEquals(2, count1_1);
-		List<BusinessGroup> groups1_1 = businessGroupDao.findBusinessGroups(params, null, false, false, resource1, 0, -1);
+		List<BusinessGroup> groups1_1 = businessGroupDao.findBusinessGroups(params, resource1, 0, -1);
 		Assert.assertNotNull(groups1_1);
 		Assert.assertEquals(2, groups1_1.size());
 		Assert.assertTrue(groups1_1.contains(group1));
 		Assert.assertTrue(groups1_1.contains(group2));
 
 		//check owner 1 + resource 1
-		int count3_1 = businessGroupDao.countBusinessGroups(params, id1, true, true, resource1);
+		SearchBusinessGroupParams paramsRestricted = new SearchBusinessGroupParams(id1, true, true);
+		int count3_1 = businessGroupDao.countBusinessGroups(paramsRestricted, resource1);
 		Assert.assertEquals(1, count3_1);
-		List<BusinessGroup> groups3_1 = businessGroupDao.findBusinessGroups(params, id1, true, true, resource1, 0, -1);
+		List<BusinessGroup> groups3_1 = businessGroupDao.findBusinessGroups(paramsRestricted, resource1, 0, -1);
 		Assert.assertNotNull(groups3_1);
 		Assert.assertEquals(1, groups3_1.size());
 		Assert.assertEquals(group1, groups3_1.get(0));
diff --git a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java
index 70f4284134f..095927746ac 100644
--- a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java
+++ b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java
@@ -218,8 +218,8 @@ public class BusinessGroupServiceTest extends OlatTestCase {
 	
 	@Test
 	public void loadBusinessGroups() {
-		SearchBusinessGroupParams params = new SearchBusinessGroupParams(); 
-		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, null, false, false, null, 0, 5);
+		SearchBusinessGroupParams params = new SearchBusinessGroupParams(null, false, false);
+		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, null, 0, 5);
 		Assert.assertNotNull(groups);
 	}
 	
@@ -229,8 +229,9 @@ public class BusinessGroupServiceTest extends OlatTestCase {
 		OLATResource c2 = JunitTestHelper.createRandomResource();
 
 		dbInstance.commitAndCloseSession(); // simulate user clicks
-		assertTrue(businessGroupService.findBusinessGroups(null, null, false, false, c1, 0, -1).isEmpty());
-		assertTrue(businessGroupService.countBusinessGroups(null, null, false, false, c1) == 0);
+		SearchBusinessGroupParams params1 = new SearchBusinessGroupParams(null, false, false);
+		assertTrue(businessGroupService.findBusinessGroups(params1, c1, 0, -1).isEmpty());
+		assertTrue(businessGroupService.countBusinessGroups(params1, c1) == 0);
 
 		dbInstance.commitAndCloseSession(); // simulate user clicks
 		BusinessGroup g1 = businessGroupService.createBusinessGroup(null, "g1", null, 0, 10, false, false, c1);
@@ -247,8 +248,9 @@ public class BusinessGroupServiceTest extends OlatTestCase {
 		assertNotNull(g4); // name duplicate in other context allowed
 
 		dbInstance.commitAndCloseSession(); // simulate user clicks
-		Assert.assertEquals(2, businessGroupService.findBusinessGroups(null, null, false, false, c1, 0, -1).size());
-		Assert.assertEquals(2, businessGroupService.countBusinessGroups(null, null, false, false, c1));
+		SearchBusinessGroupParams params2 = new SearchBusinessGroupParams(null, false, false);
+		Assert.assertEquals(2, businessGroupService.findBusinessGroups(params2, c1, 0, -1).size());
+		Assert.assertEquals(2, businessGroupService.countBusinessGroups(params2, c1));
 	}
 
 	@Test
@@ -375,7 +377,9 @@ public class BusinessGroupServiceTest extends OlatTestCase {
 		List<BusinessGroup> groupOwnedId4 = businessGroupService.findBusinessGroupsOwnedBy(id4, null);
 		Assert.assertEquals("0 BuddyGroup owned by id4", 0, groupOwnedId4.size());
 
-		List<BusinessGroup> groupAttendeeId4 = businessGroupService.findBusinessGroups(null, id4, false, true, null, 0, -1);
+
+		SearchBusinessGroupParams params4 = new SearchBusinessGroupParams(id4, false, true);
+		List<BusinessGroup> groupAttendeeId4 = businessGroupService.findBusinessGroups(params4, null, 0, -1);
 		Assert.assertEquals("1 BuddyGroup where id4 is partipicating", 1, groupAttendeeId4.size());
 		assertTrue("It's the correct BuddyGroup", groupAttendeeId4.contains(two));
 	}
-- 
GitLab