* java.io.File)
*/
public void importGroups(BGContext context, File fGroupExportXML) {
if (!fGroupExportXML.exists()) return;
Configuration groupConfig = null;
try {
groupConfig = new XMLConfiguration(fGroupExportXML);
} catch (ConfigurationException ce) {
throw new OLATRuntimeException("Error importing group config.", ce);
}
if (!groupConfig.getName().equals(EXPORT_KEY_ROOT)) throw new AssertException("Invalid group export file. Root does not match.");
// get areas
BGAreaManager am = BGAreaManagerImpl.getInstance();
Configuration confAreas = groupConfig.getChild(EXPORT_KEY_AREA_COLLECTION);
if (confAreas != null) {
List areas = confAreas.getChildren(EXPORT_KEY_AREA);
for (Iterator iter = areas.iterator(); iter.hasNext();) {
Configuration area = (Configuration) iter.next();
String areaName = area.getAttribute(EXPORT_ATTR_NAME);
String areaDesc = area.getChildValue(EXPORT_KEY_DESCRIPTION);
am.createAndPersistBGAreaIfNotExists(areaName, areaDesc, context);
}
}
// TODO fg: import group rights
// get groups
Configuration confGroups = groupConfig.getChild(EXPORT_KEY_GROUP_COLLECTION);
if (confGroups != null) {
BusinessGroupManager gm = BusinessGroupManagerImpl.getInstance();
List groups = confGroups.getChildren(EXPORT_KEY_GROUP);
for (Iterator iter = groups.iterator(); iter.hasNext();) {
// create group
Configuration group = (Configuration) iter.next();
String groupName = group.getAttribute(EXPORT_ATTR_NAME);
String groupDesc = group.getChildValue(EXPORT_KEY_DESCRIPTION);
// get min/max participants
Integer groupMinParticipants = null;
String sMinParticipants = group.getAttribute(EXPORT_ATTR_MIN_PARTICIPATS);
if (sMinParticipants != null) groupMinParticipants = new Integer(sMinParticipants);
Integer groupMaxParticipants = null;
String sMaxParticipants = group.getAttribute(EXPORT_ATTR_MAX_PARTICIPATS);
if (sMaxParticipants != null) groupMaxParticipants = new Integer(sMaxParticipants);
// waiting list configuration
String waitingListConfig = group.getAttribute(EXPORT_ATTR_WAITING_LIST);
Boolean waitingList = null;
if (waitingListConfig == null) {
waitingList = Boolean.FALSE;
} else {
waitingList = Boolean.valueOf(waitingListConfig);
}
String enableAutoCloseRanksConfig = group.getAttribute(EXPORT_ATTR_AUTO_CLOSE_RANKS);
Boolean enableAutoCloseRanks = null;
if (enableAutoCloseRanksConfig == null) {
enableAutoCloseRanks = Boolean.FALSE;
} else {
enableAutoCloseRanks = Boolean.valueOf(enableAutoCloseRanksConfig);
}
BusinessGroup newGroup = gm.createAndPersistBusinessGroup(context.getGroupType(), null, groupName, groupDesc, groupMinParticipants,
groupMaxParticipants, waitingList, enableAutoCloseRanks, context);
// get tools config
Configuration toolsConfig = group.getChild(EXPORT_KEY_COLLABTOOLS);
CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(newGroup);
for (int i = 0; i < CollaborationTools.TOOLS.length; i++) {
String sTool = toolsConfig.getAttribute(CollaborationTools.TOOLS[i]);
if (sTool != null) ct.setToolEnabled(CollaborationTools.TOOLS[i], sTool.equals("true") ? true : false);
}
if(group.getAttribute(EXPORT_KEY_CALENDAR_ACCESS)!=null) {
Long calendarAccess = Long.valueOf(group.getAttribute(EXPORT_KEY_CALENDAR_ACCESS));
ct.saveCalendarAccess(calendarAccess);
}
if(group.getAttribute(EXPORT_KEY_NEWS)!=null) {
String info = group.getAttribute(EXPORT_KEY_NEWS);
ct.saveNews(info);
}
// get memberships
List memberships = group.getChildren(EXPORT_KEY_AREA_RELATION);
for (Iterator iterator = memberships.iterator(); iterator.hasNext();) {
Configuration areaRelation = (Configuration) iterator.next();
BGArea area = am.findBGArea(areaRelation.getValue(), context);
if (area == null) throw new AssertException("Group-Area-Relationship in export, but area was not created during import.");
am.addBGToBGArea(newGroup, area);
}
//get properties