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

OO-292: rewrite the import for eportfolio with a xslt transformation to remove...

OO-292: rewrite the import for eportfolio with a xslt transformation to remove conflicting resources as user proeprties, artefacts... make the standard xstream more robust to transform hibernate collections in standard ones, make it robust to the package changes within hibernate
parent 81c504fe
No related branches found
No related tags found
No related merge requests found
Showing
with 328 additions and 322 deletions
......@@ -21,6 +21,7 @@ package org.olat.core.util.xml;
import org.hibernate.collection.internal.PersistentBag;
import org.hibernate.collection.internal.PersistentList;
import org.hibernate.collection.internal.PersistentMap;
import com.thoughtworks.xstream.mapper.MapperWrapper;
......@@ -42,19 +43,10 @@ public class EnhancedMapper extends MapperWrapper {
return PersistentBag.class;
} else if("org.hibernate.collection.PersistentList".equals(elementName)) {
return PersistentList.class;
} else if("org.hibernate.collection.PersistentMap".equals(elementName)) {
return PersistentMap.class;
} else {
return super.realClass(elementName);
}
}
@SuppressWarnings("rawtypes")
public String serializedClass(final Class type) {
if(PersistentBag.class.equals(type)) {
return "org.hibernate.collection.PersistentBag";
} else if(PersistentList.class.equals(type)) {
return "org.hibernate.collection.PersistentList";
} else {
return super.serializedClass(type);
}
}
}
/**
* <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 java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hibernate.collection.internal.PersistentBag;
import org.hibernate.collection.internal.PersistentList;
import org.hibernate.collection.internal.PersistentMap;
import org.hibernate.collection.internal.PersistentSet;
import org.hibernate.collection.internal.PersistentSortedMap;
import org.hibernate.collection.internal.PersistentSortedSet;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.collections.CollectionConverter;
import com.thoughtworks.xstream.converters.collections.MapConverter;
import com.thoughtworks.xstream.mapper.MapperWrapper;
/**
* This implmentation of XStream automatically convert hibernat list, set and map
* to standard java collections and convert by import / deserialization
* the old hibernate 3 collection packages to the new one.
*
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*/
public class EnhancedXStream extends XStream {
public EnhancedXStream() {
super();
addDefaultImplementation(PersistentList.class, List.class);
addDefaultImplementation(PersistentBag.class, List.class);
addDefaultImplementation(PersistentMap.class, Map.class);
addDefaultImplementation(PersistentSortedMap.class, Map.class);
addDefaultImplementation(PersistentSet.class, Set.class);
addDefaultImplementation(PersistentSortedSet.class, Set.class);
addDefaultImplementation(ArrayList.class, List.class);
registerConverter(new CollectionConverter(getMapper()) {
public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
return PersistentList.class == type || PersistentBag.class == type;
}
});
registerConverter(new MapConverter(getMapper()) {
public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
return PersistentMap.class == type;
}
});
}
@Override
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new EnhancedMapper(next);
}
}
/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <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>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <hr>
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* This file has been modified by the OpenOLAT community. Changes are licensed
* under the Apache 2.0 license as the original file.
* <p>
*/
package org.olat.core.util.xml;
import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Element;
import org.olat.core.logging.OLATRuntimeException;
/**
* enclosing_type Description: <br>
*
* @author Felix Jost
*/
public class Util {
/**
* @param o
* @param file
*/
public static void writeObjectAsXML(Object o, String file) {
XMLEncoder e;
try {
e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(file)));
e.writeObject(o);
e.close();
} catch (FileNotFoundException e1) {
throw new OLATRuntimeException(Util.class, "Error writing object to XML.", e1);
}
}
/**
* @param elem
* @return String
*/
public static String getTextsOnly(Element elem) {
StringBuilder sb = new StringBuilder();
visit(sb, elem);
return sb.toString();
}
private static void visit(StringBuilder sb, Element elem) {
sb.append(elem.getTextTrim());
List children = elem.elements();
for (Iterator it_ch = children.iterator(); it_ch.hasNext();) {
Element element = (Element) it_ch.next();
visit(sb, element);
}
}
}
\ No newline at end of file
/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <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>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <hr>
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* This file has been modified by the OpenOLAT community. Changes are licensed
* under the Apache 2.0 license as the original file.
* <p>
*/
package org.olat.core.util.xml;
/**
* Description:<br>
* TODO: Felix Class Description for XMLPrettyPrinter
* <P>
* Initial Date: 09.09.2005 <br>
*
* @author Felix
*/
public class XMLPrettyPrinter {
/*
public static String prettyPrint(String in) {
StringBuilder sb = new StringBuilder();
DefaultHandler handler = new SAXIndent(sb);
// Parse the input with the default (non-validating) parser
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(new InputSource(new StringReader(in)), handler);
try {
StringWriter sw = new StringWriter();
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty(OutputKeys.METHOD, "xml");
t.setOutputProperty(OutputKeys.STANDALONE, "yes");
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
t.transform(new StreamSource(new StringReader(componentListenerInfo)), new StreamResult(sw));
String res = sw.getBuffer().toString();
componentListenerInfo = res;
} catch (Exception e) {
// ignore
}
String r = componentListenerInfo;
}
*/
}
/*
class SAXIndent extends DefaultHandler {
private static String sNEWLINE = "\n";
private StringBuilder sb;
SAXIndent(StringBuilder sb) {
this.sb = sb;
}
public void startDocument() throws SAXException {
echoString(sNEWLINE + "<?xml ...?>" + sNEWLINE + sNEWLINE);
}
public void endDocument() throws SAXException {
echoString(sNEWLINE);
}
public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) throws SAXException {
echoTextBuffer();
String eName = ("".equals(localName)) ? qName : localName;
echoString("<" + eName); // element name
if (attrs != null) {
for (int i = 0; i < attrs.getLength(); i++) {
String aName = attrs.getLocalName(i); // Attr name
if ("".equals(aName)) aName = attrs.getQName(i);
echoString(" " + aName + "=\"" + attrs.getValue(i) + "\"");
}
}
echoString(">");
}
public void endElement(String namespaceURI, String localName, // local name
String qName) // qualified name
throws SAXException {
echoTextBuffer();
String eName = ("".equals(localName)) ? qName : localName;
echoString("</" + eName + ">"); // element name
}
public void characters(char[] buf, int offset, int len) throws SAXException {
String s = new String(buf, offset, len);
sb.append(s);
}
// ---- Helper methods ----
// Display text accumulated in the character buffer
private void echoTextBuffer() throws SAXException {
if (textBuffer == null) return;
echoString(textBuffer.toString());
textBuffer = null;
}
// Wrap I/O exceptions in SAX exceptions, to
// suit handler signature requirements
private void echoString(String s) throws SAXException {
try {
if (null == out) out = new OutputStreamWriter(System.out, "UTF8");
out.write(s);
out.flush();
} catch (IOException ex) {
throw new SAXException("I/O error", ex);
}
}
}
*/
......@@ -40,7 +40,6 @@ 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>
......@@ -225,7 +224,8 @@ public class XStreamHelper {
* writing to a configured XML mapping
*/
public static XStream createXStreamInstance() {
return new EnhancedXStream();
EnhancedXStream xstream = new EnhancedXStream();
return xstream;
}
/**
......@@ -379,12 +379,4 @@ public class XStreamHelper {
FileUtils.closeSafely(os);
}
}
private static class EnhancedXStream extends XStream {
@Override
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new EnhancedMapper(next);
}
}
}
......@@ -50,6 +50,7 @@ import org.olat.course.nodes.CourseNode;
import org.olat.course.nodes.portfolio.PortfolioCourseNodeEditController;
import org.olat.portfolio.EPTemplateMapResource;
import org.olat.portfolio.manager.EPFrontendManager;
import org.olat.portfolio.manager.EPXStreamHandler;
import org.olat.portfolio.model.structel.EPStructuredMapTemplate;
import org.olat.portfolio.model.structel.PortfolioStructure;
import org.olat.portfolio.model.structel.PortfolioStructureMap;
......@@ -59,7 +60,6 @@ import org.olat.repository.RepositoryEntryImportExport;
import org.olat.repository.RepositoryManager;
import org.olat.repository.RepositoryTableModel;
import org.olat.repository.controllers.RepositorySearchController;
import org.olat.repository.handlers.PortfolioHandler;
import org.olat.repository.handlers.RepositoryHandler;
import org.olat.repository.handlers.RepositoryHandlerFactory;
import org.olat.resource.OLATResource;
......@@ -174,7 +174,7 @@ public class ImportPortfolioReferencesController extends BasicController {
public static RepositoryEntry doImport(RepositoryEntryImportExport importExport, CourseNode node, boolean keepSoftkey,
Identity owner) {
File fExportedFile = importExport.importGetExportedFile();
PortfolioStructure structure = PortfolioHandler.getAsObject(fExportedFile);
PortfolioStructure structure = EPXStreamHandler.getAsObject(fExportedFile, false);
if(structure == null) {
log.warn("Error adding portfolio map resource during repository reference import: " + importExport.getDisplayName());
return null;
......
Entfernen aller versions etc. Tags die beim mergen Konflikte bereiten und eh überflüssig sind:
1) Paket selektieren und auf Search gehen
2) File search nach ^ *\*.*\$:*$ (regexp enablen)
3) Nicht suchen sondern replace drücken
4) Jede gefundene Stelle duchsteppen und ersetzen mit nichts
5) Refresh (F5)
6) Synchronize, outgoing changes
7) Jeden change anschauen und die Leerzeile weglöschen. So hat man grad
die Kontrolle dass alles korrekt gelöscht ist. Zudem immer schauen ob Tags vergessen
gegangen sind (Ein paar werden mit der regexp nicht gefunden)
8) Checkin
Packages (inklusive subpackages)
PACKAGE WER STATUS
-------------------------------
admin fg done
basesecurity fg done
bookmark fg done
catalog fg done
collaboration fg done
configuration fg done
org.olat.gui.components fj done
......@@ -28,7 +28,6 @@ import java.util.Map;
import java.util.Set;
import org.olat.basesecurity.BaseSecurity;
import org.olat.basesecurity.BaseSecurityManager;
import org.olat.basesecurity.Constants;
import org.olat.basesecurity.IdentityShort;
import org.olat.basesecurity.Policy;
......
......@@ -1877,6 +1877,9 @@ public class EPStructureManager extends BasicManager {
private static class KeyStructureToStructureLinkComparator implements Comparator<EPStructureToStructureLink>, Serializable {
private static final long serialVersionUID = 366101659547497002L;
public KeyStructureToStructureLinkComparator() {
//
}
......
/**
* <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.portfolio.manager;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.io.IOUtils;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.xml.XStreamHelper;
import org.olat.portfolio.model.restriction.CollectRestriction;
import org.olat.portfolio.model.structel.EPAbstractMap;
import org.olat.portfolio.model.structel.EPDefaultMap;
import org.olat.portfolio.model.structel.EPPage;
import org.olat.portfolio.model.structel.EPStructureElement;
import org.olat.portfolio.model.structel.EPStructureToArtefactLink;
import org.olat.portfolio.model.structel.EPStructureToStructureLink;
import org.olat.portfolio.model.structel.EPStructuredMap;
import org.olat.portfolio.model.structel.EPStructuredMapTemplate;
import org.olat.portfolio.model.structel.PortfolioStructure;
import com.thoughtworks.xstream.XStream;
/**
*
*
*
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*/
public class EPXStreamHandler {
private static final OLog log = Tracing.createLoggerFor(EPXStreamHandler.class);
private static final XStream myStream = XStreamHelper.createXStreamInstance();
private static Templates filterArtefactsTemplates;
static { // initialize supported types
myStream.alias("defaultMap", EPDefaultMap.class);
myStream.alias("structureMap", EPStructuredMap.class);
myStream.alias("templateMap", EPStructuredMapTemplate.class);
myStream.alias("structure", EPStructureElement.class);
myStream.alias("page", EPPage.class);
myStream.alias("structureToArtefact", EPStructureToArtefactLink.class);
myStream.alias("structureToStructure", EPStructureToStructureLink.class);
myStream.alias("collectionRestriction", CollectRestriction.class);
myStream.omitField(EPAbstractMap.class, "ownerGroup"); // see also OLAT-6344
try {
InputStream xsltIn = EPXStreamHandler.class.getResourceAsStream("portfolio_without_artefacts.xsl");
Source xsltSource = new StreamSource(xsltIn);
filterArtefactsTemplates = TransformerFactory.newInstance().newTemplates(xsltSource);
} catch (TransformerConfigurationException e) {
log.error("", e);
} catch (TransformerFactoryConfigurationError e) {
log.error("", e);
}
}
public static final PortfolioStructure copy(PortfolioStructure structure) {
String stringuified = myStream.toXML(structure);
PortfolioStructure newStructure = (PortfolioStructure)myStream.fromXML(stringuified);
return newStructure;
}
public static final PortfolioStructure getAsObject(File fMapXml, boolean withArtefacts) {
try {
//extract from zip
InputStream in = new FileInputStream(fMapXml);
ZipInputStream zipIn = new ZipInputStream(in);
//open the entry of the map
zipIn.getNextEntry();
Writer buffer = new StringWriter();
if(!withArtefacts) {
Transformer transformer = filterArtefactsTemplates.newTransformer();
transformer.transform(new StreamSource(zipIn), new StreamResult(buffer));
} else {
IOUtils.copy(zipIn, buffer);
}
PortfolioStructure struct = (PortfolioStructure) myStream.fromXML(buffer.toString());
// OLAT-6344: reset ownerGroup from earlier exports. A new group is created by import in ePFMgr.importPortfolioMapTemplate() later on anyway.
((EPAbstractMap) struct).setOwnerGroup(null);
return struct;
} catch (Exception e) {
log.error("Cannot export this map: " + fMapXml, e);
}
return null;
}
public static final InputStream toStream(PortfolioStructure structure)
throws IOException {
String xmlStructure = myStream.toXML(structure);
try {
//prepare a zip
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream(out);
zipOut.putNextEntry(new ZipEntry("map.xml"));
InputStream in = new ByteArrayInputStream(xmlStructure.getBytes("UTF8"));
IOUtils.copy(in, out);
zipOut.closeEntry();
zipOut.close();
//prepare media resource
byte[] outArray = out.toByteArray();
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(in);
return new ByteArrayInputStream(outArray);
} catch (IOException e) {
log.error("Cannot export this map: " + structure, e);
return null;
}
}
}
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="artefacts">
<!-- Ommit artefacts -->
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
......@@ -25,12 +25,21 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.fullWebApp.LayoutMain3ColsController;
import org.olat.core.gui.UserRequest;
......@@ -55,6 +64,7 @@ import org.olat.portfolio.EPSecurityCallbackFactory;
import org.olat.portfolio.EPTemplateMapResource;
import org.olat.portfolio.EPUIFactory;
import org.olat.portfolio.manager.EPFrontendManager;
import org.olat.portfolio.manager.EPXStreamHandler;
import org.olat.portfolio.model.restriction.CollectRestriction;
import org.olat.portfolio.model.structel.EPAbstractMap;
import org.olat.portfolio.model.structel.EPDefaultMap;
......@@ -76,7 +86,6 @@ import org.olat.resource.accesscontrol.ui.RepositoryMainAccessControllerWrapper;
import org.olat.resource.references.ReferenceManager;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.collections.CollectionConverter;
import de.bps.onyx.plugin.StreamMediaResource;
......@@ -97,7 +106,6 @@ public class PortfolioHandler implements RepositoryHandler {
public static final String PROCESS_CREATENEW = "create_new";
public static final String PROCESS_UPLOAD = "upload";
public static XStream myStream = XStreamHelper.createXStreamInstance();
private static final boolean DOWNLOADABLE = false;
private static final boolean EDITABLE = true;
......@@ -108,24 +116,6 @@ public class PortfolioHandler implements RepositoryHandler {
static { // initialize supported types
supportedTypes = new ArrayList<String>(1);
supportedTypes.add(EPTemplateMapResource.TYPE_NAME);
myStream.alias("defaultMap", EPDefaultMap.class);
myStream.alias("structureMap", EPStructuredMap.class);
myStream.alias("templateMap", EPStructuredMapTemplate.class);
myStream.alias("structure", EPStructureElement.class);
myStream.alias("page", EPPage.class);
myStream.alias("structureToArtefact", EPStructureToArtefactLink.class);
myStream.alias("structureToStructure", EPStructureToStructureLink.class);
myStream.alias("collectionRestriction", CollectRestriction.class);
myStream.omitField(EPAbstractMap.class, "ownerGroup"); // see also OLAT-6344
//myStream.addDefaultImplementation(PersistentList.class, List.class);
myStream.addDefaultImplementation(ArrayList.class, List.class);
/*myStream.registerConverter(new CollectionConverter(myStream.getMapper()) {
public boolean canConvert(Class type) {
return PersistentList.class == type;
}
});*/
}
/**
......@@ -211,8 +201,7 @@ public class PortfolioHandler implements RepositoryHandler {
public OLATResourceable createCopy(OLATResourceable res, UserRequest ureq) {
EPFrontendManager ePFMgr = (EPFrontendManager)CoreSpringFactory.getBean("epFrontendManager");
PortfolioStructure structure = ePFMgr.loadPortfolioStructure(res);
String stringuified = myStream.toXML(structure);
PortfolioStructure newStructure = (PortfolioStructure)myStream.fromXML(stringuified);
PortfolioStructure newStructure = EPXStreamHandler.copy(structure);
PortfolioStructureMap map = ePFMgr.importPortfolioMapTemplate(newStructure, ureq.getIdentity());
return map.getOlatResource();
}
......@@ -239,54 +228,14 @@ public class PortfolioHandler implements RepositoryHandler {
EPFrontendManager ePFMgr = (EPFrontendManager)CoreSpringFactory.getBean("epFrontendManager");
PortfolioStructure structure = ePFMgr.loadPortfolioStructure(res);
String xmlStructure = myStream.toXML(structure);
try {
//prepare a zip
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream(out);
zipOut.putNextEntry(new ZipEntry("map.xml"));
InputStream in = new ByteArrayInputStream(xmlStructure.getBytes("UTF8"));
FileUtils.copy(in, zipOut);
zipOut.closeEntry();
zipOut.close();
//prepare media resource
byte[] outArray = out.toByteArray();
FileUtils.closeSafely(out);
FileUtils.closeSafely(in);
InputStream inOut = new ByteArrayInputStream(outArray);
InputStream inOut = EPXStreamHandler.toStream(structure);
mr = new StreamMediaResource(inOut, null, 0l, 0l);
} catch (IOException e) {
log.error("Cannot export this map: " + structure, e);
}
return mr;
}
public static final PortfolioStructure getAsObject(File fMapXml) {
try {
//extract from zip
InputStream in = new FileInputStream(fMapXml);
ZipInputStream zipIn = new ZipInputStream(in);
ZipEntry entry = zipIn.getNextEntry();
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileUtils.copy(zipIn, out);
zipIn.closeEntry();
zipIn.close();
//prepare decoding with xstream
byte[] outArray = out.toByteArray();
String xml = new String(outArray);
PortfolioStructure struct = (PortfolioStructure) myStream.fromXML(xml);
// OLAT-6344: reset ownerGroup from earlier exports. A new group is created by import in ePFMgr.importPortfolioMapTemplate() later on anyway.
((EPAbstractMap) struct).setOwnerGroup(null);
return struct;
} catch (IOException e) {
log.error("Cannot export this map: " + fMapXml, e);
}
return null;
}
/**
* @see org.olat.repository.handlers.RepositoryHandler#getDetailsComponent(org.olat.core.id.OLATResourceable,
......
......@@ -133,6 +133,7 @@ public class EPFrontendManagerTest extends OlatTestCase {
epStructureManager.savePortfolioStructure(struct11);
//structure element 2 from page 1
PortfolioStructure struct12 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "template-structure-1.2", "template-structure-1.2");
assertNotNull(struct12);
//first page
PortfolioStructure page2 = epFrontendManager.createAndPersistPortfolioPage(templateEl, "template-page-2", "template-page-2");
//structure element 1 from page 2
......
/**
* <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.portfolio;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import junit.framework.Assert;
import org.junit.Test;
import org.olat.core.commons.persistence.DB;
import org.olat.portfolio.manager.EPFrontendManager;
import org.olat.portfolio.manager.EPXStreamHandler;
import org.olat.portfolio.model.structel.PortfolioStructure;
import org.olat.portfolio.model.structel.PortfolioStructureMap;
import org.olat.test.OlatTestCase;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Test different imports
*
*
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*/
public class EPImportTest extends OlatTestCase {
@Autowired
private DB dbInstance;
@Autowired
private EPFrontendManager epFrontendManager;
@Test
public void testImportFromOpenOLAT_81_Hibernate3() throws URISyntaxException {
URL mapUrl = EPImportTest.class.getResource("map_81.xml.zip");
assertNotNull(mapUrl);
File mapFile = new File(mapUrl.toURI());
//import the map
PortfolioStructure rootStructure = EPXStreamHandler.getAsObject(mapFile, false);
PortfolioStructureMap importedMap = epFrontendManager.importPortfolioMapTemplate(rootStructure, null);
Assert.assertNotNull(importedMap);
dbInstance.commitAndCloseSession();
}
}
File added
......@@ -122,6 +122,7 @@ import org.junit.runners.Suite;
org.olat.portfolio.EPFrontendManagerTest.class,
org.olat.portfolio.EPStructureManagerTest.class,
org.olat.portfolio.EPStructureToArtefactTest.class,
org.olat.portfolio.EPImportTest.class,
org.olat.commons.info.InfoManagerTest.class,
org.olat.core.commons.service.tagging.SimpleTagProposalManagerTest.class,
org.olat.commons.coordinate.singlevm.SingleVMLockerTest.class,
......
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