Index: lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java,v diff -u -r1.6 -r1.7 --- lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java 5 Dec 2013 12:52:23 -0000 1.6 +++ lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java 19 Feb 2014 17:59:02 -0000 1.7 @@ -266,7 +266,7 @@ // check if any groups already exist in this grouping Grouping lessonGrouping = getLessonGrouping(request, activityId, true); Set lessonGroups = lessonGrouping == null ? null : lessonGrouping.getGroups(); - if ((activityId != null) && (orgGroupingId != null) && isDefaultChosenGrouping(lessonGroups)) { + if ((activityId != null) && (orgGroupingId != null) && isDefaultChosenGrouping(lessonGrouping)) { if (OrganisationGroupAction.log.isDebugEnabled()) { OrganisationGroupAction.log.debug("Removing default groups for grouping " + orgGroupingId); } @@ -385,16 +385,16 @@ duplicateCheckProperties.put("organisationId", organisationId); duplicateCheckProperties.put("name", orgGroupingName); - List duplicateOrgGrouping = getUserManagementService() - .findByProperties(OrganisationGrouping.class, duplicateCheckProperties); + List duplicateOrgGrouping = getUserManagementService().findByProperties( + OrganisationGrouping.class, duplicateCheckProperties); if (duplicateOrgGrouping.isEmpty()) { orgGrouping.setName(orgGroupingName); } else { throw new InvalidParameterException("Grouping with name \"" + orgGroupingName + "\" already exists"); } } - + getUserManagementService().saveOrganisationGrouping(orgGrouping, orgGroups); return null; } @@ -506,7 +506,7 @@ request.setAttribute(GroupingAJAXAction.PARAM_USED_FOR_BRANCHING, isUsedForBranching); // check if it is immutable (for branching) or default groups are allowed - return !groups.isEmpty() && (isUsedForBranching || allowDefault || !isDefaultChosenGrouping(groups)) ? grouping + return !groups.isEmpty() && (isUsedForBranching || allowDefault || !isDefaultChosenGrouping(grouping)) ? grouping : null; } } @@ -515,10 +515,14 @@ } /** - * Check if the give groups are default for chosen grouping. + * Check if the give groups are default for chosen grouping. There is actually no good way to detect this, but even + * if a custom grouping is mistaken for the default one, it should bring little harm. */ - private boolean isDefaultChosenGrouping(Set groups) { - if ((groups == null) || (groups.size() != 2)) { + @SuppressWarnings("unchecked") + private boolean isDefaultChosenGrouping(Grouping grouping) { + Set groups = grouping.getGroups(); + if (groups == null || grouping.getMaxNumberOfGroups() == null + || !grouping.getMaxNumberOfGroups().equals(groups.size())) { return false; } for (Group group : groups) {