diff --git a/src/main/java/org/olat/course/PersistingCourseImpl.java b/src/main/java/org/olat/course/PersistingCourseImpl.java index 11fc170adc8c418326b746a209eb6511d39ee095..1e3c09bd9023bd3907d8654d44883766170b59da 100644 --- a/src/main/java/org/olat/course/PersistingCourseImpl.java +++ b/src/main/java/org/olat/course/PersistingCourseImpl.java @@ -295,13 +295,23 @@ public class PersistingCourseImpl implements ICourse, OLATResourceable, Serializ long s = System.currentTimeMillis(); log.info("exportToFilesystem: exporting course "+this+" to "+exportDirectory+"..."); File fCourseBase = getCourseBaseContainer().getBasefile(); + //make the folder structure + File fExportedDataDir = new File(exportDirectory, EXPORTED_DATA_FOLDERNAME); + fExportedDataDir.mkdirs(); + //export course config FileUtils.copyFileToDir(new File(fCourseBase, CourseConfigManager.COURSECONFIG_XML), exportDirectory, "course export courseconfig"); + //export business groups + CourseEnvironmentMapper envMapper = PersistingCourseGroupManager.getInstance(this).getBusinessGroupEnvironment(); + if(backwardsCompatible) { + //prevents duplicate names + envMapper.avoidDuplicateNames(); + } + PersistingCourseGroupManager.getInstance(this).exportCourseBusinessGroups(fExportedDataDir, envMapper, backwardsCompatible); if(backwardsCompatible) { XStream xstream = CourseXStreamAliases.getReadCourseXStream(); - CourseEnvironmentMapper envMapper = PersistingCourseGroupManager.getInstance(this).getBusinessGroupEnvironment(); - + Structure exportedStructure = (Structure)XStreamHelper.readObject(xstream, new File(fCourseBase, RUNSTRUCTURE_XML)); visit(new NodePostExportVisitor(envMapper, backwardsCompatible), exportedStructure.getRootNode()); XStreamHelper.writeObject(xstream, new File(exportDirectory, RUNSTRUCTURE_XML), exportedStructure); @@ -321,8 +331,6 @@ public class PersistingCourseImpl implements ICourse, OLATResourceable, Serializ // export course folder FileUtils.copyDirToDir(getIsolatedCourseFolder().getBasefile(), exportDirectory, "course export folder"); // export any node data - File fExportedDataDir = new File(exportDirectory, EXPORTED_DATA_FOLDERNAME); - fExportedDataDir.mkdirs(); log.info("exportToFilesystem: exporting course "+this+": exporting all nodes..."); Visitor visitor = new NodeExportVisitor(fExportedDataDir, this); TreeVisitor tv = new TreeVisitor(visitor, getEditorTreeModel().getRootNode(), true); @@ -380,11 +388,7 @@ public class PersistingCourseImpl implements ICourse, OLATResourceable, Serializ log.info("exportToFilesystem: exporting course "+this+": configuration and repo data..."); // export configuration file FileUtils.copyFileToDir(new File(fCourseBase, CourseConfigManager.COURSECONFIG_XML), exportDirectory, "course export configuration and repo info"); - // export learning groups - PersistingCourseGroupManager.getInstance(this).exportCourseBusinessGroups(fExportedDataDir, backwardsCompatible); - // export right groups - //PersistingCourseGroupManager.getInstance(this).exportCourseRightGroups(fExportedDataDir); // export repo metadata RepositoryManager rm = RepositoryManager.getInstance(); RepositoryEntry myRE = rm.lookupRepositoryEntry(this, true); diff --git a/src/main/java/org/olat/course/export/CourseEnvironmentMapper.java b/src/main/java/org/olat/course/export/CourseEnvironmentMapper.java index a5edd8e576a555c410dbd2b1522ef90a81b10c0f..e43cdbfadef4a92d5ef470cad6fb998a6df2d19c 100644 --- a/src/main/java/org/olat/course/export/CourseEnvironmentMapper.java +++ b/src/main/java/org/olat/course/export/CourseEnvironmentMapper.java @@ -20,7 +20,11 @@ package org.olat.course.export; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.UUID; import org.olat.core.util.StringHelper; import org.olat.group.model.BGAreaReference; @@ -49,6 +53,38 @@ public class CourseEnvironmentMapper { groups.addAll(env.getGroups()); } + public void avoidDuplicateNames() { + Set<String> names = new HashSet<String>(); + for(BusinessGroupReference ref:getGroups()) { + if(names.contains(ref.getName())) { + String newName = generateName(ref.getName(), names); + names.add(newName); + ref.setName(newName); + } else { + names.add(ref.getName()); + } + } + names.clear(); + for(BGAreaReference ref:getAreas()) { + if(names.contains(ref.getName())) { + String newName = generateName(ref.getName(), names); + names.add(newName); + ref.setName(newName); + } else { + names.add(ref.getName()); + } + } + } + + private String generateName(String name, Collection<String> names) { + for(int i=1; i<100; i++) { + String newName = name + "_" + i; + if(!names.contains(newName)) { + return newName; + } + } + return name + "_" + UUID.randomUUID().toString(); + } public List<Long> toGroupKeyFromOriginalNames(String groupNames) { if(!StringHelper.containsNonWhitespace(groupNames)) return null; diff --git a/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java b/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java index 420ea2317bcd034e3ed104bc1daed4b618828157..3251aaf5979068f5e1950be03f7a17877148d406 100644 --- a/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java +++ b/src/main/java/org/olat/course/groupsandrights/CourseGroupManager.java @@ -32,7 +32,6 @@ import org.olat.core.id.Identity; import org.olat.course.export.CourseEnvironmentMapper; import org.olat.group.BusinessGroup; import org.olat.group.area.BGArea; -import org.olat.group.model.BusinessGroupEnvironment; import org.olat.resource.OLATResource; /** @@ -184,7 +183,7 @@ public interface CourseGroupManager { * * @param fExportDirectory */ - public void exportCourseBusinessGroups(File fExportDirectory, boolean backwardsCompatible); + public void exportCourseBusinessGroups(File fExportDirectory, CourseEnvironmentMapper env, boolean backwardsCompatible); /** * Import course internal groups fa previous export. diff --git a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java index 04ca05dbb838be2e820574c83c743481c8006077..b1d67183e9f7c25846e0d8cf488ca2aadbc1dd42 100644 --- a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java +++ b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java @@ -309,11 +309,16 @@ public class PersistingCourseGroupManager extends BasicManager implements Course /** * @see org.olat.course.groupsandrights.CourseGroupManager#exportCourseBusinessGroups(java.io.File) */ - public void exportCourseBusinessGroups(File fExportDirectory, boolean backwardsCompatible) { + @Override + public void exportCourseBusinessGroups(File fExportDirectory, CourseEnvironmentMapper courseEnv, boolean backwardsCompatible) { File fExportFile = new File(fExportDirectory, LEARNINGGROUPEXPORT_XML); List<BGArea> areas = getAllAreas(); List<BusinessGroup> groups = getAllBusinessGroups(); - businessGroupService.exportGroups(groups, areas, fExportFile, backwardsCompatible); + + BusinessGroupEnvironment bgEnv = new BusinessGroupEnvironment(); + bgEnv.getGroups().addAll(courseEnv.getGroups()); + bgEnv.getAreas().addAll(courseEnv.getAreas()); + businessGroupService.exportGroups(groups, areas, fExportFile, bgEnv, backwardsCompatible); } /** diff --git a/src/main/java/org/olat/course/run/preview/PreviewCourseGroupManager.java b/src/main/java/org/olat/course/run/preview/PreviewCourseGroupManager.java index aa5bb3f3168ff4a6f4e8715e3872c49d36f7cf14..8e653e6b08ffce6c83736287f1b5fb6bc34f6d5c 100644 --- a/src/main/java/org/olat/course/run/preview/PreviewCourseGroupManager.java +++ b/src/main/java/org/olat/course/run/preview/PreviewCourseGroupManager.java @@ -267,7 +267,7 @@ final class PreviewCourseGroupManager extends BasicManager implements CourseGrou } @Override - public void exportCourseBusinessGroups(File fExportDirectory, boolean backwardsCompatible) { + public void exportCourseBusinessGroups(File fExportDirectory, CourseEnvironmentMapper env, boolean backwardsCompatible) { throw new AssertException("unsupported"); } diff --git a/src/main/java/org/olat/group/BusinessGroupService.java b/src/main/java/org/olat/group/BusinessGroupService.java index 77b95d5096e01b12dfb56a18c4d5ebf910260770..39e117ed14996420a04eea7c7ee1fc34bb8f13d8 100644 --- a/src/main/java/org/olat/group/BusinessGroupService.java +++ b/src/main/java/org/olat/group/BusinessGroupService.java @@ -464,7 +464,7 @@ public interface BusinessGroupService { * @param groups * @param fExportFile */ - public void exportGroups(List<BusinessGroup> groups, List<BGArea> areas, File fExportFile, boolean backwardsCompatible); + public void exportGroups(List<BusinessGroup> groups, List<BGArea> areas, File fExportFile, BusinessGroupEnvironment env, boolean backwardsCompatible); /** * Import previously exported group definitions. diff --git a/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java b/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java index 092ffe8d01cb7a93b7fd6b59e04fae906601d7cc..887f4bf42e19c2bcb82b5cbab86af7142158bd33 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupImportExport.java @@ -69,9 +69,10 @@ public class BusinessGroupImportExport { private BusinessGroupPropertyDAO businessGroupPropertyManager; - public void exportGroups(List<BusinessGroup> groups, List<BGArea> areas, File fExportFile, boolean backwardsCompatible) { - if (groups == null || groups.isEmpty()) + public void exportGroups(List<BusinessGroup> groups, List<BGArea> areas, File fExportFile, BusinessGroupEnvironment env, boolean backwardsCompatible) { + if (groups == null || groups.isEmpty()) { return; // nothing to do... says Florian. + } OLATGroupExport root = new OLATGroupExport(); // export areas @@ -81,6 +82,12 @@ public class BusinessGroupImportExport { Area newArea = new Area(); newArea.key = backwardsCompatible ? null : area.getKey(); newArea.name = area.getName(); + if(backwardsCompatible && env != null) { + String newName = env.getAreaName(area.getKey()); + if(StringHelper.containsNonWhitespace(newName)) { + newArea.name = newName; + } + } newArea.description = Collections.singletonList(area.getDescription()); root.getAreas().getGroups().add(newArea); } @@ -89,7 +96,11 @@ public class BusinessGroupImportExport { root.setGroups(new GroupCollection()); root.getGroups().setGroups(new ArrayList<Group>()); for (BusinessGroup group : groups) { - Group newGroup = exportGroup(fExportFile, group, backwardsCompatible); + String groupName = null; + if(backwardsCompatible && env != null) { + groupName = env.getGroupName(group.getKey()); + } + Group newGroup = exportGroup(fExportFile, group, groupName, backwardsCompatible); root.getGroups().getGroups().add(newGroup); } saveGroupConfiguration(fExportFile, root); @@ -97,17 +108,17 @@ public class BusinessGroupImportExport { public void exportGroup(BusinessGroup group, File fExportFile, boolean backwardsCompatible) { OLATGroupExport root = new OLATGroupExport(); - Group newGroup = exportGroup(fExportFile, group, backwardsCompatible); + Group newGroup = exportGroup(fExportFile, group, null, backwardsCompatible); root.setGroups(new GroupCollection()); root.getGroups().setGroups(new ArrayList<Group>()); root.getGroups().getGroups().add(newGroup); saveGroupConfiguration(fExportFile, root); } - private Group exportGroup(File fExportFile, BusinessGroup group, boolean backwardsCompatible) { + private Group exportGroup(File fExportFile, BusinessGroup group, String groupName, boolean backwardsCompatible) { Group newGroup = new Group(); newGroup.key = backwardsCompatible ? null : group.getKey(); - newGroup.name = group.getName(); + newGroup.name = StringHelper.containsNonWhitespace(groupName) ? groupName : group.getName(); if (group.getMinParticipants() != null) { newGroup.minParticipants = group.getMinParticipants(); } diff --git a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java index 66da4ca56c1f8ea0ddc04f8a97b93eac8f003c99..4ddb31ca3dfbeba7c5554da9ca083c06524d0f47 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java @@ -1269,8 +1269,9 @@ public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataD } @Override - public void exportGroups(List<BusinessGroup> groups, List<BGArea> areas, File fExportFile, boolean backwardsCompatible) { - businessGroupImportExport.exportGroups(groups, areas, fExportFile, backwardsCompatible); + public void exportGroups(List<BusinessGroup> groups, List<BGArea> areas, File fExportFile, + BusinessGroupEnvironment env, boolean backwardsCompatible) { + businessGroupImportExport.exportGroups(groups, areas, fExportFile, env, backwardsCompatible); } @Override diff --git a/src/main/java/org/olat/group/model/BusinessGroupEnvironment.java b/src/main/java/org/olat/group/model/BusinessGroupEnvironment.java index cdd75c6a43cc222b3c172ec091dc7eda67996c08..1e3941223939fdaf2a306ee922ce94b311c33f02 100644 --- a/src/main/java/org/olat/group/model/BusinessGroupEnvironment.java +++ b/src/main/java/org/olat/group/model/BusinessGroupEnvironment.java @@ -38,4 +38,22 @@ public class BusinessGroupEnvironment { public List<BusinessGroupReference> getGroups() { return groups; } + + public String getGroupName(Long groupKey) { + for(BusinessGroupReference ref:getGroups()) { + if(ref.getKey().equals(groupKey)) { + return ref.getName(); + } + } + return null; + } + + public String getAreaName(Long areaKey) { + for(BGAreaReference ref:getAreas()) { + if(ref.getKey().equals(areaKey)) { + return ref.getName(); + } + } + return null; + } } diff --git a/src/main/java/org/olat/group/model/BusinessGroupReference.java b/src/main/java/org/olat/group/model/BusinessGroupReference.java index 767c24691a36f15d592fada16275332bc0b705a8..aac83b2f0f05dfdb8662a2523d093149ddd71e13 100644 --- a/src/main/java/org/olat/group/model/BusinessGroupReference.java +++ b/src/main/java/org/olat/group/model/BusinessGroupReference.java @@ -58,6 +58,10 @@ public class BusinessGroupReference { public String getName() { return name; } + + public void setName(String name) { + this.name = name; + } public Long getOriginalKey() { return originalKey;