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

OO-324: the list of course nodes is made on the fly, and check every time if a...

OO-324: the list of course nodes is made on the fly, and check every time if a course building block is enabled or not, remove the flag for the vitero course building block
parent da22337a
No related branches found
No related tags found
No related merge requests found
......@@ -27,10 +27,11 @@ package org.olat.course.nodes;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.olat.OlatBeanTypes;
import org.olat.core.CoreSpringFactory;
......@@ -43,8 +44,6 @@ import org.olat.core.id.OLATResourceable;
import org.olat.core.id.context.BusinessControlFactory;
import org.olat.core.id.context.ContextEntry;
import org.olat.core.logging.AssertException;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.controllers.RepositoryDetailsController;
import org.olat.repository.handlers.RepositoryHandler;
......@@ -57,12 +56,8 @@ import org.olat.repository.handlers.RepositoryHandlerFactory;
* @author guido
*/
public class CourseNodeFactory {
private static final OLog log = Tracing.createLoggerFor(CourseNodeFactory.class);
private static CourseNodeFactory INSTANCE;
private static List<String> courseNodeConfigurationsAliases;
private static Map<String, CourseNodeConfiguration> courseNodeConfigurations;
private Object lockObject = new Object();
private Map<String, CourseNodeConfiguration> allCourseNodeConfigurations;
/**
......@@ -80,70 +75,52 @@ public class CourseNodeFactory {
return INSTANCE;
}
/**
* @return the list of enabled aliases
*/
public List<String> getRegisteredCourseNodeAliases() {
if (courseNodeConfigurationsAliases == null) {
initCourseNodeConfigurationList();
List<CourseNodeConfiguration> configList = new ArrayList<CourseNodeConfiguration>(getAllCourseNodeConfigurations().values());
Collections.sort(configList, new OrderComparator());
List<String> alias = new ArrayList<String>(configList.size());
for(CourseNodeConfiguration config:configList) {
if(config.isEnabled()) {
alias.add(config.getAlias());
}
}
return courseNodeConfigurationsAliases;
return alias;
}
private void initCourseNodeConfigurationList() {
courseNodeConfigurationsAliases = new ArrayList<String>();
courseNodeConfigurations = new HashMap<String, CourseNodeConfiguration>();
allCourseNodeConfigurations = new HashMap<String, CourseNodeConfiguration>();
Map<Integer,CourseNodeConfiguration> sortedMap = new TreeMap<Integer,CourseNodeConfiguration>();
Map<String, Object> courseNodeConfigurationMap = CoreSpringFactory.getBeansOfType(OlatBeanTypes.courseNodeConfiguration);
Collection<Object> courseNodeConfigurationValues = courseNodeConfigurationMap.values();
for (Object object : courseNodeConfigurationValues) {
CourseNodeConfiguration courseNodeConfiguration = (CourseNodeConfiguration) object;
int key = courseNodeConfiguration.getOrder();
if (courseNodeConfiguration.isEnabled()) {
while (sortedMap.containsKey(key) ) {
// a key with this value already exist => add 1000 because offset must be outside of other values.
key += 1000;
}
if ( key != courseNodeConfiguration.getOrder() ) {
log.warn("CourseNodeConfiguration Problem: Dublicate order-value for node=" + courseNodeConfiguration.getAlias() + ", append course node at the end");
}
sortedMap.put(key, courseNodeConfiguration);
} else {
log.debug("Disabled courseNodeConfiguration=" + courseNodeConfiguration);
private synchronized Map<String,CourseNodeConfiguration> getAllCourseNodeConfigurations() {
if(allCourseNodeConfigurations == null) {
allCourseNodeConfigurations = new HashMap<String, CourseNodeConfiguration>();
Map<String, Object> courseNodeConfigurationMap = CoreSpringFactory.getBeansOfType(OlatBeanTypes.courseNodeConfiguration);
Collection<Object> courseNodeConfigurationValues = courseNodeConfigurationMap.values();
for (Object object : courseNodeConfigurationValues) {
CourseNodeConfiguration courseNodeConfiguration = (CourseNodeConfiguration)object;
allCourseNodeConfigurations.put(courseNodeConfiguration.getAlias(), courseNodeConfiguration);
}
allCourseNodeConfigurations.put(courseNodeConfiguration.getAlias(), courseNodeConfiguration);
}
for (Object key : sortedMap.keySet()) {
CourseNodeConfiguration courseNodeConfiguration = sortedMap.get(key);
courseNodeConfigurationsAliases.add(courseNodeConfiguration.getAlias());
courseNodeConfigurations.put(courseNodeConfiguration.getAlias(), courseNodeConfiguration);
}
return allCourseNodeConfigurations;
}
/**
* @param type The node type
* @return a new instance of the desired type of node
* @param alias The node type or alias
* @return The instance of the desired type of node if enabled
*/
public CourseNodeConfiguration getCourseNodeConfiguration(String alias) {
if (courseNodeConfigurations == null) {
synchronized(lockObject) {
if (courseNodeConfigurations == null) { // check again in synchronized-block, only one may create list
initCourseNodeConfigurationList();
}
}
CourseNodeConfiguration config = getAllCourseNodeConfigurations().get(alias);
if(config.isEnabled()) {
return config;
}
return courseNodeConfigurations.get(alias);
return null;
}
/**
* @param alias The node type or alias
* @return The instance of the desired type of node if enabled or not
*/
public CourseNodeConfiguration getCourseNodeConfigurationEvenForDisabledBB(String alias) {
if (allCourseNodeConfigurations == null) {
synchronized(lockObject) {
if (allCourseNodeConfigurations == null) { // check again in synchronized-block, only one may create list
initCourseNodeConfigurationList();
}
}
}
return allCourseNodeConfigurations.get(alias);
return getAllCourseNodeConfigurations().get(alias);
}
/**
......@@ -187,5 +164,24 @@ public class CourseNodeFactory {
List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromResourceType(RepositoryDetailsController.ACTIVATE_EDITOR);
dts.activate(ureq, dt, entries);
}
}
private static class OrderComparator implements Comparator<CourseNodeConfiguration> {
@Override
public int compare(CourseNodeConfiguration c1, CourseNodeConfiguration c2) {
if(c1 == null) return -1;
if(c2 == null) return 1;
int k1 = c1.getOrder();
int k2 = c2.getOrder();
int diff = (k1 < k2 ? -1 : (k1==k2 ? 0 : 1));
if(diff == 0) {
String a1 = c1.getAlias();
String a2 = c2.getAlias();
if(a1 == null) return -1;
if(a2 == null) return 1;
diff = a1.compareTo(a1);
}
return diff;
}
}
}
\ No newline at end of file
......@@ -65,9 +65,8 @@ public class ViteroCourseNodeConfiguration extends AbstractCourseNodeConfigurati
@Override
public boolean isEnabled() {
ViteroModule viteroModule = (ViteroModule) CoreSpringFactory.getBean("viteroModule");
if (!viteroModule.isEnabled()) return false;
else return super.isEnabled();
ViteroModule viteroModule = CoreSpringFactory.getImpl(ViteroModule.class);
return viteroModule.isEnabled();
}
public String getName() {
......
......@@ -7,7 +7,6 @@
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="vitero" class="org.olat.course.nodes.vitero.ViteroCourseNodeConfiguration" scope="prototype">
<property name="enabled" value="${course.node.vitero.enabled}" />
<property name="order" value="301" />
<property name="alternativeCourseNodes">
<list>
......
......@@ -797,7 +797,6 @@ course.node.portfolio.enabled=true
course.node.infomessage.enabled=true
course.node.members.enabled=true
course.node.vc.enabled=false
course.node.vitero.enabled=false
########################################
# Options for e-portfolio
......
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