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

OO-5230: indexer for document course element

parent 43a515f0
No related branches found
No related tags found
No related merge requests found
...@@ -172,6 +172,7 @@ ...@@ -172,6 +172,7 @@
<property name="indexerList"> <property name="indexerList">
<list> <list>
<ref bean="spCourseNodeIndexer" /> <ref bean="spCourseNodeIndexer" />
<ref bean="documentCourseNodeIndexer" />
<ref bean="foCourseNodeIndexer" /> <ref bean="foCourseNodeIndexer" />
<ref bean="stCourseNodeIndexer" /> <ref bean="stCourseNodeIndexer" />
<ref bean="bcCourseNodeIndexer" /> <ref bean="bcCourseNodeIndexer" />
...@@ -228,6 +229,7 @@ ...@@ -228,6 +229,7 @@
<bean id="pfCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.PFCourseNodeIndexer" /> <bean id="pfCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.PFCourseNodeIndexer" />
<bean id="openMeetingsCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.OpenMeetingsCourseNodeIndexer" /> <bean id="openMeetingsCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.OpenMeetingsCourseNodeIndexer" />
<bean id="spCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.SPCourseNodeIndexer" /> <bean id="spCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.SPCourseNodeIndexer" />
<bean id="documentCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.DocumentCourseNodeIndexer" />
<bean id="foCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.FOCourseNodeIndexer" /> <bean id="foCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.FOCourseNodeIndexer" />
<bean id="stCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.STCourseNodeIndexer" /> <bean id="stCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.STCourseNodeIndexer" />
<bean id="bcCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.BCCourseNodeIndexer" /> <bean id="bcCourseNodeIndexer" class="org.olat.search.service.indexer.repository.course.BCCourseNodeIndexer" />
......
...@@ -84,11 +84,11 @@ public class CourseIndexer extends AbstractHierarchicalIndexer { ...@@ -84,11 +84,11 @@ public class CourseIndexer extends AbstractHierarchicalIndexer {
@Override @Override
public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) { public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) {
RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject; RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
if (log.isDebugEnabled()) log.debug("Analyse Course... repositoryEntry=" + repositoryEntry); if (log.isDebugEnabled()) log.debug("Analyse Course... repositoryEntry={}", repositoryEntry);
try { try {
RepositoryEntryStatusEnum status = repositoryEntry.getEntryStatus(); RepositoryEntryStatusEnum status = repositoryEntry.getEntryStatus();
if(status.decommissioned()) { if(status.decommissioned()) {
if(log.isDebugEnabled()) log.debug("Course not indexed because it's " + status + ": repositoryEntry=" + repositoryEntry); if(log.isDebugEnabled()) log.debug("Course not indexed because it's {}: repositoryEntry={}", status, repositoryEntry);
return; return;
} }
...@@ -98,9 +98,9 @@ public class CourseIndexer extends AbstractHierarchicalIndexer { ...@@ -98,9 +98,9 @@ public class CourseIndexer extends AbstractHierarchicalIndexer {
parentResourceContext.setParentContextName(course.getCourseTitle()); parentResourceContext.setParentContextName(course.getCourseTitle());
doIndexCourse( parentResourceContext, course, course.getRunStructure().getRootNode(), indexWriter); doIndexCourse( parentResourceContext, course, course.getRunStructure().getRootNode(), indexWriter);
} catch(CorruptedCourseException ex) { } catch(CorruptedCourseException ex) {
log.warn("Can not index repositoryEntry (" + repositoryEntry.getKey() + ")", ex); log.warn("Can not index repositoryEntry ({})", repositoryEntry.getKey(), ex);
} catch (Exception ex) { } catch (Exception ex) {
log.warn("Can not index repositoryEntry=" + repositoryEntry,ex); log.warn("Can not index repositoryEntry={}", repositoryEntry,ex);
} }
} }
...@@ -117,19 +117,19 @@ public class CourseIndexer extends AbstractHierarchicalIndexer { ...@@ -117,19 +117,19 @@ public class CourseIndexer extends AbstractHierarchicalIndexer {
throws IOException,InterruptedException { throws IOException,InterruptedException {
//try to index the course node //try to index the course node
if(node instanceof CourseNode) { if(node instanceof CourseNode) {
if (log.isDebugEnabled()) log.debug("Analyse CourseNode child ... childCourseNode=" + node); if (log.isDebugEnabled()) log.debug("Analyse CourseNode child ... childCourseNode={}", node);
// go further with resource // go further with resource
CourseNode childCourseNode = (CourseNode)node; CourseNode childCourseNode = (CourseNode)node;
CourseNodeIndexer courseNodeIndexer = getCourseNodeIndexer(childCourseNode); CourseNodeIndexer courseNodeIndexer = getCourseNodeIndexer(childCourseNode);
if (courseNodeIndexer != null) { if (courseNodeIndexer != null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("courseNodeIndexer=" + courseNodeIndexer); log.debug("courseNodeIndexer={}", courseNodeIndexer);
} }
try { try {
courseNodeIndexer.doIndex(repositoryResourceContext, course, childCourseNode, indexWriter); courseNodeIndexer.doIndex(repositoryResourceContext, course, childCourseNode, indexWriter);
} catch (Exception e) { } catch (Exception e) {
log.warn("Can not index course node=" + childCourseNode.getIdent(), e); log.warn("Can not index course node={}", childCourseNode.getIdent(), e);
} }
} }
} }
...@@ -164,28 +164,30 @@ public class CourseIndexer extends AbstractHierarchicalIndexer { ...@@ -164,28 +164,30 @@ public class CourseIndexer extends AbstractHierarchicalIndexer {
// not a course node of course we have access to the course metadata // not a course node of course we have access to the course metadata
return true; return true;
} }
if (log.isDebugEnabled()) log.debug("Start identity=" + identity + " roles=" + roles);
boolean debug = log.isDebugEnabled();
if (debug) log.debug("Start identity={} roles={}", identity, roles);
Long repositoryKey = contextEntry.getOLATResourceable().getResourceableId(); Long repositoryKey = contextEntry.getOLATResourceable().getResourceableId();
RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryKey); RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryKey);
if (log.isDebugEnabled()) log.debug("repositoryEntry=" + repositoryEntry ); if (debug) log.debug("repositoryEntry={}", repositoryEntry);
if(roles.isGuestOnly() && repositoryEntry.isGuests()) { if(roles.isGuestOnly() && repositoryEntry.isGuests()) {
return false; return false;
} }
Long nodeId = bcContextEntry.getOLATResourceable().getResourceableId(); Long nodeId = bcContextEntry.getOLATResourceable().getResourceableId();
if (log.isDebugEnabled()) log.debug("nodeId=" + nodeId ); if (debug) log.debug("nodeId={}", nodeId);
ICourse course = CourseFactory.loadCourse(repositoryEntry); ICourse course = CourseFactory.loadCourse(repositoryEntry);
IdentityEnvironment ienv = new IdentityEnvironment(); IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(identity); ienv.setIdentity(identity);
ienv.setRoles(roles); ienv.setRoles(roles);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment()); UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
if (log.isDebugEnabled()) log.debug("userCourseEnv=" + userCourseEnv + "ienv=" + ienv ); if (debug) log.debug("userCourseEnv={} ienv={}", userCourseEnv, ienv );
String nodeIdS = nodeId.toString(); String nodeIdS = nodeId.toString();
CourseNode courseNode = course.getRunStructure().getNode(nodeIdS); CourseNode courseNode = course.getRunStructure().getNode(nodeIdS);
if (log.isDebugEnabled()) log.debug("courseNode=" + courseNode ); if (debug) log.debug("courseNode={}", courseNode);
TreeNode treeNode = CoreSpringFactory.getImpl(NodeAccessService.class) TreeNode treeNode = CoreSpringFactory.getImpl(NodeAccessService.class)
.getCourseTreeModelBuilder(userCourseEnv) .getCourseTreeModelBuilder(userCourseEnv)
......
...@@ -50,9 +50,9 @@ public class CPCourseNodeIndexer extends FolderIndexer implements CourseNodeInde ...@@ -50,9 +50,9 @@ public class CPCourseNodeIndexer extends FolderIndexer implements CourseNodeInde
// Must correspond with LocalString_xx.properties // Must correspond with LocalString_xx.properties
// Do not use '_' because we want to seach for certain documenttype and lucene haev problems with '_' // Do not use '_' because we want to seach for certain documenttype and lucene haev problems with '_'
public final static String TYPE = "type.course.node.cp"; public static final String TYPE = "type.course.node.cp";
private final static String SUPPORTED_TYPE_NAME = "org.olat.course.nodes.CPCourseNode"; private static final String SUPPORTED_TYPE_NAME = "org.olat.course.nodes.CPCourseNode";
@Override @Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter)
......
/**
* <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.search.service.indexer.repository.course;
import java.io.IOException;
import org.apache.lucene.document.Document;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.course.ICourse;
import org.olat.course.folder.CourseContainerOptions;
import org.olat.course.nodes.CourseNode;
import org.olat.course.nodes.DocumentCourseNode;
import org.olat.search.service.SearchResourceContext;
import org.olat.search.service.document.CourseNodeDocument;
import org.olat.search.service.indexer.LeafIndexer;
import org.olat.search.service.indexer.OlatFullIndexer;
/**
*
* Initial date: 15 janv. 2021<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class DocumentCourseNodeIndexer extends LeafIndexer implements CourseNodeIndexer {
private static final String SUPPORTED_TYPE_NAME = "org.olat.course.nodes.DocumentCourseNode";
public static final String TYPE = "type.course.node.document";
@Override
public String getSupportedTypeName() {
return SUPPORTED_TYPE_NAME;
}
@Override
public void doIndex(SearchResourceContext courseResourceContext, ICourse course, CourseNode node,
OlatFullIndexer indexWriter) throws IOException, InterruptedException {
DocumentCourseNode docNode = (DocumentCourseNode)node;
SearchResourceContext courseNodeResourceContext = createSearchResourceContext(courseResourceContext, docNode, TYPE);
Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, docNode);
indexWriter.addDocument(nodeDocument);
VFSContainer courseFolderCont = course.getCourseEnvironment()
.getCourseFolderContainer(CourseContainerOptions.withoutElements());
VFSLeaf vfsLeaf = docNode.getDocumentSource(courseFolderCont).getVfsLeaf();
if(vfsLeaf != null) {
SearchResourceContext fileContext = new SearchResourceContext(courseNodeResourceContext);
doIndexVFSLeafByMySelf(fileContext, vfsLeaf, indexWriter, SUPPORTED_TYPE_NAME);
}
}
}
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