From 74f28a2958778befaa7416a12f0ca6e32955eabf Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Mon, 25 Jun 2012 18:11:01 +0200 Subject: [PATCH] OO-291: group management refactoring, remove context and business group manager --- .../assessment/AssessmentMainController.java | 5 +- src/main/java/org/olat/ControllerFactory.java | 5 - .../admin/user/groups/GroupAddManager.java | 7 +- .../user/groups/GroupOverviewController.java | 33 +- .../user/groups/GroupSearchController.java | 9 +- .../groups/GroupSearchResultProvider.java | 2 - .../user/groups/_content/resulttable.html | 2 - .../coordinate/cluster/jms/JmsTestSer.java | 9 - .../table/DefaultTableDataModel.java | 16 +- .../java/org/olat/course/CourseFactory.java | 4 - .../assessment/AssessmentMainController.java | 7 +- .../assessment/GroupAndContextTableModel.java | 13 +- .../condition/ConditionEditController.java | 7 - .../course/editor/EditorMainController.java | 5 - .../course/editor/NodeEditController.java | 4 - .../groupsandrights/CourseGroupManager.java | 71 -- .../course/groupsandrights/CourseRights.java | 9 +- .../PersistingCourseGroupManager.java | 77 -- .../CourseGroupManagementMainController.java | 125 +-- .../nodes/_spring/buildingblockContext.xml | 1 + .../nodes/bc/BCCourseNodeEditController.java | 1 - .../olat/course/nodes/en/ENRunController.java | 3 +- .../course/nodes/en/EnrollmentManager.java | 42 +- .../nodes/fo/FOCourseNodeEditController.java | 1 - .../ProjectBrokerCourseEditorController.java | 12 +- .../projectbroker/ProjectGroupController.java | 15 +- .../service/ProjectBrokerManagerImpl.java | 5 +- .../service/ProjectGroupManagerImpl.java | 10 +- .../repository/CreateNewCourseController.java | 8 +- .../repository/ImportCourseController.java | 1 - .../olat/course/run/RunMainController.java | 35 +- .../preview/PreviewCourseGroupManager.java | 111 +-- .../java/org/olat/group/BusinessGroup.java | 10 - .../org/olat/group/BusinessGroupFactory.java | 11 +- .../org/olat/group/BusinessGroupImpl.java | 14 +- .../org/olat/group/BusinessGroupManager.java | 75 +- .../olat/group/BusinessGroupManagerImpl.java | 27 +- .../org/olat/group/BusinessGroupModule.java | 5 - .../org/olat/group/BusinessGroupService.java | 55 +- .../group/_spring/businessGroupContext.xml | 6 +- .../org/olat/group/area/BGAreaManager.java | 12 +- .../olat/group/area/BGAreaManagerImpl.java | 148 ++-- .../olat/group/context/BGContextManager.java | 334 -------- .../group/context/BGContextManagerImpl.java | 17 +- .../group/delete/GroupDeleteTableModel.java | 32 +- .../group/delete/ReadyToDeleteController.java | 17 +- .../group/delete/SelectionController.java | 31 +- .../olat/group/delete/StatusController.java | 15 +- .../group/manager/BusinessGroupArchiver.java | 77 +- .../olat/group/manager/BusinessGroupDAO.java | 9 +- .../BusinessGroupDeletionManager.java} | 76 +- .../manager/BusinessGroupImportExport.java | 5 +- .../manager/BusinessGroupServiceImpl.java | 744 +++++++++++++++++- .../org/olat/group/right/BGRightManager.java | 2 +- .../olat/group/right/BGRightManagerImpl.java | 46 +- .../java/org/olat/group/right/BGRights.java | 4 +- .../olat/group/site/GroupsManagementSite.java | 105 --- .../group/site/GroupsManagementSiteDef.java | 89 --- .../olat/group/ui/BGControllerFactory.java | 18 +- .../BusinessGroupTableModelWithMaxSize.java | 10 +- .../ui/context/BGContextEditController.java | 411 ---------- .../olat/group/ui/context/BGContextEvent.java | 65 -- .../ui/context/BGContextFormController.java | 217 ----- .../BGContextManagementController.java | 456 ----------- .../group/ui/context/BGContextTableModel.java | 111 --- .../ui/edit/BusinessGroupEditController.java | 33 +- .../olat/group/ui/main/BGMainController.java | 44 +- .../ui/management/BGManagementController.java | 51 +- .../run/BusinessGroupMainRunController.java | 3 - .../ui/wizard/BGCopyWizardController.java | 11 +- .../BGMultipleCopyWizardController.java | 6 +- .../org/olat/portfolio/PortfolioModule.java | 6 +- .../portfolio/_spring/portfolioContext.xml | 1 + .../olat/repository/RepositoryManager.java | 9 +- .../WizardCloseCourseController.java | 40 +- .../service/_spring/repoDeletionContext.xml | 5 - .../manager/ACMethodManagerImpl.java | 1 - .../accesscontrol/manager/ACOfferManager.java | 1 - ...ecurityGroupsRepositoryMainController.java | 15 +- .../group/LearningGroupWebService.java | 37 +- .../repository/course/CoursesWebService.java | 6 +- .../org/olat/upgrade/OLATUpgrade_7_1_1.java | 1 - .../org/olat/_spring/sitedefContext.xml | 7 - .../lifecycle/LifeCycleManagerTest.java | 33 +- .../CourseGroupManagementTest.java | 23 +- .../nodes/en/EnrollmentManagerTest.java | 20 +- .../ProjectBrokerManagerTest.java | 5 +- .../group/BusinessGroupManagerImplTest.java | 233 +++--- .../org/olat/group/BusinessGroupTest.java | 71 +- .../org/olat/properties/PropertyTest.java | 15 +- .../java/org/olat/restapi/ContactsTest.java | 19 +- .../org/olat/restapi/CourseGroupMgmtTest.java | 20 +- .../org/olat/restapi/GroupFoldersTest.java | 17 +- .../java/org/olat/restapi/GroupMgmtTest.java | 20 +- .../java/org/olat/restapi/UserMgmtTest.java | 19 +- .../java/org/olat/test/JunitTestHelper.java | 25 +- 96 files changed, 1482 insertions(+), 3224 deletions(-) delete mode 100644 src/main/java/org/olat/group/context/BGContextManager.java rename src/main/java/org/olat/group/{delete/service/GroupDeletionManager.java => manager/BusinessGroupDeletionManager.java} (83%) delete mode 100644 src/main/java/org/olat/group/site/GroupsManagementSite.java delete mode 100644 src/main/java/org/olat/group/site/GroupsManagementSiteDef.java delete mode 100644 src/main/java/org/olat/group/ui/context/BGContextEditController.java delete mode 100644 src/main/java/org/olat/group/ui/context/BGContextEvent.java delete mode 100644 src/main/java/org/olat/group/ui/context/BGContextFormController.java delete mode 100644 src/main/java/org/olat/group/ui/context/BGContextManagementController.java delete mode 100644 src/main/java/org/olat/group/ui/context/BGContextTableModel.java diff --git a/src/main/java/de/bps/course/assessment/AssessmentMainController.java b/src/main/java/de/bps/course/assessment/AssessmentMainController.java index 64e57c0ec32..e0af74d3f8e 100644 --- a/src/main/java/de/bps/course/assessment/AssessmentMainController.java +++ b/src/main/java/de/bps/course/assessment/AssessmentMainController.java @@ -69,7 +69,6 @@ import org.olat.core.gui.control.generic.dtabs.Activateable; import org.olat.core.gui.control.generic.messages.MessageUIFactory; import org.olat.core.gui.control.generic.tool.ToolController; import org.olat.core.gui.control.generic.tool.ToolFactory; -import org.olat.core.gui.translator.PackageTranslator; import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; import org.olat.core.id.IdentityEnvironment; @@ -110,7 +109,6 @@ import org.olat.course.nodes.STCourseNode; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.course.run.userview.UserCourseEnvironmentImpl; import org.olat.group.BusinessGroup; -import org.olat.group.ui.context.BGContextTableModel; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; import org.olat.user.UserManager; @@ -837,7 +835,6 @@ AssessmentMainController(UserRequest ureq, WindowControl wControl, OLATResourcea groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.group.name", 0, CMD_CHOOSE_GROUP, ureq.getLocale())); groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.group.desc", 1, null, ureq.getLocale())); - Translator defaultContextTranslator = new PackageTranslator(Util.getPackageName(BGContextTableModel.class), ureq.getLocale()); // loop over all groups to filter depending on condition List<BusinessGroup> currentGroups = new ArrayList<BusinessGroup>(); for (BusinessGroup group: coachedGroups) { @@ -845,7 +842,7 @@ AssessmentMainController(UserRequest ureq, WindowControl wControl, OLATResourcea currentGroups.add(group); } } - GroupAndContextTableModel groupTableDataModel = new GroupAndContextTableModel(currentGroups, defaultContextTranslator); + GroupAndContextTableModel groupTableDataModel = new GroupAndContextTableModel(currentGroups); groupListCtr.setTableDataModel(groupTableDataModel); groupChoose.put("grouplisttable", groupListCtr.getInitialComponent()); diff --git a/src/main/java/org/olat/ControllerFactory.java b/src/main/java/org/olat/ControllerFactory.java index 87c940d9938..9e8dd9c4403 100644 --- a/src/main/java/org/olat/ControllerFactory.java +++ b/src/main/java/org/olat/ControllerFactory.java @@ -48,7 +48,6 @@ import org.olat.course.nodes.ta.ReturnboxController; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGControllerFactory; -import org.olat.group.ui.context.BGContextManagementController; import org.olat.group.ui.main.BGMainController; import org.olat.home.HomeMainController; import org.olat.home.InviteeHomeMainController; @@ -169,10 +168,6 @@ public class ControllerFactory { } else if (OresHelper.isOfType(olatResourceable, UserAdminMainController.class)) { if (!roles.isUserManager()) throw new OLATSecurityException("Tried to launch a UserAdminMainController, but is not in admin group " + roles); return new UserAdminMainController(ureq, wControl); - } else if (OresHelper.isOfType(olatResourceable, BGContextManagementController.class)) { - if (!roles.isGroupManager()) throw new OLATSecurityException("Tried to launch a BGContextManagementController, but is not in group groupmanager " - + roles); - return new BGContextManagementController(ureq, wControl); } else if (OresHelper.isOfType(olatResourceable, InviteeHomeMainController.class)) { if (!roles.isInvitee()) throw new OLATSecurityException("Tried to launch a InviteeMainController, but is not an invitee " + roles); return new InviteeHomeMainController(ureq, wControl); diff --git a/src/main/java/org/olat/admin/user/groups/GroupAddManager.java b/src/main/java/org/olat/admin/user/groups/GroupAddManager.java index 5252c86594f..f49e36b45b5 100644 --- a/src/main/java/org/olat/admin/user/groups/GroupAddManager.java +++ b/src/main/java/org/olat/admin/user/groups/GroupAddManager.java @@ -33,8 +33,6 @@ import org.olat.core.util.mail.MailTemplate; import org.olat.core.util.mail.MailerResult; import org.olat.core.util.mail.MailerWithTemplate; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGConfigFlags; import org.olat.group.ui.BGMailHelper; @@ -81,7 +79,6 @@ public class GroupAddManager extends BasicManager { * @return */ public String[] addIdentityToGroups(AddToGroupsEvent groupsEv, final Identity ident, final Identity addingIdentity){ - final BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); BaseSecurity securityManager = BaseSecurityManager.getInstance(); final BGConfigFlags flags = BGConfigFlags.createBuddyGroupDefaultFlags(); @@ -101,7 +98,7 @@ public class GroupAddManager extends BasicManager { if (group != null && !securityManager.isIdentityInSecurityGroup(ident, group.getOwnerGroup())){ // seems not to work, but would be the way to go! // ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(group)); - bgm.addOwnerAndFireEvent(addingIdentity, ident, group, flags, false); + bgs.addOwner(addingIdentity, ident, group, flags); ownerGroupnames += group.getName() + ", "; addToAnyGroup = true; if (!notifyAboutAdd.contains(group.getKey()) && mailKeys.contains(group.getKey())) notifyAboutAdd.add(group.getKey()); @@ -120,7 +117,7 @@ public class GroupAddManager extends BasicManager { // ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(group)); CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerExecutor(){ public void execute() { - bgm.addParticipantAndFireEvent(addingIdentity, ident, toAddGroup, flags, false); + bgs.addParticipant(addingIdentity, ident, toAddGroup, flags); }}); participantGroupnames += group.getName() + ", "; addToAnyGroup = true; 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 cf388e5caa8..578ae23bff5 100644 --- a/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java +++ b/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java @@ -20,6 +20,7 @@ package org.olat.admin.user.groups; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -56,8 +57,6 @@ 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.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGConfigFlags; import org.olat.group.ui.BGControllerFactory; @@ -87,11 +86,15 @@ public class GroupOverviewController extends BasicController { private DialogBoxController removeFromGrpDlg; private DialogBoxController sendMailDlg; private static String TABLE_ACTION_LAUNCH ; + + private final BusinessGroupService businessGroupService; public GroupOverviewController(UserRequest ureq, WindowControl control, Identity identity, Boolean canStartGroups) { super(ureq, control, Util.createPackageTranslator(BusinessGroupTableModel.class, ureq.getLocale())); this.wControl = control; this.identity = identity; + + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); if (canStartGroups){ TABLE_ACTION_LAUNCH = "bgTblLaunch"; } else { @@ -124,8 +127,7 @@ public class GroupOverviewController extends BasicController { tblCtr.addColumnDescriptor(new StaticColumnDescriptor(TABLE_ACTION_UNSUBSCRIBE, "table.user.unsubscribe", translate("table.user.unsubscribe"))); //build data model - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); - BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); + BaseSecurity sm = BaseSecurityManager.getInstance(); List<Object[]> userGroups = new ArrayList<Object[]>(); //loop over all kind of groups with all possible memberships @@ -134,9 +136,9 @@ public class GroupOverviewController extends BasicController { bgTypes.add(BusinessGroup.TYPE_LEARNINGROUP); bgTypes.add(BusinessGroup.TYPE_RIGHTGROUP); for (String bgType : bgTypes) { - List<BusinessGroup> ownedGroups = bgs.findBusinessGroupsOwnedBy(bgType, identity, null); - List<BusinessGroup> attendedGroups = bgs.findBusinessGroupsAttendedBy(bgType, identity, null); - List<BusinessGroup> waitingGroups = bgs.findBusinessGroupsWithWaitingListAttendedBy(bgType, identity, null); + List<BusinessGroup> ownedGroups = businessGroupService.findBusinessGroupsOwnedBy(bgType, identity, null); + List<BusinessGroup> attendedGroups = businessGroupService.findBusinessGroupsAttendedBy(bgType, identity, null); + List<BusinessGroup> waitingGroups = businessGroupService.findBusinessGroupsWithWaitingListAttendedBy(bgType, identity, null); //using HashSet to remove duplicate entries HashSet<BusinessGroup> allGroups = new HashSet<BusinessGroup>(); allGroups.addAll(ownedGroups); @@ -163,7 +165,7 @@ public class GroupOverviewController extends BasicController { joinDate = sm.getSecurityGroupJoinDateForIdentity(group.getOwnerGroup(), identity); } else if(waitingGroups.contains(group)) { - int waitingListPosition = bgm.getPositionInWaitingListFor(identity, group); + int waitingListPosition = businessGroupService.getPositionInWaitingListFor(identity, group); groupEntry[2] = translate("waiting", String.valueOf(waitingListPosition)); joinDate = sm.getSecurityGroupJoinDateForIdentity(group.getWaitingGroup(), identity); } @@ -273,7 +275,6 @@ public class GroupOverviewController extends BasicController { */ private void removeUserFromGroup(UserRequest ureq, boolean doSendMail) { // fxdiff: FXOLAT-101 see similar doBuddyGroupLeave() in BGMainController - final BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); BusinessGroup currBusinessGroup = (BusinessGroup) removeFromGrpDlg.getUserObject(); String groupName = currBusinessGroup.getName(); BaseSecurity securityManager = BaseSecurityManager.getInstance(); @@ -284,21 +285,23 @@ public class GroupOverviewController extends BasicController { 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) - bgm.deleteBusinessGroupWithMail(currBusinessGroup, wControl, ureq, getTranslator(), null); - else - bgm.deleteBusinessGroup(currBusinessGroup); + if(doSendMail) { + String businessPath = getWindowControl().getBusinessControl().getAsString(); + businessGroupService.deleteBusinessGroupWithMail(currBusinessGroup, businessPath, getIdentity(), getLocale()); + } else { + businessGroupService.deleteBusinessGroup(currBusinessGroup); + } } else { // 1) remove as owner if (securityManager.isIdentityInSecurityGroup(identity, owners)) { - bgm.removeOwnerAndFireEvent(ureq.getIdentity(), identity, currBusinessGroup, flags, false); + businessGroupService.removeOwners(ureq.getIdentity(), Collections.singletonList(identity), currBusinessGroup, flags); } // 2) remove as participant final BusinessGroup toRemFromGroup = currBusinessGroup; CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(currBusinessGroup, new SyncerExecutor() { public void execute() { - bgm.removeParticipantAndFireEvent(getIdentity(), identity, toRemFromGroup, flags, false); + businessGroupService.removeParticipant(getIdentity(), identity, toRemFromGroup, flags); } }); 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 ec015a7c628..0d9e23df1f7 100644 --- a/src/main/java/org/olat/admin/user/groups/GroupSearchController.java +++ b/src/main/java/org/olat/admin/user/groups/GroupSearchController.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; @@ -44,7 +45,7 @@ import org.olat.core.gui.control.generic.wizard.StepsRunContext; import org.olat.core.gui.translator.Translator; import org.olat.core.util.StringHelper; import org.olat.core.util.Util; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.group.ui.BusinessGroupTableModel; /** @@ -66,10 +67,13 @@ public class GroupSearchController extends StepFormBasicController { private ArrayList<MultipleSelectionElement> owners; private FormItem errorComp; private String lastSearchValue; + + private final BusinessGroupService businessGroupService; // constructor to be used like a normal FormBasicController public GroupSearchController(UserRequest ureq, WindowControl wControl) { super(ureq, wControl, FormBasicController.LAYOUT_VERTICAL); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); Translator pT = Util.createPackageTranslator(BusinessGroupTableModel.class, ureq.getLocale(), getTranslator()); this.flc.setTranslator(pT); initForm(ureq); @@ -78,6 +82,7 @@ public class GroupSearchController extends StepFormBasicController { // constructor for use in steps-wizzard public GroupSearchController(UserRequest ureq, WindowControl wControl, Form form, StepsRunContext stepsRunContext, int layoutVertical, String pageName) { super(ureq, wControl, form, stepsRunContext, layoutVertical, pageName); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); Translator pT = Util.createPackageTranslator(BusinessGroupTableModel.class, ureq.getLocale(), getTranslator()); this.flc.setTranslator(pT); initForm(ureq); @@ -96,7 +101,7 @@ public class GroupSearchController extends StepFormBasicController { resTable = FormLayoutContainer.createCustomFormLayout("resultsTable", getTranslator(), this.velocity_root + "/resulttable.html"); formLayout.add(resTable); - resTable.contextPut("bGM", BusinessGroupManagerImpl.getInstance()); + resTable.contextPut("bGM", businessGroupService); if (!isUsedInStepWizzard()) uifactory.addSpacerElement("space", formLayout, false); errorComp = uifactory.createSimpleErrorText("error", ""); 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 fa456b2f8d5..567014a72d2 100644 --- a/src/main/java/org/olat/admin/user/groups/GroupSearchResultProvider.java +++ b/src/main/java/org/olat/admin/user/groups/GroupSearchResultProvider.java @@ -40,8 +40,6 @@ import org.olat.course.CourseModule; import org.olat.course.ICourse; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; import org.olat.group.model.SearchBusinessGroupParams; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; diff --git a/src/main/java/org/olat/admin/user/groups/_content/resulttable.html b/src/main/java/org/olat/admin/user/groups/_content/resulttable.html index d9a8b7fcb72..b604ea6f455 100644 --- a/src/main/java/org/olat/admin/user/groups/_content/resulttable.html +++ b/src/main/java/org/olat/admin/user/groups/_content/resulttable.html @@ -4,7 +4,6 @@ <thead> <tr> <th class="b_first_child">$r.translate("table.group.name")</th> - <th>$r.translate("table.group.type")</th> <th>$r.translate("description")</th> <th>$r.translate("group.add.as", $r.translate("owner"))</th> <th>$r.translate("group.add.as", $r.translate("attende"))</th> @@ -18,7 +17,6 @@ #set($group = $bGM.loadBusinessGroup("$id", false) ) <tr class="#if($velocityCount % 2 == 0) b_table_odd #end #if($velocityCount >= $resMap.size()) b_last_child #end" > <td>$title</td> - <td>$r.translate($group.getType()) </td> <td>$!group.getDescription()</td> <td style="text-align: center;">$r.render("owner$id")</td> <td style="text-align: center;">$r.render("part$id")</td> diff --git a/src/main/java/org/olat/commons/coordinate/cluster/jms/JmsTestSer.java b/src/main/java/org/olat/commons/coordinate/cluster/jms/JmsTestSer.java index 842f1e4ebcd..5aa97eb2378 100644 --- a/src/main/java/org/olat/commons/coordinate/cluster/jms/JmsTestSer.java +++ b/src/main/java/org/olat/commons/coordinate/cluster/jms/JmsTestSer.java @@ -34,7 +34,6 @@ import org.olat.core.id.User; import org.olat.core.util.ObjectCloner; import org.olat.course.assessment.AssessmentChangedEvent; import org.olat.group.BusinessGroup; -import org.olat.group.context.BGContext; import org.olat.group.ui.edit.BusinessGroupModifiedEvent; public class JmsTestSer { @@ -139,10 +138,6 @@ public class JmsTestSer { return null; } - public BGContext getGroupContext() { - return null; - } - public Date getLastUsage() { return null; } @@ -187,10 +182,6 @@ public class JmsTestSer { // } - public void setGroupContext(BGContext groupContext) { - // - } - public void setLastUsage(Date lastUsage) { // } diff --git a/src/main/java/org/olat/core/gui/components/table/DefaultTableDataModel.java b/src/main/java/org/olat/core/gui/components/table/DefaultTableDataModel.java index 9083eedddb2..ce39583e12c 100644 --- a/src/main/java/org/olat/core/gui/components/table/DefaultTableDataModel.java +++ b/src/main/java/org/olat/core/gui/components/table/DefaultTableDataModel.java @@ -38,14 +38,14 @@ import org.olat.core.logging.AssertException; * * @author Felix Jost */ -public abstract class DefaultTableDataModel implements TableDataModel { +public abstract class DefaultTableDataModel<U> implements TableDataModel<U> { private Locale locale; - protected List objects; + protected List<U> objects; /** * @param objects */ - public DefaultTableDataModel(final List objects) { + public DefaultTableDataModel(final List<U> objects) { this.objects = objects; } @@ -71,7 +71,7 @@ public abstract class DefaultTableDataModel implements TableDataModel { * * @param objects The objects to set */ - public void setObjects(List objects) { + public void setObjects(List<U> objects) { this.objects = objects; } @@ -79,7 +79,7 @@ public abstract class DefaultTableDataModel implements TableDataModel { * @param row * @return */ - public Object getObject(final int row) { + public U getObject(final int row) { return objects.get(row); } @@ -94,8 +94,8 @@ public abstract class DefaultTableDataModel implements TableDataModel { * @param objectMarkers * @return */ - public List getObjects(final BitSet objectMarkers) { - List results = new ArrayList(); + public List<U> getObjects(final BitSet objectMarkers) { + List<U> results = new ArrayList<U>(); for(int i=objectMarkers.nextSetBit(0); i >= 0; i=objectMarkers.nextSetBit(i+1)) { results.add(getObject(i)); } @@ -121,7 +121,7 @@ public abstract class DefaultTableDataModel implements TableDataModel { /** * @return List */ - public List getObjects() { + public List<U> getObjects() { return objects; } diff --git a/src/main/java/org/olat/course/CourseFactory.java b/src/main/java/org/olat/course/CourseFactory.java index 659cab77c5e..b61854e6555 100644 --- a/src/main/java/org/olat/course/CourseFactory.java +++ b/src/main/java/org/olat/course/CourseFactory.java @@ -512,9 +512,6 @@ public class CourseFactory extends BasicManager { DBFactory.getInstance(false).intermediateCommit(); } } - CourseGroupManager sourceCgm = sourceCourse.getCourseEnvironment().getCourseGroupManager(); - CourseGroupManager targetCgm = targetCourse.getCourseEnvironment().getCourseGroupManager(); - targetCgm.createCourseGroupmanagementAsCopy(sourceCgm, sourceCourse.getCourseTitle()); } return targetRes; } @@ -626,7 +623,6 @@ public class CourseFactory extends BasicManager { course = openCourseEditSession(course.getResourceableId()); // create group management CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager(); - cgm.createCourseGroupmanagement(course.getResourceableId().toString()); // import groups cgm.importCourseLearningGroups(courseExportData); cgm.importCourseRightGroups(courseExportData); diff --git a/src/main/java/org/olat/course/assessment/AssessmentMainController.java b/src/main/java/org/olat/course/assessment/AssessmentMainController.java index 258f5503308..2f843986ff1 100644 --- a/src/main/java/org/olat/course/assessment/AssessmentMainController.java +++ b/src/main/java/org/olat/course/assessment/AssessmentMainController.java @@ -69,7 +69,6 @@ import org.olat.core.gui.control.generic.dtabs.Activateable2; import org.olat.core.gui.control.generic.messages.MessageUIFactory; import org.olat.core.gui.control.generic.tool.ToolController; import org.olat.core.gui.control.generic.tool.ToolFactory; -import org.olat.core.gui.translator.PackageTranslator; import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; import org.olat.core.id.IdentityEnvironment; @@ -82,7 +81,6 @@ import org.olat.core.logging.OLATSecurityException; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.logging.activity.ActionType; -import org.olat.core.util.Util; import org.olat.core.util.event.GenericEventListener; import org.olat.core.util.resource.OresHelper; import org.olat.core.util.tree.TreeHelper; @@ -102,7 +100,6 @@ import org.olat.course.properties.CoursePropertyManager; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.course.run.userview.UserCourseEnvironmentImpl; import org.olat.group.BusinessGroup; -import org.olat.group.ui.context.BGContextTableModel; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; import org.olat.user.UserManager; @@ -668,7 +665,6 @@ AssessmentMainController(UserRequest ureq, WindowControl wControl, OLATResourcea * @param ureq The user request */ private void doGroupChoose(UserRequest ureq) { - ICourse course = CourseFactory.loadCourse(ores); removeAsListenerAndDispose(groupListCtr); TableGuiConfiguration tableConfig = new TableGuiConfiguration(); tableConfig.setTableEmptyMessage(translate("groupchoose.nogroups")); @@ -679,7 +675,6 @@ AssessmentMainController(UserRequest ureq, WindowControl wControl, OLATResourcea groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.group.name", 0, CMD_CHOOSE_GROUP, ureq.getLocale())); groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.group.desc", 1, null, ureq.getLocale())); - Translator defaultContextTranslator = new PackageTranslator(Util.getPackageName(BGContextTableModel.class), ureq.getLocale()); // loop over all groups to filter depending on condition List<BusinessGroup> currentGroups = new ArrayList<BusinessGroup>(); for (BusinessGroup group:coachedGroups) { @@ -687,7 +682,7 @@ AssessmentMainController(UserRequest ureq, WindowControl wControl, OLATResourcea currentGroups.add(group); } } - GroupAndContextTableModel groupTableDataModel = new GroupAndContextTableModel(currentGroups, defaultContextTranslator); + GroupAndContextTableModel groupTableDataModel = new GroupAndContextTableModel(currentGroups); groupListCtr.setTableDataModel(groupTableDataModel); groupChoose.put("grouplisttable", groupListCtr.getInitialComponent()); diff --git a/src/main/java/org/olat/course/assessment/GroupAndContextTableModel.java b/src/main/java/org/olat/course/assessment/GroupAndContextTableModel.java index 9b65e2aaf1e..17cef978ca2 100644 --- a/src/main/java/org/olat/course/assessment/GroupAndContextTableModel.java +++ b/src/main/java/org/olat/course/assessment/GroupAndContextTableModel.java @@ -29,11 +29,8 @@ import java.util.List; import org.apache.commons.lang.StringEscapeUtils; import org.olat.core.gui.components.table.DefaultTableDataModel; -import org.olat.core.gui.components.table.TableDataModel; -import org.olat.core.gui.translator.Translator; import org.olat.core.util.Formatter; import org.olat.core.util.filter.FilterFactory; -import org.olat.course.groupsandrights.ui.DefaultContextTranslationHelper; import org.olat.group.BusinessGroup; /** @@ -45,18 +42,16 @@ import org.olat.group.BusinessGroup; * * @author gnaegi */ -public class GroupAndContextTableModel extends DefaultTableDataModel implements TableDataModel { +public class GroupAndContextTableModel extends DefaultTableDataModel<BusinessGroup> { private static final int COLUMN_COUNT = 4; - private Translator trans; /** * Constructor for the group and context table model * @param groups * @param trans translator for the business group context */ - public GroupAndContextTableModel(List groups, Translator trans) { + public GroupAndContextTableModel(List<BusinessGroup> groups) { super(groups); - this.trans = trans; } /** @@ -70,7 +65,7 @@ public class GroupAndContextTableModel extends DefaultTableDataModel implements * @see org.olat.core.gui.components.table.TableDataModel#getValueAt(int, int) */ public Object getValueAt(int row, int col) { - BusinessGroup businessGroup = (BusinessGroup) objects.get(row); + BusinessGroup businessGroup = objects.get(row); switch (col) { case 0 : return StringEscapeUtils.escapeHtml(businessGroup.getName()).toString(); @@ -93,7 +88,7 @@ public class GroupAndContextTableModel extends DefaultTableDataModel implements * @return the business group at the given row */ public BusinessGroup getBusinessGroupAt(int row) { - return (BusinessGroup) objects.get(row); + return objects.get(row); } } \ No newline at end of file diff --git a/src/main/java/org/olat/course/condition/ConditionEditController.java b/src/main/java/org/olat/course/condition/ConditionEditController.java index 648c6b94c43..8e8877c46e5 100644 --- a/src/main/java/org/olat/course/condition/ConditionEditController.java +++ b/src/main/java/org/olat/course/condition/ConditionEditController.java @@ -43,7 +43,6 @@ import org.olat.core.util.Util; import org.olat.course.editor.EditorMainController; import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.run.userview.UserCourseEnvironment; -import org.olat.group.ui.context.BGContextEvent; /** * Initial Date: Apr 7, 2004 * @author gnaegi @@ -126,12 +125,6 @@ public class ConditionEditController extends BasicController { // this event goes to the NodeEditController and from there to the // CourseEditorController which then saves the condition fireEvent(ureq, Event.CHANGED_EVENT); - }else if(event instanceof BGContextEvent){ - //fired by condition easy ctrllr in the case a group/area was created - //within default context. As more then one condition edit controller - //may be on the screen -> see Forum node => those most be informed about - //the changed condition, e.g. toggle the create link to choose link. - fireEvent(ureq, event); } } else if (source == conditionExpertForm) { if (event == Event.CANCELLED_EVENT) { diff --git a/src/main/java/org/olat/course/editor/EditorMainController.java b/src/main/java/org/olat/course/editor/EditorMainController.java index aaa8e534db9..acd07815402 100644 --- a/src/main/java/org/olat/course/editor/EditorMainController.java +++ b/src/main/java/org/olat/course/editor/EditorMainController.java @@ -105,7 +105,6 @@ import org.olat.course.run.preview.PreviewConfigController; import org.olat.course.tree.CourseEditorTreeModel; import org.olat.course.tree.CourseEditorTreeNode; import org.olat.course.tree.CourseInternalLinkTreeModel; -import org.olat.group.ui.context.BGContextEvent; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; import org.olat.testutils.codepoints.server.Codepoint; @@ -503,10 +502,6 @@ public class EditorMainController extends MainLayoutBasicController implements G * org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event) */ public void event(UserRequest ureq, Controller source, Event event) { - if (event.getCommand().equals(BGContextEvent.RESOURCE_ADDED)) { - return; - } - try { ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId()); diff --git a/src/main/java/org/olat/course/editor/NodeEditController.java b/src/main/java/org/olat/course/editor/NodeEditController.java index e486599b2d0..8bff9cad082 100644 --- a/src/main/java/org/olat/course/editor/NodeEditController.java +++ b/src/main/java/org/olat/course/editor/NodeEditController.java @@ -46,7 +46,6 @@ import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.nodes.CourseNode; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.course.tree.CourseEditorTreeModel; -import org.olat.group.ui.context.BGContextEvent; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; import org.olat.util.logging.activity.LoggingResourceable; @@ -194,9 +193,6 @@ public class NodeEditController extends ActivateableTabbableDefaultController im fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT); } - if (event.getCommand().equals(BGContextEvent.RESOURCE_ADDED)) { - System.out.println("nec:resource added"); - } // do logging ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_EDITED, getClass()); } diff --git a/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java b/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java index e24a9d4acd3..fd10020ed79 100644 --- a/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java +++ b/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java @@ -68,17 +68,6 @@ public interface CourseGroupManager { */ public boolean hasRight(Identity identity, String courseRight); - /** - * Checks users course rights in the specified right group context of this - * course - * - * @param identity - * @param courseRight - * @param groupContextName - * @return true if user has course right, false otherwhise - */ - public boolean hasRight(Identity identity, String courseRight, String groupContextName); - /** * Checks if an identity is in a learning group with the given name in any * contexts of this course, either as owner or as participant @@ -89,17 +78,6 @@ public interface CourseGroupManager { */ public boolean isIdentityInLearningGroup(Identity identity, String groupName); - /** - * Checks if an identity is in a learning group with the given name in the the - * given group context of this course, either as owner or as participant - * - * @param identity - * @param groupName - * @param groupContextName - * @return true if user is in learning group, false otherwhise - */ - //public boolean isIdentityInLearningGroup(Identity identity, String groupName, String groupContextName); - /** * Checks whether a set of learning groups with an identical name are full or not. * @@ -119,17 +97,6 @@ public interface CourseGroupManager { */ public boolean isIdentityInRightGroup(Identity identity, String groupName); - /** - * Checks if an identity is in a right group with the given name in the the - * given group context of this course - * - * @param identity - * @param groupName - * @param groupContextName - * @return true if user is in right group, false otherwhise - */ - //public boolean isIdentityInRightGroup(Identity identity, String groupName, String groupContextName); - /** * Checks if an identity is in any learning areas with the given name in any * of the courses group contexts @@ -140,26 +107,6 @@ public interface CourseGroupManager { */ public boolean isIdentityInLearningArea(Identity identity, String areaName); - /** - * Checks if an identity is in a learning areas with the given name in the - * given group context - * - * @param identity - * @param areaName - * @param groupContextName - * @return true if user is in such an area, false otherwhise - */ - public boolean isIdentityInLearningArea(Identity identity, String areaName, String groupContextName); - - /** - * Checks if an identity is in the given group context - * - * @param identity - * @param groupContextName - * @return true if user is in this context, false otherwhise - */ - public boolean isIdentityInGroupContext(Identity identity, String groupContextName); - /** * Checks if user is coach in any of the courses learning groups * @@ -286,24 +233,6 @@ public interface CourseGroupManager { */ public void deleteCourseGroupmanagement(); - /** - * Initializes the course groupmanagement. This will create the initial - * default learning and right group contexts. - * - * @param courseTitle - */ - public void createCourseGroupmanagement(String courseTitle); - - /** - * Initializes the course groupmanagement as a copy of another course. This - * will copy the initial default learning and right group contexts and add the - * references to all other group contexts. - * - * @param originalCourseGroupManager - * @param courseTitle - */ - public void createCourseGroupmanagementAsCopy(CourseGroupManager originalCourseGroupManager, String courseTitle); - /** * Method to count group memberships. Only participants will be counted, no * the owners. diff --git a/src/main/java/org/olat/course/groupsandrights/CourseRights.java b/src/main/java/org/olat/course/groupsandrights/CourseRights.java index c55238ad876..c44c644431b 100644 --- a/src/main/java/org/olat/course/groupsandrights/CourseRights.java +++ b/src/main/java/org/olat/course/groupsandrights/CourseRights.java @@ -29,7 +29,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import org.olat.core.gui.translator.PackageTranslator; import org.olat.core.gui.translator.Translator; import org.olat.core.util.Util; import org.olat.group.right.BGRightManager; @@ -60,12 +59,12 @@ public class CourseRights implements BGRights { /** course right for statistics tool */ public static final String RIGHT_STATISTICS = BGRightManager.BG_RIGHT_PREFIX + "statistics"; - private static List rights; + private static List<String> rights; private Translator trans; static { // initialize list of valid course rights - rights = new ArrayList(); + rights = new ArrayList<String>(); rights.add(RIGHT_GROUPMANAGEMENT); rights.add(RIGHT_COURSEEDITOR); rights.add(RIGHT_ARCHIVING); @@ -80,7 +79,7 @@ public class CourseRights implements BGRights { * @param locale */ public CourseRights(Locale locale) { - this.trans = new PackageTranslator(Util.getPackageName(CourseRights.class),locale); + this.trans = Util.createPackageTranslator(CourseRights.class,locale); } /** @@ -119,7 +118,7 @@ public class CourseRights implements BGRights { /** * @see org.olat.group.right.BGRights#getRights() */ - public List getRights() { + public List<String> getRights() { return rights; } diff --git a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java index 8707604a778..8655fa97fbc 100644 --- a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java +++ b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java @@ -119,14 +119,6 @@ public class PersistingCourseGroupManager extends BasicManager implements Course * java.lang.String) */ public boolean hasRight(Identity identity, String courseRight) { - return hasRight(identity, courseRight, null); - } - - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#hasRight(org.olat.core.id.Identity, - * java.lang.String, java.lang.String) - */ - public boolean hasRight(Identity identity, String courseRight, String groupContextName) { boolean hasRight = rightManager.hasBGRight(courseRight, identity, courseResource); return hasRight; } @@ -193,22 +185,9 @@ public class PersistingCourseGroupManager extends BasicManager implements Course * java.lang.String) */ public boolean isIdentityInLearningArea(Identity identity, String areaName) { - return isIdentityInLearningArea(identity, areaName, null); - } - - @Override - public boolean isIdentityInLearningArea(Identity identity, String areaName, String groupContextName) { return areaManager.isIdentityInBGArea(identity, areaName, courseResource); } - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#isIdentityInGroupContext(org.olat.core.id.Identity, - * java.lang.String) - */ - public boolean isIdentityInGroupContext(Identity identity, String groupContextName) { - return businessGroupService.isIdentityInBusinessGroup(identity, null, null, true, true, courseResource); - } - /** * @see org.olat.course.groupsandrights.CourseGroupManager#getRightGroupsFromAllContexts(java.lang.String) */ @@ -391,62 +370,6 @@ public class PersistingCourseGroupManager extends BasicManager implements Course return businessGroupService.isIdentityInBusinessGroup(identity, null, BusinessGroup.TYPE_RIGHTGROUP, false, true, courseResource); } - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#createCourseGroupmanagement(java.lang.String) - */ - public void createCourseGroupmanagement(String courseTitle) { - //nothing to do - } - - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#createCourseGroupmanagementAsCopy(org.olat.course.groupsandrights.CourseGroupManager, - * java.lang.String) - */ - public void createCourseGroupmanagementAsCopy(CourseGroupManager originalCourseGroupManager, String courseTitle) { - //TODO gm - // wrap as transatcion: do everything or nothing -/* - // 1. do copy learning group contexts - int count = 0; - BGContextManager contextManager = BGContextManagerImpl.getInstance(); - List<BGContext> origLgC = originalCourseGroupManager.getLearningGroupContexts(); - for (BGContext origContext:origLgC) { - if (origContext.isDefaultContext()) { - // we found default context, copy this one - String learningGroupContextName = CourseGroupManager.DEFAULT_NAME_LC_PREFIX + courseTitle; - contextManager.copyAndAddBGContextToResource(learningGroupContextName, this.courseResource, origContext); - // no need to add it to list of contexts, already done by copyAndAddBGContextToResource - } else { - // not a course default context but an associated context - copy only - // reference - contextManager.addBGContextToResource(origContext, courseResource); - // no need to add it to list of contexts, already done by addBGContextToResource - } - if(count++ % 2 == 0) { - DBFactory.getInstance().intermediateCommit(); - } - } - - // 2. do copy right group contexts - List<BGContext> origRgC = originalCourseGroupManager.getRightGroupContexts(); - for (BGContext origContext:origRgC) { - if (origContext.isDefaultContext()) { - // we found default context, copy this one - String rightGroupContextName = CourseGroupManager.DEFAULT_NAME_RC_PREFIX + courseTitle; - contextManager.copyAndAddBGContextToResource(rightGroupContextName, this.courseResource, origContext); - // no need to add it to list of contexts, already done by copyAndAddBGContextToResource - } else { - // not a course default context but an associated context - copy only - // reference - contextManager.addBGContextToResource(origContext, courseResource); - // no need to add it to list of contexts, already done by addBGContextToResource - } - if(count++ % 2 == 0) { - DBFactory.getInstance().intermediateCommit(); - } - }*/ - } - /** * @see org.olat.course.groupsandrights.CourseGroupManager#deleteCourseGroupmanagement() */ diff --git a/src/main/java/org/olat/course/groupsandrights/ui/CourseGroupManagementMainController.java b/src/main/java/org/olat/course/groupsandrights/ui/CourseGroupManagementMainController.java index 96828aff20b..852dc884527 100644 --- a/src/main/java/org/olat/course/groupsandrights/ui/CourseGroupManagementMainController.java +++ b/src/main/java/org/olat/course/groupsandrights/ui/CourseGroupManagementMainController.java @@ -31,14 +31,9 @@ import org.olat.core.commons.fullWebApp.LayoutMain3ColsController; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.panel.Panel; -import org.olat.core.gui.components.table.BooleanColumnDescriptor; -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.TableGuiConfiguration; -import org.olat.core.gui.components.tree.GenericTreeModel; -import org.olat.core.gui.components.tree.GenericTreeNode; import org.olat.core.gui.components.tree.MenuTree; import org.olat.core.gui.components.velocity.VelocityContainer; import org.olat.core.gui.control.Controller; @@ -46,28 +41,16 @@ import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.controller.MainLayoutBasicController; import org.olat.core.gui.control.generic.tool.ToolController; -import org.olat.core.gui.control.generic.tool.ToolFactory; -import org.olat.core.gui.translator.PackageTranslator; -import org.olat.core.gui.translator.Translator; import org.olat.core.id.OLATResourceable; -import org.olat.core.logging.AssertException; import org.olat.core.logging.activity.ActionType; import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; -import org.olat.core.util.Util; import org.olat.course.CourseFactory; import org.olat.course.ICourse; import org.olat.course.groupsandrights.CourseGroupManager; -import org.olat.group.BusinessGroup; import org.olat.group.GroupLoggingAction; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; import org.olat.group.ui.BGControllerFactory; -import org.olat.group.ui.context.BGContextEditController; -import org.olat.group.ui.context.BGContextTableModel; import org.olat.group.ui.management.BGManagementController; import org.olat.resource.OLATResource; -import org.olat.resource.OLATResourceManager; import org.olat.util.logging.activity.LoggingResourceable; /** @@ -80,20 +63,14 @@ import org.olat.util.logging.activity.LoggingResourceable; */ public class CourseGroupManagementMainController extends MainLayoutBasicController { private static final String CMD_CLOSE = "cmd.close"; - private static final String CMD_CONTEXT_RUN = "cmd.context.run"; private Panel content; private LayoutMain3ColsController columnLayoutCtr; - private MenuTree olatMenuTree; private ToolController toolC; - - private VelocityContainer contextListVC; private TableController contextListCtr; - private BGContextTableModel contextTableModel; private BGManagementController groupManageCtr; - private String groupType; private OLATResourceable ores; /** @@ -110,96 +87,26 @@ public class CourseGroupManagementMainController extends MainLayoutBasicControll getUserActivityLogger().setStickyActionType(ActionType.admin); this.ores = ores; - this.groupType = groupType; // set user activity logger for this controller ICourse course = CourseFactory.loadCourse(ores); addLoggingResourceable(LoggingResourceable.wrap(course)); CourseGroupManager groupManager = course.getCourseEnvironment().getCourseGroupManager(); + OLATResource courseResource = groupManager.getCourseResource(); - List groupContexts; - String defaultContextName; - // init content panel. current panel content will be set later in init process, use null for now content = putInitialPanel(null); -/* - if (BusinessGroup.TYPE_LEARNINGROUP.equals(groupType)) { - groupContexts = groupManager.getLearningGroupContexts(); - defaultContextName = CourseGroupManager.DEFAULT_NAME_LC_PREFIX + course.getCourseTitle(); - } else if (BusinessGroup.TYPE_RIGHTGROUP.equals(groupType)) { - groupContexts = groupManager.getRightGroupContexts(); - defaultContextName = CourseGroupManager.DEFAULT_NAME_RC_PREFIX + course.getCourseTitle(); - } else { - throw new AssertException("Invalid group type ::" + groupType); - } - - if (groupContexts.size() == 0) { - // create new default context if none exists - BGContextManager contextManager = BGContextManagerImpl.getInstance(); - OLATResource courseResource = OLATResourceManager.getInstance().findOrPersistResourceable(course); - BGContext context = contextManager.createAndAddBGContextToResource(defaultContextName, courseResource, groupType, null, true); - groupContexts.add(context); - doInitGroupmanagement(ureq, context, false); - } else if (groupContexts.size() == 1) { - BGContext context = (BGContext) groupContexts.get(0); - doInitGroupmanagement(ureq, context, false); - } else { - // multiple, show list first - Translator fallback = new PackageTranslator(Util.getPackageName(BGContextEditController.class), ureq.getLocale()); - setTranslator(Util.createPackageTranslator(this.getClass(), ureq.getLocale(), fallback)); - doInitContextListLayout(ureq); - doInitContextList(ureq, groupContexts); - }*/ - - } - private void doInitContextListLayout(UserRequest ureq) { - // Layout is controlled with generic controller: menu - content - tools to - // look the same as in the groupmanagement - // 1) menu - olatMenuTree = new MenuTree("olatMenuTree"); - GenericTreeModel gtm = new GenericTreeModel(); - GenericTreeNode root = new GenericTreeNode(); - if (groupType.equals(BusinessGroup.TYPE_RIGHTGROUP)) { - root.setTitle(translate("rightmanagement.index")); - root.setAltText(translate("rightmanagement.index.alt")); - } else { - root.setTitle(translate("groupmanagement.index")); - root.setAltText(translate("groupmanagement.index.alt")); - } - gtm.setRootNode(root); - olatMenuTree.setTreeModel(gtm); - olatMenuTree.setSelectedNodeId(gtm.getRootNode().getIdent()); - // 2) context list - contextListVC = createVelocityContainer("contextlist"); - // 3) tools - toolC = ToolFactory.createToolController(getWindowControl()); - listenTo(toolC); - if (groupType.equals(BusinessGroup.TYPE_RIGHTGROUP)) toolC.addHeader(translate("tools.title.rightmanagement")); - else toolC.addHeader(translate("tools.title.groupmanagement")); - toolC.addLink(CMD_CLOSE, translate(CMD_CLOSE), null, "b_toolbox_close"); - // now build layout controller - columnLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), olatMenuTree, toolC.getInitialComponent(), contextListVC, null); - listenTo(columnLayoutCtr); // cleanup on dispose + removeAsListenerAndDispose(groupManageCtr); + groupManageCtr = BGControllerFactory.getInstance().createManagementController(ureq, getWindowControl(), courseResource, false); + listenTo(groupManageCtr); + content.setContent(groupManageCtr.getInitialComponent()); + + // logging + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUPMANAGEMENT_START, getClass()); } - private void doInitContextList(UserRequest ureq, List groupContexts) { - TableGuiConfiguration tableConfig = new TableGuiConfiguration(); - tableConfig.setTableEmptyMessage(translate("contextlist.no.contexts")); - // init group list filter controller - removeAsListenerAndDispose(contextListCtr); - contextListCtr = new TableController(tableConfig, ureq, getWindowControl(), getTranslator()); - listenTo(contextListCtr); - contextListCtr.addColumnDescriptor(new DefaultColumnDescriptor("contextlist.table.name", 0, CMD_CONTEXT_RUN, ureq.getLocale())); - contextListCtr.addColumnDescriptor(new DefaultColumnDescriptor("contextlist.table.desc", 1, null, ureq.getLocale())); - contextListCtr.addColumnDescriptor(new BooleanColumnDescriptor("contextlist.table.default", 2, null, - translate("contextlist.table.default.true"), translate("contextlist.table.default.false"))); - contextListVC.put("contextlist", contextListCtr.getInitialComponent()); - contextTableModel = new BGContextTableModel(groupContexts, getTranslator(), false, true); - contextListCtr.setTableDataModel(contextTableModel); - content.setContent(columnLayoutCtr.getInitialComponent()); - } /** * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, @@ -240,10 +147,10 @@ public class CourseGroupManagementMainController extends MainLayoutBasicControll TableEvent te = (TableEvent) event; String actionid = te.getActionId(); int rowid = te.getRowId(); - BGContext context = contextTableModel.getGroupContextAt(rowid); + /*BGContext context = contextTableModel.getGroupContextAt(rowid); if (actionid.equals(CMD_CONTEXT_RUN)) { doInitGroupmanagement(ureq, context, true); - } + }*/ } } else if (source == toolC) { if (event.getCommand().equals(CMD_CLOSE)) { @@ -253,18 +160,6 @@ public class CourseGroupManagementMainController extends MainLayoutBasicControll } - private void doInitGroupmanagement(UserRequest ureq, BGContext groupContext, boolean contextSelectSwitch) { - // launch generic group management controller - removeAsListenerAndDispose(groupManageCtr); - groupManageCtr = BGControllerFactory.getInstance().createManagementController(ureq, getWindowControl(), groupContext, contextSelectSwitch); - listenTo(groupManageCtr); - content.setContent(groupManageCtr.getInitialComponent()); - - // logging - addLoggingResourceable(LoggingResourceable.wrap(groupContext)); - ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUPMANAGEMENT_START, getClass()); - } - /** * @see org.olat.core.gui.control.DefaultController#doDispose(boolean) */ diff --git a/src/main/java/org/olat/course/nodes/_spring/buildingblockContext.xml b/src/main/java/org/olat/course/nodes/_spring/buildingblockContext.xml index c45e999a669..9f3b10fd03d 100644 --- a/src/main/java/org/olat/course/nodes/_spring/buildingblockContext.xml +++ b/src/main/java/org/olat/course/nodes/_spring/buildingblockContext.xml @@ -9,6 +9,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config /> + <context:component-scan base-package="org.olat.course.nodes.en" /> <!-- Course node spring config: Course Nodes are searched on the whole classpath, just place your CourceNodeConfiguration somewhere on the classpath best as a jar. The xml file with ending ...Context.xml has do to be outside of the jar to get automatically loaded --> diff --git a/src/main/java/org/olat/course/nodes/bc/BCCourseNodeEditController.java b/src/main/java/org/olat/course/nodes/bc/BCCourseNodeEditController.java index e53d84816b8..6460ae6f904 100644 --- a/src/main/java/org/olat/course/nodes/bc/BCCourseNodeEditController.java +++ b/src/main/java/org/olat/course/nodes/bc/BCCourseNodeEditController.java @@ -51,7 +51,6 @@ import org.olat.course.condition.ConditionEditController; import org.olat.course.editor.NodeEditController; import org.olat.course.nodes.BCCourseNode; import org.olat.course.run.userview.UserCourseEnvironment; -import org.olat.group.ui.context.BGContextEvent; /** * Initial Date: Apr 28, 2004 diff --git a/src/main/java/org/olat/course/nodes/en/ENRunController.java b/src/main/java/org/olat/course/nodes/en/ENRunController.java index 9314946cee1..9ff1819252e 100644 --- a/src/main/java/org/olat/course/nodes/en/ENRunController.java +++ b/src/main/java/org/olat/course/nodes/en/ENRunController.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.table.BooleanColumnDescriptor; @@ -113,7 +114,7 @@ public class ENRunController extends BasicController implements GenericEventList //this.trans = new PackageTranslator(PACKAGE, ureq.getLocale()); // init managers - this.enrollmentManager = EnrollmentManager.getInstance(); + enrollmentManager = CoreSpringFactory.getImpl(EnrollmentManager.class); this.courseGroupManager = userCourseEnv.getCourseEnvironment().getCourseGroupManager(); this.coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager(); diff --git a/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java b/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java index 14f1ed30c74..d73432782be 100644 --- a/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java +++ b/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java @@ -30,7 +30,6 @@ import java.util.Iterator; import java.util.List; import org.olat.basesecurity.BaseSecurity; -import org.olat.basesecurity.BaseSecurityManager; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.translator.Translator; @@ -50,12 +49,13 @@ import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.nodes.ENCourseNode; import org.olat.course.properties.CoursePropertyManager; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGConfigFlags; import org.olat.group.ui.BGMailHelper; import org.olat.properties.Property; import org.olat.testutils.codepoints.server.Codepoint; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; /** * Description:<BR> @@ -67,28 +67,14 @@ import org.olat.testutils.codepoints.server.Codepoint; * * @author Christian Guretzki */ -public class EnrollmentManager extends BasicManager { - // TODO with spring - static final EnrollmentManager enrollmentManager = new EnrollmentManager(); - // Managers TODO inject with spring - private BaseSecurity securityManager; - private BusinessGroupManager businessGroupManager; +@Service("enrollmentManager") +public class EnrollmentManager extends BasicManager { - /** - * @param moduleConfiguration - * @param ureq - * @param wControl - * @param userCourseEnv - * @param enNode - */ - private EnrollmentManager() { - this.securityManager = BaseSecurityManager.getInstance(); - this.businessGroupManager = BusinessGroupManagerImpl.getInstance(); - } + @Autowired + private BaseSecurity securityManager; + @Autowired + private BusinessGroupService businessGroupService; - public static EnrollmentManager getInstance() { - return enrollmentManager; - } public EnrollStatus doEnroll(final Identity identity, final BusinessGroup group, final ENCourseNode enNode, final CoursePropertyManager coursePropertyManager, final WindowControl wControl, final Translator trans, List groupNames, List areaNames, CourseGroupManager cgm) { @@ -156,8 +142,8 @@ public class EnrollmentManager extends BasicManager { public void execute() { // Remove participant. This will also check if a waiting-list with auto-close-ranks is configurated // and move the users accordingly - businessGroupManager.removeParticipantAndFireEvent(identity, identity, enrolledGroup, flags, false); - Tracing.logInfo("doCancelEnrollment in group " + enrolledGroup, identity.getName() , EnrollmentManager.class); + businessGroupService.removeParticipant(identity, identity, enrolledGroup, flags); + logInfo("doCancelEnrollment in group " + enrolledGroup, identity.getName()); // 2. Remove enrollmentdate property // only remove last time date, not firsttime Property lastTime = coursePropertyManager @@ -182,7 +168,7 @@ public class EnrollmentManager extends BasicManager { // 1. Remove group membership, fire events, do loggin etc. CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(enrolledWaitingListGroup, new SyncerExecutor(){ public void execute() { - businessGroupManager.removeFromWaitingListAndFireEvent(identity, identity, enrolledWaitingListGroup, false); + businessGroupService.removeFromWaitingList(identity, identity, enrolledWaitingListGroup); // 2. Remove enrollmentdate property // only remove last time date, not firsttime Property lastTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, @@ -316,7 +302,7 @@ public class EnrollmentManager extends BasicManager { CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(group); // 1. Add user to group, fire events, do loggin etc. BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - businessGroupManager.addParticipantAndFireEvent(identity, identity, group, flags, false); + businessGroupService.addParticipant(identity, identity, group, flags); // 2. Set first enrollment date String nowString = Long.toString(System.currentTimeMillis()); Property firstTime = coursePropertyManager @@ -354,7 +340,7 @@ public class EnrollmentManager extends BasicManager { CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) { CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(group); // 1. Add user to group, fire events, do loggin etc. - businessGroupManager.addToWaitingListAndFireEvent(identity, identity, group, false); + businessGroupService.addToWaitingList(identity, identity, group); // 2. Set first waiting-list date String nowString = Long.toString(System.currentTimeMillis()); Property firstTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, diff --git a/src/main/java/org/olat/course/nodes/fo/FOCourseNodeEditController.java b/src/main/java/org/olat/course/nodes/fo/FOCourseNodeEditController.java index 45a88e1ae4a..eeb5d4239c2 100644 --- a/src/main/java/org/olat/course/nodes/fo/FOCourseNodeEditController.java +++ b/src/main/java/org/olat/course/nodes/fo/FOCourseNodeEditController.java @@ -43,7 +43,6 @@ import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.nodes.FOCourseNode; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.course.tree.CourseEditorTreeModel; -import org.olat.group.ui.context.BGContextEvent; /** * Initial Date: Apr 7, 2004 diff --git a/src/main/java/org/olat/course/nodes/projectbroker/ProjectBrokerCourseEditorController.java b/src/main/java/org/olat/course/nodes/projectbroker/ProjectBrokerCourseEditorController.java index b0c294e8386..3bbbf7cfefb 100644 --- a/src/main/java/org/olat/course/nodes/projectbroker/ProjectBrokerCourseEditorController.java +++ b/src/main/java/org/olat/course/nodes/projectbroker/ProjectBrokerCourseEditorController.java @@ -29,12 +29,12 @@ import org.olat.admin.quota.QuotaConstants; import org.olat.admin.securitygroup.gui.GroupController; import org.olat.admin.securitygroup.gui.IdentitiesAddEvent; import org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent; +import org.olat.core.CoreSpringFactory; import org.olat.core.commons.modules.bc.FolderRunController; import org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl; import org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; - import org.olat.core.gui.components.link.Link; import org.olat.core.gui.components.link.LinkFactory; import org.olat.core.gui.components.tabbedpane.TabbedPane; @@ -74,7 +74,7 @@ import org.olat.course.properties.CoursePropertyManager; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupAddResponse; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGConfigFlags; import org.olat.group.ui.BGMailHelper; import org.olat.modules.ModuleConfiguration; @@ -129,6 +129,8 @@ public class ProjectBrokerCourseEditorController extends ActivateableTabbableDef private CloseableModalController cmc; private Long projectBrokerId; + private final BusinessGroupService businessGroupService; + /** * @param ureq * @param wControl @@ -139,6 +141,8 @@ public class ProjectBrokerCourseEditorController extends ActivateableTabbableDef protected ProjectBrokerCourseEditorController(UserRequest ureq, WindowControl wControl, ICourse course, ProjectBrokerCourseNode node, CourseGroupManager groupMgr, UserCourseEnvironment euce) { super(ureq, wControl); + + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); this.node = node; //o_clusterOk by guido: save to hold reference to course inside editor @@ -298,14 +302,14 @@ public class ProjectBrokerCourseEditorController extends ActivateableTabbableDef BGConfigFlags flags = BGConfigFlags.createRightGroupDefaultFlags(); if (event instanceof IdentitiesAddEvent) { IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent)event; - BusinessGroupAddResponse response = BusinessGroupManagerImpl.getInstance().addParticipantsAndFireEvent(urequest.getIdentity(), identitiesAddedEvent.getAddIdentities(), accountManagerGroup, flags); + BusinessGroupAddResponse response = businessGroupService.addParticipants(urequest.getIdentity(), identitiesAddedEvent.getAddIdentities(), accountManagerGroup, flags); identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities()); identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission()); identitiesAddedEvent.setIdentitiesAlreadyInGroup(response.getIdentitiesAlreadyInGroup()); getLogger().info("Add users as account-managers"); fireEvent(urequest, Event.CHANGED_EVENT ); } else if (event instanceof IdentitiesRemoveEvent) { - BusinessGroupManagerImpl.getInstance().removeParticipantsAndFireEvent(urequest.getIdentity(), ((IdentitiesRemoveEvent) event).getRemovedIdentities(), accountManagerGroup, flags); + businessGroupService.removeParticipants(urequest.getIdentity(), ((IdentitiesRemoveEvent) event).getRemovedIdentities(), accountManagerGroup, flags); getLogger().info("Remove users as account-managers"); fireEvent(urequest, Event.CHANGED_EVENT ); } diff --git a/src/main/java/org/olat/course/nodes/projectbroker/ProjectGroupController.java b/src/main/java/org/olat/course/nodes/projectbroker/ProjectGroupController.java index 87473830e5f..5bbc149e362 100644 --- a/src/main/java/org/olat/course/nodes/projectbroker/ProjectGroupController.java +++ b/src/main/java/org/olat/course/nodes/projectbroker/ProjectGroupController.java @@ -33,6 +33,7 @@ import org.olat.admin.securitygroup.gui.IdentitiesAddEvent; import org.olat.admin.securitygroup.gui.IdentitiesMoveEvent; import org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent; import org.olat.admin.securitygroup.gui.WaitingGroupController; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.velocity.VelocityContainer; @@ -52,7 +53,7 @@ import org.olat.course.nodes.projectbroker.datamodel.Project; import org.olat.course.nodes.projectbroker.service.ProjectBrokerManagerFactory; import org.olat.course.nodes.projectbroker.service.ProjectBrokerModuleConfiguration; import org.olat.group.BusinessGroupAddResponse; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGConfigFlags; /** @@ -69,6 +70,8 @@ public class ProjectGroupController extends BasicController { private Project project; private ProjectBrokerModuleConfiguration projectBrokerModuleConfiguration; + + private final BusinessGroupService businessGroupService; /** * @param ureq @@ -78,6 +81,7 @@ public class ProjectGroupController extends BasicController { public ProjectGroupController(UserRequest ureq, WindowControl wControl, Project project, ProjectBrokerModuleConfiguration projectBrokerModuleConfiguration) { super(ureq, wControl); getUserActivityLogger().setStickyActionType(ActionType.admin); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); this.project = project; this.projectBrokerModuleConfiguration = projectBrokerModuleConfiguration; @@ -137,7 +141,6 @@ public class ProjectGroupController extends BasicController { } private void handleCandidateGroupEvent(UserRequest urequest, Event event) { - BGConfigFlags flags = BGConfigFlags.createRightGroupDefaultFlags(); if (event instanceof IdentitiesAddEvent) { IdentitiesAddEvent identitiesAddEvent = (IdentitiesAddEvent)event; List<Identity> addedIdentities = ProjectBrokerManagerFactory.getProjectGroupManager().addCandidates(identitiesAddEvent.getAddIdentities(), project); @@ -181,14 +184,14 @@ public class ProjectGroupController extends BasicController { BGConfigFlags flags = BGConfigFlags.createRightGroupDefaultFlags(); if (event instanceof IdentitiesAddEvent) { IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent)event; - BusinessGroupAddResponse response = BusinessGroupManagerImpl.getInstance().addParticipantsAndFireEvent(urequest.getIdentity(), identitiesAddedEvent.getAddIdentities(), project.getProjectGroup(), flags); + BusinessGroupAddResponse response = businessGroupService.addParticipants(urequest.getIdentity(), identitiesAddedEvent.getAddIdentities(), project.getProjectGroup(), flags); identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities()); identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission()); identitiesAddedEvent.setIdentitiesAlreadyInGroup(response.getIdentitiesAlreadyInGroup()); getLogger().info("Add users as project-members"); fireEvent(urequest, Event.CHANGED_EVENT ); } else if (event instanceof IdentitiesRemoveEvent) { - BusinessGroupManagerImpl.getInstance().removeParticipantsAndFireEvent(urequest.getIdentity(), ((IdentitiesRemoveEvent) event).getRemovedIdentities(), project.getProjectGroup(), flags); + businessGroupService.removeParticipants(urequest.getIdentity(), ((IdentitiesRemoveEvent) event).getRemovedIdentities(), project.getProjectGroup(), flags); getLogger().info("Remove users as account-managers"); fireEvent(urequest, Event.CHANGED_EVENT ); } @@ -198,14 +201,14 @@ public class ProjectGroupController extends BasicController { BGConfigFlags flags = BGConfigFlags.createRightGroupDefaultFlags(); if (event instanceof IdentitiesAddEvent) { IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent)event; - BusinessGroupAddResponse response = BusinessGroupManagerImpl.getInstance().addOwnersAndFireEvent(urequest.getIdentity(), identitiesAddedEvent.getAddIdentities(), project.getProjectGroup(), flags); + BusinessGroupAddResponse response = businessGroupService.addOwners(urequest.getIdentity(), identitiesAddedEvent.getAddIdentities(), project.getProjectGroup(), flags); identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities()); identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission()); identitiesAddedEvent.setIdentitiesAlreadyInGroup(response.getIdentitiesAlreadyInGroup()); getLogger().info("Add users as project-leader"); fireEvent(urequest, Event.CHANGED_EVENT ); } else if (event instanceof IdentitiesRemoveEvent) { - BusinessGroupManagerImpl.getInstance().removeOwnersAndFireEvent(urequest.getIdentity(), ((IdentitiesRemoveEvent) event).getRemovedIdentities(), project.getProjectGroup(), flags); + businessGroupService.removeOwners(urequest.getIdentity(), ((IdentitiesRemoveEvent) event).getRemovedIdentities(), project.getProjectGroup(), flags); getLogger().info("Remove users as account-managers"); fireEvent(urequest, Event.CHANGED_EVENT ); } diff --git a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java index 6b1623f4924..6f2e0555317 100644 --- a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java +++ b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java @@ -39,6 +39,7 @@ import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.Type; import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.SecurityGroup; +import org.olat.core.CoreSpringFactory; import org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.id.Identity; @@ -68,7 +69,7 @@ import org.olat.course.nodes.projectbroker.datamodel.ProjectImpl; import org.olat.course.properties.CoursePropertyManager; import org.olat.course.run.environment.CourseEnvironment; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.group.DeletableGroupData; import org.olat.group.DeletableReference; import org.olat.properties.Property; @@ -88,7 +89,7 @@ public class ProjectBrokerManagerImpl extends BasicManager implements ProjectBro protected ProjectBrokerManagerImpl() { // cache name should not be too long e.g. 'projectbroker' is too long, use 'pb' instead. projectCache = CoordinatorManager.getInstance().getCoordinator().getCacher().getOrCreateCache(ProjectBrokerManagerImpl.class, "pb"); - BusinessGroupManagerImpl.getInstance().registerDeletableGroupDataListener(this); + CoreSpringFactory.getImpl(BusinessGroupService.class).registerDeletableGroupDataListener(this); logDebug("ProjectBrokerManagerImpl created"); } diff --git a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java index d3b0a2e7e15..ad4e46720a6 100644 --- a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java +++ b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java @@ -50,7 +50,6 @@ import org.olat.course.properties.CoursePropertyManager; import org.olat.course.run.environment.CourseEnvironment; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupAddResponse; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGConfigFlags; import org.olat.group.ui.edit.BusinessGroupModifiedEvent; @@ -138,7 +137,8 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou if (groupKey != null) { BusinessGroup accountManagerGroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey); if (accountManagerGroup != null) { - BusinessGroupManagerImpl.getInstance().deleteBusinessGroup(accountManagerGroup); + BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + bgs.deleteBusinessGroup(accountManagerGroup); logAudit("ProjectBroker: Deleted accountManagerGroup=" + accountManagerGroup); } else { logDebug("deleteAccountManagerGroup: accountManagerGroup=" + accountManagerGroup + " has already been deleted"); @@ -188,7 +188,8 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou } public void deleteProjectGroupFor(Project project) { - BusinessGroupManagerImpl.getInstance().deleteBusinessGroup(project.getProjectGroup()); + BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + bgs.deleteBusinessGroup(project.getProjectGroup()); } /** @@ -258,13 +259,14 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou Codepoint.codepoint(ProjectBrokerManagerImpl.class, "beforeDoInSync"); final Project reloadedProject = (Project) DBFactory.getInstance().loadObject(project, true); final BusinessGroupAddResponse response = new BusinessGroupAddResponse(); + final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); Boolean result = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(project.getProjectGroup(), new SyncerCallback<Boolean>(){ public Boolean execute() { for (final Identity identity : identities) { if (!BaseSecurityManager.getInstance().isIdentityInSecurityGroup(identity, reloadedProject.getProjectGroup().getPartipiciantGroup())) { BaseSecurityManager.getInstance().removeIdentityFromSecurityGroup(identity, reloadedProject.getCandidateGroup()); final BGConfigFlags flags = BGConfigFlags.createRightGroupDefaultFlags(); - BusinessGroupManagerImpl.getInstance().addParticipantAndFireEvent(actionIdentity, identity, reloadedProject.getProjectGroup(), flags, false); + bgs.addParticipant(actionIdentity, identity, reloadedProject.getProjectGroup(), flags); logAudit("ProjectBroker: Accept candidate, identity=" + identity + " project=" + reloadedProject); response.getAddedIdentities().add(identity); } else { diff --git a/src/main/java/org/olat/course/repository/CreateNewCourseController.java b/src/main/java/org/olat/course/repository/CreateNewCourseController.java index c29ce339e28..bddafe838a9 100644 --- a/src/main/java/org/olat/course/repository/CreateNewCourseController.java +++ b/src/main/java/org/olat/course/repository/CreateNewCourseController.java @@ -38,7 +38,6 @@ import org.olat.core.util.Formatter; import org.olat.course.CourseFactory; import org.olat.course.CourseModule; import org.olat.course.ICourse; -import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.nodes.CourseNode; import org.olat.course.tree.CourseEditorTreeNode; import org.olat.repository.RepositoryEntry; @@ -95,12 +94,7 @@ public class CreateNewCourseController extends BasicController implements IAddCo */ public boolean transactionFinishBeforeCreate() { // Create course and persist course resourceable. - course = CourseFactory.createEmptyCourse( - newCourseResource, "New Course", "New Course", ""); - // initialize course groupmanagement - CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager(); - cgm.createCourseGroupmanagement(course.getResourceableId().toString()); - + course = CourseFactory.createEmptyCourse(newCourseResource, "New Course", "New Course", ""); return true; } diff --git a/src/main/java/org/olat/course/repository/ImportCourseController.java b/src/main/java/org/olat/course/repository/ImportCourseController.java index 7ab3a8aa7db..9abb61c8d5f 100644 --- a/src/main/java/org/olat/course/repository/ImportCourseController.java +++ b/src/main/java/org/olat/course/repository/ImportCourseController.java @@ -124,7 +124,6 @@ public class ImportCourseController extends BasicController implements IAddContr public boolean transactionFinishBeforeCreate() { // create group management CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager(); - cgm.createCourseGroupmanagement(course.getResourceableId().toString()); // import groups cgm.importCourseLearningGroups(getExportDataDir(course)); cgm.importCourseRightGroups(getExportDataDir(course)); diff --git a/src/main/java/org/olat/course/run/RunMainController.java b/src/main/java/org/olat/course/run/RunMainController.java index be75cc8a573..d0b82f62d45 100644 --- a/src/main/java/org/olat/course/run/RunMainController.java +++ b/src/main/java/org/olat/course/run/RunMainController.java @@ -26,7 +26,6 @@ package org.olat.course.run; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -74,7 +73,6 @@ import org.olat.core.id.context.ContextEntry; import org.olat.core.id.context.StateEntry; import org.olat.core.logging.AssertException; import org.olat.core.logging.OLATSecurityException; -import org.olat.core.logging.Tracing; import org.olat.core.logging.activity.CourseLoggingAction; import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; import org.olat.core.util.coordinate.CoordinatorManager; @@ -113,8 +111,6 @@ import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.course.run.userview.UserCourseEnvironmentImpl; import org.olat.course.statistic.StatisticMainController; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGControllerFactory; import org.olat.group.ui.edit.BusinessGroupModifiedEvent; @@ -171,13 +167,13 @@ public class RunMainController extends MainLayoutBasicController implements Gene private boolean isInEditor = false; - private Map courseRightsCache = new HashMap(); + private Map<String, Boolean> courseRightsCache = new HashMap<String, Boolean>(); private boolean isCourseAdmin = false; private boolean isCourseCoach = false; - private List ownedGroups; - private List participatedGroups; - private List waitingListGroups; - private List rightGroups; + private List<BusinessGroup> ownedGroups; + private List<BusinessGroup> participatedGroups; + private List<BusinessGroup> waitingListGroups; + private List<BusinessGroup> rightGroups; private CourseNode currentCourseNode; private TreeModel treeModel; @@ -250,7 +246,7 @@ public class RunMainController extends MainLayoutBasicController implements Gene // log shows who entered which course, this can then be further used to jump // to the courselog - Tracing.logAudit("Entering course: [[["+courseTitle+"]]]", course.getResourceableId().toString(), RunMainController.class); + logAudit("Entering course: [[["+courseTitle+"]]]", course.getResourceableId().toString()); // set up the components all = new Panel("allofcourse"); @@ -1160,9 +1156,7 @@ public class RunMainController extends MainLayoutBasicController implements Gene // 2) add coached groups if (ownedGroups.size() > 0) { myTool.addHeader(translate("header.tools.ownerGroups")); - Iterator iter = ownedGroups.iterator(); - while (iter.hasNext()) { - BusinessGroup group = (BusinessGroup) iter.next(); + for (BusinessGroup group:ownedGroups) { myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(), group.getName()); } } @@ -1170,9 +1164,7 @@ public class RunMainController extends MainLayoutBasicController implements Gene // 3) add participating groups if (participatedGroups.size() > 0) { myTool.addHeader(translate("header.tools.participatedGroups")); - Iterator iter = participatedGroups.iterator(); - while (iter.hasNext()) { - BusinessGroup group = (BusinessGroup) iter.next(); + for (BusinessGroup group: participatedGroups) { myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(), group.getName()); } } @@ -1180,9 +1172,7 @@ public class RunMainController extends MainLayoutBasicController implements Gene // 4) add right groups if (rightGroups.size() > 0) { myTool.addHeader(translate("header.tools.rightGroups")); - Iterator iter = rightGroups.iterator(); - while (iter.hasNext()) { - BusinessGroup group = (BusinessGroup) iter.next(); + for (BusinessGroup group : rightGroups) { myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(), group.getName()); } } @@ -1190,11 +1180,8 @@ public class RunMainController extends MainLayoutBasicController implements Gene // 5) add waiting-list groups if (waitingListGroups.size() > 0) { myTool.addHeader(translate("header.tools.waitingListGroups")); - Iterator iter = waitingListGroups.iterator(); - while (iter.hasNext()) { - BusinessGroup group = (BusinessGroup) iter.next(); - BusinessGroupManager businessGroupManager = BusinessGroupManagerImpl.getInstance(); - int pos = businessGroupManager.getPositionInWaitingListFor(identity, group); + for (BusinessGroup group:waitingListGroups) { + int pos = businessGroupService.getPositionInWaitingListFor(identity, group); myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(), group.getName() + "(" + pos + ")", group .getKey().toString(), null); myTool.setEnabled(group.getKey().toString(), false); diff --git a/src/main/java/org/olat/course/run/preview/PreviewCourseGroupManager.java b/src/main/java/org/olat/course/run/preview/PreviewCourseGroupManager.java index 347bf329bb8..2920af689f4 100644 --- a/src/main/java/org/olat/course/run/preview/PreviewCourseGroupManager.java +++ b/src/main/java/org/olat/course/run/preview/PreviewCourseGroupManager.java @@ -33,6 +33,8 @@ import org.olat.core.logging.AssertException; import org.olat.core.manager.BasicManager; import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.groupsandrights.CourseRights; +import org.olat.group.BusinessGroup; +import org.olat.group.area.BGArea; import org.olat.resource.OLATResource; /** @@ -42,8 +44,8 @@ import org.olat.resource.OLATResource; */ final class PreviewCourseGroupManager extends BasicManager implements CourseGroupManager { - private List groups; - private List areas; + private List<BusinessGroup> groups; + private List<BGArea> areas; private boolean isCoach, isCourseAdmin; /** @@ -52,7 +54,7 @@ final class PreviewCourseGroupManager extends BasicManager implements CourseGrou * @param isCoach * @param isCourseAdmin */ - public PreviewCourseGroupManager(List groups, List areas, boolean isCoach, boolean isCourseAdmin) { + public PreviewCourseGroupManager(List<BusinessGroup> groups, List<BGArea> areas, boolean isCoach, boolean isCourseAdmin) { this.groups = groups; this.areas = areas; this.isCourseAdmin = isCourseAdmin; @@ -81,26 +83,12 @@ final class PreviewCourseGroupManager extends BasicManager implements CourseGrou throw new AssertException("unsupported"); } - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#hasRight(org.olat.core.id.Identity, java.lang.String, java.lang.String) - */ - public boolean hasRight(Identity identity, String courseRight, String groupContextName) { - throw new AssertException("unsupported"); - } - /** * @see org.olat.course.groupsandrights.CourseGroupManager#isIdentityInLearningGroup(org.olat.core.id.Identity, java.lang.String) */ public boolean isIdentityInLearningGroup(Identity identity, String groupName) { return groups.contains(groupName); } - - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#isIdentityInLearningGroup(org.olat.core.id.Identity, java.lang.String, java.lang.String) - */ - public boolean isIdentityInLearningGroup(Identity identity, String groupName, String groupContextName) { - return groups.contains(groupName); - } /** * @see org.olat.course.groupsandrights.CourseGroupManager#isLearningGroupFull(java.lang.String) @@ -116,13 +104,6 @@ final class PreviewCourseGroupManager extends BasicManager implements CourseGrou return groups.contains(groupName); } - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#isIdentityInRightGroup(org.olat.core.id.Identity, java.lang.String, java.lang.String) - */ - public boolean isIdentityInRightGroup(Identity identity, String groupName, String groupContextName) { - return groups.contains(groupName); - } - /** * @see org.olat.course.groupsandrights.CourseGroupManager#isIdentityInLearningArea(org.olat.core.id.Identity, java.lang.String) */ @@ -130,20 +111,6 @@ final class PreviewCourseGroupManager extends BasicManager implements CourseGrou return areas.contains(areaName); } - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#isIdentityInLearningArea(org.olat.core.id.Identity, java.lang.String, java.lang.String) - */ - public boolean isIdentityInLearningArea(Identity identity, String areaName, String groupContextName) { - return areas.contains(areaName); - } - - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#isIdentityInGroupContext(org.olat.core.id.Identity, java.lang.String) - */ - public boolean isIdentityInGroupContext(Identity identity, String groupContextName) { - throw new AssertException("unsupported"); - } - /** * @see org.olat.course.groupsandrights.CourseGroupManager#isIdentityCourseCoach(org.olat.core.id.Identity) */ @@ -177,87 +144,73 @@ final class PreviewCourseGroupManager extends BasicManager implements CourseGrou throw new AssertException("unsupported"); } - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#getLearningGroupContexts() - */ - public List getLearningGroupContexts() { - throw new AssertException("unsupported"); - } - - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#getRightGroupContexts() - */ - public List getRightGroupContexts() { - throw new AssertException("unsupported"); - } - /** * @see org.olat.course.groupsandrights.CourseGroupManager#getAllLearningGroupsFromAllContexts() */ - public List getAllLearningGroupsFromAllContexts() { + public List<BusinessGroup> getAllLearningGroupsFromAllContexts() { return groups; } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getLearningGroupsFromAllContexts(java.lang.String) */ - public List getLearningGroupsFromAllContexts(String groupName) { + public List<BusinessGroup> getLearningGroupsFromAllContexts(String groupName) { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getLearningGroupsInAreaFromAllContexts(java.lang.String) */ - public List getLearningGroupsInAreaFromAllContexts(String areaName) { + public List<BusinessGroup> getLearningGroupsInAreaFromAllContexts(String areaName) { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getParticipatingLearningGroupsFromAllContexts(org.olat.core.id.Identity, java.lang.String) */ - public List getParticipatingLearningGroupsFromAllContexts(Identity identity, String groupName) { + public List<BusinessGroup> getParticipatingLearningGroupsFromAllContexts(Identity identity, String groupName) { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getParticipatingLearningGroupsInAreaFromAllContexts(org.olat.core.id.Identity, java.lang.String) */ - public List getParticipatingLearningGroupsInAreaFromAllContexts(Identity identity, String araName) { + public List<BusinessGroup> getParticipatingLearningGroupsInAreaFromAllContexts(Identity identity, String araName) { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getOwnedLearningGroupsFromAllContexts(org.olat.core.id.Identity) */ - public List getOwnedLearningGroupsFromAllContexts(Identity identity) { + public List<BusinessGroup> getOwnedLearningGroupsFromAllContexts(Identity identity) { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getParticipatingLearningGroupsFromAllContexts(org.olat.core.id.Identity) */ - public List getParticipatingLearningGroupsFromAllContexts(Identity identity) { + public List<BusinessGroup> getParticipatingLearningGroupsFromAllContexts(Identity identity) { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getParticipatingRightGroupsFromAllContexts(org.olat.core.id.Identity) */ - public List getParticipatingRightGroupsFromAllContexts(Identity identity) { + public List<BusinessGroup> getParticipatingRightGroupsFromAllContexts(Identity identity) { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getAllRightGroupsFromAllContexts() */ - public List getAllRightGroupsFromAllContexts() { + public List<BusinessGroup> getAllRightGroupsFromAllContexts() { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getAllAreasFromAllContexts() */ - public List getAllAreasFromAllContexts() { + public List<BGArea> getAllAreasFromAllContexts() { return areas; } @@ -268,61 +221,47 @@ final class PreviewCourseGroupManager extends BasicManager implements CourseGrou throw new AssertException("unsupported"); } - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#createCourseGroupmanagement(java.lang.String) - */ - public void createCourseGroupmanagement(String courseTitle) { - throw new AssertException("unsupported"); - } - - /** - * @see org.olat.course.groupsandrights.CourseGroupManager#createCourseGroupmanagementAsCopy(org.olat.course.groupsandrights.CourseGroupManager, java.lang.String) - */ - public void createCourseGroupmanagementAsCopy(CourseGroupManager originalCourseGroupManager, String courseTitle) { - throw new AssertException("unsupported"); - } - /** * @see org.olat.course.groupsandrights.CourseGroupManager#getNumberOfMembersFromGroups(java.util.List) */ - public List getNumberOfMembersFromGroups(List groupList) { + public List<Integer> getNumberOfMembersFromGroups(List<BusinessGroup> groupList) { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getUniqueLearningGroupNamesFromAllContexts() */ - public List getUniqueLearningGroupNamesFromAllContexts() { + public List<String> getUniqueLearningGroupNamesFromAllContexts() { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getUniqueAreaNamesFromAllContexts() */ - public List getUniqueAreaNamesFromAllContexts() { + public List<String> getUniqueAreaNamesFromAllContexts() { throw new AssertException("unsupported"); } /** * @see org.olat.course.groupsandrights.CourseGroupManager#getLearningAreasOfGroupFromAllContexts(java.lang.String) */ - public List getLearningAreasOfGroupFromAllContexts(String groupName) { + public List<BGArea> getLearningAreasOfGroupFromAllContexts(String groupName) { throw new AssertException("unsupported"); } - public List getCoachesFromLearningGroup(String groupName) { + public List<Identity> getCoachesFromLearningGroup(String groupName) { throw new AssertException("unsupported"); } - public List getCoachesFromArea(String areaName) { + public List<Identity> getCoachesFromArea(String areaName) { throw new AssertException("unsupported"); } - public List getParticipantsFromLearningGroup(String groupName) { + public List<Identity> getParticipantsFromLearningGroup(String groupName) { throw new AssertException("unsupported"); } - public List getParticipantsFromArea(String areaName) { + public List<Identity> getParticipantsFromArea(String areaName) { throw new AssertException("unsupported"); } @@ -337,7 +276,7 @@ final class PreviewCourseGroupManager extends BasicManager implements CourseGrou throw new AssertException("unsupported"); } - public List getRightGroupsFromAllContexts(String groupName) { + public List<BusinessGroup> getRightGroupsFromAllContexts(String groupName) { throw new AssertException("unsupported"); } @@ -357,7 +296,7 @@ final class PreviewCourseGroupManager extends BasicManager implements CourseGrou throw new AssertException("unsupported"); } - public List getWaitingListGroupsFromAllContexts(Identity identity) { + public List<BusinessGroup> getWaitingListGroupsFromAllContexts(Identity identity) { throw new AssertException("unsupported"); } diff --git a/src/main/java/org/olat/group/BusinessGroup.java b/src/main/java/org/olat/group/BusinessGroup.java index 1143ae7006d..87e67575951 100644 --- a/src/main/java/org/olat/group/BusinessGroup.java +++ b/src/main/java/org/olat/group/BusinessGroup.java @@ -114,16 +114,6 @@ public interface BusinessGroup extends Persistable, CreateInfo, ModifiedInfo, OL */ public Date getLastUsage(); - /** - * @return the business group context for this group - */ - //public BGContext getGroupContext(); - - /** - * @param groupContext the business group context - */ - //public void setGroupContext(BGContext groupContext); - /** * @return the maximal number of participants */ diff --git a/src/main/java/org/olat/group/BusinessGroupFactory.java b/src/main/java/org/olat/group/BusinessGroupFactory.java index 8c0e0850fbe..ee194f21f50 100644 --- a/src/main/java/org/olat/group/BusinessGroupFactory.java +++ b/src/main/java/org/olat/group/BusinessGroupFactory.java @@ -74,7 +74,8 @@ public class BusinessGroupFactory { * @return The newly created group or null if this groupname is already taken * by another group in the given context. */ - static BusinessGroup createAndPersistBusinessGroup(String type, Identity identity, String name, String description, + /* + protected static BusinessGroup createAndPersistBusinessGroup(String type, Identity identity, String name, String description, Integer minParticipants, Integer maxParticipants, Boolean waitingListEnabled,Boolean autoCloseRanksEnabled, BGContext groupContext) { if (BusinessGroup.TYPE_BUDDYGROUP.equals(type)) { return BusinessGroupFactory.createAndPersistBuddyGroup(identity, name, description, minParticipants, maxParticipants); @@ -86,7 +87,7 @@ public class BusinessGroupFactory { } else { throw new AssertException("Unknown business group type::" + type); } - } + }*/ /** * Create a group of type buddy group @@ -111,7 +112,7 @@ public class BusinessGroupFactory { SecurityGroup ownerGroup = securityManager.createAndPersistSecurityGroup(); SecurityGroup partipiciantGroup = securityManager.createAndPersistSecurityGroup(); - businessgroup = new BusinessGroupImpl(BusinessGroup.TYPE_BUDDYGROUP, name, description, ownerGroup, partipiciantGroup,null/* no waitingGroup*/, null); + businessgroup = new BusinessGroupImpl(BusinessGroup.TYPE_BUDDYGROUP, name, description, ownerGroup, partipiciantGroup,null/* no waitingGroup*/); businessgroup.setMinParticipants(minParticipants); businessgroup.setMaxParticipants(maxParticipants); @@ -177,7 +178,7 @@ public class BusinessGroupFactory { SecurityGroup partipiciantGroup = securityManager.createAndPersistSecurityGroup(); SecurityGroup waitingGroup = securityManager.createAndPersistSecurityGroup(); // - businessgroup = new BusinessGroupImpl(BusinessGroup.TYPE_LEARNINGROUP, name, description, ownerGroup, partipiciantGroup, waitingGroup, groupContext); + businessgroup = new BusinessGroupImpl(BusinessGroup.TYPE_LEARNINGROUP, name, description, ownerGroup, partipiciantGroup, waitingGroup); businessgroup.setMinParticipants(minParticipants); businessgroup.setMaxParticipants(maxParticipants); businessgroup.setWaitingListEnabled(waitingListEnabled); @@ -248,7 +249,7 @@ public class BusinessGroupFactory { // group SecurityGroup partipiciantGroup = securityManager.createAndPersistSecurityGroup(); // - businessgroup = new BusinessGroupImpl(BusinessGroup.TYPE_RIGHTGROUP, name, description, null, partipiciantGroup,null/* no waitingGroup */, groupContext); + businessgroup = new BusinessGroupImpl(BusinessGroup.TYPE_RIGHTGROUP, name, description, null, partipiciantGroup,null/* no waitingGroup */); businessgroup.setMinParticipants(minParticipants); businessgroup.setMaxParticipants(maxParticipants); // diff --git a/src/main/java/org/olat/group/BusinessGroupImpl.java b/src/main/java/org/olat/group/BusinessGroupImpl.java index 5c0e85649bb..0f28c71f31e 100644 --- a/src/main/java/org/olat/group/BusinessGroupImpl.java +++ b/src/main/java/org/olat/group/BusinessGroupImpl.java @@ -30,9 +30,9 @@ import java.util.Date; import org.olat.basesecurity.SecurityGroup; import org.olat.core.commons.persistence.PersistentObject; import org.olat.core.logging.AssertException; -import org.olat.core.util.resource.OresHelper; -import org.olat.group.context.BGContext; +import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; +import org.olat.core.util.resource.OresHelper; /** * Description: <br> @@ -44,6 +44,10 @@ import org.olat.core.logging.Tracing; */ public class BusinessGroupImpl extends PersistentObject implements BusinessGroup { + + private static final long serialVersionUID = -6977108696910447781L; + private static final OLog log = Tracing.createLoggerFor(BusinessGroupImpl.class); + private String description; private String name; private String type; @@ -75,15 +79,13 @@ public class BusinessGroupImpl extends PersistentObject implements BusinessGroup * @param description * @param ownerGroup * @param partipiciantGroup - * @param groupContext */ public BusinessGroupImpl(String type, String groupName, String description, SecurityGroup ownerGroup, SecurityGroup partipiciantGroup, - SecurityGroup waitingGroup, BGContext groupContext) { + SecurityGroup waitingGroup) { this.setName(groupName); this.setDescription(description); this.setOwnerGroup(ownerGroup); this.setPartipiciantGroup(partipiciantGroup); - this.setGroupContextKey(groupContext.getKey()); this.setWaitingGroup(waitingGroup); this.setType(type); // per default no waiting-list @@ -236,7 +238,7 @@ public class BusinessGroupImpl extends PersistentObject implements BusinessGroup int oldMaxParticipants = getMaxParticipants()!=null ? getMaxParticipants() : 0; this.maxParticipants = maxParticipants; if(maxParticipantsChanged) { - Tracing.logAudit("Max participants value changed for group " + this + " was " + oldMaxParticipants + " changed to " + maxParticipants, BusinessGroupImpl.class); + log.audit("Max participants value changed for group " + this + " was " + oldMaxParticipants + " changed to " + maxParticipants); } } diff --git a/src/main/java/org/olat/group/BusinessGroupManager.java b/src/main/java/org/olat/group/BusinessGroupManager.java index 616f85c62dd..c8c6196b9f5 100644 --- a/src/main/java/org/olat/group/BusinessGroupManager.java +++ b/src/main/java/org/olat/group/BusinessGroupManager.java @@ -25,19 +25,6 @@ package org.olat.group; -import java.io.File; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import org.olat.basesecurity.SecurityGroup; -import org.olat.core.gui.UserRequest; -import org.olat.core.gui.control.WindowControl; -import org.olat.core.gui.translator.Translator; -import org.olat.core.id.Identity; -import org.olat.group.context.BGContext; -import org.olat.group.ui.BGConfigFlags; /** * Description: <br> @@ -82,8 +69,8 @@ public interface BusinessGroupManager { * @param enableAutoCloseRanks * @return the created BusinessGroup */ - public BusinessGroup createAndPersistBusinessGroup(String type, Identity identity, String name, String description, Integer minParticipants, - Integer maxParticipants, Boolean enableWaitinglist, Boolean enableAutoCloseRanks, BGContext groupContext); + //public BusinessGroup createAndPersistBusinessGroup(String type, Identity identity, String name, String description, Integer minParticipants, + // Integer maxParticipants, Boolean enableWaitinglist, Boolean enableAutoCloseRanks, BGContext groupContext); /** * find the BusinessGroups list of type <code>type</code> associated with @@ -144,7 +131,7 @@ public interface BusinessGroupManager { * * @param businessGroupTodelete */ - public void deleteBusinessGroup(BusinessGroup businessGroupTodelete); + //public void deleteBusinessGroup(BusinessGroup businessGroupTodelete); /** * delete a business group and send a mail to all users in the group @@ -155,15 +142,15 @@ public interface BusinessGroupManager { * @param trans * @param contactLists */ - public void deleteBusinessGroupWithMail(BusinessGroup businessGroupTodelete, WindowControl wControl, UserRequest ureq, Translator trans, - List contactLists); + //public void deleteBusinessGroupWithMail(BusinessGroup businessGroupTodelete, WindowControl wControl, UserRequest ureq, Translator trans, + // List contactLists); /** * delete all business groups from this list * * @param businessGroups */ - public void deleteBusinessGroups(List businessGroups); + //public void deleteBusinessGroups(List businessGroups); /** * Checks if an identity is in a specific business group, either as owner or @@ -236,9 +223,9 @@ public interface BusinessGroupManager { * @param copyMemberVisibility * @return BusinessGroup the copied group */ - public BusinessGroup copyBusinessGroup(BusinessGroup sourceBusinessGroup, String targetName, String targetDescription, Integer targetMin, - Integer targetMax, BGContext targetBgContext, Map areaLookupMap, boolean copyAreas, boolean copyCollabToolConfig, boolean copyRights, - boolean copyOwners, boolean copyParticipants, boolean copyMemberVisibility, boolean copyWaitingList); + //public BusinessGroup copyBusinessGroup(BusinessGroup sourceBusinessGroup, String targetName, String targetDescription, Integer targetMin, + // Integer targetMax, BGContext targetBgContext, Map areaLookupMap, boolean copyAreas, boolean copyCollabToolConfig, boolean copyRights, + // boolean copyOwners, boolean copyParticipants, boolean copyMemberVisibility, boolean copyWaitingList); /** * Adds a user to a group as owner and does all the magic that needs to be @@ -255,8 +242,8 @@ public interface BusinessGroupManager { * security group, do only the other stuff, false: add user to * security group first */ - public void addOwnerAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags, - boolean doOnlyPostAddingStuff); + //public void addOwnerAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags, + // boolean doOnlyPostAddingStuff); /** * Adds a user to a group as participant and does all the magic that needs to @@ -274,8 +261,8 @@ public interface BusinessGroupManager { * security group, do only the other stuff, false: add user to * security group first */ - public void addParticipantAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags, - boolean doOnlyPostAddingStuff); + //public void addParticipantAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags, + // boolean doOnlyPostAddingStuff); /** * Remove a user from a group as owner and does all the magic that needs to be @@ -293,8 +280,8 @@ public interface BusinessGroupManager { * security group, do only the other stuff, false: remove user from * security group first */ - public void removeOwnerAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags, - boolean doOnlyPostRemovingStuff); + //public void removeOwnerAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags, + // boolean doOnlyPostRemovingStuff); /** * Remove a user from a group as participant and does all the magic that needs @@ -312,8 +299,8 @@ public interface BusinessGroupManager { * security group, do only the other stuff, false: remove user from * security group first */ - public void removeParticipantAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags, - boolean doOnlyPostRemovingStuff); + //public void removeParticipantAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags, + // boolean doOnlyPostRemovingStuff); /** * Export group definitions to file. @@ -347,7 +334,7 @@ public interface BusinessGroupManager { * security group, do only the other stuff, false: add user to * security group first */ - public void addToWaitingListAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, boolean b); + //public void addToWaitingListAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup group, boolean b); /** * Remove a user from a waiting-list as participant and does all the magic that needs @@ -365,7 +352,7 @@ public interface BusinessGroupManager { * security group, do only the other stuff, false: remove user from * security group first */ - public void removeFromWaitingListAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup waitingListGroup, boolean b); + //public void removeFromWaitingListAndFireEvent(Identity ureqIdentity, Identity identity, BusinessGroup waitingListGroup, boolean b); /** * Move users from a waiting-list to participant-list. @@ -378,7 +365,7 @@ public interface BusinessGroupManager { * @param flags * @param userActivityLogger */ - public BusinessGroupAddResponse moveIdenityFromWaitingListToParticipant(List<Identity> identities, Identity ureqIdentity, BusinessGroup currBusinessGroup, BGConfigFlags flags); + //public BusinessGroupAddResponse moveIdenityFromWaitingListToParticipant(List<Identity> identities, Identity ureqIdentity, BusinessGroup currBusinessGroup, BGConfigFlags flags); /** * Find all business-groups where the idenity is on the waiting-list. @@ -400,7 +387,7 @@ public interface BusinessGroupManager { * @param businessGroup * @return 0=not found on waiting-list */ - public int getPositionInWaitingListFor(Identity identity, BusinessGroup businessGroup); + //public int getPositionInWaitingListFor(Identity identity, BusinessGroup businessGroup); /** * Get all business-groups. @@ -417,7 +404,7 @@ public interface BusinessGroupManager { * @param userActivityLogger Use this logger to log event. * @return */ - public BusinessGroupAddResponse addOwnersAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + //public BusinessGroupAddResponse addOwnersAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); /** * Add a list of identity as participant to a business-group. @@ -428,7 +415,7 @@ public interface BusinessGroupManager { * @param userActivityLogger Use this logger to log event. * @return */ - public BusinessGroupAddResponse addParticipantsAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + //public BusinessGroupAddResponse addParticipantsAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); /** * Remove a list of identity as owner from a business-group. @@ -438,10 +425,10 @@ public interface BusinessGroupManager { * @param flags Business-group configuration flags. * @param userActivityLogger Use this logger to log event. */ - public void removeOwnersAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + //public void removeOwnersAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); //fxdiff VCRP-1,2: access control of resources - public void removeAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, SecurityGroup secGroup); + //public void removeAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, SecurityGroup secGroup); /** @@ -452,7 +439,7 @@ public interface BusinessGroupManager { * @param flags Business-group configuration flags. * @param userActivityLogger Use this logger to log event. */ - public void removeParticipantsAndFireEvent(Identity ureqIdentity, List<Identity> identities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + //public void removeParticipantsAndFireEvent(Identity ureqIdentity, List<Identity> identities, BusinessGroup currBusinessGroup, BGConfigFlags flags); /** * Add a list of identity to waiting-list of a business-group. @@ -463,7 +450,7 @@ public interface BusinessGroupManager { * @param userActivityLogger Use this logger to log event. * @return */ - public BusinessGroupAddResponse addToWaitingListAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + //public BusinessGroupAddResponse addToWaitingListAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); /** * Remove a list of identity from waiting-list of a business-group. @@ -473,10 +460,10 @@ public interface BusinessGroupManager { * @param flags Business-group configuration flags. * @param userActivityLogger Use this logger to log event. */ - public void removeFromWaitingListAndFireEvent(Identity ureqIdentity, List<Identity> identities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + //public void removeFromWaitingListAndFireEvent(Identity ureqIdentity, List<Identity> identities, BusinessGroup currBusinessGroup, BGConfigFlags flags); //fxdiff VCRP-1,2: access control of resources - public BusinessGroupAddResponse addToSecurityGroupAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, SecurityGroup secGroup); + //public BusinessGroupAddResponse addToSecurityGroupAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, SecurityGroup secGroup); //public void exportGroup(BusinessGroup businessGroup, File file); @@ -507,9 +494,9 @@ public interface BusinessGroupManager { * Listener will be called in method deleteBusinessGroup. * @param listener */ - public void registerDeletableGroupDataListener(DeletableGroupData listener); + //public void registerDeletableGroupDataListener(DeletableGroupData listener); - public List<String> getDependingDeletablableListFor(BusinessGroup currentGroup, Locale locale); + //public List<String> getDependingDeletablableListFor(BusinessGroup currentGroup, Locale locale); } diff --git a/src/main/java/org/olat/group/BusinessGroupManagerImpl.java b/src/main/java/org/olat/group/BusinessGroupManagerImpl.java index e1f569764fb..ebd07084b25 100644 --- a/src/main/java/org/olat/group/BusinessGroupManagerImpl.java +++ b/src/main/java/org/olat/group/BusinessGroupManagerImpl.java @@ -80,7 +80,7 @@ import org.olat.course.nodes.projectbroker.service.ProjectBrokerManagerFactory; import org.olat.group.area.BGArea; import org.olat.group.area.BGAreaManager; import org.olat.group.context.BGContext; -import org.olat.group.delete.service.GroupDeletionManager; +import org.olat.group.manager.BusinessGroupDeletionManager; import org.olat.group.model.SearchBusinessGroupParams; import org.olat.group.properties.BusinessGroupPropertyManager; import org.olat.group.right.BGRightManager; @@ -147,7 +147,7 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr /** * @see org.olat.group.BusinessGroupManager#createAndPersistBusinessGroup(java.lang.String, org.olat.core.id.Identity, java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Boolean, java.lang.Boolean, org.olat.group.context.BGContext) */ - public BusinessGroup createAndPersistBusinessGroup(String type, Identity identity, String name, String description, + /*public BusinessGroup createAndPersistBusinessGroup(String type, Identity identity, String name, String description, Integer minParticipants, Integer maxParticipants, Boolean enableWaitinglist, Boolean enableAutoCloseRanks, BGContext groupContext) { BusinessGroup grp = BusinessGroupFactory.createAndPersistBusinessGroup(type, identity, name, description, minParticipants, maxParticipants, enableWaitinglist, enableAutoCloseRanks, groupContext); @@ -156,7 +156,7 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr } // else no group created return grp; - } + }*/ /** * check if all given names in context exists. @@ -608,7 +608,7 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr * org.olat.core.gui.translator.Translator, java.util.List) */ public void deleteBusinessGroupWithMail(BusinessGroup businessGroupTodelete, WindowControl wControl, UserRequest ureq, Translator trans, - List contactLists) { + List contactLi) { Codepoint.codepoint(this.getClass(), "deleteBusinessGroupWithMail"); // collect data for mail @@ -797,8 +797,8 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr // 1. create group String bgType = sourceBusinessGroup.getType(); // create group, set waitingListEnabled, enableAutoCloseRanks like source business-group - BusinessGroup newGroup = createAndPersistBusinessGroup(bgType, null, targetName, targetDescription, targetMin, targetMax, - sourceBusinessGroup.getWaitingListEnabled(), sourceBusinessGroup.getAutoCloseRanksEnabled(), targetBgContext); + BusinessGroup newGroup = null;//createAndPersistBusinessGroup(bgType, null, targetName, targetDescription, targetMin, targetMax, + // sourceBusinessGroup.getWaitingListEnabled(), sourceBusinessGroup.getAutoCloseRanksEnabled(), targetBgContext); // return immediately with null value to indicate an already take groupname if (newGroup == null) { return null; } // 2. copy tools @@ -1343,8 +1343,8 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr // check if idenity is allready in participant if (!securityManager.isIdentityInSecurityGroup(identity,currBusinessGroup.getPartipiciantGroup()) ) { // Idenity is not in participant-list => move idenity from waiting-list to participant-list - BusinessGroupManagerImpl.this.addParticipantAndFireEvent(ureqIdentity, identity, currBusinessGroup, flags, false); - BusinessGroupManagerImpl.this.removeFromWaitingListAndFireEvent(ureqIdentity, identity, currBusinessGroup, false); + addParticipantAndFireEvent(ureqIdentity, identity, currBusinessGroup, flags, false); + removeFromWaitingListAndFireEvent(ureqIdentity, identity, currBusinessGroup, false); response.getAddedIdentities().add(identity); // notification mail is handled in controller } else { @@ -1373,7 +1373,7 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr return pos; } - @Override + //fxdiff VCRP-1,2: access control of resources public BusinessGroupAddResponse addToSecurityGroupAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, SecurityGroup secGroup) { BusinessGroupAddResponse response = new BusinessGroupAddResponse(); @@ -1471,7 +1471,7 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr response.getIdentitiesAlreadyInGroup().add(identity); } else { // identity has permission and is not already in group => add it - BusinessGroupManagerImpl.this.addToWaitingListAndFireEvent(ureqIdentity, identity, currBusinessGroup, false); + addToWaitingListAndFireEvent(ureqIdentity, identity, currBusinessGroup, false); response.getAddedIdentities().add(identity); Tracing.logAudit("added identity '" + identity.getName() + "' to securitygroup with key " + currBusinessGroup.getPartipiciantGroup().getKey(), this.getClass()); } @@ -1480,7 +1480,6 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr return response; } - @Override //fxdiff VCRP-1,2: access control of resources public void removeAndFireEvent(Identity ureqIdentity, List<Identity> identities, SecurityGroup secGroup) { for (Identity identity : identities) { @@ -1710,7 +1709,7 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr try { BusinessGroup reloadedBusinessGroup = loadBusinessGroup(currBusinessGroup); reloadedBusinessGroup.setLastUsage(new Date()); - LifeCycleManager.createInstanceFor(reloadedBusinessGroup).deleteTimestampFor(GroupDeletionManager.SEND_DELETE_EMAIL_ACTION); + LifeCycleManager.createInstanceFor(reloadedBusinessGroup).deleteTimestampFor(BusinessGroupDeletionManager.SEND_DELETE_EMAIL_ACTION); updateBusinessGroup(reloadedBusinessGroup); return reloadedBusinessGroup; } catch(DBRuntimeException e) { @@ -1740,8 +1739,8 @@ public class BusinessGroupManagerImpl extends BasicManager implements BusinessGr Set<BusinessGroup> newGroups = new HashSet<BusinessGroup>(); for (Iterator<String> iter = allNames.iterator(); iter.hasNext();) { String bgName = iter.next(); - BusinessGroup newGroup = createAndPersistBusinessGroup(bgContext.getGroupType(), null, bgName, bgDesc, bgMin, bgMax, - enableWaitinglist, enableAutoCloseRanks, bgContext); + BusinessGroup newGroup = null;// createAndPersistBusinessGroup(bgContext.getGroupType(), null, bgName, bgDesc, bgMin, bgMax, + //enableWaitinglist, enableAutoCloseRanks, bgContext); newGroups.add(newGroup); } return newGroups; diff --git a/src/main/java/org/olat/group/BusinessGroupModule.java b/src/main/java/org/olat/group/BusinessGroupModule.java index 5af9554c6ca..b5b22d52843 100644 --- a/src/main/java/org/olat/group/BusinessGroupModule.java +++ b/src/main/java/org/olat/group/BusinessGroupModule.java @@ -24,8 +24,6 @@ import org.olat.core.configuration.AbstractOLATModule; import org.olat.core.configuration.PersistedProperties; import org.olat.core.id.context.SiteContextEntryControllerCreator; import org.olat.core.util.resource.OresHelper; -import org.olat.course.CourseModule; -import org.olat.group.site.GroupsManagementSite; import org.olat.group.site.GroupsSite; /** @@ -58,9 +56,6 @@ public class BusinessGroupModule extends AbstractOLATModule { new BusinessGroupContextEntryControllerCreator()); NewControllerFactory.getInstance().addContextEntryControllerCreator(GroupsSite.class.getSimpleName(), new SiteContextEntryControllerCreator(GroupsSite.class)); - NewControllerFactory.getInstance().addContextEntryControllerCreator(GroupsManagementSite.class.getSimpleName(), - new SiteContextEntryControllerCreator(GroupsManagementSite.class)); - } /** diff --git a/src/main/java/org/olat/group/BusinessGroupService.java b/src/main/java/org/olat/group/BusinessGroupService.java index c37a3c4939e..0b098ba4e78 100644 --- a/src/main/java/org/olat/group/BusinessGroupService.java +++ b/src/main/java/org/olat/group/BusinessGroupService.java @@ -23,13 +23,13 @@ import java.io.File; import java.util.Collection; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Set; import org.olat.basesecurity.SecurityGroup; -import org.olat.core.gui.UserRequest; import org.olat.core.id.Identity; +import org.olat.core.util.mail.MailerResult; import org.olat.group.area.BGArea; -import org.olat.group.context.BGContext; import org.olat.group.model.SearchBusinessGroupParams; import org.olat.group.ui.BGConfigFlags; import org.olat.repository.RepositoryEntry; @@ -43,6 +43,10 @@ import org.olat.resource.OLATResource; */ public interface BusinessGroupService { + public void registerDeletableGroupDataListener(DeletableGroupData listener); + + public List<String> getDependingDeletablableListFor(BusinessGroup currentGroup, Locale locale); + public BusinessGroup createBusinessGroup(Identity creator, String name, String description, String type, @@ -55,6 +59,8 @@ public interface BusinessGroupService { public void deleteBusinessGroup(BusinessGroup group); + public MailerResult deleteBusinessGroupWithMail(BusinessGroup group, String businessPath, Identity deletedBy, Locale locale); + public BusinessGroup setLastUsageFor(BusinessGroup group); public BusinessGroup loadBusinessGroup(BusinessGroup group); @@ -67,6 +73,10 @@ public interface BusinessGroupService { public BusinessGroup loadBusinessGroup(OLATResource resource); + public BusinessGroup copyBusinessGroup(BusinessGroup sourceBusinessGroup, String targetName, String targetDescription, Integer targetMin, + Integer targetMax, OLATResource targetResource, Map<BGArea,BGArea> areaLookupMap, boolean copyAreas, boolean copyCollabToolConfig, boolean copyRights, + boolean copyOwners, boolean copyParticipants, boolean copyMemberVisibility, boolean copyWaitingList); + //search methods @@ -107,7 +117,40 @@ public interface BusinessGroupService { public List<Identity> getMembersOf(OLATResource resource, boolean owner, boolean attendee); + public int getPositionInWaitingListFor(Identity identity, BusinessGroup businessGroup); + + //memberships + public void addOwner(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags); + + public BusinessGroupAddResponse addOwners(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup group, BGConfigFlags flags); + public void removeOwners(Identity ureqIdentity, Collection<Identity> identitiesToRemove, BusinessGroup currBusinessGroup, BGConfigFlags flags); + + + public void addParticipant(Identity ureqIdentity, Identity identityToAdd, BusinessGroup group, BGConfigFlags flags); + + public BusinessGroupAddResponse addParticipants(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + + public void removeParticipant(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags); + + public void removeParticipants(Identity ureqIdentity, List<Identity> identities, BusinessGroup group, BGConfigFlags flags); + + + public void addToWaitingList(Identity ureqIdentity, Identity identity, BusinessGroup group); + + public BusinessGroupAddResponse addToWaitingList(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + + public void removeFromWaitingList(Identity ureqIdentity, Identity identity, BusinessGroup waitingListGroup); + + public void removeFromWaitingList(Identity ureqIdentity, List<Identity> identities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + + public BusinessGroupAddResponse moveIdentityFromWaitingListToParticipant(List<Identity> identities, Identity ureqIdentity, BusinessGroup currBusinessGroup, BGConfigFlags flags); + + + + public BusinessGroupAddResponse addToSecurityGroupAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, SecurityGroup secGroup); + + public void removeAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, SecurityGroup secGroup); //security @@ -121,15 +164,9 @@ public interface BusinessGroupService { */ public boolean isIdentityInBusinessGroup(Identity identity, String groupName, String groupType, boolean ownedById, boolean attendedById, OLATResource resource); - - - //memberships - public void removeParticipantsAndFireEvent(Identity ureqIdentity, List<Identity> identities, BusinessGroup group, BGConfigFlags flags); - - public void removeOwnerAndFireEvent(Identity identity, Identity currentIdentity, BusinessGroup group, BGConfigFlags flags, boolean b); + - public List<String> getDependingDeletablableListFor(BusinessGroup currentGroup, Locale locale); public Set<BusinessGroup> createUniqueBusinessGroupsFor(Set<String> allNames, OLATResource resource, String bgDesc, Integer bgMin, Integer bgMax, Boolean enableWaitingList, Boolean enableAutoCloseRanks); diff --git a/src/main/java/org/olat/group/_spring/businessGroupContext.xml b/src/main/java/org/olat/group/_spring/businessGroupContext.xml index cd97d7346e0..33fb565f1be 100644 --- a/src/main/java/org/olat/group/_spring/businessGroupContext.xml +++ b/src/main/java/org/olat/group/_spring/businessGroupContext.xml @@ -24,9 +24,11 @@ <property name="dbVendor" value="${db.vendor}" /> </bean> - <bean id="areaManager" class="org.olat.group.area.BGAreaManagerImpl"> - + <bean id="areaManager" class="org.olat.group.area.BGAreaManagerImpl"/> + <bean id="groupDeletionManager" class="org.olat.group.manager.BusinessGroupDeletionManager"> + <constructor-arg index="0" ref="deletionModule" /> + <property name="businessGroupService" ref="businessGroupService"/> </bean> </beans> \ No newline at end of file diff --git a/src/main/java/org/olat/group/area/BGAreaManager.java b/src/main/java/org/olat/group/area/BGAreaManager.java index be5f6e85460..aa4cce5354f 100644 --- a/src/main/java/org/olat/group/area/BGAreaManager.java +++ b/src/main/java/org/olat/group/area/BGAreaManager.java @@ -47,7 +47,7 @@ public interface BGAreaManager { * * @param areaName The visible area name * @param description The area description - * @param groupContext The group context of this area + * @param resource The resource of this area * @return The new area or null if no area has been created */ public abstract BGArea createAndPersistBGAreaIfNotExists(String areaName, String description, OLATResource resource); @@ -67,7 +67,7 @@ public interface BGAreaManager { * Finds an area in the given context * * @param areaName - * @param groupContext + * @param resource * @return The area or null if the area does not exists */ public abstract BGArea findBGArea(String areaName, OLATResource resource); @@ -150,7 +150,7 @@ public interface BGAreaManager { * Counts the number of business group areas of the given business group * context * - * @param groupContext + * @param resource * @return Number of business gropu areas */ public abstract int countBGAreasOfBGContext(OLATResource resource); @@ -158,7 +158,7 @@ public interface BGAreaManager { /** * Searches for all business group areas in the given business group context * - * @param groupContext + * @param resource * @return A list of business group areas */ public List<BGArea> findBGAreasOfBGContext(OLATResource resource); @@ -169,8 +169,8 @@ public interface BGAreaManager { * * @param identity * @param areaName - * @param groupContext - * @return true if identity is in such an area, false otherwhise + * @param resource + * @return true if identity is in such an area, false otherwise */ public boolean isIdentityInBGArea(Identity identity, String areaName, OLATResource resource); diff --git a/src/main/java/org/olat/group/area/BGAreaManagerImpl.java b/src/main/java/org/olat/group/area/BGAreaManagerImpl.java index d2ebf795ccf..d24083df760 100644 --- a/src/main/java/org/olat/group/area/BGAreaManagerImpl.java +++ b/src/main/java/org/olat/group/area/BGAreaManagerImpl.java @@ -35,11 +35,8 @@ import java.util.Set; import javax.persistence.TypedQuery; -import org.hibernate.type.StandardBasicTypes; -import org.hibernate.type.Type; import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DBFactory; -import org.olat.core.commons.persistence.DBQuery; import org.olat.core.id.Identity; import org.olat.core.logging.OLATRuntimeException; import org.olat.core.manager.BasicManager; @@ -47,6 +44,7 @@ import org.olat.core.util.coordinate.CoordinatorManager; import org.olat.core.util.coordinate.SyncerCallback; import org.olat.core.util.coordinate.SyncerExecutor; import org.olat.group.BusinessGroup; +import org.olat.group.BusinessGroupImpl; import org.olat.resource.OLATResource; import org.springframework.beans.factory.annotation.Autowired; @@ -66,7 +64,7 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * @see org.olat.group.area.BGAreaManager#createAndPersistBGAreaIfNotExists(java.lang.String, * java.lang.String, org.olat.group.context.BGContext) */ - //o_clusterOK by:cg synchronized on groupContext's olatresourceable + //o_clusterOK by:cg synchronized on resource public BGArea createAndPersistBGAreaIfNotExists(final String areaName, final String description, final OLATResource resource) { BGArea createdBGArea =CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(resource, new SyncerCallback<BGArea>(){ public BGArea execute() { @@ -102,18 +100,21 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * org.olat.group.context.BGContext) */ public BGArea findBGArea(String areaName, OLATResource resource) { + StringBuilder sb = new StringBuilder(); + sb.append("select area from ").append(BGAreaImpl.class.getName()).append(" area ") + .append(" where area.name=:areaName and area.resource.key=:resourceKey"); + + List<BGArea> areas = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BGArea.class) + .setParameter("areaName", areaName) + .setParameter("resourceKey", resource.getKey()) + .getResultList(); - String q = "select area from org.olat.group.area.BGAreaImpl area " + " where area.name = :areaName" - + " and area.resource = :resource"; - DBQuery query = dbInstance.createQuery(q); - query.setString("areaName", areaName); - query.setEntity("context", resource); - List<BGArea> areas = query.list(); - if (areas.size() == 0) { + if (areas.isEmpty()) { return null; - } else if (areas.size() > 1) { throw new OLATRuntimeException(BGAreaManagerImpl.class, "findBGArea(" + areaName - + ") returned more than one row for BGContext with key " + resource.getKey(), null); } - return (BGAreaImpl) areas.get(0); + } else if (areas.size() > 1) { + throw new OLATRuntimeException(BGAreaManagerImpl.class, "findBGArea(" + areaName+ ") returned more than one row for BGContext with key " + resource.getKey(), null); + } + return areas.get(0); } /** @@ -174,8 +175,12 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * @param group */ public void deleteBGtoAreaRelations(BusinessGroup group) { - String q = " from org.olat.group.area.BGtoAreaRelationImpl as bgarel where bgarel.businessGroup = ?"; - dbInstance.delete(q, new Object[] { group.getKey() }, new Type[] { StandardBasicTypes.LONG }); + StringBuilder sb = new StringBuilder(); + sb.append(" delete from ").append(BGtoAreaRelationImpl.class.getName()).append(" as bgarel where bgarel.businessGroup.key=:groupKey"); + + dbInstance.getCurrentEntityManager().createQuery(sb.toString()) + .setParameter("groupKey", group.getKey()) + .executeUpdate(); } /** @@ -227,20 +232,20 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * java.lang.String, org.olat.group.context.BGContext) */ public List<BusinessGroup> findBusinessGroupsOfAreaAttendedBy(Identity identity, String areaName, OLATResource resource) { - String query = "select bgi from " + " org.olat.group.BusinessGroupImpl as bgi " - + ", org.olat.basesecurity.SecurityGroupMembershipImpl as sgmi" + ", org.olat.group.area.BGtoAreaRelationImpl as bgarel" - + ", org.olat.group.area.BGAreaImpl as area" + " where area.name = :name " + " and bgarel.businessGroup = bgi" - + " and bgarel.groupArea = area" + " and bgi.partipiciantGroup = sgmi.securityGroup" + " and sgmi.identity = :identId" - + " and bgi.groupContext = :context"; - - //TODO gm + StringBuilder sb = new StringBuilder(); + sb.append("select bgi from ").append(BusinessGroupImpl.class.getName()).append(" as bgi ") + .append(", org.olat.basesecurity.SecurityGroupMembershipImpl as sgmi , org.olat.group.area.BGtoAreaRelationImpl as bgarel") + .append(", org.olat.group.area.BGAreaImpl as area") + .append(" where area.name=:name and bgarel.businessGroup=bgi") + .append(" and bgarel.groupArea=area and bgi.partipiciantGroup=sgmi.securityGroup and sgmi.identity.key=:identityKey") + .append(" and area.resource.key=:resourceKey"); - DBQuery dbq = dbInstance.createQuery(query); - dbq.setEntity("identId", identity); - dbq.setString("name", areaName); - dbq.setEntity("context", resource); - List result = dbq.list(); - return result; + List<BusinessGroup> groups = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BusinessGroup.class) + .setParameter("identityKey", identity.getKey()) + .setParameter("resourceKey", resource.getKey()) + .getResultList(); + + return groups; } /** @@ -271,20 +276,24 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * @see org.olat.group.area.BGAreaManager#countBGAreasOfBGContext(org.olat.group.context.BGContext) */ public int countBGAreasOfBGContext(OLATResource resource) { - String q = " select count(area) from org.olat.group.area.BGAreaImpl area where area.groupContext = :context"; - DBQuery query = dbInstance.createQuery(q); - query.setEntity("context", resource); - return ((Long) query.list().get(0)).intValue(); + StringBuilder sb = new StringBuilder(); + sb.append("select count(area) from ").append(BGAreaImpl.class.getName()).append(" area where area.resource.key=:resourceKey"); + Number count = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Number.class) + .setParameter("resourceKey", resource.getKey()) + .getSingleResult(); + return count.intValue(); } /** * @see org.olat.group.area.BGAreaManager#findBGAreasOfBGContext(org.olat.group.context.BGContext) */ public List<BGArea> findBGAreasOfBGContext(OLATResource resource) { - String q = " select area from org.olat.group.area.BGAreaImpl area where area.groupContext = :context "; - DBQuery query = dbInstance.createQuery(q); - query.setEntity("context", resource); - return query.list(); + StringBuilder sb = new StringBuilder(); + sb.append("select area from ").append(BGAreaImpl.class.getName()).append(" area where area.resource.key=:resourceKey"); + List<BGArea> areas = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BGArea.class) + .setParameter("resourceKey", resource.getKey()) + .getResultList(); + return areas; } /** @@ -292,19 +301,19 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * java.lang.String, org.olat.group.context.BGContext) */ public boolean isIdentityInBGArea(Identity identity, String areaName, OLATResource resource) { - String q = " select count(grp) from" + " org.olat.group.BusinessGroupImpl as grp," + " org.olat.group.area.BGAreaImpl as area," - + " org.olat.group.area.BGtoAreaRelationImpl bgarel," + " org.olat.basesecurity.SecurityGroupMembershipImpl as secgmemb" - + " where area.name = :name" + " and bgarel.groupArea = area" + " and bgarel.businessGroup = grp" - + " and grp.groupContext = :context" + " and ((grp.partipiciantGroup = secgmemb.securityGroup and secgmemb.identity = :id) " - + " or (grp.ownerGroup = secgmemb.securityGroup and secgmemb.identity = :id)) "; - DBQuery query = dbInstance.createQuery(q); - query.setEntity("id", identity); - query.setEntity("context", resource); - query.setString("name", areaName); - query.setCacheable(true); - List result = query.list(); - if (result.size() == 0) return false; - return ( ((Long) result.get(0)).intValue() > 0); + StringBuilder sb = new StringBuilder(); + sb.append("select count(grp) from ").append(BusinessGroupImpl.class.getName()).append(" as grp") + .append(", org.olat.group.area.BGAreaImpl as area, org.olat.group.area.BGtoAreaRelationImpl bgarel, org.olat.basesecurity.SecurityGroupMembershipImpl as secgmemb") + .append(" where bgarel.groupArea = area and bgarel.businessGroup = grp") + .append(" and area.name=:name and area.resource.key=:resourceKey ") + .append(" and ((grp.partipiciantGroup = secgmemb.securityGroup and secgmemb.identity.key=:identityKey) or (grp.ownerGroup = secgmemb.securityGroup and secgmemb.identity=:identityKey))"); + + Number count = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Number.class) + .setParameter("identityKey", identity.getKey()) + .setParameter("resourceKey", resource.getKey()) + .setParameter("name", areaName) + .getSingleResult(); + return count.intValue() > 0; } /** @@ -315,9 +324,14 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { } public boolean checkIfOneOrMoreNameExistsInContext(Set<String> allNames, OLATResource resource) { - String q = " select count(area) from org.olat.group.area.BGAreaImpl area where area.resource =:resource and area.name in (:names)"; - Number count = dbInstance.getCurrentEntityManager().createQuery(q, Number.class) - .setParameter("context", resource) + if(allNames == null || allNames.isEmpty()) { + return false; + } + + StringBuilder sb = new StringBuilder(); + sb.append("select count(area) from ").append(BGAreaImpl.class.getName()).append(" area where area.resource.key=:resourceKey and area.name in (:names)"); + Number count = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Number.class) + .setParameter("resourceKey", resource.getKey()) .setParameter("names", allNames) .getSingleResult(); return count.intValue() > 0; @@ -328,14 +342,16 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * * @param areaName The visible area name * @param description The area description - * @param groupContext The group context of this area + * @param resource The resource of this area * @return The new area */ private BGArea createAndPersistBGArea(String areaName, String description, OLATResource resource) { BGArea area = new BGAreaImpl(areaName, description, resource); - dbInstance.saveObject(area); - if (area != null) logAudit("Created Business Group Area", area.toString()); - // else no area created, name douplicate + dbInstance.getCurrentEntityManager().persist(area); + if (area != null) { + logAudit("Created Business Group Area", area.toString()); + } + // else no area created, name duplicate return area; } @@ -347,8 +363,13 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * @param bgAreaKey */ private void removeBGFromArea(Long businessGroupKey, Long bgAreaKey) { - String q = " from org.olat.group.area.BGtoAreaRelationImpl as bgarel where bgarel.groupArea.key = ? and bgarel.businessGroup = ?"; - dbInstance.delete(q, new Object[] { bgAreaKey, businessGroupKey }, new Type[] { StandardBasicTypes.LONG, StandardBasicTypes.LONG }); + StringBuilder sb = new StringBuilder(); + sb.append("delete from ").append(BGtoAreaRelationImpl.class.getName()).append(" as bgarel where bgarel.groupArea.key=:areaKey and bgarel.businessGroup=:groupKey"); + + dbInstance.getCurrentEntityManager().createQuery(sb.toString()) + .setParameter("areaKey", bgAreaKey) + .setParameter("groupKey", businessGroupKey) + .executeUpdate(); } /** @@ -358,8 +379,11 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * @param area */ private void deleteBGtoAreaRelations(BGArea area) { - String q = " from org.olat.group.area.BGtoAreaRelationImpl as bgarel where bgarel.groupArea = ?"; - dbInstance.delete(q, new Object[] { area.getKey() }, new Type[] { StandardBasicTypes.LONG }); + StringBuilder sb = new StringBuilder(); + sb.append("delete from ").append(BGtoAreaRelationImpl.class.getName()).append(" as bgarel where bgarel.groupArea.key=:areaKey"); + + dbInstance.getCurrentEntityManager().createQuery(sb.toString()) + .setParameter("areaKey", area.getKey()) + .executeUpdate(); } - } \ No newline at end of file diff --git a/src/main/java/org/olat/group/context/BGContextManager.java b/src/main/java/org/olat/group/context/BGContextManager.java deleted file mode 100644 index e43f19820ad..00000000000 --- a/src/main/java/org/olat/group/context/BGContextManager.java +++ /dev/null @@ -1,334 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <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 -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <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> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -*/ - -package org.olat.group.context; - -import java.util.Collection; -import java.util.List; - -import org.olat.core.id.Identity; -import org.olat.group.BusinessGroup; -import org.olat.repository.RepositoryEntry; -import org.olat.resource.OLATResource; - -/** - * Description:<BR/> Manager to manipulate business group contexts. A business - * group context is a collection of business groups of the same business group - * type and of business group areas that area associated with the business - * groups. A business group context can be associated with multiple courses. - * Every course has at least two business group contexts, the default learning - * group context and the default right group context - * <p> - * Initial Date: Aug 25, 2004 - * - * @author gnaegi - */ -public interface BGContextManager { - - /** - * Creates a busines group context object and persists the object in the - * database - * - * @param name Display name of the group context - * @param description - * @param groupType Business group type that this business group context can - * contain - * @param owner The initial owner, the users who can manage the business group - * context using the group context management tool - * @param defaultContext true: create as a default context, false: create as a - * regular context - * @return The persisted business group context - */ - //public abstract BGContext createAndPersistBGContext(String name, String description, String groupType, Identity owner, - // boolean defaultContext); - - /** - * Creates and persists a business group context as a copy of an existing - * business group context. The new created context will then be associated to - * the given OLATResource. The copy process will copy all business group areas - * and all business groups. The groups will be configured identically as the - * original groups but will not contain any users. - * - * @param contextName The new context name - * @param resource The OALTResource that the new context should be associated - * with using the group context management tool - * @param originalBgContext The original business group context that is uses - * for the copy process - * @return The new copied business group context - */ - //public abstract BGContext copyAndAddBGContextToResource(String contextName, OLATResource resource, BGContext originalBgContext); - - /** - * Updates a business group context in the database - * - * @param bgContext - */ - //public abstract void updateBGContext(BGContext bgContext); - - /** - * Deletes a business group context from the database - * - * @param bgContext - */ - //public abstract void deleteBGContext(BGContext bgContext); - - /** - * Find all groups from a business group context - * - * @param bgContext the business group context or null to find groups that are - * not within a business group context (e.b. buddygroups) - * @return A list containing business group contexts - */ - //public abstract List<BusinessGroup> getGroupsOfBGContext(BGContext bgContext); - - /** - * Find all groups from a list of group contexts - * - * @param bgContext the business group context or null to find groups that are - * not within a business group context (e.b. buddygroups) - * @return A list containing business group contexts - */ - //public abstract List<BusinessGroup> getGroupsOfBGContext(Collection<BGContext> bgContexts, int firstResult, int maxResults); - - /** - * Count the number of groups within a business group context - * - * @param bgContext - * @return The number of groups - */ - //public abstract int countGroupsOfBGContext(BGContext bgContext); - - /** - * Count the number of groups of a certain group type - * @param groupType - * @return - */ - //public abstract int countGroupsOfType(String groupType); - - /** - * Find the identities that are owners of any group in the given business - * group context - * - * @param bgContext - * @return A list of identities - */ - //public abstract List getBGOwnersOfBGContext(BGContext bgContext); - - //fxdiff VCRP-2: access control - //public List<BusinessGroup> getBusinessGroupAsOwnerOfBGContext(Identity owner, BGContext bgContext); - - - /** - * Count the number of identities that are owner of any group in the given - * business group context - * - * @param bgContext - * @return The number of identities - */ - //public abstract int countBGOwnersOfBGContext(BGContext bgContext); - - /** - * Find the identities that are participants of any group in the given - * business group context - * - * @param bgContext - * @return A list of identities - */ - //public abstract List getBGParticipantsOfBGContext(BGContext bgContext); - - //fxdiff VCRP-2: access control - //public List<BusinessGroup> getBusinessGroupAsParticipantOfBGContext(Identity participant, BGContext bgContext); - - /** - * Count the number of identities that are participants of any group in the - * given business group context - * - * @param bgContext - * @return The number of identities - */ - //public abstract int countBGParticipantsOfBGContext(BGContext bgContext); - - /** - * Check if the given identity is in this business group context - * - * @param identity - * @param bgContext - * @param asOwner Flag to check if the user is in any group as owner - * @param asParticipant Flag to check if the user is in any group as - * participant - * @return true if user is in any group with ghe given role, false otherwhise - */ - //public abstract boolean isIdentityInBGContext(Identity identity, List<BGContext> bgContexts, boolean asOwner, boolean asParticipant); - - /** - * Find a business group in the given business group context - * - * @param groupName - * @param bgContext - * @return The business group or null if no group found - */ - //public abstract BusinessGroup findGroupOfBGContext(String groupName, BGContext bgContext); - - /** - * Find a business group in the given business group context where the given - * user is in the group as participant - * - * @param identity - * @param groupName - * @param context - * @return The business group or null if no group found - */ - //public abstract BusinessGroup findGroupAttendedBy(Identity identity, String groupName, BGContext context); - - // context to resource relation - - /** - * Creates a relation from a business group context to an OLATResource (e.g. - * course) - * - * @param contextName The new context name - * @param resource The OALTResource that the new context should be associated - * with - * @param initialOwner The initial owner. the users who can manage the - * business group context using the group context management tool - * @param groupType The group type the context should be used for - * @param defaultContext true: create as a default context, false: create as a - * regular context - * @return The new created business group context - */ - //public abstract BGContext createAndAddBGContextToResource(String contextName, OLATResource resource, String groupType, - // Identity initialOwner, boolean defaultContext); - - /** - * Add a business group context to an OLATResource - * - * @param bgContext - * @param resource - */ - //public abstract void addBGContextToResource(BGContext bgContext, OLATResource resource); - - /** - * Find all business group contexts for the given OLATResource defaultContexts - * and nonDefaultContexts can both be true or partly be true, but not be both - * false - * - * @param resource - * @param defaultContexts true: find default contexts - * @param nonDefaultContexts true: find non-default contexts - * @return A list of business group contexts - */ - //public abstract List<BGContext> findBGContextsForResource(OLATResource resource, boolean defaultContexts, boolean nonDefaultContexts); - - /** - * Find all business group contexts for the given OLATResource with the given - * group type defaultContexts and nonDefaultContexts can both be true or - * partly be true, but not be both false - * - * @param resource - * @param groupType - * @param defaultContexts true: find default contexts - * @param nonDefaultContexts true: find non-default contexts - * @return A list of business group contexts - */ - //public abstract List<BGContext> findBGContextsForResource(OLATResource resource, String groupType, boolean defaultContexts, - // boolean nonDefaultContexts); - - /** - * Find all business group contexts for a specific user. This will find all - * contexts where the user is in the owner group and all context where the - * user is in the owner group of the olat resource that uses this context. - * defaultContexts and nonDefaultContexts can both be true or partly be true, - * but not be both false - * - * @param identity - * @param defaultContexts true: find default contexts - * @param nonDefaultContexts true: find non-default contexts - * @return A list of business group contexts - */ - //public abstract List<BGContext> findBGContextsForIdentity(Identity identity, boolean defaultContexts, boolean nonDefaultContexts); - - /** - * Find all OLATResources that are associated with the given business group - * context - * - * @param bgContext - * @return A list of OLATResources - */ - //public abstract List findOLATResourcesForBGContext(BGContext bgContext); - - /** - * Find all repository entries of the OLAT resources that have a relation to - * this group context. (see findOlatResourcesForBGContext) - * - * @param bgContext - * @return List of repository entries - */ - //public List<RepositoryEntry> findRepositoryEntriesForBGContext(BGContext bgContext); - - /** - * Find all repository entries of the OLAT resources that have a relation to - * this group context. (see findOlatResourcesForBGContext) - * - * @param bgContext - * @param firstResult mandatory - * @param maxResults set to -1 if you want all entries - * @return - */ - //fxdiff VCRP-1,2: access control of resources - //public List<RepositoryEntry> findRepositoryEntriesForBGContext(Collection<BGContext> bgContext, int firstResult, int maxResults); - - /** - * Find all repository entries of the OLAT resources that have a relation to - * this group context. (see findOlatResourcesForBGContext) - * - * @param bgContexts - * @param access - * @param asOwner - * @param asCoach - * @param asParticipant - * @param identity - * @return - */ - //fxdiff VCRP-1,2: access control of resources - //public List<RepositoryEntry> findRepositoryEntriesForBGContext(Collection<BGContext> bgContexts, int access, boolean asOwner, boolean asCoach, - // boolean asParticipant, Identity identity); - - /** - * Remove the given business group context from this OLATResource - * - * @param bgContext - * @param resource - */ - //public abstract void removeBGContextFromResource(BGContext bgContext, OLATResource resource); - - /** - * Refresh the given bgContext - * - * @param bgContext - * @return BGContext the updated context - */ - //public BGContext loadBGContext(BGContext bgContext); - -} \ No newline at end of file diff --git a/src/main/java/org/olat/group/context/BGContextManagerImpl.java b/src/main/java/org/olat/group/context/BGContextManagerImpl.java index 69ed0a5485e..0bb43f45ac5 100644 --- a/src/main/java/org/olat/group/context/BGContextManagerImpl.java +++ b/src/main/java/org/olat/group/context/BGContextManagerImpl.java @@ -30,7 +30,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Map; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.Type; @@ -39,7 +38,6 @@ import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.Constants; import org.olat.basesecurity.SecurityGroup; import org.olat.basesecurity.SecurityGroupMembershipImpl; -import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.commons.persistence.DBQuery; @@ -53,11 +51,6 @@ import org.olat.course.CourseModule; import org.olat.course.ICourse; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupImpl; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; -import org.olat.group.area.BGArea; -import org.olat.group.area.BGAreaManager; -import org.olat.group.area.BGAreaManagerImpl; import org.olat.repository.RepositoryEntry; import org.olat.resource.OLATResource; @@ -69,9 +62,9 @@ import org.olat.resource.OLATResource; * * @author gnaegi */ -public class BGContextManagerImpl extends BasicManager implements BGContextManager { +public class BGContextManagerImpl extends BasicManager { - private static BGContextManager INSTANCE; + private static BGContextManagerImpl INSTANCE; static { INSTANCE = new BGContextManagerImpl(); } @@ -79,7 +72,7 @@ public class BGContextManagerImpl extends BasicManager implements BGContextManag /** * @return singleton instance */ - public static BGContextManager getInstance() { + public static BGContextManagerImpl getInstance() { return INSTANCE; } @@ -167,11 +160,9 @@ public class BGContextManagerImpl extends BasicManager implements BGContextManag */ public void deleteBGContext(BGContext bgContext) { bgContext = (BGContext) DBFactory.getInstance().loadObject(bgContext); - BusinessGroupManager bgManager = BusinessGroupManagerImpl.getInstance(); - BGAreaManager areaManager = CoreSpringFactory.getImpl(BGAreaManager.class); // 1) Delete all groups from group context List groups = getGroupsOfBGContext(bgContext); - bgManager.deleteBusinessGroups(groups); + //bgManager.deleteBusinessGroups(groups); // 2) Delete all group areas /* List areas = areaManager.findBGAreasOfBGContext(bgContext); diff --git a/src/main/java/org/olat/group/delete/GroupDeleteTableModel.java b/src/main/java/org/olat/group/delete/GroupDeleteTableModel.java index bcb3b2f31e4..2d0c355512d 100644 --- a/src/main/java/org/olat/group/delete/GroupDeleteTableModel.java +++ b/src/main/java/org/olat/group/delete/GroupDeleteTableModel.java @@ -25,6 +25,7 @@ package org.olat.group.delete; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -33,30 +34,41 @@ import org.olat.core.gui.components.table.DefaultTableDataModel; import org.olat.core.gui.translator.Translator; import org.olat.core.util.filter.FilterFactory; import org.olat.group.BusinessGroup; -import org.olat.group.delete.service.GroupDeletionManager; +import org.olat.group.manager.BusinessGroupDeletionManager; /** * The repository-entry table data model for repository deletion. * * @author Christian Guretzki */ -public class GroupDeleteTableModel extends DefaultTableDataModel { - - +public class GroupDeleteTableModel extends DefaultTableDataModel<BusinessGroup> { private Translator translator; + /** * @param objects */ - public GroupDeleteTableModel(List objects, Translator translator) { + public GroupDeleteTableModel(List<BusinessGroup> objects, Translator translator) { super(objects); this.translator = translator; } + + /** + * @see org.olat.core.gui.components.table.TableDataModel#getColumnCount() + */ + public int getColumnCount() { + return 5; + } + + @Override + public Object createCopyWithEmptyList() { + return new GroupDeleteTableModel(new ArrayList<BusinessGroup>(), translator); + } /** * @see org.olat.core.gui.components.table.TableDataModel#getValueAt(int, int) */ public final Object getValueAt(int row, int col) { - BusinessGroup businessGroup = (BusinessGroup) getObject(row); + BusinessGroup businessGroup = getObject(row); switch (col) { case 0 : return businessGroup.getName(); @@ -71,16 +83,10 @@ public class GroupDeleteTableModel extends DefaultTableDataModel { Date lastUsage= businessGroup.getLastUsage(); return (lastUsage == null ? "n/a" : lastUsage); case 4 : - Date deleteEmail= LifeCycleManager.createInstanceFor(businessGroup).lookupLifeCycleEntry(GroupDeletionManager.SEND_DELETE_EMAIL_ACTION).getLcTimestamp(); + Date deleteEmail= LifeCycleManager.createInstanceFor(businessGroup).lookupLifeCycleEntry(BusinessGroupDeletionManager.SEND_DELETE_EMAIL_ACTION).getLcTimestamp(); return (deleteEmail == null ? "n/a" : deleteEmail); default : return "error"; } } - /** - * @see org.olat.core.gui.components.table.TableDataModel#getColumnCount() - */ - public int getColumnCount() { - return 5; - } } diff --git a/src/main/java/org/olat/group/delete/ReadyToDeleteController.java b/src/main/java/org/olat/group/delete/ReadyToDeleteController.java index 87f83b8e744..78839bbaf8e 100644 --- a/src/main/java/org/olat/group/delete/ReadyToDeleteController.java +++ b/src/main/java/org/olat/group/delete/ReadyToDeleteController.java @@ -27,6 +27,7 @@ package org.olat.group.delete; import java.util.List; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.link.Link; @@ -48,7 +49,7 @@ import org.olat.core.gui.control.generic.modal.DialogBoxUIFactory; import org.olat.core.gui.translator.PackageTranslator; import org.olat.core.util.Util; import org.olat.group.BusinessGroup; -import org.olat.group.delete.service.GroupDeletionManager; +import org.olat.group.manager.BusinessGroupDeletionManager; import org.olat.group.ui.BGTranslatorFactory; import org.olat.group.ui.main.BGMainController; @@ -69,9 +70,11 @@ public class ReadyToDeleteController extends BasicController { private TableController tableCtr; private GroupDeleteTableModel redtm; private Link feedbackBackLink; - private List groupsReadyToDelete; + private List<BusinessGroup> groupsReadyToDelete; private DialogBoxController deleteConfirmController; private PackageTranslator tableModelTypeTranslator; + + private final BusinessGroupDeletionManager bgDeletionManager; /** * @param ureq @@ -80,6 +83,7 @@ public class ReadyToDeleteController extends BasicController { */ public ReadyToDeleteController(UserRequest ureq, WindowControl wControl) { super(ureq, wControl); + bgDeletionManager = CoreSpringFactory.getImpl(BusinessGroupDeletionManager.class); /* * createBGPackageTranslator creates a Translator for Business Groups and the provided package, e.g. ReadyToDelete.class @@ -109,7 +113,6 @@ public class ReadyToDeleteController extends BasicController { * org.olat.core.gui.components.Component, * org.olat.core.gui.control.Event) */ - @SuppressWarnings("unused") public void event(UserRequest ureq, Component source, Event event) { if (source == feedbackBackLink) { initializeTableController(ureq); @@ -126,7 +129,7 @@ public class ReadyToDeleteController extends BasicController { TableEvent te = (TableEvent) event; if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) { int rowid = te.getRowId(); - GroupDeletionManager.getInstance().setLastUsageNowFor( (BusinessGroup) redtm.getObject(rowid) ); + bgDeletionManager.setLastUsageNowFor( (BusinessGroup) redtm.getObject(rowid) ); updateGroupList(); } } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) { @@ -137,7 +140,7 @@ public class ReadyToDeleteController extends BasicController { } } else if (source == deleteConfirmController) { if (DialogBoxUIFactory.isOkEvent(event)) { - GroupDeletionManager.getInstance().deleteGroups(groupsReadyToDelete); + bgDeletionManager.deleteGroups(groupsReadyToDelete); showInfo("readyToDelete.deleted.msg"); } updateGroupList(); @@ -178,13 +181,13 @@ public class ReadyToDeleteController extends BasicController { VelocityContainer readyToDeleteContent = createVelocityContainer("readyToDelete"); readyToDeleteContent.put("readyToDelete", tableCtr.getInitialComponent()); readyToDeleteContent.contextPut("header", translate("ready.to.delete.header", - Integer.toString(GroupDeletionManager.getInstance().getDeleteEmailDuration()) )); + Integer.toString(bgDeletionManager.getDeleteEmailDuration()) )); readyToDeletePanel.setContent(readyToDeleteContent); } protected void updateGroupList() { - List l = GroupDeletionManager.getInstance().getGroupsReadyToDelete(GroupDeletionManager.getInstance().getDeleteEmailDuration()); + List<BusinessGroup> l = bgDeletionManager.getGroupsReadyToDelete(bgDeletionManager.getDeleteEmailDuration()); redtm = new GroupDeleteTableModel(l,tableModelTypeTranslator); tableCtr.setTableDataModel(redtm); } diff --git a/src/main/java/org/olat/group/delete/SelectionController.java b/src/main/java/org/olat/group/delete/SelectionController.java index 494c3aa4100..7b7b7fdd85b 100644 --- a/src/main/java/org/olat/group/delete/SelectionController.java +++ b/src/main/java/org/olat/group/delete/SelectionController.java @@ -29,6 +29,7 @@ import java.util.List; import org.apache.velocity.VelocityContext; import org.olat.admin.user.delete.service.UserDeletionManager; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.form.flexible.FormItemContainer; @@ -58,7 +59,7 @@ import org.olat.core.util.Util; import org.olat.core.util.mail.MailNotificationEditController; import org.olat.core.util.mail.MailTemplate; import org.olat.group.BusinessGroup; -import org.olat.group.delete.service.GroupDeletionManager; +import org.olat.group.manager.BusinessGroupDeletionManager; import org.olat.group.ui.BGTranslatorFactory; import org.olat.group.ui.main.BGMainController; @@ -84,10 +85,12 @@ public class SelectionController extends BasicController { private VelocityContainer selectionListContent; private Link editParameterLink; private MailNotificationEditController deleteGroupMailCtr; - private List selectedGroups; + private List<BusinessGroup> selectedGroups; private PackageTranslator tableModelTypeTranslator; private CloseableModalController cmc; + + private final BusinessGroupDeletionManager bgDeletionManager; /** * @param ureq @@ -96,6 +99,8 @@ public class SelectionController extends BasicController { */ public SelectionController(UserRequest ureq, WindowControl wControl) { super(ureq, wControl); + + bgDeletionManager = CoreSpringFactory.getImpl(BusinessGroupDeletionManager.class); PackageTranslator fallbackTrans = new PackageTranslator(PACKAGE_BG_MAIN_CONTROLLER, ureq.getLocale()); this.setTranslator( new PackageTranslator( MY_PACKAGE, ureq.getLocale(), fallbackTrans) ); @@ -118,7 +123,7 @@ public class SelectionController extends BasicController { selectionListContent = createVelocityContainer("selectionlist"); selectionListContent.put("repositorylist", tableCtr.getInitialComponent() ); selectionListContent.contextPut("header", translate("selection.delete.header", - new String[] { Integer.toString(GroupDeletionManager.getInstance().getLastUsageDuration()) })); + new String[] { Integer.toString(bgDeletionManager.getLastUsageDuration()) })); editParameterLink = LinkFactory.createButtonXSmall("button.editParameter", selectionListContent, this); deleteSelectionPanel.setContent(selectionListContent); } @@ -132,7 +137,7 @@ public class SelectionController extends BasicController { if (source == editParameterLink) { removeAsListenerAndDispose(selectionForm); - selectionForm = new SelectionForm(ureq, getWindowControl()); + selectionForm = new SelectionForm(ureq, getWindowControl(), bgDeletionManager); listenTo(selectionForm); removeAsListenerAndDispose(cmc); @@ -154,8 +159,8 @@ public class SelectionController extends BasicController { public void event(UserRequest ureq, Controller source, Event event) { if (source == selectionForm) { if (event == Event.DONE_EVENT) { - GroupDeletionManager.getInstance().setLastUsageDuration(selectionForm.getLastUsageDuration()); - GroupDeletionManager.getInstance().setDeleteEmailDuration(selectionForm.getDeleteEmailDuration()); + bgDeletionManager.setLastUsageDuration(selectionForm.getLastUsageDuration()); + bgDeletionManager.setDeleteEmailDuration(selectionForm.getDeleteEmailDuration()); initializeContent(); } else if (event == Event.CANCELLED_EVENT) { fireEvent(ureq, Event.CANCELLED_EVENT); @@ -167,7 +172,7 @@ public class SelectionController extends BasicController { TableEvent te = (TableEvent) event; if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) { int rowid = te.getRowId(); - GroupDeletionManager.getInstance().setLastUsageNowFor((BusinessGroup) redtm.getObject(rowid)); + bgDeletionManager.setLastUsageNowFor((BusinessGroup) redtm.getObject(rowid)); updateGroupList(); } } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) { @@ -179,7 +184,7 @@ public class SelectionController extends BasicController { initializeContent(); } else if (source == deleteGroupMailCtr) { if (event == Event.DONE_EVENT) { - String warningMessage = GroupDeletionManager.getInstance().sendDeleteEmailTo( + String warningMessage = bgDeletionManager.sendDeleteEmailTo( selectedGroups, deleteGroupMailCtr.getMailTemplate(), deleteGroupMailCtr.isTemplateChanged(), KEY_EMAIL_SUBJECT, KEY_EMAIL_BODY, ureq.getIdentity(), (PackageTranslator) getTranslator() @@ -253,7 +258,7 @@ public class SelectionController extends BasicController { } public void updateGroupList() { - List l = GroupDeletionManager.getInstance().getDeletableGroups(GroupDeletionManager.getInstance().getLastUsageDuration()); + List<BusinessGroup> l = bgDeletionManager.getDeletableGroups(bgDeletionManager.getLastUsageDuration()); redtm = new GroupDeleteTableModel(l, tableModelTypeTranslator); tableCtr.setTableDataModel(redtm); } @@ -282,6 +287,7 @@ class SelectionForm extends FormBasicController { private IntegerElement lastUsageDuration; private IntegerElement emailDuration; + private final BusinessGroupDeletionManager bgDeletionManager; /** * @param name @@ -290,8 +296,9 @@ class SelectionForm extends FormBasicController { * validation takes place */ - public SelectionForm(UserRequest ureq, WindowControl wControl) { + public SelectionForm(UserRequest ureq, WindowControl wControl, BusinessGroupDeletionManager bgDeletionManager) { super(ureq, wControl); + this.bgDeletionManager = bgDeletionManager; initForm(ureq); } @@ -315,8 +322,8 @@ class SelectionForm extends FormBasicController { @Override protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { - lastUsageDuration= uifactory.addIntegerElement("lastUsageDuration", "edit.parameter.form.lastusage.duration", GroupDeletionManager.getInstance().getLastUsageDuration(), formLayout); - emailDuration = uifactory.addIntegerElement("emailDuration", "edit.parameter.form.email.duration", GroupDeletionManager.getInstance().getDeleteEmailDuration(), formLayout); + lastUsageDuration= uifactory.addIntegerElement("lastUsageDuration", "edit.parameter.form.lastusage.duration", bgDeletionManager.getLastUsageDuration(), formLayout); + emailDuration = uifactory.addIntegerElement("emailDuration", "edit.parameter.form.email.duration", bgDeletionManager.getDeleteEmailDuration(), formLayout); lastUsageDuration.setMinValueCheck(1, null); emailDuration.setMinValueCheck(1, null); diff --git a/src/main/java/org/olat/group/delete/StatusController.java b/src/main/java/org/olat/group/delete/StatusController.java index 8d2181e0629..7003a92e647 100644 --- a/src/main/java/org/olat/group/delete/StatusController.java +++ b/src/main/java/org/olat/group/delete/StatusController.java @@ -27,6 +27,7 @@ package org.olat.group.delete; import java.util.List; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.panel.Panel; @@ -44,7 +45,7 @@ import org.olat.core.gui.control.controller.BasicController; import org.olat.core.gui.translator.PackageTranslator; import org.olat.core.util.Util; import org.olat.group.BusinessGroup; -import org.olat.group.delete.service.GroupDeletionManager; +import org.olat.group.manager.BusinessGroupDeletionManager; import org.olat.group.ui.BGTranslatorFactory; import org.olat.group.ui.main.BGMainController; @@ -65,6 +66,8 @@ public class StatusController extends BasicController { private TableController tableCtr; private GroupDeleteTableModel redtm; private PackageTranslator tableModelTypeTranslator; + + private final BusinessGroupDeletionManager bgDeletionManager; /** @@ -74,6 +77,8 @@ public class StatusController extends BasicController { */ public StatusController(UserRequest ureq, WindowControl wControl) { super(ureq, wControl); + + bgDeletionManager = CoreSpringFactory.getImpl(BusinessGroupDeletionManager.class); PackageTranslator fallbackTrans = new PackageTranslator(PACKAGE_BG_MAIN_CONTROLLER, ureq.getLocale()); this.setTranslator( new PackageTranslator( MY_PACKAGE, ureq.getLocale(), fallbackTrans) ); @@ -86,7 +91,7 @@ public class StatusController extends BasicController { repositoryDeleteStatusPanel.addListener(this); myContent.put("repositoryDeleteStatusPanel", repositoryDeleteStatusPanel); myContent.contextPut("header", translate("status.delete.email.header", - new String [] { Integer.toString(GroupDeletionManager.getInstance().getDeleteEmailDuration()) })); + new String [] { Integer.toString(bgDeletionManager.getDeleteEmailDuration()) })); initializeTableController(ureq); putInitialPanel(myContent); @@ -97,7 +102,6 @@ public class StatusController extends BasicController { * org.olat.core.gui.components.Component, * org.olat.core.gui.control.Event) */ - @SuppressWarnings("unused") public void event(UserRequest ureq, Component source, Event event) { //no sources send events } @@ -106,14 +110,13 @@ public class StatusController extends BasicController { * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, * org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event) */ - @SuppressWarnings("unused") public void event(UserRequest ureq, Controller source, Event event) { if (source == tableCtr) { if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) { TableEvent te = (TableEvent) event; if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) { int rowid = te.getRowId(); - GroupDeletionManager.getInstance().setLastUsageNowFor( (BusinessGroup) redtm.getObject(rowid) ); + bgDeletionManager.setLastUsageNowFor( (BusinessGroup) redtm.getObject(rowid) ); updateGroupList(); } } @@ -142,7 +145,7 @@ public class StatusController extends BasicController { } protected void updateGroupList() { - List l = GroupDeletionManager.getInstance().getGroupsInDeletionProcess(GroupDeletionManager.getInstance().getDeleteEmailDuration()); + List<BusinessGroup> l = bgDeletionManager.getGroupsInDeletionProcess(bgDeletionManager.getDeleteEmailDuration()); redtm = new GroupDeleteTableModel(l, tableModelTypeTranslator); tableCtr.setTableDataModel(redtm); } diff --git a/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java b/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java index dc6e9e7a034..455602f9905 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java @@ -167,8 +167,8 @@ public class BusinessGroupArchiver { if (group != null) { appendTitle(buf, title ); appendIdentityTableHeader(buf); - for (Iterator iter = securityManager.getIdentitiesAndDateOfSecurityGroup(group).iterator(); iter.hasNext();) { - Object[] element = (Object[]) iter.next(); + for (Iterator<Object[]> iter = securityManager.getIdentitiesAndDateOfSecurityGroup(group).iterator(); iter.hasNext();) { + Object[] element = iter.next(); Identity identity = (Identity) element[0]; Date addedTo = (Date) element[1]; appendIdentity(buf, identity, addedTo ); @@ -269,15 +269,15 @@ public class BusinessGroupArchiver { List<BusinessGroup> areaBusinessGroupList = areaManager.findBusinessGroupsOfArea(area); for (BusinessGroup group : areaBusinessGroupList) { if(group.getOwnerGroup()!=null) { - Iterator ownerIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getOwnerGroup()).iterator(); + Iterator<Object[]> ownerIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getOwnerGroup()).iterator(); addMembers(area.getKey(), ownerIterator, owners, OWNER); } if(group.getPartipiciantGroup()!=null) { - Iterator participantsIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getPartipiciantGroup()).iterator(); + Iterator<Object[]> participantsIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getPartipiciantGroup()).iterator(); addMembers(area.getKey(), participantsIterator, participants, PARTICIPANT); } if(group.getWaitingGroup()!=null) { - Iterator waitingIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getWaitingGroup()).iterator(); + Iterator<Object[]> waitingIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getWaitingGroup()).iterator(); addMembers(area.getKey(), waitingIterator, waitings, WAITING); } } @@ -285,7 +285,7 @@ public class BusinessGroupArchiver { } Translator trans = getPackageTranslator(locale); - List<OrganisationalEntity> organisationalEntityList = getOrganisationalEntityList(areaList); + List<OrganisationalEntity> organisationalEntityList = getOrganisationalEntityListFromAreas(areaList); return generateArchiveFile(resource, owners, participants, waitings, columnList, organisationalEntityList, trans.translate("archive.areas"), archiveType, locale, charset); } @@ -315,22 +315,22 @@ public class BusinessGroupArchiver { for (BusinessGroup group: groups) { if (groupList.contains(group)) { //rely on the equals() method of the BusinessGroup impl if(group.getOwnerGroup()!=null) { - Iterator ownerIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getOwnerGroup()).iterator(); + Iterator<Object[]> ownerIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getOwnerGroup()).iterator(); addMembers(group.getKey(), ownerIterator, owners, OWNER); } if(group.getPartipiciantGroup()!=null) { - Iterator participantsIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getPartipiciantGroup()).iterator(); + Iterator<Object[]> participantsIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getPartipiciantGroup()).iterator(); addMembers(group.getKey(), participantsIterator, participants, PARTICIPANT); } if(group.getWaitingGroup()!=null) { - Iterator waitingIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getWaitingGroup()).iterator(); + Iterator<Object[]> waitingIterator = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getWaitingGroup()).iterator(); addMembers(group.getKey(), waitingIterator, waitings, WAITING); } } } Translator trans = getPackageTranslator(locale); - List<OrganisationalEntity> organisationalEntityList = getOrganisationalEntityList(groupList); + List<OrganisationalEntity> organisationalEntityList = getOrganisationalEntityListFromGroups(groupList); return generateArchiveFile(resource, owners, participants, waitings, columnList, organisationalEntityList, trans.translate("archive.groups"), archiveType, locale, charset); } @@ -670,12 +670,12 @@ public class BusinessGroupArchiver { * @param members * @param roleName */ - private void addMembers(Long entityKey, Iterator identityIterator, List<Member> members, String roleName) { + private void addMembers(Long entityKey, Iterator<Object[]> identityIterator, List<Member> members, String roleName) { while (identityIterator.hasNext()) { - Object[] element = (Object[]) identityIterator.next(); + Object[] element = identityIterator.next(); Identity identity = (Identity) element[0]; OrganisationalEntityRole role = new OrganisationalEntityRole(entityKey, roleName); - Member member = new Member(identity,new ArrayList()); + Member member = new Member(identity, new ArrayList<OrganisationalEntityRole>()); member.getOrganisationalEntityRoleList().add(role); if(!members.contains(member)) { members.add(member); @@ -688,8 +688,8 @@ public class BusinessGroupArchiver { } } } - } - } + } + } /** * Appends course names and archive date. @@ -824,18 +824,18 @@ public class BusinessGroupArchiver { * @param itemList * @return */ - private List<OrganisationalEntity> getOrganisationalEntityList(List itemList) { + private List<OrganisationalEntity> getOrganisationalEntityListFromGroups(List<BusinessGroup> itemList) { List<OrganisationalEntity> entryList = new ArrayList<OrganisationalEntity>(); - Iterator itemIterator = itemList.iterator(); - while (itemIterator.hasNext()) { - Object item = itemIterator.next(); - if (item instanceof BusinessGroup) { - BusinessGroup group = (BusinessGroup) item; - entryList.add(new OrganisationalEntity(group.getKey(), group.getName())); - } else if (item instanceof BGArea) { - BGArea area = (BGArea) item; - entryList.add(new OrganisationalEntity(area.getKey(), area.getName())); - } + for (BusinessGroup group : itemList){ + entryList.add(new OrganisationalEntity(group.getKey(), group.getName())); + } + return entryList; + } + + private List<OrganisationalEntity> getOrganisationalEntityListFromAreas(List<BGArea> areas) { + List<OrganisationalEntity> entryList = new ArrayList<OrganisationalEntity>(); + for (BGArea area : areas){ + entryList.add(new OrganisationalEntity(area.getKey(), area.getName())); } return entryList; } @@ -863,17 +863,9 @@ public class BusinessGroupArchiver { return roleInGroup; } - public void setRoleInGroup(String roleInGroup) { - this.roleInGroup = roleInGroup; - } - public Long getEntityKey() { return entityKey; } - - public void setEntityKey(Long groupKey) { - this.entityKey = groupKey; - } public boolean equals(Object obj) { OrganisationalEntityRole that = (OrganisationalEntityRole) obj; @@ -908,15 +900,9 @@ public class BusinessGroupArchiver { return organisationalEntityRoleList; } - public void setOrganisationalEntityRoleList(List<OrganisationalEntityRole> groupRoleList) { - this.organisationalEntityRoleList = groupRoleList; - } public Identity getIdentity() { return identity; } - public void setIdentity(Identity identity) { - this.identity = identity; - } /** * Compares the identity of the members. @@ -936,7 +922,7 @@ public class BusinessGroupArchiver { public int hashCode() { return this.identity.hashCode(); } - } + } private class OrganisationalEntity { private Long key; @@ -953,17 +939,8 @@ public class BusinessGroupArchiver { return key; } - public void setKey(Long key) { - this.key = key; - } - public String getName() { return name; } - - public void setName(String name) { - this.name = name; - } } - } \ No newline at end of file diff --git a/src/main/java/org/olat/group/manager/BusinessGroupDAO.java b/src/main/java/org/olat/group/manager/BusinessGroupDAO.java index aef6c2550c5..18f219f5776 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupDAO.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupDAO.java @@ -77,7 +77,7 @@ public class BusinessGroupDAO { SecurityGroup participantGroup = securityManager.createAndPersistSecurityGroup(); SecurityGroup waitingGroup = securityManager.createAndPersistSecurityGroup(); - businessgroup = new BusinessGroupImpl(type, name, description, ownerGroup, participantGroup, waitingGroup, null); + businessgroup = new BusinessGroupImpl(type, name, description, ownerGroup, participantGroup, waitingGroup); businessgroup.setMinParticipants(minParticipants); businessgroup.setMaxParticipants(maxParticipants); businessgroup.setWaitingListEnabled(waitingListEnabled); @@ -161,6 +161,11 @@ public class BusinessGroupDAO { return mergedGroup; } + public void delete(BusinessGroup group) { + EntityManager em = dbInstance.getCurrentEntityManager(); + em.remove(group); + } + /** * Work with the hibernate session * @param group @@ -293,7 +298,7 @@ public class BusinessGroupDAO { where = where(query, where); query.append("bgi in (") .append(" select relation.group from ").append(BGResourceRelation.class.getName()).append(" relation where relation.resource.key=:resourceKey") - .append(""); + .append(")"); } if(params.getTypes() != null && !params.getTypes().isEmpty()) { diff --git a/src/main/java/org/olat/group/delete/service/GroupDeletionManager.java b/src/main/java/org/olat/group/manager/BusinessGroupDeletionManager.java similarity index 83% rename from src/main/java/org/olat/group/delete/service/GroupDeletionManager.java rename to src/main/java/org/olat/group/manager/BusinessGroupDeletionManager.java index 08e5ee03d54..9eb1b11449e 100644 --- a/src/main/java/org/olat/group/delete/service/GroupDeletionManager.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupDeletionManager.java @@ -23,7 +23,7 @@ * under the Apache 2.0 license as the original file. */ -package org.olat.group.delete.service; +package org.olat.group.manager; import java.io.File; import java.util.ArrayList; @@ -31,8 +31,8 @@ import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.HashMap; -import java.util.Iterator; import java.util.List; +import java.util.Map; import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.SecurityGroup; @@ -41,7 +41,6 @@ import org.olat.commons.lifecycle.LifeCycleManager; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.commons.persistence.DBQuery; -import org.olat.core.gui.translator.PackageTranslator; import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; import org.olat.core.id.UserConstants; @@ -55,9 +54,7 @@ import org.olat.core.util.mail.MailTemplate; import org.olat.core.util.mail.MailerResult; import org.olat.core.util.mail.MailerWithTemplate; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; -import org.olat.group.manager.BusinessGroupArchiver; import org.olat.properties.Property; import org.olat.properties.PropertyManager; import org.olat.repository.delete.service.DeletionModule; @@ -67,7 +64,7 @@ import org.olat.repository.delete.service.DeletionModule; * Manager for group deletion. Handle deletion-email and db-access for group-deletion lists. * @author Chreistian Guretzki */ -public class GroupDeletionManager extends BasicManager { +public class BusinessGroupDeletionManager extends BasicManager { private static final String GROUP_ARCHIVE_DIR = "archive_deleted_groups"; @@ -79,8 +76,6 @@ public class GroupDeletionManager extends BasicManager { private static final String GROUPEXPORT_XML = "groupexport.xml"; private static final String GROUPARCHIVE_XLS = "grouparchive.xls"; - - private static GroupDeletionManager INSTANCE; public static final String SEND_DELETE_EMAIL_ACTION = "sendDeleteEmail"; private static final String GROUP_DELETED_ACTION = "groupDeleted"; @@ -91,9 +86,8 @@ public class GroupDeletionManager extends BasicManager { * [used by spring] * @param deletionModule */ - private GroupDeletionManager(DeletionModule deletionModule) { + private BusinessGroupDeletionManager(DeletionModule deletionModule) { this.module = deletionModule; - INSTANCE = this; } /** @@ -103,13 +97,6 @@ public class GroupDeletionManager extends BasicManager { this.businessGroupService = businessGroupService; } - /** - * @return Singleton. - */ - public static GroupDeletionManager getInstance() { - return INSTANCE; - } - public void setLastUsageDuration(int lastUsageDuration) { setProperty(LAST_USAGE_DURATION_PROPERTY_NAME, lastUsageDuration); } @@ -126,46 +113,42 @@ public class GroupDeletionManager extends BasicManager { return getPropertyByName(DELETE_EMAIL_DURATION_PROPERTY_NAME, DEFAULT_DELETE_EMAIL_DURATION); } - public String sendDeleteEmailTo(List selectedGroups, MailTemplate mailTemplate, boolean isTemplateChanged, String keyEmailSubject, - String keyEmailBody, Identity sender, PackageTranslator pT) { + public String sendDeleteEmailTo(List<BusinessGroup> selectedGroups, MailTemplate mailTemplate, boolean isTemplateChanged, String keyEmailSubject, + String keyEmailBody, Identity sender, Translator pT) { StringBuffer warningMessage = new StringBuffer(); if (mailTemplate != null) { MailerWithTemplate mailer = MailerWithTemplate.getInstance(); - HashMap identityGroupList = new HashMap(); - for (Iterator iter = selectedGroups.iterator(); iter.hasNext();) { - BusinessGroup group = (BusinessGroup)iter.next(); - + Map<Identity,List<BusinessGroup>> identityGroupList = new HashMap<Identity,List<BusinessGroup>>(); + for (BusinessGroup group: selectedGroups) { // Build owner group, list of identities SecurityGroup ownerGroup = group.getOwnerGroup(); - List ownerIdentities = BaseSecurityManager.getInstance().getIdentitiesOfSecurityGroup(ownerGroup); + List<Identity> ownerIdentities = BaseSecurityManager.getInstance().getIdentitiesOfSecurityGroup(ownerGroup); // loop over this list and send email - for (Iterator iterator = ownerIdentities.iterator(); iterator.hasNext();) { - Identity identity = (Identity) iterator.next(); + for (Identity identity : ownerIdentities) { if (identityGroupList.containsKey(identity) ) { - List groupsOfIdentity = (List)identityGroupList.get(identity); + List<BusinessGroup> groupsOfIdentity = identityGroupList.get(identity); groupsOfIdentity.add(group); } else { - List groupsOfIdentity = new ArrayList(); + List<BusinessGroup> groupsOfIdentity = new ArrayList<BusinessGroup>(); groupsOfIdentity.add(group); identityGroupList.put(identity, groupsOfIdentity); } } } // loop over identity list and send email - for (Iterator iterator = identityGroupList.keySet().iterator(); iterator.hasNext();) { - Identity identity = (Identity) iterator.next(); - + for (Identity identity : identityGroupList.keySet()) { mailTemplate.addToContext("responseTo", module.getEmailResponseTo()); if (!isTemplateChanged) { // Email template has NOT changed => take translated version of subject and body text - Translator identityTranslator = Util.createPackageTranslator(this.getClass(), I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage())); + String language = identity.getUser().getPreferences().getLanguage(); + Translator identityTranslator = Util.createPackageTranslator(BusinessGroupService.class, I18nManager.getInstance().getLocaleOrDefault(language)); mailTemplate.setSubjectTemplate(identityTranslator.translate(keyEmailSubject)); mailTemplate.setBodyTemplate(identityTranslator.translate(keyEmailBody)); } + // loop over all repositoriesOfIdentity to build email message StringBuilder buf = new StringBuilder(); - for (Iterator groupIterator = ((List)identityGroupList.get(identity)).iterator(); groupIterator.hasNext();) { - BusinessGroup group = (BusinessGroup) groupIterator.next(); + for (BusinessGroup group : identityGroupList.get(identity)) { buf.append("\n ").append( group.getName() ).append(" / ").append(FilterFactory.getHtmlTagsFilter().filter(group.getDescription())); } mailTemplate.addToContext("groupList", buf.toString()); @@ -180,8 +163,7 @@ public class GroupDeletionManager extends BasicManager { MailerResult mailerResult = mailer.sendMailUsingTemplateContext(identity, ccIdentities, null, mailTemplate, sender); if (mailerResult.getReturnCode() == MailerResult.OK) { // Email sended ok => set deleteEmailDate - for (Iterator groupIterator = ((List)identityGroupList.get(identity)).iterator(); groupIterator.hasNext();) { - BusinessGroup group = (BusinessGroup) groupIterator.next(); + for (BusinessGroup group : identityGroupList.get(identity)) { logAudit("Group-Deletion: Delete-email send to identity=" + identity.getName() + " with email=" + identity.getUser().getProperty(UserConstants.EMAIL, null) + " for group=" + group); markSendEmailEvent(group); } @@ -191,8 +173,7 @@ public class GroupDeletionManager extends BasicManager { } } else { // no template => User decides to sending no delete-email, mark only in lifecycle table 'sendEmail' - for (Iterator iter = selectedGroups.iterator(); iter.hasNext();) { - BusinessGroup group = (BusinessGroup)iter.next(); + for (BusinessGroup group : selectedGroups) { logAudit("Group-Deletion: Move in 'Email sent' section without sending email, group=" + group); markSendEmailEvent(group); } @@ -208,7 +189,7 @@ public class GroupDeletionManager extends BasicManager { group = bgs.mergeBusinessGroup(group); } - public List getDeletableGroups(int lastLoginDuration) { + public List<BusinessGroup> getDeletableGroups(int lastLoginDuration) { Calendar lastUsageLimit = Calendar.getInstance(); lastUsageLimit.add(Calendar.MONTH, - lastLoginDuration); logDebug("lastLoginLimit=" + lastUsageLimit); @@ -233,7 +214,8 @@ public class GroupDeletionManager extends BasicManager { return groups; } - public List getGroupsInDeletionProcess(int deleteEmailDuration) { + //TODO gm ONLY BUDDY???? + public List<BusinessGroup> getGroupsInDeletionProcess(int deleteEmailDuration) { Calendar deleteEmailLimit = Calendar.getInstance(); deleteEmailLimit.add(Calendar.DAY_OF_MONTH, - (deleteEmailDuration - 1)); logDebug("deleteEmailLimit=" + deleteEmailLimit); @@ -249,7 +231,8 @@ public class GroupDeletionManager extends BasicManager { return dbq.list(); } - public List getGroupsReadyToDelete(int deleteEmailDuration) { + //TODO gm ONLY BUDDY???? + public List<BusinessGroup> getGroupsReadyToDelete(int deleteEmailDuration) { Calendar deleteEmailLimit = Calendar.getInstance(); deleteEmailLimit.add(Calendar.DAY_OF_MONTH, - (deleteEmailDuration - 1)); logDebug("deleteEmailLimit=" + deleteEmailLimit); @@ -265,13 +248,12 @@ public class GroupDeletionManager extends BasicManager { return dbq.list(); } - public void deleteGroups(List objects) { - for (Iterator iter = objects.iterator(); iter.hasNext();) { - BusinessGroup businessGroup = (BusinessGroup) iter.next(); + public void deleteGroups(List<BusinessGroup> groups) { + for (BusinessGroup businessGroup : groups) { String archiveFileName = archive(getArchivFilePath(businessGroup), businessGroup); logAudit("Group-Deletion: archived businessGroup=" + businessGroup + " , archive-file-name=" + archiveFileName); CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup).deleteTools(businessGroup); - BusinessGroupManagerImpl.getInstance().deleteBusinessGroup(businessGroup); + businessGroupService.deleteBusinessGroup(businessGroup); LifeCycleManager.createInstanceFor(businessGroup).deleteTimestampFor(SEND_DELETE_EMAIL_ACTION); LifeCycleManager.createInstanceFor(businessGroup).markTimestampFor(GROUP_DELETED_ACTION, createLifeCycleLogDataFor(businessGroup)); logAudit("Group-Deletion: deleted businessGroup=" + businessGroup); @@ -325,7 +307,7 @@ public class GroupDeletionManager extends BasicManager { // Private Methods ////////////////// private int getPropertyByName(String name, int defaultValue) { - List properties = PropertyManager.getInstance().findProperties(null, null, null, PROPERTY_CATEGORY, name); + List<Property> properties = PropertyManager.getInstance().findProperties(null, null, null, PROPERTY_CATEGORY, name); if (properties.size() == 0) { return defaultValue; } else { @@ -334,7 +316,7 @@ public class GroupDeletionManager extends BasicManager { } private void setProperty(String propertyName, int value) { - List properties = PropertyManager.getInstance().findProperties(null, null, null, PROPERTY_CATEGORY, propertyName); + List<Property> properties = PropertyManager.getInstance().findProperties(null, null, null, PROPERTY_CATEGORY, propertyName); Property property = null; if (properties.size() == 0) { property = PropertyManager.getInstance().createPropertyInstance(null, null, null, PROPERTY_CATEGORY, propertyName, null, new Long(value), null, null); diff --git a/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java b/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java index 8a2cde4be82..3e83ed66bea 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java @@ -57,10 +57,7 @@ public class BusinessGroupImportExport { - /** - * @see org.olat.group.BusinessGroupManager#importGroups(org.olat.group.context.BGContext, - * java.io.File) - */ + public void importGroups(OLATResource resource, File fGroupExportXML) { if (!fGroupExportXML.exists()) return; diff --git a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java index d33100c6ad4..f7b507d3128 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java @@ -20,25 +20,68 @@ package org.olat.group.manager; import java.io.File; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Set; +import org.hibernate.ObjectNotFoundException; +import org.hibernate.StaleObjectStateException; import org.olat.basesecurity.BaseSecurity; +import org.olat.basesecurity.BaseSecurityManager; +import org.olat.basesecurity.Constants; import org.olat.basesecurity.SecurityGroup; +import org.olat.collaboration.CollaborationTools; +import org.olat.collaboration.CollaborationToolsFactory; import org.olat.commons.lifecycle.LifeCycleManager; +import org.olat.core.commons.persistence.DBFactory; +import org.olat.core.commons.taskExecutor.TaskExecutorManager; import org.olat.core.id.Identity; +import org.olat.core.logging.DBRuntimeException; +import org.olat.core.logging.KnownIssueException; +import org.olat.core.logging.OLog; +import org.olat.core.logging.Tracing; +import org.olat.core.logging.activity.ActionType; +import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; +import org.olat.core.util.coordinate.CoordinatorManager; +import org.olat.core.util.coordinate.SyncerExecutor; +import org.olat.core.util.mail.MailContext; +import org.olat.core.util.mail.MailContextImpl; +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.NotificationsManager; +import org.olat.core.util.notifications.Subscriber; +import org.olat.core.util.resource.OLATResourceableJustBeforeDeletedEvent; +import org.olat.course.nodes.projectbroker.service.ProjectBrokerManagerFactory; import org.olat.group.BusinessGroup; +import org.olat.group.BusinessGroupAddResponse; import org.olat.group.BusinessGroupService; +import org.olat.group.DeletableGroupData; +import org.olat.group.DeletableReference; +import org.olat.group.GroupLoggingAction; import org.olat.group.area.BGArea; -import org.olat.group.delete.service.GroupDeletionManager; +import org.olat.group.area.BGAreaManager; import org.olat.group.model.SearchBusinessGroupParams; +import org.olat.group.properties.BusinessGroupPropertyManager; +import org.olat.group.right.BGRightManager; import org.olat.group.ui.BGConfigFlags; +import org.olat.group.ui.BGMailHelper; +import org.olat.group.ui.edit.BusinessGroupModifiedEvent; +import org.olat.instantMessaging.InstantMessagingModule; +import org.olat.instantMessaging.syncservice.SyncSingleUserTask; +import org.olat.notifications.NotificationsManagerImpl; import org.olat.repository.RepositoryEntry; +import org.olat.repository.RepositoryManager; import org.olat.resource.OLATResource; import org.olat.resource.OLATResourceImpl; +import org.olat.testutils.codepoints.server.Codepoint; +import org.olat.util.logging.activity.LoggingResourceable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -50,8 +93,12 @@ import org.springframework.transaction.annotation.Transactional; */ @Service("businessGroupService") public class BusinessGroupServiceImpl implements BusinessGroupService { - + private final OLog log = Tracing.createLoggerFor(BusinessGroupServiceImpl.class); + @Autowired + private BGAreaManager areaManager; + @Autowired + private BGRightManager rightManager; @Autowired private BusinessGroupDAO businessGroupDAO; @Autowired @@ -62,6 +109,29 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { private BusinessGroupImportExport businessGroupImportExport; @Autowired private BusinessGroupArchiver businessGroupArchiver; + @Autowired + private RepositoryManager repositoryManager; + + + private List<DeletableGroupData> deleteListeners = new ArrayList<DeletableGroupData>(); + + + public void registerDeletableGroupDataListener(DeletableGroupData listener) { + this.deleteListeners.add(listener); + } + + public List<String> getDependingDeletablableListFor(BusinessGroup currentGroup, Locale locale) { + List<String> deletableList = new ArrayList<String>(); + for (DeletableGroupData deleteListener : deleteListeners) { + DeletableReference deletableReference = deleteListener.checkIfReferenced(currentGroup, locale); + if (deletableReference.isReferenced()) { + deletableList.add(deletableReference.getName()); + } + } + return deletableList; + } + + @Override public BusinessGroup createBusinessGroup(Identity creator, String name, String description, String type, @@ -76,8 +146,6 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { return group; } - - @Override public Set<BusinessGroup> createUniqueBusinessGroupsFor(Set<String> allNames, OLATResource resource, String bgDesc, Integer bgMin, Integer bgMax, Boolean enableWaitingList, Boolean enableAutoCloseRanks) { @@ -104,7 +172,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { public BusinessGroup setLastUsageFor(BusinessGroup group) { BusinessGroup reloadedGroup = businessGroupDAO.load(group.getKey()); reloadedGroup.setLastUsage(new Date()); - LifeCycleManager.createInstanceFor(reloadedGroup).deleteTimestampFor(GroupDeletionManager.SEND_DELETE_EMAIL_ACTION); + LifeCycleManager.createInstanceFor(reloadedGroup).deleteTimestampFor(BusinessGroupDeletionManager.SEND_DELETE_EMAIL_ACTION); updateBusinessGroup(reloadedGroup); return reloadedGroup; } @@ -144,6 +212,82 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { return businessGroupDAO.checkIfOneOrMoreNameExistsInContext(names, resource); } + @Override + public BusinessGroup copyBusinessGroup(BusinessGroup sourceBusinessGroup, String targetName, String targetDescription, Integer targetMin, + Integer targetMax, OLATResource targetResource, Map<BGArea, BGArea> areaLookupMap, boolean copyAreas, boolean copyCollabToolConfig, + boolean copyRights, boolean copyOwners, boolean copyParticipants, boolean copyMemberVisibility, boolean copyWaitingList) { + + // 1. create group, set waitingListEnabled, enableAutoCloseRanks like source business-group + BusinessGroup newGroup = createBusinessGroup(null, targetName, targetDescription, null, targetMin, targetMax, + sourceBusinessGroup.getWaitingListEnabled(), sourceBusinessGroup.getAutoCloseRanksEnabled(), targetResource); + // return immediately with null value to indicate an already take groupname + if (newGroup == null) { + return null; + } + // 2. copy tools + if (copyCollabToolConfig) { + CollaborationToolsFactory toolsF = CollaborationToolsFactory.getInstance(); + // get collab tools from original group and the new group + CollaborationTools oldTools = toolsF.getOrCreateCollaborationTools(sourceBusinessGroup); + CollaborationTools newTools = toolsF.getOrCreateCollaborationTools(newGroup); + // copy the collab tools settings + for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { + String tool = CollaborationTools.TOOLS[i]; + newTools.setToolEnabled(tool, oldTools.isToolEnabled(tool)); + } + String oldNews = oldTools.lookupNews(); + newTools.saveNews(oldNews); + } + // 3. copy member visibility + if (copyMemberVisibility) { + BusinessGroupPropertyManager bgpm = new BusinessGroupPropertyManager(newGroup); + bgpm.copyConfigurationFromGroup(sourceBusinessGroup); + } + // 4. copy areas + if (copyAreas) { + List<BGArea> areas = areaManager.findBGAreasOfBusinessGroup(sourceBusinessGroup); + for(BGArea area : areas) { + if (areaLookupMap == null) { + // reference target group to source groups areas + areaManager.addBGToBGArea(newGroup, area); + } else { + // reference target group to mapped group areas + BGArea mappedArea = (BGArea) areaLookupMap.get(area); + areaManager.addBGToBGArea(newGroup, mappedArea); + } + } + } + // 5. copy owners + if (copyOwners) { + List<Identity> owners = securityManager.getIdentitiesOfSecurityGroup(sourceBusinessGroup.getOwnerGroup()); + for (Identity identity:owners) { + securityManager.addIdentityToSecurityGroup(identity, newGroup.getOwnerGroup()); + } + } + // 6. copy participants + if (copyParticipants) { + List<Identity> participants = securityManager.getIdentitiesOfSecurityGroup(sourceBusinessGroup.getPartipiciantGroup()); + for(Identity identity:participants) { + securityManager.addIdentityToSecurityGroup(identity, newGroup.getPartipiciantGroup()); + } + } + // 7. copy rights + if (copyRights) { + List<String> sourceRights = rightManager.findBGRights(sourceBusinessGroup); + for (String sourceRight:sourceRights) { + rightManager.addBGRight(sourceRight, newGroup); + } + } + // 8. copy waiting-lisz + if (copyWaitingList) { + List<Identity> waitingList = securityManager.getIdentitiesOfSecurityGroup(sourceBusinessGroup.getWaitingGroup()); + for (Identity identity:waitingList) { + securityManager.addIdentityToSecurityGroup(identity, newGroup.getWaitingGroup()); + } + } + return newGroup; + } + @Override @Transactional public BusinessGroup findBusinessGroup(SecurityGroup secGroup) { @@ -169,7 +313,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { @Override public List<BusinessGroup> findBusinessGroupsWithWaitingListAttendedBy(String type, Identity identity, OLATResource resource) { // TODO Auto-generated method stub - return null; + return Collections.emptyList(); } @Override @@ -192,9 +336,6 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { return businessGroupDAO.findBusinessGroups(params, identity, ownedById, attendedById, resource, firstResult, maxResults); } - - - @Override @Transactional(readOnly=true) public int countContacts(Identity identity) { @@ -207,12 +348,151 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { return businessGroupDAO.findContacts(identity, firstResult, maxResults); } - - @Override public void deleteBusinessGroup(BusinessGroup group) { - // TODO Auto-generated method stub + try{ + OLATResourceableJustBeforeDeletedEvent delEv = new OLATResourceableJustBeforeDeletedEvent(group); + // notify all (currently running) BusinessGroupXXXcontrollers + // about the deletion which will occur. + CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(delEv, group); + + // refresh object to avoid stale object exceptions + group = loadBusinessGroup(group); + // 0) Loop over all deletableGroupData + for (DeletableGroupData deleteListener : deleteListeners) { + if(log.isDebug()) { + log.debug("deleteBusinessGroup: call deleteListener=" + deleteListener); + } + deleteListener.deleteGroupDataFor(group); + } + + // 0) Delete from project broker + ProjectBrokerManagerFactory.getProjectBrokerManager().deleteGroupDataFor(group); + // 1) Delete all group properties + + CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group); + ct.deleteTools(group);// deletes everything concerning properties&collabTools + + // 1.b)delete display member property + BusinessGroupPropertyManager bgpm = new BusinessGroupPropertyManager(group); + bgpm.deleteDisplayMembers(); + // 1.c)delete user in security groups + removeFromRepositoryEntrySecurityGroup(group); + // 2) Delete the group areas + areaManager.deleteBGtoAreaRelations(group); + // 3) Delete the group object itself on the database + businessGroupDAO.delete(group); + // 4) Delete the associated security groups + if(group.getOwnerGroup() != null) { + securityManager.deleteSecurityGroup(group.getOwnerGroup()); + } + // in all cases the participant groups + if(group.getPartipiciantGroup() != null) { + securityManager.deleteSecurityGroup(group.getPartipiciantGroup()); + } + // Delete waiting-group when one exists + if (group.getWaitingGroup() != null) { + securityManager.deleteSecurityGroup(group.getWaitingGroup()); + } + + // delete the publisher attached to this group (e.g. the forum and folder + // publisher) + NotificationsManagerImpl.getInstance().deletePublishersOf(group); + + // delete potential jabber group roster + if (InstantMessagingModule.isEnabled()) { + String groupID = InstantMessagingModule.getAdapter().createChatRoomString(group); + InstantMessagingModule.getAdapter().deleteRosterGroup(groupID); + } + log.audit("Deleted Business Group", group.toString()); + } catch(DBRuntimeException dbre) { + Throwable th = dbre.getCause(); + if ((th instanceof ObjectNotFoundException) && th.getMessage().contains("org.olat.group.BusinessGroupImpl")) { + //group already deleted + return; + } + if ((th instanceof StaleObjectStateException) && + (th.getMessage().startsWith("Row was updated or deleted by another transaction"))) { + // known issue OLAT-3654 + log.info("Group was deleted by another user in the meantime. Known issue OLAT-3654"); + throw new KnownIssueException("Group was deleted by another user in the meantime", 3654); + } else { + throw dbre; + } + } + } + + public MailerResult deleteBusinessGroupWithMail(BusinessGroup businessGroupTodelete, String businessPath, Identity deletedBy, Locale locale) { + Codepoint.codepoint(this.getClass(), "deleteBusinessGroupWithMail"); + + // collect data for mail + BaseSecurity secMgr = BaseSecurityManager.getInstance(); + List<Identity> users = new ArrayList<Identity>(); + SecurityGroup ownerGroup = businessGroupTodelete.getOwnerGroup(); + if (ownerGroup != null) { + List<Identity> owner = secMgr.getIdentitiesOfSecurityGroup(ownerGroup); + users.addAll(owner); + } + SecurityGroup partGroup = businessGroupTodelete.getPartipiciantGroup(); + if (partGroup != null) { + List<Identity> participants = secMgr.getIdentitiesOfSecurityGroup(partGroup); + users.addAll(participants); + } + SecurityGroup watiGroup = businessGroupTodelete.getWaitingGroup(); + if (watiGroup != null) { + List<Identity> waiting = secMgr.getIdentitiesOfSecurityGroup(watiGroup); + users.addAll(waiting); + } + // now delete the group first + deleteBusinessGroup(businessGroupTodelete); + // finally send email + MailerWithTemplate mailer = MailerWithTemplate.getInstance(); + MailTemplate mailTemplate = BGMailHelper.createDeleteGroupMailTemplate(businessGroupTodelete, deletedBy); + if (mailTemplate != null) { + //fxdiff VCRP-16: intern mail system + MailContext context = new MailContextImpl(businessPath); + MailerResult mailerResult = mailer.sendMailAsSeparateMails(context, users, null, null, mailTemplate, null); + //MailHelper.printErrorsAndWarnings(mailerResult, wControl, locale); + return mailerResult; + } + return null; + } + + private void removeFromRepositoryEntrySecurityGroup(BusinessGroup group) { + /* + BGContext context = group.getGroupContext(); + if(context == null) return;//nothing to do + + BGContextManager contextManager = BGContextManagerImpl.getInstance(); + List<Identity> coaches = group.getOwnerGroup() == null ? Collections.<Identity>emptyList() : + securityManager.getIdentitiesOfSecurityGroup(group.getOwnerGroup()); + List<Identity> participants = group.getPartipiciantGroup() == null ? Collections.<Identity>emptyList() : + securityManager.getIdentitiesOfSecurityGroup(group.getPartipiciantGroup()); + List<RepositoryEntry> entries = contextManager.findRepositoryEntriesForBGContext(context); + + for(Identity coach:coaches) { + List<BusinessGroup> businessGroups = contextManager.getBusinessGroupAsOwnerOfBGContext(coach, context) ; + if(context.isDefaultContext() && businessGroups.size() == 1) { + for(RepositoryEntry entry:entries) { + if(entry.getTutorGroup() != null && securityManager.isIdentityInSecurityGroup(coach, entry.getTutorGroup())) { + securityManager.removeIdentityFromSecurityGroup(coach, entry.getTutorGroup()); + } + } + } + } + + for(Identity participant:participants) { + List<BusinessGroup> businessGroups = contextManager.getBusinessGroupAsParticipantOfBGContext(participant, context) ; + if(context.isDefaultContext() && businessGroups.size() == 1) { + for(RepositoryEntry entry:entries) { + if(entry.getParticipantGroup() != null && securityManager.isIdentityInSecurityGroup(participant, entry.getParticipantGroup())) { + securityManager.removeIdentityFromSecurityGroup(participant, entry.getParticipantGroup()); + } + } + } + } + */ } @Override @@ -224,7 +504,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { @Override public List<Identity> getMembersOf(BusinessGroup group, boolean owner, boolean attendee) { // TODO Auto-generated method stub - return null; + return Collections.emptyList(); } @Override @@ -236,10 +516,417 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { @Override public List<Identity> getMembersOf(OLATResource resource, boolean owner, boolean attendee) { // TODO Auto-generated method stub - return null; + return Collections.emptyList(); } + @Override + public void addOwner(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags) { + //fxdiff VCRP-1,2: access control of resources + List<RepositoryEntry> res = businessGroupRelationDAO.findRepositoryEntries(Collections.singletonList(group), 0, 1); + for(RepositoryEntry re:res) { + if(re.getTutorGroup() == null) { + repositoryManager.createTutorSecurityGroup(re); + repositoryManager.updateRepositoryEntry(re); + } + if(re.getTutorGroup() != null && !securityManager.isIdentityInSecurityGroup(identity, re.getTutorGroup())) { + securityManager.addIdentityToSecurityGroup(identity, re.getTutorGroup()); + } + } + securityManager.addIdentityToSecurityGroup(identity, group.getOwnerGroup()); + + // add user to buddies rosters + addToRoster(ureqIdentity, identity, group, flags); + // notify currently active users of this business group + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.IDENTITY_ADDED_EVENT, group, identity); + // do logging + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_OWNER_ADDED, getClass(), LoggingResourceable.wrap(group), LoggingResourceable.wrap(identity)); + // send notification mail in your controller! + } + + @Override + public BusinessGroupAddResponse addOwners(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup group, BGConfigFlags flags) { + BusinessGroupAddResponse response = new BusinessGroupAddResponse(); + for (Identity identity : addIdentities) { + group = loadBusinessGroup(group); // reload business group + if (securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GUESTONLY)) { + response.getIdentitiesWithoutPermission().add(identity); + } + // Check if identity is already in group. make a db query in case + // someone in another workflow already added this user to this group. if + // found, add user to model + else if (securityManager.isIdentityInSecurityGroup(identity, group.getOwnerGroup())) { + response.getIdentitiesAlreadyInGroup().add(identity); + } else { + // identity has permission and is not already in group => add it + addOwner(ureqIdentity, identity, group, flags); + response.getAddedIdentities().add(identity); + log.audit("added identity '" + identity.getName() + "' to securitygroup with key " + group.getOwnerGroup().getKey()); + } + } + return response; + } + + @Override + public void addParticipant(Identity ureqIdentity, Identity identityToAdd, BusinessGroup group, BGConfigFlags flags) { + CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(group); + + //fxdiff VCRP-1,2: access control of resources + List<RepositoryEntry> res = businessGroupRelationDAO.findRepositoryEntries(Collections.singletonList(group), 0, -1); + for(RepositoryEntry re:res) { + if(re.getParticipantGroup() == null) { + repositoryManager.createParticipantSecurityGroup(re); + repositoryManager.updateRepositoryEntry(re); + } + if(re.getParticipantGroup() != null && !securityManager.isIdentityInSecurityGroup(identityToAdd, re.getParticipantGroup())) { + securityManager.addIdentityToSecurityGroup(identityToAdd, re.getParticipantGroup()); + } + } + securityManager.addIdentityToSecurityGroup(identityToAdd, group.getPartipiciantGroup()); + + // add user to buddies rosters + addToRoster(ureqIdentity, identityToAdd, group, flags); + // notify currently active users of this business group + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.IDENTITY_ADDED_EVENT, group, identityToAdd); + // do logging + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_PARTICIPANT_ADDED, getClass(), LoggingResourceable.wrap(group), LoggingResourceable.wrap(identityToAdd)); + // send notification mail in your controller! + } + + @Override + public BusinessGroupAddResponse addParticipants(final Identity ureqIdentity, final List<Identity> addIdentities, + final BusinessGroup group, final BGConfigFlags flags) { + + final BusinessGroupAddResponse response = new BusinessGroupAddResponse(); + CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerExecutor(){ + public void execute() { + final BusinessGroup currBusinessGroup = loadBusinessGroup(group); // reload business group + for (final Identity identity : addIdentities) { + if (securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GUESTONLY)) { + response.getIdentitiesWithoutPermission().add(identity); + } + // Check if identity is already in group. make a db query in case + // someone in another workflow already added this user to this group. if + // found, add user to model + else if (securityManager.isIdentityInSecurityGroup(identity, currBusinessGroup.getPartipiciantGroup())) { + response.getIdentitiesAlreadyInGroup().add(identity); + } else { + // identity has permission and is not already in group => add it + addParticipant(ureqIdentity, identity, currBusinessGroup, flags); + response.getAddedIdentities().add(identity); + log.audit("added identity '" + identity.getName() + "' to securitygroup with key " + currBusinessGroup.getPartipiciantGroup().getKey()); + } + } + }}); + return response; + } + + @Override + public void removeParticipant(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags) { + CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(group); + + //fxdiff VCRP-2: access control + List<RepositoryEntry> entries = businessGroupRelationDAO.findRepositoryEntries(Collections.singletonList(group), 0, -1); + for(RepositoryEntry entry:entries) { + if(entry.getParticipantGroup() != null && securityManager.isIdentityInSecurityGroup(identity, entry.getParticipantGroup())) { + securityManager.removeIdentityFromSecurityGroup(identity, entry.getParticipantGroup()); + } + } + securityManager.removeIdentityFromSecurityGroup(identity, group.getPartipiciantGroup()); + + // remove user from buddies rosters + removeFromRoster(identity, group, flags); + + //remove subsciptions if user gets removed + removeSubscriptions(identity, group); + + // notify currently active users of this business group + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.IDENTITY_REMOVED_EVENT, group, identity); + // do logging + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_PARTICIPANT_REMOVED, getClass(), LoggingResourceable.wrap(identity), LoggingResourceable.wrap(group)); + // Check if a waiting-list with auto-close-ranks is configurated + if ( group.getWaitingListEnabled().booleanValue() && group.getAutoCloseRanksEnabled().booleanValue() ) { + // even when doOnlyPostRemovingStuff is set to true we really transfer the first Identity here + transferFirstIdentityFromWaitingToParticipant(ureqIdentity, group, flags); + } + // send notification mail in your controller! + + } + + @Override + public void removeParticipants(final Identity ureqIdentity, final List<Identity> identities, final BusinessGroup group, final BGConfigFlags flags) { + CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerExecutor(){ + public void execute() { + for (Identity identity : identities) { + removeParticipant(ureqIdentity, identity, group, flags); + log.audit("removed identiy '" + identity.getName() + "' from securitygroup with key " + group.getPartipiciantGroup().getKey()); + } + } + }); + } + + @Override + public void addToWaitingList(Identity ureqIdentity, Identity identity, BusinessGroup group) { + CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(group); + securityManager.addIdentityToSecurityGroup(identity, group.getWaitingGroup()); + + // notify currently active users of this business group + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.IDENTITY_ADDED_EVENT, group, identity); + // do logging + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_TO_WAITING_LIST_ADDED, getClass(), LoggingResourceable.wrap(identity)); + // send notification mail in your controller! + } + + @Override + public BusinessGroupAddResponse addToWaitingList(final Identity ureqIdentity, final List<Identity> addIdentities, + final BusinessGroup group, final BGConfigFlags flags) { + + final BusinessGroupAddResponse response = new BusinessGroupAddResponse(); + final BusinessGroup currBusinessGroup = loadBusinessGroup(group); // reload business group + CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(currBusinessGroup, new SyncerExecutor(){ + public void execute() { + for (final Identity identity : addIdentities) { + if (securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GUESTONLY)) { + response.getIdentitiesWithoutPermission().add(identity); + } + // Check if identity is already in group. make a db query in case + // someone in another workflow already added this user to this group. if + // found, add user to model + else if (securityManager.isIdentityInSecurityGroup(identity, currBusinessGroup.getWaitingGroup())) { + response.getIdentitiesAlreadyInGroup().add(identity); + } else { + // identity has permission and is not already in group => add it + addToWaitingList(ureqIdentity, identity, currBusinessGroup); + response.getAddedIdentities().add(identity); + log.audit("added identity '" + identity.getName() + "' to securitygroup with key " + currBusinessGroup.getPartipiciantGroup().getKey()); + } + } + }}); + return response; + } + + @Override + public void removeFromWaitingList(Identity ureqIdentity, Identity identity, BusinessGroup group) { + CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(group); + securityManager.removeIdentityFromSecurityGroup(identity, group.getWaitingGroup()); + // notify currently active users of this business group + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.IDENTITY_REMOVED_EVENT, group, identity); + // do logging + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_FROM_WAITING_LIST_REMOVED, getClass(), LoggingResourceable.wrap(identity)); + // send notification mail in your controller! + } + + @Override + public void removeFromWaitingList(final Identity ureqIdentity, final List<Identity> identities, final BusinessGroup currBusinessGroup, + final BGConfigFlags flags) { + CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(currBusinessGroup, new SyncerExecutor(){ + public void execute() { + for (Identity identity : identities) { + removeFromWaitingList(ureqIdentity, identity, currBusinessGroup); + log.audit("removed identiy '" + identity.getName() + "' from securitygroup with key " + currBusinessGroup.getOwnerGroup().getKey()); + } + } + }); + } + + @Override + public int getPositionInWaitingListFor(Identity identity, BusinessGroup businessGroup) { + // get position in waiting-list + List<Object[]> identities = securityManager.getIdentitiesAndDateOfSecurityGroup(businessGroup.getWaitingGroup(), true); + int pos = 0; + for (int i = 0; i<identities.size(); i++) { + Object[] co = identities.get(i); + Identity waitingListIdentity = (Identity) co[0]; + if (waitingListIdentity.getName().equals(identity.getName()) ) { + pos = i+1;// '+1' because list begins with 0 + } + } + return pos; + } + + @Override + public BusinessGroupAddResponse moveIdentityFromWaitingListToParticipant(final List<Identity> identities, final Identity ureqIdentity, + final BusinessGroup currBusinessGroup, final BGConfigFlags flags) { + + final BusinessGroupAddResponse response = new BusinessGroupAddResponse(); + CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(currBusinessGroup,new SyncerExecutor(){ + public void execute() { + for (final Identity identity : identities) { + // check if idenity is allready in participant + if (!securityManager.isIdentityInSecurityGroup(identity,currBusinessGroup.getPartipiciantGroup()) ) { + // Idenity is not in participant-list => move idenity from waiting-list to participant-list + addParticipant(ureqIdentity, identity, currBusinessGroup, flags); + removeFromWaitingList(ureqIdentity, identity, currBusinessGroup); + response.getAddedIdentities().add(identity); + // notification mail is handled in controller + } else { + response.getIdentitiesAlreadyInGroup().add(identity); + } + } + }}); + return response; + } + + @Override + public BusinessGroupAddResponse addToSecurityGroupAndFireEvent(Identity ureqIdentity, List<Identity> addIdentities, SecurityGroup secGroup) { + BusinessGroupAddResponse response = new BusinessGroupAddResponse(); + for (Identity identity : addIdentities) { + if (securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GUESTONLY)) { + response.getIdentitiesWithoutPermission().add(identity); + } + // Check if identity is already in group. make a db query in case + // someone in another workflow already added this user to this group. if + // found, add user to model + else if (securityManager.isIdentityInSecurityGroup(identity, secGroup)) { + response.getIdentitiesAlreadyInGroup().add(identity); + } else { + // identity has permission and is not already in group => add it + securityManager.addIdentityToSecurityGroup(identity, secGroup); + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_OWNER_ADDED, getClass(), LoggingResourceable.wrap(identity)); + + response.getAddedIdentities().add(identity); + log.audit("added identity '" + identity.getName() + "' to securitygroup with key " + secGroup.getKey()); + } + } + return response; + } + + @Override + public void removeAndFireEvent(Identity ureqIdentity, List<Identity> identities, SecurityGroup secGroup) { + for (Identity identity : identities) { + securityManager.removeIdentityFromSecurityGroup(identity, secGroup); + log.audit("removed identiy '" + identity.getName() + "' from securitygroup with key " + secGroup.getKey()); + } + } + + + private void transferFirstIdentityFromWaitingToParticipant(Identity ureqIdentity, BusinessGroup group, BGConfigFlags flags) { + CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(group); + // Check if waiting-list is enabled and auto-rank-up + if (group.getWaitingListEnabled().booleanValue() && group.getAutoCloseRanksEnabled().booleanValue()) { + // Check if participant is not full + Integer maxSize = group.getMaxParticipants(); + int waitingPartipiciantSize = securityManager.countIdentitiesOfSecurityGroup(group.getPartipiciantGroup()); + if ( (maxSize != null) && (waitingPartipiciantSize < maxSize.intValue()) ) { + // ok it has free places => get first idenity from Waitinglist + List<Object[]> identities = securityManager.getIdentitiesAndDateOfSecurityGroup(group.getWaitingGroup(), true/*sortedByAddedDate*/); + int i = 0; + boolean transferNotDone = true; + while (i<identities.size() && transferNotDone) { + // It has an identity and transfer from waiting-list to participant-group is not done + Object[] co = (Object[])identities.get(i++); + Identity firstWaitingListIdentity = (Identity) co[0]; + //reload group + group = (BusinessGroup)DBFactory.getInstance().loadObject(group, true); + // Check if firstWaitingListIdentity is not allready in participant-group + if (!securityManager.isIdentityInSecurityGroup(firstWaitingListIdentity,group.getPartipiciantGroup())) { + // move the identity from the waitinglist to the participant group + + ActionType formerStickyActionType = ThreadLocalUserActivityLogger.getStickyActionType(); + try{ + // OLAT-4955: force add-participant and remove-from-waitinglist logging actions + // that get triggered in the next two methods to be of ActionType admin + // This is needed to make sure the targetIdentity ends up in the o_loggingtable + ThreadLocalUserActivityLogger.setStickyActionType(ActionType.admin); + addParticipant(ureqIdentity, firstWaitingListIdentity, group, flags); + removeFromWaitingList(ureqIdentity, firstWaitingListIdentity, group); + } finally { + ThreadLocalUserActivityLogger.setStickyActionType(formerStickyActionType); + } + // send a notification mail if available + MailTemplate mailTemplate = BGMailHelper.createWaitinglistTransferMailTemplate(group, ureqIdentity); + if (mailTemplate != null) { + MailerWithTemplate mailer = MailerWithTemplate.getInstance(); + //fxdiff VCRP-16: intern mail system + MailContext context = new MailContextImpl("[BusinessGroup:" + group.getKey() + "]"); + mailer.sendMail(context, firstWaitingListIdentity, null, null, mailTemplate, null); + // Does not report errors to current screen because this is the identity who triggered the transfer + log.warn("Could not send WaitinglistTransferMail for identity=" + firstWaitingListIdentity.getName()); + } + transferNotDone = false; + } + } + } + } else { + log.warn("Called method transferFirstIdentityFromWaitingToParticipant but waiting-list or autoCloseRanks is disabled."); + } + } + + private void addToRoster(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags) { + if (flags.isEnabled(BGConfigFlags.BUDDYLIST) && InstantMessagingModule.isEnabled()) { + //evaluate whether to sync or not + boolean syncBuddy = InstantMessagingModule.getAdapter().getConfig().isSyncPersonalGroups(); + boolean isBuddy = group.getType().equals(BusinessGroup.TYPE_BUDDYGROUP); + + boolean syncLearn = InstantMessagingModule.getAdapter().getConfig().isSyncLearningGroups(); + boolean isLearn = group.getType().equals(BusinessGroup.TYPE_LEARNINGROUP); + + //only sync when a group is a certain type and this type is configured that you want to sync it + if ((syncBuddy && isBuddy) || (syncLearn && isLearn)) { + String groupID = InstantMessagingModule.getAdapter().createChatRoomString(group); + String groupDisplayName = group.getName(); + //course group enrolment is time critial so we move this in an separate thread and catch all failures + TaskExecutorManager.getInstance().runTask(new SyncSingleUserTask(ureqIdentity, groupID, groupDisplayName, identity)); + } + } + } + + @Override + public void removeOwners(Identity ureqIdentity, Collection<Identity> identitiesToRemove, BusinessGroup group, BGConfigFlags flags) { + //fxdiff VCRP-2: access control + List<RepositoryEntry> entries = businessGroupRelationDAO.findRepositoryEntries(Collections.singletonList(group), 0, -1); + for(RepositoryEntry entry:entries) { + if(entry.getTutorGroup() != null) { + for(Identity identity:identitiesToRemove) { + if(securityManager.isIdentityInSecurityGroup(identity, entry.getTutorGroup())) { + securityManager.removeIdentityFromSecurityGroup(identity, entry.getTutorGroup()); + } + } + } + } + + for(Identity identity:identitiesToRemove) { + securityManager.removeIdentityFromSecurityGroup(identity, group.getOwnerGroup()); + // remove user from buddies rosters + removeFromRoster(identity, group, flags); + + //remove subsciptions if user gets removed + removeSubscriptions(identity, group); + + // notify currently active users of this business group + if (identity.getKey().equals(ureqIdentity.getKey()) ) { + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.MYSELF_ASOWNER_REMOVED_EVENT, group, identity); + } else { + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.IDENTITY_REMOVED_EVENT, group, identity); + } + // do logging + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_OWNER_REMOVED, getClass(), LoggingResourceable.wrap(group), LoggingResourceable.wrap(identity)); + // send notification mail in your controller! + } + } + + private void removeSubscriptions(Identity identity, BusinessGroup group) { + NotificationsManager notiMgr = NotificationsManager.getInstance(); + List<Subscriber> l = notiMgr.getSubscribers(identity); + for (Iterator<Subscriber> iterator = l.iterator(); iterator.hasNext();) { + Subscriber subscriber = iterator.next(); + Long resId = subscriber.getPublisher().getResId(); + Long groupKey = group.getKey(); + if (resId != null && groupKey != null && resId.equals(groupKey)) { + notiMgr.unsubscribe(subscriber); + } + } + } + + private void removeFromRoster(Identity identity, BusinessGroup group, BGConfigFlags flags) { + if (flags.isEnabled(BGConfigFlags.BUDDYLIST) && InstantMessagingModule.isEnabled()) { + // only remove user from roster if not in other security group + if (!isIdentityInBusinessGroup(identity, group)) { + String groupID = InstantMessagingModule.getAdapter().createChatRoomString(group); + InstantMessagingModule.getAdapter().removeUserFromFriendsRoster(groupID, identity.getName()); + } + } + } @Override public List<OLATResource> findResources(Collection<BusinessGroup> groups, int firstResult, int maxResults) { @@ -276,7 +963,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { @Override public void exportGroups(List<BusinessGroup> groups, File fExportFile) { // TODO Auto-generated method stub - + } @Override @@ -299,31 +986,4 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { public File archiveGroupMembers(OLATResource resource, List<String> columnList, List<BusinessGroup> groupList, String archiveType, Locale locale, String charset) { return businessGroupArchiver.archiveGroupMembers(resource, columnList, groupList, archiveType, locale, charset); } - - - - @Override - public List<String> getDependingDeletablableListFor(BusinessGroup currentGroup, Locale locale) { - // TODO Auto-generated method stub - return null; - } - - - //memberships management - - - - @Override - public void removeParticipantsAndFireEvent(Identity ureqIdentity, List<Identity> identities, BusinessGroup group, BGConfigFlags flags) { - // TODO Auto-generated method stub - - } - - @Override - public void removeOwnerAndFireEvent(Identity identity, Identity currentIdentity, BusinessGroup group, BGConfigFlags flags, boolean b) { - // TODO Auto-generated method stub - - } - - } diff --git a/src/main/java/org/olat/group/right/BGRightManager.java b/src/main/java/org/olat/group/right/BGRightManager.java index 8b5e6cf0bbe..72287e605d5 100644 --- a/src/main/java/org/olat/group/right/BGRightManager.java +++ b/src/main/java/org/olat/group/right/BGRightManager.java @@ -84,5 +84,5 @@ public interface BGRightManager { * @return a list of all business group rights associated with the given * business group */ - public abstract List findBGRights(BusinessGroup rightGroup); + public List<String> findBGRights(BusinessGroup rightGroup); } \ No newline at end of file diff --git a/src/main/java/org/olat/group/right/BGRightManagerImpl.java b/src/main/java/org/olat/group/right/BGRightManagerImpl.java index 33a67663cce..65e14c946f9 100644 --- a/src/main/java/org/olat/group/right/BGRightManagerImpl.java +++ b/src/main/java/org/olat/group/right/BGRightManagerImpl.java @@ -32,7 +32,6 @@ import java.util.List; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.Policy; import org.olat.core.id.Identity; -import org.olat.core.logging.AssertException; import org.olat.core.manager.BasicManager; import org.olat.group.BusinessGroup; import org.olat.group.manager.BusinessGroupRelationDAO; @@ -42,7 +41,8 @@ import org.springframework.stereotype.Service; /** * Description:<BR> - * TODO: Class Description for BGRightManagerImpl Initial Date: Aug 24, 2004 + * + * Initial Date: Aug 24, 2004 * * @author gnaegi */ @@ -54,21 +54,14 @@ public class BGRightManagerImpl extends BasicManager implements BGRightManager { @Autowired private BusinessGroupRelationDAO businessGroupRelationDAO; - /** * @see org.olat.group.right.BGRightManager#addBGRight(java.lang.String, * org.olat.group.BusinessGroup) */ public void addBGRight(String bgRight, BusinessGroup rightGroup) { - if (bgRight.indexOf(BG_RIGHT_PREFIX) == -1) throw new AssertException("Groups rights must start with prefix '" + BG_RIGHT_PREFIX - + "', but given right is ::" + bgRight); - if (BusinessGroup.TYPE_RIGHTGROUP.equals(rightGroup.getType())) { - List<OLATResource> resources = businessGroupRelationDAO.findResources(Collections.singletonList(rightGroup), 0, -1); - for(OLATResource resource:resources) { - securityManager.createAndPersistPolicy(rightGroup.getPartipiciantGroup(), bgRight, resource); - } - } else { - throw new AssertException("Only right groups can have bg rights, but type was ::" + rightGroup.getType()); + List<OLATResource> resources = businessGroupRelationDAO.findResources(Collections.singletonList(rightGroup), 0, -1); + for(OLATResource resource:resources) { + securityManager.createAndPersistPolicy(rightGroup.getPartipiciantGroup(), bgRight, resource); } } @@ -77,39 +70,18 @@ public class BGRightManagerImpl extends BasicManager implements BGRightManager { * org.olat.group.BusinessGroup) */ public void removeBGRight(String bgRight, BusinessGroup rightGroup) { - if (BusinessGroup.TYPE_RIGHTGROUP.equals(rightGroup.getType())) { - List<OLATResource> resources = businessGroupRelationDAO.findResources(Collections.singletonList(rightGroup), 0, -1); - for(OLATResource resource:resources) { - securityManager.deletePolicy(rightGroup.getPartipiciantGroup(), bgRight, resource); - } - } else { - throw new AssertException("Only right groups can have bg rights, but type was ::" + rightGroup.getType()); + List<OLATResource> resources = businessGroupRelationDAO.findResources(Collections.singletonList(rightGroup), 0, -1); + for(OLATResource resource:resources) { + securityManager.deletePolicy(rightGroup.getPartipiciantGroup(), bgRight, resource); } } - /** - * @see org.olat.group.right.BGRightManager#hasBGRight(java.lang.String, - * org.olat.group.BusinessGroup) - */ - /* - * public boolean hasBGRight(String bgRight, BusinessGroup rightGroup) { if - * (BusinessGroup.TYPE_RIGHTGROUP.equals(rightGroup.getType())) { Manager secm = - * ManagerFactory.getManager(); return - * secm.isGroupPermittedOnResourceable(rightGroup.getPartipiciantGroup(), - * bgRight, rightGroup.getGroupContext()); } throw new AssertException("Only - * right groups can have bg rights, but type was ::" + rightGroup.getType()); } - */ - /** * @see org.olat.group.right.BGRightManager#hasBGRight(java.lang.String, * org.olat.core.id.Identity, org.olat.group.context.BGContext) */ public boolean hasBGRight(String bgRight, Identity identity, OLATResource resource) { - String groupType = ""; - if (BusinessGroup.TYPE_RIGHTGROUP.equals(groupType)) { - return securityManager.isIdentityPermittedOnResourceable(identity, bgRight, resource); - } - throw new AssertException("Only right groups can have bg rights, but type was ::" + groupType); + return securityManager.isIdentityPermittedOnResourceable(identity, bgRight, resource); } /** diff --git a/src/main/java/org/olat/group/right/BGRights.java b/src/main/java/org/olat/group/right/BGRights.java index bf90a907278..7b410dc0711 100644 --- a/src/main/java/org/olat/group/right/BGRights.java +++ b/src/main/java/org/olat/group/right/BGRights.java @@ -42,12 +42,12 @@ public interface BGRights { /** * @return A list of right keys */ - abstract List getRights(); + public List<String> getRights(); /** * @param right * @return The translated right */ - abstract String transateRight(String right); + public String transateRight(String right); } diff --git a/src/main/java/org/olat/group/site/GroupsManagementSite.java b/src/main/java/org/olat/group/site/GroupsManagementSite.java deleted file mode 100644 index bc61e0370c9..00000000000 --- a/src/main/java/org/olat/group/site/GroupsManagementSite.java +++ /dev/null @@ -1,105 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <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 -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <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> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -*/ - -package org.olat.group.site; - -import java.util.Locale; - -import org.olat.ControllerFactory; -import org.olat.core.commons.chiefcontrollers.BaseChiefController; -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.gui.control.navigation.DefaultNavElement; -import org.olat.core.gui.control.navigation.NavElement; -import org.olat.core.gui.control.navigation.SiteInstance; -import org.olat.core.gui.translator.PackageTranslator; -import org.olat.core.gui.translator.Translator; -import org.olat.core.id.OLATResourceable; -import org.olat.core.id.context.BusinessControlFactory; -import org.olat.core.id.context.StateSite; -import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; -import org.olat.core.util.Util; -import org.olat.core.util.resource.OresHelper; -import org.olat.group.ui.context.BGContextManagementController; -import org.olat.util.logging.activity.LoggingResourceable; - -/** - * Description:<br> - * <P> - * Initial Date: 19.07.2005 <br> - * - * @author Felix Jost - */ -public class GroupsManagementSite implements SiteInstance { - private static final OLATResourceable ORES_GROUPSMANAGEMENT = OresHelper.lookupType(BGContextManagementController.class); - - // refer to the definitions in org.olat - private static final String PACKAGE = Util.getPackageName(BaseChiefController.class); - - private NavElement origNavElem; - private NavElement curNavElem; - - /** - * - */ - public GroupsManagementSite(Locale loc) { - Translator trans = new PackageTranslator(PACKAGE, loc); - origNavElem = new DefaultNavElement(trans.translate("topnav.gm"), trans.translate("topnav.gm.alt"), "o_site_groupsmanagement"); - curNavElem = new DefaultNavElement(origNavElem); - } - - /** - * @see org.olat.navigation.SiteInstance#getNavElement() - */ - public NavElement getNavElement() { - return curNavElem; - } - - /** - * @see org.olat.navigation.SiteInstance#createController(org.olat.core.gui.UserRequest, - * org.olat.core.gui.control.WindowControl) - */ - public MainLayoutController createController(UserRequest ureq, WindowControl wControl) { - //fxdiff BAKS-7 Resume function - OLATResourceable ores = OresHelper.createOLATResourceableInstance(GroupsManagementSite.class, 0l); - ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrapBusinessPath(ores)); - WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, ores, new StateSite(this), wControl, true); - MainLayoutController c = ControllerFactory.createLaunchController(ORES_GROUPSMANAGEMENT, null, ureq, bwControl, true); - return c; - } - - /** - * @see org.olat.navigation.SiteInstance#isKeepState() - */ - public boolean isKeepState() { - return true; - } - - public void reset() { - curNavElem = new DefaultNavElement(origNavElem); - } - -} diff --git a/src/main/java/org/olat/group/site/GroupsManagementSiteDef.java b/src/main/java/org/olat/group/site/GroupsManagementSiteDef.java deleted file mode 100644 index a33c5d92712..00000000000 --- a/src/main/java/org/olat/group/site/GroupsManagementSiteDef.java +++ /dev/null @@ -1,89 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <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 -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <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> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -*/ - -package org.olat.group.site; - -import java.util.List; - -import org.olat.core.extensions.ExtensionResource; -import org.olat.core.gui.UserRequest; -import org.olat.core.gui.control.WindowControl; -import org.olat.core.gui.control.navigation.AbstractSiteDefinition; -import org.olat.core.gui.control.navigation.SiteDefinition; -import org.olat.core.gui.control.navigation.SiteInstance; - -/** - * Description:<br> - * Initial Date: 12.07.2005 <br> - * - * @author Felix Jost - */ -public class GroupsManagementSiteDef extends AbstractSiteDefinition implements SiteDefinition { - - /** - * - */ - public GroupsManagementSiteDef() { - super(); - // TODO Auto-generated constructor stub - } - - /** - * @see org.olat.core.extensions.OLATExtension#getName() - */ - public String getName() { - return "groupssite"; - } - - /** - * @see org.olat.core.extensions.OLATExtension#getExtensionResources() - */ - public List getExtensionResources() { - // no ressources, part of main css - return null; - } - - /** - * @see org.olat.core.extensions.OLATExtension#getExtensionCSS() - */ - public ExtensionResource getExtensionCSS() { - // no ressources, part of main css - return null; - } - - /** - * @see org.olat.navigation.SiteDefinition#createSite(org.olat.core.gui.UserRequest, - * org.olat.core.gui.control.WindowControl) - */ - public SiteInstance createSite(UserRequest ureq, WindowControl wControl) { - SiteInstance si = null; - if (ureq.getUserSession().getRoles().isGroupManager()) { - // only groupmanagers see this site (restricted rights and navigation) - si = new GroupsManagementSite(ureq.getLocale()); - } // no access for all others - return si; - } - -} diff --git a/src/main/java/org/olat/group/ui/BGControllerFactory.java b/src/main/java/org/olat/group/ui/BGControllerFactory.java index 2280b0e428a..0ee19b1a575 100644 --- a/src/main/java/org/olat/group/ui/BGControllerFactory.java +++ b/src/main/java/org/olat/group/ui/BGControllerFactory.java @@ -35,7 +35,6 @@ import org.olat.core.id.context.BusinessControlFactory; import org.olat.core.id.context.ContextEntry; import org.olat.core.logging.AssertException; import org.olat.group.BusinessGroup; -import org.olat.group.context.BGContext; import org.olat.group.ui.edit.BusinessGroupEditController; import org.olat.group.ui.main.BGMainController; import org.olat.group.ui.management.BGManagementController; @@ -214,17 +213,16 @@ public class BGControllerFactory { * @param useBackLink * @return a business group management controller for this group context */ - public BGManagementController createManagementController(UserRequest ureq, WindowControl wControl, BGContext bgContext, + public BGManagementController createManagementController(UserRequest ureq, WindowControl wControl, OLATResource resource, boolean useBackLink) { - if (bgContext == null) throw new AssertException("Group context must not be null"); - if (BusinessGroup.TYPE_LEARNINGROUP.equals(bgContext.getGroupType())) { - return createLearningGroupManagementController(ureq, wControl, bgContext, useBackLink); + return createLearningGroupManagementController(ureq, wControl, resource, useBackLink); + /* } else if (BusinessGroup.TYPE_RIGHTGROUP.equals(bgContext.getGroupType())) { return createRightGroupManagementController(ureq, wControl, bgContext, useBackLink); } else { throw new AssertException("Can't handle group type ::" + bgContext.getGroupType()); - } + }*/ } /** @@ -259,19 +257,19 @@ public class BGControllerFactory { } - private BGManagementController createLearningGroupManagementController(UserRequest ureq, WindowControl wControl, BGContext bgContext, + private BGManagementController createLearningGroupManagementController(UserRequest ureq, WindowControl wControl, OLATResource resource, boolean useBackLink) { // controller configuration BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); flags.setEnabled(BGConfigFlags.BACK_SWITCH, useBackLink); - return new BGManagementController(ureq, wControl, bgContext, flags); + return new BGManagementController(ureq, wControl, resource, flags); } - private BGManagementController createRightGroupManagementController(UserRequest ureq, WindowControl wControl, BGContext bgContext, + private BGManagementController createRightGroupManagementController(UserRequest ureq, WindowControl wControl, OLATResource resource, boolean useBackLink) { BGConfigFlags flags = BGConfigFlags.createRightGroupDefaultFlags(); flags.setEnabled(BGConfigFlags.BACK_SWITCH, useBackLink); - return new BGManagementController(ureq, wControl, bgContext, flags); + return new BGManagementController(ureq, wControl, resource, flags); } /** diff --git a/src/main/java/org/olat/group/ui/BusinessGroupTableModelWithMaxSize.java b/src/main/java/org/olat/group/ui/BusinessGroupTableModelWithMaxSize.java index 6260b521993..9a9cfbb9fb7 100644 --- a/src/main/java/org/olat/group/ui/BusinessGroupTableModelWithMaxSize.java +++ b/src/main/java/org/olat/group/ui/BusinessGroupTableModelWithMaxSize.java @@ -30,6 +30,7 @@ import java.util.List; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurityManager; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.components.table.DefaultTableDataModel; import org.olat.core.gui.components.table.TableDataModel; import org.olat.core.gui.translator.Translator; @@ -38,8 +39,7 @@ import org.olat.core.logging.Tracing; import org.olat.core.util.Formatter; import org.olat.core.util.filter.FilterFactory; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; /** * Description:<BR> @@ -57,7 +57,7 @@ public class BusinessGroupTableModelWithMaxSize extends DefaultTableDataModel im private Identity identity; private boolean cancelEnrollEnabled; private BaseSecurity securityManager; - private BusinessGroupManager businessGroupManager; + private BusinessGroupService businessGroupService; /** * @param groups List of business groups @@ -71,7 +71,7 @@ public class BusinessGroupTableModelWithMaxSize extends DefaultTableDataModel im this.trans = trans; this.identity = identity; securityManager = BaseSecurityManager.getInstance(); - businessGroupManager = BusinessGroupManagerImpl.getInstance(); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); this.cancelEnrollEnabled = cancelEnrollEnabled; } @@ -125,7 +125,7 @@ public class BusinessGroupTableModelWithMaxSize extends DefaultTableDataModel im if (securityManager.isIdentityInSecurityGroup(this.identity,businessGroup.getPartipiciantGroup())) { return trans.translate("grouplist.table.state.onPartipiciantList"); } else if (securityManager.isIdentityInSecurityGroup(this.identity,businessGroup.getWaitingGroup())) { - int pos = businessGroupManager.getPositionInWaitingListFor(identity,businessGroup); + int pos = businessGroupService.getPositionInWaitingListFor(identity,businessGroup); String[] onWaitingListArgs = new String[] { Integer.toString(pos) }; return trans.translate("grouplist.table.state.onWaitingList",onWaitingListArgs); } else if (max != null && !businessGroup.getWaitingListEnabled().booleanValue() && (numbParts.intValue() >= max.intValue()) ) { diff --git a/src/main/java/org/olat/group/ui/context/BGContextEditController.java b/src/main/java/org/olat/group/ui/context/BGContextEditController.java deleted file mode 100644 index 15f94ce8e93..00000000000 --- a/src/main/java/org/olat/group/ui/context/BGContextEditController.java +++ /dev/null @@ -1,411 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <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 -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <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> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -*/ - -package org.olat.group.ui.context; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang.StringEscapeUtils; -import org.olat.admin.securitygroup.gui.GroupController; -import org.olat.admin.securitygroup.gui.IdentitiesAddEvent; -import org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent; -import org.olat.basesecurity.BaseSecurityManager; -import org.olat.core.commons.persistence.PersistenceHelper; -import org.olat.core.gui.UserRequest; -import org.olat.core.gui.components.Component; -import org.olat.core.gui.components.link.Link; -import org.olat.core.gui.components.link.LinkFactory; -import org.olat.core.gui.components.panel.Panel; -import org.olat.core.gui.components.tabbedpane.TabbedPane; -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.TableGuiConfiguration; -import org.olat.core.gui.components.velocity.VelocityContainer; -import org.olat.core.gui.control.Controller; -import org.olat.core.gui.control.ControllerEventListener; -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.modal.DialogBoxController; -import org.olat.core.gui.control.generic.modal.DialogBoxUIFactory; -import org.olat.core.gui.translator.Translator; -import org.olat.core.id.Identity; -import org.olat.core.util.Util; -import org.olat.core.util.coordinate.CoordinatorManager; -import org.olat.core.util.coordinate.LockResult; -import org.olat.core.util.event.GenericEventListener; -import org.olat.core.util.event.MultiUserEvent; -import org.olat.course.CourseModule; -import org.olat.course.groupsandrights.ui.DefaultContextTranslationHelper; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; -import org.olat.repository.RepositoryEntry; -import org.olat.repository.RepositoryTableModel; -import org.olat.repository.controllers.ReferencableEntriesSearchController; - -/** - * Description:<BR> - * Controller to edit a business group context. The editor proviedes a tabbed - * pane with the following tabs: - details / metadata - owner management (who - * can edit this group context) - resource management (where to use this group - * context) This controller however does no functionality to create groups, - * learning areas etc. See BGManagementController for this functionality - * <P> - * Initial Date: Jan 31, 2005 - * - * @author gnaegi - */ -public class BGContextEditController extends BasicController implements ControllerEventListener, GenericEventListener { - private GroupController ownerCtr; - private TabbedPane tabbedPane; - private Panel content; - private VelocityContainer editVC; - private VelocityContainer tabDetailsVC; - private VelocityContainer tabOwnersVC; - private VelocityContainer tabResourcesVC; - - private BGContext groupContext; - private BGContextFormController contextController; - private TableController resourcesCtr; - private RepositoryTableModel repoTableModel; - private List repoTableModelEntries; - private RepositoryEntry currentRepoEntry; - private ReferencableEntriesSearchController repoSearchCtr; - private CloseableModalController cmc; - private DialogBoxController confirmRemoveResource; - private Link addTabResourcesButton; - private LockResult lockEntry; - private DialogBoxController alreadyLockedDialogController; - - private final BGContextManagerImpl contextManager; - - /** - * Constructor for a business group edit controller - * - * @param ureq The user request - * @param wControl The window control - * @param groupContext The business group context to be edited - */ - public BGContextEditController(UserRequest ureq, WindowControl wControl, BGContext groupContext) { - super(ureq, wControl); - // reload context to minimize stale object exception - contextManager = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - this.groupContext = contextManager.loadBGContext(groupContext); - - - // try to acquire edit lock on business group context - String lockSubKey = "contextEdit"; - this.lockEntry = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(groupContext, ureq.getIdentity(), lockSubKey); - if (this.lockEntry.isSuccess()) { - this.tabbedPane = new TabbedPane("tabbedPane", ureq.getLocale()); - this.tabbedPane.addListener(this); - // details and metadata - this.tabDetailsVC = doCreateTabDetails(ureq); - this.tabbedPane.addTab(translate("edit.tab.details"), this.tabDetailsVC); - // owner group management - this.tabOwnersVC = doCreateTabOwners(ureq); - this.tabbedPane.addTab(translate("edit.tab.owners"), this.tabOwnersVC); - // associated resources management - this.tabResourcesVC = doCreateTabResources(ureq, false); - this.tabbedPane.addTab(translate("edit.tab.resources"), this.tabResourcesVC); - // put everything in a velocity container - this.editVC = createVelocityContainer("contextmanagement_edit"); - this.editVC.put("tabbedpane", this.tabbedPane); - String title = DefaultContextTranslationHelper.translateIfDefaultContextName(groupContext, getTranslator()); - this.editVC.contextPut("title", getTranslator().translate("edit.title", new String[] { "<i>" + StringEscapeUtils.escapeHtml(title) + "</i>" })); - this.content = new Panel("contexteditpanel"); - this.content.setContent(this.editVC); - }else{ - //lock was not successful ! - this.alreadyLockedDialogController = DialogBoxUIFactory.createResourceLockedMessage(ureq, wControl, this.lockEntry, "error.message.locked", getTranslator()); - listenTo(this.alreadyLockedDialogController); - this.alreadyLockedDialogController.activate(); - } - // register for changes in this group context - CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, ureq.getIdentity(), groupContext); - - putInitialPanel(this.content); - } - - /** - * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, - * org.olat.core.gui.components.Component, org.olat.core.gui.control.Event) - */ - @Override - public void event(UserRequest ureq, Component source, Event event) { - if (source == this.addTabResourcesButton) { - if (this.groupContext.isDefaultContext()) { - if (this.repoTableModelEntries.size() == 1) { - // display error and exit - do not remove resource - showError("resource.error.isDefault",null); - this.contextController.setValues(this.groupContext); - return; - } - } - removeAsListenerAndDispose(repoSearchCtr); - repoSearchCtr = new ReferencableEntriesSearchController(getWindowControl(), ureq, CourseModule.getCourseTypeName(), translate("resources.add")); - listenTo(repoSearchCtr); - - removeAsListenerAndDispose(cmc); - cmc = new CloseableModalController(getWindowControl(), translate("close"), this.repoSearchCtr.getInitialComponent(), true, translate("resources.add.title")); - listenTo(cmc); - - cmc.activate(); - } - } - - /** - * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, - * org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event) - */ - @Override - public void event(UserRequest ureq, Controller source, Event event) { - if (source == this.repoSearchCtr) { - if (event == ReferencableEntriesSearchController.EVENT_REPOSITORY_ENTRY_SELECTED) { - // repository search controller done - RepositoryEntry re = this.repoSearchCtr.getSelectedEntry(); - removeAsListenerAndDispose(this.repoSearchCtr); - this.cmc.deactivate(); - if (re != null && !this.repoTableModelEntries.contains(re)) { - // check if already in model - boolean alreadyAssociated = PersistenceHelper.listContainsObjectByKey(this.repoTableModelEntries, re); - if (!alreadyAssociated) { - doAddRepositoryEntry(re); - fireEvent(ureq, Event.CHANGED_EVENT); - MultiUserEvent mue = new BGContextEvent(BGContextEvent.RESOURCE_ADDED, this.groupContext); - CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, this.groupContext); - } - } - } - } else if (source == this.ownerCtr) { - if(event instanceof IdentitiesAddEvent ) { - List<Identity> addedIdentities = new ArrayList<Identity>(); - for (Identity identity : ((IdentitiesAddEvent) event).getAddIdentities()) { - if (!BaseSecurityManager.getInstance().isIdentityInSecurityGroup(identity, this.groupContext.getOwnerGroup())) { - BaseSecurityManager.getInstance().addIdentityToSecurityGroup(identity, this.groupContext.getOwnerGroup()); - addedIdentities.add(identity); - } - } - ((IdentitiesAddEvent) event).setIdentitiesAddedEvent(addedIdentities); - } else if (event instanceof IdentitiesRemoveEvent) { - for (Identity identity : ((IdentitiesRemoveEvent) event).getRemovedIdentities()) { - if (BaseSecurityManager.getInstance().isIdentityInSecurityGroup(identity, this.groupContext.getOwnerGroup())) { - BaseSecurityManager.getInstance().removeIdentityFromSecurityGroup(identity, this.groupContext.getOwnerGroup()); - } - } - } - fireEvent(ureq, Event.CHANGED_EVENT); - } else if (source == this.resourcesCtr) { - if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) { - TableEvent te = (TableEvent) event; - String actionid = te.getActionId(); - int rowid = te.getRowId(); - this.currentRepoEntry = (RepositoryEntry)this.repoTableModel.getObject(rowid); - if (actionid.equals(RepositoryTableModel.TABLE_ACTION_SELECT_LINK)) { - if (this.groupContext.isDefaultContext()) { - if (this.repoTableModelEntries.size() == 1) { - // display error and exit - do not remove resource - showError("resource.error.isDefault"); - this.contextController.setValues(this.groupContext); - return; - } - } - //present dialog box if resource should be removed - String text = getTranslator().translate("resource.remove", new String[] { this.groupContext.getName(), this.currentRepoEntry.getDisplayname() }); - this.confirmRemoveResource = activateYesNoDialog(ureq, null, text, this.confirmRemoveResource); - - } - } - } else if (source == this.confirmRemoveResource) { - if (DialogBoxUIFactory.isYesEvent(event)) { // yes case - doRemoveResource(this.currentRepoEntry); - fireEvent(ureq, Event.CHANGED_EVENT); - MultiUserEvent mue = new BGContextEvent(BGContextEvent.RESOURCE_REMOVED, this.groupContext); - CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, this.groupContext); - } - } else if (source == this.contextController) { - if (event == Event.DONE_EVENT) { - doUpdateContext(ureq); - fireEvent(ureq, Event.CHANGED_EVENT); - } else if (event == Event.CANCELLED_EVENT) { - // init the details form again - - removeAsListenerAndDispose(contextController); - contextController = new BGContextFormController(ureq, getWindowControl(), this.groupContext.getGroupType(), ureq.getUserSession().getRoles().isOLATAdmin()); - listenTo(contextController); - - this.contextController.setValues(this.groupContext); - this.tabDetailsVC.put("contextForm", this.contextController.getInitialComponent()); - } - } - } - - /** - * persist the updates - */ - private void doUpdateContext(UserRequest ureq) { - // refresh group to prevent stale object exception and context proxy issues - this.groupContext = contextManager.loadBGContext(this.groupContext); - // update defaultContext switch changes - if (ureq.getUserSession().getRoles().isOLATAdmin()) { - boolean newisDefaultContext = this.contextController.isDefaultContext(); - if (newisDefaultContext) { - if (this.repoTableModelEntries.size() == 0) { - showError("form.error.defaultButNoResource"); - this.contextController.setValues(this.groupContext); - return; - } - } - this.groupContext.setDefaultContext(newisDefaultContext); - } - // update name and descripton - String name = this.contextController.getName(); - String desc = this.contextController.getDescription(); - this.groupContext.setName(name); - this.groupContext.setDescription(desc); - contextManager.updateBGContext(this.groupContext); - // update velocity - String title = DefaultContextTranslationHelper.translateIfDefaultContextName(this.groupContext, getTranslator()); - this.editVC.contextPut("title", getTranslator().translate("edit.title", new String[] { "<i>" + StringEscapeUtils.escapeHtml(title) + "</i>" })); - } - - private void doRemoveResource(RepositoryEntry entry) { - // remove on db - contextManager.removeBGContextFromResource(this.groupContext, entry.getOlatResource()); - // remove on table model - this.repoTableModelEntries.remove(entry); - this.resourcesCtr.modelChanged(); - } - - private void doAddRepositoryEntry(RepositoryEntry entry) { - // persist on db - contextManager.addBGContextToResource(this.groupContext, entry.getOlatResource()); - // update table model - this.repoTableModelEntries.add(entry); - this.resourcesCtr.modelChanged(); - } - - private VelocityContainer doCreateTabDetails(UserRequest ureq) { - this.tabDetailsVC = createVelocityContainer("tab_details"); - - - removeAsListenerAndDispose(this.contextController); - this.contextController = new BGContextFormController(ureq, getWindowControl(), this.groupContext.getGroupType(), ureq.getUserSession().getRoles().isOLATAdmin()); - listenTo(this.contextController); - - this.contextController.setValues(this.groupContext); - this.tabDetailsVC.put("contextForm", this.contextController.getInitialComponent()); - return this.tabDetailsVC; - } - - private VelocityContainer doCreateTabOwners(UserRequest ureq) { - this.tabOwnersVC = createVelocityContainer("tab_owners"); - - removeAsListenerAndDispose(this.ownerCtr); - this.ownerCtr = new GroupController(ureq, getWindowControl(), true, true, false, this.groupContext.getOwnerGroup()); - listenTo(this.ownerCtr); - - this.tabOwnersVC.put("owners", this.ownerCtr.getInitialComponent()); - return this.tabOwnersVC; - } - - private VelocityContainer doCreateTabResources(UserRequest ureq, boolean initOnlyModel) { - Translator resourceTrans = Util.createPackageTranslator(RepositoryTableModel.class, getLocale(), getTranslator()); - if (!initOnlyModel) { - TableGuiConfiguration tableConfig = new TableGuiConfiguration(); - tableConfig.setTableEmptyMessage(translate("resources.noresources")); - - removeAsListenerAndDispose(resourcesCtr); - resourcesCtr = new TableController(tableConfig, ureq, getWindowControl(), resourceTrans); - listenTo(resourcesCtr); - - this.tabResourcesVC = createVelocityContainer("tab_resources"); - this.addTabResourcesButton = LinkFactory.createButtonSmall("cmd.addresource", this.tabResourcesVC, this); - } - - this.repoTableModel = new RepositoryTableModel(resourceTrans); - this.repoTableModelEntries = contextManager.findRepositoryEntriesForBGContext(this.groupContext); - this.repoTableModel.setObjects(this.repoTableModelEntries); - if (!initOnlyModel) { - this.repoTableModel.addColumnDescriptors(this.resourcesCtr, translate("resources.remove"), false); - } - this.resourcesCtr.setTableDataModel(this.repoTableModel); - - this.tabResourcesVC.put("resources", this.resourcesCtr.getInitialComponent()); - return this.tabResourcesVC; - } - - /** - * @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event) - */ - public void event(Event event) { - if (event instanceof BGContextEvent) { - BGContextEvent contextEvent = (BGContextEvent) event; - if (contextEvent.getBgContextKey().equals(this.groupContext.getKey())) { - if (contextEvent.getCommand().equals(BGContextEvent.CONTEXT_DELETED)) { - // this context is deleted, dispose this edit controller - dispose(); - } else if (contextEvent.getCommand().equals(BGContextEvent.RESOURCE_ADDED) - || contextEvent.getCommand().equals(BGContextEvent.RESOURCE_REMOVED)) { - // update resource table model - this.tabResourcesVC = doCreateTabResources(null, true); - } - } - } - } - - /** - * @return true if lock on group has been acquired, flase otherwhise - */ - public boolean isLockAcquired() { - return this.lockEntry.isSuccess(); - } - - /** - * @see org.olat.core.gui.control.DefaultController#doDispose(boolean asynchronous) - */ - @Override - protected void doDispose() { - // deregister for changes in this group context - CoordinatorManager.getInstance().getCoordinator().getEventBus().deregisterFor(this, this.groupContext); - // release Lock - releaseGroupContextLock(); - } - - private void releaseGroupContextLock() { - if(this.lockEntry.isSuccess()){ - //release lock - CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLock(this.lockEntry); - }else if(this.alreadyLockedDialogController != null){ - //dispose lock dialog if still visible. - this.alreadyLockedDialogController.dispose(); - } - } - -} \ No newline at end of file diff --git a/src/main/java/org/olat/group/ui/context/BGContextEvent.java b/src/main/java/org/olat/group/ui/context/BGContextEvent.java deleted file mode 100644 index 3e5828f1c57..00000000000 --- a/src/main/java/org/olat/group/ui/context/BGContextEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <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 -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <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> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -*/ - -package org.olat.group.ui.context; - -import org.olat.core.util.event.MultiUserEvent; -import org.olat.group.context.BGContext; - -/** - * Description:<BR> - * Multi user event fired by the business manage and edit controllers - * <P> - * Initial Date: Jan 31, 2005 - * - * @author gnaegi - */ -public class BGContextEvent extends MultiUserEvent { - - /** the context is deleted * */ - public static final String CONTEXT_DELETED = "contextdeleted"; - /** a new resource has been added * */ - public static final String RESOURCE_ADDED = "resourceadded"; - /** a resource has been removed * */ - public static final String RESOURCE_REMOVED = "resourceremoved"; - - private Long bgContextKey; - - /** - * @param command User public final stings here - * @param bgContext - */ - public BGContextEvent(String command, BGContext bgContext) { - super(command); - this.bgContextKey = bgContext.getKey(); - } - - /** - * @return the key of the BGContext - */ - public Long getBgContextKey() { - return bgContextKey; - } -} diff --git a/src/main/java/org/olat/group/ui/context/BGContextFormController.java b/src/main/java/org/olat/group/ui/context/BGContextFormController.java deleted file mode 100644 index 1c0e0ed2bb9..00000000000 --- a/src/main/java/org/olat/group/ui/context/BGContextFormController.java +++ /dev/null @@ -1,217 +0,0 @@ -/** - * <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.context; - -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.elements.RichTextElement; -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.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.logging.AssertException; -import org.olat.core.util.StringHelper; -import org.olat.course.groupsandrights.ui.DefaultContextTranslationHelper; -import org.olat.group.context.BGContext; - -/** - * Provides a FlexiForm-based dialog for entering group administration info. - * - * @author twuersch - * - */ -public class BGContextFormController extends FormBasicController { - - /** Input element for the group name. */ - private TextElement name; - - /** Key for the group type. */ - private String typeKey; - - /** Checkbox "only visible within course". */ - private MultipleSelectionElement defaultContext; - - /** Keys for the checkbox. */ - private String[] defaultContextKeys = new String[] { "form.defaultContext" }; - - /** Values for the checkbox. */ - private String[] defaultContextValues = new String[] { "" }; - - /** Input element for the description of this group. */ - private RichTextElement description; - - /** Decides whether the "only visible within course" checkbox is shown. */ - private boolean showIsDefaultOption; - - /** - * Creates this controller. - * - * @param ureq The user request. - * @param wControl The window control. - * @param groupType This group's type. - * @param showIsDefaultOption Decides whether the "only visible within course" - * checkbox is shown. - */ - public BGContextFormController(UserRequest ureq, WindowControl wControl, String groupType, boolean showIsDefaultOption) { - super(ureq, wControl, FormBasicController.LAYOUT_DEFAULT); - this.showIsDefaultOption = showIsDefaultOption; - this.typeKey = groupType; - initForm(ureq); - } - - /** - * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#doDispose() - */ - @Override - protected void doDispose() { - // Nothing to dispose - - } - - /** - * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest) - */ - @Override - protected void formOK(UserRequest ureq) { - fireEvent(ureq, Event.DONE_EVENT); - } - - /** - * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formNOK(org.olat.core.gui.UserRequest) - */ - @Override - protected void formNOK(UserRequest ureq) { - fireEvent(ureq, Event.FAILED_EVENT); - } - - /** - * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formCancelled(org.olat.core.gui.UserRequest) - */ - @Override - protected void formCancelled(UserRequest ureq) { - fireEvent(ureq, Event.CANCELLED_EVENT); - } - - /** - * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, - * org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest) - */ - @Override - protected void initForm(FormItemContainer formLayout, @SuppressWarnings("unused") Controller listener, UserRequest ureq) { - // add the type of business group as a static text - uifactory.addStaticTextElement("form.type", typeKey, formLayout); - - // add visibility checkbox - if (showIsDefaultOption) { - defaultContext = uifactory.addCheckboxesHorizontal("form.defaultContext", formLayout, defaultContextKeys, - defaultContextValues, null); - } - - // add business group name input element - name = uifactory.addTextElement("form.name", "form.name", 255, "", formLayout); - name.setMandatory(true); - - // add business group description input element - description = uifactory.addRichTextElementForStringDataMinimalistic("form.description", "form.description", "", 10, -1, false, - formLayout, ureq.getUserSession(), getWindowControl()); - - // Create submit and cancel buttons - final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator()); - formLayout.add(buttonLayout); - uifactory.addFormSubmitButton("finish", buttonLayout); - uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl()); - - } - - /** - * Set the name and description of the context in this form - * - * @param context - */ - public void setValues(BGContext context) { - String contextName = DefaultContextTranslationHelper.translateIfDefaultContextName(context, getTranslator()); - if (defaultContext != null) { - defaultContext.select("form.defaultContext", context.isDefaultContext()); - } - name.setValue(contextName); - description.setValue(context.getDescription()); - } - - /** - * @return boolean true if this is now a default context - */ - public boolean isDefaultContext() { - if (defaultContext == null) { - throw new AssertException("default context switch only editable when form is started with isAdmin=true"); - } else { - return (defaultContext.getSelectedKeys().size() != 0); - } - } - - /** - * @return the context description as string - */ - public String getDescription() { - return description.getValue(); - } - - /** - * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#validateFormLogic(org.olat.core.gui.UserRequest) - */ - @Override - protected boolean validateFormLogic(@SuppressWarnings("unused") UserRequest ureq) { - if (!StringHelper.containsNonWhitespace(name.getValue())) { - // name is mandatory - name.setErrorKey("form.error.emptyName", new String[] {}); - return false; - } else if (!name.getValue().matches(BGContext.VALID_GROUPCONTEXTNAME_REGEXP)) { - // name must match a given format - name.setErrorKey("form.error.illegalName", new String[] {}); - return false; - } - // stip whitespace - name.clearError(); - if (description.getValue().length() > 4000) { - // description has maximum length - description.setErrorKey("input.toolong", new String[] {}); - return false; - } - // ok, passed all checks - return true; - } - - /** - * @return String context name - */ - public String getName() { - return name.getValue().trim(); - } - - /** - * @return String the group context type - */ - public String getType() { - return typeKey; - } -} diff --git a/src/main/java/org/olat/group/ui/context/BGContextManagementController.java b/src/main/java/org/olat/group/ui/context/BGContextManagementController.java deleted file mode 100644 index 867f3a5302c..00000000000 --- a/src/main/java/org/olat/group/ui/context/BGContextManagementController.java +++ /dev/null @@ -1,456 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <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 -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <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> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -*/ - -package org.olat.group.ui.context; - -import java.util.List; - -import org.olat.core.commons.fullWebApp.LayoutMain3ColsController; -import org.olat.core.gui.UserRequest; -import org.olat.core.gui.components.Component; -import org.olat.core.gui.components.panel.Panel; -import org.olat.core.gui.components.table.DefaultColumnDescriptor; -import org.olat.core.gui.components.table.StaticColumnDescriptor; -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.TableGuiConfiguration; -import org.olat.core.gui.components.tree.GenericTreeModel; -import org.olat.core.gui.components.tree.GenericTreeNode; -import org.olat.core.gui.components.tree.MenuTree; -import org.olat.core.gui.components.tree.TreeModel; -import org.olat.core.gui.components.tree.TreeNode; -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.MainLayoutBasicController; -import org.olat.core.gui.control.generic.dtabs.Activateable; -import org.olat.core.gui.control.generic.dtabs.Activateable2; -import org.olat.core.gui.control.generic.modal.DialogBoxController; -import org.olat.core.gui.control.generic.modal.DialogBoxUIFactory; -import org.olat.core.gui.control.generic.tool.ToolController; -import org.olat.core.gui.control.generic.tool.ToolFactory; -import org.olat.core.id.OLATResourceable; -import org.olat.core.id.context.ContextEntry; -import org.olat.core.id.context.StateEntry; -import org.olat.core.logging.AssertException; -import org.olat.core.util.coordinate.CoordinatorManager; -import org.olat.core.util.event.MultiUserEvent; -import org.olat.core.util.resource.OresHelper; -import org.olat.group.BusinessGroup; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManagerImpl; -import org.olat.group.ui.BGControllerFactory; -import org.olat.group.ui.management.BGManagementController; - -/** - * Description:<BR> - * Management controller for the group context. A group context is a container - * for groups and learning areas. Group contexts are associated with - * OLATResources, currently only with courses. Default contexts belong only to - * one resource, regular contexts can be associated with many courses, they then - * share the same groupmanagement. With this controller this group contexts can - * be created and managed. - * <P> - * - * Initial Date: Jan 24, 2005 - * @author gnaegi - */ -public class BGContextManagementController extends MainLayoutBasicController implements Activateable, Activateable2 { - - // Menu commands - private static final String CMD_INDEX = "cmd.index"; - private static final String CMD_CONTEXTLIST = "cmd.contextlist"; - // Toolbox commands - private static final String CMD_LG_CONTEXT_CREATE = "cmd.learninggroup.context.create"; - private static final String CMD_RG_CONTEXT_CREATE = "cmd.rightgroup.context.create"; - // List commands - private static final String CMD_CONTEXT_RUN = "cmd.context.run"; - private static final String CMD_CONTEXT_EDIT = "cmd.context.edit"; - private static final String CMD_CONTEXT_DELETE = "cmd.context.delete"; - - private VelocityContainer indexVC, newContextVC, contextListVC; - private TableController contextListCtr; - private BGContextTableModel contextTableModel; - private DialogBoxController confirmDeleteContext; - - // Layout components and controllers - - private Panel content; - private LayoutMain3ColsController columnLayoutCtr; - private MenuTree olatMenuTree; - private ToolController toolC; - - // Managers - private BGContextManagerImpl contextManager; - - // components - private BGContextFormController newContextController; - - // Workflow variables - private BGManagementController groupManagementController; - private BGContextEditController contextEditCtr; - private BGContext currentGroupContext; - - /** - * Constructor for a business group management controller. - * - * @param ureq The user request - * @param wControl The window control - */ - public BGContextManagementController(UserRequest ureq, WindowControl wControl) { - super(ureq, wControl); - - // Initialize managers - this.contextManager = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - // Initialize all velocity containers - initVC(); - - // Layout is controlled with generic controller: menu - content - tools - // Navigation menu - this.olatMenuTree = new MenuTree("olatMenuTree"); - TreeModel tm = buildTreeModel(); - this.olatMenuTree.setTreeModel(tm); - this.olatMenuTree.setSelectedNodeId(tm.getRootNode().getIdent()); - this.olatMenuTree.addListener(this); - // Content - this.content = new Panel("content"); - // Tools - // 1 create empty Tools and init menuAndToolController - // 2 set correct tools using setTools method (override step 1) - this.toolC = ToolFactory.createToolController(getWindowControl()); - this.columnLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), this.olatMenuTree, this.toolC.getInitialComponent(), this.content, "groupcontextmngt"); - columnLayoutCtr.addCssClassToMain("o_groupsmanagement"); - - listenTo(this.columnLayoutCtr); - - doIndex(ureq); - - putInitialPanel(this.columnLayoutCtr.getInitialComponent()); - } - - /** - * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, - * org.olat.core.gui.components.Component, org.olat.core.gui.control.Event) - */ - @Override - public void event(UserRequest ureq, Component source, Event event) { - String cmd = event.getCommand(); - if (source == this.olatMenuTree) { - if (cmd.equals(MenuTree.COMMAND_TREENODE_CLICKED)) { - handleMenuCommands(ureq); - } - } - } - - /** - * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, - * org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event) - */ - @Override - public void event(UserRequest ureq, Controller source, Event event) { - String cmd = event.getCommand(); - if (source == this.toolC) { - handleToolCommands(ureq, cmd); - } else if (source == groupManagementController) { - if (event == Event.DONE_EVENT) { - getWindowControl().pop(); - //fxdiff BAKS-7 Resume function - if(contextListCtr != null) {//de facto -> contextlist - addToHistory(ureq, contextListCtr); - } - } - } else if (source == this.confirmDeleteContext) { - if (DialogBoxUIFactory.isYesEvent(event)) { - // yes case - doContextDelete(); - this.content.popContent(); - doContextList(ureq, true); - MultiUserEvent mue = new BGContextEvent(BGContextEvent.CONTEXT_DELETED, this.currentGroupContext); - CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, this.currentGroupContext); - } - } else if (source == this.contextListCtr) { - if (cmd.equals(Table.COMMANDLINK_ROWACTION_CLICKED)) { - TableEvent te = (TableEvent) event; - String actionid = te.getActionId(); - int rowid = te.getRowId(); - this.currentGroupContext = this.contextTableModel.getGroupContextAt(rowid); - if (actionid.equals(CMD_CONTEXT_EDIT)) { - doContextEdit(ureq); - } else if (actionid.equals(CMD_CONTEXT_RUN)) { - doContextRun(ureq); - } else if (actionid.equals(CMD_CONTEXT_DELETE)) { - doContextDeleteConfirm(ureq); - } - } - } else if (source == this.newContextController) { - if (event == Event.DONE_EVENT) { - BGContext newContext = doContextCreate(ureq); - if (newContext == null) { - throw new AssertException("Could not create new BGContext - unknown reason"); - } else { - this.currentGroupContext = newContext; - doContextEdit(ureq); - } - } else if (event == Event.CANCELLED_EVENT) { - doIndex(ureq); - } - } - } - - private void handleToolCommands(UserRequest ureq, String cmd) { - if (cmd.equals(CMD_LG_CONTEXT_CREATE)) { - doContextCreateForm(ureq, BusinessGroup.TYPE_LEARNINGROUP); - } else if (cmd.equals(CMD_RG_CONTEXT_CREATE)) { - doContextCreateForm(ureq, BusinessGroup.TYPE_RIGHTGROUP); - } else if (cmd.equals(CMD_CONTEXT_RUN)) { - doContextRun(ureq); - } else if (cmd.equals(CMD_CONTEXT_DELETE)) { - doContextDeleteConfirm(ureq); - } - - } - - private void handleMenuCommands(UserRequest ureq) { - - // remove lock from current context - removeAsListenerAndDispose(contextEditCtr); - - TreeNode selTreeNode = this.olatMenuTree.getSelectedNode(); - String cmd = (String) selTreeNode.getUserObject(); - - if (cmd.equals(CMD_INDEX)) { - doIndex(ureq); - } else if (cmd.equals(CMD_CONTEXTLIST)) { - doContextList(ureq, true); - } - } - - private TreeModel buildTreeModel() { - GenericTreeNode root, gtn; - - GenericTreeModel gtm = new GenericTreeModel(); - root = new GenericTreeNode(); - root.setTitle(translate("menu.index")); - root.setUserObject(CMD_INDEX); - root.setAltText(translate("menu.index.alt")); - gtm.setRootNode(root); - - gtn = new GenericTreeNode(); - gtn.setTitle(translate("menu.allcontexts")); - gtn.setUserObject(CMD_CONTEXTLIST); - gtn.setAltText(translate("menu.allcontexts.alt")); - root.addChild(gtn); - - return gtm; - } - - private void setTools(boolean contextSelected) { - removeAsListenerAndDispose(toolC); - toolC = ToolFactory.createToolController(getWindowControl()); - listenTo(toolC); - - this.columnLayoutCtr.setCol2(this.toolC.getInitialComponent()); - this.toolC.addHeader(translate("tools.title.contextmanagement")); - // Generic actions - this.toolC.addLink(CMD_LG_CONTEXT_CREATE, translate(CMD_LG_CONTEXT_CREATE)); - this.toolC.addLink(CMD_RG_CONTEXT_CREATE, translate(CMD_RG_CONTEXT_CREATE)); - // context specific actions - if (contextSelected) { - this.toolC.addHeader(translate("tools.title.context")); - this.toolC.addLink(CMD_CONTEXT_RUN, translate(CMD_CONTEXT_RUN)); - this.toolC.addLink(CMD_CONTEXT_DELETE, translate(CMD_CONTEXT_DELETE)); - } - } - - private void initVC() { - this.indexVC = createVelocityContainer("contextmanagement"); - // Create new context form - this.newContextVC = createVelocityContainer("newcontext"); - // Context list - this.contextListVC = createVelocityContainer("contextlist"); - } - - @Override - //fxdiff BAKS-7 Resume function - public void activate(UserRequest ureq, String viewIdentifier) { - if(viewIdentifier != null && viewIdentifier.endsWith(":0")) { - viewIdentifier = viewIdentifier.substring(0, viewIdentifier.length() - 2); - } - - if(CMD_CONTEXTLIST.equals(viewIdentifier)) { - TreeNode node = ((GenericTreeModel)olatMenuTree.getTreeModel()).findNodeByUserObject(CMD_CONTEXTLIST); - olatMenuTree.setSelectedNode(node); - doContextList(ureq, true); - } - } - - @Override - //fxdiff BAKS-7 Resume function - public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) { - if(entries == null || entries.isEmpty()) return; - - ContextEntry ce = entries.remove(0); - String type = ce.getOLATResourceable().getResourceableTypeName(); - TreeNode node = ((GenericTreeModel)olatMenuTree.getTreeModel()).findNodeByUserObject(type); - if(node != null) { - olatMenuTree.setSelectedNode(node); - - handleMenuCommands(ureq); - if(CMD_CONTEXTLIST.equals(ce.getOLATResourceable().getResourceableTypeName())) { - //try to select a context if there is one - if(!entries.isEmpty()) { - ContextEntry groupCe = entries.remove(0); - List<BGContext> contexts = contextTableModel.getObjects(); - for(BGContext context:contexts) { - if(context.getKey().equals(groupCe.getOLATResourceable().getResourceableId())) { - currentGroupContext = context; - break; - } - } - - if(currentGroupContext != null) { - doContextRun(ureq); - } - } - } - } - } - - private void doIndex(UserRequest ureq) { - this.content.setContent(this.indexVC); - setTools(false); - //fxdiff BAKS-7 Resume function - OLATResourceable ores = OresHelper.createOLATResourceableInstance(CMD_INDEX, 0l); - addToHistory(ureq, ores, null); - } - - private void doContextCreateForm(UserRequest ureq, String type) { - - removeAsListenerAndDispose(this.newContextController); - this.newContextController = new BGContextFormController(ureq, getWindowControl(), type, ureq.getUserSession().getRoles().isOLATAdmin()); - listenTo(this.newContextController); - - this.newContextVC.put("newContextForm", this.newContextController.getInitialComponent()); - this.content.setContent(this.newContextVC); - } - - private BGContext doContextCreate(UserRequest ureq) { - String name = this.newContextController.getName(); - String desc = this.newContextController.getDescription(); - String type = this.newContextController.getType(); - return this.contextManager.createAndPersistBGContext(name, desc, type, ureq.getIdentity(), false); - } - - private void doContextEdit(UserRequest ureq) { - - // create new edit controller - removeAsListenerAndDispose(contextEditCtr); - contextEditCtr = new BGContextEditController(ureq, getWindowControl(), this.currentGroupContext); - listenTo(contextEditCtr); - - if (this.contextEditCtr.isLockAcquired()) { - this.content.setContent(this.contextEditCtr.getInitialComponent()); - setTools(true); - } - } - - private void doContextRun(UserRequest ureq) { - removeAsListenerAndDispose(groupManagementController); - //fxdiff BAKS-7 Resume function - OLATResourceable ores = OresHelper.createOLATResourceableInstance(BGContext.class, currentGroupContext.getKey()); - WindowControl bwControl = addToHistory(ureq, ores, null, contextListCtr.getWindowControlForDebug(), true); - groupManagementController = BGControllerFactory.getInstance().createManagementController(ureq, bwControl, this.currentGroupContext, false); - listenTo (groupManagementController); - - //FIXME fg: no layout ctr in a modal panel! - getWindowControl().pushToMainArea(this.groupManagementController.getInitialComponent()); - } - - private void doContextDeleteConfirm(UserRequest ureq) { - List resource = this.contextManager.findOLATResourcesForBGContext(this.currentGroupContext); - if (resource.size() == 0) { - this.confirmDeleteContext = activateYesNoDialog(ureq, null, translate( - "context.delete.used.zero", this.currentGroupContext.getName() ), this.confirmDeleteContext); - } else if (resource.size() == 1) { - this.confirmDeleteContext = activateYesNoDialog(ureq, null, translate( - "context.delete.used.one", this.currentGroupContext.getName() ), this.confirmDeleteContext); - } else { - this.confirmDeleteContext = activateYesNoDialog(ureq, null, getTranslator().translate( - "context.delete.used.multi", new String[] { this.currentGroupContext.getName(), Integer.toString(resource.size()) }), this.confirmDeleteContext); - } - } - - private void doContextDelete() { - this.contextManager.deleteBGContext(this.currentGroupContext); - } - - private void doContextList(UserRequest ureq, boolean initializeModel) { - // Init table only once - if (this.contextListCtr == null) { - TableGuiConfiguration tableConfig = new TableGuiConfiguration(); - tableConfig.setTableEmptyMessage(translate("contextlist.no.contexts")); - // init group list filter controller - removeAsListenerAndDispose(contextListCtr); - //fxdiff BAKS-7 Resume function - OLATResourceable ores = OresHelper.createOLATResourceableInstance(CMD_CONTEXTLIST, 0l); - WindowControl bwControl = addToHistory(ureq, ores, null, getWindowControl(), false); - contextListCtr = new TableController(tableConfig, ureq, bwControl, getTranslator()); - listenTo(contextListCtr); - - this.contextListCtr.addColumnDescriptor(new DefaultColumnDescriptor("contextlist.table.name", 0, CMD_CONTEXT_RUN, ureq.getLocale())); - this.contextListCtr.addColumnDescriptor(new DefaultColumnDescriptor("contextlist.table.desc", 1, null, ureq.getLocale())); - this.contextListCtr.addColumnDescriptor(new DefaultColumnDescriptor("contextlist.table.type", 2, null, ureq.getLocale())); - this.contextListCtr.addColumnDescriptor(new StaticColumnDescriptor(CMD_CONTEXT_EDIT, "contextlist.table.edit", - translate(CMD_CONTEXT_EDIT))); - this.contextListCtr.addColumnDescriptor(new StaticColumnDescriptor(CMD_CONTEXT_DELETE, "contextlist.table.delete", - translate(CMD_CONTEXT_DELETE))); - this.contextListVC.put("contextlist", this.contextListCtr.getInitialComponent()); - } - - if (this.contextTableModel == null || initializeModel) { - List contexts = this.contextManager.findBGContextsForIdentity(ureq.getIdentity(), false, true); - this.contextTableModel = new BGContextTableModel(contexts, getTranslator(), true, false); - this.contextListCtr.setTableDataModel(this.contextTableModel); - } - //fxdiff BAKS-7 Resume function - addToHistory(ureq, contextListCtr); - this.content.setContent(this.contextListVC); - setTools(false); - } - - /** - * @see org.olat.core.gui.control.DefaultController#doDispose(boolean) - */ - @Override - protected void doDispose() { - // Controllers disposed by BasicController: - } - - private void cleanupContextLock() { - - } -} \ No newline at end of file diff --git a/src/main/java/org/olat/group/ui/context/BGContextTableModel.java b/src/main/java/org/olat/group/ui/context/BGContextTableModel.java deleted file mode 100644 index ce8ad257021..00000000000 --- a/src/main/java/org/olat/group/ui/context/BGContextTableModel.java +++ /dev/null @@ -1,111 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <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 -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <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> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -*/ - -package org.olat.group.ui.context; - -import java.util.List; - -import org.apache.commons.lang.StringEscapeUtils; -import org.olat.core.gui.components.table.DefaultTableDataModel; -import org.olat.core.gui.components.table.TableDataModel; -import org.olat.core.gui.translator.Translator; -import org.olat.core.util.Formatter; -import org.olat.core.util.filter.FilterFactory; -import org.olat.course.groupsandrights.ui.DefaultContextTranslationHelper; -import org.olat.group.context.BGContext; - -/** - * Description:<BR> - * The business group table model contains a list of business groups and can - * display the business groups - * <P> - * Initial Date: Jan 24, 2005 - * - * @author gnaegi - */ -public class BGContextTableModel extends DefaultTableDataModel implements TableDataModel { - private Translator trans; - private boolean showType; - private boolean showDefault; - - /** - * Constructor for the business group table model - * - * @param groupContexts The list of group contexts - * @param trans - * @param showType true: show type row - * @param showDefault true: show isDefaultContext flag - */ - public BGContextTableModel(List groupContexts, Translator trans, boolean showType, boolean showDefault) { - super(groupContexts); - this.trans = trans; - this.showType = showType; - this.showDefault = showDefault; - } - - /** - * @see org.olat.core.gui.components.table.TableDataModel#getColumnCount() - */ - public int getColumnCount() { - int column = 2; - if (showType) column++; - if (showDefault) column++; - return column; - } - - /** - * @see org.olat.core.gui.components.table.TableDataModel#getValueAt(int, int) - */ - public Object getValueAt(int row, int col) { - BGContext context = (BGContext) objects.get(row); - switch (col) { - case 0: - String name = DefaultContextTranslationHelper.translateIfDefaultContextName(context, trans); - name = StringEscapeUtils.escapeHtml(name).toString(); - return name; - case 1: - String description = context.getDescription(); - description = FilterFactory.getHtmlTagsFilter().filter(description); - description = Formatter.truncate(description, 256); - return description; - case 2: - if (showType) return trans.translate(context.getGroupType()); - else return new Boolean(context.isDefaultContext()); - case 3: - return new Boolean(context.isDefaultContext()); - default: - return "ERROR"; - } - } - - /** - * @param row - * @return BGContext from given row - */ - public BGContext getGroupContextAt(int row) { - return (BGContext) objects.get(row); - } - -} \ No newline at end of file diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java index 980aa5eb029..953128c86ad 100644 --- a/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java +++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java @@ -80,16 +80,13 @@ import org.olat.core.util.resource.OLATResourceableJustBeforeDeletedEvent; import org.olat.course.groupsandrights.CourseRights; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupAddResponse; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.GroupLoggingAction; import org.olat.group.area.BGArea; import org.olat.group.area.BGAreaManager; -import org.olat.group.delete.service.GroupDeletionManager; +import org.olat.group.manager.BusinessGroupDeletionManager; import org.olat.group.properties.BusinessGroupPropertyManager; import org.olat.group.right.BGRightManager; -import org.olat.group.right.BGRightManagerImpl; import org.olat.group.right.BGRights; import org.olat.group.ui.BGConfigFlags; import org.olat.group.ui.BGMailHelper; @@ -116,8 +113,7 @@ public class BusinessGroupEditController extends BasicController implements Cont private static final String PACKAGE = Util.getPackageName(BusinessGroupEditController.class); private final BGRightManager rightManager; private final BGAreaManager areaManager; - private final BusinessGroupManager bgm; - private final BusinessGroupService bgs; + private final BusinessGroupService businessGroupService; private BusinessGroupFormController modifyBusinessGroupController; private BusinessGroup currBusinessGroup; @@ -170,10 +166,9 @@ public class BusinessGroupEditController extends BasicController implements Cont addLoggingResourceable(LoggingResourceable.wrap(businessGroup)); // Initialize managers - this.areaManager = CoreSpringFactory.getImpl(BGAreaManager.class); - this.rightManager = CoreSpringFactory.getImpl(BGRightManager.class); - this.bgm = BusinessGroupManagerImpl.getInstance(); - this.bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + areaManager = CoreSpringFactory.getImpl(BGAreaManager.class); + rightManager = CoreSpringFactory.getImpl(BGRightManager.class); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); // Initialize other members // group @@ -195,7 +190,7 @@ public class BusinessGroupEditController extends BasicController implements Cont if (lockEntry.isSuccess()) { // reload group to minimize stale object exception and update last usage // timestamp - currBusinessGroup = bgs.setLastUsageFor(businessGroup); + currBusinessGroup = businessGroupService.setLastUsageFor(businessGroup); if(currBusinessGroup == null) { VelocityContainer vc = createVelocityContainer("deleted"); vc.contextPut("name", businessGroup.getName()); @@ -335,11 +330,11 @@ public class BusinessGroupEditController extends BasicController implements Cont BusinessGroupAddResponse response = null; addLoggingResourceable(LoggingResourceable.wrap(currBusinessGroup)); if (source == ownerGrpCntrllr) { - response = bgm.addOwnersAndFireEvent(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), currBusinessGroup, flags); + response = businessGroupService.addOwners(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), currBusinessGroup, flags); } else if (source == partipGrpCntrllr) { - response = bgm.addParticipantsAndFireEvent(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), currBusinessGroup, flags); + response = businessGroupService.addParticipants(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), currBusinessGroup, flags); } else if (source == waitingGruppeController) { - response = bgm.addToWaitingListAndFireEvent(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), currBusinessGroup, flags); + response = businessGroupService.addToWaitingList(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), currBusinessGroup, flags); } identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities()); identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission()); @@ -348,22 +343,22 @@ public class BusinessGroupEditController extends BasicController implements Cont } else if (event instanceof IdentitiesRemoveEvent) { List<Identity> identities = ((IdentitiesRemoveEvent) event).getRemovedIdentities(); if (source == ownerGrpCntrllr) { - bgm.removeOwnersAndFireEvent(ureq.getIdentity(), identities, currBusinessGroup, flags); + businessGroupService.removeOwners(ureq.getIdentity(), identities, currBusinessGroup, flags); } else if (source == partipGrpCntrllr) { - bgm.removeParticipantsAndFireEvent(ureq.getIdentity(), identities, currBusinessGroup, flags); + businessGroupService.removeParticipants(ureq.getIdentity(), identities, currBusinessGroup, flags); if (currBusinessGroup.getWaitingListEnabled().booleanValue()) { // It is possible that a user is transfered from waiting-list to participants => reload data to see transfered user in right group. partipGrpCntrllr.reloadData(); waitingGruppeController.reloadData(); } } else if (source == waitingGruppeController) { - bgm.removeFromWaitingListAndFireEvent(ureq.getIdentity(), identities, currBusinessGroup, flags); + businessGroupService.removeFromWaitingList(ureq.getIdentity(), identities, currBusinessGroup, flags); } fireEvent(ureq, Event.CHANGED_EVENT ); } else if (source == waitingGruppeController) { if (event instanceof IdentitiesMoveEvent) { IdentitiesMoveEvent identitiesMoveEvent = (IdentitiesMoveEvent) event; - BusinessGroupAddResponse response = bgm.moveIdenityFromWaitingListToParticipant(identitiesMoveEvent.getChosenIdentities(), ureq.getIdentity(), currBusinessGroup, flags); + BusinessGroupAddResponse response = businessGroupService.moveIdentityFromWaitingListToParticipant(identitiesMoveEvent.getChosenIdentities(), ureq.getIdentity(), currBusinessGroup, flags); identitiesMoveEvent.setNotMovedIdentities(response.getIdentitiesAlreadyInGroup()); identitiesMoveEvent.setMovedIdentities(response.getAddedIdentities()); // Participant and waiting-list were changed => reload both @@ -450,7 +445,7 @@ public class BusinessGroupEditController extends BasicController implements Cont } bg.setAutoCloseRanksEnabled(autoCloseRanksEnabled); bg.setLastUsage(new Date(System.currentTimeMillis())); - LifeCycleManager.createInstanceFor(bg).deleteTimestampFor(GroupDeletionManager.SEND_DELETE_EMAIL_ACTION); + LifeCycleManager.createInstanceFor(bg).deleteTimestampFor(BusinessGroupDeletionManager.SEND_DELETE_EMAIL_ACTION); // switch on/off waiting-list in member tab vc_tab_grpmanagement.contextPut("hasWaitingGrp", waitingListEnabled); 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 7eb7de151ce..64f1b58c8e2 100644 --- a/src/main/java/org/olat/group/ui/main/BGMainController.java +++ b/src/main/java/org/olat/group/ui/main/BGMainController.java @@ -43,7 +43,6 @@ import org.olat.commons.calendar.CalendarManagerFactory; import org.olat.commons.calendar.ui.components.KalendarRenderWrapper; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.fullWebApp.LayoutMain3ColsController; -import org.olat.core.commons.persistence.PersistenceHelper; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.link.Link; @@ -84,23 +83,17 @@ import org.olat.core.id.context.BusinessControl; import org.olat.core.id.context.BusinessControlFactory; import org.olat.core.id.context.ContextEntry; import org.olat.core.id.context.StateEntry; -import org.olat.core.logging.Tracing; import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; import org.olat.core.util.StringHelper; import org.olat.core.util.Util; -import org.olat.core.util.mail.ContactList; import org.olat.core.util.notifications.NotificationsManager; import org.olat.core.util.notifications.Publisher; import org.olat.core.util.notifications.SubscriptionContext; import org.olat.core.util.resource.OresHelper; import org.olat.core.util.tree.TreeHelper; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.GroupLoggingAction; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; import org.olat.group.delete.TabbedPaneController; import org.olat.group.model.SearchBusinessGroupParams; import org.olat.group.ui.BGConfigFlags; @@ -162,11 +155,10 @@ public class BGMainController extends MainLayoutBasicController implements Activ private BusinessGroupFormController createBuddyGroupController; private BusinessGroup currBusinessGroup; private final Identity identity; - private final BusinessGroupManager bgm; private final BusinessGroupService businessGroupService; + private final BaseSecurity securityManager; //fxdiff VCRP-1,2: access control of resources private final ACFrontendManager acFrontendManager; - private final BGContextManager contextManager; private TabbedPaneController deleteTabPaneCtr; private CloseableModalController cmc; private DialogBoxController deleteDialogBox; @@ -203,11 +195,10 @@ public class BGMainController extends MainLayoutBasicController implements Activ super(ureq, wControl); businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); + securityManager = CoreSpringFactory.getImpl(BaseSecurity.class); identity = ureq.getIdentity(); setTranslator(BGTranslatorFactory.createBGPackageTranslator(PACKAGE, BusinessGroup.TYPE_BUDDYGROUP, ureq.getLocale())); - bgm = BusinessGroupManagerImpl.getInstance(); - contextManager = BGContextManagerImpl.getInstance(); //fxdiff VCRP-1,2: access control of resources acFrontendManager = (ACFrontendManager)CoreSpringFactory.getBean("acFrontendManager"); @@ -475,24 +466,16 @@ public class BGMainController extends MainLayoutBasicController implements Activ */ private void doBuddyGroupDelete(UserRequest ureq, boolean doSendMail) { // 1) send notification mails to users - BaseSecurity securityManager = BaseSecurityManager.getInstance(); - ContactList owners = new ContactList(translate("userlist.owners.title")); - List<Identity> ow = securityManager.getIdentitiesOfSecurityGroup(currBusinessGroup.getOwnerGroup()); - owners.addAllIdentites(ow); - ContactList participants = new ContactList(translate("userlist.participants.title")); - participants.addAllIdentites(securityManager.getIdentitiesOfSecurityGroup(currBusinessGroup.getPartipiciantGroup())); + boolean ow = securityManager.isIdentityInSecurityGroup(getIdentity(), currBusinessGroup.getOwnerGroup()); // check if user is in owner group (could fake link in table) - if (!PersistenceHelper.listContainsObjectByKey(ow, ureq.getIdentity())) { - Tracing.logWarn("User tried to delete a group but he was not owner of the group", null, BGMainController.class); + if (ow) { + logWarn("User tried to delete a group but he was not owner of the group", null); return; } - List<ContactList> everybody = new ArrayList<ContactList>(); - everybody.add(owners); - everybody.add(participants); // inform Indexer about change // 3) delete the group - currBusinessGroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(currBusinessGroup); + currBusinessGroup = businessGroupService.loadBusinessGroup(currBusinessGroup); //change state of publisher so that notifications of deleted group calendars make no problems CalendarManager calMan = CalendarManagerFactory.getInstance().getCalendarManager(); @@ -507,9 +490,10 @@ public class BGMainController extends MainLayoutBasicController implements Activ // fxdiff: FXOLAT-138 if (doSendMail) { - bgm.deleteBusinessGroupWithMail(currBusinessGroup, getWindowControl(), ureq, getTranslator(), everybody); + String businessPath = getWindowControl().getBusinessControl().getAsString(); + businessGroupService.deleteBusinessGroupWithMail(currBusinessGroup, businessPath, getIdentity(), getLocale()); } else { - bgm.deleteBusinessGroup(currBusinessGroup); + businessGroupService.deleteBusinessGroup(currBusinessGroup); } // do Logging ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_DELETED, getClass(), LoggingResourceable.wrap(currBusinessGroup)); @@ -531,9 +515,9 @@ public class BGMainController extends MainLayoutBasicController implements Activ // 1) remove as owner SecurityGroup owners = currBusinessGroup.getOwnerGroup(); if (securityManager.isIdentityInSecurityGroup(identity, owners)) { - List ownerList = securityManager.getIdentitiesOfSecurityGroup(owners); + List<Identity> ownerList = securityManager.getIdentitiesOfSecurityGroup(owners); if (ownerList.size() > 1) { - bgm.removeOwnerAndFireEvent(ureq.getIdentity(), ureq.getIdentity(), currBusinessGroup, flags, false); + businessGroupService.removeOwners(ureq.getIdentity(), Collections.singletonList(ureq.getIdentity()), currBusinessGroup, flags); // update model updateGroupListModelAll(); } else { @@ -549,7 +533,7 @@ public class BGMainController extends MainLayoutBasicController implements Activ // 2) remove as participant List<Identity> identities = new ArrayList<Identity>(1); identities.add(ureq.getIdentity()); - bgm.removeParticipantsAndFireEvent(ureq.getIdentity(), identities, currBusinessGroup, flags); + businessGroupService.removeParticipants(ureq.getIdentity(), identities, currBusinessGroup, flags); // update Tables doAllGroupList(ureq, getWindowControl()); @@ -571,14 +555,14 @@ public class BGMainController extends MainLayoutBasicController implements Activ * description and also the CollaborationTools are enabled during creation. * The GroupContext is null in the case of BuddyGroups. */ - BusinessGroup newGroup = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_BUDDYGROUP, identity, bgName, bgDesc, bgMin, bgMax, null, null, null); + BusinessGroup newGroup = businessGroupService.createBusinessGroup(identity, bgName, bgDesc, BusinessGroup.TYPE_BUDDYGROUP, bgMin, bgMax, false, false, null); // create buddylist for group // 2. Add user to group, fire events, do loggin etc. BGConfigFlags flags = BGConfigFlags.createBuddyGroupDefaultFlags(); // do Logging ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(newGroup)); ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_CREATED, getClass()); - bgm.addOwnerAndFireEvent(ureq.getIdentity(), ureq.getIdentity(), newGroup, flags, true); + businessGroupService.addOwner(ureq.getIdentity(), ureq.getIdentity(), newGroup, flags); return newGroup; } 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 91ddc58dc45..2edeb7afc34 100644 --- a/src/main/java/org/olat/group/ui/management/BGManagementController.java +++ b/src/main/java/org/olat/group/ui/management/BGManagementController.java @@ -26,6 +26,7 @@ package org.olat.group.ui.management; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -82,15 +83,10 @@ import org.olat.core.util.i18n.I18nManager; import org.olat.core.util.mail.ContactList; import org.olat.core.util.mail.ContactMessage; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.GroupLoggingAction; import org.olat.group.area.BGArea; import org.olat.group.area.BGAreaManager; -import org.olat.group.area.BGAreaManagerImpl; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; import org.olat.group.ui.BGConfigFlags; import org.olat.group.ui.BGControllerFactory; import org.olat.group.ui.BGTranslatorFactory; @@ -99,8 +95,6 @@ import org.olat.group.ui.NewAreaController; import org.olat.group.ui.NewBGController; import org.olat.group.ui.area.BGAreaEditController; import org.olat.group.ui.area.BGAreaTableModel; -import org.olat.group.ui.context.BGContextEditController; -import org.olat.group.ui.context.BGContextEvent; import org.olat.group.ui.edit.BusinessGroupEditController; import org.olat.group.ui.edit.BusinessGroupModifiedEvent; import org.olat.group.ui.run.BusinessGroupMainRunController; @@ -118,7 +112,6 @@ import org.olat.user.HomePageDisplayController; import org.olat.user.UserManager; import org.olat.util.logging.activity.LoggingResourceable; -import edu.emory.mathcs.backport.java.util.Collections; /** * Description:<BR/> This controller provides a complete groupmanagement for a @@ -163,12 +156,10 @@ public class BGManagementController extends MainLayoutBasicController implements private static final String CMD_LIST_MEMBERS_WITH_AREAS = "cmd.list.members.with.areas"; private Translator userTrans; - private OLATResource resource; - private String groupType; + private final OLATResource resource; + private final String groupType = BusinessGroup.TYPE_LEARNINGROUP; private BGConfigFlags flags; - private boolean isContextOwner; private static final int STATE_OVERVIEW = 1; - private static final int STATE_CONTEXT_EDIT = 2; private static final int STATE_CONTEXT_REMOVED = 3; private static final int STATE_GROUP_CREATE_FORM = 100; private static final int STATE_GROUP_EDIT = 101; @@ -182,7 +173,7 @@ public class BGManagementController extends MainLayoutBasicController implements private BusinessGroupEditController groupEditCtr; private BGAreaEditController areaEditCtr; - private VelocityContainer overviewVC, newGroupVC, sendMessageVC, contextEditVC, vc_sendToChooserForm; + private VelocityContainer overviewVC, newGroupVC, sendMessageVC, vc_sendToChooserForm; private BusinessGroupSendToChooserForm sendToChooserForm; private Translator businessGroupTranslator; private boolean isGMAdminOwner; @@ -196,7 +187,6 @@ public class BGManagementController extends MainLayoutBasicController implements private ContactFormController contactCtr; private BGCopyWizardController bgCopyWizardCtr; private BGMultipleCopyWizardController bgMultipleCopyWizardCtr; - private BGContextEditController contextEditCtr; private TableController resourcesCtr; private GroupController contextOwnersCtr; @@ -207,9 +197,8 @@ public class BGManagementController extends MainLayoutBasicController implements private ToolController toolC; // Managers - private BGContextManager contextManager; - private BGAreaManager areaManager; - private BusinessGroupService businessGroupService; + private final BGAreaManager areaManager; + private final BusinessGroupService businessGroupService; // Workflow variables private List<ShortName> areaFilters; @@ -234,17 +223,14 @@ public class BGManagementController extends MainLayoutBasicController implements * @param bgContext * @param controllerFlags */ - public BGManagementController(UserRequest ureq, WindowControl wControl, BGContext bgContext, BGConfigFlags controllerFlags) { + public BGManagementController(UserRequest ureq, WindowControl wControl, OLATResource resource, BGConfigFlags controllerFlags) { super(ureq, wControl); this.resource = resource; - this.groupType = bgContext.getGroupType(); this.flags = controllerFlags; // Initialize managers - contextManager = BGContextManagerImpl.getInstance(); - if (flags.isEnabled(BGConfigFlags.AREAS)) { - areaManager = CoreSpringFactory.getImpl(BGAreaManager.class); - } + areaManager = CoreSpringFactory.getImpl(BGAreaManager.class); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); businessGroupTranslator = Util.createPackageTranslator(BusinessGroupMainRunController.class, ureq.getLocale()); // Initialize translator @@ -257,10 +243,6 @@ public class BGManagementController extends MainLayoutBasicController implements // initialize all velocity containers initVC(); - // check if user is owner of this group context - BaseSecurity securityManager = BaseSecurityManager.getInstance(); - isContextOwner = businessGroupService.isIdentityInBusinessGroup(getIdentity(), null, null, true, false, resource); - // Layout is controlled with generic controller: menu - content - tools // Navigation menu olatMenuTree = new MenuTree("olatMenuTree"); @@ -275,7 +257,7 @@ public class BGManagementController extends MainLayoutBasicController implements // 2 set correct tools using setTools method (override step 1) toolC = ToolFactory.createToolController(getWindowControl()); listenTo(toolC); - columnLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), olatMenuTree, toolC.getInitialComponent(), content, "groupmngt" + bgContext.getKey()); + columnLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), olatMenuTree, toolC.getInitialComponent(), content, "groupmngt"); listenTo(columnLayoutCtr); doOverview(ureq); @@ -287,7 +269,7 @@ public class BGManagementController extends MainLayoutBasicController implements Panel empty = new Panel("empty");//empty panel set as "menu" and "tool" Controller courseCloser = new DisposedBGAManagementController(ureq, wControl, this); listenTo(courseCloser); - Controller disposedBGAManagementController = new LayoutMain3ColsController(ureq, wControl, empty, empty, courseCloser.getInitialComponent(), "disposed " + "groupmngt" + bgContext.getKey()); + Controller disposedBGAManagementController = new LayoutMain3ColsController(ureq, wControl, empty, empty, courseCloser.getInitialComponent(), "disposedgroupmngt"); listenTo(disposedBGAManagementController); setDisposedMsgController(disposedBGAManagementController); @@ -608,11 +590,6 @@ public class BGManagementController extends MainLayoutBasicController implements doUserDetails(ureq); } } - } else if (source == contextEditCtr) { - if (event == Event.CHANGED_EVENT) { - // reload context, maybe updated title or something - //this.bgContext = contextManager.loadBGContext(this.bgContext); - } } else if (source == groupCreateController){ if (event == Event.DONE_EVENT) { releaseAdminLockAndGroupMUE(); @@ -812,8 +789,6 @@ public class BGManagementController extends MainLayoutBasicController implements overviewVC = createVelocityContainer("overview"); overviewVC.contextPut("flags", flags); overviewVC.contextPut("type", this.groupType); - // Context edit container - init anyway, maybe not used - contextEditVC = createVelocityContainer("contextedit"); // Create new group form newGroupVC = createVelocityContainer("newgroup"); newGroupVC.contextPut("type", this.groupType); @@ -1150,7 +1125,7 @@ public class BGManagementController extends MainLayoutBasicController implements if(group != null) { List<Identity> identities = new ArrayList<Identity>(1); identities.add(toRemoveIdentity); - businessGroupService.removeParticipantsAndFireEvent(ureqIdentity, identities, group, flags); + businessGroupService.removeParticipants(ureqIdentity, identities, group, flags); } } @@ -1158,7 +1133,7 @@ public class BGManagementController extends MainLayoutBasicController implements Long key = Long.valueOf(groupKey); BusinessGroup group = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(key); if(group != null) { - businessGroupService.removeOwnerAndFireEvent(ureq.getIdentity(), currentIdentity, group, flags, false); + businessGroupService.removeOwners(ureq.getIdentity(), Collections.singletonList(currentIdentity), group, flags); } } diff --git a/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java b/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java index 2330ef28832..22c894cfb86 100644 --- a/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java +++ b/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java @@ -84,8 +84,6 @@ import org.olat.course.nodes.iq.AssessmentEvent; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; import org.olat.group.GroupLoggingAction; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; import org.olat.group.properties.BusinessGroupPropertyManager; import org.olat.group.ui.BGConfigFlags; import org.olat.group.ui.BGControllerFactory; @@ -1028,7 +1026,6 @@ public class BusinessGroupMainRunController extends MainLayoutBasicController im private void doShowResources(UserRequest ureq) { // always refresh data model, maybe it has changed RepositoryTableModel repoTableModel = new RepositoryTableModel(resourceTrans); - BGContextManager contextManager = BGContextManagerImpl.getInstance(); List<RepositoryEntry> repoTableModelEntries = businessGroupService.findRepositoryEntries(Collections.singletonList(businessGroup), 0, -1); repoTableModel.setObjects(repoTableModelEntries); // init table controller only once diff --git a/src/main/java/org/olat/group/ui/wizard/BGCopyWizardController.java b/src/main/java/org/olat/group/ui/wizard/BGCopyWizardController.java index b3f9d104936..a3762710ed6 100644 --- a/src/main/java/org/olat/group/ui/wizard/BGCopyWizardController.java +++ b/src/main/java/org/olat/group/ui/wizard/BGCopyWizardController.java @@ -36,11 +36,8 @@ import org.olat.core.gui.translator.Translator; import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; import org.olat.core.util.Util; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.GroupLoggingAction; -import org.olat.group.context.BGContext; import org.olat.group.ui.BGConfigFlags; import org.olat.group.ui.BGTranslatorFactory; import org.olat.group.ui.BusinessGroupFormController; @@ -131,9 +128,9 @@ public class BGCopyWizardController extends WizardController { } private BusinessGroup doCopyGroup() { - BusinessGroupManager groupManager = BusinessGroupManagerImpl.getInstance(); // reload original group to prevent context proxy problems - this.originalGroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(originalGroup); + BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + this.originalGroup = bgs.loadBusinessGroup(originalGroup); //OLATResource resource = originalGroup.get(); String bgName = this.groupController.getGroupName(); String bgDesc = this.groupController.getGroupDescription(); @@ -141,9 +138,7 @@ public class BGCopyWizardController extends WizardController { Integer bgMin = this.groupController.getGroupMin(); boolean copyAreas = (this.flags.isEnabled(BGConfigFlags.AREAS) && this.copyForm.isCopyAreas()); - //TODO gm copy the relation to resources - - BusinessGroup newGroup = groupManager.copyBusinessGroup(this.originalGroup, bgName, bgDesc, bgMin, bgMax, null, null, copyAreas, + BusinessGroup newGroup = bgs.copyBusinessGroup(originalGroup, bgName, bgDesc, bgMin, bgMax, null, null, copyAreas, copyForm.isCopyTools(), copyForm.isCopyRights(), copyForm.isCopyOwners(), copyForm.isCopyParticipants(), copyForm .isCopyMembersVisibility(), copyForm.isCopyWaitingList()); return newGroup; diff --git a/src/main/java/org/olat/group/ui/wizard/BGMultipleCopyWizardController.java b/src/main/java/org/olat/group/ui/wizard/BGMultipleCopyWizardController.java index 156aa8b0d67..f784df70fec 100644 --- a/src/main/java/org/olat/group/ui/wizard/BGMultipleCopyWizardController.java +++ b/src/main/java/org/olat/group/ui/wizard/BGMultipleCopyWizardController.java @@ -140,14 +140,14 @@ public class BGMultipleCopyWizardController extends WizardController { } private BusinessGroup doCopyGroup(String newGroupName, Integer max) { - BusinessGroupManager groupManager = BusinessGroupManagerImpl.getInstance(); + BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); // reload original group to prevent context proxy problems - this.originalGroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(this.originalGroup); + this.originalGroup = bgs.loadBusinessGroup(this.originalGroup); //BGContext bgContext = this.originalGroup.getGroupContext(); boolean copyAreas = (flags.isEnabled(BGConfigFlags.AREAS) && copyForm.isCopyAreas()); //TODO gm copy relations to resources - BusinessGroup newGroup = groupManager.copyBusinessGroup(this.originalGroup, newGroupName, this.originalGroup.getDescription(), null, max, null, null, copyAreas, + BusinessGroup newGroup = bgs.copyBusinessGroup(originalGroup, newGroupName, this.originalGroup.getDescription(), null, max, null, null, copyAreas, copyForm.isCopyTools(), copyForm.isCopyRights(), copyForm.isCopyOwners(), copyForm.isCopyParticipants(), copyForm .isCopyMembersVisibility(), copyForm.isCopyWaitingList()); return newGroup; diff --git a/src/main/java/org/olat/portfolio/PortfolioModule.java b/src/main/java/org/olat/portfolio/PortfolioModule.java index dc9aea96ed3..1155ae1b30c 100755 --- a/src/main/java/org/olat/portfolio/PortfolioModule.java +++ b/src/main/java/org/olat/portfolio/PortfolioModule.java @@ -39,7 +39,7 @@ import org.olat.core.util.event.FrameworkStartedEvent; import org.olat.core.util.event.FrameworkStartupEventChannel; import org.olat.core.util.vfs.VFSContainer; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.group.DeletableGroupData; import org.olat.group.DeletableReference; import org.olat.portfolio.manager.EPFrontendManager; @@ -71,8 +71,8 @@ public class PortfolioModule extends AbstractOLATModule implements ConfigOnOff, private boolean isReflexionStepEnabled; private boolean isCopyrightStepEnabled; - public PortfolioModule(){ - BusinessGroupManagerImpl.getInstance().registerDeletableGroupDataListener(this); + public PortfolioModule(BusinessGroupService businessGroupService){ + businessGroupService.registerDeletableGroupDataListener(this); FrameworkStartupEventChannel.registerForStartupEvent(this); } diff --git a/src/main/java/org/olat/portfolio/_spring/portfolioContext.xml b/src/main/java/org/olat/portfolio/_spring/portfolioContext.xml index bfcca079138..d68bb09c6ca 100644 --- a/src/main/java/org/olat/portfolio/_spring/portfolioContext.xml +++ b/src/main/java/org/olat/portfolio/_spring/portfolioContext.xml @@ -8,6 +8,7 @@ <!-- ========================= --> <bean id="portfolioModule" class="org.olat.portfolio.PortfolioModule"> + <constructor-arg index="0" ref="businessGroupService"/> <property name="persistedProperties"> <bean class="org.olat.core.configuration.PersistedProperties" scope="prototype" init-method="init" destroy-method="destroy" depends-on="coordinatorManager,org.olat.core.util.WebappHelper"> diff --git a/src/main/java/org/olat/repository/RepositoryManager.java b/src/main/java/org/olat/repository/RepositoryManager.java index 5e73d26381b..6b976084816 100644 --- a/src/main/java/org/olat/repository/RepositoryManager.java +++ b/src/main/java/org/olat/repository/RepositoryManager.java @@ -72,8 +72,7 @@ import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; import org.olat.group.GroupLoggingAction; -import org.olat.group.context.BGContext2Resource; -import org.olat.group.context.BGContextImpl; +import org.olat.group.model.BGResourceRelation; import org.olat.group.model.SearchBusinessGroupParams; import org.olat.repository.async.BackgroundTaskQueueManager; import org.olat.repository.async.IncrementDownloadCounterBackgroundTask; @@ -618,15 +617,13 @@ public class RepositoryManager extends BasicManager { .append(" and ((") .append(" v.ownerGroup in (select ownerSgmsi.securityGroup from ").append(SecurityGroupMembershipImpl.class.getName()).append(" ownerSgmsi where ownerSgmsi.identity.key=:editorKey)") .append(" ) or (") - .append(" reResource in (select context2res.resource from ").append(BGContext2Resource.class.getName()).append(" as context2res, ") - .append(" ").append(BGContextImpl.class.getName()).append(" as context,") + .append(" reResource in (select groupRelation.resource from ").append(BGResourceRelation.class.getName()).append(" as groupRelation, ") .append(" ").append(SecurityGroupMembershipImpl.class.getName()).append(" as sgmsi,") .append(" ").append(PolicyImpl.class.getName()).append(" as poi,") .append(" ").append(OLATResourceImpl.class.getName()).append(" as ori") .append(" where sgmsi.identity.key = :editorKey and sgmsi.securityGroup = poi.securityGroup") .append(" and poi.permission = 'bgr.editor' and poi.olatResource = ori") - .append(" and (ori.resId = context.key) and ori.resName = 'org.olat.group.context.BGContextImpl'") - .append(" and context2res.groupContext=context") + .append(" and groupRelation.resource=ori") .append(" )") .append(" ))"); //TODO gm diff --git a/src/main/java/org/olat/repository/controllers/WizardCloseCourseController.java b/src/main/java/org/olat/repository/controllers/WizardCloseCourseController.java index c874c6dad2a..cf7939a4643 100644 --- a/src/main/java/org/olat/repository/controllers/WizardCloseCourseController.java +++ b/src/main/java/org/olat/repository/controllers/WizardCloseCourseController.java @@ -32,6 +32,7 @@ import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.SecurityGroup; import org.olat.catalog.CatalogManager; +import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; @@ -66,6 +67,7 @@ import org.olat.course.CourseFactory; import org.olat.course.ICourse; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGConfigFlags; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntryStatus; @@ -95,10 +97,13 @@ public class WizardCloseCourseController extends WizardController implements Wiz private VelocityContainer sendNotificationVC; private CloseRessourceOptionForm formStep2; + private final BusinessGroupService businessGroupService; + public WizardCloseCourseController(UserRequest ureq, WindowControl control, RepositoryEntry repositoryEntry) { super(ureq, control, NUM_STEPS); setBasePackage(RepositoryManager.class); this.repositoryEntry = repositoryEntry; + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); this.mainVc = createVelocityContainer("wizard"); this.panel = new Panel("panel"); @@ -249,38 +254,35 @@ public class WizardCloseCourseController extends WizardController implements Wiz ICourse course = CourseFactory.loadCourse(repositoryEntry.getOlatResource()); if(course != null) { BaseSecurity securityManager = BaseSecurityManager.getInstance(); - SecurityGroup secGroupOwner = null; - SecurityGroup secGroupPartipiciant = null; - SecurityGroup secGroupWaiting = null; + + // LearningGroups - List allGroups = course.getCourseEnvironment().getCourseGroupManager().getAllLearningGroupsFromAllContexts(); + List<BusinessGroup> allGroups = course.getCourseEnvironment().getCourseGroupManager().getAllLearningGroupsFromAllContexts(); BGConfigFlags flagsLearning = BGConfigFlags.createLearningGroupDefaultFlags(); - for (Object bGroup : allGroups) { - secGroupOwner = ((BusinessGroup) bGroup).getOwnerGroup(); - secGroupPartipiciant = ((BusinessGroup) bGroup).getPartipiciantGroup(); - BusinessGroupManagerImpl.getInstance().removeOwnersAndFireEvent(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupOwner), ((BusinessGroup) bGroup), flagsLearning); - BusinessGroupManagerImpl.getInstance().removeParticipantsAndFireEvent(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupPartipiciant), ((BusinessGroup) bGroup), flagsLearning); - if(((BusinessGroup) bGroup).getWaitingListEnabled()) { - secGroupWaiting = ((BusinessGroup) bGroup).getWaitingGroup(); - BusinessGroupManagerImpl.getInstance().removeFromWaitingListAndFireEvent(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupWaiting), ((BusinessGroup) bGroup), flagsLearning); - } + for (BusinessGroup bGroup : allGroups) { + SecurityGroup secGroupOwner = bGroup.getOwnerGroup(); + SecurityGroup secGroupPartipiciant = bGroup.getPartipiciantGroup(); + SecurityGroup secGroupWaiting = bGroup.getWaitingGroup(); + businessGroupService.removeOwners(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupOwner), bGroup, flagsLearning); + businessGroupService.removeParticipants(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupPartipiciant), bGroup, flagsLearning); + businessGroupService.removeFromWaitingList(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupWaiting), bGroup, flagsLearning); } // RightGroups allGroups.clear(); allGroups = course.getCourseEnvironment().getCourseGroupManager().getAllRightGroupsFromAllContexts(); BGConfigFlags flagsRightgroup = BGConfigFlags.createRightGroupDefaultFlags(); for (Object bGroup : allGroups) { - secGroupPartipiciant = ((BusinessGroup) bGroup).getPartipiciantGroup(); - BusinessGroupManagerImpl.getInstance().removeParticipantsAndFireEvent(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupPartipiciant), ((BusinessGroup) bGroup), flagsRightgroup); + SecurityGroup secGroupPartipiciant = ((BusinessGroup) bGroup).getPartipiciantGroup(); + businessGroupService.removeParticipants(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupPartipiciant), ((BusinessGroup) bGroup), flagsRightgroup); } //fxdiff VCRP-1,2: access control of resources if(repositoryEntry.getParticipantGroup() != null) { - secGroupPartipiciant = repositoryEntry.getParticipantGroup(); - BusinessGroupManagerImpl.getInstance().removeAndFireEvent(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupPartipiciant), secGroupPartipiciant); + SecurityGroup secGroupPartipiciant = repositoryEntry.getParticipantGroup(); + businessGroupService.removeAndFireEvent(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupPartipiciant), secGroupPartipiciant); } if(repositoryEntry.getTutorGroup() != null) { - secGroupPartipiciant = repositoryEntry.getTutorGroup(); - BusinessGroupManagerImpl.getInstance().removeAndFireEvent(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupPartipiciant), secGroupPartipiciant); + SecurityGroup secGroupPartipiciant = repositoryEntry.getTutorGroup(); + businessGroupService.removeAndFireEvent(identity, securityManager.getIdentitiesOfSecurityGroup(secGroupPartipiciant), secGroupPartipiciant); } } } diff --git a/src/main/java/org/olat/repository/delete/service/_spring/repoDeletionContext.xml b/src/main/java/org/olat/repository/delete/service/_spring/repoDeletionContext.xml index 259ce6adb79..d8d2965df77 100644 --- a/src/main/java/org/olat/repository/delete/service/_spring/repoDeletionContext.xml +++ b/src/main/java/org/olat/repository/delete/service/_spring/repoDeletionContext.xml @@ -37,11 +37,6 @@ <constructor-arg index="1" ref="deletionModule" /> </bean> - <bean id="groupDeletionManager" class="org.olat.group.delete.service.GroupDeletionManager"> - <constructor-arg index="0" ref="deletionModule" /> - <property name="businessGroupService" ref="businessGroupService"/> - </bean> - <bean id="userDeletionManager" class="org.olat.admin.user.delete.service.UserDeletionManager"> <constructor-arg index="0" ref="deletionModule" /> <constructor-arg index="1" ref="coordinatorManager" /> 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 015f753c40e..51d96203b6c 100644 --- a/src/main/java/org/olat/resource/accesscontrol/manager/ACMethodManagerImpl.java +++ b/src/main/java/org/olat/resource/accesscontrol/manager/ACMethodManagerImpl.java @@ -40,7 +40,6 @@ import org.olat.core.util.event.FrameworkStartupEventChannel; import org.olat.core.util.event.GenericEventListener; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupImpl; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.resource.OLATResource; import org.olat.resource.OLATResourceImpl; diff --git a/src/main/java/org/olat/resource/accesscontrol/manager/ACOfferManager.java b/src/main/java/org/olat/resource/accesscontrol/manager/ACOfferManager.java index 5ba8320680e..eb66fc57009 100644 --- a/src/main/java/org/olat/resource/accesscontrol/manager/ACOfferManager.java +++ b/src/main/java/org/olat/resource/accesscontrol/manager/ACOfferManager.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Set; import org.olat.resource.OLATResource; -import org.olat.resource.accesscontrol.model.BusinessGroupAccess; import org.olat.resource.accesscontrol.model.Offer; /** diff --git a/src/main/java/org/olat/resource/accesscontrol/ui/SecurityGroupsRepositoryMainController.java b/src/main/java/org/olat/resource/accesscontrol/ui/SecurityGroupsRepositoryMainController.java index c3f36c08458..c13a5484ecd 100644 --- a/src/main/java/org/olat/resource/accesscontrol/ui/SecurityGroupsRepositoryMainController.java +++ b/src/main/java/org/olat/resource/accesscontrol/ui/SecurityGroupsRepositoryMainController.java @@ -51,8 +51,7 @@ import org.olat.course.ICourse; import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupAddResponse; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; import org.olat.resource.accesscontrol.AccessControlModule; @@ -87,9 +86,9 @@ public class SecurityGroupsRepositoryMainController extends MainLayoutBasicContr private final RepositoryEntry repoEntry; private final RepositoryManager rm; - private final BusinessGroupManager bgm; private final BaseSecurity securityManager; private final AccessControlModule acModule; + private final BusinessGroupService businessGroupService; private final boolean mayModifyMembers; @@ -107,9 +106,9 @@ public class SecurityGroupsRepositoryMainController extends MainLayoutBasicContr this.repoEntry = repoEntry; this.mayModifyMembers = mayModifyMembers; - bgm = BusinessGroupManagerImpl.getInstance(); securityManager = BaseSecurityManager.getInstance(); acModule = (AccessControlModule)CoreSpringFactory.getBean("acModule"); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); getUserActivityLogger().setStickyActionType(ActionType.admin); @@ -288,7 +287,7 @@ public class SecurityGroupsRepositoryMainController extends MainLayoutBasicContr } else if (source == participantsController) { secGroup = repoEntry.getParticipantGroup(); } - BusinessGroupAddResponse response = bgm.addToSecurityGroupAndFireEvent(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), secGroup); + BusinessGroupAddResponse response = businessGroupService.addToSecurityGroupAndFireEvent(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), secGroup); identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities()); identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission()); identitiesAddedEvent.setIdentitiesAlreadyInGroup(response.getIdentitiesAlreadyInGroup()); @@ -298,14 +297,14 @@ public class SecurityGroupsRepositoryMainController extends MainLayoutBasicContr List<Identity> identitiesToRemove = identitiesRemoveEvent.getRemovedIdentities(); if (source == ownersController) { SecurityGroup ownerGroup = repoEntry.getOwnerGroup(); - bgm.removeAndFireEvent(ureq.getIdentity(), identitiesToRemove, ownerGroup); + businessGroupService.removeAndFireEvent(ureq.getIdentity(), identitiesToRemove, ownerGroup); } else if (source == tutorsController) { SecurityGroup tutorGroup = repoEntry.getTutorGroup(); - bgm.removeAndFireEvent(ureq.getIdentity(), identitiesToRemove, tutorGroup); + businessGroupService.removeAndFireEvent(ureq.getIdentity(), identitiesToRemove, tutorGroup); removeTutors(identitiesToRemove); } else if (source == participantsController) { SecurityGroup participantGroup = repoEntry.getParticipantGroup(); - bgm.removeAndFireEvent(ureq.getIdentity(), identitiesToRemove, participantGroup); + businessGroupService.removeAndFireEvent(ureq.getIdentity(), identitiesToRemove, participantGroup); removeParticipants(identitiesToRemove); } } diff --git a/src/main/java/org/olat/restapi/group/LearningGroupWebService.java b/src/main/java/org/olat/restapi/group/LearningGroupWebService.java index c125407f198..71ef79e1099 100644 --- a/src/main/java/org/olat/restapi/group/LearningGroupWebService.java +++ b/src/main/java/org/olat/restapi/group/LearningGroupWebService.java @@ -22,6 +22,7 @@ package org.olat.restapi.group; import static org.olat.restapi.security.RestSecurityHelper.isGroupManager; import static org.olat.restapi.support.ObjectFactory.getInformation; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -64,8 +65,6 @@ import org.olat.core.util.vfs.callbacks.VFSSecurityCallback; import org.olat.core.util.vfs.restapi.VFSWebServiceSecurityCallback; import org.olat.core.util.vfs.restapi.VFSWebservice; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.model.SearchBusinessGroupParams; import org.olat.group.properties.BusinessGroupPropertyManager; @@ -80,6 +79,7 @@ import org.olat.restapi.support.vo.GroupVO; import org.olat.user.restapi.UserVO; import org.olat.user.restapi.UserVOFactory; + /** * Description:<br> * This handles the learning groups. @@ -248,12 +248,12 @@ public class LearningGroupWebService { return Response.serverError().status(Status.UNAUTHORIZED).build(); } - BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); - BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey); + BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + BusinessGroup bg = bgs.loadBusinessGroup(groupKey); if(bg == null) { return Response.serverError().status(Status.NOT_FOUND).build(); } - bgm.deleteBusinessGroup(bg); + bgs.deleteBusinessGroup(bg); return Response.ok().build(); } @@ -483,9 +483,8 @@ public class LearningGroupWebService { } final UserRequest ureq = RestSecurityHelper.getUserRequest(request); - - final BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); - final BusinessGroup group = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey); + final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + final BusinessGroup group = bgs.loadBusinessGroup(groupKey); final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false); if(identity == null || group == null) { return Response.serverError().status(Status.NOT_FOUND).build(); @@ -494,7 +493,7 @@ public class LearningGroupWebService { CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerCallback<Boolean>(){ public Boolean execute() { BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - bgm.addOwnerAndFireEvent(ureq.getIdentity(), identity, group, flags, false); + bgs.addOwner(ureq.getIdentity(), identity, group, flags); return Boolean.TRUE; } });// end of doInSync @@ -543,8 +542,8 @@ public class LearningGroupWebService { final UserRequest ureq = RestSecurityHelper.getUserRequest(request); - final BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); - final BusinessGroup group = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey); + final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + final BusinessGroup group = bgs.loadBusinessGroup(groupKey); final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false); if(identity == null || group == null) { return Response.serverError().status(Status.NOT_FOUND).build(); @@ -553,7 +552,7 @@ public class LearningGroupWebService { CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerCallback<Boolean>(){ public Boolean execute() { BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - bgm.removeOwnerAndFireEvent(ureq.getIdentity(), identity, group, flags, false); + bgs.removeOwners(ureq.getIdentity(), Collections.singletonList(identity), group, flags); return Boolean.TRUE; } });// end of doInSync @@ -600,9 +599,8 @@ public class LearningGroupWebService { } final UserRequest ureq = RestSecurityHelper.getUserRequest(request); - - final BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); - final BusinessGroup group = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey); + final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + final BusinessGroup group = bgs.loadBusinessGroup(groupKey); final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false); if(identity == null || group == null) { return Response.serverError().status(Status.NOT_FOUND).build(); @@ -611,7 +609,7 @@ public class LearningGroupWebService { CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerCallback<Boolean>(){ public Boolean execute() { BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - bgm.addParticipantAndFireEvent(ureq.getIdentity(), identity, group, flags, false); + bgs.addParticipant(ureq.getIdentity(), identity, group, flags); return Boolean.TRUE; } });// end of doInSync @@ -658,9 +656,8 @@ public class LearningGroupWebService { } final UserRequest ureq = RestSecurityHelper.getUserRequest(request); - - final BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); - final BusinessGroup group = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey); + final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + final BusinessGroup group = bgs.loadBusinessGroup(groupKey); final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false); if(identity == null || group == null) { return Response.serverError().status(Status.NOT_FOUND).build(); @@ -669,7 +666,7 @@ public class LearningGroupWebService { CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerExecutor(){ public void execute() { BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - bgm.removeParticipantAndFireEvent(ureq.getIdentity(), identity, group, flags, false); + bgs.removeParticipant(ureq.getIdentity(), identity, group, flags); } }); diff --git a/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java b/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java index f489ee0c0c6..67c8cb4bed8 100644 --- a/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java +++ b/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java @@ -60,7 +60,6 @@ import org.olat.course.CourseFactory; import org.olat.course.CourseModule; import org.olat.course.ICourse; import org.olat.course.config.CourseConfig; -import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.nodes.CourseNode; import org.olat.course.tree.CourseEditorTreeNode; import org.olat.repository.RepositoryEntry; @@ -283,10 +282,7 @@ public class CoursesWebService { addedEntry.setOlatResource(ores); // create an empty course - ICourse course = CourseFactory.createEmptyCourse(oresable, shortTitle, longTitle, learningObjectives); - // initialize course group management - CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager(); - cgm.createCourseGroupmanagement(course.getResourceableId().toString()); + CourseFactory.createEmptyCourse(oresable, shortTitle, longTitle, learningObjectives); prepareSecurityGroup(initialAuthor, addedEntry); return prepareCourse(addedEntry, courseConfigVO); } catch (Exception e) { diff --git a/src/main/java/org/olat/upgrade/OLATUpgrade_7_1_1.java b/src/main/java/org/olat/upgrade/OLATUpgrade_7_1_1.java index 8e5595c3e73..29502633fee 100644 --- a/src/main/java/org/olat/upgrade/OLATUpgrade_7_1_1.java +++ b/src/main/java/org/olat/upgrade/OLATUpgrade_7_1_1.java @@ -38,7 +38,6 @@ import org.olat.core.commons.services.commentAndRating.model.UserComment; import org.olat.core.id.Identity; import org.olat.group.BusinessGroup; import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManager; import org.olat.group.context.BGContextManagerImpl; import org.olat.portfolio.PortfolioModule; import org.olat.portfolio.manager.EPFrontendManager; diff --git a/src/main/resources/serviceconfig/org/olat/_spring/sitedefContext.xml b/src/main/resources/serviceconfig/org/olat/_spring/sitedefContext.xml index 079bc6ab33c..d5f22843f77 100644 --- a/src/main/resources/serviceconfig/org/olat/_spring/sitedefContext.xml +++ b/src/main/resources/serviceconfig/org/olat/_spring/sitedefContext.xml @@ -25,9 +25,6 @@ <bean id="olatsites_repository" class="org.olat.repository.site.RepositorySiteDef" scope="prototype" > <property name="order" value="3" /> </bean> - <bean id="olatsites_groupman" class="org.olat.group.site.GroupsManagementSiteDef" scope="prototype" > - <property name="order" value="4" /> - </bean> <bean id="olatsites_useradmin" class="org.olat.admin.site.UserAdminSiteDef" scope="prototype" > <property name="order" value="5" /> </bean> @@ -38,9 +35,5 @@ <property name="order" value="7" /> <property name="enabled" value="${guidemo.enabled}"/> </bean> - <!-- <bean id="olatsites_testing" class="org.olat.test.site.TestSiteDef" scope="prototype" > - <property name="order" value="8" /> - </bean> - --> </beans> \ No newline at end of file diff --git a/src/test/java/org/olat/commons/lifecycle/LifeCycleManagerTest.java b/src/test/java/org/olat/commons/lifecycle/LifeCycleManagerTest.java index 1ab9fb5ecd2..2eb5c4fe884 100644 --- a/src/test/java/org/olat/commons/lifecycle/LifeCycleManagerTest.java +++ b/src/test/java/org/olat/commons/lifecycle/LifeCycleManagerTest.java @@ -36,19 +36,16 @@ import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.olat.basesecurity.BaseSecurityManager; -import org.olat.basesecurity.BaseSecurityModule; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.logging.Tracing; -import org.olat.core.util.Encoder; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.resource.OLATResourceManager; import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; +import org.springframework.beans.factory.annotation.Autowired; /** * Initial Date: Mar 11, 2004 @@ -62,27 +59,25 @@ public class LifeCycleManagerTest extends OlatTestCase implements OLATResourceab private long RESOURCE_ID = 144; private String RESOURCE_TYPE = "org.olat.commons.lifecycle.LifeCycleManagerTest"; - private BusinessGroupManager gm; private static Logger log = Logger.getLogger(LifeCycleManagerTest.class); - private static boolean isInitialized = false; private static Identity identity = null; private static BusinessGroup group = null; private static org.olat.resource.OLATResource res = null; - + + @Autowired + private BusinessGroupService businessGroupService; + /** * @see junit.framework.TestCase#setUp() */ - @Before public void setup() { - - // identity with null User should be ok for test case - res = OLATResourceManager.getInstance().createOLATResourceInstance(this); - OLATResourceManager.getInstance().saveOLATResource(res); - identity = JunitTestHelper.createAndPersistIdentityAsUser("foo"); - gm = BusinessGroupManagerImpl.getInstance(); - group = gm.createAndPersistBusinessGroup(BusinessGroup.TYPE_BUDDYGROUP, - identity, "a buddygroup", "a desc", null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, null); - + @Before + public void setup() { + // identity with null User should be ok for test case + res = OLATResourceManager.getInstance().createOLATResourceInstance(this); + OLATResourceManager.getInstance().saveOLATResource(res); + identity = JunitTestHelper.createAndPersistIdentityAsUser("foo"); + group = businessGroupService.createBusinessGroup( identity, "a buddygroup", "a desc", BusinessGroup.TYPE_BUDDYGROUP, -1, -1, false, false, null); } /** @@ -91,7 +86,7 @@ public class LifeCycleManagerTest extends OlatTestCase implements OLATResourceab @After public void tearDown() { try { OLATResourceManager.getInstance().deleteOLATResource(res); - gm.deleteBusinessGroup(group); + businessGroupService.deleteBusinessGroup(group); Tracing.logInfo("tearDown: DB.getInstance().closeSession()", this.getClass()); DBFactory.getInstance().closeSession(); } catch (Exception e) { diff --git a/src/test/java/org/olat/course/groupsandrights/CourseGroupManagementTest.java b/src/test/java/org/olat/course/groupsandrights/CourseGroupManagementTest.java index af78001cf52..0fec2987493 100644 --- a/src/test/java/org/olat/course/groupsandrights/CourseGroupManagementTest.java +++ b/src/test/java/org/olat/course/groupsandrights/CourseGroupManagementTest.java @@ -40,13 +40,9 @@ import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.util.resource.OresHelper; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.group.area.BGArea; import org.olat.group.area.BGAreaManager; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManagerImpl; import org.olat.group.right.BGRightManager; import org.olat.resource.OLATResource; import org.olat.resource.OLATResourceManager; @@ -112,13 +108,10 @@ public class CourseGroupManagementTest extends OlatTestCase { /** rights tests */ @Test public void testHasRightIsInMethods() { - BGContextManagerImpl cm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); BaseSecurity secm = BaseSecurityManager.getInstance(); // 1) context one: learning groups - BGContext ctxt1 = cm.createAndAddBGContextToResource("c1name", course1, BusinessGroup.TYPE_LEARNINGROUP, id1, true); - OLATResource c1 = resourceManager.findOrPersistResourceable(course1); + OLATResource c1 = JunitTestHelper.createRandomResource(); // create groups without waitinglist BusinessGroup g1 = businessGroupService.createBusinessGroup(null, "g1", null, BusinessGroup.TYPE_LEARNINGROUP,new Integer(0), new Integer(10), false, false, c1); @@ -139,10 +132,10 @@ public class CourseGroupManagementTest extends OlatTestCase { areaManager.addBGToBGArea(g2, a3); // 2) context two: right groups - BGContext c2 = cm.createAndAddBGContextToResource("c2name", course1, BusinessGroup.TYPE_RIGHTGROUP, id2, true); + OLATResource c2 = JunitTestHelper.createRandomResource(); // groups - BusinessGroup g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "g3", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); - BusinessGroup g4 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "g4", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); + BusinessGroup g3 = businessGroupService.createBusinessGroup(null, "g3", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); + BusinessGroup g4 = businessGroupService.createBusinessGroup(null, "g4", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); // members secm.addIdentityToSecurityGroup(id1, g3.getPartipiciantGroup()); secm.addIdentityToSecurityGroup(id1, g4.getPartipiciantGroup()); @@ -205,18 +198,18 @@ public class CourseGroupManagementTest extends OlatTestCase { assertTrue(gm.hasRight(id1, CourseRights.RIGHT_COURSEEDITOR)); assertTrue(gm.hasRight(id1, CourseRights.RIGHT_GROUPMANAGEMENT)); assertFalse(gm.hasRight(id1, CourseRights.RIGHT_ASSESSMENT)); - assertTrue(gm.hasRight(id1, CourseRights.RIGHT_COURSEEDITOR, c2.getName())); + //assertTrue(gm.hasRight(id1, CourseRights.RIGHT_COURSEEDITOR, c2.getName())); //TODO gm assertFalse(gm.hasRight(id1, CourseRights.RIGHT_COURSEEDITOR, c1.getName())); assertFalse(gm.hasRight(id2, CourseRights.RIGHT_COURSEEDITOR)); // test context DBFactory.getInstance().closeSession(); //TODO gm assertTrue(gm.isIdentityInGroupContext(id1,c1.getName())); - assertTrue(gm.isIdentityInGroupContext(id1,c2.getName())); + //assertTrue(gm.isIdentityInGroupContext(id1,c2.getName())); //TODO gm assertTrue(gm.isIdentityInGroupContext(id2,c1.getName())); - assertFalse(gm.isIdentityInGroupContext(id2,c2.getName())); + //assertFalse(gm.isIdentityInGroupContext(id2,c2.getName())); //TODO gm assertTrue(gm.isIdentityInGroupContext(id3,c1.getName())); - assertTrue(gm.isIdentityInGroupContext(id3,c2.getName())); + //assertTrue(gm.isIdentityInGroupContext(id3,c2.getName())); } } \ No newline at end of file diff --git a/src/test/java/org/olat/course/nodes/en/EnrollmentManagerTest.java b/src/test/java/org/olat/course/nodes/en/EnrollmentManagerTest.java index d81e4165441..7ef1e814ceb 100644 --- a/src/test/java/org/olat/course/nodes/en/EnrollmentManagerTest.java +++ b/src/test/java/org/olat/course/nodes/en/EnrollmentManagerTest.java @@ -68,12 +68,8 @@ import org.olat.course.run.environment.CourseEnvironment; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.course.run.userview.UserCourseEnvironmentImpl; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; +import org.olat.resource.OLATResource; import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; import org.springframework.beans.factory.annotation.Autowired; @@ -103,7 +99,8 @@ public class EnrollmentManagerTest extends OlatTestCase implements WindowControl @Autowired private BusinessGroupService businessGroupService; - + @Autowired + private EnrollmentManager enrollmentManager; /** * @see junit.framework.TestCase#setUp() @@ -112,17 +109,15 @@ public class EnrollmentManagerTest extends OlatTestCase implements WindowControl // Identities id1 = JunitTestHelper.createAndPersistIdentityAsUser("id1"); DBFactory.getInstance().closeSession(); - BusinessGroupManager bgManager = BusinessGroupManagerImpl.getInstance(); // create business-group with waiting-list String bgWithWaitingListName = "Group with WaitingList"; String bgWithWaitingListDesc = "some short description for Group with WaitingList"; Boolean enableWaitinglist = new Boolean(true); Boolean enableAutoCloseRanks = new Boolean(true); - BGContextManagerImpl bgcm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BGContext groupContext = bgcm.createAndPersistBGContext("c1name", "c1desc", BusinessGroup.TYPE_LEARNINGROUP, null, true); - System.out.println("testAddToWaitingListAndFireEvent: groupContext=" + groupContext); - bgWithWaitingList = bgManager.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, id1, bgWithWaitingListName, - bgWithWaitingListDesc, null, null, enableWaitinglist, enableAutoCloseRanks, groupContext); + OLATResource resource = JunitTestHelper.createRandomResource(); + System.out.println("testAddToWaitingListAndFireEvent: resource=" + resource); + bgWithWaitingList = businessGroupService.createBusinessGroup(id1, bgWithWaitingListName, + bgWithWaitingListDesc, BusinessGroup.TYPE_LEARNINGROUP, -1, -1, enableWaitinglist, enableAutoCloseRanks, resource); bgWithWaitingList.setMaxParticipants(new Integer(2)); System.out.println("TEST bgWithWaitingList=" + bgWithWaitingList); System.out.println("TEST bgWithWaitingList.getMaxParticipants()=" + bgWithWaitingList.getMaxParticipants() ); @@ -147,7 +142,6 @@ public class EnrollmentManagerTest extends OlatTestCase implements WindowControl */ @Test public void testEnroll() throws Exception { System.out.println("testEnroll: start..."); - EnrollmentManager enrollmentManager = EnrollmentManager.getInstance(); ENCourseNode enNode = new ENCourseNode(); OLATResourceable ores = OresHelper.createOLATResourceableTypeWithoutCheck("TestCourse"); CourseEnvironment cenv = CourseFactory.createEmptyCourse(ores, "Test", "Test", "learningObjectives").getCourseEnvironment(); diff --git a/src/test/java/org/olat/course/nodes/projectbroker/ProjectBrokerManagerTest.java b/src/test/java/org/olat/course/nodes/projectbroker/ProjectBrokerManagerTest.java index 5929f030d10..6e3865085fd 100644 --- a/src/test/java/org/olat/course/nodes/projectbroker/ProjectBrokerManagerTest.java +++ b/src/test/java/org/olat/course/nodes/projectbroker/ProjectBrokerManagerTest.java @@ -45,6 +45,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.olat.basesecurity.SecurityGroupImpl; +import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.gui.translator.PackageTranslator; import org.olat.core.id.Identity; @@ -55,7 +56,7 @@ import org.olat.course.nodes.projectbroker.service.ProjectBrokerManagerFactory; import org.olat.course.nodes.projectbroker.service.ProjectBrokerModuleConfiguration; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupImpl; -import org.olat.group.BusinessGroupManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.group.ui.BGConfigFlags; import org.olat.modules.ModuleConfiguration; import org.olat.repository.RepositoryEntry; @@ -264,7 +265,7 @@ public class ProjectBrokerManagerTest extends OlatTestCase { assertFalse("Can not be project leader of project B",ProjectBrokerManagerFactory.getProjectGroupManager().isProjectManager(id1, testProjectB)); assertTrue("Must be project-leader of project A", ProjectBrokerManagerFactory.getProjectGroupManager().isProjectManager(id2, testProjectB)); - BusinessGroupManagerImpl.getInstance().removeOwnersAndFireEvent(id1, projectManagerList, testProjectA.getProjectGroup(),flags); + CoreSpringFactory.getImpl(BusinessGroupService.class).removeOwners(id1, projectManagerList, testProjectA.getProjectGroup(),flags); // check no project leader anymore assertFalse("Can not be project leader of project A",ProjectBrokerManagerFactory.getProjectGroupManager().isProjectManager(id1, testProjectA)); assertFalse("Can not be project leader of project B",ProjectBrokerManagerFactory.getProjectGroupManager().isProjectManager(id1, testProjectB)); diff --git a/src/test/java/org/olat/group/BusinessGroupManagerImplTest.java b/src/test/java/org/olat/group/BusinessGroupManagerImplTest.java index 75a3a8efae0..5f6d1075011 100644 --- a/src/test/java/org/olat/group/BusinessGroupManagerImplTest.java +++ b/src/test/java/org/olat/group/BusinessGroupManagerImplTest.java @@ -42,7 +42,6 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Set; import org.apache.log4j.Logger; @@ -61,20 +60,16 @@ import org.olat.core.gui.control.WindowBackOffice; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.generic.dtabs.DTabs; import org.olat.core.gui.control.info.WindowControlInfo; -import org.olat.core.gui.translator.PackageTranslator; -import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; import org.olat.core.id.User; import org.olat.core.id.context.BusinessControl; import org.olat.core.util.Encoder; -import org.olat.core.util.Util; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; import org.olat.group.ui.BGConfigFlags; +import org.olat.resource.OLATResource; import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; import org.olat.user.UserManager; +import org.springframework.beans.factory.annotation.Autowired; /** * Description: <BR/>TODO: Class Description for BusinessGroupManagerImplTest @@ -121,13 +116,15 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window private String threeDesc = "some short description for second buddygroup"; // private String threeIntr = "notting more"; // - private static boolean isInitialized; private static final int NROFTESTCASES = 3; private static int nrOfTestCasesAlreadyRun = 0; private static boolean suiteIsAborted = true; // For WaitingGroup tests - private static Translator testTranslator = null; private static BusinessGroup bgWithWaitingList = null; + + + @Autowired + private BusinessGroupService businessGroupService; /** @@ -135,42 +132,41 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window */ @Before public void setUp() throws Exception { - BusinessGroupManagerImpl bgManager = (BusinessGroupManagerImpl)BusinessGroupManagerImpl.getInstance(); // Identities id1 = JunitTestHelper.createAndPersistIdentityAsUser("id1"); id2 = JunitTestHelper.createAndPersistIdentityAsUser("id2"); id3 = JunitTestHelper.createAndPersistIdentityAsUser("id3"); id4 = JunitTestHelper.createAndPersistIdentityAsUser("id4"); // buddyGroups without waiting-list: groupcontext is null - List l = bgManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id1, null); + List<BusinessGroup> l = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id1, null); if (l.size() == 0) { - one = bgManager.createAndPersistBusinessGroup(BusinessGroup.TYPE_BUDDYGROUP, id1, oneName, oneDesc, null, null, false, false, null); + one = businessGroupService.createBusinessGroup(id1, oneName, oneDesc, BusinessGroup.TYPE_BUDDYGROUP, -1, -1, false, false, null); } else { - List<BusinessGroup> groups = bgManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id1, null); + List<BusinessGroup> groups = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id1, null); for(BusinessGroup group:groups) { if(oneName.equals(group.getName())) { one = group; } } } - l = bgManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); + l = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); if (l.size() == 0) { - two = bgManager.createAndPersistBusinessGroup(BusinessGroup.TYPE_BUDDYGROUP, id2, twoName, twoDesc, null, null, false, false, null); + two = businessGroupService.createBusinessGroup(id2, twoName, twoDesc, BusinessGroup.TYPE_BUDDYGROUP, -1, -1, false, false, null); SecurityGroup twoPartips = two.getPartipiciantGroup(); BaseSecurityManager.getInstance().addIdentityToSecurityGroup(id3, twoPartips); BaseSecurityManager.getInstance().addIdentityToSecurityGroup(id4, twoPartips); } else { - two = (BusinessGroup) bgManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null).get(0); + two = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null).get(0); } - l = bgManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id3, null); + l = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id3, null); if (l.size() == 0) { - three = bgManager.createAndPersistBusinessGroup(BusinessGroup.TYPE_BUDDYGROUP, id3, threeName, threeDesc, null, null, false, false, null); + three = businessGroupService.createBusinessGroup(id3, threeName, threeDesc, BusinessGroup.TYPE_BUDDYGROUP, -1, -1, false, false, null); SecurityGroup threeOwner = three.getOwnerGroup(); SecurityGroup threeOPartips = three.getPartipiciantGroup(); BaseSecurityManager.getInstance().addIdentityToSecurityGroup(id2, threeOPartips); BaseSecurityManager.getInstance().addIdentityToSecurityGroup(id1, threeOwner); } else { - three = (BusinessGroup) bgManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id3, null).get(0); + three = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id3, null).get(0); } /* * Membership in ParticipiantGroups............................. id1 @@ -181,7 +177,7 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window DBFactory.getInstance().closeSession(); - setupWaitingList(bgManager); + setupWaitingList(businessGroupService); /* * phuuu finally initialized */ @@ -191,10 +187,8 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window public void testCheckIfNamesExistsInContext() throws Exception { suiteIsAborted = true; - BusinessGroupManagerImpl bgManager = (BusinessGroupManagerImpl)BusinessGroupManagerImpl.getInstance(); - BGContextManagerImpl bgContextManager = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BGContext ctxA = bgContextManager.createAndPersistBGContext("DefaultA", "Empty", BusinessGroup.TYPE_LEARNINGROUP, id1, true); - BGContext ctxB = bgContextManager.createAndPersistBGContext("DefaultB", "Empty", BusinessGroup.TYPE_LEARNINGROUP, id1, true); + OLATResource ctxA = JunitTestHelper.createRandomResource(); + OLATResource ctxB = JunitTestHelper.createRandomResource(); String[] namesInCtxA = new String[] { "A-GroupOne", "A-GroupTwo", "A-GroupThree", "A-GroupFour", "A-GroupFive", "A-GroupSix" }; String[] namesInCtxB = new String[] { "B-GroupAAA", "B-GroupBBB", "B-GroupCCC", "B-GroupDDD", "B-GroupEEE", "B-GroupFFF" }; @@ -202,11 +196,11 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window BusinessGroup[] ctxBgroups = new BusinessGroup[namesInCtxB.length]; for (int i = 0; i < namesInCtxA.length; i++) { - ctxAgroups[i] = bgManager.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, id1, namesInCtxA[i], null, 0, 0, false, + ctxAgroups[i] = businessGroupService.createBusinessGroup(id1, namesInCtxA[i], null, BusinessGroup.TYPE_LEARNINGROUP, 0, 0, false, false, ctxA); } for (int i = 0; i < namesInCtxB.length; i++) { - ctxBgroups[i] = bgManager.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, id1, namesInCtxB[i], null, 0, 0, false, + ctxBgroups[i] = businessGroupService.createBusinessGroup(id1, namesInCtxB[i], null, BusinessGroup.TYPE_LEARNINGROUP, 0, 0, false, false, ctxB); } // first click created two context and each of them containg groups @@ -215,72 +209,59 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window for (int i = 0; i < ctxAgroups.length; i++) { System.out.println("Test: i=" + i); System.out.println("Test: ctxAgroups[i]=" + ctxAgroups[i]); - DBFactory.getInstance().closeSession(); - } - for (int i = 0; i < ctxBgroups.length; i++) { - DBFactory.getInstance().closeSession(); } + DBFactory.getInstance().closeSession(); + // next click needs to check of a set of groupnames already exists. - Set subsetOkInA = new HashSet() { - { - add("A-GroupTwo"); - add("A-GroupThree"); - add("A-GroupFour"); - } - }; - Set subsetNOkInA = new HashSet() { - { - add("A-GroupTwo"); - add("NOT-IN-A"); - add("A-GroupThree"); - add("A-GroupFour"); - } - }; - Set subsetOkInB = new HashSet() { - { - add("B-GroupCCC"); - add("B-GroupDDD"); - add("B-GroupEEE"); - add("B-GroupFFF"); - } - }; - Set subsetNOkInB = new HashSet() { - { - add("B-GroupCCC"); - add("NOT-IN-B"); - add("B-GroupEEE"); - add("B-GroupFFF"); - } - }; - Set setSpansAandBNok = new HashSet() { - { - add("B-GroupCCC"); - add("A-GroupTwo"); - add("A-GroupThree"); - add("B-GroupEEE"); - add("B-GroupFFF"); - } - }; + Set<String> subsetOkInA = new HashSet<String>(); + subsetOkInA.add("A-GroupTwo"); + subsetOkInA.add("A-GroupThree"); + subsetOkInA.add("A-GroupFour"); + + Set<String> subsetNOkInA = new HashSet<String>(); + subsetNOkInA.add("A-GroupTwo"); + subsetNOkInA.add("NOT-IN-A"); + subsetNOkInA.add("A-GroupThree"); + subsetNOkInA.add("A-GroupFour"); + + Set<String> subsetOkInB = new HashSet<String>(); + subsetOkInB.add("B-GroupCCC"); + subsetOkInB.add("B-GroupDDD"); + subsetOkInB.add("B-GroupEEE"); + subsetOkInB.add("B-GroupFFF"); + + Set<String> subsetNOkInB = new HashSet<String>(); + subsetNOkInB.add("B-GroupCCC"); + subsetNOkInB.add("NOT-IN-B"); + subsetNOkInB.add("B-GroupEEE"); + subsetNOkInB.add("B-GroupFFF"); + + Set<String> setSpansAandBNok = new HashSet<String>(); + setSpansAandBNok.add("B-GroupCCC"); + setSpansAandBNok.add("A-GroupTwo"); + setSpansAandBNok.add("A-GroupThree"); + setSpansAandBNok.add("B-GroupEEE"); + setSpansAandBNok.add("B-GroupFFF"); boolean allExist = false; - allExist = bgManager.checkIfOneOrMoreNameExistsInContext(subsetOkInA, ctxA); + allExist = businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetOkInA, ctxA); assertTrue("Three A-Group.. should find all", allExist); // Check : one name does not exist, 3 exist - assertTrue("A 'NOT-IN-A'.. should not find all", bgManager.checkIfOneOrMoreNameExistsInContext(subsetNOkInA, ctxA)); + assertTrue("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetNOkInA, ctxA)); // Check : no name exist in context - assertFalse("A 'NOT-IN-A'.. should not find all", bgManager.checkIfOneOrMoreNameExistsInContext(subsetOkInB, ctxA)); + assertFalse("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetOkInB, ctxA)); // - allExist = bgManager.checkIfOneOrMoreNameExistsInContext(subsetOkInB, ctxB); + allExist = businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetOkInB, ctxB); assertTrue("Three B-Group.. should find all", allExist); // Check : one name does not exist, 3 exist - assertTrue("A 'NOT-IN-B'.. should not find all", bgManager.checkIfOneOrMoreNameExistsInContext(subsetNOkInB, ctxB)); + assertTrue("A 'NOT-IN-B'.. should not find all", businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetNOkInB, ctxB)); // Check : no name exist in context - assertFalse("A 'NOT-IN-A'.. should not find all", bgManager.checkIfOneOrMoreNameExistsInContext(subsetOkInA, ctxB)); + assertFalse("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetOkInA, ctxB)); // Mix A (2x) and B (3x) - allExist = bgManager.checkIfOneOrMoreNameExistsInContext(setSpansAandBNok, ctxA); + allExist = businessGroupService.checkIfOneOrMoreNameExistsInContext(setSpansAandBNok, ctxA); assertTrue("Groupnames spanning two context... should not find all in context A", allExist); // Mix A (2x) and B (3x) - allExist = bgManager.checkIfOneOrMoreNameExistsInContext(setSpansAandBNok, ctxB); + allExist = businessGroupService.checkIfOneOrMoreNameExistsInContext(setSpansAandBNok, ctxB); assertTrue("Groupnames spanning two context... should not find all in context B", allExist); // @@ -302,13 +283,12 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window /* * */ - List sqlRes; + List<BusinessGroup> sqlRes; BusinessGroup found; /* * id1 */ - BusinessGroupManagerImpl myManager = (BusinessGroupManagerImpl)BusinessGroupManagerImpl.getInstance(); - sqlRes = myManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id1, null); + sqlRes = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id1, null); assertTrue("2 BuddyGroups owned by id1", sqlRes.size() == 2); for (int i = 0; i < sqlRes.size(); i++) { assertTrue("It's a BuddyGroup Object", sqlRes.get(i) instanceof BusinessGroup); @@ -318,19 +298,19 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window assertTrue("It's the correct BuddyGroup", ok); } - sqlRes = myManager.findBusinessGroupsAttendedBy(BusinessGroup.TYPE_BUDDYGROUP, id1, null); + sqlRes = businessGroupService.findBusinessGroupsAttendedBy(BusinessGroup.TYPE_BUDDYGROUP, id1, null); assertTrue("0 BuddyGroup where id1 is partipicating", sqlRes.size() == 0); /* * id2 */ - sqlRes = myManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); + sqlRes = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); assertTrue("1 BuddyGroup owned by id2", sqlRes.size() == 1); assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); found = (BusinessGroup) sqlRes.get(0); // equality by comparing PersistenObject.getKey()!!! assertTrue("It's the correct BuddyGroup", two.getKey().longValue() == found.getKey().longValue()); - sqlRes = myManager.findBusinessGroupsAttendedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); + sqlRes = businessGroupService.findBusinessGroupsAttendedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); assertTrue("1 BuddyGroup where id2 is partipicating", sqlRes.size() == 1); assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); found = (BusinessGroup) sqlRes.get(0); @@ -339,13 +319,13 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window /* * id3 */ - sqlRes = myManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id3, null); + sqlRes = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id3, null); assertTrue("1 BuddyGroup owned by id3", sqlRes.size() == 1); assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); found = (BusinessGroup) sqlRes.get(0); // equality by comparing PersistenObject.getKey()!!! assertTrue("It's the correct BuddyGroup", three.getKey().longValue() == found.getKey().longValue()); - sqlRes = myManager.findBusinessGroupsAttendedBy(BusinessGroup.TYPE_BUDDYGROUP, id3, null); + sqlRes = businessGroupService.findBusinessGroupsAttendedBy(BusinessGroup.TYPE_BUDDYGROUP, id3, null); assertTrue("1 BuddyGroup where id3 is partipicating", sqlRes.size() == 1); assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); found = (BusinessGroup) sqlRes.get(0); @@ -354,10 +334,10 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window /* * id4 */ - sqlRes = myManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id4, null); + sqlRes = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id4, null); assertTrue("0 BuddyGroup owned by id4", sqlRes.size() == 0); // - sqlRes = myManager.findBusinessGroupsAttendedBy(BusinessGroup.TYPE_BUDDYGROUP, id4, null); + sqlRes = businessGroupService.findBusinessGroupsAttendedBy(BusinessGroup.TYPE_BUDDYGROUP, id4, null); assertTrue("1 BuddyGroup where id4 is partipicating", sqlRes.size() == 1); assertTrue("It's a BuddyGroup Object", sqlRes.get(0) instanceof BusinessGroup); found = (BusinessGroup) sqlRes.get(0); @@ -380,15 +360,13 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window /* * */ - List sqlRes; + List<BusinessGroup> sqlRes; BusinessGroup found; /* * id2 */ - BusinessGroupManagerImpl myManager = (BusinessGroupManagerImpl)BusinessGroupManagerImpl.getInstance(); - - sqlRes = myManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); + sqlRes = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); found = (BusinessGroup) sqlRes.get(0); CollaborationTools myCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(found); for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { @@ -438,14 +416,13 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window /* * */ - List sqlRes; + List<BusinessGroup> sqlRes; BusinessGroup found; /* * id2 */ - BusinessGroupManagerImpl myManager = (BusinessGroupManagerImpl)BusinessGroupManagerImpl.getInstance(); - sqlRes = myManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); + sqlRes = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); assertTrue("1 BuddyGroup owned by id2", sqlRes.size() == 1); found = (BusinessGroup) sqlRes.get(0); CollaborationTools myCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(found); @@ -456,8 +433,8 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window /* * */ - myManager.deleteBusinessGroup(found); - sqlRes = myManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); + businessGroupService.deleteBusinessGroup(found); + sqlRes = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, id2, null); assertTrue("0 BuddyGroup owned by id2", sqlRes.size() == 0); /* * @@ -476,33 +453,31 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window @Test public void testAddToWaitingListAndFireEvent() throws Exception { System.out.println("testAddToWaitingListAndFireEvent: start..."); - BusinessGroupManager myManager = BusinessGroupManagerImpl.getInstance(); - // Add wg2 BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); List<Identity> identities = new ArrayList<Identity>(); identities.add(wg2); - myManager.addToWaitingListAndFireEvent(wg2, identities, bgWithWaitingList, flags); + businessGroupService.addToWaitingList(wg2, identities, bgWithWaitingList, flags); // Add wg3 identities = new ArrayList<Identity>(); identities.add(wg3); - myManager.addToWaitingListAndFireEvent(wg3, identities, bgWithWaitingList, flags); + businessGroupService.addToWaitingList(wg3, identities, bgWithWaitingList, flags); // Add wg4 identities = new ArrayList<Identity>(); identities.add(wg4); - myManager.addToWaitingListAndFireEvent(wg4, identities, bgWithWaitingList, flags); + businessGroupService.addToWaitingList(wg4, identities, bgWithWaitingList, flags); System.out.println("testAddToWaitingListAndFireEvent: 3 user added to waiting list"); // Check position of 'wg2' - int pos = myManager.getPositionInWaitingListFor(wg2, bgWithWaitingList); + int pos = businessGroupService.getPositionInWaitingListFor(wg2, bgWithWaitingList); System.out.println("testAddToWaitingListAndFireEvent: wg2 pos=" + pos); assertTrue("pos must be 1, bit is=" + pos, pos == 1); // Check position of 'wg3' - pos = myManager.getPositionInWaitingListFor(wg3, bgWithWaitingList); + pos = businessGroupService.getPositionInWaitingListFor(wg3, bgWithWaitingList); System.out.println("testAddToWaitingListAndFireEvent wg3: pos=" + pos); assertTrue("pos must be 2, bit is=" + pos, pos == 2); // Check position of 'wg4' - pos = myManager.getPositionInWaitingListFor(wg4, bgWithWaitingList); + pos = businessGroupService.getPositionInWaitingListFor(wg4, bgWithWaitingList); System.out.println("testAddToWaitingListAndFireEvent wg4: pos=" + pos); assertTrue("pos must be 3, bit is=" + pos, pos == 3); } @@ -515,18 +490,17 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window @Test public void testRemoveFromWaitingListAndFireEvent() throws Exception { System.out.println("testRemoveFromWaitingListAndFireEvent: start..."); - BusinessGroupManager myManager = BusinessGroupManagerImpl.getInstance(); // Remove wg3 BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); List<Identity> identities = new ArrayList<Identity>(); identities.add(wg3); - myManager.removeFromWaitingListAndFireEvent(wg1, identities, bgWithWaitingList, flags); + businessGroupService.removeFromWaitingList(wg1, identities, bgWithWaitingList, flags); // Check position of 'wg2' - int pos = myManager.getPositionInWaitingListFor(wg2, bgWithWaitingList); + int pos = businessGroupService.getPositionInWaitingListFor(wg2, bgWithWaitingList); System.out.println("testRemoveFromWaitingListAndFireEvent: wg2 pos=" + pos); assertTrue("pos must be 1, bit is=" + pos, pos == 1); // Check position of 'wg4' - pos = myManager.getPositionInWaitingListFor(wg4, bgWithWaitingList); + pos = businessGroupService.getPositionInWaitingListFor(wg4, bgWithWaitingList); System.out.println("testRemoveFromWaitingListAndFireEvent wg4: pos=" + pos); assertTrue("pos must be 2, bit is=" + pos, pos == 2); @@ -541,43 +515,41 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window @Test public void testMoveIdenityFromWaitingListToParticipant() throws Exception { System.out.println("testMoveIdenityFromWaitingListToParticipant: start..."); - BusinessGroupManagerImpl myManager = (BusinessGroupManagerImpl)BusinessGroupManagerImpl.getInstance(); // Check that 'wg4' is not in participant list - assertFalse("Identity is allready in participant-list, remove it(dbsetup?)", myManager + assertFalse("Identity is allready in participant-list, remove it(dbsetup?)", businessGroupService .isIdentityInBusinessGroup(wg4, bgWithWaitingList)); // Move wg4 from waiting-list to participant BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); List<Identity> identities = new ArrayList<Identity>(); identities.add(wg4); - myManager.moveIdenityFromWaitingListToParticipant(identities, wg1, bgWithWaitingList, flags); + businessGroupService.moveIdentityFromWaitingListToParticipant(identities, wg1, bgWithWaitingList, flags); // Check position of 'wg2' - int pos = myManager.getPositionInWaitingListFor(wg2, bgWithWaitingList); + int pos = businessGroupService.getPositionInWaitingListFor(wg2, bgWithWaitingList); System.out.println("testMoveIdenityFromWaitingListToParticipant: wg2 pos=" + pos); assertTrue("pos must be 1, bit is=" + pos, pos == 1); // Check if 'wg4' is in participant-list - assertTrue("Identity is not in participant-list", myManager.isIdentityInBusinessGroup(wg4, bgWithWaitingList)); + assertTrue("Identity is not in participant-list", businessGroupService.isIdentityInBusinessGroup(wg4, bgWithWaitingList)); } @Test public void testMoveRegisteredIdentityFromWaitingToParticipant() throws Exception { System.out.println("testMoveRegisteredIdentityFromWaitingToParticipant: start..."); - BusinessGroupManagerImpl myManager = (BusinessGroupManagerImpl)BusinessGroupManagerImpl.getInstance(); // Add a user to waiting-list which is allready in participant-list and try // and try to move this user => user will be removed from waiting-list // Add again wg2 BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); List<Identity> identities = new ArrayList<Identity>(); identities.add(wg1); - myManager.addToWaitingListAndFireEvent(wg4, identities, bgWithWaitingList, flags); + businessGroupService.addToWaitingList(wg4, identities, bgWithWaitingList, flags); identities = new ArrayList<Identity>(); identities.add(wg4); - myManager.moveIdenityFromWaitingListToParticipant(identities, wg1, bgWithWaitingList, flags); + businessGroupService.moveIdentityFromWaitingListToParticipant(identities, wg1, bgWithWaitingList, flags); // Check position of 'wg4' - int pos = myManager.getPositionInWaitingListFor(wg4, bgWithWaitingList); + int pos = businessGroupService.getPositionInWaitingListFor(wg4, bgWithWaitingList); System.out.println("testMoveIdenityFromWaitingListToParticipant: wg4 pos=" + pos); assertTrue("pos must be 0, bit is=" + pos, pos == 0); // Check if 'wg4' is still in participant-list - assertTrue("Identity is not in participant-list", myManager.isIdentityInBusinessGroup(wg4, bgWithWaitingList)); + assertTrue("Identity is not in participant-list", businessGroupService.isIdentityInBusinessGroup(wg4, bgWithWaitingList)); } @Test public void testDeleteBusinessGroupWithWaitingGroup() { @@ -588,11 +560,10 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window doTestDeleteBusinessGroup(false); } private void doTestDeleteBusinessGroup(boolean withWaitingList) { - BGContextManagerImpl bgcm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BGContext groupContext = bgcm.createAndPersistBGContext("c1delete", "c1delete", BusinessGroup.TYPE_LEARNINGROUP, null, true); + OLATResource resource = JunitTestHelper.createRandomResource(); - BusinessGroup deleteTestGroup = BusinessGroupManagerImpl.getInstance().createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, id1, "deleteTestGroup-1", - "deleteTestGroup-1", null, null, withWaitingList, true, groupContext); + BusinessGroup deleteTestGroup = businessGroupService.createBusinessGroup(id1, "deleteTestGroup-1", + "deleteTestGroup-1", BusinessGroup.TYPE_LEARNINGROUP, -1, -1, withWaitingList, true, resource); Long ownerGroupKey = deleteTestGroup.getOwnerGroup().getKey(); Long partipiciantGroupKey = deleteTestGroup.getPartipiciantGroup().getKey(); @@ -601,7 +572,7 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window assertNotNull("Could not find owner-group",DBFactory.getInstance().findObject(SecurityGroupImpl.class, ownerGroupKey)); assertNotNull("Could not find partipiciant-group",DBFactory.getInstance().findObject(SecurityGroupImpl.class, partipiciantGroupKey)); assertNotNull("Could not find waiting-group",DBFactory.getInstance().findObject(SecurityGroupImpl.class, waitingGroupKey)); - BusinessGroupManagerImpl.getInstance().deleteBusinessGroup(deleteTestGroup); + businessGroupService.deleteBusinessGroup(deleteTestGroup); assertNull("owner-group still exist after delete",DBFactory.getInstance().findObject(SecurityGroupImpl.class, ownerGroupKey)); assertNull("partipiciant-group still exist after delete",DBFactory.getInstance().findObject(SecurityGroupImpl.class, partipiciantGroupKey)); assertNull("waiting-group still exist after delete",DBFactory.getInstance().findObject(SecurityGroupImpl.class, waitingGroupKey)); @@ -625,22 +596,18 @@ public class BusinessGroupManagerImplTest extends OlatTestCase implements Window // Helper methods // /////////////// - private void setupWaitingList(BusinessGroupManagerImpl bgManager) { + private void setupWaitingList(BusinessGroupService bgManager) { if (bgManager.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_LEARNINGROUP, id1, null).size() == 0) { // create business-group with waiting-list String bgWithWaitingListName = "Group with WaitingList"; String bgWithWaitingListDesc = "some short description for Group with WaitingList"; Boolean enableWaitinglist = new Boolean(true); Boolean enableAutoCloseRanks = new Boolean(true); - BGContextManagerImpl bgcm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BGContext groupContext = bgcm.createAndPersistBGContext("c1name", "c1desc", BusinessGroup.TYPE_LEARNINGROUP, null, true); - System.out.println("testAddToWaitingListAndFireEvent: groupContext=" + groupContext); - bgWithWaitingList = bgManager.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, id1, bgWithWaitingListName, - bgWithWaitingListDesc, null, null, enableWaitinglist, enableAutoCloseRanks, groupContext); + OLATResource resource = JunitTestHelper.createRandomResource(); + System.out.println("testAddToWaitingListAndFireEvent: resource=" + resource); + bgWithWaitingList = businessGroupService.createBusinessGroup(id1, bgWithWaitingListName, + bgWithWaitingListDesc, BusinessGroup.TYPE_LEARNINGROUP, -1, -1, enableWaitinglist, enableAutoCloseRanks, resource); bgWithWaitingList.setMaxParticipants(new Integer(2)); - // create mock objects - String PACKAGE = Util.getPackageName(BusinessGroupManagerImplTest.class); - testTranslator = new PackageTranslator(PACKAGE, new Locale("de")); // Identities User UserWg1 = UserManager.getInstance().createAndPersistUser("FirstName_wg1", "LastName_wg1", "wg1_junittest@olat.unizh.ch"); wg1 = BaseSecurityManager.getInstance().createAndPersistIdentity("wg1", UserWg1, diff --git a/src/test/java/org/olat/group/BusinessGroupTest.java b/src/test/java/org/olat/group/BusinessGroupTest.java index b46cbb5976e..6fa73d9b859 100644 --- a/src/test/java/org/olat/group/BusinessGroupTest.java +++ b/src/test/java/org/olat/group/BusinessGroupTest.java @@ -26,7 +26,6 @@ package org.olat.group; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -50,9 +49,7 @@ import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.logging.AssertException; import org.olat.core.util.resource.OresHelper; -import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.groupsandrights.CourseRights; -import org.olat.course.groupsandrights.PersistingCourseGroupManager; import org.olat.group.context.BGContext; import org.olat.group.context.BGContextManagerImpl; import org.olat.group.right.BGRightManager; @@ -402,80 +399,34 @@ public class BusinessGroupTest extends OlatTestCase { /** BGContextManagerImpl:getGroupsOfBGContext and countGroupsOfBGContext* */ @Test public void testGroupsOfBGContext() { - BGContextManagerImpl bgcm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); - BGContext c1 = bgcm.createAndPersistBGContext("c1name4", "c1desc", BusinessGroup.TYPE_LEARNINGROUP, null, true); - BGContext c2 = bgcm.createAndPersistBGContext("c2name4", "c2desc", BusinessGroup.TYPE_LEARNINGROUP, id1, false); + OLATResource c1 = JunitTestHelper.createRandomResource(); + OLATResource c2 = JunitTestHelper.createRandomResource(); DBFactory.getInstance().closeSession(); // simulate user clicks - assertTrue(bgcm.getGroupsOfBGContext(c1).size() == 0); - assertTrue(bgcm.countGroupsOfBGContext(c1) == 0); + assertTrue(businessGroupService.findBusinessGroups(null, null, false, false, c1, 0, -1).isEmpty()); + assertTrue(businessGroupService.countBusinessGroups(null, null, false, false, c1) == 0); DBFactory.getInstance().closeSession(); // simulate user clicks - BusinessGroup g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g1", null, new Integer(0), + BusinessGroup g1 = businessGroupService.createBusinessGroup(null, "g1", null, BusinessGroup.TYPE_LEARNINGROUP, new Integer(0), new Integer(10), false, false, c1); assertNotNull(g1); - BusinessGroup g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g2", null, new Integer(0), + BusinessGroup g2 = businessGroupService.createBusinessGroup(null, "g2", null, BusinessGroup.TYPE_LEARNINGROUP, new Integer(0), new Integer(10), false, false, c1); assertNotNull(g2); - BusinessGroup g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g3", null, new Integer(0), + BusinessGroup g3 = businessGroupService.createBusinessGroup(null, "g3", null, BusinessGroup.TYPE_LEARNINGROUP, new Integer(0), new Integer(10), false, false, c2); assertNotNull(g3); - BusinessGroup g2douplicate = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g2", null, new Integer(0), + BusinessGroup g2douplicate = businessGroupService.createBusinessGroup(null, "g2", null, BusinessGroup.TYPE_LEARNINGROUP, new Integer(0), new Integer(10), false, false, c1); assertNull(g2douplicate); // name douplicate names allowed per group context - BusinessGroup g4 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "g2", null, new Integer(0), + BusinessGroup g4 = businessGroupService.createBusinessGroup(null, "g2", null, BusinessGroup.TYPE_LEARNINGROUP, new Integer(0), new Integer(10), false, false, c2); assertNotNull(g4); // name douplicate in other context allowed DBFactory.getInstance().closeSession(); // simulate user clicks - assertTrue(bgcm.getGroupsOfBGContext(c1).size() == 2); - assertTrue(bgcm.countGroupsOfBGContext(c1) == 2); - } - - /** BGContext2ResourceManager tests */ - @Test - public void testFindContextMethods() { - BGContextManagerImpl cm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BGContext c1 = cm.createAndAddBGContextToResource("c1name5", course1, BusinessGroup.TYPE_LEARNINGROUP, null, true); - cm.createAndAddBGContextToResource("c2name5", course1, BusinessGroup.TYPE_LEARNINGROUP, id4, false); - cm.createAndAddBGContextToResource("c3name5", course1, BusinessGroup.TYPE_RIGHTGROUP, id2, false); - - DBFactory.getInstance().closeSession(); // simulate user clicks - assertTrue(cm.findBGContextsForResource(course1, true, true).size() == 3); - assertTrue(cm.findBGContextsForResource(course1, true, false).size() == 1); - assertTrue(cm.findBGContextsForResource(course1, false, true).size() == 2); - assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_LEARNINGROUP, true, true).size() == 2); - assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_RIGHTGROUP, true, true).size() == 1); - - assertTrue(cm.findBGContextsForIdentity(id4, true, true).size() == 1); - assertTrue(cm.findBGContextsForIdentity(id4, true, false).size() == 0); - assertTrue(cm.findBGContextsForIdentity(id4, false, true).size() == 1); - - DBFactory.getInstance().closeSession(); // simulate user clicks - cm.removeBGContextFromResource(c1, course1); - assertTrue(cm.findBGContextsForResource(course1, true, true).size() == 2); - assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_LEARNINGROUP, true, true).size() == 1); - assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_RIGHTGROUP, true, true).size() == 1); - - DBFactory.getInstance().closeSession(); // simulate user clicks - // cm.removeAllBGContextsFromResource(course1); - CourseGroupManager cgm = PersistingCourseGroupManager.getInstance(course1); - cgm.deleteCourseGroupmanagement(); - assertTrue(cm.findBGContextsForResource(course1, true, true).size() == 0); - assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_LEARNINGROUP, true, true).size() == 0); - assertTrue(cm.findBGContextsForResource(course1, BusinessGroup.TYPE_RIGHTGROUP, true, true).size() == 0); + assertTrue(businessGroupService.findBusinessGroups(null, null, false, false, c1, 0, -1).size() == 2); + assertTrue(businessGroupService.countBusinessGroups(null, null, false, false, c1) == 2); } - - @Test - public void testRemoveBGFromArea() { - BGContextManagerImpl cm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BGContext bgContext = cm.createAndAddBGContextToResource("c2name6", course1, BusinessGroup.TYPE_LEARNINGROUP, null, true); - assertEquals( 1,cm.findBGContextsForResource(course1, true, true).size() ); - cm.removeBGContextFromResource(bgContext, course1); - assertEquals( 0,cm.findBGContextsForResource(course1, true, true).size() ); - } - } \ No newline at end of file diff --git a/src/test/java/org/olat/properties/PropertyTest.java b/src/test/java/org/olat/properties/PropertyTest.java index 3b5d18d4860..2eb8577c66a 100644 --- a/src/test/java/org/olat/properties/PropertyTest.java +++ b/src/test/java/org/olat/properties/PropertyTest.java @@ -37,18 +37,16 @@ import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.logging.Tracing; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; import org.olat.resource.OLATResourceManager; import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; +import org.springframework.beans.factory.annotation.Autowired; /** * Initial Date: Mar 11, 2004 @@ -67,6 +65,9 @@ public class PropertyTest extends OlatTestCase implements OLATResourceable { private static BusinessGroup group = null; private static org.olat.resource.OLATResource res = null; private static PropertyManager pm; + + @Autowired + private BusinessGroupService businessGroupService; /** @@ -86,12 +87,10 @@ public class PropertyTest extends OlatTestCase implements OLATResourceable { res = OLATResourceManager.getInstance().createOLATResourceInstance(this); OLATResourceManager.getInstance().saveOLATResource(res); } - BusinessGroupManager gm = BusinessGroupManagerImpl.getInstance(); - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); - List<BusinessGroup> l = bgs.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, identity, null); + + List<BusinessGroup> l = businessGroupService.findBusinessGroupsOwnedBy(BusinessGroup.TYPE_BUDDYGROUP, identity, null); if (l.size() == 0) { - group = gm.createAndPersistBusinessGroup(BusinessGroup.TYPE_BUDDYGROUP, - identity, "a buddygroup", "a desc", null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, null); + group = businessGroupService.createBusinessGroup(identity, "a buddygroup", "a desc", BusinessGroup.TYPE_BUDDYGROUP, -1, -1, false, false, null); } else { group = (BusinessGroup) l.get(0); } diff --git a/src/test/java/org/olat/restapi/ContactsTest.java b/src/test/java/org/olat/restapi/ContactsTest.java index 184cd7d2832..e45e9803fb3 100644 --- a/src/test/java/org/olat/restapi/ContactsTest.java +++ b/src/test/java/org/olat/restapi/ContactsTest.java @@ -45,12 +45,7 @@ import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; import org.olat.core.util.resource.OresHelper; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; import org.olat.group.properties.BusinessGroupPropertyManager; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; @@ -119,15 +114,13 @@ public class ContactsTest extends OlatJerseyTestCase { DBFactory.getInstance().intermediateCommit(); //create learn group - BGContextManagerImpl cm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); BaseSecurity secm = BaseSecurityManager.getInstance(); // 1) context one: learning groups - BGContext c1 = cm.createAndAddBGContextToResource("c1name-learn", course, BusinessGroup.TYPE_LEARNINGROUP, owner1, true); + OLATResource c1 = null;//TODO gm cm.createAndAddBGContextToResource("c1name-learn", course, BusinessGroup.TYPE_LEARNINGROUP, owner1, true); // create groups without waiting list - g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "rest-g1", null, new Integer(0), new Integer(10), false, false, c1); - g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "rest-g2", null, new Integer(0), new Integer(10), false, false, c1); + g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, BusinessGroup.TYPE_LEARNINGROUP, new Integer(0), new Integer(10), false, false, c1); + g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, BusinessGroup.TYPE_LEARNINGROUP, new Integer(0), new Integer(10), false, false, c1); //permission to see owners and participants BusinessGroupPropertyManager bgpm1 = new BusinessGroupPropertyManager(g1); @@ -147,10 +140,10 @@ public class ContactsTest extends OlatJerseyTestCase { // 2) context two: right groups - BGContext c2 = cm.createAndAddBGContextToResource("c2name-area", course, BusinessGroup.TYPE_RIGHTGROUP, owner2, true); + OLATResource c2 = null;//TODO gm cm.createAndAddBGContextToResource("c2name-area", course, BusinessGroup.TYPE_RIGHTGROUP, owner2, true); // groups - g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "rest-g3", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); - g4 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "rest-g4", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); + g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); + g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); // members -> default participants are visible secm.addIdentityToSecurityGroup(owner1, g3.getPartipiciantGroup()); secm.addIdentityToSecurityGroup(part3, g3.getPartipiciantGroup()); diff --git a/src/test/java/org/olat/restapi/CourseGroupMgmtTest.java b/src/test/java/org/olat/restapi/CourseGroupMgmtTest.java index aad1692dcbb..cd40c594662 100644 --- a/src/test/java/org/olat/restapi/CourseGroupMgmtTest.java +++ b/src/test/java/org/olat/restapi/CourseGroupMgmtTest.java @@ -60,12 +60,7 @@ import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.util.resource.OresHelper; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; import org.olat.resource.OLATResource; import org.olat.resource.OLATResourceManager; import org.olat.restapi.support.vo.GroupVO; @@ -121,16 +116,13 @@ public class CourseGroupMgmtTest extends OlatJerseyTestCase { DBFactory.getInstance().closeSession(); //create learn group - - BGContextManagerImpl cm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); BaseSecurity secm = BaseSecurityManager.getInstance(); // 1) context one: learning groups - BGContext c1 = cm.createAndAddBGContextToResource("c1name-learn", course, BusinessGroup.TYPE_LEARNINGROUP, id1, true); + OLATResource c1 = JunitTestHelper.createRandomResource(); // create groups without waiting list - g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "rest-g1", null, new Integer(0), new Integer(10), false, false, c1); - g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "rest-g2", null, new Integer(0), new Integer(10), false, false, c1); + g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, BusinessGroup.TYPE_LEARNINGROUP, 0, 10, false, false, c1); + g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, BusinessGroup.TYPE_LEARNINGROUP, 0, 10, false, false, c1); // members secm.addIdentityToSecurityGroup(id1, g2.getOwnerGroup()); secm.addIdentityToSecurityGroup(id1, g1.getPartipiciantGroup()); @@ -139,10 +131,10 @@ public class CourseGroupMgmtTest extends OlatJerseyTestCase { // 2) context two: right groups - BGContext c2 = cm.createAndAddBGContextToResource("c2name-area", course, BusinessGroup.TYPE_RIGHTGROUP, id2, true); + OLATResource c2 = JunitTestHelper.createRandomResource(); // groups - g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "rest-g3", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); - g4 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "rest-g4", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); + g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); + g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); // members secm.addIdentityToSecurityGroup(id1, g3.getPartipiciantGroup()); secm.addIdentityToSecurityGroup(id2, g4.getPartipiciantGroup()); diff --git a/src/test/java/org/olat/restapi/GroupFoldersTest.java b/src/test/java/org/olat/restapi/GroupFoldersTest.java index 1c9254ba515..37311683f39 100644 --- a/src/test/java/org/olat/restapi/GroupFoldersTest.java +++ b/src/test/java/org/olat/restapi/GroupFoldersTest.java @@ -67,10 +67,7 @@ import org.olat.core.util.resource.OresHelper; import org.olat.core.util.vfs.VFSContainer; import org.olat.core.util.vfs.VFSLeaf; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManagerImpl; +import org.olat.group.BusinessGroupService; import org.olat.group.properties.BusinessGroupPropertyManager; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; @@ -79,6 +76,7 @@ import org.olat.resource.OLATResourceManager; import org.olat.restapi.support.vo.FileVO; import org.olat.test.JunitTestHelper; import org.olat.test.OlatJerseyTestCase; +import org.springframework.beans.factory.annotation.Autowired; /** * @@ -96,6 +94,9 @@ public class GroupFoldersTest extends OlatJerseyTestCase { private OLATResource course; private RestConnection conn; + @Autowired + private BusinessGroupService businessGroupService; + /** * Set up a course with learn group and group area * EXACTLY THE SAME AS GroupMgmTest @@ -144,15 +145,13 @@ public class GroupFoldersTest extends OlatJerseyTestCase { DBFactory.getInstance().intermediateCommit(); //create learn group - BGContextManagerImpl cm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); BaseSecurity secm = BaseSecurityManager.getInstance(); // 1) context one: learning groups - BGContext c1 = cm.createAndAddBGContextToResource("c1name-learn", course, BusinessGroup.TYPE_LEARNINGROUP, owner1, true); + OLATResource c1 = JunitTestHelper.createRandomResource(); // create groups without waiting list - g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "rest-g1", null, new Integer(0), new Integer(10), false, false, c1); - g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "rest-g2", null, new Integer(0), new Integer(10), false, false, c1); + g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, BusinessGroup.TYPE_LEARNINGROUP, 0, 10, false, false, c1); + g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, BusinessGroup.TYPE_LEARNINGROUP, 0, 10, false, false, c1); //permission to see owners and participants BusinessGroupPropertyManager bgpm1 = new BusinessGroupPropertyManager(g1); diff --git a/src/test/java/org/olat/restapi/GroupMgmtTest.java b/src/test/java/org/olat/restapi/GroupMgmtTest.java index bfa14097f7b..99bb0396d8b 100644 --- a/src/test/java/org/olat/restapi/GroupMgmtTest.java +++ b/src/test/java/org/olat/restapi/GroupMgmtTest.java @@ -66,12 +66,7 @@ import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.util.resource.OresHelper; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManager; -import org.olat.group.context.BGContextManagerImpl; import org.olat.group.properties.BusinessGroupPropertyManager; import org.olat.modules.fo.Forum; import org.olat.modules.fo.ForumManager; @@ -162,16 +157,13 @@ public class GroupMgmtTest extends OlatJerseyTestCase { DBFactory.getInstance().intermediateCommit(); //create learn group - - BGContextManagerImpl cm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); BaseSecurity secm = BaseSecurityManager.getInstance(); // 1) context one: learning groups - BGContext c1 = cm.createAndAddBGContextToResource("c1name-learn", course, BusinessGroup.TYPE_LEARNINGROUP, owner1, true); + OLATResource c1 = JunitTestHelper.createRandomResource(); // create groups without waiting list - g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "rest-g1", null, new Integer(0), new Integer(10), false, false, c1); - g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "rest-g2", null, new Integer(0), new Integer(10), false, false, c1); + g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, BusinessGroup.TYPE_LEARNINGROUP, 0, 10, false, false, c1); + g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, BusinessGroup.TYPE_LEARNINGROUP, 0, 10, false, false, c1); //permission to see owners and participants BusinessGroupPropertyManager bgpm1 = new BusinessGroupPropertyManager(g1); @@ -191,10 +183,10 @@ public class GroupMgmtTest extends OlatJerseyTestCase { // 2) context two: right groups - BGContext c2 = cm.createAndAddBGContextToResource("c2name-area", course, BusinessGroup.TYPE_RIGHTGROUP, owner2, true); + OLATResource c2 = JunitTestHelper.createRandomResource(); // groups - g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "rest-g3", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); - g4 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "rest-g4", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); + g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); + g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); // members secm.addIdentityToSecurityGroup(owner1, g3.getPartipiciantGroup()); secm.addIdentityToSecurityGroup(owner2, g4.getPartipiciantGroup()); diff --git a/src/test/java/org/olat/restapi/UserMgmtTest.java b/src/test/java/org/olat/restapi/UserMgmtTest.java index 05f1310a531..2fb1f3a528b 100644 --- a/src/test/java/org/olat/restapi/UserMgmtTest.java +++ b/src/test/java/org/olat/restapi/UserMgmtTest.java @@ -84,11 +84,7 @@ import org.olat.course.ICourse; import org.olat.course.nodes.BCCourseNode; import org.olat.course.nodes.FOCourseNode; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupManager; -import org.olat.group.BusinessGroupManagerImpl; import org.olat.group.BusinessGroupService; -import org.olat.group.context.BGContext; -import org.olat.group.context.BGContextManagerImpl; import org.olat.modules.fo.Forum; import org.olat.modules.fo.ForumManager; import org.olat.modules.fo.Message; @@ -175,16 +171,13 @@ public class UserMgmtTest extends OlatJerseyTestCase { DBFactory.getInstance().intermediateCommit(); //create learn group - - BGContextManagerImpl cm = (BGContextManagerImpl)BGContextManagerImpl.getInstance(); - BusinessGroupManager bgm = BusinessGroupManagerImpl.getInstance(); BaseSecurity secm = BaseSecurityManager.getInstance(); // 1) context one: learning groups - BGContext c1 = cm.createAndAddBGContextToResource("c1name-learn", course, BusinessGroup.TYPE_LEARNINGROUP, owner1, true); + OLATResource c1 = JunitTestHelper.createRandomResource(); // create groups without waiting list - g1 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "user-rest-g1", null, new Integer(0), new Integer(10), false, false, c1); - g2 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_LEARNINGROUP, null, "user-rest-g2", null, new Integer(0), new Integer(10), false, false, c1); + g1 = businessGroupService.createBusinessGroup(null, "user-rest-g1", null, BusinessGroup.TYPE_LEARNINGROUP, 0, 10, false, false, c1); + g2 = businessGroupService.createBusinessGroup(null, "user-rest-g2", null, BusinessGroup.TYPE_LEARNINGROUP, 0, 10, false, false, c1); // members g1 secm.addIdentityToSecurityGroup(id1, g1.getOwnerGroup()); secm.addIdentityToSecurityGroup(id2, g1.getPartipiciantGroup()); @@ -193,10 +186,10 @@ public class UserMgmtTest extends OlatJerseyTestCase { secm.addIdentityToSecurityGroup(id1, g2.getPartipiciantGroup()); // 2) context two: right groups - BGContext c2 = cm.createAndAddBGContextToResource("c2name-area", course, BusinessGroup.TYPE_RIGHTGROUP, owner1, true); + OLATResource c2 = JunitTestHelper.createRandomResource(); // groups - g3 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "user-rest-g3", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); - g4 = bgm.createAndPersistBusinessGroup(BusinessGroup.TYPE_RIGHTGROUP, null, "user-rest-g4", null, null, null, null/* enableWaitinglist */, null/* enableAutoCloseRanks */, c2); + g3 = businessGroupService.createBusinessGroup(null, "user-rest-g3", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); + g4 = businessGroupService.createBusinessGroup(null, "user-rest-g4", null, BusinessGroup.TYPE_RIGHTGROUP, -1, -1, false, false, c2); // members secm.addIdentityToSecurityGroup(id1, g3.getPartipiciantGroup()); secm.addIdentityToSecurityGroup(id2, g4.getPartipiciantGroup()); diff --git a/src/test/java/org/olat/test/JunitTestHelper.java b/src/test/java/org/olat/test/JunitTestHelper.java index cf06cd8f7a6..eb19555cb71 100644 --- a/src/test/java/org/olat/test/JunitTestHelper.java +++ b/src/test/java/org/olat/test/JunitTestHelper.java @@ -29,6 +29,7 @@ package org.olat.test; import java.util.List; +import java.util.UUID; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurityManager; @@ -36,14 +37,18 @@ import org.olat.basesecurity.BaseSecurityModule; import org.olat.basesecurity.Constants; import org.olat.basesecurity.SecurityGroup; import org.olat.core.id.Identity; +import org.olat.core.id.OLATResourceable; import org.olat.core.id.User; import org.olat.core.util.Encoder; +import org.olat.core.util.resource.OresHelper; import org.olat.course.CourseFactory; import org.olat.course.DeployableCourseExport; import org.olat.properties.Property; import org.olat.properties.PropertyManager; import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; +import org.olat.resource.OLATResource; +import org.olat.resource.OLATResourceManager; import org.olat.user.UserManager; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -66,6 +71,14 @@ public class JunitTestHelper { maildomain = "mytrashmail.com"; } } + + public static final OLATResource createRandomResource() { + String resName = UUID.randomUUID().toString().replace("-", ""); + OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, 0l); + OLATResource resource = OLATResourceManager.getInstance().createOLATResourceInstance(ores); + OLATResourceManager.getInstance().saveOLATResource(resource); + return resource; + } /** * Create an identity with user permissions @@ -121,18 +134,6 @@ public class JunitTestHelper { return identity; } - /** - * Remove identity from <code>Constants.GROUP_OLATUSERS</code> group. - * @param identity - */ - /*public static void deleteIdentityFromUsersGroup(Identity identity) { - Manager securityManager = ManagerFactory.getManager(); - SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS); - if (group != null) { - securityManager.removeIdentityFromSecurityGroup(identity, group); - } - }*/ - /** * Deploys/imports the "Demo Course". * @return the created RepositoryEntry -- GitLab