diff --git a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java index 565214868579e559439e3c2612771f3a3ced1855..20c96933dcfbee5fb0cfa2b21fb3961a6f42cd10 100644 --- a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java +++ b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java @@ -26,10 +26,8 @@ package org.olat.course.nodes.projectbroker.service; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Set; import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.SecurityGroup; @@ -196,23 +194,9 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou * If the goup-name already exist, it will be automatically try another one with suffix e.g. ' _2' * @see org.olat.course.nodes.projectbroker.service.ProjectGroupManager#changeProjectGroupName(org.olat.group.BusinessGroup, java.lang.String, java.lang.String) */ - public BusinessGroup changeProjectGroupName(BusinessGroup projectGroup, String initialGroupName, String groupDescription, OLATResource courseResource) { + public BusinessGroup changeProjectGroupName(BusinessGroup projectGroup, String groupName, String groupDescription, OLATResource courseResource) { BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); BusinessGroup reloadedBusinessGroup = bgs.loadBusinessGroup(projectGroup); - logDebug("initialGroupName=" + initialGroupName); - String groupName = initialGroupName; - Set<String> names = new HashSet<String>(); - names.add(groupName); - int counter = 2; - while (bgs.checkIfOneOrMoreNameExists(names, courseResource)) { - // a group with name already exist => look for an other one, append a number - groupName = initialGroupName + " _" + counter++ ; - logDebug("try groupName=" + groupName); - names = new HashSet<String>(); - names.add(groupName); - - } - logDebug("groupName=" + groupName); return bgs.updateBusinessGroup(reloadedBusinessGroup, groupName, groupDescription, reloadedBusinessGroup.getMinParticipants(), reloadedBusinessGroup.getMaxParticipants()); } diff --git a/src/main/java/org/olat/group/BusinessGroupService.java b/src/main/java/org/olat/group/BusinessGroupService.java index c09249c7f18ae64e5156075884acf01ff5f4e190..c92bcb993bdc1efd3e1cd004e4ef96f3cbe7cbf1 100644 --- a/src/main/java/org/olat/group/BusinessGroupService.java +++ b/src/main/java/org/olat/group/BusinessGroupService.java @@ -88,8 +88,8 @@ public interface BusinessGroupService { * @param resource * @return */ - public Set<BusinessGroup> createUniqueBusinessGroupsFor(Set<String> allNames, String description, Integer minParticipants, Integer maxParticipants, - boolean waitingListEnabled, boolean autoCloseRanksEnabled, OLATResource resource); + //public Set<BusinessGroup> createUniqueBusinessGroupsFor(Set<String> allNames, String description, Integer minParticipants, Integer maxParticipants, + // boolean waitingListEnabled, boolean autoCloseRanksEnabled, OLATResource resource); /** * Update the business group with the supplied arguments and do it in sync @@ -255,11 +255,6 @@ public interface BusinessGroupService { public List<BusinessGroup> findBusinessGroups(SearchBusinessGroupParams params, OLATResource resource, int firstResult, int maxResults); public List<Long> toGroupKeys(String groupNames, OLATResource resource); - - //check - public boolean checkIfOneOrMoreNameExists(Set<String> names, OLATResource resource); - - public boolean checkIfOneOrMoreNameExists(Set<String> names, BusinessGroup group); //retrieve repository entries diff --git a/src/main/java/org/olat/group/area/BGAreaManager.java b/src/main/java/org/olat/group/area/BGAreaManager.java index f7d04999bc63c01f6f27385e5c0b249db36e76ac..240de2c14f94d496338b370d7afc2fe3802ad3d1 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.Set; import org.olat.core.id.Identity; import org.olat.group.BusinessGroup; @@ -51,7 +50,7 @@ public interface BGAreaManager { * @param resource The resource of this area * @return The new area or null if no area has been created */ - public abstract BGArea createAndPersistBGAreaIfNotExists(String areaName, String description, OLATResource resource); + public abstract BGArea createAndPersistBGArea(String areaName, String description, OLATResource resource); /** * Finds an area in the given context @@ -82,7 +81,7 @@ public interface BGAreaManager { * @param area * @return the updated area */ - public abstract BGArea updateBGArea(BGArea area); + public BGArea updateBGArea(BGArea area); /** * Delete the given area form the database @@ -207,16 +206,8 @@ public interface BGAreaManager { * @param area * @return The reloaded area */ - public abstract BGArea reloadArea(BGArea area); + public BGArea reloadArea(BGArea area); - /** - * checks if one or more of the given names exists already in the context. - * @param allNames - * @param bgContext - * @return - */ - public abstract boolean checkIfOneOrMoreNameExistsInContext(Set<String> allNames, OLATResource resource); - /** * Check if an area exist with this anem or this primary key within the * context of the resource diff --git a/src/main/java/org/olat/group/area/BGAreaManagerImpl.java b/src/main/java/org/olat/group/area/BGAreaManagerImpl.java index 8761315c2633ddc53f30ecc4e9f3b41d4a3e869a..67f9f840a30265df9bdcca8faa45d505b984115e 100644 --- a/src/main/java/org/olat/group/area/BGAreaManagerImpl.java +++ b/src/main/java/org/olat/group/area/BGAreaManagerImpl.java @@ -30,7 +30,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; -import java.util.Set; import javax.persistence.TypedQuery; @@ -64,24 +63,6 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { @Autowired private BusinessGroupArchiver businessGroupArchiver; - - /** - * @see org.olat.group.area.BGAreaManager#createAndPersistBGAreaIfNotExists(java.lang.String, - * java.lang.String, org.olat.group.context.BGContext) - */ - //o_clusterOK by:cg synchronized on resource - public BGArea createAndPersistBGAreaIfNotExists(final String areaName, final String description, final OLATResource resource) { - BGArea createdBGArea =CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(resource, new SyncerCallback<BGArea>(){ - public BGArea execute() { - BGArea area = findBGArea(areaName, resource); - if (area == null) { - return createAndPersistBGArea(areaName, description, resource); - } - return null; - } - }); - return createdBGArea; - } @Override public BGArea loadArea(Long key) { @@ -134,20 +115,10 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { BGArea updatedBGArea =CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(resource, new SyncerCallback<BGArea>(){ public BGArea execute() { - BGArea douplicate = findBGArea(area.getName(), resource); - if (douplicate == null) { - // does not exist, so just update it - dbInstance.updateObject(area); - return area; - } else if (douplicate.getKey().equals(area.getKey())) { - // name already exists, found the same object (name didn't change) - // need to copy description (that has changed) and update the object. - // if we updated area at this place we would get a hibernate exception - douplicate.setDescription(area.getDescription()); - dbInstance.updateObject(douplicate); - return douplicate; - } - return null; // nothing updated + BGArea reloadArea = loadArea(area.getKey()); + reloadArea.setName(area.getName()); + reloadArea.setDescription(area.getDescription()); + return dbInstance.getCurrentEntityManager().merge(reloadArea); } }); return updatedBGArea; @@ -162,7 +133,7 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(resource, new SyncerExecutor(){ public void execute() { - BGArea reloadArea = findBGArea(area.getName(), resource); + BGArea reloadArea = loadArea(area.getKey()); if (reloadArea != null) { // 1) delete all area - group relations deleteBGtoAreaRelations(reloadArea); @@ -369,21 +340,6 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { return (BGArea) DBFactory.getInstance().loadObject(area); } - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> allNames, OLATResource resource) { - if(allNames == null || allNames.isEmpty()) { - return false; - } - - StringBuilder sb = new StringBuilder(); - sb.append("select count(area) from ").append(BGAreaImpl.class.getName()).append(" area where area.resource.key=:resourceKey and area.name in (:names)"); - Number count = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Number.class) - .setParameter("resourceKey", resource.getKey()) - .setParameter("names", allNames) - .setHint("org.hibernate.cacheable", Boolean.TRUE) - .getSingleResult(); - return count.intValue() > 0; - } - @Override public boolean existArea(String nameOrKey, OLATResource resource) { Long key = null; @@ -443,7 +399,8 @@ public class BGAreaManagerImpl extends BasicManager implements BGAreaManager { * @param resource The resource of this area * @return The new area */ - private BGArea createAndPersistBGArea(String areaName, String description, OLATResource resource) { + @Override + public BGArea createAndPersistBGArea(String areaName, String description, OLATResource resource) { BGArea area = new BGAreaImpl(areaName, description, resource); dbInstance.getCurrentEntityManager().persist(area); if (area != null) { diff --git a/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java b/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java index e2c6ad8926779256c96ec45907cb6eafd873be14..092ffe8d01cb7a93b7fd6b59e04fae906601d7cc 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java @@ -211,7 +211,7 @@ public class BusinessGroupImportExport { for (Area area : groupConfig.getAreas().getGroups()) { String areaName = area.name; String areaDesc = (area.description != null && !area.description.isEmpty()) ? area.description.get(0) : ""; - BGArea newArea = areaManager.createAndPersistBGAreaIfNotExists(areaName, areaDesc, resource); + BGArea newArea = areaManager.createAndPersistBGArea(areaName, areaDesc, resource); if(areaSet.add(newArea)) { env.getAreas().add(new BGAreaReference(newArea, area.key, area.name)); } diff --git a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java index 6ea1eb90d6484db3bcf9b44b8633ee74ac8b8fa7..fd91eca1f1f4d409570d55072b5ca24a6cca70ec 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; @@ -182,41 +181,6 @@ public class BusinessGroupRelationDAO { return db; } - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, OLATResource resource) { - return checkIfOneOrMoreNameExistsInContext(names, Collections.singletonList(resource.getKey())); - } - - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, BusinessGroup group) { - if(names == null || names.isEmpty()) return false; - - StringBuilder sb = new StringBuilder(); - sb.append("select rel.resource.key from ").append(BGResourceRelation.class.getName()).append(" as rel ") - .append(" inner join rel.group bgs ") - .append(" where bgs.key=:groupKey"); - - List<Long> resourceKeys = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Long.class) - .setParameter("groupKey", group.getKey()) - .getResultList(); - - return checkIfOneOrMoreNameExistsInContext(names, resourceKeys); - } - - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, List<Long> resourceKeys) { - if(resourceKeys == null || resourceKeys.isEmpty()) return false; - if(names == null || names.isEmpty()) return false; - - StringBuilder sb = new StringBuilder(); - sb.append("select count(bgs) from ").append(BGResourceRelation.class.getName()).append(" as rel ") - .append(" inner join rel.group bgs ") - .append(" where rel.resource.key in (:resourceKey) and bgs.name in (:names)"); - - Number count = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Number.class) - .setParameter("resourceKey", resourceKeys) - .setParameter("names", names) - .getSingleResult(); - return count.intValue() > 0; - } - public int countResources(BusinessGroup group) { if(group == null) return 0; StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java index 403e35df3e47281f571a6ddfd809e4af4c7b92cf..0be624c8bcf78b431d59fcfff49b23af6f68a2a9 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java @@ -24,12 +24,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; import javax.annotation.PostConstruct; @@ -181,19 +179,9 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD public BusinessGroup createBusinessGroup(Identity creator, String name, String description, Integer minParticipants, Integer maxParticipants, boolean waitingListEnabled, boolean autoCloseRanksEnabled, OLATResource resource) { - - if(resource != null) { - boolean groupExists = businessGroupRelationDAO.checkIfOneOrMoreNameExistsInContext(Collections.singleton(name), resource); - if (groupExists) { - // there is already a group with this name, return without creating a new group - log.warn("A group with this name already exists! You will get null instead of a businessGroup returned!"); - return null; - } - } - + BusinessGroup group = businessGroupDAO.createAndPersist(creator, name, description, minParticipants, maxParticipants, waitingListEnabled, autoCloseRanksEnabled, false, false, false); - if(resource instanceof OLATResourceImpl) { businessGroupRelationDAO.addRelationToResource(group, resource); //add coach and participant permission @@ -202,32 +190,6 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD } return group; } - - @Override - public Set<BusinessGroup> createUniqueBusinessGroupsFor(final Set<String> allNames, final String description, - final Integer minParticipants, final Integer maxParticipants, final boolean waitingListEnabled, final boolean autoCloseRanksEnabled, - final OLATResource resource) { - - //o_clusterOK by:cg - Set<BusinessGroup> createdGroups = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(resource, new SyncerCallback<Set<BusinessGroup>>(){ - public Set<BusinessGroup> execute() { - if(checkIfOneOrMoreNameExists(allNames, resource)){ - // set error of non existing name - return null; - } else { - // create bulkgroups only if there is no name which already exists. - Set<BusinessGroup> newGroups = new HashSet<BusinessGroup>(); - for (String name : allNames) { - BusinessGroup newGroup = createBusinessGroup(null, name, description, minParticipants, maxParticipants, - waitingListEnabled, autoCloseRanksEnabled, resource); - newGroups.add(newGroup); - } - return newGroups; - } - } - }); - return createdGroups; - } @Override @Transactional @@ -347,16 +309,6 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD public List<BusinessGroup> loadAllBusinessGroups() { return businessGroupDAO.loadAll(); } - - @Override - public boolean checkIfOneOrMoreNameExists(Set<String> names, OLATResource resource) { - return businessGroupRelationDAO.checkIfOneOrMoreNameExistsInContext(names, resource); - } - - @Override - public boolean checkIfOneOrMoreNameExists(Set<String> names, BusinessGroup group) { - return businessGroupRelationDAO.checkIfOneOrMoreNameExistsInContext(names, group); - } @Override public BusinessGroup copyBusinessGroup(BusinessGroup sourceBusinessGroup, String targetName, String targetDescription, Integer targetMin, diff --git a/src/main/java/org/olat/group/ui/BusinessGroupFormController.java b/src/main/java/org/olat/group/ui/BusinessGroupFormController.java index 0dea7ac77cab177a35302a74245f1fa1fbbab03e..38b59a5c7686d7c39c125b60be9799f93ccf59e1 100644 --- a/src/main/java/org/olat/group/ui/BusinessGroupFormController.java +++ b/src/main/java/org/olat/group/ui/BusinessGroupFormController.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Set; import org.olat.basesecurity.BaseSecurityManager; -import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItemContainer; import org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement; @@ -40,7 +39,6 @@ import org.olat.core.id.context.BusinessControlFactory; import org.olat.core.id.context.ContextEntry; import org.olat.core.util.StringHelper; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupService; /** * Implements a Business group creation dialog using FlexiForms. @@ -97,8 +95,6 @@ public class BusinessGroupFormController extends FormBasicController { /** The value for the autoCloseRanks checkbox. */ private final String[] autoCloseValues = new String[] { translate("create.form.enableAutoCloseRanks") }; - private final BusinessGroupService businessGroupService; - /** * Creates this controller. * @@ -110,7 +106,6 @@ public class BusinessGroupFormController extends FormBasicController { public BusinessGroupFormController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup) { super(ureq, wControl, FormBasicController.LAYOUT_DEFAULT); this.businessGroup = businessGroup; - businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); initForm(ureq); } @@ -126,7 +121,6 @@ public class BusinessGroupFormController extends FormBasicController { super(ureq, wControl, FormBasicController.LAYOUT_DEFAULT); this.businessGroup = businessGroup; this.bulkMode = bulkMode; - businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); initForm(ureq); // depends on bulkMode flag } @@ -309,35 +303,12 @@ public class BusinessGroupFormController extends FormBasicController { } businessGroupMaximumMembers.clearError(); } - - //7) check for name duplication - if(checkIfDuplicateGroupName()) { - businessGroupName.setErrorKey("error.group.name.exists", new String[] {}); - return false; - } // group name duplication test passed businessGroupName.clearError(); // all checks passed return true; } - - /** - * Checks if this a learning group or right group, - * if the group name changes, - * and if the name is already used in this context. - * @return - */ - private boolean checkIfDuplicateGroupName() { - Set<String> names = new HashSet<String>(); - names.add(businessGroupName.getValue()); - //group name changes to an already used name, and is a learning group - if(businessGroup!=null && !businessGroup.getName().equals(businessGroupName.getValue()) - && businessGroupService.checkIfOneOrMoreNameExists(names, businessGroup)) { - return true; - } - return false; - } /** * @param name @@ -393,18 +364,6 @@ public class BusinessGroupFormController extends FormBasicController { } } - /** - * @param nonexistingnames - */ - public void setGroupNameExistsError(Set<String> nonexistingnames) { - if (nonexistingnames == null || nonexistingnames.size() == 0) { - businessGroupName.setErrorKey("error.group.name.exists", new String[] {}); - } else { - String[] args = new String[] { StringHelper.formatAsCSVString(nonexistingnames) }; - businessGroupName.setErrorKey("error.group.name.exists", args); - } - } - /** * @return */ diff --git a/src/main/java/org/olat/group/ui/NewAreaController.java b/src/main/java/org/olat/group/ui/NewAreaController.java index b46c2e052375b090c59c034e7bb873e43113316a..08a3d62a1c1985cf7e16a842fc0791489e81b297 100644 --- a/src/main/java/org/olat/group/ui/NewAreaController.java +++ b/src/main/java/org/olat/group/ui/NewAreaController.java @@ -26,7 +26,6 @@ package org.olat.group.ui; import java.util.ArrayList; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -129,29 +128,22 @@ public class NewAreaController extends BasicController { allNames.add(this.areaCreateController.getAreaName()); } - if(areaManager.checkIfOneOrMoreNameExistsInContext(allNames, resource)){ - // set error of non existing name - this.areaCreateController.setAreaNameExistsError(null); - } else { - Codepoint.codepoint(this.getClass(), "createArea"); - // create bulkgroups only if there is no name which already exists. - newAreas = new HashSet<BGArea>(); - newAreaNames = new HashSet<String>(); - for (Iterator<String> iter = allNames.iterator(); iter.hasNext();) { - String areaName = iter.next(); - BGArea newArea = areaManager.createAndPersistBGAreaIfNotExists(areaName, areaDesc, resource); - newAreas.add(newArea); - newAreaNames.add(areaName); - } - // do loggin if ual given - for (Iterator<BGArea> iter = newAreas.iterator(); iter.hasNext();) { - BGArea a = iter.next(); - ThreadLocalUserActivityLogger.log(GroupLoggingAction.AREA_CREATED, getClass(), LoggingResourceable.wrap(a)); - } - // workflow successfully finished - // so far no events on the systembus to inform about new groups in BGContext - fireEvent(ureq, Event.DONE_EVENT); + Codepoint.codepoint(this.getClass(), "createArea"); + // create bulkgroups only if there is no name which already exists. + newAreas = new HashSet<BGArea>(); + newAreaNames = new HashSet<String>(); + for (String areaName : allNames) { + BGArea newArea = areaManager.createAndPersistBGArea(areaName, areaDesc, resource); + newAreas.add(newArea); + newAreaNames.add(areaName); } + // do loggin if ual given + for (BGArea area:newAreas) { + ThreadLocalUserActivityLogger.log(GroupLoggingAction.AREA_CREATED, getClass(), LoggingResourceable.wrap(area)); + } + // workflow successfully finished + // so far no events on the systembus to inform about new groups in BGContext + fireEvent(ureq, Event.DONE_EVENT); } else if (event == Event.CANCELLED_EVENT) { // workflow cancelled fireEvent(ureq, Event.CANCELLED_EVENT); diff --git a/src/main/java/org/olat/group/ui/NewBGController.java b/src/main/java/org/olat/group/ui/NewBGController.java index 38a7d6bef98fb94eb678f85c34e5e4875ed74531..740857e7f0026154f5dac875c54ecc1f9404ddd6 100644 --- a/src/main/java/org/olat/group/ui/NewBGController.java +++ b/src/main/java/org/olat/group/ui/NewBGController.java @@ -24,8 +24,10 @@ */ package org.olat.group.ui; +import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Set; import org.olat.core.CoreSpringFactory; @@ -122,14 +124,18 @@ public class NewBGController extends BasicController { boolean enableWaitingList = groupCreateController.isWaitingListEnabled(); boolean enableAutoCloseRanks = groupCreateController.isAutoCloseRanksEnabled(); - Set<String> allNames = new HashSet<String>(); + List<BusinessGroup> newGroups = new ArrayList<BusinessGroup>(); if (bulkMode) { - allNames = groupCreateController.getGroupNames(); + for(String bgName:groupCreateController.getGroupNames()) { + BusinessGroup group = businessGroupService.createBusinessGroup(null, bgName, bgDesc, bgMin, bgMax, enableWaitingList, enableAutoCloseRanks, resource); + newGroups.add(group); + } } else { - allNames.add(groupCreateController.getGroupName()); + String bgName = groupCreateController.getGroupName(); + BusinessGroup group = businessGroupService.createBusinessGroup(null, bgName, bgDesc, bgMin, bgMax, enableWaitingList, enableAutoCloseRanks, resource); + newGroups.add(group); } - newGroups = businessGroupService.createUniqueBusinessGroupsFor(allNames, bgDesc, bgMin, bgMax, enableWaitingList, enableAutoCloseRanks, resource); if(newGroups != null){ for (BusinessGroup bg: newGroups) { LoggingResourceable resourceInfo = LoggingResourceable.wrap(bg); @@ -138,9 +144,6 @@ public class NewBGController extends BasicController { // workflow successfully finished // so far no events on the systembus to inform about new groups in BGContext fireEvent(ureq, Event.DONE_EVENT); - } else { - // Could not create any group, because one or groups-name already exist. Set error of non existing name - this.groupCreateController.setGroupNameExistsError(null); } } else if (event == Event.CANCELLED_EVENT) { // workflow cancelled diff --git a/src/main/java/org/olat/group/ui/area/BGAreaFormController.java b/src/main/java/org/olat/group/ui/area/BGAreaFormController.java index b8d8028f9137fcd4dc57a8a72e25118ff13ed37a..715d3eeb324498929a776ba8bddf25ae1bd0c68e 100644 --- a/src/main/java/org/olat/group/ui/area/BGAreaFormController.java +++ b/src/main/java/org/olat/group/ui/area/BGAreaFormController.java @@ -78,7 +78,7 @@ public class BGAreaFormController extends FormBasicController { * org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest) */ @Override - protected void initForm(FormItemContainer formLayout, @SuppressWarnings("unused") Controller listener, UserRequest ureq) { + protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { // add the name field name = uifactory.addTextElement("area.form.name", "area.form.name", 255, "", formLayout); name.setMandatory(true); @@ -107,7 +107,7 @@ public class BGAreaFormController extends FormBasicController { * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#validateFormLogic(org.olat.core.gui.UserRequest) */ @Override - protected boolean validateFormLogic(@SuppressWarnings("unused") UserRequest ureq) { + protected boolean validateFormLogic(UserRequest ureq) { // check name first if (!StringHelper.containsNonWhitespace(this.name.getValue())) { name.setErrorKey("form.legende.mandatory", new String[] {}); @@ -199,15 +199,6 @@ public class BGAreaFormController extends FormBasicController { name.setValue(areaName); } - /** - * Displays an error message that this group already exists. - * - * @param object <i>(unused)</i> - */ - public void setAreaNameExistsError(@SuppressWarnings("unused") Object object) { - name.setErrorKey("error.area.name.exists", new String[] {}); - } - /** * Gets the description text. * 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 8baddf6ea8448f4f4ba856e8adb255bdaf4236cb..ca06cbcff2f3f9dc52d1322f991b1ea0617b15f4 100644 --- a/src/main/java/org/olat/group/ui/wizard/BGCopyWizardController.java +++ b/src/main/java/org/olat/group/ui/wizard/BGCopyWizardController.java @@ -89,17 +89,12 @@ public class BGCopyWizardController extends WizardController { public void event(UserRequest ureq, Controller source, Event event) { if (source == this.groupController) { if (event == Event.DONE_EVENT) { - BusinessGroup newGroup = doCopyGroup(); - if (newGroup == null) { - this.groupController.setGroupNameExistsError(null); - } else { - this.copiedGroup = newGroup; - // finished event - fireEvent(ureq, Event.DONE_EVENT); - // do logging - ThreadLocalUserActivityLogger.log(GroupLoggingAction.BG_GROUP_COPIED, getClass(), - LoggingResourceable.wrap(originalGroup), LoggingResourceable.wrap(copiedGroup)); - } + copiedGroup = doCopyGroup(); + // finished event + fireEvent(ureq, Event.DONE_EVENT); + // do logging + ThreadLocalUserActivityLogger.log(GroupLoggingAction.BG_GROUP_COPIED, getClass(), + LoggingResourceable.wrap(originalGroup), LoggingResourceable.wrap(copiedGroup)); } } else if (source == copyForm) { 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 73319b1381becc942722dbd862e996470bebd20b..5500bb2ed19684de4c0a040f08ae9c73078ed93b 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 @@ -267,7 +267,7 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade { List<Long> resourcesGroupKeys = findBusinessGroupsOfResource(resource); BGArea existingArea = areaManager.findBGArea(area.getName(), resource); if(existingArea == null) { - BGArea copyArea = areaManager.createAndPersistBGAreaIfNotExists(area.getName(), area.getDescription(), resource); + BGArea copyArea = areaManager.createAndPersistBGArea(area.getName(), area.getDescription(), resource); for(BusinessGroup group:originalGroupList) { if(resourcesGroupKeys.contains(group.getKey())) { areaManager.addBGToBGArea(group, copyArea); diff --git a/src/test/java/org/olat/course/groupsandrights/CourseGroupManagementTest.java b/src/test/java/org/olat/course/groupsandrights/CourseGroupManagementTest.java index f0d261c54932208b57bc2a16c67ccf49fb3688d2..44cdb823ff074aca346040e90cb0286bc46883cd 100644 --- a/src/test/java/org/olat/course/groupsandrights/CourseGroupManagementTest.java +++ b/src/test/java/org/olat/course/groupsandrights/CourseGroupManagementTest.java @@ -176,9 +176,9 @@ public class CourseGroupManagementTest extends OlatTestCase { securityManager.addIdentityToSecurityGroup(id2, g2.getPartipiciantGroup()); securityManager.addIdentityToSecurityGroup(id3, g1.getOwnerGroup()); // areas - BGArea a1 = areaManager.createAndPersistBGAreaIfNotExists("a1", "desca1", course1); - BGArea a2 = areaManager.createAndPersistBGAreaIfNotExists("a2", null, course1); - BGArea a3 = areaManager.createAndPersistBGAreaIfNotExists("a3", null, course1); + BGArea a1 = areaManager.createAndPersistBGArea("a1", "desca1", course1); + BGArea a2 = areaManager.createAndPersistBGArea("a2", null, course1); + BGArea a3 = areaManager.createAndPersistBGArea("a3", null, course1); areaManager.addBGToBGArea(g1, a1); areaManager.addBGToBGArea(g2, a1); areaManager.addBGToBGArea(g1, a2); diff --git a/src/test/java/org/olat/group/test/BGAreaManagerTest.java b/src/test/java/org/olat/group/test/BGAreaManagerTest.java index 5e81de15b565a72feeea6744b75827a0068cf56d..e7ba79e4215c0d6dea4c3ad8ac657dc3d890b3b5 100644 --- a/src/test/java/org/olat/group/test/BGAreaManagerTest.java +++ b/src/test/java/org/olat/group/test/BGAreaManagerTest.java @@ -33,9 +33,7 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -108,7 +106,7 @@ public class BGAreaManagerTest extends OlatTestCase { OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); String description = "description:" + areaName; - BGArea area = areaManager.createAndPersistBGAreaIfNotExists(areaName, description, resource); + BGArea area = areaManager.createAndPersistBGArea(areaName, description, resource); Assert.assertNotNull(area); dbInstance.commitAndCloseSession(); @@ -127,8 +125,8 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource with areas OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("load-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("load-2-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("load-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("load-2-" + areaName, "description:" + areaName, resource); dbInstance.commitAndCloseSession(); //check if it's robust agains empty argument @@ -158,7 +156,7 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource with areas OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area = areaManager.createAndPersistBGAreaIfNotExists("exists-" + areaName, "description:" + areaName, resource); + BGArea area = areaManager.createAndPersistBGArea("exists-" + areaName, "description:" + areaName, resource); dbInstance.commitAndCloseSession(); //check exist by key @@ -180,8 +178,8 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource with areas OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("find-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("find-2-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("find-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("find-2-" + areaName, "description:" + areaName, resource); dbInstance.commitAndCloseSession(); @@ -198,7 +196,7 @@ public class BGAreaManagerTest extends OlatTestCase { public void updateBGArea() { OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area = areaManager.createAndPersistBGAreaIfNotExists("upd-1-" + areaName, "description:" + areaName, resource); + BGArea area = areaManager.createAndPersistBGArea("upd-1-" + areaName, "description:" + areaName, resource); dbInstance.commitAndCloseSession(); @@ -224,7 +222,7 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource, an area, a group OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area = areaManager.createAndPersistBGAreaIfNotExists("area-" + areaName, "description:" + areaName, resource); + BGArea area = areaManager.createAndPersistBGArea("area-" + areaName, "description:" + areaName, resource); BusinessGroup group = businessGroupService.createBusinessGroup(null, "area-group", "area-group-desc", 0, -1, false, false, resource); dbInstance.commitAndCloseSession(); @@ -237,8 +235,8 @@ public class BGAreaManagerTest extends OlatTestCase { public void deleteBGArea() { OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("area-2-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource); BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource); BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource); @@ -268,9 +266,9 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource, an area, a group OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("area-2-" + areaName, "description:" + areaName, resource); - BGArea area3 = areaManager.createAndPersistBGAreaIfNotExists("area-3-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource); + BGArea area3 = areaManager.createAndPersistBGArea("area-3-" + areaName, "description:" + areaName, resource); BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource); BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource); @@ -301,8 +299,8 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource, an area, a group OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("area-2-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource); BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource); BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource); @@ -335,8 +333,8 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource, an area, a group OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("area-2-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource); BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource); BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource); @@ -390,7 +388,7 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource, an area, a group OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource); //create 2 groups BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource); BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource); @@ -424,9 +422,9 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource, 3 area and 2 group OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("area-2-" + areaName, "description:" + areaName, resource); - BGArea area3 = areaManager.createAndPersistBGAreaIfNotExists("area-3-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource); + BGArea area3 = areaManager.createAndPersistBGArea("area-3-" + areaName, "description:" + areaName, resource); //create 2 groups BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource); BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource); @@ -466,8 +464,8 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource, an area, a group OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("area-2-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource); //create 2 groups BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource); BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource); @@ -496,44 +494,6 @@ public class BGAreaManagerTest extends OlatTestCase { Assert.assertNotNull(areaGroup2After); Assert.assertEquals(0, areaGroup2After.size()); } - - @Test - public void checkIfOneOrMoreNameExistsInContext() { - //create a resource, an area, a group - OLATResource resource1 = JunitTestHelper.createRandomResource(); - String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource1); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("area-2-" + areaName, "description:" + areaName, resource1); - //create 2 groups - dbInstance.commitAndCloseSession(); - - //check empty list - boolean emptyTest = areaManager.checkIfOneOrMoreNameExistsInContext(Collections.<String>emptySet(), resource1); - Assert.assertFalse(emptyTest); - - //check names - Set<String> name1 = new HashSet<String>(); - name1.add("Hello OpenOLAT"); - name1.add(area1.getName()); - boolean test1 = areaManager.checkIfOneOrMoreNameExistsInContext(name1, resource1); - Assert.assertTrue(test1); - - //check more names - Set<String> name2 = new HashSet<String>(); - name2.add("Hello OpenOLAT"); - name2.add(area1.getName()); - name2.add(area2.getName()); - boolean test2 = areaManager.checkIfOneOrMoreNameExistsInContext(name2, resource1); - Assert.assertTrue(test2); - - //check wrong names - Set<String> name3 = new HashSet<String>(); - name3.add("Hello OpenOLAT"); - name3.add("area-1-"); - name3.add("area-2-"); - boolean test3 = areaManager.checkIfOneOrMoreNameExistsInContext(name3, resource1); - Assert.assertFalse(test3); - } @Test public void findBusinessGroupsOfAreaAttendedBy() { @@ -543,8 +503,8 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource, an area, a group OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("area-2-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource); //create 2 groups BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource); BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource); @@ -590,9 +550,9 @@ public class BGAreaManagerTest extends OlatTestCase { //create a resource, an area, a group OLATResource resource = JunitTestHelper.createRandomResource(); String areaName = UUID.randomUUID().toString(); - BGArea area1 = areaManager.createAndPersistBGAreaIfNotExists("area-1-" + areaName, "description:" + areaName, resource); - BGArea area2 = areaManager.createAndPersistBGAreaIfNotExists("area-2-" + areaName, "description:" + areaName, resource); - BGArea area3 = areaManager.createAndPersistBGAreaIfNotExists("area-3-" + areaName, "description:" + areaName, resource); + BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource); + BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource); + BGArea area3 = areaManager.createAndPersistBGArea("area-3-" + areaName, "description:" + areaName, resource); //create 2 groups BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource); BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource); @@ -685,7 +645,7 @@ public class BGAreaManagerTest extends OlatTestCase { for (int i=0; i<maxLoop; i++) { try { - BGArea bgArea = areaManager.createAndPersistBGAreaIfNotExists(areaName, "description:" + areaName, c1); + BGArea bgArea = areaManager.createAndPersistBGArea(areaName, "description:" + areaName, c1); if (bgArea != null) { DBFactory.getInstance().closeSession(); // created a new bg area @@ -730,7 +690,7 @@ public class BGAreaManagerTest extends OlatTestCase { BGArea bgArea = areaManager.findBGArea(areaName, c1); assertNull(bgArea); - bgArea = areaManager.createAndPersistBGAreaIfNotExists(areaName, "description:" + areaName, c1); + bgArea = areaManager.createAndPersistBGArea(areaName, "description:" + areaName, c1); assertNotNull(bgArea); startThreadUpdateBGArea(areaName, maxLoop, exceptionHolder, 20, finfishCount); diff --git a/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java b/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java index dc689f4964dbdcd55d26fd305931094d31cac86d..8f4922ba69a9c05ff6a724e2c2d9cb531c5ca457 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupRelationDAOTest.java @@ -19,11 +19,8 @@ */ package org.olat.group.test; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.UUID; import junit.framework.Assert; @@ -305,195 +302,6 @@ public class BusinessGroupRelationDAOTest extends OlatTestCase { boolean test4 = businessGroupRelationDao.isIdentityInBusinessGroup(id, "rel-bg-part-1", null, resource3); Assert.assertFalse(test4); } - - @Test - public void checkIfOneOrMoreNameExistsInContextByResource() { - //prepare 2 resources and 3 groups - OLATResource resource1 = JunitTestHelper.createRandomResource(); - OLATResource resource2 = JunitTestHelper.createRandomResource(); - - BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-part-one", "rel-bgis-1-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group1, resource1); - businessGroupRelationDao.addRelationToResource(group1, resource2); - - BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-part-two", "rel-bgis-2-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group2, resource1); - - BusinessGroup group3 = businessGroupDao.createAndPersist(null, "rel-bg-part-three", "rel-bgis-3-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group3, resource2); - - dbInstance.commitAndCloseSession(); - - //check with empty set (must return without exception) - boolean test0 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(Collections.<String>emptySet(), resource1); - Assert.assertFalse(test0); - - //check if name of group 1 is in resource 1 - Set<String> name1 = Collections.singleton("rel-bg-part-one"); - boolean test1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, resource1); - Assert.assertTrue(test1); - - //check if name of group 1 and 2 is in resource 1 - Set<String> name1_2 = new HashSet<String>(); - name1_2.add("rel-bg-part-one"); - name1_2.add("rel-bg-part-two"); - boolean test2_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1_2, resource1); - Assert.assertTrue(test2_1); - //check if name of group 1 and 2 is in resource 1 - boolean test2_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1_2, resource2); - Assert.assertTrue(test2_2); - - //check if name of group 1 and 2 is in resource 1 - Set<String> name3 = Collections.singleton("rel-bg-part-three"); - boolean test3_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name3, resource1); - Assert.assertFalse(test3_1); - //check if name of group 1 and 2 is in resource 2 - boolean test3_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name3, resource2); - Assert.assertTrue(test3_2); - - //check if name of group 1 and something else is in resource 1 - Set<String> name2_4 = new HashSet<String>(); - name2_4.add("rel-bg-part-two"); - name2_4.add("rel-bg-part-four"); - boolean test4_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2_4, resource1); - Assert.assertTrue(test4_1); - boolean test4_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2_4, resource2); - Assert.assertFalse(test4_2); - } - - @Test - public void checkIfOneOrMoreNameExistsInContextByResourceKeys() { - //prepare 2 resources and 3 groups - OLATResource resource1 = JunitTestHelper.createRandomResource(); - OLATResource resource2 = JunitTestHelper.createRandomResource(); - - BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-part-one", "rel-bgis-1-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group1, resource1); - businessGroupRelationDao.addRelationToResource(group1, resource2); - - BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-part-two", "rel-bgis-2-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group2, resource1); - - BusinessGroup group3 = businessGroupDao.createAndPersist(null, "rel-bg-part-three", "rel-bgis-3-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group3, resource2); - - dbInstance.commitAndCloseSession(); - - //check with empty set (must return without exception) - boolean test0 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(Collections.<String>emptySet(), resource1); - Assert.assertFalse(test0); - - List<Long> resourceKey1 = Collections.singletonList(resource1.getKey()); - List<Long> resourceKey2 = Collections.singletonList(resource2.getKey()); - List<Long> resourceKey1_2 = new ArrayList<Long>(); - resourceKey1_2.add(resource1.getKey()); - resourceKey1_2.add(resource2.getKey()); - - //check empty lists - Set<String> emptyName = Collections.<String>emptySet(); - boolean test0_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(emptyName, resourceKey1); - Assert.assertFalse(test0_1); - //empty keys - Set<String> name1 = Collections.singleton("rel-bg-part-one"); - List<Long> emptyKey = Collections.<Long>emptyList(); - boolean test0_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, emptyKey); - Assert.assertFalse(test0_2); - //all empty - boolean test0_3 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(emptyName, emptyKey); - Assert.assertFalse(test0_3); - - //check if name of group 1 is in resource 1 - boolean test1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, resourceKey1); - Assert.assertTrue(test1); - - //check if name of group 2 and something else is in resource 1 - Set<String> name2_4 = new HashSet<String>(); - name2_4.add("rel-bg-part-two"); - name2_4.add("rel-bg-part-four"); - boolean test4_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2_4, resourceKey1); - Assert.assertTrue(test4_1); - boolean test4_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2_4, resourceKey2); - Assert.assertFalse(test4_2); - - //check if name of group 1 and 3 is in resource 1 - Set<String> name1_3 = new HashSet<String>(); - name1_3.add("rel-bg-part-one"); - name1_3.add("rel-bg-part-three"); - boolean test5_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1_3, resourceKey1); - Assert.assertTrue(test5_1); - boolean test5_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1_3, resourceKey2); - Assert.assertTrue(test5_2); - - //check if a lot of keys and names make problems - Set<String> nameBig = new HashSet<String>(); - for(int i=0; i<10000; i++) { - nameBig.add("rel-bg-part-" + 1); - } - List<Long> keyBig = new ArrayList<Long>(); - for(int i=0; i<10000; i++) { - keyBig.add(new Long(800000 + i)); - } - boolean test6_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(nameBig, keyBig); - Assert.assertFalse(test6_1); - //check with the same log of + something real - nameBig.add("rel-bg-part-two"); - keyBig.add(resource2.getKey()); - boolean test7_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(nameBig, keyBig); - Assert.assertFalse(test7_1); - //add resource 2 - keyBig.add(resource1.getKey()); - boolean test8_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(nameBig, keyBig); - Assert.assertTrue(test8_1); - } - - @Test - public void checkIfOneOrMoreNameExistsInContextByGroup() { - //prepare 2 resources and 3 groups - OLATResource resource1 = JunitTestHelper.createRandomResource(); - OLATResource resource2 = JunitTestHelper.createRandomResource(); - OLATResource resource3 = JunitTestHelper.createRandomResource(); - - BusinessGroup group1 = businessGroupDao.createAndPersist(null, "rel-bg-part-one", "rel-bgis-1-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group1, resource1); - businessGroupRelationDao.addRelationToResource(group1, resource2); - - BusinessGroup group2 = businessGroupDao.createAndPersist(null, "rel-bg-part-two", "rel-bgis-2-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group2, resource1); - - BusinessGroup group3 = businessGroupDao.createAndPersist(null, "rel-bg-part-three", "rel-bgis-3-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group3, resource2); - - BusinessGroup group4 = businessGroupDao.createAndPersist(null, "rel-bg-part-four", "rel-bgis-4-desc", -1, -1, false, false, false, false, false); - businessGroupRelationDao.addRelationToResource(group4, resource3); - - dbInstance.commitAndCloseSession(); - - //check with empty set (must return without exception) - boolean test0 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(Collections.<String>emptySet(), group1); - Assert.assertFalse(test0); - - //check name 1 - Set<String> name1 = Collections.singleton("rel-bg-part-one"); - boolean test1_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, group1); - Assert.assertTrue(test1_1); - boolean test1_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, group2); - Assert.assertTrue(test1_2); - boolean test1_3 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, group3); - Assert.assertTrue(test1_3); - boolean test1_4 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name1, group4); - Assert.assertFalse(test1_4); - - //check name 2 - Set<String> name2 = Collections.singleton("rel-bg-part-one"); - boolean test2_1 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2, group1); - Assert.assertTrue(test2_1); - boolean test2_2 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2, group2); - Assert.assertTrue(test2_2); - boolean test2_3 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2, group3); - Assert.assertTrue(test2_3); - boolean test2_4 = businessGroupRelationDao.checkIfOneOrMoreNameExistsInContext(name2, group4); - Assert.assertFalse(test2_4); - } @Test public void findBusinessGroupsWithWaitingListAttendedBy() { diff --git a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java index c59f511f6d2b197fc02cc837fdc32b7f13fcf8d0..1bb5a7be091c8bc16a67bc6cc3e40c9df4acadd1 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java @@ -25,9 +25,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.UUID; import junit.framework.Assert; @@ -240,98 +238,16 @@ public class BusinessGroupServiceTest extends OlatTestCase { BusinessGroup g3 = businessGroupService.createBusinessGroup(null, "g3", null, 0, 10, false, false, c2); assertNotNull(g3); - BusinessGroup g2douplicate = businessGroupService.createBusinessGroup(null, "g2", null, 0, 10, false, false, c1); - assertNull(g2douplicate); // name duplicate names allowed per group context + BusinessGroup g2duplicate = businessGroupService.createBusinessGroup(null, "g2", null, 0, 10, false, false, c1); + assertNotNull(g2duplicate); // name duplicate names are allowed per group context BusinessGroup g4 = businessGroupService.createBusinessGroup(null, "g2", null, 0, 10, false, false, c2); assertNotNull(g4); // name duplicate in other context allowed dbInstance.commitAndCloseSession(); // simulate user clicks SearchBusinessGroupParams params2 = new SearchBusinessGroupParams(null, false, false); - Assert.assertEquals(2, businessGroupService.findBusinessGroups(params2, c1, 0, -1).size()); - Assert.assertEquals(2, businessGroupService.countBusinessGroups(params2, c1)); - } - - @Test - public void testCheckIfNamesExistsInContext() throws Exception { - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("id5-check-" + UUID.randomUUID().toString()); - - OLATResource ctxA = JunitTestHelper.createRandomResource(); - OLATResource ctxB = JunitTestHelper.createRandomResource(); - - String[] namesInCtxA = new String[] { "A-GroupOne", "A-GroupTwo", "A-GroupThree", "A-GroupFour", "A-GroupFive", "A-GroupSix" }; - String[] namesInCtxB = new String[] { "B-GroupAAA", "B-GroupBBB", "B-GroupCCC", "B-GroupDDD", "B-GroupEEE", "B-GroupFFF" }; - BusinessGroup[] ctxAgroups = new BusinessGroup[namesInCtxA.length]; - BusinessGroup[] ctxBgroups = new BusinessGroup[namesInCtxB.length]; - - for (int i = 0; i < namesInCtxA.length; i++) { - ctxAgroups[i] = businessGroupService.createBusinessGroup(id, namesInCtxA[i], null, 0, 0, false, - false, ctxA); - } - for (int i = 0; i < namesInCtxB.length; i++) { - ctxBgroups[i] = businessGroupService.createBusinessGroup(id, namesInCtxB[i], null, 0, 0, false, - false, ctxB); - } - // first click created two context and each of them containg groups - // evict all created and search - System.out.println("Test: ctxAgroups.length=" + ctxAgroups.length); - for (int i = 0; i < ctxAgroups.length; i++) { - System.out.println("Test: i=" + i); - System.out.println("Test: ctxAgroups[i]=" + ctxAgroups[i]); - } - dbInstance.commitAndCloseSession(); - - // next click needs to check of a set of groupnames already exists. - Set<String> subsetOkInA = new HashSet<String>(); - subsetOkInA.add("A-GroupTwo"); - subsetOkInA.add("A-GroupThree"); - subsetOkInA.add("A-GroupFour"); - - Set<String> subsetNOkInA = new HashSet<String>(); - subsetNOkInA.add("A-GroupTwo"); - subsetNOkInA.add("NOT-IN-A"); - subsetNOkInA.add("A-GroupThree"); - subsetNOkInA.add("A-GroupFour"); - - Set<String> subsetOkInB = new HashSet<String>(); - subsetOkInB.add("B-GroupCCC"); - subsetOkInB.add("B-GroupDDD"); - subsetOkInB.add("B-GroupEEE"); - subsetOkInB.add("B-GroupFFF"); - - Set<String> subsetNOkInB = new HashSet<String>(); - subsetNOkInB.add("B-GroupCCC"); - subsetNOkInB.add("NOT-IN-B"); - subsetNOkInB.add("B-GroupEEE"); - subsetNOkInB.add("B-GroupFFF"); - - Set<String> setSpansAandBNok = new HashSet<String>(); - setSpansAandBNok.add("B-GroupCCC"); - setSpansAandBNok.add("A-GroupTwo"); - setSpansAandBNok.add("A-GroupThree"); - setSpansAandBNok.add("B-GroupEEE"); - setSpansAandBNok.add("B-GroupFFF"); - - boolean allExist = false; - allExist = businessGroupService.checkIfOneOrMoreNameExists(subsetOkInA, ctxA); - assertTrue("Three A-Group.. should find all", allExist); - // Check : one name does not exist, 3 exist - assertTrue("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExists(subsetNOkInA, ctxA)); - // Check : no name exist in context - assertFalse("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExists(subsetOkInB, ctxA)); - // - allExist = businessGroupService.checkIfOneOrMoreNameExists(subsetOkInB, ctxB); - assertTrue("Three B-Group.. should find all", allExist); - // Check : one name does not exist, 3 exist - assertTrue("A 'NOT-IN-B'.. should not find all", businessGroupService.checkIfOneOrMoreNameExists(subsetNOkInB, ctxB)); - // Check : no name exist in context - assertFalse("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExists(subsetOkInA, ctxB)); - // Mix A (2x) and B (3x) - allExist = businessGroupService.checkIfOneOrMoreNameExists(setSpansAandBNok, ctxA); - assertTrue("Groupnames spanning two context... should not find all in context A", allExist); - // Mix A (2x) and B (3x) - allExist = businessGroupService.checkIfOneOrMoreNameExists(setSpansAandBNok, ctxB); - assertTrue("Groupnames spanning two context... should not find all in context B", allExist); + Assert.assertEquals(3, businessGroupService.findBusinessGroups(params2, c1, 0, -1).size()); + Assert.assertEquals(3, businessGroupService.countBusinessGroups(params2, c1)); } /**