diff --git a/src/main/java/org/olat/core/util/PathUtils.java b/src/main/java/org/olat/core/util/PathUtils.java index b54ec3819456929481eb723073856d14b6bc41ca..703ed0c88c7b402fd2284fe91c83f8324e715e8a 100644 --- a/src/main/java/org/olat/core/util/PathUtils.java +++ b/src/main/java/org/olat/core/util/PathUtils.java @@ -28,9 +28,11 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.PathMatcher; import java.nio.file.Paths; +import java.nio.file.ProviderNotFoundException; import java.nio.file.SimpleFileVisitor; import java.nio.file.StandardCopyOption; import java.nio.file.attribute.BasicFileAttributes; +import java.util.ServiceConfigurationError; /** * @@ -50,7 +52,11 @@ public class PathUtils { if(file.isDirectory()) { fPath = file.toPath(); } else if(filename != null && filename.toLowerCase().endsWith(".zip")) { - fPath = FileSystems.newFileSystem(file.toPath(), null).getPath("/"); + try { + fPath = FileSystems.newFileSystem(file.toPath(), null).getPath("/"); + } catch (ProviderNotFoundException | ServiceConfigurationError e) { + throw new IOException("Unreadable file with .zip extension: " + file, e); + } } else { fPath = file.toPath(); } diff --git a/src/main/java/org/olat/portfolio/manager/EPStructureManager.java b/src/main/java/org/olat/portfolio/manager/EPStructureManager.java index 1536171ab6def8a3fb01439b324f177666e673d2..eb5253a26beda9014e77c66739fcba272f89249f 100755 --- a/src/main/java/org/olat/portfolio/manager/EPStructureManager.java +++ b/src/main/java/org/olat/portfolio/manager/EPStructureManager.java @@ -1653,7 +1653,7 @@ public class EPStructureManager extends BasicManager { el.setDescription(description); OLATResource resource = resourceManager.createOLATResourceInstance(el.getClass()); el.setOlatResource(resource); - dbInstance.saveObject(resource); + dbInstance.getCurrentEntityManager().persist(resource); return el; } @@ -1661,7 +1661,9 @@ public class EPStructureManager extends BasicManager { el.setTitle(title); el.setDescription(description); el.setOlatResource(resource); - dbInstance.saveObject(resource); + if(resource.getKey() == null) { + dbInstance.getCurrentEntityManager().persist(resource); + } return el; } @@ -1860,8 +1862,10 @@ public class EPStructureManager extends BasicManager { if(portfolioStructure instanceof PersistentObject) { PersistentObject persistentStructure = (PersistentObject)portfolioStructure; if(persistentStructure.getKey() == null) { - dbInstance.saveObject(portfolioStructure.getOlatResource()); - dbInstance.saveObject(portfolioStructure); + if(portfolioStructure.getOlatResource().getKey() == null) { + dbInstance.getCurrentEntityManager().persist(portfolioStructure.getOlatResource()); + } + dbInstance.getCurrentEntityManager().persist(portfolioStructure); } else { dbInstance.updateObject(portfolioStructure); } diff --git a/src/main/java/org/olat/repository/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/repository/_i18n/LocalStrings_de.properties index 3b3a908ba1c2005291a9cc0f22e9371e0d4a03ae..23a16e9a2b87108232531b72a61a510e24d45e0f 100644 --- a/src/main/java/org/olat/repository/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/repository/_i18n/LocalStrings_de.properties @@ -340,6 +340,7 @@ error.course.alreadylocked=Dieser Kurs wird im Moment von {0} editiert und ist d error.createcopy=Beim Kopieren des Objektes ist ein Fehler aufgetreten. Die Aktion wurde abgebrochen. error.download=Beim Download des Objektes ist ein Fehler aufgetreten. Die Aktion wurde abgebrochen. error.export=Beim Exportieren des Objektes ist ein Fehler aufgetreten. Die Aktion wurde abgebrochen. +error.import=Beim Importieren des Objektes ist ein Fehler aufgetreten. Die Aktion wurde abgebrochen. error.launch=Beim Starten des Objektes ist ein Fehler aufgetreten. Die Aktion wurde abgebrochen. error.msg.send.no.rcps=$org.olat.modules.co\:error.msg.send.no.rcps filter.booked.author=Belegt als Autor diff --git a/src/main/java/org/olat/repository/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/repository/_i18n/LocalStrings_en.properties index ea60daed3a479678cf41ee93be1564ba1f2cd3a8..52a0c4b0756c872a9ca296d0aadfb821e38c3086 100644 --- a/src/main/java/org/olat/repository/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/repository/_i18n/LocalStrings_en.properties @@ -339,6 +339,7 @@ error.course.alreadylocked=This course is currently edited by {0} and therefore error.createcopy=An error occurred while trying to copy the object. Action canceled. error.download=An error occurred while trying to download the object. Action canceled. error.export=Error while exporting this object. Action aborted. +error.import=Error while importing this object. Action aborted. error.launch=An error occurred while trying to launch the object. Action canceled. error.msg.send.no.rcps=$org.olat.modules.co\:error.msg.send.no.rcps filter.booked.author=Booked as author diff --git a/src/main/java/org/olat/repository/handlers/PortfolioHandler.java b/src/main/java/org/olat/repository/handlers/PortfolioHandler.java index 6e6edb63917a5541142823aeae734169ed87be09..7031582cb6ad9f540cdb873d7bf92a2f32647406 100644 --- a/src/main/java/org/olat/repository/handlers/PortfolioHandler.java +++ b/src/main/java/org/olat/repository/handlers/PortfolioHandler.java @@ -141,7 +141,7 @@ public class PortfolioHandler implements RepositoryHandler { @Override public RepositoryEntry copy(RepositoryEntry source, RepositoryEntry target) { OLATResource sourceResource = source.getOlatResource(); - OLATResource targetResource = source.getOlatResource(); + OLATResource targetResource = target.getOlatResource(); EPFrontendManager ePFMgr = CoreSpringFactory.getImpl(EPFrontendManager.class); PortfolioStructure structure = ePFMgr.loadPortfolioStructure(sourceResource); diff --git a/src/main/java/org/olat/repository/ui/author/AuthorListController.java b/src/main/java/org/olat/repository/ui/author/AuthorListController.java index c387e384cfbb09fb8474a4d34a1801eb90141080..14e8f823dca86f25cf08f85ebc04b263c4192a61 100644 --- a/src/main/java/org/olat/repository/ui/author/AuthorListController.java +++ b/src/main/java/org/olat/repository/ui/author/AuthorListController.java @@ -841,10 +841,12 @@ public class AuthorListController extends FormBasicController implements Activat } private void launchEditDescription(UserRequest ureq, RepositoryEntry re) { - RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(re); - if(handler != null) { - String businessPath = "[RepositoryEntry:" + re.getKey() + "][EditDescription:0]"; - NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl()); + if(re != null) { + RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(re); + if(handler != null) { + String businessPath = "[RepositoryEntry:" + re.getKey() + "][EditDescription:0]"; + NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl()); + } } } diff --git a/src/main/java/org/olat/repository/ui/author/ImportRepositoryEntryController.java b/src/main/java/org/olat/repository/ui/author/ImportRepositoryEntryController.java index 76ff6d1ec62368b81bc85ae97420bab0f93ade34..bfbb84e21f0d780e17a2ec4c47ce0cbb217d5894 100644 --- a/src/main/java/org/olat/repository/ui/author/ImportRepositoryEntryController.java +++ b/src/main/java/org/olat/repository/ui/author/ImportRepositoryEntryController.java @@ -227,11 +227,15 @@ public class ImportRepositoryEntryController extends FormBasicController { importedEntry = handler.importResource(getIdentity(), null, displayname, "", withReferences, getLocale(), uploadedFile, uploadedFilename); - - ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_CREATE, getClass(), - LoggingResourceable.wrap(importedEntry, OlatResourceableType.genRepoEntry)); - repositoryManager.triggerIndexer(importedEntry); + if(importedEntry == null) { + showWarning("error.import"); + } else { + ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_CREATE, getClass(), + LoggingResourceable.wrap(importedEntry, OlatResourceableType.genRepoEntry)); + + repositoryManager.triggerIndexer(importedEntry); + } } } diff --git a/src/test/java/org/olat/portfolio/EPImportTest.java b/src/test/java/org/olat/portfolio/EPImportTest.java index 3617c09f8f3bbc6283c874644d292c3c7594bf29..44d9298d214c116f23f672563fd9a821586755e7 100644 --- a/src/test/java/org/olat/portfolio/EPImportTest.java +++ b/src/test/java/org/olat/portfolio/EPImportTest.java @@ -28,14 +28,18 @@ import java.net.URL; import org.junit.Assert; import org.junit.Test; import org.olat.core.commons.persistence.DB; -import org.olat.core.id.OLATResourceable; -import org.olat.core.util.resource.OresHelper; +import org.olat.core.id.Identity; import org.olat.portfolio.manager.EPFrontendManager; +import org.olat.portfolio.manager.EPStructureManager; import org.olat.portfolio.manager.EPXStreamHandler; import org.olat.portfolio.model.structel.PortfolioStructure; import org.olat.portfolio.model.structel.PortfolioStructureMap; +import org.olat.repository.RepositoryEntry; +import org.olat.repository.RepositoryManager; +import org.olat.repository.RepositoryService; import org.olat.resource.OLATResource; import org.olat.resource.OLATResourceManager; +import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; import org.springframework.beans.factory.annotation.Autowired; @@ -53,6 +57,12 @@ public class EPImportTest extends OlatTestCase { private OLATResourceManager resourceManager; @Autowired private EPFrontendManager epFrontendManager; + @Autowired + private EPStructureManager epStructureManager; + @Autowired + private RepositoryManager repositoryManager; + @Autowired + private RepositoryService repositoryService; @Test @@ -60,16 +70,34 @@ public class EPImportTest extends OlatTestCase { URL mapUrl = EPImportTest.class.getResource("map_81.xml.zip"); assertNotNull(mapUrl); File mapFile = new File(mapUrl.toURI()); - - OLATResourceable ores = OresHelper.createOLATResourceableType("EPMapTemplate"); - OLATResource resource = resourceManager.createAndPersistOLATResourceInstance(ores); - //import the map PortfolioStructure rootStructure = EPXStreamHandler.getAsObject(mapFile, false); + OLATResource resource = epStructureManager.createPortfolioMapTemplateResource(); + + //import the map PortfolioStructureMap importedMap = epFrontendManager.importPortfolioMapTemplate(rootStructure, resource); Assert.assertNotNull(importedMap); dbInstance.commitAndCloseSession(); } + @Test + public void testCopy() throws URISyntaxException { + Identity ident = JunitTestHelper.createAndPersistIdentityAsRndUser("ImPort-1"); + //save the map + PortfolioStructureMap map = epStructureManager.createPortfolioMapTemplate(ident, "import-map-1", "map-template"); + epStructureManager.savePortfolioStructure(map); + dbInstance.commitAndCloseSession(); + + //check that the author are in the + OLATResource resource = resourceManager.findResourceable(map.getResourceableId(), map.getResourceableTypeName()); + RepositoryEntry re = repositoryManager.lookupRepositoryEntry(resource, false); + Assert.assertNotNull(re); + dbInstance.commitAndCloseSession(); - + RepositoryEntry copy = repositoryService.copy(re, ident, "ImPort - (Copy 1)"); + Assert.assertNotNull(copy); + dbInstance.commitAndCloseSession(); + + PortfolioStructure copiedMap = epFrontendManager.loadPortfolioStructure(copy.getOlatResource()); + Assert.assertNotNull(copiedMap); + } }