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

OO-1712: get the share folder by olat resource which can be cached by hibernate

parent 4bb3e90d
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@
*/
package org.olat.course;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl;
import org.olat.core.commons.services.webdav.servlets.RequestUtil;
import org.olat.core.gui.components.tree.GenericTreeModel;
......@@ -45,7 +46,9 @@ import org.olat.course.run.userview.VisibleTreeFilter;
import org.olat.modules.sharedfolder.SharedFolderManager;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryManager;
import org.olat.repository.RepositoryService;
import org.olat.repository.model.RepositoryEntrySecurity;
import org.olat.resource.OLATResource;
/**
*
......@@ -88,10 +91,10 @@ public class MergedCourseContainer extends MergeSource {
OlatRootFolderImpl sharedFolder = null;
String sfSoftkey = persistingCourse.getCourseConfig().getSharedFolderSoftkey();
if (StringHelper.containsNonWhitespace(sfSoftkey) && !CourseConfig.VALUE_EMPTY_SHAREDFOLDER_SOFTKEY.equals(sfSoftkey)) {
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry re = rm.lookupRepositoryEntryBySoftkey(sfSoftkey, false);
if (re != null) {
sharedFolder = SharedFolderManager.getInstance().getSharedFolder(re.getOlatResource());
OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class)
.loadRepositoryEntryResourceBySoftKey(sfSoftkey);
if (sharedResource != null) {
sharedFolder = SharedFolderManager.getInstance().getSharedFolder(sharedResource);
if (sharedFolder != null) {
sharedFolder.setLocalSecurityCallback(new ReadOnlyCallback());
//add local course folder's children as read/write source and any sharedfolder as subfolder
......@@ -150,10 +153,10 @@ public class MergedCourseContainer extends MergeSource {
OlatRootFolderImpl sharedFolder = null;
String sfSoftkey = course.getCourseConfig().getSharedFolderSoftkey();
if (StringHelper.containsNonWhitespace(sfSoftkey) && !CourseConfig.VALUE_EMPTY_SHAREDFOLDER_SOFTKEY.equals(sfSoftkey)) {
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry re = rm.lookupRepositoryEntryBySoftkey(sfSoftkey, false);
if (re != null) {
sharedFolder = SharedFolderManager.getInstance().getSharedFolder(re.getOlatResource());
OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class)
.loadRepositoryEntryResourceBySoftKey(sfSoftkey);
if (sharedResource != null) {
sharedFolder = SharedFolderManager.getInstance().getSharedFolder(sharedResource);
VFSContainer courseBase = sharedFolder;
sharedFolder.setLocalSecurityCallback(new ReadOnlyCallback());
subpath = subpath.replaceFirst("/_sharedfolder", "");
......
......@@ -61,6 +61,18 @@ public interface RepositoryService {
public List<RepositoryEntry> loadByResourceKeys(Collection<Long> keys);
/**
* @param repositoryEntryKey The key of the repository entry
* @return The olat resource of the repository entry
*/
public OLATResource loadRepositoryEntryResource(Long repositoryEntryKey);
/**
* @param softkey The soft key of the repository entry
* @return The olat resource of the repository entry
*/
public OLATResource loadRepositoryEntryResourceBySoftKey(String softkey);
public VFSLeaf getIntroductionImage(RepositoryEntry re);
public VFSLeaf getIntroductionMovie(RepositoryEntry re);
......
......@@ -28,6 +28,7 @@ import javax.persistence.TypedQuery;
import org.olat.core.commons.persistence.DB;
import org.olat.core.util.StringHelper;
import org.olat.repository.RepositoryEntry;
import org.olat.resource.OLATResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -123,4 +124,35 @@ public class RepositoryEntryDAO {
.setMaxResults(maxResults)
.getResultList();
}
public OLATResource loadRepositoryEntryResource(Long key) {
if (key == null) return null;
String query = "select v.olatResource from repositoryentry as v where v.key=:repoKey";
List<OLATResource> entries = dbInstance.getCurrentEntityManager()
.createQuery(query, OLATResource.class)
.setParameter("repoKey", key)
.setHint("org.hibernate.cacheable", Boolean.TRUE)
.getResultList();
if(entries.isEmpty()) {
return null;
}
return entries.get(0);
}
public OLATResource loadRepositoryEntryResourceBySoftKey(String softkey) {
if(softkey == null || "sf.notconfigured".equals(softkey)) {
return null;
}
String query = "select v.olatResource from repositoryentry as v where v.softkey=:softkey";
List<OLATResource> entries = dbInstance.getCurrentEntityManager()
.createQuery(query, OLATResource.class)
.setParameter("softkey", softkey)
.setHint("org.hibernate.cacheable", Boolean.TRUE)
.getResultList();
if(entries.isEmpty()) {
return null;
}
return entries.get(0);
}
}
\ No newline at end of file
......@@ -264,6 +264,16 @@ public class RepositoryServiceImpl implements RepositoryService {
return repositoryEntryDAO.loadByResourceKeys(resourceKeys);
}
@Override
public OLATResource loadRepositoryEntryResource(Long repositoryEntryKey) {
return repositoryEntryDAO.loadRepositoryEntryResource(repositoryEntryKey);
}
@Override
public OLATResource loadRepositoryEntryResourceBySoftKey(String softkey) {
return repositoryEntryDAO.loadRepositoryEntryResourceBySoftKey(softkey);
}
@Override
public VFSLeaf getIntroductionImage(RepositoryEntry re) {
VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
......
......@@ -30,6 +30,7 @@ import org.olat.core.commons.persistence.DB;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryManager;
import org.olat.repository.RepositoryService;
import org.olat.resource.OLATResource;
import org.olat.test.OlatTestCase;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -154,4 +155,30 @@ public class RepositoryEntryDAOTest extends OlatTestCase {
Assert.assertFalse(allRes.isEmpty());
Assert.assertTrue(allRes.size() < 26);
}
@Test
public void loadRepositoryEntryResource() {
RepositoryEntry re = repositoryService.create("Rei Ayanami", "-", "Repository entry DAO Test 5", "", null);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(re);
Assert.assertNotNull(re.getSoftkey());
Assert.assertNotNull(re.getOlatResource());
OLATResource loadedResource = repositoryEntryDao.loadRepositoryEntryResource(re.getKey());
Assert.assertNotNull(loadedResource);
Assert.assertEquals(re.getOlatResource(), loadedResource);
}
@Test
public void loadRepositoryEntryResourceBySoftKey() {
RepositoryEntry re = repositoryService.create("Rei Ayanami", "-", "Repository entry DAO Test 5", "", null);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(re);
Assert.assertNotNull(re.getSoftkey());
Assert.assertNotNull(re.getOlatResource());
OLATResource loadedResource = repositoryEntryDao.loadRepositoryEntryResourceBySoftKey(re.getSoftkey());
Assert.assertNotNull(loadedResource);
Assert.assertEquals(re.getOlatResource(), loadedResource);
}
}
\ No newline at end of file
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