From ca5ff21bed65fceac70dcb5537702c13432a7ec6 Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Wed, 13 Aug 2014 11:37:58 +0200
Subject: [PATCH] OO-1160: refactor the deploy mechanism of courses to use the
 standard import of the course handler

---
 .../java/org/olat/course/CourseFactory.java   | 137 ++----------------
 .../java/org/olat/course/CourseModule.java    |   4 +-
 .../org/olat/course/_spring/courseContext.xml |  16 +-
 .../course/nodes/AbstractFeedCourseNode.java  |  26 ----
 .../ImportGlossaryReferencesController.java   | 110 --------------
 ...mportSharedfolderReferencesController.java | 100 -------------
 .../RepositoryEntryImportExport.java          |  25 +++-
 .../olat/repository/RepositoryManager.java    |   3 +
 .../java/org/olat/restapi/MyForumsTest.java   |   2 +-
 9 files changed, 48 insertions(+), 375 deletions(-)
 delete mode 100644 src/main/java/org/olat/course/repository/ImportGlossaryReferencesController.java
 delete mode 100644 src/main/java/org/olat/course/repository/ImportSharedfolderReferencesController.java

diff --git a/src/main/java/org/olat/course/CourseFactory.java b/src/main/java/org/olat/course/CourseFactory.java
index 2bfc5eacd2c..37d9e4c7ee5 100644
--- a/src/main/java/org/olat/course/CourseFactory.java
+++ b/src/main/java/org/olat/course/CourseFactory.java
@@ -43,8 +43,6 @@ import java.util.zip.ZipOutputStream;
 
 import org.apache.poi.util.IOUtils;
 import org.olat.admin.quota.QuotaConstants;
-import org.olat.basesecurity.BaseSecurity;
-import org.olat.basesecurity.BaseSecurityManager;
 import org.olat.commons.calendar.CalendarManager;
 import org.olat.commons.calendar.CalendarManagerFactory;
 import org.olat.commons.calendar.notification.CalendarNotificationManager;
@@ -102,7 +100,6 @@ import org.olat.core.util.vfs.VFSManager;
 import org.olat.core.util.vfs.VFSStatus;
 import org.olat.core.util.xml.XStreamHelper;
 import org.olat.course.archiver.ScoreAccountingHelper;
-import org.olat.course.assessment.manager.UserCourseInformationsManager;
 import org.olat.course.config.CourseConfig;
 import org.olat.course.config.CourseConfigManagerImpl;
 import org.olat.course.config.ui.courselayout.CourseLayoutHelper;
@@ -119,8 +116,6 @@ import org.olat.course.nodes.STCourseNode;
 import org.olat.course.nodes.TACourseNode;
 import org.olat.course.properties.CoursePropertyManager;
 import org.olat.course.properties.PersistingCoursePropertyManager;
-import org.olat.course.repository.ImportGlossaryReferencesController;
-import org.olat.course.repository.ImportSharedfolderReferencesController;
 import org.olat.course.run.RunMainController;
 import org.olat.course.run.environment.CourseEnvironment;
 import org.olat.course.statistic.AsyncExportManager;
@@ -130,14 +125,13 @@ import org.olat.course.tree.PublishTreeModel;
 import org.olat.group.BusinessGroup;
 import org.olat.instantMessaging.InstantMessagingService;
 import org.olat.instantMessaging.manager.ChatLogHelper;
-import org.olat.modules.glossary.GlossaryManager;
-import org.olat.modules.sharedfolder.SharedFolderManager;
 import org.olat.repository.RepositoryEntry;
 import org.olat.repository.RepositoryEntryImportExport;
 import org.olat.repository.RepositoryManager;
 import org.olat.repository.RepositoryService;
+import org.olat.repository.handlers.RepositoryHandler;
+import org.olat.repository.handlers.RepositoryHandlerFactory;
 import org.olat.resource.OLATResource;
-import org.olat.resource.OLATResourceManager;
 import org.olat.resource.references.ReferenceImpl;
 import org.olat.resource.references.ReferenceManager;
 import org.olat.testutils.codepoints.server.Codepoint;
@@ -162,26 +156,20 @@ public class CourseFactory extends BasicManager {
 	public static final String COURSE_EDITOR_LOCK = "courseEditLock";
   //this is the lock that must be aquired at course editing, copy course, export course, configure course.
 	private static Map<Long,PersistingCourseImpl> courseEditSessionMap = new ConcurrentHashMap<Long,PersistingCourseImpl>();
-	private static OLog log = Tracing.createLoggerFor(CourseFactory.class);
+	private static final OLog log = Tracing.createLoggerFor(CourseFactory.class);
 	private static RepositoryManager repositoryManager;
-	private static OLATResourceManager olatResourceManager;
-	private static BaseSecurity securityManager;
 	private static ReferenceManager referenceManager;
-	private static GlossaryManager glossaryManager;
 	private static RepositoryService repositoryService;
 	
 	
 	/**
 	 * [used by spring]
 	 */
-	private CourseFactory(CoordinatorManager coordinatorManager, RepositoryManager repositoryManager, RepositoryService repositoryService, OLATResourceManager olatResourceManager, 
-			BaseSecurity securityManager, ReferenceManager referenceManager, GlossaryManager glossaryManager) {
+	private CourseFactory(CoordinatorManager coordinatorManager, RepositoryManager repositoryManager,
+			RepositoryService repositoryService, ReferenceManager referenceManager) {
 		loadedCourses = coordinatorManager.getCoordinator().getCacher().getCache(CourseFactory.class.getSimpleName(), "courses");
 		CourseFactory.repositoryManager = repositoryManager;
-		CourseFactory.olatResourceManager = olatResourceManager;
-		CourseFactory.securityManager = securityManager;
 		CourseFactory.referenceManager = referenceManager;
-		CourseFactory.glossaryManager = glossaryManager;
 		CourseFactory.repositoryService = repositoryService;
 	}
 	
@@ -579,129 +567,32 @@ public class CourseFactory extends BasicManager {
 	 * 
 	 * @param exportedCourseZIPFile
 	 */
-	public static RepositoryEntry deployCourseFromZIP(File exportedCourseZIPFile, int access) {
-		return deployCourseFromZIP(exportedCourseZIPFile, null, access);
-	}
-	
 	public static RepositoryEntry deployCourseFromZIP(File exportedCourseZIPFile, String softKey, int access) {
-		// create the course instance
-		OLATResource newCourseResource = olatResourceManager.createOLATResourceInstance(CourseModule.class);
-		ICourse course = CourseFactory.importCourseFromZip(newCourseResource, exportedCourseZIPFile);
-		// course is now also in course cache!
-		if (course == null) {
-			log.error("Error deploying course from ZIP: " + exportedCourseZIPFile.getAbsolutePath());
-			return null;
-		}
-		File courseExportData = course.getCourseExportDataDir().getBasefile();
-		// get the export data directory
-		// create the repository entry
-		RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(courseExportData);
+
+		RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(exportedCourseZIPFile);
 		if(!StringHelper.containsNonWhitespace(softKey)) {
 			softKey = importExport.getSoftkey();
 		}
 		RepositoryEntry existingEntry = repositoryManager.lookupRepositoryEntryBySoftkey(softKey, false);
 		if (existingEntry != null) {
 			log.info("RepositoryEntry with softkey " + softKey + " already exists. Course will not be deployed.");
-			//seem to be a problem
-			UserCourseInformationsManager userCourseInformationsManager = CoreSpringFactory.getImpl(UserCourseInformationsManager.class);
-			userCourseInformationsManager.deleteUserCourseInformations(existingEntry);
-			CourseFactory.deleteCourse(newCourseResource);
 			return existingEntry;
 		}
 		
-		newCourseResource = olatResourceManager.findOrPersistResourceable(newCourseResource);
-		RepositoryEntry re = repositoryService.create(importExport.getInitialAuthor(), importExport.getResourceName(),
-				importExport.getDisplayName(), importExport.getDescription(), newCourseResource);
-		// ok, continue import
-		re.setOlatResource(newCourseResource);
+		
+		RepositoryHandler courseHandler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(CourseModule.getCourseTypeName());
+		RepositoryEntry re = courseHandler.importResource(null, importExport.getInitialAuthor(), importExport.getDisplayName(), importExport.getDescription(),
+				true, Locale.ENGLISH, exportedCourseZIPFile, exportedCourseZIPFile.getName());
+		
 		re.setSoftkey(softKey);
-		// set access configuration
 		re.setAccess(access);
-
-		// save the repository entry
 		repositoryService.update(re);
-
-		//import groups
-		course = openCourseEditSession(course.getResourceableId());
-		// create group management
-		CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
-		// import groups
-		cgm.importCourseBusinessGroups(courseExportData);
 		
-		// deploy any referenced repository entries of the editor structure. This will also
-		// include any references in the run structure, since any node in the runstructure is also
-		// present in the editor structure.
-		deployReferencedRepositoryEntries(courseExportData, course,
-				(CourseEditorTreeNode)course.getEditorTreeModel().getRootNode());
-		// register any references in the run structure. The referenced entries have been 
-		// previousely deplyed (as part of the editor structure deployment process - see above method call)
-		registerReferences(course, 
-				(CourseEditorTreeNode)course.getEditorTreeModel().getRootNode());
-		// import shared folder references
-		deployReferencedSharedFolders(courseExportData, course);
-		// import glossary references
-		deployReferencedGlossary(courseExportData, course);
-		closeCourseEditSession(course.getResourceableId(), true);
-		// cleanup export data
-		FileUtils.deleteDirsAndFiles(courseExportData, true, true);
-		log.info("Successfully deployed course " + re.getDisplayname() + " from ZIP: " + exportedCourseZIPFile.getAbsolutePath());
+		ICourse course = CourseFactory.loadCourse(re.getOlatResource());
+		CourseFactory.publishCourse(course, RepositoryEntry.ACC_USERS, false,  null, Locale.ENGLISH);
 		return re;
 	}
-	
-	
-	/**
-	 * Unattended deploy any referenced repository entries.
-	 * 
-	 * @param importDirectory
-	 * @param course
-	 * @param currentNode
-	 */
-	private static void deployReferencedRepositoryEntries(File importDirectory, ICourse course, CourseEditorTreeNode currentNode) {
-		for (int i = 0; i < currentNode.getChildCount(); i++) {
-			CourseEditorTreeNode childNode = (CourseEditorTreeNode)currentNode.getChildAt(i);
-			childNode.getCourseNode().importNode(importDirectory, course, null, null);
-			deployReferencedRepositoryEntries(importDirectory, course, childNode);
-		}
-	}
-	
-	/**
-	 * Register any referenced repository entries.
-	 * @param course
-	 * @param currentNode
-	 */
-	private static void registerReferences(ICourse course, CourseEditorTreeNode currentNode) {
-		for (int i = 0; i < currentNode.getChildCount(); i++) {
-			CourseEditorTreeNode childNode = (CourseEditorTreeNode)currentNode.getChildAt(i);
-			CourseNode childCourseNode = childNode.getCourseNode();
-			if (childCourseNode.needsReferenceToARepositoryEntry()) {
-				RepositoryEntry re = childCourseNode.getReferencedRepositoryEntry();
-				referenceManager.addReference(course, re.getOlatResource(), childNode.getIdent());
-			}
-			registerReferences(course, childNode);
-		}
-	}
-	
-	private static void deployReferencedSharedFolders(File importDirectory, ICourse course) {
-		CourseConfig cc = course.getCourseEnvironment().getCourseConfig();
-		if (!cc.hasCustomSharedFolder()) return;
-		RepositoryEntryImportExport importExport = SharedFolderManager.getInstance()
-			.getRepositoryImportExport(importDirectory);
-		Identity owner = BaseSecurityManager.getInstance().findIdentityByName("administrator");
-		ImportSharedfolderReferencesController.doImport(importExport, course, owner);
-	}
 
-	/**
-	 * Deploy referenced glossaries using the administrator account as owner
-	 * @param importDirectory
-	 * @param course
-	 */
-	private static void deployReferencedGlossary(File importDirectory, ICourse course) {
-		CourseConfig cc = course.getCourseEnvironment().getCourseConfig();
-		if (!cc.hasGlossary()) return;
-		RepositoryEntryImportExport importExport = glossaryManager.getRepositoryImportExport(importDirectory);
-		Identity owner = securityManager.findIdentityByName("administrator");
-		ImportGlossaryReferencesController.doImport(importExport, course, owner);
-	}
 	
 	/**
 	 * Publish the course with some standard options
diff --git a/src/main/java/org/olat/course/CourseModule.java b/src/main/java/org/olat/course/CourseModule.java
index 4a1fde26e97..e4a7482b1cf 100644
--- a/src/main/java/org/olat/course/CourseModule.java
+++ b/src/main/java/org/olat/course/CourseModule.java
@@ -87,7 +87,7 @@ public class CourseModule extends AbstractOLATModule {
 	 * [used by spring]
 	 */
 	private CourseModule(CoordinatorManager coordinatorManager, PropertyManager propertyManager, CourseFactory courseFactory, RepositoryService repositoryService, OLATResourceManager olatResourceManager) {
-		this.coordinatorManager = coordinatorManager;
+		CourseModule.coordinatorManager = coordinatorManager;
 		this.propertyManager = propertyManager;
 		this.courseFactory = courseFactory;
 		this.repositoryService = repositoryService;
@@ -192,7 +192,7 @@ public class CourseModule extends AbstractOLATModule {
 				logWarn("Cannot deploy course from file: " + file.getAbsolutePath(),null);
 				return null;
 			}
-			re = courseFactory.deployCourseFromZIP(file, access);
+			re = CourseFactory.deployCourseFromZIP(file, null, access);
 			if (re != null) markAsDeployed(export, re);
 			return re;
 		}
diff --git a/src/main/java/org/olat/course/_spring/courseContext.xml b/src/main/java/org/olat/course/_spring/courseContext.xml
index 89a122c83ca..787cb666cdf 100644
--- a/src/main/java/org/olat/course/_spring/courseContext.xml
+++ b/src/main/java/org/olat/course/_spring/courseContext.xml
@@ -73,15 +73,13 @@
 	
 </bean>
 				
-<bean id="courseFactory" class="org.olat.course.CourseFactory" depends-on="businessGroupService">
-	<constructor-arg index="0" ref="coordinatorManager" />
-	<constructor-arg index="1" ref="repositoryManager" />
-	<constructor-arg index="2" ref="repositoryService" />
-	<constructor-arg index="3" ref="resourceManager" />
-	<constructor-arg index="4" ref="baseSecurityManager" />
-	<constructor-arg index="5" ref="referenceManager" />
-	<constructor-arg index="6" ref="glossaryManager" />
-</bean>
+	<bean id="courseFactory" class="org.olat.course.CourseFactory"
+		depends-on="businessGroupService,resourceManager,baseSecurityManager,glossaryManager">
+		<constructor-arg index="0" ref="coordinatorManager" />
+		<constructor-arg index="1" ref="repositoryManager" />
+		<constructor-arg index="2" ref="repositoryService" />
+		<constructor-arg index="3" ref="referenceManager" />
+	</bean>
 
                 
 <bean  class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
diff --git a/src/main/java/org/olat/course/nodes/AbstractFeedCourseNode.java b/src/main/java/org/olat/course/nodes/AbstractFeedCourseNode.java
index e29a34ef6a9..585c650d2c3 100644
--- a/src/main/java/org/olat/course/nodes/AbstractFeedCourseNode.java
+++ b/src/main/java/org/olat/course/nodes/AbstractFeedCourseNode.java
@@ -244,30 +244,4 @@ public abstract class AbstractFeedCourseNode extends GenericCourseNode {
 			FeedNodeEditController.setReference(re, getModuleConfiguration());
 		}
 	}
-
-	/**
-	 * @see org.olat.course.nodes.GenericCourseNode#archiveNodeData(java.util.Locale,
-	 *      org.olat.course.ICourse, java.io.File, java.lang.String)
-	 *//*
-	@Override
-	public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
-		VFSContainer exportContainer = new LocalFolderImpl(exportDirectory);
-		VFSContainer exportDir = (VFSContainer) exportContainer.resolve(type);
-		if (exportDir == null) {
-			exportDir = exportContainer.createChildContainer(type);
-		}
-		String exportDirName = getShortTitle() + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
-		VFSContainer destination = exportDir.createChildContainer(exportDirName);
-		String repoRef = (String) getModuleConfiguration().get(CONFIG_KEY_REPOSITORY_SOFTKEY);
-		if (repoRef != null) {
-			OLATResourceable ores = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repoRef, true).getOlatResource();
-			
-			VFSContainer container = FeedManager.getInstance().getFeedContainer(ores);
-			if (container != null) {
-				VFSLeaf archive = FeedManager.getInstance().getFeedArchive(ores);
-				destination.copyFrom(archive);
-			}
-			// FIXME:FG:6.3 Archive user comments as soon as implemented.			
-		}
-	}*/
 }
diff --git a/src/main/java/org/olat/course/repository/ImportGlossaryReferencesController.java b/src/main/java/org/olat/course/repository/ImportGlossaryReferencesController.java
deleted file mode 100644
index 87585946d13..00000000000
--- a/src/main/java/org/olat/course/repository/ImportGlossaryReferencesController.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
-* 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>
-* Initial code contributed and copyrighted by<br>
-* frentix GmbH, http://www.frentix.com
-* <p>
-*/
-package org.olat.course.repository;
-
-import java.io.File;
-
-import org.olat.core.CoreSpringFactory;
-import org.olat.core.id.Identity;
-import org.olat.core.logging.OLog;
-import org.olat.core.logging.Tracing;
-import org.olat.core.util.ZipUtil;
-import org.olat.core.util.vfs.LocalFileImpl;
-import org.olat.core.util.vfs.VFSContainer;
-import org.olat.course.CourseFactory;
-import org.olat.course.ICourse;
-import org.olat.course.config.CourseConfig;
-import org.olat.fileresource.types.GlossaryResource;
-import org.olat.modules.glossary.GlossaryManager;
-import org.olat.repository.RepositoryEntry;
-import org.olat.repository.RepositoryEntryImportExport;
-import org.olat.repository.RepositoryService;
-import org.olat.resource.OLATResource;
-import org.olat.resource.OLATResourceManager;
-import org.olat.resource.references.ReferenceManager;
-
-/**
- * 
- * Description:<br>
- * 
- * <P>
- * Initial Date:  9 déc. 2011 <br>
- *
- * @author Florian Gnägi, frentix GmbH, http://www.frentix.com
- */
-public class ImportGlossaryReferencesController {
-	
-	private static final OLog log = Tracing.createLoggerFor(ImportGlossaryReferencesController.class);
-
-
-
-	/**
-	 * Import a referenced repository entry.
-	 * 
-	 * @param importExport
-	 * @param node
-	 * @param importMode Type of import.
-	 * @param keepSoftkey If true, no new softkey will be generated.
-	 * @param owner
-	 * @return
-	 */
-	public static RepositoryEntry doImport(RepositoryEntryImportExport importExport, ICourse course, Identity owner) {
-		GlossaryManager gm = GlossaryManager.getInstance();
-		GlossaryResource resource = gm.createGlossary();
-		if (resource == null) {
-			log.error("Error adding glossary directry during repository reference import: " + importExport.getDisplayName());
-			return null;
-		}
-
-		// unzip contents
-		VFSContainer glossaryContainer = gm.getGlossaryRootFolder(resource);
-		File fExportedFile = importExport.importGetExportedFile();
-		if (fExportedFile.exists()) {
-			ZipUtil.unzip(new LocalFileImpl(fExportedFile), glossaryContainer);
-		} else {
-			log.warn("The actual contents of the glossary were not found in the export.");
-		}
-
-		// create repository entry
-		RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
-		OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(resource);
-		
-		RepositoryEntry importedRepositoryEntry = repositoryService.create(owner,
-				null, importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), ores, 0);
-
-			// set the new glossary reference
-		CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
-		courseConfig.setGlossarySoftKey(importedRepositoryEntry.getSoftkey());
-		ReferenceManager.getInstance().addReference(course, importedRepositoryEntry.getOlatResource(), GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER);			
-		CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
-
-
-		return importedRepositoryEntry;
-	}
-}
diff --git a/src/main/java/org/olat/course/repository/ImportSharedfolderReferencesController.java b/src/main/java/org/olat/course/repository/ImportSharedfolderReferencesController.java
deleted file mode 100644
index 708be13459a..00000000000
--- a/src/main/java/org/olat/course/repository/ImportSharedfolderReferencesController.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
-* 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.course.repository;
-
-import java.io.File;
-
-import org.olat.core.CoreSpringFactory;
-import org.olat.core.id.Identity;
-import org.olat.core.logging.OLog;
-import org.olat.core.logging.Tracing;
-import org.olat.core.util.ZipUtil;
-import org.olat.core.util.vfs.LocalFileImpl;
-import org.olat.core.util.vfs.VFSContainer;
-import org.olat.course.CourseFactory;
-import org.olat.course.ICourse;
-import org.olat.course.config.CourseConfig;
-import org.olat.course.config.ui.CourseSharedFolderController;
-import org.olat.fileresource.types.SharedFolderFileResource;
-import org.olat.modules.sharedfolder.SharedFolderManager;
-import org.olat.repository.RepositoryEntry;
-import org.olat.repository.RepositoryEntryImportExport;
-import org.olat.repository.RepositoryService;
-import org.olat.resource.OLATResource;
-import org.olat.resource.OLATResourceManager;
-
-/**
- * Initial Date:  19.05.2005
- *
- * @author Mike Stock
- */
-public class ImportSharedfolderReferencesController  {
-	
-	private static final OLog log = Tracing.createLoggerFor(ImportSharedfolderReferencesController.class);
-	
-
-	/**
-	 * Import a referenced repository entry.
-	 * 
-	 * @param importExport
-	 * @param node
-	 * @param importMode Type of import.
-	 * @param keepSoftkey If true, no new softkey will be generated.
-	 * @param owner
-	 * @return
-	 */
-	public static RepositoryEntry doImport(RepositoryEntryImportExport importExport, ICourse course, Identity owner) {
-		SharedFolderManager sfm = SharedFolderManager.getInstance();
-		SharedFolderFileResource resource = sfm.createSharedFolder();
-		if (resource == null) {
-			log.error("Error adding file resource during repository reference import: " + importExport.getDisplayName());
-			return null;
-		}
-
-		// unzip contents
-		VFSContainer sfContainer = sfm.getSharedFolder(resource);
-		File fExportedFile = importExport.importGetExportedFile();
-		if (fExportedFile.exists()) {
-			ZipUtil.unzip(new LocalFileImpl(fExportedFile), sfContainer);
-		} else {
-			log.warn("The actual contents of the shared folder were not found in the export.");
-		}
-		// create repository entry
-		RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
-		OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(resource);
-		RepositoryEntry importedRepositoryEntry = repositoryService.create(owner, null,
-				importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), ores, 0);
-
-		// set the new shared folder reference
-		CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
-		courseConfig.setSharedFolderSoftkey(importedRepositoryEntry.getSoftkey());
-		CourseSharedFolderController.updateRefTo(importedRepositoryEntry, course);			
-		CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
-
-		
-		return importedRepositoryEntry;
-	}
-}
\ No newline at end of file
diff --git a/src/main/java/org/olat/repository/RepositoryEntryImportExport.java b/src/main/java/org/olat/repository/RepositoryEntryImportExport.java
index cb0bc19f4ae..46c152895f7 100644
--- a/src/main/java/org/olat/repository/RepositoryEntryImportExport.java
+++ b/src/main/java/org/olat/repository/RepositoryEntryImportExport.java
@@ -29,8 +29,10 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
 
 import org.apache.commons.io.IOUtils;
 import org.olat.core.gui.media.MediaResource;
@@ -163,10 +165,25 @@ public class RepositoryEntryImportExport {
 	 */
 	private void loadConfiguration() {
 		try {
-			File inputFile = new File(baseDirectory, PROPERTIES_FILE);
-			if(inputFile.exists()) {
-				XStream xstream = getXStream();
-				repositoryProperties = (RepositoryEntryImport)xstream.fromXML(inputFile);
+			if(baseDirectory.exists()) {
+				if(baseDirectory.getName().endsWith(".zip")) {
+					Path fPath = FileSystems.newFileSystem(baseDirectory.toPath(), null).getPath("/");
+					Path manifestPath = fPath.resolve("export").resolve(PROPERTIES_FILE);
+					try(InputStream inputFile = Files.newInputStream(manifestPath, StandardOpenOption.READ)) {
+						XStream xstream = getXStream();
+						repositoryProperties = (RepositoryEntryImport)xstream.fromXML(inputFile);
+					} catch(Exception e) {
+						log.error("Cannot read repo.xml im zip", e);
+					}
+				} else {
+					File inputFile = new File(baseDirectory, PROPERTIES_FILE);
+					if(inputFile.exists()) {
+						XStream xstream = getXStream();
+						repositoryProperties = (RepositoryEntryImport)xstream.fromXML(inputFile);
+					} else {
+						repositoryProperties = new RepositoryEntryImport();
+					}
+				}
 			} else {
 				repositoryProperties = new RepositoryEntryImport();
 			}
diff --git a/src/main/java/org/olat/repository/RepositoryManager.java b/src/main/java/org/olat/repository/RepositoryManager.java
index 78ea2c419b2..1d9d8e7af2f 100644
--- a/src/main/java/org/olat/repository/RepositoryManager.java
+++ b/src/main/java/org/olat/repository/RepositoryManager.java
@@ -1059,6 +1059,9 @@ public class RepositoryManager extends BasicManager {
 	 * @return true if the identity is member of the security group of the repository entry
 	 */
 	public boolean isOwnerOfRepositoryEntry(Identity identity, RepositoryEntry entry) {
+		if(entry == null || identity == null) {
+			return false;
+		}
 		return repositoryEntryRelationDao.hasRole(identity, entry, GroupRoles.owner.name());
 	}
 	
diff --git a/src/test/java/org/olat/restapi/MyForumsTest.java b/src/test/java/org/olat/restapi/MyForumsTest.java
index 58b8839ca1f..7ae72d098b9 100644
--- a/src/test/java/org/olat/restapi/MyForumsTest.java
+++ b/src/test/java/org/olat/restapi/MyForumsTest.java
@@ -89,7 +89,7 @@ public class MyForumsTest extends OlatJerseyTestCase {
 		URL courseWithForumsUrl = MyForumsTest.class.getResource("myCourseWS.zip");
 		Assert.assertNotNull(courseWithForumsUrl);
 		File courseWithForums = new File(courseWithForumsUrl.toURI());
-		myCourseRe = CourseFactory.deployCourseFromZIP(courseWithForums, 4);	
+		myCourseRe = CourseFactory.deployCourseFromZIP(courseWithForums, null, 4);	
 		Assert.assertNotNull(myCourseRe);
 		myCourse = CourseFactory.loadCourse(myCourseRe.getOlatResource().getResourceableId());
 
-- 
GitLab