YML config should override lesson class
This commit is contained in:
parent
0a26e05ca5
commit
c350e86772
@ -80,7 +80,7 @@ public class StartLesson {
|
|||||||
public ModelAndView lessonPage(HttpServletRequest request) {
|
public ModelAndView lessonPage(HttpServletRequest request) {
|
||||||
// I will set here the thymeleaf fragment location based on the resource requested.
|
// I will set here the thymeleaf fragment location based on the resource requested.
|
||||||
ModelAndView model = new ModelAndView();
|
ModelAndView model = new ModelAndView();
|
||||||
SecurityContext context = SecurityContextHolder.getContext();
|
SecurityContext context = SecurityContextHolder.getContext(); //TODO this should work with the security roles of Spring
|
||||||
GrantedAuthority authority = context.getAuthentication().getAuthorities().iterator().next();
|
GrantedAuthority authority = context.getAuthentication().getAuthorities().iterator().next();
|
||||||
String path = request.getServletPath(); // we now got /a/b/c/AccessControlMatrix.lesson
|
String path = request.getServletPath(); // we now got /a/b/c/AccessControlMatrix.lesson
|
||||||
String lessonName = path.substring(path.lastIndexOf('/') + 1, path.indexOf(".lesson"));
|
String lessonName = path.substring(path.lastIndexOf('/') + 1, path.indexOf(".lesson"));
|
||||||
@ -88,8 +88,7 @@ public class StartLesson {
|
|||||||
List<AbstractLesson> lessons = ws.getCourse()
|
List<AbstractLesson> lessons = ws.getCourse()
|
||||||
.getLessons(ws, AbstractLesson.USER_ROLE);//TODO this should work with the security roles of Spring
|
.getLessons(ws, AbstractLesson.USER_ROLE);//TODO this should work with the security roles of Spring
|
||||||
Optional<AbstractLesson> lesson = lessons.stream()
|
Optional<AbstractLesson> lesson = lessons.stream()
|
||||||
.filter(l -> l instanceof YmlBasedLesson)
|
.filter(l -> l.getHtml().equals(lessonName))
|
||||||
.filter(l -> ((YmlBasedLesson) l).getHtml().equals(lessonName))
|
|
||||||
.findFirst();
|
.findFirst();
|
||||||
model.setViewName("lesson_content");
|
model.setViewName("lesson_content");
|
||||||
model.addObject("lesson", lesson.get());
|
model.addObject("lesson", lesson.get());
|
||||||
|
@ -68,10 +68,8 @@ public class Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//New code all lessons should work as below
|
//New code all lessons should work as below
|
||||||
if (this.lesson == null) {
|
|
||||||
readYmlLessonConfiguration();
|
readYmlLessonConfiguration();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void readYmlLessonConfiguration() {
|
private void readYmlLessonConfiguration() {
|
||||||
java.util.Optional<File> ymlFile = this.pluginFiles.stream().filter(f -> f.getName().endsWith(".yml")).findFirst();
|
java.util.Optional<File> ymlFile = this.pluginFiles.stream().filter(f -> f.getName().endsWith(".yml")).findFirst();
|
||||||
@ -87,6 +85,7 @@ public class Plugin {
|
|||||||
final String title = (String) lessonYml.get("title");
|
final String title = (String) lessonYml.get("title");
|
||||||
final String html = (String) lessonYml.get("html");
|
final String html = (String) lessonYml.get("html");
|
||||||
this.ymlBasedLesson = new YmlBasedLesson(category, hints, title, html);
|
this.ymlBasedLesson = new YmlBasedLesson(category, hints, title, html);
|
||||||
|
this.lesson = null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new PluginLoadingFailure("Unable to read yml file", e);
|
throw new PluginLoadingFailure("Unable to read yml file", e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user