From 74af4d7e0e24bdfbdf573bf13c10a236cc2f6406 Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Thu, 2 Aug 2012 12:02:15 +0200
Subject: [PATCH] OO-291: update the group part of the user administration

---
 .../groups/GroupLeaveDialogBoxController.java | 131 ++++++++++++
 .../user/groups/GroupOverviewController.java  | 188 ++++++++++--------
 .../user/groups/GroupSearchController.java    |   2 +-
 .../groups/GroupSearchResultProvider.java     |   5 +-
 .../groups/_i18n/LocalStrings_de.properties   |   1 +
 .../olat/course/run/RunMainController.java    |   5 +-
 .../olat/group/manager/BusinessGroupDAO.java  |  39 ----
 .../model/SearchBusinessGroupParams.java      |  19 --
 .../olat/group/ui/BGControllerFactory.java    |  27 ---
 .../ui/management/BGManagementController.java |  11 +-
 .../olat/group/test/BusinessGroupDAOTest.java | 183 ++++++++++++++++-
 11 files changed, 429 insertions(+), 182 deletions(-)
 create mode 100644 src/main/java/org/olat/admin/user/groups/GroupLeaveDialogBoxController.java

diff --git a/src/main/java/org/olat/admin/user/groups/GroupLeaveDialogBoxController.java b/src/main/java/org/olat/admin/user/groups/GroupLeaveDialogBoxController.java
new file mode 100644
index 00000000000..7fd704e006e
--- /dev/null
+++ b/src/main/java/org/olat/admin/user/groups/GroupLeaveDialogBoxController.java
@@ -0,0 +1,131 @@
+/**
+ * <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.admin.user.groups;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.olat.core.gui.UserRequest;
+import org.olat.core.gui.components.form.flexible.FormItemContainer;
+import org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement;
+import org.olat.core.gui.components.form.flexible.impl.FormBasicController;
+import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
+import org.olat.core.gui.control.Controller;
+import org.olat.core.gui.control.Event;
+import org.olat.core.gui.control.WindowControl;
+import org.olat.core.id.Identity;
+import org.olat.core.util.Util;
+import org.olat.group.BusinessGroup;
+import org.olat.group.ui.main.BusinessGroupDeleteDialogBoxController;
+import org.olat.user.UserManager;
+
+/**
+ * 
+ * 
+ * 
+ * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
+ */
+public class GroupLeaveDialogBoxController extends FormBasicController {
+	
+	private MultipleSelectionElement sendMail;
+	private MultipleSelectionElement groupDeleteEl;
+	
+	private final String[] keys = {"send"};
+	
+	private final Identity leavingIdentity;
+	private final List<BusinessGroup> groupsToLeave;
+	private final List<BusinessGroup> groupsToDelete;
+	
+	public GroupLeaveDialogBoxController(UserRequest ureq, WindowControl wControl, Identity leavingIdentity,
+			List<BusinessGroup> groupsToLeave, List<BusinessGroup> groupsToDelete) {
+		super(ureq, wControl, null, Util.createPackageTranslator(BusinessGroupDeleteDialogBoxController.class, ureq.getLocale()));
+		this.leavingIdentity = leavingIdentity;
+		this.groupsToLeave = groupsToLeave;
+		this.groupsToDelete = groupsToDelete;
+		initForm(ureq);
+	}
+
+	@Override
+	protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
+		StringBuilder groupToLeaveNames = new StringBuilder();
+		for(BusinessGroup group:groupsToLeave) {
+			if(groupToLeaveNames.length() > 0) groupToLeaveNames.append(", ");
+			groupToLeaveNames.append(group.getName());
+		}
+		String identityName = UserManager.getInstance().getUserDisplayName(leavingIdentity.getUser());
+		String leaveText = translate("unsubscribe.text", new String[]{identityName, groupToLeaveNames.toString()});
+		uifactory.addStaticTextElement("leaving.desc", null, leaveText, formLayout);
+		String[] values = new String[]{
+				translate("dialog.modal.bg.mail.text")
+		};
+		sendMail = uifactory.addCheckboxesHorizontal("send.mail", null, formLayout, keys, values, null);
+
+		if(!groupsToDelete.isEmpty()) {
+			String deletMsg = translate("unsubscribe.group.del");
+			uifactory.addStaticTextElement("delete.desc", null, deletMsg, formLayout);
+			 
+			String[] delValues = new String[]{
+					translate("group.delete.confirmation")
+			};
+			groupDeleteEl = uifactory.addCheckboxesHorizontal("group.del", null, formLayout, keys, delValues, null);
+			groupDeleteEl.select(keys[0], true);
+		}
+		
+		;FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
+		buttonsContainer.setRootForm(mainForm);
+		formLayout.add(buttonsContainer);
+		uifactory.addFormSubmitButton("deleteButton", "ok", buttonsContainer);
+		uifactory.addFormCancelButton("cancel", buttonsContainer, ureq, getWindowControl());
+	}
+	
+	@Override
+	protected void doDispose() {
+		//
+	}
+
+	public boolean isSendMail() {
+		return sendMail.isAtLeastSelected(1);
+	}
+	
+	public boolean isGroupDelete() {
+		return groupDeleteEl == null ? false : groupDeleteEl.isAtLeastSelected(1);
+	}
+
+	public List<BusinessGroup> getGroupsToDelete() {
+		if(groupDeleteEl != null && groupDeleteEl.isAtLeastSelected(1)) {
+			return groupsToDelete;
+		}
+		return Collections.emptyList();
+	}
+	
+	public List<BusinessGroup> getGroupsToLeave() {
+		return groupsToLeave;
+	}
+
+	@Override
+	protected void formOK(UserRequest ureq) {
+		fireEvent(ureq, Event.DONE_EVENT);
+	}
+
+	@Override
+	protected void formCancelled(UserRequest ureq) {
+		fireEvent(ureq, Event.CANCELLED_EVENT);
+	}
+}
diff --git a/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java b/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java
index 567cbbab693..a7ac0a7d628 100644
--- a/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java
+++ b/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java
@@ -25,9 +25,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.olat.NewControllerFactory;
 import org.olat.basesecurity.BaseSecurity;
 import org.olat.basesecurity.BaseSecurityManager;
-import org.olat.basesecurity.SecurityGroup;
 import org.olat.core.CoreSpringFactory;
 import org.olat.core.gui.UserRequest;
 import org.olat.core.gui.components.Component;
@@ -41,14 +41,14 @@ import org.olat.core.gui.components.table.DefaultColumnDescriptor;
 import org.olat.core.gui.components.table.Table;
 import org.olat.core.gui.components.table.TableController;
 import org.olat.core.gui.components.table.TableEvent;
+import org.olat.core.gui.components.table.TableMultiSelectEvent;
 import org.olat.core.gui.components.velocity.VelocityContainer;
 import org.olat.core.gui.control.Controller;
 import org.olat.core.gui.control.Event;
 import org.olat.core.gui.control.WindowControl;
 import org.olat.core.gui.control.controller.BasicController;
+import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController;
 import org.olat.core.gui.control.generic.closablewrapper.CloseableModalWindowWrapperController;
-import org.olat.core.gui.control.generic.modal.DialogBoxController;
-import org.olat.core.gui.control.generic.modal.DialogBoxUIFactory;
 import org.olat.core.id.Identity;
 import org.olat.core.util.Util;
 import org.olat.core.util.coordinate.CoordinatorManager;
@@ -57,14 +57,12 @@ import org.olat.core.util.mail.MailHelper;
 import org.olat.core.util.mail.MailTemplate;
 import org.olat.core.util.mail.MailerResult;
 import org.olat.core.util.mail.MailerWithTemplate;
-import org.olat.core.util.notifications.NotificationHelper;
 import org.olat.group.BusinessGroup;
 import org.olat.group.BusinessGroupMembership;
 import org.olat.group.BusinessGroupService;
 import org.olat.group.model.AddToGroupsEvent;
 import org.olat.group.model.BGMembership;
 import org.olat.group.model.SearchBusinessGroupParams;
-import org.olat.group.ui.BGControllerFactory;
 import org.olat.group.ui.BGMailHelper;
 import org.olat.group.ui.main.BGRoleCellRenderer;
 import org.olat.group.ui.main.BGTableItem;
@@ -82,40 +80,36 @@ import org.olat.group.ui.main.BusinessGroupTableModelWithType.Cols;
  * @author Roman Haag, frentix GmbH, roman.haag@frentix.com
  */
 public class GroupOverviewController extends BasicController {
+	private static final String TABLE_ACTION_LAUNCH = "bgTblLaunch";
 	private static final String TABLE_ACTION_UNSUBSCRIBE = "unsubscribe";
+	
 	private VelocityContainer vc;
 	private TableController groupListCtr;
 	private BusinessGroupTableModelWithType tableDataModel;
-	private Identity identity;
+	
 	private Link addGroups;
+	private CloseableModalController cmc;
 	private CloseableModalWindowWrapperController calloutCtrl;
 	private GroupSearchController groupsCtrl;
-	private DialogBoxController removeFromGrpDlg;
-	private DialogBoxController sendMailDlg;
-	private static String TABLE_ACTION_LAUNCH ;
-	
+	private GroupLeaveDialogBoxController removeFromGrpDlg;
+
 	private final BaseSecurity securityManager;
 	private final BusinessGroupService businessGroupService;
+	
+	private final Identity identity;
 
 	public GroupOverviewController(UserRequest ureq, WindowControl control, Identity identity, Boolean canStartGroups) {
 		super(ureq, control, Util.createPackageTranslator(BusinessGroupTableModelWithType.class, ureq.getLocale()));
 		
 		this.identity = identity;
-	
 		securityManager = BaseSecurityManager.getInstance();
 		businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
-		if (canStartGroups){
-			TABLE_ACTION_LAUNCH = "bgTblLaunch";
-		} else {
-			TABLE_ACTION_LAUNCH = null;
-		}		
-		
+
 		vc = createVelocityContainer("groupoverview");
 		
 		groupListCtr = new TableController(null, ureq, control, getTranslator());
 		listenTo(groupListCtr);
-		
-		groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor(Cols.name.i18n(), Cols.name.ordinal(), TABLE_ACTION_LAUNCH, ureq.getLocale()));
+		groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor(Cols.name.i18n(), Cols.name.ordinal(), canStartGroups ? TABLE_ACTION_LAUNCH : null, ureq.getLocale()));
 		groupListCtr.addColumnDescriptor(false, new DefaultColumnDescriptor(Cols.key.i18n(), Cols.key.ordinal(), null, getLocale()));
 		groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor(Cols.firstTime.i18n(), Cols.firstTime.ordinal(), null, getLocale()));
 		groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor(Cols.lastTime.i18n(), Cols.lastTime.ordinal(), null, getLocale()));
@@ -218,29 +212,23 @@ public class GroupOverviewController extends BasicController {
 		if (source == groupListCtr){
 			if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
 				TableEvent te = (TableEvent) event;
-				String actionid = te.getActionId();
-				int rowid = te.getRowId();
-				BGTableItem item = tableDataModel.getObject(rowid);
+				BGTableItem item = tableDataModel.getObject(te.getRowId());
 				BusinessGroup currBusinessGroup = businessGroupService.loadBusinessGroup(item.getBusinessGroupKey());
 				if (currBusinessGroup==null) {
 					//group seems to be removed meanwhile, reload table and show error
 					showError("group.removed");
 					updateModel(ureq);	
-				} else if (actionid.equals(TABLE_ACTION_LAUNCH)) {
-					BGControllerFactory.getInstance().createRunControllerAsTopNavTab(currBusinessGroup, ureq, getWindowControl());
-				} else if (actionid.equals(TABLE_ACTION_UNSUBSCRIBE)){
-					// fxdiff: FXOLAT-101 see similar doBuddyGroupLeave() in BGMainController
-					String groupName = currBusinessGroup.getName();
-					
-					int numOfOwners = securityManager.countIdentitiesOfSecurityGroup(currBusinessGroup.getOwnerGroup());
-					int numOfParticipants = securityManager.countIdentitiesOfSecurityGroup(currBusinessGroup.getPartipiciantGroup());
-					
-					String rmText = translate("unsubscribe.text", new String[]{NotificationHelper.getFormatedName(identity), groupName});
-					if ((numOfOwners == 1 && numOfParticipants == 0) || (numOfOwners == 0 && numOfParticipants == 1)) {
-						rmText += " <br/>" + translate("unsubscribe.group.del");
-					}
-					removeFromGrpDlg = activateYesNoDialog(ureq, translate("unsubscribe.title"), rmText, removeFromGrpDlg);
-					removeFromGrpDlg.setUserObject(currBusinessGroup);
+				} else if (TABLE_ACTION_LAUNCH.equals(te.getActionId())) {
+					NewControllerFactory.getInstance().launch("[BusinessGroup:" + currBusinessGroup.getKey() + "]", ureq, getWindowControl());
+				} else if (TABLE_ACTION_UNSUBSCRIBE.equals(te.getActionId())){
+					doLeave(ureq, Collections.singletonList(currBusinessGroup));
+				}
+			} else if (event instanceof TableMultiSelectEvent) {
+				TableMultiSelectEvent mse = (TableMultiSelectEvent)event;
+				List<BGTableItem> items = tableDataModel.getObjects(mse.getSelection());
+				if (TABLE_ACTION_UNSUBSCRIBE.equals(mse.getAction())){
+					List<BusinessGroup> groups = toBusinessGroups(items);
+					doLeave(ureq, groups);
 				}
 			}
 		}	else if (source == groupsCtrl && event instanceof AddToGroupsEvent){
@@ -259,64 +247,100 @@ public class GroupOverviewController extends BasicController {
 				}
 				updateModel(ureq);
 			}			
-		} else if (source == removeFromGrpDlg && DialogBoxUIFactory.isYesEvent(event)){
-			//fxdiff: FXOLAT-138 let user decide to send notif-mail or not
-			sendMailDlg = activateYesNoDialog(ureq, translate("unsubscribe.title"), translate("send.email.notif"), sendMailDlg);
-		} else if (source == sendMailDlg){
-			if (DialogBoxUIFactory.isYesEvent(event))
-				removeUserFromGroup(ureq, true);
-			else
-				removeUserFromGroup(ureq, false);
+		} else if (source == removeFromGrpDlg){
+			if(event == Event.DONE_EVENT) {
+				boolean sendMail = removeFromGrpDlg.isSendMail();
+				List<BusinessGroup> groupsToDelete = removeFromGrpDlg.getGroupsToDelete();
+				List<BusinessGroup> groupsToLeave = removeFromGrpDlg.getGroupsToLeave();
+				removeUserFromGroup(ureq, groupsToLeave, groupsToDelete, sendMail);
+			}
+			cmc.deactivate();
+			cleanUpPopups();
+		} else if (source == cmc) {
+			cleanUpPopups();
 		}
 	}
+	
+	private void cleanUpPopups() {
+		removeAsListenerAndDispose(cmc);
+		removeAsListenerAndDispose(removeFromGrpDlg);
+		cmc = null;
+		removeFromGrpDlg = null;
+	}
+	
+	private void doLeave(UserRequest ureq, List<BusinessGroup> groupsToLeave) {
+		List<BusinessGroup> groupsToDelete = new ArrayList<BusinessGroup>(1);
+		for(BusinessGroup group:groupsToLeave) {
+			int numOfOwners = securityManager.countIdentitiesOfSecurityGroup(group.getOwnerGroup());
+			int numOfParticipants = securityManager.countIdentitiesOfSecurityGroup(group.getPartipiciantGroup());
+			if ((numOfOwners == 1 && numOfParticipants == 0) || (numOfOwners == 0 && numOfParticipants == 1)) {
+				groupsToDelete.add(group);
+			}
+		}
+		removeFromGrpDlg = new GroupLeaveDialogBoxController(ureq, getWindowControl(), identity, groupsToLeave, groupsToDelete);
+		listenTo(removeFromGrpDlg);
+		
+		cmc = new CloseableModalController(getWindowControl(), translate("close"), removeFromGrpDlg.getInitialComponent(),
+				true, "");
+		cmc.activate();
+		listenTo(cmc);
+	}
 
 	/**
 	 * 
 	 * @param ureq
 	 * @param doSendMail
 	 */
-	private void removeUserFromGroup(UserRequest ureq, boolean doSendMail) {
-		// fxdiff: FXOLAT-101 see similar doBuddyGroupLeave() in BGMainController
-		BusinessGroup currBusinessGroup = (BusinessGroup) removeFromGrpDlg.getUserObject();
-		String groupName = currBusinessGroup.getName();
-		BaseSecurity securityManager = BaseSecurityManager.getInstance();
-		SecurityGroup owners = currBusinessGroup.getOwnerGroup();
-		List<Identity> ownerList = securityManager.getIdentitiesOfSecurityGroup(owners);
-		List<Identity> partList = securityManager.getIdentitiesOfSecurityGroup(currBusinessGroup.getPartipiciantGroup());
-
-		if ((ownerList.size() == 1 && partList.size() == 0) || (ownerList.size() == 0 && partList.size() == 1)) {
-			// really delete the group as it has no more owners/participants
-			if(doSendMail) {
-				String businessPath = getWindowControl().getBusinessControl().getAsString();
-				businessGroupService.deleteBusinessGroupWithMail(currBusinessGroup, businessPath, getIdentity(), getLocale());
+	private void removeUserFromGroup(UserRequest ureq, List<BusinessGroup> groupsToLeave, List<BusinessGroup> groupsToDelete, boolean doSendMail) {
+		for(BusinessGroup group:groupsToLeave) {
+			if (groupsToDelete.contains(group)) {
+				// really delete the group as it has no more owners/participants
+				if(doSendMail) {
+					String businessPath = getWindowControl().getBusinessControl().getAsString();
+					businessGroupService.deleteBusinessGroupWithMail(group, businessPath, getIdentity(), getLocale());
+				} else {
+					businessGroupService.deleteBusinessGroup(group);
+				}
 			} else {
-				businessGroupService.deleteBusinessGroup(currBusinessGroup);
-			}
-		} else {
-			// 1) remove as owner
-			if (securityManager.isIdentityInSecurityGroup(identity, owners)) {
-				businessGroupService.removeOwners(ureq.getIdentity(), Collections.singletonList(identity), currBusinessGroup);
-			}
-
-			// 2) remove as participant
-			final BusinessGroup toRemFromGroup = currBusinessGroup;
-			//TODO gsync
-			CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(currBusinessGroup, new SyncerExecutor() {
-				public void execute() {
-					businessGroupService.removeParticipant(getIdentity(), identity, toRemFromGroup);
+				// 1) remove as owner
+				if (securityManager.isIdentityInSecurityGroup(identity, group.getOwnerGroup())) {
+					businessGroupService.removeOwners(ureq.getIdentity(), Collections.singletonList(identity), group);
+				}
+				// 2) remove as participant
+				final BusinessGroup toRemFromGroup = group;
+				//TODO gsync
+				CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerExecutor() {
+					public void execute() {
+						businessGroupService.removeParticipant(getIdentity(), identity, toRemFromGroup);
+					}
+				});
+	
+				// 3) notify user about this action:
+				if(doSendMail){
+					MailTemplate mailTemplate = BGMailHelper.createRemoveParticipantMailTemplate(group, getIdentity());
+					MailerWithTemplate mailer = MailerWithTemplate.getInstance();
+					MailerResult mailerResult = mailer.sendMail(null, identity, null, null, mailTemplate, null);
+					MailHelper.printErrorsAndWarnings(mailerResult, getWindowControl(), getLocale());
 				}
-			});
-
-			// 3) notify user about this action:
-			if(doSendMail){
-				MailTemplate mailTemplate = BGMailHelper.createRemoveParticipantMailTemplate(currBusinessGroup, getIdentity());
-				MailerWithTemplate mailer = MailerWithTemplate.getInstance();
-				MailerResult mailerResult = mailer.sendMail(null, identity, null, null, mailTemplate, null);
-				MailHelper.printErrorsAndWarnings(mailerResult, getWindowControl(), getLocale());
 			}
 		}
 
 		updateModel(ureq);
-		showInfo("unsubscribe.successful", groupName);	
+
+		StringBuilder groupNames = new StringBuilder();
+		for(BusinessGroup group:groupsToLeave) {
+			if(groupNames.length() > 0) groupNames.append(", ");
+			groupNames.append(group.getName());
+		}
+		showInfo("unsubscribe.successful", groupNames.toString());	
+	}
+	
+	private List<BusinessGroup> toBusinessGroups(List<BGTableItem> items) {
+		List<Long> groupKeys = new ArrayList<Long>();
+		for(BGTableItem item:items) {
+			groupKeys.add(item.getBusinessGroupKey());
+		}
+		List<BusinessGroup> groups = businessGroupService.loadBusinessGroups(groupKeys);
+		return groups;
 	}
 }
diff --git a/src/main/java/org/olat/admin/user/groups/GroupSearchController.java b/src/main/java/org/olat/admin/user/groups/GroupSearchController.java
index a1b232d0202..d9647879541 100644
--- a/src/main/java/org/olat/admin/user/groups/GroupSearchController.java
+++ b/src/main/java/org/olat/admin/user/groups/GroupSearchController.java
@@ -130,7 +130,7 @@ public class GroupSearchController extends StepFormBasicController {
 	 */
 	private void doSearchGroups(String searchValue, UserRequest ureq) {	
 		if (StringHelper.containsNonWhitespace(searchValue)){
-			GroupSearchResultProvider searchProvider = new GroupSearchResultProvider(ureq.getIdentity(), getLocale(), null);
+			GroupSearchResultProvider searchProvider = new GroupSearchResultProvider(ureq.getIdentity(), getLocale());
 			Map<String, String> resMap = new HashMap<String, String>();
 			searchProvider.getAutoCompleteContent(searchValue, resMap);
 			updateResultTable(resMap);
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 5395eb26e71..abb86c6bfb0 100644
--- a/src/main/java/org/olat/admin/user/groups/GroupSearchResultProvider.java
+++ b/src/main/java/org/olat/admin/user/groups/GroupSearchResultProvider.java
@@ -59,16 +59,14 @@ public class GroupSearchResultProvider implements ResultMapProvider {
 	private final BusinessGroupService businessGroupService;
 	private RepositoryManager repoM;
 	private Translator pT;
-	private String typeFilter;
 	private final Identity identity;
 	private static final int MAX_RESULTS = 50;
 
-	public GroupSearchResultProvider(Identity identity, Locale locale, String typeFilter){
+	public GroupSearchResultProvider(Identity identity, Locale locale){
 		this.identity = identity;
 		businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
 		repoM = RepositoryManager.getInstance();
 		pT = Util.createPackageTranslator(this.getClass(), locale);
-		this.typeFilter = typeFilter;
 	}
 	
 	/**
@@ -106,7 +104,6 @@ public class GroupSearchResultProvider implements ResultMapProvider {
 	private void searchForOneTerm(String searchValue, Map<Long, String> tempResult){
 		// search groups itself		
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
-		params.addTypes(typeFilter);
 		params.setNameOrDesc('%' + searchValue + '%');
 		List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, null, 0, -1);
 		for (BusinessGroup group : groups) {			
diff --git a/src/main/java/org/olat/admin/user/groups/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/admin/user/groups/_i18n/LocalStrings_de.properties
index 637a8c449cc..fc8b5896e44 100644
--- a/src/main/java/org/olat/admin/user/groups/_i18n/LocalStrings_de.properties
+++ b/src/main/java/org/olat/admin/user/groups/_i18n/LocalStrings_de.properties
@@ -22,6 +22,7 @@ group.add.result.none=Der Benutzer wurde keiner Gruppe hinzugef
 group.result.desc=Beschreibung: {0}
 group.result.course=Kurs: {0}, {1}
 group.result.group=Gruppe: {0}
+group.delete.confirmation=Wollen Sie die Gruppe löschen?
 search.field=Gruppe suchen:
 result=Gefundene Gruppen
 send.email=Einladung senden
diff --git a/src/main/java/org/olat/course/run/RunMainController.java b/src/main/java/org/olat/course/run/RunMainController.java
index 56f8ce3804d..0ed68c45a3c 100644
--- a/src/main/java/org/olat/course/run/RunMainController.java
+++ b/src/main/java/org/olat/course/run/RunMainController.java
@@ -30,6 +30,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
+import org.olat.NewControllerFactory;
 import org.olat.bookmark.AddAndEditBookmarkController;
 import org.olat.bookmark.BookmarkManager;
 import org.olat.core.CoreSpringFactory;
@@ -112,7 +113,6 @@ import org.olat.course.run.userview.UserCourseEnvironmentImpl;
 import org.olat.course.statistic.StatisticMainController;
 import org.olat.group.BusinessGroup;
 import org.olat.group.BusinessGroupService;
-import org.olat.group.ui.BGControllerFactory;
 import org.olat.group.ui.edit.BusinessGroupModifiedEvent;
 import org.olat.instantMessaging.InstantMessagingModule;
 import org.olat.instantMessaging.groupchat.GroupChatManagerController;
@@ -773,7 +773,8 @@ public class RunMainController extends MainLayoutBasicController implements Gene
 				// coach. the flag is not needed here
 				// since the groups knows itself if the user is coach and the user sees
 				// only his own groups.
-				BGControllerFactory.getInstance().createRunControllerAsTopNavTab(group, ureq, getWindowControl());
+				String bsuinessPath = "[BusinessGroup:" + group.getKey() + "]";
+				NewControllerFactory.getInstance().launch(bsuinessPath, ureq, getWindowControl());
 			} else {
 				// display error and do logging
 				getWindowControl().setError(translate("error.invalid.group"));
diff --git a/src/main/java/org/olat/group/manager/BusinessGroupDAO.java b/src/main/java/org/olat/group/manager/BusinessGroupDAO.java
index e8aea12b8ce..4ee4de43616 100644
--- a/src/main/java/org/olat/group/manager/BusinessGroupDAO.java
+++ b/src/main/java/org/olat/group/manager/BusinessGroupDAO.java
@@ -471,11 +471,6 @@ public class BusinessGroupDAO {
 			query.append(" )");
 		}
 		
-		if(params.getTypes() != null && !params.getTypes().isEmpty()) {
-			where = where(query, where);
-			query.append("bgi.type in (:types)");
-		}
-		
 		if(params.isOwner() || params.isAttendee() || params.isWaiting()) {
 			where = where(query, where);
 			boolean subOr = false;
@@ -587,9 +582,6 @@ public class BusinessGroupDAO {
 		if (resource != null) {
 			dbq.setParameter("resourceKey", resource.getKey());
 		}
-		if (params.getTypes() != null && !params.getTypes().isEmpty()) {
-			dbq.setParameter("types", params.getTypes());
-		}
 		if(params.getTools() != null && !params.getTools().isEmpty()) {
 			dbq.setParameter("tools", params.getTools());
 		}
@@ -614,17 +606,6 @@ public class BusinessGroupDAO {
 		}
 		return dbq;
 	}
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
 
 	public int countBusinessGroupViews(SearchBusinessGroupParams params, OLATResource resource) {
 		TypedQuery<Number> query = createFindViewDBQuery(params, resource, Number.class)
@@ -838,26 +819,6 @@ public class BusinessGroupDAO {
 		}
 		return dbq;
 	}
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
-	
 	
 	public int countContacts(Identity identity) {
 		List<Long> result = createContactsQuery(identity, Long.class).getResultList();
diff --git a/src/main/java/org/olat/group/model/SearchBusinessGroupParams.java b/src/main/java/org/olat/group/model/SearchBusinessGroupParams.java
index 9eb3e4d5c8f..c62a46ae8e4 100644
--- a/src/main/java/org/olat/group/model/SearchBusinessGroupParams.java
+++ b/src/main/java/org/olat/group/model/SearchBusinessGroupParams.java
@@ -36,7 +36,6 @@ import org.olat.core.id.Identity;
  */
 public class SearchBusinessGroupParams {
 	
-	private Collection<String> types;
 	private Collection<String> tools;
 	private String nameOrDesc;
 	private Collection<Long> groupKeys;
@@ -63,25 +62,7 @@ public class SearchBusinessGroupParams {
 		this.owner = owner;
 		this.attendee = attendee;
 	}
-
-	
-	public Collection<String> getTypes() {
-		return types;
-	}
-	
-	public void setTypes(Collection<String> types) {
-		this.types = types;
-	}
 	
-	public void addTypes(String... types) {
-		if(this.types == null) {
-			this.types = new ArrayList<String>();
-		}
-		for(String type:types) {
-			this.types.add(type);
-		}
-	}
-
 	public Collection<String> getTools() {
 		return tools;
 	}
diff --git a/src/main/java/org/olat/group/ui/BGControllerFactory.java b/src/main/java/org/olat/group/ui/BGControllerFactory.java
index 82b175b30ea..23adccb7449 100644
--- a/src/main/java/org/olat/group/ui/BGControllerFactory.java
+++ b/src/main/java/org/olat/group/ui/BGControllerFactory.java
@@ -25,12 +25,10 @@
 
 package org.olat.group.ui;
 
-import org.olat.NewControllerFactory;
 import org.olat.core.gui.UserRequest;
 import org.olat.core.gui.control.WindowControl;
 import org.olat.core.gui.control.generic.layout.MainLayoutController;
 import org.olat.core.id.OLATResourceable;
-import org.olat.core.id.context.BusinessControl;
 import org.olat.core.id.context.BusinessControlFactory;
 import org.olat.core.id.context.ContextEntry;
 import org.olat.group.BusinessGroup;
@@ -98,31 +96,6 @@ public class BGControllerFactory {
 		return new BusinessGroupMainRunController(ureq, bwControl, businessGroup);
 	}
 
-	/**
-	 * Creates a runtime environment for this business group as a tab in the top
-	 * navigation bar
-	 * 
-	 * @param businessGroup
-	 * @param ureq
-	 * @param wControl
-	 * @param userActivityLogger The logger used to log the user activities or
-	 *          null if no logger used
-	 * @param isGMAdmin
-	 * @param initialViewIdentifier
-	 * @return BusinessGroupMainRunController or null if already initialized
-	 */
-	public void createRunControllerAsTopNavTab(BusinessGroup businessGroup, UserRequest ureq,
-			WindowControl wControl) {
-		String url = "[BusinessGroup:" + businessGroup.getKey() + "]";
-		BusinessControl bc = BusinessControlFactory.getInstance().createFromString(url);
-		WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, wControl);
-		NewControllerFactory.getInstance().launch(ureq, bwControl);
-	}
-
-	//
-	// group management controllers
-	//
-
 	/**
 	 * Factory method to create a configured buddy group main controller for the
 	 * management of the users own buddygroup
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 bf3828c728d..865d5822685 100644
--- a/src/main/java/org/olat/group/ui/management/BGManagementController.java
+++ b/src/main/java/org/olat/group/ui/management/BGManagementController.java
@@ -30,6 +30,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 
+import org.olat.NewControllerFactory;
 import org.olat.admin.securitygroup.gui.UserControllerFactory;
 import org.olat.admin.user.UserTableDataModel;
 import org.olat.basesecurity.BaseSecurity;
@@ -526,7 +527,8 @@ public class BGManagementController extends MainLayoutBasicController implements
 				} else if (actionid.equals(CMD_GROUP_EDIT)) {
 					doGroupEdit(ureq);
 				} else if (actionid.equals(CMD_GROUP_RUN)) {
-					doGroupRun(ureq);
+					String bsuinessPath = "[BusinessGroup:" + currentGroup.getKey() + "]";
+					NewControllerFactory.getInstance().launch(bsuinessPath, ureq, getWindowControl());	
 				} else if (actionid.equals(CMD_GROUP_DELETE)) {
 					doGroupDeleteConfirm(ureq);
 				}
@@ -615,7 +617,8 @@ public class BGManagementController extends MainLayoutBasicController implements
 		} else if (cmd.equals(CMD_AREA_CREATE)) {
 			createNewAreaController(ureq, getWindowControl());
 		} else if (cmd.equals(CMD_GROUP_RUN)) {
-			doGroupRun(ureq);
+			String bsuinessPath = "[BusinessGroup:" + currentGroup.getKey() + "]";
+			NewControllerFactory.getInstance().launch(bsuinessPath, ureq, getWindowControl());
 		} else if (cmd.equals(CMD_GROUP_COPY)) {
 			doGroupCopy(ureq);
 		} else if (cmd.equals(CMD_GROUP_COPY_MULTIPLE)) {
@@ -841,10 +844,6 @@ public class BGManagementController extends MainLayoutBasicController implements
 		// else don't change the tools state
 	}
 
-	private void doGroupRun(UserRequest ureq) {
-		BGControllerFactory.getInstance().createRunControllerAsTopNavTab(currentGroup, ureq, getWindowControl());
-	}
-
 	private void doGroupDelete() {
 		// remove this controller as listener from the group
 		CoordinatorManager.getInstance().getCoordinator().getEventBus().deregisterFor(this, currentGroup);
diff --git a/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java b/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java
index 0810033c8ee..9ed9c47c081 100644
--- a/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java
+++ b/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java
@@ -603,6 +603,14 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(groups.contains(group1));
 		Assert.assertTrue(groups.contains(group2));
 		Assert.assertFalse(groups.contains(group3));
+		
+		//check the same with the views
+		List<BusinessGroupView> groupViews = businessGroupDao.findBusinessGroupViews(params, null, 0, -1);
+		Assert.assertNotNull(groupViews);
+		Assert.assertEquals(2, groupViews.size() );
+		Assert.assertTrue(contains(groupViews, group1));
+		Assert.assertTrue(contains(groupViews, group2));
+		Assert.assertFalse(contains(groupViews, group3));
 	}
 	
 	@Test
@@ -621,6 +629,14 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(groups.contains(group1));
 		Assert.assertTrue(groups.contains(group2));
 		Assert.assertTrue(groups.contains(group3));
+		
+		//check the same with the views
+		List<BusinessGroupView> groupViews = businessGroupDao.findBusinessGroupViews(params, null, 0, -1);
+		Assert.assertNotNull(groupViews);
+		Assert.assertEquals(3, groupViews.size() );
+		Assert.assertTrue(contains(groupViews, group1));
+		Assert.assertTrue(contains(groupViews, group2));
+		Assert.assertTrue(contains(groupViews, group3));
 	}
 	
 	@Test
@@ -631,6 +647,7 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		BusinessGroup group3 = businessGroupDao.createAndPersist(null, "fingbg-3", "desc-" + name + "-desc", 0, 5, true, false, true, false, false);
 		dbInstance.commitAndCloseSession();
 
+		//check find business group
 		SearchBusinessGroupParams params = new SearchBusinessGroupParams();
 		params.setDescription(name);
 		List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
@@ -639,6 +656,14 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(groups.contains(group1));
 		Assert.assertFalse(groups.contains(group2));
 		Assert.assertFalse(groups.contains(group3));
+		
+		//check find business group
+		List<BusinessGroupView> groupViews = businessGroupDao.findBusinessGroupViews(params, null, 0, -1);
+		Assert.assertNotNull(groupViews);
+		Assert.assertEquals(1, groupViews.size() );
+		Assert.assertTrue(contains(groupViews, group1));
+		Assert.assertFalse(contains(groupViews, group2));
+		Assert.assertFalse(contains(groupViews, group3));
 	}
 	
 	@Test
@@ -657,6 +682,14 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(groups.contains(group1));
 		Assert.assertTrue(groups.contains(group2));
 		Assert.assertTrue(groups.contains(group3));
+		
+		//check same search with the views
+		List<BusinessGroupView> groupViews = businessGroupDao.findBusinessGroupViews(params, null, 0, -1);
+		Assert.assertNotNull(groupViews);
+		Assert.assertEquals(3, groupViews.size() );
+		Assert.assertTrue(contains(groupViews, group1));
+		Assert.assertTrue(contains(groupViews, group2));
+		Assert.assertTrue(contains(groupViews, group3));
 	}
 	
 	@Test
@@ -675,6 +708,14 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(groups.contains(group1));
 		Assert.assertFalse(groups.contains(group2));
 		Assert.assertTrue(groups.contains(group3));
+		
+		//check the same search with the views
+		List<BusinessGroupView> groupViews = businessGroupDao.findBusinessGroupViews(params, null, 0, -1);
+		Assert.assertNotNull(groupViews);
+		Assert.assertEquals(2, groupViews.size() );
+		Assert.assertTrue(contains(groupViews, group1));
+		Assert.assertFalse(contains(groupViews, group2));
+		Assert.assertTrue(contains(groupViews, group3));
 	}
 	
 	@Test
@@ -693,6 +734,14 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(groups.contains(group1));
 		Assert.assertTrue(groups.contains(group2));
 		Assert.assertTrue(groups.contains(group3));
+		
+		//check the same search with the views
+		List<BusinessGroupView> groupViews = businessGroupDao.findBusinessGroupViews(params, null, 0, -1);
+		Assert.assertNotNull(groupViews);
+		Assert.assertEquals(3, groupViews.size() );
+		Assert.assertTrue(contains(groupViews, group1));
+		Assert.assertTrue(contains(groupViews, group2));
+		Assert.assertTrue(contains(groupViews, group3));
 	}
 	
 	@Test
@@ -716,6 +765,14 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(groups.contains(group1));
 		Assert.assertFalse(groups.contains(group2));
 		Assert.assertTrue(groups.contains(group3));
+		
+		//check the same with the views
+		List<BusinessGroupView> groupViews = businessGroupDao.findBusinessGroupViews(params, null, 0, -1);
+		Assert.assertNotNull(groupViews);
+		Assert.assertEquals(2, groupViews.size() );
+		Assert.assertTrue(contains(groupViews, group1));
+		Assert.assertFalse(contains(groupViews, group2));
+		Assert.assertTrue(contains(groupViews, group3));
 	}
 	
 	@Test
@@ -738,6 +795,14 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(groups.contains(group1));
 		Assert.assertTrue(groups.contains(group2));
 		Assert.assertTrue(groups.contains(group3));
+		
+		//check the same with the views
+		List<BusinessGroupView> groupViews = businessGroupDao.findBusinessGroupViews(params, null, 0, -1);
+		Assert.assertNotNull(groupViews);
+		Assert.assertEquals(3, groupViews.size() );
+		Assert.assertTrue(contains(groupViews, group1));
+		Assert.assertTrue(contains(groupViews, group2));
+		Assert.assertTrue(contains(groupViews, group3));
 	}
 	
 	@Test
@@ -791,6 +856,33 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertTrue(allGroups.contains(group1));
 		Assert.assertTrue(allGroups.contains(group2));
 		Assert.assertTrue(allGroups.contains(group3));
+		
+		//The same tests with the views
+		//check owner on views
+		List<BusinessGroupView> ownedGroupViews = businessGroupDao.findBusinessGroupViews(paramsOwner, null, 0, 0);
+		Assert.assertNotNull(ownedGroupViews);
+		Assert.assertEquals(1, ownedGroupViews.size());
+		Assert.assertTrue(contains(ownedGroupViews, group1));
+		
+		//check attendee on views
+		List<BusinessGroupView> attendeeGroupViews = businessGroupDao.findBusinessGroupViews(paramsAttendee, null, 0, 0);
+		Assert.assertNotNull(attendeeGroupViews);
+		Assert.assertEquals(1, attendeeGroupViews.size());
+		Assert.assertTrue(contains(attendeeGroupViews, group2));
+
+		//check waiting on views
+		List<BusinessGroupView> waitingGroupViews = businessGroupDao.findBusinessGroupViews(paramsWaiting, null, 0, 0);
+		Assert.assertNotNull(waitingGroupViews);
+		Assert.assertEquals(1, waitingGroupViews.size());
+		Assert.assertTrue(contains(waitingGroupViews, group3));
+		
+		//check all on views
+		List<BusinessGroupView> allGroupViews = businessGroupDao.findBusinessGroupViews(paramsAll, null, 0, 0);
+		Assert.assertNotNull(allGroupViews);
+		Assert.assertEquals(3, allGroupViews.size());
+		Assert.assertTrue(contains(allGroupViews, group1));
+		Assert.assertTrue(contains(allGroupViews, group2));
+		Assert.assertTrue(contains(allGroupViews, group3));
 	}
 	
 	@Test
@@ -817,6 +909,18 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 			Assert.assertNotNull(offers);
 			Assert.assertFalse(offers.isEmpty());
 		}
+		
+		//check the search with the views
+		List<BusinessGroupView> accessGroupViews = businessGroupDao.findBusinessGroupViews(paramsAll, null, 0, 0);
+		Assert.assertNotNull(accessGroupViews);
+		Assert.assertTrue(accessGroupViews.size() >= 1);
+		Assert.assertTrue(contains(accessGroupViews, group));
+		
+		for(BusinessGroupView accessGroup:accessGroupViews) {
+			List<Offer> offers = acFrontendManager.findOfferByResource(accessGroup.getResource(), true, new Date());
+			Assert.assertNotNull(offers);
+			Assert.assertFalse(offers.isEmpty());
+		}
 	}
 	
 	@Test
@@ -844,6 +948,19 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertNotNull(groupWithout);
 		Assert.assertFalse(groupWithout.isEmpty());
 		Assert.assertTrue(groupWithout.contains(group2));
+
+		//check the same with the views
+		//check the search function with resources
+		List<BusinessGroupView> groupViewWith = businessGroupDao.findBusinessGroupViews(paramsWith, null, 0, 0);
+		Assert.assertNotNull(groupViewWith);
+		Assert.assertFalse(groupViewWith.isEmpty());
+		Assert.assertTrue(contains(groupViewWith, group1));
+
+		//check the search function without resources
+		List<BusinessGroupView> groupViewWithout = businessGroupDao.findBusinessGroupViews(paramsWithout, null, 0, 0);
+		Assert.assertNotNull(groupViewWithout);
+		Assert.assertFalse(groupViewWithout.isEmpty());
+		Assert.assertTrue(contains(groupViewWithout, group2));
 	}
 	
 	@Test
@@ -873,6 +990,19 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertNotNull(notMarkedGroups);
 		Assert.assertEquals(1, notMarkedGroups.size());
 		Assert.assertTrue(notMarkedGroups.contains(group2));
+		
+		//check the search with the views
+		//check marked
+		List<BusinessGroupView> markedGroupViews = businessGroupDao.findBusinessGroupViews(paramsAll, null, 0, 0);
+		Assert.assertNotNull(markedGroupViews);
+		Assert.assertEquals(1, markedGroupViews.size());
+		Assert.assertTrue(contains(markedGroupViews, group1));
+		
+		//check not marked
+		List<BusinessGroupView> notMarkedGroupViews = businessGroupDao.findBusinessGroupViews(paramsNotMarked, null, 0, 0);
+		Assert.assertNotNull(notMarkedGroupViews);
+		Assert.assertEquals(1, notMarkedGroupViews.size());
+		Assert.assertTrue(contains(notMarkedGroupViews, group2));
 	}
 	
 	@Test
@@ -903,6 +1033,19 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		Assert.assertNotNull(markedGroups2);
 		Assert.assertEquals(1, markedGroups2.size());
 		Assert.assertTrue(markedGroups2.contains(group2));
+		
+		//check the search with views
+		//check marked
+		List<BusinessGroupView> markedGroupViews = businessGroupDao.findBusinessGroupViews(paramsMarker1, null, 0, 0);
+		Assert.assertNotNull(markedGroupViews);
+		Assert.assertEquals(1, markedGroupViews.size());
+		Assert.assertTrue(contains(markedGroupViews, group1));
+		
+		//check not marked
+		List<BusinessGroupView> markedGroupsView2 = businessGroupDao.findBusinessGroupViews(paramsMarker2, null, 0, 0);
+		Assert.assertNotNull(markedGroupsView2);
+		Assert.assertEquals(1, markedGroupsView2.size());
+		Assert.assertTrue(contains(markedGroupsView2, group2));
 	}
 	
 	@Test
@@ -935,6 +1078,31 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 		int index5 = orderedBy.indexOf(group1);
 		int index6 = orderedBy.indexOf(group2);
 		Assert.assertTrue(index5 < index6);
+		
+		//The find views must return exactly the same results
+		//views: check the query order by name
+		List<BusinessGroupView> orderedViewByName = businessGroupDao.findBusinessGroupViews(params, null, 0, 0, BusinessGroupOrder.nameAsc);
+		Assert.assertNotNull(orderedViewByName);
+		Assert.assertFalse(orderedViewByName.isEmpty());
+		int indexView1 = indexOf(orderedViewByName, group1);
+		int indexView2 = indexOf(orderedViewByName, group2);
+		Assert.assertTrue(indexView1 < indexView2);
+
+		//check the query order by creation date
+		List<BusinessGroupView> orderedViewByCreationDate = businessGroupDao.findBusinessGroupViews(params, null, 0, 0, BusinessGroupOrder.creationDateAsc);
+		Assert.assertNotNull(orderedViewByCreationDate);
+		Assert.assertFalse(orderedViewByCreationDate.isEmpty());
+		int indexView3 = indexOf(orderedViewByCreationDate, group1);
+		int indexView4 = indexOf(orderedViewByCreationDate, group2);
+		Assert.assertTrue(indexView3 < indexView4);
+		
+		//check the query order by creation date
+		List<BusinessGroupView> orderedViewBy = businessGroupDao.findBusinessGroupViews(params, null, 0, 0, BusinessGroupOrder.nameAsc, BusinessGroupOrder.creationDateDesc);
+		Assert.assertNotNull(orderedViewBy);
+		Assert.assertFalse(orderedViewBy.isEmpty());
+		int indexView5 = indexOf(orderedViewBy, group1);
+		int indexView6 = indexOf(orderedViewBy, group2);
+		Assert.assertTrue(indexView5 < indexView6);
 	}
 	
 	@Test
@@ -1020,7 +1188,18 @@ public class BusinessGroupDAOTest extends OlatTestCase {
 			}
 		}
 		return false;
-		
-		
+	}
+	
+	private int indexOf(List<BusinessGroupView> views, BusinessGroup group) {
+		int index = -1;
+		if(views != null && !views.isEmpty()) {
+			for(BusinessGroupView view:views) {
+				index++;
+				if(view.getKey().equals(group.getKey())) {
+					break; 
+				}
+			}
+		}
+		return index;
 	}
 }
-- 
GitLab