Skip to content
Snippets Groups Projects
Commit fa615638 authored by srosse's avatar srosse
Browse files

OO-291: fix some import/export issues (remap hibernate classes, update names of groups and areas)

parent 6f51a5b7
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ import org.olat.core.util.FileUtils;
import org.olat.core.util.Util;
import org.olat.core.util.ValidationStatus;
import org.olat.core.util.WebappHelper;
import org.olat.core.util.xml.XStreamHelper;
import org.olat.course.CourseFactory;
import org.olat.course.ICourse;
import org.olat.course.condition.Condition;
......@@ -265,7 +266,7 @@ public class ChecklistCourseNode extends AbstractAccessableCourseNode {
@Override
public void exportNode(File exportDirectory, ICourse course) {
XStream xstream = new XStream();
XStream xstream = XStreamHelper.createXStreamInstance();
ChecklistManager cm = ChecklistManager.getInstance();
Checklist checklist = loadOrCreateChecklist(course.getCourseEnvironment().getCoursePropertyManager());
Checklist copy = cm.copyChecklistInRAM(checklist);
......@@ -284,7 +285,7 @@ public class ChecklistCourseNode extends AbstractAccessableCourseNode {
return null;
}
XStream xstream = new XStream();
XStream xstream = XStreamHelper.createXStreamInstance();
Checklist checklist = (Checklist) xstream.fromXML(importContent);
if(checklist != null) {
checklist = ChecklistManager.getInstance().copyChecklist(checklist);
......
/**
* <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.core.util.xml;
import org.hibernate.collection.internal.PersistentBag;
import org.hibernate.collection.internal.PersistentList;
import com.thoughtworks.xstream.mapper.MapperWrapper;
/**
* Remap some specific class as hibernate class to maintain compatibility
* with other olat system and/or old versions
*
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*/
public class EnhancedMapper extends MapperWrapper {
public EnhancedMapper(MapperWrapper mapper) {
super(mapper);
}
@Override
public Class<?> realClass(String elementName) {
if("org.hibernate.collection.PersistentBag".equals(elementName)) {
return PersistentBag.class;
} else if("org.hibernate.collection.PersistentList".equals(elementName)) {
return PersistentList.class;
} else {
return super.realClass(elementName);
}
}
@SuppressWarnings("rawtypes")
public String serializedClass(final Class type) {
if(type.equals(PersistentBag.class)) {
return "org.hibernate.collection.PersistentBag";
} else if(type.equals(PersistentList.class)) {
return "org.hibernate.collection.PersistentList";
} else {
return super.serializedClass(type);
}
}
}
......@@ -40,6 +40,7 @@ import org.olat.core.util.FileUtils;
import org.olat.core.util.vfs.VFSLeaf;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.mapper.MapperWrapper;
/**
* Description:<br>
......@@ -224,7 +225,7 @@ public class XStreamHelper {
* writing to a configured XML mapping
*/
public static XStream createXStreamInstance() {
return new XStream();
return new EnhancedXStream();
}
/**
......@@ -378,5 +379,12 @@ public class XStreamHelper {
FileUtils.closeSafely(os);
}
}
private static class EnhancedXStream extends XStream {
@Override
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new EnhancedMapper(next);
}
}
}
......@@ -110,7 +110,7 @@ public class CourseEnvironmentMapper {
return areaKeyList;
}
public String toOriginalGroupNames(List<Long> groupKeys) {
public String toGroupNames(List<Long> groupKeys) {
if(groupKeys == null || groupKeys.isEmpty()) return "";
StringBuilder sb = new StringBuilder();
for(Long groupKey:groupKeys) {
......@@ -125,7 +125,7 @@ public class CourseEnvironmentMapper {
return sb.toString();
}
public String toOriginalAreaNames(List<Long> areaKeys) {
public String toAreaNames(List<Long> areaKeys) {
if(areaKeys == null || areaKeys.isEmpty()) return "";
StringBuilder sb = new StringBuilder();
for(Long areaKey:areaKeys) {
......
......@@ -143,14 +143,14 @@ public class COCourseNode extends AbstractAccessableCourseNode {
@SuppressWarnings("unchecked")
List<Long> groupKeys = (List<Long>) mc.get(COEditController.CONFIG_KEY_EMAILTOGROUP_IDS);
if(groupKeys != null) {
String groupNames = envMapper.toOriginalGroupNames(groupKeys);
String groupNames = envMapper.toGroupNames(groupKeys);
mc.set(COEditController.CONFIG_KEY_EMAILTOGROUPS, groupNames);
}
@SuppressWarnings("unchecked")
List<Long> areaKeys = (List<Long>) mc.get(COEditController.CONFIG_KEY_EMAILTOAREA_IDS);
if(areaKeys != null) {
String areaNames = envMapper.toOriginalAreaNames(areaKeys);
String areaNames = envMapper.toAreaNames(areaKeys);
mc.set(COEditController.CONFIG_KEY_EMAILTOAREAS, areaNames);
}
......
......@@ -294,14 +294,14 @@ public class ENCourseNode extends AbstractAccessableCourseNode {
@SuppressWarnings("unchecked")
List<Long> groupKeys = (List<Long>) mc.get(ENCourseNode.CONFIG_GROUP_IDS);
if(groupKeys != null) {
String groupNames = envMapper.toOriginalGroupNames(groupKeys);
String groupNames = envMapper.toGroupNames(groupKeys);
mc.set(ENCourseNode.CONFIG_GROUPNAME, groupNames);
}
@SuppressWarnings("unchecked")
List<Long> areaKeys = (List<Long>) mc.get(ENCourseNode.CONFIG_AREA_IDS);
if(areaKeys != null ) {
String areaNames = envMapper.toOriginalAreaNames(areaKeys);
String areaNames = envMapper.toAreaNames(areaKeys);
mc.set(ENCourseNode.CONFIG_AREANAME, areaNames);
}
......
......@@ -398,22 +398,24 @@ public abstract class GenericCourseNode extends GenericNode implements CourseNod
boolean easy = StringHelper.containsNonWhitespace(condition.getConditionFromEasyModeConfiguration());
if(easy) {
List<Long> groupKeys = condition.getEasyModeGroupAccessIdList();
if(groupKeys == null) {
if(groupKeys == null || groupKeys.isEmpty()) {
//this is an old course -> get group keys from original names
groupKeys = envMapper.toGroupKeyFromOriginalNames(condition.getEasyModeGroupAccess());
} else {
//map the original exported group key to the newly created one
groupKeys = envMapper.toGroupKeyFromOriginalKeys(groupKeys);
}
condition.setEasyModeGroupAccessIdList(groupKeys);
condition.setEasyModeGroupAccessIdList(groupKeys);//update keys
condition.setEasyModeGroupAccess(envMapper.toGroupNames(groupKeys));//update names with the current values
List<Long> areaKeys = condition.getEasyModeGroupAreaAccessIdList();
if(areaKeys == null) {
if(areaKeys == null || areaKeys.isEmpty()) {
areaKeys = envMapper.toAreaKeyFromOriginalNames(condition.getEasyModeGroupAreaAccess());
} else {
areaKeys = envMapper.toAreaKeyFromOriginalKeys(areaKeys);
}
condition.setEasyModeGroupAreaAccessIdList(areaKeys);
condition.setEasyModeGroupAreaAccess(envMapper.toAreaNames(areaKeys));
String condString = condition.getConditionFromEasyModeConfiguration();
condition.setConditionExpression(condString);
......@@ -444,9 +446,9 @@ public abstract class GenericCourseNode extends GenericNode implements CourseNod
if(condition.getEasyModeGroupAccessIdList() != null
|| condition.getEasyModeGroupAreaAccessIdList() != null) {
String groupNames = envMapper.toOriginalGroupNames(condition.getEasyModeGroupAccessIdList());
String groupNames = envMapper.toGroupNames(condition.getEasyModeGroupAccessIdList());
condition.setEasyModeGroupAccess(groupNames);
String areaNames = envMapper.toOriginalAreaNames(condition.getEasyModeGroupAreaAccessIdList());
String areaNames = envMapper.toAreaNames(condition.getEasyModeGroupAreaAccessIdList());
condition.setEasyModeGroupAreaAccess(areaNames);
String condString = condition.getConditionFromEasyModeConfiguration();
if(backwardsCompatible) {
......
......@@ -26,6 +26,7 @@ import java.util.List;
import org.olat.basesecurity.BaseSecurity;
import org.olat.core.commons.persistence.DB;
import org.olat.core.id.Roles;
import org.olat.course.CorruptedCourseException;
import org.olat.course.CourseFactory;
import org.olat.course.ICourse;
import org.olat.course.export.CourseEnvironmentMapper;
......@@ -167,9 +168,13 @@ public class OLATUpgrade_8_2_0 extends OLATUpgrade {
do {
entries = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, REPO_ENTRIES_BATCH_SIZE, true);
for(RepositoryEntry entry:entries) {
ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
CourseEnvironmentMapper envMapper = getCourseEnvironmentMapper(entry.getOlatResource());
course.postImport(envMapper);
try {
ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
CourseEnvironmentMapper envMapper = getCourseEnvironmentMapper(entry.getOlatResource());
course.postImport(envMapper);
} catch (CorruptedCourseException e) {
log.error("Course seems corrupt: " + entry.getOlatResource().getResourceableId());
}
}
counter += entries.size();
log.audit("Processed repository entries: " + entries.size());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment