diff --git a/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsController.java b/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsController.java index 4c63bad060f53e861543570fa3c0b22e53dea27c..de0828de04f9d71bee702a7ddd332915211154b6 100644 --- a/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsController.java +++ b/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsController.java @@ -148,7 +148,7 @@ public class GroupsAndRightsController extends FormBasicController { private MultipleSelectionElement createSelection(boolean selected) { String name = "cb" + UUID.randomUUID().toString().replace("-", ""); - MultipleSelectionElement selection = new MultipleSelectionElementImpl(name, Layout.vertical); + MultipleSelectionElement selection = new MultipleSelectionElementImpl(name, Layout.horizontal); selection.setKeysAndValues(keys, values); flc.add(name, selection); selection.select(keys[0], selected); diff --git a/src/main/java/org/olat/upgrade/OLATUpgrade_10_0_0.java b/src/main/java/org/olat/upgrade/OLATUpgrade_10_0_0.java index 787a7f09a49c19a0a8e509401fddc016f6ad63ac..62f8d6d1a63d351e3f7e9bd7873bbaa174bc5cec 100644 --- a/src/main/java/org/olat/upgrade/OLATUpgrade_10_0_0.java +++ b/src/main/java/org/olat/upgrade/OLATUpgrade_10_0_0.java @@ -21,7 +21,6 @@ package org.olat.upgrade; import java.io.File; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Date; import java.util.HashSet; import java.util.List; @@ -46,7 +45,6 @@ import org.olat.core.util.WebappHelper; import org.olat.group.BusinessGroupService; import org.olat.group.manager.BusinessGroupRelationDAO; import org.olat.group.right.BGRightManager; -import org.olat.group.right.BGRightsRole; import org.olat.portfolio.manager.EPMapPolicy; import org.olat.properties.Property; import org.olat.properties.PropertyManager; @@ -195,8 +193,7 @@ public class OLATUpgrade_10_0_0 extends OLATUpgrade { do { businessGroups = findBusinessGroups(counter, BATCH_SIZE); for(BusinessGroupUpgrade businessGroup:businessGroups) { - BusinessGroupUpgrade up = processBusinessGroup(businessGroup); - processRightGroup(up); + processBusinessGroup(businessGroup); } counter += businessGroups.size(); log.audit("Business groups processed: " + businessGroups.size() + ", total processed (" + counter + ")"); @@ -230,38 +227,6 @@ public class OLATUpgrade_10_0_0 extends OLATUpgrade { dbInstance.commit(); return businessGroup; } - - private void processRightGroup(BusinessGroupUpgrade businessGroup) { - boolean commit = false; - - List<String> tutorRights = findBGRights(businessGroup.getOwnerGroup()); - for(String right:tutorRights) { - bgRightManager.addBGRight(right, businessGroup, BGRightsRole.tutor); - commit = true; - } - - List<String> participantsRights = findBGRights(businessGroup.getPartipiciantGroup()); - for(String right:participantsRights) { - bgRightManager.addBGRight(right, businessGroup, BGRightsRole.participant); - commit = true; - } - - if(commit) { - dbInstance.commit(); - } - } - - private List<String> findBGRights(SecurityGroup secGroup) { - List<Policy> results = securityManager.getPoliciesOfSecurityGroup(secGroup); - // filter all business group rights permissions. group right permissions - // start with bgr. - List<String> rights = new ArrayList<String>(); - for (Policy rightPolicy:results) { - String right = rightPolicy.getPermission(); - if (right.indexOf("bgr.") == 0) rights.add(right); - } - return rights; - } private boolean upgradeRepositoryEntries(UpgradeManager upgradeManager, UpgradeHistoryData uhd) { if (!uhd.getBooleanDataValue(TASK_REPOENTRIES)) { diff --git a/src/main/java/org/olat/upgrade/OLATUpgrade_10_0_3.java b/src/main/java/org/olat/upgrade/OLATUpgrade_10_0_3.java new file mode 100644 index 0000000000000000000000000000000000000000..0c65f57cf28b16571411d8e18b6821f08628e6e3 --- /dev/null +++ b/src/main/java/org/olat/upgrade/OLATUpgrade_10_0_3.java @@ -0,0 +1,186 @@ +/** + * <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.upgrade; + +import java.util.ArrayList; +import java.util.List; + +import org.olat.admin.layout.LayoutModule; +import org.olat.basesecurity.BaseSecurity; +import org.olat.basesecurity.Policy; +import org.olat.basesecurity.SecurityGroup; +import org.olat.basesecurity.manager.GroupDAO; +import org.olat.core.commons.persistence.DB; +import org.olat.group.BusinessGroupService; +import org.olat.group.manager.BusinessGroupRelationDAO; +import org.olat.group.right.BGRightManager; +import org.olat.group.right.BGRightsRole; +import org.olat.properties.PropertyManager; +import org.olat.repository.RepositoryManager; +import org.olat.repository.manager.RepositoryEntryRelationDAO; +import org.olat.upgrade.model.BusinessGroupUpgrade; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * + * Initial date: 27.02.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class OLATUpgrade_10_0_3 extends OLATUpgrade { + + private static final int BATCH_SIZE = 50; + private static final String TASK_BUSINESS_GROUPS = "Upgrade rights groups"; + private static final String VERSION = "OLAT_10.0.3"; + + + + @Autowired + private DB dbInstance; + @Autowired + private BaseSecurity securityManager; + @Autowired + private GroupDAO groupDao; + @Autowired + private RepositoryManager repositoryManager; + @Autowired + private BGRightManager bgRightManager; + @Autowired + private BusinessGroupRelationDAO businessGroupRelationDao; + @Autowired + private RepositoryEntryRelationDAO repositoryEntryToGroupDAO; + @Autowired + private BusinessGroupService businessGroupService; + @Autowired + private PropertyManager propertyManager; + @Autowired + private LayoutModule layoutModule; + + public OLATUpgrade_10_0_3() { + super(); + } + + @Override + public String getVersion() { + return VERSION; + } + + @Override + public boolean doPreSystemInitUpgrade(UpgradeManager upgradeManager) { + return false; + } + + @Override + public boolean doPostSystemInitUpgrade(UpgradeManager upgradeManager) { + UpgradeHistoryData uhd = upgradeManager.getUpgradesHistory(VERSION); + if (uhd == null) { + // has never been called, initialize + uhd = new UpgradeHistoryData(); + } else if (uhd.isInstallationComplete()) { + return false; + } + + boolean allOk = true; + allOk &= upgradeBusinessGroups(upgradeManager, uhd); + + uhd.setInstallationComplete(allOk); + upgradeManager.setUpgradesHistory(uhd, VERSION); + if(allOk) { + log.audit("Finished OLATUpgrade_10_0_3 successfully!"); + } else { + log.audit("OLATUpgrade_10_0_3 not finished, try to restart OpenOLAT!"); + } + return allOk; + } + + private boolean upgradeBusinessGroups(UpgradeManager upgradeManager, UpgradeHistoryData uhd) { + if (!uhd.getBooleanDataValue(TASK_BUSINESS_GROUPS)) { + int counter = 0; + List<BusinessGroupUpgrade> businessGroups; + do { + businessGroups = findBusinessGroups(counter, BATCH_SIZE); + for(BusinessGroupUpgrade businessGroup:businessGroups) { + processRightGroup(businessGroup); + } + counter += businessGroups.size(); + log.audit("Rights groups processed: " + businessGroups.size() + ", total processed (" + counter + ")"); + dbInstance.commitAndCloseSession(); + } while(businessGroups.size() == BATCH_SIZE); + uhd.setBooleanDataValue(TASK_BUSINESS_GROUPS, true); + upgradeManager.setUpgradesHistory(uhd, VERSION); + } + return true; + } + + private void processRightGroup(BusinessGroupUpgrade businessGroup) { + boolean commit = false; + + List<String> tutorRights = findBGRights(businessGroup.getOwnerGroup()); + List<String> currentTutorRights = bgRightManager.findBGRights(businessGroup, BGRightsRole.tutor); + tutorRights.removeAll(currentTutorRights); + for(String right:tutorRights) { + bgRightManager.addBGRight(right, businessGroup, BGRightsRole.tutor); + commit = true; + } + + List<String> participantsRights = findBGRights(businessGroup.getPartipiciantGroup()); + List<String> currentParticipantsRights = bgRightManager.findBGRights(businessGroup, BGRightsRole.participant); + participantsRights.removeAll(currentParticipantsRights); + for(String right:participantsRights) { + bgRightManager.addBGRight(right, businessGroup, BGRightsRole.participant); + commit = true; + } + + if(commit) { + dbInstance.commit(); + } + } + + private List<String> findBGRights(SecurityGroup secGroup) { + List<Policy> results = securityManager.getPoliciesOfSecurityGroup(secGroup); + // filter all business group rights permissions. group right permissions + // start with bgr. + List<String> rights = new ArrayList<String>(); + for (Policy rightPolicy:results) { + String right = rightPolicy.getPermission(); + if (right.indexOf("bgr.") == 0) rights.add(right); + } + return rights; + } + + private List<BusinessGroupUpgrade> findBusinessGroups(int firstResult, int maxResults) { + StringBuilder sb = new StringBuilder(); + sb.append("select businessgroup from ").append(BusinessGroupUpgrade.class.getName()).append(" businessgroup") + .append(" left join fetch businessgroup.baseGroup as baseGroup") + .append(" left join fetch businessgroup.ownerGroup as ownerGroup") + .append(" left join fetch businessgroup.partipiciantGroup as partipiciantGroup") + .append(" left join fetch businessgroup.waitingGroup as waitingGroup") + .append(" left join fetch businessgroup.resource as resource") + .append(" order by businessgroup.key"); + return dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BusinessGroupUpgrade.class) + .setFirstResult(firstResult) + .setMaxResults(maxResults) + .getResultList(); + } + + + + +} diff --git a/src/main/java/org/olat/upgrade/_spring/upgradeContext.xml b/src/main/java/org/olat/upgrade/_spring/upgradeContext.xml index 5d6b04750104af1b1425eb7cdf09e60167bb1276..6aca92e0cdaa7b9bada90639c955bb86137224c3 100644 --- a/src/main/java/org/olat/upgrade/_spring/upgradeContext.xml +++ b/src/main/java/org/olat/upgrade/_spring/upgradeContext.xml @@ -41,6 +41,7 @@ <bean id="upgrade_9_0_0" class="org.olat.upgrade.OLATUpgrade_9_0_0"/> <bean id="upgrade_9_4_0" class="org.olat.upgrade.OLATUpgrade_9_4_0"/> <bean id="upgrade_10_0_0" class="org.olat.upgrade.OLATUpgrade_10_0_0"/> + <bean id="upgrade_10_0_3" class="org.olat.upgrade.OLATUpgrade_10_0_3"/> </list> </property> </bean>