diff --git a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java index b72b57e64525a5375d156ce1e96facdbdbe5eefa..09ea736d7ae8687a91b6ae26612f03a4383592ce 100644 --- a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java +++ b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java @@ -958,6 +958,7 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity { String q = "select count(sgm) from org.olat.basesecurity.SecurityGroupMembershipImpl sgm where sgm.securityGroup = :group"; DBQuery query = db.createQuery(q); query.setEntity("group", secGroup); + query.setCacheable(true); int result = ((Long) query.list().get(0)).intValue(); return result; } diff --git a/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java b/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java index 0aaa0df08a60e24b48d42eeae9f90cc73a2a4ffa..50712858ed898fb201eb9929044ef27ca0cc396e 100644 --- a/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java +++ b/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java @@ -132,7 +132,6 @@ public interface CourseGroupManager { * @return A list of all learning groups with the given group name from all * contexts of this course */ - //TODO gm why is it needed? public List<BusinessGroup> getBusinessGroups(String groupName); public boolean existGroup(String nameOrKey); diff --git a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java index ce40c920ed2e0a77fe8229020dbc36ce19b05dc4..c28156290189e6ad1849429f03491a2de4193838 100644 --- a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java +++ b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java @@ -340,21 +340,8 @@ public class PersistingCourseGroupManager extends BasicManager implements Course * @see org.olat.course.groupsandrights.CourseGroupManager#deleteCourseGroupmanagement() */ public void deleteCourseGroupmanagement() { - // contextManager.removeAllBGContextsFromResource(courseResource); //TODO gm - /* - List allContexts = contextManager.findBGContextsForResource(courseResource, true, true); - Iterator iter = allContexts.iterator(); - while (iter.hasNext()) { - BGContext context = (BGContext) iter.next(); - if (context.isDefaultContext()) { - contextManager.deleteBGContext(context); - } else { - // not a default context, only unlink from this course - contextManager.removeBGContextFromResource(context, courseResource); - } - } - */ + //delete something??? logAudit("Deleting course groupmanagement for " + courseResource.toString()); } diff --git a/src/main/java/org/olat/course/groupsandrights/ui/DefaultContextTranslationHelper.java b/src/main/java/org/olat/course/groupsandrights/ui/DefaultContextTranslationHelper.java deleted file mode 100644 index d471c9283e48170bc21b837f175d277c932394e5..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/course/groupsandrights/ui/DefaultContextTranslationHelper.java +++ /dev/null @@ -1,60 +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.course.groupsandrights.ui; - -import org.olat.core.gui.translator.Translator; -import org.olat.course.groupsandrights.CourseGroupManager; -import org.olat.group.context.BGContext; - -/** - * Description:<BR/> - * TODO: Class Description for DefaultContextTranslationHelper - * Initial Date: Mar 10, 2005 - * - * @author gnaegi - */ -public class DefaultContextTranslationHelper { - - /** - * Returns a nicly translated name for the default context. If it is not a default context, - * nothing will be done and the contexts name will be returned - * @param context - * @param trans - * @return String - */ - public static String translateIfDefaultContextName(BGContext context, Translator trans) { - String name = context.getName(); - if (name.indexOf(CourseGroupManager.DEFAULT_NAME_LC_PREFIX) == 0) { - name = trans.translate("default.context") + " " - + name.substring(CourseGroupManager.DEFAULT_NAME_LC_PREFIX.length()); - } else if (name.indexOf(CourseGroupManager.DEFAULT_NAME_RC_PREFIX) == 0) { - name = trans.translate("default.context") + " " - + name.substring(CourseGroupManager.DEFAULT_NAME_RC_PREFIX.length()); - } - return name; - } - -} diff --git a/src/main/java/org/olat/course/groupsandrights/ui/GroupAndAreaSelectController.java b/src/main/java/org/olat/course/groupsandrights/ui/GroupAndAreaSelectController.java deleted file mode 100644 index 6f2018b66d95d374e940cc0b775be650107e1872..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/course/groupsandrights/ui/GroupAndAreaSelectController.java +++ /dev/null @@ -1,194 +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.course.groupsandrights.ui; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.olat.core.gui.UserRequest; -import org.olat.core.gui.components.Component; -import org.olat.core.gui.components.choice.Choice; -import org.olat.core.gui.components.velocity.VelocityContainer; -import org.olat.core.gui.control.DefaultController; -import org.olat.core.gui.control.Event; -import org.olat.core.gui.control.WindowControl; -import org.olat.core.gui.translator.PackageTranslator; -import org.olat.core.gui.translator.Translator; -import org.olat.core.logging.OLATRuntimeException; -import org.olat.core.util.Util; -import org.olat.course.groupsandrights.CourseGroupManager; - -/** - * Description:<BR/> - * Controller to handle a popup business group or business group area selection - * as a checkbox list. After selecting the items, the values will be put - * together to a comma separated string and written to the original window - * via javascript. - * - * Initial Date: Oct 5, 2004 - * - * @author gnaegi - */ -public class GroupAndAreaSelectController extends DefaultController { - private static final String PACKAGE = Util.getPackageName(GroupAndAreaSelectController.class); - private static final String VELOCITY_ROOT = Util.getPackageVelocityRoot(PACKAGE); - - /** Configuration flag: use strings for business groups */ - public static final int TYPE_GROUP = 1; - /** Configuration flag: use strings for business group areas */ - public static final int TYPE_AREA = 2; - - private StringListTableDataModel stringModel; - private VelocityContainer main; - private Choice stringChoice; - private String htmlElemId; - - /** - * @param ureq The user request - * @param cgm The course group manager - * @param type The choice type: group or area (use controller public constants) - * @param preselectedNames String containing the comma separated names that should be preselected - * @param htmlElemId the name of the html id of the window that opened this popup controller - */ - public GroupAndAreaSelectController(UserRequest ureq, WindowControl wControl, CourseGroupManager cgm, int type, String preselectedNames, String htmlElemId) { - super(wControl); - Translator trans = new PackageTranslator(PACKAGE, ureq.getLocale()); - List namesList; - this.htmlElemId = htmlElemId; - // main window containg title and the cooser list - main = new VelocityContainer("main",VELOCITY_ROOT + "/groupandareaselect.html", trans, this); - - // initialize some type specific stuff - switch (type) { - case 1: - namesList = cgm.getUniqueBusinessGroupNames(); - main.contextPut("title", trans.translate("groupandareaselect.groups.title")); - main.contextPut("noChoicesText", trans.translate("groupandareaselect.groups.nodata")); - break; - case 2: - namesList = cgm.getUniqueAreaNames(); - main.contextPut("title", trans.translate("groupandareaselect.areas.title")); - main.contextPut("noChoicesText", trans.translate("groupandareaselect.areas.nodata")); - break; - default: - throw new OLATRuntimeException("Must use valid type. type::" + type, null); - } - - // get preselected List from the comma separated string - List preselectedNamesList; - if (preselectedNames == null) { - preselectedNamesList = new ArrayList(); - } - else { - preselectedNamesList = stringToList(preselectedNames); - } - - if (namesList.size() > 0) { - stringModel = new StringListTableDataModel(namesList, preselectedNamesList); - stringChoice = new Choice("stringChoice", trans); - stringChoice.setSubmitKey("select"); - stringChoice.setCancelKey("cancel"); - stringChoice.setTableDataModel(stringModel); - stringChoice.addListener(this); - main.put("stringChoice", stringChoice); - main.contextPut("hasChoices", Boolean.TRUE); - } - else { - main.contextPut("hasChoices", Boolean.FALSE); - } - setInitialComponent(main); - } - - /** - * @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) - */ - public void event(UserRequest ureq, Component source, Event event) { - if (source == stringChoice) { - if (event == Choice.EVNT_FORM_CANCELLED) { - main.setPage(VELOCITY_ROOT+ "/cancelled.html"); - } - else { - List selectedList = stringChoice.getSelectedRows(); - List selectedEntries = new ArrayList(); - for (Iterator iter = selectedList.iterator(); iter.hasNext();) { - Integer sel = (Integer) iter.next(); - String obj = stringModel.getString(sel.intValue()); - selectedEntries.add(obj); - } - String selectedString = listToString(selectedEntries); - main.setPage(VELOCITY_ROOT+ "/closing.html"); - main.contextPut("var", htmlElemId); - main.contextPut("val", selectedString); - } - } - } - - - /** - * Converts a list of strings to a comma separated string - * @param myList - * @return String - */ - private String listToString(List myList) { - boolean first = true; - StringBuilder sb = new StringBuilder(); - Iterator iterator = myList.iterator(); - while (iterator.hasNext()) { - String name = (String) iterator.next(); - if (!first) { - sb.append(","); - } - else { - first = false; - } - sb.append(name); - } - return sb.toString(); - } - - /** - * Converts a coma separated string to a list containing the strings - * @param s the comma separated string - * @return the List of strings - */ - private List stringToList(String s) { - String[] sArray = s.split(","); - List result = new ArrayList(); - for (int i = 0; i < sArray.length; i++) { - result.add(sArray[i].trim()); - } - return result; - } - - /** - * @see org.olat.core.gui.control.DefaultController#doDispose(boolean) - */ - protected void doDispose() { - // nothing to dispose - } - -} diff --git a/src/main/java/org/olat/course/nodes/co/COEditController.java b/src/main/java/org/olat/course/nodes/co/COEditController.java index 2bed2ea9897f26a46dd254f1db2797889e2944d9..9ecbeaf16cbaedaf997f4fe742c5ce3334a17f85 100644 --- a/src/main/java/org/olat/course/nodes/co/COEditController.java +++ b/src/main/java/org/olat/course/nodes/co/COEditController.java @@ -25,8 +25,6 @@ package org.olat.course.nodes.co; -import org.olat.core.commons.fullWebApp.LayoutMain3ColsController; -import org.olat.core.commons.fullWebApp.popup.BaseFullWebappPopupLayoutFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.panel.Panel; @@ -36,15 +34,12 @@ 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.creator.ControllerCreator; -import org.olat.core.gui.control.generic.popup.PopupBrowserWindow; import org.olat.core.gui.control.generic.tabbable.ActivateableTabbableDefaultController; import org.olat.course.ICourse; import org.olat.course.assessment.AssessmentHelper; import org.olat.course.condition.Condition; import org.olat.course.condition.ConditionEditController; import org.olat.course.editor.NodeEditController; -import org.olat.course.groupsandrights.ui.GroupAndAreaSelectController; import org.olat.course.nodes.COCourseNode; import org.olat.course.run.userview.UserCourseEnvironment; import org.olat.modules.ModuleConfiguration; @@ -80,17 +75,12 @@ public class COEditController extends ActivateableTabbableDefaultController impl /** config key: default body text */ public static final String CONFIG_KEY_MBODY_DEFAULT = "mBodyDefault"; - private static final String JSELEMENTID = "bel_"; - private ModuleConfiguration moduleConfiguration; - private VelocityContainer myContent; + private final VelocityContainer myContent; private Panel main; private COConfigForm configForm; private COCourseNode courseNode; private ConditionEditController accessibilityCondContr; - private ICourse course; - private GroupAndAreaSelectController selectGroupsCtr; - private GroupAndAreaSelectController selectAreasCtr; private TabbedPane myTabbedPane; /** @@ -106,11 +96,10 @@ public class COEditController extends ActivateableTabbableDefaultController impl this.moduleConfiguration = config; resolveModuleConfigurationIssues(moduleConfiguration); this.courseNode = coCourseNode; - this.course = course; main = new Panel("coeditpanel"); - myContent = this.createVelocityContainer("edit"); + myContent = createVelocityContainer("edit"); configForm = new COConfigForm(ureq, wControl, config, euce); configForm.addControllerListener(this); @@ -120,10 +109,10 @@ public class COEditController extends ActivateableTabbableDefaultController impl // not needed: setInitialComponent(myContent); // Accessibility precondition Condition accessCondition = courseNode.getPreConditionAccess(); - accessibilityCondContr = new ConditionEditController(ureq, getWindowControl(), course.getCourseEnvironment().getCourseGroupManager(), - accessCondition, "accessabilityConditionForm", AssessmentHelper.getAssessableNodes(course - .getEditorTreeModel(), coCourseNode),euce); - this.listenTo(accessibilityCondContr); + accessibilityCondContr = new ConditionEditController(ureq, getWindowControl(), euce.getCourseEnvironment().getCourseGroupManager(), + accessCondition, "accessabilityConditionForm", + AssessmentHelper.getAssessableNodes(course.getEditorTreeModel(), coCourseNode), euce); + listenTo(accessibilityCondContr); main.setContent(myContent); } @@ -164,51 +153,6 @@ public class COEditController extends ActivateableTabbableDefaultController impl fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT); return; - } else if (event.getCommand().equals("popupchoosegroups")) { - // open a controller in a new window which only results in sending back - // javascript - // get preselected groups - final String groups = (String) moduleConfiguration.get(CONFIG_KEY_EMAILTOGROUPS); - // get group select controller - ControllerCreator ctrlCreator = new ControllerCreator() { - public Controller createController(UserRequest lureq, WindowControl lwControl) { - selectGroupsCtr = new GroupAndAreaSelectController(lureq,lwControl,course.getCourseEnvironment().getCourseGroupManager(), - GroupAndAreaSelectController.TYPE_GROUP, groups, - JSELEMENTID + "popupchoosegroups"+configForm.hashCode()); - // use a one-column main layout - // disposed in dispose method of COEditController! - LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(lureq, lwControl, null, null, selectGroupsCtr.getInitialComponent(), "null"); - return layoutCtr; - } - }; - //wrap the content controller into a full header layout - ControllerCreator layoutCtrlr = BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, ctrlCreator); - //open in new browser window - PopupBrowserWindow pbw = getWindowControl().getWindowBackOffice().getWindowManager().createNewPopupBrowserWindowFor(ureq, layoutCtrlr); - pbw.open(ureq); - // - } else if (event.getCommand().equals("popupchooseareas")) { - // open a controller in a new window which only results in sending back - // javascript - // get preselected areas - final String areas = (String) moduleConfiguration.get(CONFIG_KEY_EMAILTOAREAS); - // get area select controller - ControllerCreator ctrlCreator = new ControllerCreator() { - public Controller createController(UserRequest lureq, WindowControl lwControl) { - selectAreasCtr = new GroupAndAreaSelectController(lureq, lwControl, course.getCourseEnvironment().getCourseGroupManager(), - GroupAndAreaSelectController.TYPE_AREA, areas, JSELEMENTID + "popupchooseareas" + configForm.hashCode()); - // use a one-column main layout - // disposed in dispose method of COEditController! - LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(lureq, lwControl, null, null, selectAreasCtr.getInitialComponent(), null); - return layoutCtr; - } - }; - //wrap the content controller into a full header layout - ControllerCreator layoutCtrlr = BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, ctrlCreator); - //open in new browser window - PopupBrowserWindow pbw = getWindowControl().getWindowBackOffice().getWindowManager().createNewPopupBrowserWindowFor(ureq, layoutCtrlr); - pbw.open(ureq); - // } } } @@ -227,13 +171,7 @@ public class COEditController extends ActivateableTabbableDefaultController impl * @see org.olat.core.gui.control.DefaultController#doDispose(boolean) */ protected void doDispose() { - // child controllers registered with listenTo() get disposed in BasicController - if (selectGroupsCtr != null) { - selectGroupsCtr.dispose(); - } - if (selectAreasCtr != null) { - selectAreasCtr.dispose(); - } + //nothing to do } /** 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 e9bef180e8435230de8aa828296ba90dbeb07c6a..ebd04d8fedd7107f408e7cbba99528330022d137 100644 --- a/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java +++ b/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java @@ -46,6 +46,7 @@ import org.olat.course.nodes.ENCourseNode; import org.olat.course.properties.CoursePropertyManager; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; +import org.olat.group.area.BGArea; import org.olat.group.area.BGAreaManager; import org.olat.group.model.SearchBusinessGroupParams; import org.olat.group.ui.BGMailHelper; @@ -217,9 +218,9 @@ public class EnrollmentManager extends BasicManager { } // 2. check in areas if(areaKeys != null && !areaKeys.isEmpty()) { - for (Long areaKey:areaKeys) { - String areaName = areaKey.toString();//TODO gm - List<BusinessGroup> groups = cgm.getParticipatingBusinessGroupsInArea(identity, areaName); + List<BGArea> areas = areaManager.loadAreas(areaKeys); + for (BGArea area:areas) { + List<BusinessGroup> groups = areaManager.findBusinessGroupsOfArea(area); if (groups.size() > 0) { // Usually it is only possible to be in one group. However, // theoretically the diff --git a/src/main/java/org/olat/group/BusinessGroupService.java b/src/main/java/org/olat/group/BusinessGroupService.java index d52483e839b32c9f5aa223067b2afabb76764728..457e66174a0d554229d1231fa49ef2638ad5fc8c 100644 --- a/src/main/java/org/olat/group/BusinessGroupService.java +++ b/src/main/java/org/olat/group/BusinessGroupService.java @@ -214,7 +214,7 @@ public interface BusinessGroupService { */ 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); + boolean copyOwners, boolean copyParticipants, boolean copyMemberVisibility, boolean copyWaitingList, boolean copyRelations); //search methods /** diff --git a/src/main/java/org/olat/group/area/BGAreaImpl.java b/src/main/java/org/olat/group/area/BGAreaImpl.java index 3f15e16983ffefc8edf7099dfd09fdac0e7c055c..56fa71cdc82a47b930c856a2ffd2488d6737ba33 100644 --- a/src/main/java/org/olat/group/area/BGAreaImpl.java +++ b/src/main/java/org/olat/group/area/BGAreaImpl.java @@ -26,7 +26,6 @@ package org.olat.group.area; import org.olat.core.commons.persistence.PersistentObject; -import org.olat.group.context.BGContext; import org.olat.resource.OLATResource; /** @@ -48,12 +47,6 @@ public class BGAreaImpl extends PersistentObject implements BGArea { protected BGAreaImpl() { // nothing to do } - - BGAreaImpl(String name, String description, BGContext context) { - setName(name); - setGroupContextKey(context.getKey()); - setDescription(description); - } BGAreaImpl(String name, String description, OLATResource resource) { setName(name); diff --git a/src/main/java/org/olat/group/area/BGAreaManager.java b/src/main/java/org/olat/group/area/BGAreaManager.java index 3aaad692b00bf8124bbb9b85235c379ee426fd45..08da66362c7ff7ae60f262f976407a91ef3e3d60 100644 --- a/src/main/java/org/olat/group/area/BGAreaManager.java +++ b/src/main/java/org/olat/group/area/BGAreaManager.java @@ -28,7 +28,6 @@ package org.olat.group.area; import java.io.File; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Set; import org.olat.core.id.Identity; @@ -54,17 +53,6 @@ public interface BGAreaManager { */ public abstract BGArea createAndPersistBGAreaIfNotExists(String areaName, String description, OLATResource resource); - /** - * Copies all group areas from the original context to the target context. The - * method returns a hash map with all original areas as key and the newly - * created areas as value. - * - * @param origBgContext Context containing the orignial areas - * @param targetBgContext Context where the areas should be created - * @return Map mapping the original to the new areas - */ - public abstract Map<BGArea,BGArea> copyBGAreasOfBGContext(OLATResource sourceResource, OLATResource targetResource); - /** * Finds an area in the given context * @@ -145,6 +133,14 @@ public interface BGAreaManager { * @return A list of business groups */ public List<BusinessGroup> findBusinessGroupsOfAreas(List<BGArea> areas); + + /** + * Searches for all business groups that are associated with the given + * business group areas primary keys + * + * @param area + * @return A list of business groups + */ public List<BusinessGroup> findBusinessGroupsOfAreaKeys(List<Long> areaKeys); /** @@ -237,6 +233,16 @@ public interface BGAreaManager { */ public List<Long> toAreaKeys(String areaNames, OLATResource resource); - - public File archiveAreaMembers(OLATResource resource, List<String> columnList, List<BGArea> areaList, String archiveType, Locale locale, String charset); + /** + * + * @param resource + * @param columnList + * @param areaList + * @param archiveType + * @param locale + * @param charset + * @return + */ + public File archiveAreaMembers(OLATResource resource, List<String> columnList, List<BGArea> areaList, + String archiveType, Locale locale, String charset); } \ No newline at end of file diff --git a/src/main/java/org/olat/group/area/BGAreaManagerImpl.java b/src/main/java/org/olat/group/area/BGAreaManagerImpl.java index b2eebfa5760302049eb9ec020ca6d4ece2b5d90e..c9ea31f1771a28c612b0c07bfdc8eccc05b53e2f 100644 --- a/src/main/java/org/olat/group/area/BGAreaManagerImpl.java +++ b/src/main/java/org/olat/group/area/BGAreaManagerImpl.java @@ -28,11 +28,8 @@ package org.olat.group.area; import java.io.File; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Set; import javax.persistence.TypedQuery; @@ -85,23 +82,6 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { }); return createdBGArea; } - - /** - * @see org.olat.group.area.BGAreaManager#copyBGAreasOfBGContext(org.olat.group.context.BGContext, - * org.olat.group.context.BGContext) - */ - // o_clusterOK by:cg ; must be synchronized too ? => not 100% sure, - public Map<BGArea,BGArea> copyBGAreasOfBGContext(OLATResource origBgContext, final OLATResource targetBgContext) { - List<BGArea> origAreas = findBGAreasInContext(origBgContext); - Map<BGArea,BGArea> areas = new HashMap<BGArea,BGArea>(); - Iterator<BGArea> iterator = origAreas.iterator(); - while (iterator.hasNext()) { - BGArea origArea = (BGArea) iterator.next(); - BGArea targetArea = createAndPersistBGArea(origArea.getName(), origArea.getDescription(), targetBgContext); - areas.put(origArea, targetArea); - } - return areas; - } @Override public BGArea loadArea(Long key) { diff --git a/src/main/java/org/olat/group/context/BGContext.java b/src/main/java/org/olat/group/context/BGContext.java deleted file mode 100644 index c9beb452c18748790b5b1e6f371f08e4bf16c218..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/group/context/BGContext.java +++ /dev/null @@ -1,94 +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 org.olat.basesecurity.SecurityGroup; -import org.olat.core.id.CreateInfo; -import org.olat.core.id.OLATResourceable; -import org.olat.core.id.Persistable; - -/** - * Description:<BR> - * A business group context is a container for groups that are used together as - * a set. Eg. all groups of a course, or a class with some subgroups, or a - * Lehrgang / Studiengang. Group contexts can be attached many courses. The - * group context can contain only business groups of one specific business group - * type. Default group contexts can only be used for one resource (one - * association allowed). This is configured by the setDefaultContext() method. - * <P> - * Initial Date: Aug 18, 2004 - * - * @author gnaegi - */ -public interface BGContext extends Persistable, CreateInfo, OLATResourceable { - /** regular expression to check for valid group context names */ - public final static String VALID_GROUPCONTEXTNAME_REGEXP = "^[^,\"]*$"; - - /** - * @return The context name - */ - abstract String getName(); - - /** - * @return The context description - */ - abstract String getDescription(); - - /** - * @param string The context description - */ - abstract void setDescription(String string); - - /** - * @param string The context name - */ - abstract void setName(String string); - - /** - * @return The owner group of this context - */ - abstract SecurityGroup getOwnerGroup(); - - /** - * @return The group type used in this context - */ - abstract String getGroupType(); - - /** - * @return boolen true: this is a default context, only one relation to a - * resource allowed - */ - abstract boolean isDefaultContext(); - - /** - * Set the default context: true means that only one resource relation is - * allowed - * - * @param defaultContext - */ - abstract void setDefaultContext(boolean defaultContext); - -} \ No newline at end of file diff --git a/src/main/java/org/olat/group/context/BGContext2Resource.java b/src/main/java/org/olat/group/context/BGContext2Resource.java index b3e186399308b1d93abd8c4ac9f8a6fcf4245399..8704066cfca70b5ca64f32a6a1532fb1582f2641 100644 --- a/src/main/java/org/olat/group/context/BGContext2Resource.java +++ b/src/main/java/org/olat/group/context/BGContext2Resource.java @@ -36,7 +36,7 @@ import org.olat.resource.OLATResource; */ public class BGContext2Resource extends PersistentObject { - private BGContext groupContext; + private BGContextImpl groupContext; private OLATResource resource; /** @@ -53,7 +53,7 @@ public class BGContext2Resource extends PersistentObject { * @param resource * @param groupContext */ - BGContext2Resource(OLATResource resource, BGContext groupContext) { + BGContext2Resource(OLATResource resource, BGContextImpl groupContext) { setResource(resource); setGroupContext(groupContext); } @@ -75,14 +75,14 @@ public class BGContext2Resource extends PersistentObject { /** * @return The group context */ - public BGContext getGroupContext() { + public BGContextImpl getGroupContext() { return groupContext; } /** * @param groupContext The group context */ - public void setGroupContext(BGContext groupContext) { + public void setGroupContext(BGContextImpl groupContext) { this.groupContext = groupContext; } } diff --git a/src/main/java/org/olat/group/context/BGContextImpl.java b/src/main/java/org/olat/group/context/BGContextImpl.java index 20889e3ca6a22c23f7b2801c488c003d819cce79..4adcaa2464d77dcedc7c61a57d7874915e3219c0 100644 --- a/src/main/java/org/olat/group/context/BGContextImpl.java +++ b/src/main/java/org/olat/group/context/BGContextImpl.java @@ -37,7 +37,7 @@ import org.olat.core.logging.AssertException; * * @author gnaegi */ -public class BGContextImpl extends PersistentObject implements BGContext { +public class BGContextImpl extends PersistentObject { private static final int GROUPTYPE_MAXLENGTH = 15; @@ -167,8 +167,8 @@ public class BGContextImpl extends PersistentObject implements BGContext { if(this == obj) { return true; } - if(obj instanceof BGContext) { - BGContext ctx = (BGContext)obj; + if(obj instanceof BGContextImpl) { + BGContextImpl ctx = (BGContextImpl)obj; return equalsByPersistableKey(ctx); } return false; diff --git a/src/main/java/org/olat/group/context/BGContextManagerImpl.java b/src/main/java/org/olat/group/context/BGContextManagerImpl.java deleted file mode 100644 index 253ea6e00bfb4e3edb7486b3578e6993139ef250..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/group/context/BGContextManagerImpl.java +++ /dev/null @@ -1,631 +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 org.olat.core.manager.BasicManager; - -/** - * Description: <BR> - * Implementation of the business group context manager. - * <P> - * Initial Date: Aug 19, 2004 <br> - * - * @author gnaegi - */ -public class BGContextManagerImpl extends BasicManager { - - private static BGContextManagerImpl INSTANCE; - static { - INSTANCE = new BGContextManagerImpl(); - } - - /** - * @return singleton instance - */ - public static BGContextManagerImpl getInstance() { - return INSTANCE; - } - - private BGContextManagerImpl() { - // no public constructor - } - - /** - * @see org.olat.group.context.BGContextManager#createAndPersistBGContext(java.lang.String, - * java.lang.String, java.lang.String, org.olat.core.id.Identity, - * boolean) - *//* - public BGContext createAndPersistBGContext(String name, String description, String groupType, Identity owner, boolean defaultContext) { - if (name == null) throw new AssertException("Business group context name must not be null"); - if (groupType == null) throw new AssertException("Business group groupType name must not be null"); - BaseSecurity securityManager = BaseSecurityManager.getInstance(); - // 1) create administrative owner security group, add owner if available - SecurityGroup ownerGroup = securityManager.createAndPersistSecurityGroup(); - if (owner != null) { - securityManager.addIdentityToSecurityGroup(owner, ownerGroup); - } - // 2) create new group context with this security group and save it - BGContext bgContext = new BGContextImpl(name, description, ownerGroup, groupType, defaultContext); - DBFactory.getInstance().saveObject(bgContext); - // 3) save context owner policy to this context and the owner group - securityManager.createAndPersistPolicy(ownerGroup, Constants.PERMISSION_ACCESS, bgContext); - // 4) save groupmanager policy on this group - all members are automatically - // group managers - securityManager.createAndPersistPolicy(ownerGroup, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GROUPMANAGER); - Tracing.logAudit("Created Business Group Context", bgContext.toString(), this.getClass()); - return bgContext; - } - - /** - * @see org.olat.group.context.BGContextManager#copyAndAddBGContextToResource(java.lang.String, - * org.olat.resource.OLATResource, org.olat.group.context.BGContext) - *//* - public BGContext copyAndAddBGContextToResource(String contextName, OLATResource resource, BGContext originalBgContext) { - /* - BGAreaManager areaManager = BGAreaManagerImpl.getInstance(); - BusinessGroupManager groupManager = BusinessGroupManagerImpl.getInstance(); - if (!originalBgContext.isDefaultContext()) { throw new AssertException("Can only copy default contexts"); } - - // 1. Copy context as default context. Owner group of original context will - // not be - // copied since this is a default context - BGContext targetContext = createAndAddBGContextToResource(contextName, resource, originalBgContext.getGroupType(), null, true); - // 2. Copy areas - Map areas = areaManager.copyBGAreasOfBGContext(originalBgContext, targetContext); - // 3. Copy Groups - // only group configuration will be copied, no group members are copied - List origGroups = getGroupsOfBGContext(originalBgContext); - Iterator iter = origGroups.iterator(); - while (iter.hasNext()) { - BusinessGroup origGroup = (BusinessGroup) iter.next(); - groupManager.copyBusinessGroup(origGroup, origGroup.getName(), origGroup.getDescription(), origGroup.getMinParticipants(), origGroup - .getMaxParticipants(), targetContext, areas, true, true, true, false, false, true, false); - }*//* - return null; - } - - /** - * @see org.olat.group.context.BGContextManager#updateBGContext(org.olat.group.context.BGContext) - *//* - public void updateBGContext(BGContext bgContext) { - // 1) update context - DBFactory.getInstance().updateObject(bgContext); - // 2) reload course contexts for all courses wher this context is used - List resources = findOLATResourcesForBGContext(bgContext); - for (Iterator iter = resources.iterator(); iter.hasNext();) { - OLATResource resource = (OLATResource) iter.next(); - if (resource.getResourceableTypeName().equals(CourseModule.getCourseTypeName())) { - ICourse course = CourseFactory.loadCourse(resource); - course.getCourseEnvironment().getCourseGroupManager().initGroupContextsList(); - } else if (resource.getResourceableTypeName().equals("junitcourse")) { - // do nothing when in junit test mode - } else { - throw new AssertException("Currently only course resources allowed in resource to context relations."); - } - } - } - - /** - * @see org.olat.group.context.BGContextManager#deleteBGContext(org.olat.group.context.BGContext) - *//* - public void deleteBGContext(BGContext bgContext) { - bgContext = (BGContext) DBFactory.getInstance().loadObject(bgContext); - // 1) Delete all groups from group context - List groups = getGroupsOfBGContext(bgContext); - //bgManager.deleteBusinessGroups(groups); - // 2) Delete all group areas - /* - List areas = areaManager.findBGAreasOfBGContext(bgContext); - for (Iterator iter = areas.iterator(); iter.hasNext();) { - BGArea area = (BGArea) iter.next(); - areaManager.deleteBGArea(area); - } - *//* - // 3) Delete group to resource relations - List referencingResources = findOLATResourcesForBGContext(bgContext); - for (Iterator iter = referencingResources.iterator(); iter.hasNext();) { - OLATResource refRes = (OLATResource) iter.next(); - removeBGContextFromResource(bgContext, refRes); - } - // 4) Delete group context - DBFactory.getInstance().deleteObject(bgContext); - // 5) Delete security group - SecurityGroup owners = bgContext.getOwnerGroup(); - if (owners != null) { - BaseSecurity secMgr = BaseSecurityManager.getInstance(); - secMgr.deleteSecurityGroup(owners); - } - Tracing.logAudit("Deleted Business Group Context", bgContext.toString(), this.getClass()); - } - - /** - * @see org.olat.group.context.BGContextManager#getGroupsOfBGContext(org.olat.group.context.BGContext) - *//* - public List<BusinessGroup> getGroupsOfBGContext(BGContext bgContext) { - DB db = DBFactory.getInstance(); - DBQuery query; - if (bgContext == null) { - String q = "select bg from org.olat.group.BusinessGroupImpl bg where bg.groupContext is null"; - query = db.createQuery(q); - } else { - String q = "select bg from org.olat.group.BusinessGroupImpl bg where bg.groupContext = :context"; - query = db.createQuery(q); - query.setEntity("context", bgContext); - } - return (List<BusinessGroup>) query.list(); - } - - public List<BusinessGroup> getGroupsOfBGContext(Collection<BGContext> bgContexts, int firstResult, int maxResults) { - if(bgContexts == null || bgContexts.isEmpty()) { - return Collections.emptyList(); - } - - DB db = DBFactory.getInstance(); - StringBuilder sb = new StringBuilder(); - sb.append("select bg from ").append(BusinessGroupImpl.class.getName()).append(" bg") - .append(" where bg.groupContext.key in (:contextKeys)"); - - DBQuery query = db.createQuery(sb.toString()); - List<Long> contextKeys = new ArrayList<Long>(bgContexts.size()); - for(BGContext bgContext:bgContexts) { - contextKeys.add(bgContext.getKey()); - } - query.setParameterList("contextKeys", contextKeys); - query.setFirstResult(firstResult); - if(maxResults > 0) { - query.setMaxResults(maxResults); - } - return query.list(); - } - - /** - * @see org.olat.group.context.BGContextManager#countGroupsOfBGContext(org.olat.group.context.BGContext) - *//* - public int countGroupsOfBGContext(BGContext bgContext) { - DB db = DBFactory.getInstance(); - String q = "select count(bg) from org.olat.group.BusinessGroupImpl bg where bg.groupContext = :context"; - DBQuery query = db.createQuery(q); - query.setEntity("context", bgContext); - return ((Long) query.list().get(0)).intValue(); - } - - /** - * @see org.olat.group.context.BGContextManager#countGroupsOfType(java.lang.String) - *//* - public int countGroupsOfType(String groupType) { - DB db = DBFactory.getInstance(); - String q = "select count(bg) from org.olat.group.BusinessGroupImpl bg where bg.type = :type"; - DBQuery query = db.createQuery(q); - query.setString("type", groupType); - return ((Long) query.list().get(0)).intValue(); - } - - /** - * @see org.olat.group.context.BGContextManager#findGroupOfBGContext(java.lang.String, - * org.olat.group.context.BGContext) - *//* - public BusinessGroup findGroupOfBGContext(String groupName, BGContext bgContext) { - DB db = DBFactory.getInstance(); - String q = "select bg from org.olat.group.BusinessGroupImpl bg where bg.groupContext = :context and bg.name = :name"; - DBQuery query = db.createQuery(q); - query.setEntity("context", bgContext); - query.setString("name", groupName); - List results = query.list(); - if (results.size() == 0) return null; - return (BusinessGroup) results.get(0); - } - - /** - * @see org.olat.group.context.BGContextManager#findGroupAttendedBy(org.olat.core.id.Identity, - * java.lang.String, org.olat.group.context.BGContext) - *//* - public BusinessGroup findGroupAttendedBy(Identity identity, String groupName, BGContext bgContext) { - String query = "select bgi from " + " org.olat.group.BusinessGroupImpl as bgi " - + ", org.olat.basesecurity.SecurityGroupMembershipImpl as sgmi" + " where bgi.name = :name " - + " and bgi.partipiciantGroup = sgmi.securityGroup" + " and sgmi.identity = :identId" + " and bgi.groupContext = :context"; - DB db = DBFactory.getInstance(); - DBQuery dbq = db.createQuery(query); - dbq.setEntity("identId", identity); - dbq.setString("name", groupName); - dbq.setEntity("context", bgContext); - List res = dbq.list(); - if (res.size() == 0) return null; - else if (res.size() > 1) throw new AssertException("more than one result row found for (identity, groupname, context) (" - + identity.getName() + ", " + groupName + ", " + bgContext.getName()); - return (BusinessGroup) res.get(0); - } - - /** - * @see org.olat.group.context.BGContextManager#getBGOwnersOfBGContext(org.olat.group.context.BGContext) - *//* - public List getBGOwnersOfBGContext(BGContext bgContext) { - DB db = DBFactory.getInstance(); - String q = "select distinct id from org.olat.basesecurity.IdentityImpl as id inner join fetch id.user as iuser" - + ", org.olat.basesecurity.SecurityGroupMembershipImpl sgm" + ", org.olat.group.BusinessGroupImpl bg" - + " where bg.groupContext = :context" + " and bg.ownerGroup = sgm.securityGroup" + " and sgm.identity = id"; - DBQuery query = db.createQuery(q); - query.setEntity("context", bgContext); - return query.list(); - } - - //fxdiff VCRP-2: access control - public List<BusinessGroup> getBusinessGroupAsOwnerOfBGContext(Identity owner, BGContext bgContext) { - DB db = DBFactory.getInstance(); - StringBuilder sb = new StringBuilder(); - sb.append("select bg from org.olat.group.BusinessGroupImpl bg") - .append(" ,org.olat.basesecurity.SecurityGroupMembershipImpl sgm") - .append(" where bg.groupContext=:context and bg.ownerGroup=sgm.securityGroup and sgm.identity=:id"); - - DBQuery query = db.createQuery(sb.toString()); - query.setEntity("context", bgContext); - query.setEntity("id", owner); - return query.list(); - } - - /** - * @see org.olat.group.context.BGContextManager#countBGOwnersOfBGContext(org.olat.group.context.BGContext) - *//* - public int countBGOwnersOfBGContext(BGContext bgContext) { - DB db = DBFactory.getInstance(); - String q = "select count(distinct id) from org.olat.basesecurity.IdentityImpl id" - + ", org.olat.basesecurity.SecurityGroupMembershipImpl sgm" + ", org.olat.group.BusinessGroupImpl bg" - + " where bg.groupContext = :context" + " and bg.ownerGroup = sgm.securityGroup" + " and sgm.identity = id"; - DBQuery query = db.createQuery(q); - query.setEntity("context", bgContext); - List resultList = query.list(); - - int result = 0; - // if no join/group by matches, result list size is 0 and count undefined -> - // result is 0 - if (resultList.size() > 0) { - Object obj = resultList.get(0); - if (obj == null) return 0; - result = ((Long) obj).intValue(); - } - return result; - } - - /** - * @see org.olat.group.context.BGContextManager#getBGParticipantsOfBGContext(org.olat.group.context.BGContext) - *//* - public List getBGParticipantsOfBGContext(BGContext bgContext) { - DB db = DBFactory.getInstance(); - String q = "select distinct id from org.olat.basesecurity.IdentityImpl as id inner join fetch id.user as iuser" - + ", org.olat.basesecurity.SecurityGroupMembershipImpl sgm" + ", org.olat.group.BusinessGroupImpl bg" - + " where bg.groupContext = :context" + " and bg.partipiciantGroup = sgm.securityGroup" + " and sgm.identity = id"; - DBQuery query = db.createQuery(q); - query.setEntity("context", bgContext); - return query.list(); - } - - //fxdiff VCRP-2: access control - public List<BusinessGroup> getBusinessGroupAsParticipantOfBGContext(Identity participant, BGContext bgContext) { - DB db = DBFactory.getInstance(); - StringBuilder sb = new StringBuilder(); - sb.append("select bg from org.olat.group.BusinessGroupImpl bg") - .append(" ,org.olat.basesecurity.SecurityGroupMembershipImpl sgm") - .append(" where bg.groupContext=:context and bg.partipiciantGroup=sgm.securityGroup and sgm.identity=:id"); - - DBQuery query = db.createQuery(sb.toString()); - query.setEntity("context", bgContext); - query.setEntity("id", participant); - return query.list(); - } - - /** - * @see org.olat.group.context.BGContextManager#countBGParticipantsOfBGContext(org.olat.group.context.BGContext) - *//* - public int countBGParticipantsOfBGContext(BGContext bgContext) { - DB db = DBFactory.getInstance(); - String q = "select count(distinct id) from org.olat.basesecurity.IdentityImpl id" - + ", org.olat.basesecurity.SecurityGroupMembershipImpl sgm" + ", org.olat.group.BusinessGroupImpl bg" - + " where bg.groupContext = :context" + " and bg.partipiciantGroup = sgm.securityGroup" + " and sgm.identity = id"; - DBQuery query = db.createQuery(q); - query.setEntity("context", bgContext); - List resultList = query.list(); - int result = 0; - // if no join/group by matches, result list size is 0 and count undefined -> - // result is 0 - if (resultList.size() > 0) { - Object obj = resultList.get(0); - if (obj == null) return 0; - result = ((Long) obj).intValue(); - } - return result; - } - - /** - * @see org.olat.group.context.BGContextManager#isIdentityInBGContext(org.olat.core.id.Identity, - * org.olat.group.context.BGContext, boolean, boolean) - *//* - public boolean isIdentityInBGContext(Identity identity, List<BGContext> bgContexts, boolean asOwner, boolean asParticipant) { - if(bgContexts == null || bgContexts.isEmpty()) return false; - - DB db = DBFactory.getInstance(); - StringBuilder q = new StringBuilder(); - q.append(" select count(grp) from ").append(BusinessGroupImpl.class.getName()).append(" as grp,") - .append(SecurityGroupMembershipImpl.class.getName()).append(" as secgmemb where grp.groupContext in (:contexts) and "); - // restricting where clause for participants - String partRestr = "(grp.partipiciantGroup = secgmemb.securityGroup and secgmemb.identity = :id) "; - // restricting where clause for owners - String ownRestr = "(grp.ownerGroup = secgmemb.securityGroup and secgmemb.identity = :id)"; - - if (asParticipant && asOwner) { - q.append("(").append(partRestr).append(" or ").append(ownRestr).append(")"); - } else if (asParticipant && !asOwner) { - q.append(partRestr); - } else if (!asParticipant && asOwner) { - q.append(ownRestr); - } else { - throw new AssertException("illegal arguments: at leas one of asOwner or asParticipant must be true"); - } - - DBQuery query = db.createQuery(q.toString()); - query.setEntity("id", identity); - query.setParameterList("contexts", bgContexts); - query.setCacheable(true); - - @SuppressWarnings("rawtypes") - List result = query.list(); - if (result.size() == 0) return false; - return (((Number) result.get(0)).intValue() > 0); - } - - /** - * @see org.olat.group.context.BGContextManager#createAndAddBGContextToResource(java.lang.String, - * org.olat.resource.OLATResource, java.lang.String, - * org.olat.core.id.Identity, boolean) - *//* - public BGContext createAndAddBGContextToResource(String contextName, OLATResource resource, String groupType, Identity initialOwner, - boolean defaultContext) { - BGContext context = createAndPersistBGContext(contextName, null, groupType, initialOwner, defaultContext); - addBGContextToResource(context, resource); - return context; - } - - /** - * @see org.olat.group.context.BGContextManager#addBGContextToResource(org.olat.group.context.BGContext, - * org.olat.resource.OLATResource) - *//* - public void addBGContextToResource(BGContext bgContext, OLATResource resource) { - BGContext2Resource courseBgContext = new BGContext2Resource(resource, bgContext); - DBFactory.getInstance().saveObject(courseBgContext); - // update course context list in this course resource - if (resource.getResourceableTypeName().equals(CourseModule.getCourseTypeName())) { - ICourse course = CourseFactory.loadCourse(resource); - course.getCourseEnvironment().getCourseGroupManager().initGroupContextsList(); - } else if (resource.getResourceableTypeName().equals("junitcourse")) { - // do nothing when in junit test mode - } else { - throw new AssertException("Currently only course resources allowed in resource to context relations."); - } - Tracing.logAudit("Added Business Group Context to OLATResource " + resource.toString(), bgContext.toString(), this.getClass()); - } - - /** - * @see org.olat.group.context.BGContextManager#findBGContextsForResource(org.olat.resource.OLATResource, - * boolean, boolean) - *//* - public List<BGContext> findBGContextsForResource(OLATResource resource, boolean defaultContexts, boolean nonDefaultContexts) { - return findBGContextsForResource(resource, null, defaultContexts, nonDefaultContexts); - } - - /** - * @see org.olat.group.context.BGContextManager#findBGContextsForResource(org.olat.resource.OLATResource, - * java.lang.String, boolean, boolean) - *//* - public List<BGContext> findBGContextsForResource(OLATResource resource, String groupType, boolean defaultContexts, boolean nonDefaultContexts) { - DB db = DBFactory.getInstance(); - StringBuilder q = new StringBuilder(); - q.append(" select context from org.olat.group.context.BGContextImpl as context,"); - q.append(" org.olat.group.context.BGContext2Resource as bgcr"); - q.append(" where bgcr.resource = :resource"); - q.append(" and bgcr.groupContext = context"); - if (groupType != null) q.append(" and context.groupType = :gtype"); - - boolean checkDefault = defaultContexts != nonDefaultContexts; - if (checkDefault){ - q.append(" and context.defaultContext = :isDefault"); - } - DBQuery query = db.createQuery(q.toString()); - query.setEntity("resource", resource); - if (groupType != null) query.setString("gtype", groupType); - if (checkDefault){ - query.setBoolean("isDefault", defaultContexts ? true : false); - } - @SuppressWarnings("unchecked") - List<BGContext> contexts = query.list(); - return contexts; - } - - /** - * @see org.olat.group.context.BGContextManager#findBGContextsForIdentity(org.olat.core.id.Identity, - * boolean, boolean) - *//* - public List<BGContext> findBGContextsForIdentity(Identity identity, boolean defaultContexts, boolean nonDefaultContexts) { - DB db = DBFactory.getInstance(); - StringBuilder q = new StringBuilder(); - q.append(" select context from org.olat.group.context.BGContextImpl as context,"); - q.append(" org.olat.basesecurity.SecurityGroupMembershipImpl as secgmemb"); - q.append(" where context.ownerGroup = secgmemb.securityGroup"); - q.append(" and secgmemb.identity = :identity"); - - boolean checkDefault = defaultContexts != nonDefaultContexts; - if (checkDefault){ - q.append(" and context.defaultContext = :isDefault"); - } - DBQuery query = db.createQuery(q.toString()); - query.setEntity("identity", identity); - if (checkDefault){ - query.setBoolean("isDefault", defaultContexts ? true : false); - } - - @SuppressWarnings("unchecked") - List<BGContext> contexts = query.list(); - return contexts; - } - - /** - * @see org.olat.group.context.BGContextManager#findOLATResourcesForBGContext(org.olat.group.context.BGContext) - *//* - public List<OLATResource> findOLATResourcesForBGContext(BGContext bgContext) { - DB db = DBFactory.getInstance(); - String q = " select bgcr.resource from org.olat.group.context.BGContext2Resource as bgcr where bgcr.groupContext = :context"; - DBQuery query = db.createQuery(q); - query.setEntity("context", bgContext); - return query.list(); - } - - /** - * @see org.olat.group.context.BGContextManager#findRepositoryEntriesForBGContext(org.olat.group.context.BGContext) - *//* - public List<RepositoryEntry> findRepositoryEntriesForBGContext(BGContext bgContext) { - /*List resources = findOLATResourcesForBGContext(bgContext); - List entries = new ArrayList(); - for (Iterator iter = resources.iterator(); iter.hasNext();) { - OLATResource resource = (OLATResource) iter.next(); - RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(resource, false); - if (entry == null) { - throw new AssertException("No repository entry found for olat resource with TYPE::" + resource.getResourceableTypeName() + " ID::" - + resource.getResourceableId()); - } else { - entries.add(entry); - } - }*//* - //fxdiff VCRP-1,2: access control of resources - return findRepositoryEntriesForBGContext(Collections.singletonList(bgContext), 0, -1); - } - - //fxdiff VCRP-1,2: access control of resources - public List<RepositoryEntry> findRepositoryEntriesForBGContext(Collection<BGContext> bgContexts, int firstResult, int maxResults) { - if(bgContexts == null || bgContexts.isEmpty()) return Collections.emptyList(); - DB db = DBFactory.getInstance(); - StringBuilder sb = new StringBuilder(); - sb.append("select v from ").append(RepositoryEntry.class.getName()).append(" as v ") - .append(" inner join fetch v.olatResource as ores ") - .append(" where ores in (") - .append(" select bgcr.resource from ").append(BGContext2Resource.class.getName()).append(" as bgcr where bgcr.groupContext in (:contexts)") - .append(" )"); - - DBQuery query = db.createQuery(sb.toString()); - query.setFirstResult(firstResult); - if(maxResults > 0) { - query.setMaxResults(maxResults); - } - query.setParameterList("contexts", bgContexts); - return query.list(); - } - - //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) { - if(bgContexts == null || bgContexts.isEmpty()) return Collections.emptyList(); - - DB db = DBFactory.getInstance(); - StringBuilder sb = new StringBuilder(); - sb.append("select distinct v from ").append(RepositoryEntry.class.getName()).append(" as v ") - .append(" inner join fetch v.olatResource as ores ") - .append(" where ores in (") - .append(" select bgcr.resource from ").append(BGContext2Resource.class.getName()).append(" as bgcr where bgcr.groupContext in (:contexts)") - .append(" ) and "); - - boolean setIdentity = appendAccessSubSelects(sb, access, asOwner, asCoach, asParticipant, identity); - - DBQuery query = db.createQuery(sb.toString()); - query.setParameterList("contexts", bgContexts); - if(setIdentity) { - query.setEntity("identity", identity); - } - - List<RepositoryEntry> results = query.list(); - return results; - } - - private boolean appendAccessSubSelects(StringBuilder sb, int access, boolean asOwner, boolean asCoach, boolean asParticipant, Identity identity) { - sb.append("(v.access >= "); - if (access == RepositoryEntry.ACC_OWNERS) { - sb.append(access).append(")"); - return false; - } - sb.append(access); - boolean setIdentity = false; - if(identity != null && (asOwner || asCoach || asParticipant)) { - setIdentity = true; - //sub select are very quick - sb.append(" or (") - .append(" v.access=1 and v.membersOnly=true and ("); - - if(asOwner) { - sb.append(" v.ownerGroup in (select ownerSgmsi.securityGroup from ").append(SecurityGroupMembershipImpl.class.getName()).append(" ownerSgmsi where ownerSgmsi.identity=:identity)"); - } - if(asCoach) { - if(asOwner) sb.append(" or "); - sb.append(" v.tutorGroup in (select tutorSgmsi.securityGroup from ").append(SecurityGroupMembershipImpl.class.getName()).append(" tutorSgmsi where tutorSgmsi.identity=:identity)"); - } - if(asParticipant) { - if(asOwner || asCoach) sb.append(" or "); - sb.append(" v.participantGroup in (select partiSgmsi.securityGroup from ").append(SecurityGroupMembershipImpl.class.getName()).append(" partiSgmsi where partiSgmsi.identity=:identity)"); - } - sb.append(" ))"); - } - sb.append(")"); - return setIdentity; - } - - /** - * @see org.olat.group.context.BGContextManager#removeBGContextFromResource(org.olat.group.context.BGContext, - * org.olat.resource.OLATResource) - *//* - public void removeBGContextFromResource(BGContext bgContext, OLATResource resource) { - // 1) delete references for this resource - String q = " from org.olat.group.context.BGContext2Resource as bgcr where bgcr.groupContext = ? and bgcr.resource = ?"; - DBFactory.getInstance().delete(q, new Object[] { bgContext.getKey(), resource.getKey() }, - new Type[] { StandardBasicTypes.LONG, StandardBasicTypes.LONG }); - // 2) update course context list in this course resource - if (resource.getResourceableTypeName().equals(CourseModule.getCourseTypeName())) { - try { - ICourse course = CourseFactory.loadCourse(resource); - course.getCourseEnvironment().getCourseGroupManager().initGroupContextsList(); - } catch (CorruptedCourseException e) { - logError("Corrupted course, cannot update group contexts", null); - } - } else if (resource.getResourceableTypeName().equals("junitcourse")) { - // do nothing when in junit test mode - } else { - throw new AssertException("Currently only course resources allowed in resource to context relations."); - } - - Tracing.logAudit("Removed Business Group Context from OLATResource " + resource.toString(), bgContext.toString(), this.getClass()); - } - - /** - * @see org.olat.group.context.BGContextManager#loadBGContext(org.olat.group.context.BGContext) - *//* - public BGContext loadBGContext(BGContext bgContext) { - return (BGContext) DBFactory.getInstance().loadObject(bgContext); - }*/ - -} \ No newline at end of file diff --git a/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java b/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java index 152f3365b1bdd94af2b5ba3d3f63bf3bb81eca11..10b73f0af1c30af4f3dfb9525fa5407beeb08456 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java @@ -300,8 +300,6 @@ public class BusinessGroupArchiver { * @param archiveType * @param userLocale * @return the output file which could be an CSV or a zip file depending on the input archiveType. - * @see BGContext - * @see BusinessGroup */ public File archiveGroupMembers(OLATResource resource, List<String> columnList, List<BusinessGroup> groupList, String archiveType, Locale locale, String charset) { diff --git a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java index eebad09a92cdbf2f7aa30f0e537800702b1ae874..265585bec98af8a123e540b960e61ad061a76712 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java @@ -363,7 +363,8 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD @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) { + boolean copyRights, boolean copyOwners, boolean copyParticipants, boolean copyMemberVisibility, boolean copyWaitingList, + boolean copyRelations) { // 1. create group, set waitingListEnabled, enableAutoCloseRanks like source business-group BusinessGroup newGroup = createBusinessGroup(null, targetName, targetDescription, targetMin, targetMax, @@ -432,6 +433,13 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD securityManager.addIdentityToSecurityGroup(identity, newGroup.getWaitingGroup()); } } + //9. copy relations + if(copyRelations) { + List<OLATResource> resources = businessGroupRelationDAO.findResources(Collections.singletonList(sourceBusinessGroup), 0, -1); + for(OLATResource resource:resources) { + businessGroupRelationDAO.addRelationToResource(newGroup, resource); + } + } 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 c591a9861e985bb00f876cddc3a24dc1da844a99..d8003035624efba475a203338f54f43fc0f47684 100644 --- a/src/main/java/org/olat/group/ui/management/BGManagementController.java +++ b/src/main/java/org/olat/group/ui/management/BGManagementController.java @@ -30,7 +30,6 @@ import java.util.Collections; import java.util.List; import java.util.Locale; -import org.olat.admin.securitygroup.gui.GroupController; import org.olat.admin.securitygroup.gui.UserControllerFactory; import org.olat.admin.user.UserTableDataModel; import org.olat.basesecurity.BaseSecurity; @@ -179,8 +178,6 @@ public class BGManagementController extends MainLayoutBasicController implements private ContactFormController contactCtr; private BGCopyWizardController bgCopyWizardCtr; private BGMultipleCopyWizardController bgMultipleCopyWizardCtr; - private TableController resourcesCtr; - private GroupController contextOwnersCtr; private final boolean backLink; 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 7353b269d8ddcd099bb9aea1085446be515f750f..8baddf6ea8448f4f4ba856e8adb255bdaf4236cb 100644 --- a/src/main/java/org/olat/group/ui/wizard/BGCopyWizardController.java +++ b/src/main/java/org/olat/group/ui/wizard/BGCopyWizardController.java @@ -60,6 +60,8 @@ public class BGCopyWizardController extends WizardController { private BusinessGroupFormController groupController; private Translator trans; private BusinessGroup originalGroup, copiedGroup; + + private final BusinessGroupService bgs; /** * Constructor fot the business group copy wizard @@ -72,6 +74,7 @@ public class BGCopyWizardController extends WizardController { public BGCopyWizardController(UserRequest ureq, WindowControl wControl, BusinessGroup originalGroup) { super(ureq, wControl, 2); setBasePackage(BGCopyWizardController.class); + bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); this.trans = BGTranslatorFactory.createBGPackageTranslator(PACKAGE, originalGroup.getType(), ureq.getLocale()); this.originalGroup = originalGroup; // init wizard step 1 @@ -125,19 +128,17 @@ public class BGCopyWizardController extends WizardController { } private BusinessGroup doCopyGroup() { - // reload original group to prevent context proxy problems - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); - this.originalGroup = bgs.loadBusinessGroup(originalGroup); - //OLATResource resource = originalGroup.get(); + originalGroup = bgs.loadBusinessGroup(originalGroup); String bgName = groupController.getGroupName(); String bgDesc = groupController.getGroupDescription(); Integer bgMax = groupController.getGroupMax(); Integer bgMin = groupController.getGroupMin(); - boolean copyAreas = copyForm.isCopyAreas(); - - BusinessGroup newGroup = bgs.copyBusinessGroup(originalGroup, bgName, bgDesc, bgMin, bgMax, null, null, copyAreas, - copyForm.isCopyTools(), copyForm.isCopyRights(), copyForm.isCopyOwners(), copyForm.isCopyParticipants(), copyForm - .isCopyMembersVisibility(), copyForm.isCopyWaitingList()); + + BusinessGroup newGroup = bgs.copyBusinessGroup(originalGroup, bgName, bgDesc, + bgMin, bgMax, null, null, + copyForm.isCopyAreas(), copyForm.isCopyTools(), copyForm.isCopyRights(), copyForm.isCopyOwners(), + copyForm.isCopyParticipants(), copyForm.isCopyMembersVisibility(), copyForm.isCopyWaitingList(), + true /*copy resources */ ); return newGroup; } @@ -146,14 +147,6 @@ public class BGCopyWizardController extends WizardController { * group */ public BusinessGroup getNewGroup() { - return this.copiedGroup; - } - - /** - * @see org.olat.core.gui.control.generic.wizard.WizardController#doDispose() - */ - @Override - protected void doDispose() { - super.doDispose(); + return copiedGroup; } } \ No newline at end of file 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 9db688e262c8dc8d13be01962cbe5cfaee69e3be..aa74aef3ed9e20fb5590040a480f51f19c44f18d 100644 --- a/src/main/java/org/olat/group/ui/wizard/BGMultipleCopyWizardController.java +++ b/src/main/java/org/olat/group/ui/wizard/BGMultipleCopyWizardController.java @@ -25,7 +25,6 @@ package org.olat.group.ui.wizard; -import java.util.Iterator; import java.util.List; import org.olat.core.CoreSpringFactory; @@ -61,6 +60,8 @@ public class BGMultipleCopyWizardController extends WizardController { private Translator trans; private BusinessGroup originalGroup; private GroupNamesForm groupNamesForm; + + private final BusinessGroupService businessGroupService; /** * Constructor fot the business group multiple copy wizard @@ -72,6 +73,7 @@ public class BGMultipleCopyWizardController extends WizardController { */ public BGMultipleCopyWizardController(UserRequest ureq, WindowControl wControl, BusinessGroup originalGroup) { super(ureq, wControl, 2); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); this.trans = BGTranslatorFactory.createBGPackageTranslator(PACKAGE, originalGroup.getType(), ureq.getLocale()); this.originalGroup = originalGroup; // init wizard step 1 @@ -101,13 +103,11 @@ public class BGMultipleCopyWizardController extends WizardController { } else if (source == groupNamesForm) { if (event == Event.DONE_EVENT) { - List groupNames = this.groupNamesForm.getGroupNamesList(); + List<String> groupNames = groupNamesForm.getGroupNamesList(); StringBuilder okGroups = new StringBuilder(); StringBuilder nokGroups = new StringBuilder(); - Integer max = this.groupNamesForm.getGroupMax(); - Iterator iter = groupNames.iterator(); - while (iter.hasNext()) { - String groupName = (String) iter.next(); + Integer max = groupNamesForm.getGroupMax(); + for (String groupName: groupNames) { BusinessGroup newGroup = doCopyGroup(groupName, max); if (newGroup == null) { nokGroups.append("<li>"); @@ -134,15 +134,17 @@ public class BGMultipleCopyWizardController extends WizardController { } private BusinessGroup doCopyGroup(String newGroupName, Integer max) { - BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + // reload original group to prevent context proxy problems - originalGroup = bgs.loadBusinessGroup(this.originalGroup); - boolean copyAreas = copyForm.isCopyAreas(); - //TODO gm copy relations to resources + originalGroup = businessGroupService.loadBusinessGroup(originalGroup); - BusinessGroup newGroup = bgs.copyBusinessGroup(originalGroup, newGroupName, originalGroup.getDescription(), null, max, null, null, copyAreas, - copyForm.isCopyTools(), copyForm.isCopyRights(), copyForm.isCopyOwners(), copyForm.isCopyParticipants(), copyForm - .isCopyMembersVisibility(), copyForm.isCopyWaitingList()); + BusinessGroup newGroup = businessGroupService.copyBusinessGroup(originalGroup, newGroupName, originalGroup.getDescription(), + null, max, null, null /* areas map */, + copyForm.isCopyAreas(), copyForm.isCopyTools(), copyForm.isCopyRights(), copyForm.isCopyOwners(), + copyForm.isCopyParticipants(), copyForm.isCopyMembersVisibility(), copyForm.isCopyWaitingList(), + true /*copy relations*/); + + return newGroup; } diff --git a/src/main/java/org/olat/group/ui/wizard/GroupNamesForm.java b/src/main/java/org/olat/group/ui/wizard/GroupNamesForm.java index fbbb8380c7ceb29dd8deef69ec3b8b434c340f4b..14c85844fb5ce48165a2e47167218ad24fb02319 100644 --- a/src/main/java/org/olat/group/ui/wizard/GroupNamesForm.java +++ b/src/main/java/org/olat/group/ui/wizard/GroupNamesForm.java @@ -51,7 +51,7 @@ public class GroupNamesForm extends FormBasicController { private TextElement groupNames; private TextElement bgMax; - private List groupNamesList; + private List<String> groupNamesList; private Integer defaultMaxValue; @@ -62,7 +62,7 @@ public class GroupNamesForm extends FormBasicController { } protected boolean validateFormLogic(UserRequest ureq) { - List namesList = new ArrayList(); + List<String> namesList = new ArrayList<String>(); String groupNamesString = groupNames.getValue(); String[] groups = groupNamesString.split("[\t\n\f\r]"); @@ -82,9 +82,9 @@ public class GroupNamesForm extends FormBasicController { } } // list seems to be valid. store for later retrival - this.groupNamesList = namesList; + groupNamesList = namesList; - if (namesList.size()==0) { + if (namesList.isEmpty()) { groupNames.setErrorKey("create.form.error.emptylist", null); return false; } @@ -96,9 +96,11 @@ public class GroupNamesForm extends FormBasicController { * @return A valid list of groupnames. The list is only valid if the form * returned the validation ok event! */ - public List getGroupNamesList() { - if (this.groupNamesList == null) { throw new AssertException("getGroupNamesList() called prior to form EVENT_VALIDATION_OK event"); } - return this.groupNamesList; + public List<String> getGroupNamesList() { + if (groupNamesList == null) { + throw new AssertException("getGroupNamesList() called prior to form EVENT_VALIDATION_OK event"); + } + return groupNamesList; } /** diff --git a/src/main/java/org/olat/repository/RepositoryManager.java b/src/main/java/org/olat/repository/RepositoryManager.java index 0e0286a9dd58216bf6026d85f4b26ede8158817d..56c5625bbf47a661610b534c4f5da5a157a8c23d 100644 --- a/src/main/java/org/olat/repository/RepositoryManager.java +++ b/src/main/java/org/olat/repository/RepositoryManager.java @@ -68,11 +68,9 @@ import org.olat.core.util.vfs.VFSContainer; import org.olat.core.util.vfs.VFSItem; import org.olat.core.util.vfs.VFSLeaf; import org.olat.core.util.vfs.VFSManager; -import org.olat.course.CourseFactory; -import org.olat.course.ICourse; import org.olat.course.assessment.manager.UserCourseInformationsManager; -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.model.BGResourceRelation; import org.olat.repository.async.BackgroundTaskQueueManager; @@ -106,6 +104,7 @@ public class RepositoryManager extends BasicManager { private ImageHelper imageHelper; private static BackgroundTaskQueueManager taskQueueManager; private UserCourseInformationsManager userCourseInformationsManager; + private BusinessGroupService businessGroupService; private DB dbInstance; /** @@ -124,7 +123,15 @@ public class RepositoryManager extends BasicManager { public void setUserCourseInformationsManager(UserCourseInformationsManager userCourseInformationsManager) { this.userCourseInformationsManager = userCourseInformationsManager; } - + + /** + * [used by Spring] + * @param businessGroupService + */ + public void setBusinessGroupService(BusinessGroupService businessGroupService) { + this.businessGroupService = businessGroupService; + } + /** * [used by Spring] * @param userCourseInformationsManager @@ -1553,7 +1560,7 @@ public class RepositoryManager extends BasicManager { * @param logger */ public void removeParticipants(Identity ureqIdentity, List<Identity> removeIdentities, RepositoryEntry re){ - List<BusinessGroup> groups = getCourseGroups(re); + List<BusinessGroup> groups = getCourseGroups(re); for (Identity identity : removeIdentities) { securityManager.removeIdentityFromSecurityGroup(identity, re.getParticipantGroup()); for(BusinessGroup group:groups) { @@ -1582,11 +1589,7 @@ public class RepositoryManager extends BasicManager { */ private List<BusinessGroup> getCourseGroups(RepositoryEntry repoEntry) { if("CourseModule".equals(repoEntry.getOlatResource().getResourceableTypeName())) { - //TODO gm - ICourse course = CourseFactory.loadCourse(repoEntry.getOlatResource()); - CourseGroupManager gm = course.getCourseEnvironment().getCourseGroupManager(); - List<BusinessGroup> groups = gm.getAllBusinessGroups(); - return groups; + return businessGroupService.findBusinessGroups(null, repoEntry.getOlatResource(), 0, -1); } return Collections.emptyList(); } diff --git a/src/main/java/org/olat/repository/_spring/repositoryContext.xml b/src/main/java/org/olat/repository/_spring/repositoryContext.xml index 360ec651ddd70ae14550d69a7c54f04cee30c9fe..737874e665704da150e238b00baf6da98e37cfce 100644 --- a/src/main/java/org/olat/repository/_spring/repositoryContext.xml +++ b/src/main/java/org/olat/repository/_spring/repositoryContext.xml @@ -27,6 +27,7 @@ <property name="userCourseInformationsManager" ref="userCourseInformationsManager"/> <property name="imageHelper" ref="imageHelper"/> <property name="dbInstance" ref="database"/> + <property name="businessGroupService" ref="businessGroupService"/> </bean> <!-- BackgroundTaskQueueManager for increment launch-,download-counter and set LastUsage in background thread --> 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 6d0f9d9096a408ebe4d34a299e2cbd0bae8e6279..fbdc4267294c8beb2ab27b806f7b44c3423a33d0 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,7 @@ import org.olat.core.commons.services.commentAndRating.UserCommentsManager; 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.BGContextImpl; import org.olat.portfolio.PortfolioModule; import org.olat.portfolio.manager.EPFrontendManager; import org.olat.portfolio.model.artefacts.AbstractArtefact; @@ -459,8 +459,8 @@ public class OLATUpgrade_7_1_1 extends OLATUpgrade { private void migrateRepoEntrySecurityGroups(RepositoryEntry entry) { BaseSecurity securityManager = BaseSecurityManager.getInstance(); - List<BGContext> contexts = findBGContextsForResource(entry.getOlatResource(), true, true); - for(BGContext context:contexts) { + List<BGContextImpl> contexts = findBGContextsForResource(entry.getOlatResource(), true, true); + for(BGContextImpl context:contexts) { List<BusinessGroup> groups = getGroupsOfBGContext(context); for(BusinessGroup group:groups) { //migrate tutors @@ -501,10 +501,10 @@ public class OLATUpgrade_7_1_1 extends OLATUpgrade { } } - private List<BusinessGroup> getGroupsOfBGContext(BGContext bgContext) { - String q = "select bg from org.olat.group.BusinessGroupImpl bg where bg.groupContext = :context"; + private List<BusinessGroup> getGroupsOfBGContext(BGContextImpl bgContext) { + String q = "select bg from org.olat.group.BusinessGroupImpl bg where bg.groupContextKey = :contextKey"; DBQuery query = DBFactory.getInstance().createQuery(q); - query.setEntity("context", bgContext); + query.setLong("contextKey", bgContext.getKey()); @SuppressWarnings("unchecked") List<BusinessGroup> groups = query.list(); return groups; @@ -521,7 +521,7 @@ public class OLATUpgrade_7_1_1 extends OLATUpgrade { return entries; } - private List<BGContext> findBGContextsForResource(OLATResource resource, boolean defaultContexts, boolean nonDefaultContexts) { + private List<BGContextImpl> findBGContextsForResource(OLATResource resource, boolean defaultContexts, boolean nonDefaultContexts) { DB db = DBFactory.getInstance(); StringBuilder q = new StringBuilder(); q.append(" select context from org.olat.group.context.BGContextImpl as context,"); @@ -539,7 +539,7 @@ public class OLATUpgrade_7_1_1 extends OLATUpgrade { query.setBoolean("isDefault", defaultContexts ? true : false); } @SuppressWarnings("unchecked") - List<BGContext> contexts = query.list(); + List<BGContextImpl> contexts = query.list(); return contexts; } diff --git a/src/main/java/org/olat/upgrade/OLATUpgrade_8_2_0.java b/src/main/java/org/olat/upgrade/OLATUpgrade_8_2_0.java index d24b90a286b598cd3e9182b0b17090735d9528fb..d7e6c1fe01d232b61bfbb2f7309d394dec20f3ef 100644 --- a/src/main/java/org/olat/upgrade/OLATUpgrade_8_2_0.java +++ b/src/main/java/org/olat/upgrade/OLATUpgrade_8_2_0.java @@ -33,8 +33,20 @@ import org.olat.course.ICourse; import org.olat.course.Structure; import org.olat.course.condition.Condition; import org.olat.course.nodes.AbstractAccessableCourseNode; +import org.olat.course.nodes.AbstractFeedCourseNode; +import org.olat.course.nodes.BCCourseNode; +import org.olat.course.nodes.CalCourseNode; import org.olat.course.nodes.CourseNode; +import org.olat.course.nodes.DialogCourseNode; +import org.olat.course.nodes.FOCourseNode; import org.olat.course.nodes.GenericCourseNode; +import org.olat.course.nodes.InfoCourseNode; +import org.olat.course.nodes.PortfolioCourseNode; +import org.olat.course.nodes.ProjectBrokerCourseNode; +import org.olat.course.nodes.STCourseNode; +import org.olat.course.nodes.TACourseNode; +import org.olat.course.nodes.WikiCourseNode; +import org.olat.course.run.scoring.ScoreCalculator; import org.olat.course.tree.CourseEditorTreeModel; import org.olat.course.tree.CourseEditorTreeNode; import org.olat.group.BusinessGroup; @@ -190,21 +202,20 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade { try { List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, entry.getOlatResource(), 0, -1); List<BGArea> areas = areaManager.findBGAreasInContext(entry.getOlatResource()); - - + ICourse course = CourseFactory.loadCourse(entry.getOlatResource()); ProcessingOccured processingFlag = new ProcessingOccured(); - System.out.println("Start: " + course.getCourseTitle()); + log.info("Start: " + course.getCourseTitle()); Structure structure = course.getRunStructure(); processCourseRec(processingFlag, structure.getRootNode(), groups, areas); CourseEditorTreeModel editorTree = course.getEditorTreeModel(); processEditorCourseRec(processingFlag, editorTree.getRootNode(), groups, areas); if(processingFlag.isProcessed()) { opendedCourse = CourseFactory.openCourseEditSession(course.getResourceableId()); - System.out.println("Save of:" + course.getCourseTitle() + " (" + course.getResourceableId() + ")"); + log.info("Save of:" + course.getCourseTitle() + " (" + course.getResourceableId() + ")"); CourseFactory.saveCourse(opendedCourse.getResourceableId()); } else { - System.out.println("No change for: " + course.getCourseTitle() + " (" + course.getResourceableId() + ")"); + log.info("No change for: " + course.getCourseTitle() + " (" + course.getResourceableId() + ")"); } } catch (Exception e) { log.error("", e); @@ -237,6 +248,13 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade { } } + /** + * Update all the conditions in every type of course node + * @param processingFlag + * @param node + * @param groups + * @param areas + */ private void processCourseNode(ProcessingOccured processingFlag, CourseNode node, List<BusinessGroup> groups, List<BGArea> areas) { if(node instanceof GenericCourseNode) { @@ -244,8 +262,81 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade { processCondition(processingFlag, genericNode.getPreConditionAccess(), groups, areas); processCondition(processingFlag, genericNode.getPreConditionVisibility(), groups, areas); if(node instanceof AbstractAccessableCourseNode) { - //nothing + //nothing self but + if(node instanceof WikiCourseNode) { + WikiCourseNode wikiNode = (WikiCourseNode)node; + processCondition(processingFlag, wikiNode.getPreConditionEdit(), groups, areas); + } else if(node instanceof STCourseNode) { + STCourseNode structureNode = (STCourseNode)node; + ScoreCalculator calculator = structureNode.getScoreCalculator(); + String score = calculator.getScoreExpression(); + String passed = calculator.getPassedExpression(); + + boolean stProcessed = false; + if(StringHelper.containsNonWhitespace(score)) { + String processedExpression = processExpression(processingFlag, score, groups, areas); + if(!processedExpression.equals(score)) { + calculator.setScoreExpression(processedExpression); + stProcessed = true; + } + } + + if(StringHelper.containsNonWhitespace(passed)) { + String processedExpression = processExpression(processingFlag, passed, groups, areas); + if(!processedExpression.equals(score)) { + calculator.setScoreExpression(processedExpression); + stProcessed = true; + } + } + + if(stProcessed) { + structureNode.setScoreCalculator(calculator); + } + } else if (node instanceof PortfolioCourseNode) { + PortfolioCourseNode portfolioNode = (PortfolioCourseNode)node; + processCondition(processingFlag, portfolioNode.getPreConditionEdit(), groups, areas); + } else if (node instanceof InfoCourseNode) { + InfoCourseNode infoNode = (InfoCourseNode)node; + processCondition(processingFlag, infoNode.getPreConditionEdit(), groups, areas); + processCondition(processingFlag, infoNode.getPreConditionAdmin(), groups, areas); + } else if (node instanceof DialogCourseNode) { + DialogCourseNode dialogNode = (DialogCourseNode)node; + processCondition(processingFlag, dialogNode.getPreConditionModerator(), groups, areas); + processCondition(processingFlag, dialogNode.getPreConditionPoster(), groups, areas); + processCondition(processingFlag, dialogNode.getPreConditionReader(), groups, areas); + } else if (node instanceof CalCourseNode) { + CalCourseNode calNode = (CalCourseNode)node; + processCondition(processingFlag, calNode.getPreConditionEdit(), groups, areas); + } + } + if(node instanceof TACourseNode) { + TACourseNode taskNode = (TACourseNode)node; + processCondition(processingFlag, taskNode.getConditionDrop(), groups, areas); + processCondition(processingFlag, taskNode.getConditionReturnbox(), groups, areas); + processCondition(processingFlag, taskNode.getConditionScoring(), groups, areas); + processCondition(processingFlag, taskNode.getConditionSolution(), groups, areas); + processCondition(processingFlag, taskNode.getConditionTask(), groups, areas); + } else if(node instanceof ProjectBrokerCourseNode) { + ProjectBrokerCourseNode brokerNode = (ProjectBrokerCourseNode)node; + processCondition(processingFlag, brokerNode.getConditionDrop(), groups, areas); + processCondition(processingFlag, brokerNode.getConditionReturnbox(), groups, areas); + processCondition(processingFlag, brokerNode.getConditionScoring(), groups, areas); + processCondition(processingFlag, brokerNode.getConditionProjectBroker(), groups, areas); + } else if (node instanceof FOCourseNode) { + FOCourseNode forumNode = (FOCourseNode)node; + processCondition(processingFlag, forumNode.getPreConditionModerator(), groups, areas); + processCondition(processingFlag, forumNode.getPreConditionPoster(), groups, areas); + processCondition(processingFlag, forumNode.getPreConditionReader(), groups, areas); + } else if (node instanceof BCCourseNode) { + BCCourseNode bcNode = (BCCourseNode)node; + processCondition(processingFlag, bcNode.getPreConditionDownloaders(), groups, areas); + processCondition(processingFlag, bcNode.getPreConditionUploaders(), groups, areas); + } else if (node instanceof AbstractFeedCourseNode) { + AbstractFeedCourseNode feedNode = (AbstractFeedCourseNode)node; + processCondition(processingFlag, feedNode.getPreConditionModerator(), groups, areas); + processCondition(processingFlag, feedNode.getPreConditionPoster(), groups, areas); + processCondition(processingFlag, feedNode.getPreConditionReader(), groups, areas); } } } @@ -273,25 +364,32 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade { String expression = condition.getConditionExpression(); if(StringHelper.containsNonWhitespace(expression)) { String reference = condition.getConditionExpression(); - for(BusinessGroup group:groups) { - String strToMatch = "\"" + group.getName() + "\""; - String replacement = "\"" + group.getKey() + "\""; - expression = replaceAllCaseInsensitive(expression, strToMatch, replacement); - } - for(BGArea area:areas) { - String strToMatch = "\"" + area.getName() + "\""; - String replacement = "\"" + area.getKey() + "\""; - expression = replaceAllCaseInsensitive(expression, strToMatch, replacement); - } - - if(!reference.equals(expression)) { - condition.setConditionUpgraded(expression); + String processExpression = processExpression(processingFlag, expression, groups, areas); + if(!reference.equals(processExpression)) { + condition.setConditionUpgraded(processExpression); processingFlag.processed(); } } } } + private String processExpression(ProcessingOccured processingFlag, String expression, + List<BusinessGroup> groups, List<BGArea> areas) { + + for(BusinessGroup group:groups) { + String strToMatch = "\"" + group.getName() + "\""; + String replacement = "\"" + group.getKey() + "\""; + expression = replaceAllCaseInsensitive(expression, strToMatch, replacement); + } + for(BGArea area:areas) { + String strToMatch = "\"" + area.getName() + "\""; + String replacement = "\"" + area.getKey() + "\""; + expression = replaceAllCaseInsensitive(expression, strToMatch, replacement); + } + + return expression; + } + private String replaceAllCaseInsensitive(String expression, String name, String replacement) { String lcExpresion = expression.toLowerCase(); String lcName = name.toLowerCase(); diff --git a/src/main/java/org/olat/util/logging/activity/LoggingResourceable.java b/src/main/java/org/olat/util/logging/activity/LoggingResourceable.java index 443fc21a36f0780b5439eb8c535cfac4c34f955b..5bfa6ab80606fb1499072315c5fa617656cb54e8 100644 --- a/src/main/java/org/olat/util/logging/activity/LoggingResourceable.java +++ b/src/main/java/org/olat/util/logging/activity/LoggingResourceable.java @@ -41,11 +41,9 @@ import org.olat.core.logging.activity.OlatResourceableType; import org.olat.core.logging.activity.StringResourceableType; import org.olat.core.util.resource.OresHelper; import org.olat.course.ICourse; -import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.nodes.CourseNode; import org.olat.group.BusinessGroup; import org.olat.group.area.BGArea; -import org.olat.group.context.BGContext; import org.olat.group.ui.run.BusinessGroupMainRunController; import org.olat.modules.fo.Forum; import org.olat.modules.fo.ForumManager; @@ -93,8 +91,6 @@ public class LoggingResourceable implements ILoggingResourceable { /** the logging object used in this class **/ private static final OLog log_ = Tracing.createLoggerFor(LoggingResourceable.class); - private static final String DEFAULT_COURSE_GROUP_CONTEXT_NAME = "Default Course Group Context"; - /** the maximum number of bytes for the name field **/ public static final int MAX_NAME_LEN = 240; @@ -430,20 +426,6 @@ public class LoggingResourceable implements ILoggingResourceable { } } - /** - * Wraps a BGContext into a LoggingResourceable - setting type/id/name accordingly - * @param bgContext the bgContext to be wrapped - * @return a LoggingResourceable wrapping the given BGContext - */ - public static LoggingResourceable wrap(BGContext bgContext) { - String name = bgContext.getName(); - if (name.startsWith(CourseGroupManager.DEFAULT_NAME_LC_PREFIX)) { - name = DEFAULT_COURSE_GROUP_CONTEXT_NAME; - } - return new LoggingResourceable(bgContext, OlatResourceableType.bgContext, bgContext.getGroupType(), - String.valueOf(bgContext.getResourceableId()), name, false); - } - /** * Wraps a BusinessGroup into a LoggingResourceable - setting type/id/name accordingly * @param group the group to be wrapped