diff --git a/src/main/java/org/olat/core/commons/services/commentAndRating/manager/UserCommentsDAO.java b/src/main/java/org/olat/core/commons/services/commentAndRating/manager/UserCommentsDAO.java index 1cc11bab16bc910ea22de2c238582534b092102a..47410e91a24d37cc606f4ca535e53b11819ac0d4 100644 --- a/src/main/java/org/olat/core/commons/services/commentAndRating/manager/UserCommentsDAO.java +++ b/src/main/java/org/olat/core/commons/services/commentAndRating/manager/UserCommentsDAO.java @@ -30,6 +30,7 @@ import javax.persistence.TypedQuery; import org.olat.basesecurity.IdentityRef; import org.olat.core.commons.persistence.DB; +import org.olat.core.commons.persistence.QueryBuilder; import org.olat.core.commons.services.commentAndRating.CommentAndRatingLoggingAction; import org.olat.core.commons.services.commentAndRating.UserCommentsDelegate; import org.olat.core.commons.services.commentAndRating.model.UserComment; @@ -100,19 +101,25 @@ public class UserCommentsDAO { } public List<UserComment> getComments(OLATResourceable ores, String resSubPath) { - TypedQuery<UserComment> query; + QueryBuilder sb = new QueryBuilder(512); + sb.append("select comment from usercomment as comment") + .append(" left join fetch comment.creator as creatorIdent") + .append(" left join fetch creatorIdent.user as creatorUser") + .append(" where resName=:resname and resId=:resId"); if (resSubPath == null) { - // special query when sub path is null - query = dbInstance.getCurrentEntityManager() - .createQuery("select comment from usercomment as comment where resName=:resname AND resId=:resId AND resSubPath is NULL", UserComment.class); + sb.append(" and resSubPath is null"); } else { - query = dbInstance.getCurrentEntityManager() - .createQuery("select comment from usercomment as comment where resName=:resname AND resId=:resId AND resSubPath=:resSubPath", UserComment.class) - .setParameter("resSubPath", resSubPath); + sb.append(" and resSubPath=:resSubPath"); } - return query.setParameter("resname", ores.getResourceableTypeName()) - .setParameter("resId", ores.getResourceableId()) - .getResultList(); + + TypedQuery<UserComment> query = dbInstance.getCurrentEntityManager() + .createQuery(sb.toString(), UserComment.class) + .setParameter("resname", ores.getResourceableTypeName()) + .setParameter("resId", ores.getResourceableId()); + if(resSubPath != null) { + query.setParameter("resSubPath", resSubPath); + } + return query.getResultList(); } public List<UserComment> getComments(IdentityRef identity) { diff --git a/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDisplayController.java b/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDisplayController.java index be725331260accea40239a66dbbd448295db82eb..e5aa092d2cfaca3bacd334832026093f338447f8 100644 --- a/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDisplayController.java +++ b/src/main/java/org/olat/core/gui/control/generic/iframe/IFrameDisplayController.java @@ -336,28 +336,25 @@ public class IFrameDisplayController extends BasicController implements GenericE setPageDownload(isPageDownloadAllowed(currentUri)); } - private boolean isPageDownloadAllowed(String uri) { + private boolean isPageDownloadAllowed(final String uri) { if(!allowDownload || !StringHelper.containsNonWhitespace(uri)) { return false; } // remove any URL parameters String uriLc = uri.toLowerCase(); - int qmarkPos = uriLc.indexOf("?"); + int qmarkPos = uriLc.indexOf('?'); if (qmarkPos != -1) { // e.g. index.html?olatraw=true uriLc = uriLc.substring(0, qmarkPos); } // remove any anchor references - int hTagPos = uri.indexOf("#"); + int hTagPos = uriLc.indexOf('#'); if (hTagPos != -1) { // e.g. index.html#checkThisOut uriLc = uriLc.substring(0, hTagPos); } // HTML pages are rendered inline, everything else is regarded as "downloadable" - if(uriLc.endsWith(".html") || uriLc.endsWith(".htm") || uriLc.endsWith(".xhtml")) { - return false; - } - return true; + return !uriLc.endsWith(".html") && !uriLc.endsWith(".htm") && !uriLc.endsWith(".xhtml"); } private void setPageDownload(boolean allow) { @@ -385,8 +382,7 @@ public class IFrameDisplayController extends BasicController implements GenericE if (NEW_URI_EVENT.equals(event.getCommand())) { // This event gets triggered from the iframe content by calling a js function outside // Get new uri from JS method and fire to parents - String newUri = ureq.getModuleURI(); - newUri = ureq.getHttpReq().getParameter("uri"); + String newUri = ureq.getHttpReq().getParameter("uri"); int baseUriPos = newUri.indexOf(baseURI); if (baseUriPos != -1) { int newUriPos = baseUriPos + baseURI.length(); diff --git a/src/main/java/org/olat/course/nodes/video/VideoEditController.java b/src/main/java/org/olat/course/nodes/video/VideoEditController.java index 71ba02dc3dd54df2fa8bde3ca4b5241e378d72cb..bcdfa781da0393d0be3ea7c845bbf0332b861f04 100644 --- a/src/main/java/org/olat/course/nodes/video/VideoEditController.java +++ b/src/main/java/org/olat/course/nodes/video/VideoEditController.java @@ -271,16 +271,16 @@ public class VideoEditController extends ActivateableTabbableDefaultController i boolean showRating = config.getBooleanSafe(VideoEditController.CONFIG_KEY_RATING); boolean showComments = config.getBooleanSafe(VideoEditController.CONFIG_KEY_COMMENTS); - VideoDisplayOptions options = VideoDisplayOptions.valueOf(autoplay, showComments, showRating, true, false, false, "", true, true); - switch(config.getStringValue(VideoEditController.CONFIG_KEY_DESCRIPTION_SELECT)) { - case "resourceDescription": break; + VideoDisplayOptions options = VideoDisplayOptions.valueOf(autoplay, showComments, showRating, true, true, false, false, "", true, true); + switch(config.getStringValue(VideoEditController.CONFIG_KEY_DESCRIPTION_SELECT, "none")) { case "customDescription": options.setCustomDescription(true); options.setDescriptionText(config.getStringValue(VideoEditController.CONFIG_KEY_DESCRIPTION_CUSTOMTEXT)); break; case "none": - options.setCustomDescription(true); - options.setDescriptionText(""); + options.setShowDescription(false); + break; + default: break; } @@ -302,9 +302,7 @@ public class VideoEditController extends ActivateableTabbableDefaultController i else return null; } RepositoryManager rm = RepositoryManager.getInstance(); - RepositoryEntry entry = rm.lookupRepositoryEntryBySoftkey(repoSoftkey, strict); - // entry can be null only if !strict - return entry; + return rm.lookupRepositoryEntryBySoftkey(repoSoftkey, strict); } /** @@ -391,7 +389,7 @@ class VideoOptionsForm extends FormBasicController{ config.setBooleanEntry(VideoEditController.CONFIG_KEY_RATING, videoRating.isSelected(0)); config.setBooleanEntry(VideoEditController.CONFIG_KEY_AUTOPLAY, videoAutoplay.isSelected(0)); config.setStringValue(VideoEditController.CONFIG_KEY_DESCRIPTION_SELECT, description.getSelectedKey()); - if(description.getSelectedKey() == "customDescription"){ + if("customDescription".equals(description.getSelectedKey())) { config.setStringValue(VideoEditController.CONFIG_KEY_DESCRIPTION_CUSTOMTEXT, descriptionField.getValue()); } fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT); @@ -425,7 +423,7 @@ class VideoOptionsForm extends FormBasicController{ config.setBooleanEntry(VideoEditController.CONFIG_KEY_RATING, videoRating.isSelected(0)); config.setBooleanEntry(VideoEditController.CONFIG_KEY_AUTOPLAY, videoAutoplay.isSelected(0)); config.setStringValue(VideoEditController.CONFIG_KEY_DESCRIPTION_SELECT, description.getSelectedKey()); - if(description.getSelectedKey() == "customDescription"){ + if("customDescription".equals(description.getSelectedKey())) { config.setStringValue(VideoEditController.CONFIG_KEY_DESCRIPTION_CUSTOMTEXT, descriptionField.getValue()); } } diff --git a/src/main/java/org/olat/course/nodes/video/VideoRunController.java b/src/main/java/org/olat/course/nodes/video/VideoRunController.java index c01d8e4aba7f72f200655fe2c355122c32583702..1418706518329832439c665d3dee11f7d41ba1df 100644 --- a/src/main/java/org/olat/course/nodes/video/VideoRunController.java +++ b/src/main/java/org/olat/course/nodes/video/VideoRunController.java @@ -113,17 +113,17 @@ public class VideoRunController extends BasicController { boolean comments = config.getBooleanSafe(VideoEditController.CONFIG_KEY_COMMENTS); boolean ratings = config.getBooleanSafe(VideoEditController.CONFIG_KEY_RATING); String customtext = config.getStringValue(VideoEditController.CONFIG_KEY_DESCRIPTION_CUSTOMTEXT); - - VideoDisplayOptions displayOptions = VideoDisplayOptions.valueOf(autoplay, comments, ratings, true, false, false, "", false, userCourseEnv.isCourseReadOnly()); + + VideoDisplayOptions displayOptions = VideoDisplayOptions.valueOf(autoplay, comments, ratings, true, true, false, false, null, false, userCourseEnv.isCourseReadOnly()); switch(config.getStringValue(VideoEditController.CONFIG_KEY_DESCRIPTION_SELECT,"none")) { - case "resourceDescription": break; case "customDescription": displayOptions.setCustomDescription(true); displayOptions.setDescriptionText(customtext); break; case "none": - displayOptions.setCustomDescription(true); - displayOptions.setDescriptionText(""); + displayOptions.setShowDescription(false); + break; + default: break; } diff --git a/src/main/java/org/olat/modules/lecture/ui/coach/AbsenceNoticesListController.java b/src/main/java/org/olat/modules/lecture/ui/coach/AbsenceNoticesListController.java index 8f459f9471e3a0b03b98e732b77674f57fbfdc79..c1882aea0fdbe9e3bb37f58de5ffb9b48b50b5f7 100644 --- a/src/main/java/org/olat/modules/lecture/ui/coach/AbsenceNoticesListController.java +++ b/src/main/java/org/olat/modules/lecture/ui/coach/AbsenceNoticesListController.java @@ -248,21 +248,23 @@ public class AbsenceNoticesListController extends FormBasicController { } // decorate with teachers - LecturesBlockSearchParameters searchTeachersParams = new LecturesBlockSearchParameters(); - List<LectureBlockRef> lectureBlocks = blockWithNotices.stream() - .map(LectureBlockWithNotice::getLectureBlock).collect(Collectors.toList()); - searchTeachersParams.setLectureBlocks(lectureBlocks); - List<LectureBlockWithTeachers> teacherBlocks = lectureService.getLectureBlocksWithTeachers(searchTeachersParams); Map<Long, List<Identity>> blockKeyWithTeachersMap = new HashMap<>(); - Map<Identity,Identity> deduplicatesTeachers = new HashMap<>(); - for(LectureBlockWithTeachers teacherBlock:teacherBlocks) { - Long lectureBlockKey = teacherBlock.getLectureBlock().getKey(); - List<Identity> blockList = blockKeyWithTeachersMap - .computeIfAbsent(lectureBlockKey, key -> new ArrayList<>()); - // prevent to load 100X the same identity object - for(Identity teacher:teacherBlock.getTeachers()) { - Identity uniqueTeacher = deduplicatesTeachers.computeIfAbsent(teacher, t -> t); - blockList.add(uniqueTeacher); + if(!blockWithNotices.isEmpty()) { + LecturesBlockSearchParameters searchTeachersParams = new LecturesBlockSearchParameters(); + List<LectureBlockRef> lectureBlocks = blockWithNotices.stream() + .map(LectureBlockWithNotice::getLectureBlock).collect(Collectors.toList()); + searchTeachersParams.setLectureBlocks(lectureBlocks); + List<LectureBlockWithTeachers> teacherBlocks = lectureService.getLectureBlocksWithTeachers(searchTeachersParams); + Map<Identity,Identity> deduplicatesTeachers = new HashMap<>(); + for(LectureBlockWithTeachers teacherBlock:teacherBlocks) { + Long lectureBlockKey = teacherBlock.getLectureBlock().getKey(); + List<Identity> blockList = blockKeyWithTeachersMap + .computeIfAbsent(lectureBlockKey, key -> new ArrayList<>()); + // prevent to load 100X the same identity object + for(Identity teacher:teacherBlock.getTeachers()) { + Identity uniqueTeacher = deduplicatesTeachers.computeIfAbsent(teacher, t -> t); + blockList.add(uniqueTeacher); + } } } diff --git a/src/main/java/org/olat/modules/video/ui/VideoDisplayController.java b/src/main/java/org/olat/modules/video/ui/VideoDisplayController.java index 2fdc84fc49790b5317c8229e481486884379a651..d166f6cf904da62cdb6dbd2be5ae7eabece8ebf6 100644 --- a/src/main/java/org/olat/modules/video/ui/VideoDisplayController.java +++ b/src/main/java/org/olat/modules/video/ui/VideoDisplayController.java @@ -119,11 +119,11 @@ public class VideoDisplayController extends BasicController { private VideoManager videoManager; public VideoDisplayController(UserRequest ureq, WindowControl wControl, RepositoryEntry videoEntry, boolean autoWidth) { - this(ureq, wControl, videoEntry, null, null, VideoDisplayOptions.valueOf(false, false, false, true, false, autoWidth, null, false, false)); + this(ureq, wControl, videoEntry, null, null, VideoDisplayOptions.valueOf(false, false, false, true, true, false, autoWidth, null, false, false)); } public VideoDisplayController(UserRequest ureq, WindowControl wControl, RepositoryEntry videoEntry) { - this(ureq, wControl, videoEntry, null, null, VideoDisplayOptions.valueOf(false, false, false, true, false, false, null, false, false)); + this(ureq, wControl, videoEntry, null, null, VideoDisplayOptions.valueOf(false, false, false, true, true, false, false, null, false, false)); } /** @@ -196,7 +196,8 @@ public class VideoDisplayController extends BasicController { listenTo(commentsAndRatingCtr); mainVC.put("commentsAndRating", commentsAndRatingCtr.getInitialComponent()); } - mainVC.contextPut("showTitleAndDescription", displayOptions.isShowTitleAndDescription()); + mainVC.contextPut("showTitle", displayOptions.isShowTitle()); + mainVC.contextPut("showDescription", displayOptions.isShowDescription()); mainVC.contextPut("alwaysShowControls", displayOptions.isAlwaysShowControls()); mainVC.contextPut("clickToPlayPause", displayOptions.isClickToPlayPause()); // Finally load the video, transcoded versions and tracks @@ -411,8 +412,11 @@ public class VideoDisplayController extends BasicController { mainVC.contextPut("masterUrl", masterUrl); mainVC.contextPut("title", videoEntry.getDisplayname()); - String desc = (StringHelper.containsNonWhitespace(descriptionText) ? descriptionText : videoEntry.getDescription()); - setText(desc, "description"); + if(displayOptions == null || displayOptions.isShowDescription()) { + String desc = (StringHelper.containsNonWhitespace(descriptionText) ? descriptionText : videoEntry.getDescription()); + setText(desc, "description"); + } + String authors = videoEntry.getAuthors(); mainVC.contextPut("authors", (StringHelper.containsNonWhitespace(authors) ? authors : null)); diff --git a/src/main/java/org/olat/modules/video/ui/VideoDisplayOptions.java b/src/main/java/org/olat/modules/video/ui/VideoDisplayOptions.java index 056d0ba6035712b9faf0f79a795d23d0adf31b5a..466bf607e35458b65f83beb24a067fe1fc5ee8ad 100644 --- a/src/main/java/org/olat/modules/video/ui/VideoDisplayOptions.java +++ b/src/main/java/org/olat/modules/video/ui/VideoDisplayOptions.java @@ -31,7 +31,8 @@ public class VideoDisplayOptions { private boolean autoplay; private boolean showComments; private boolean showRating; - private boolean showTitleAndDescription; + private boolean showTitle; + private boolean showDescription; private boolean customDescription; private boolean autoWidth; private boolean readOnly; @@ -44,7 +45,7 @@ public class VideoDisplayOptions { private boolean clickToPlayPause; private boolean authorMode; - public static VideoDisplayOptions valueOf(boolean autoplay, boolean showComments, boolean showRating, boolean showTitleAndDescription, + public static VideoDisplayOptions valueOf(boolean autoplay, boolean showComments, boolean showRating, boolean showTitle, boolean showDescription, boolean customDescription, boolean autoWidth, String descriptionText, boolean authorMode, boolean readOnly) { VideoDisplayOptions options = new VideoDisplayOptions(); options.setAutoplay(autoplay); @@ -54,7 +55,8 @@ public class VideoDisplayOptions { options.setReadOnly(readOnly); options.setShowComments(showComments); options.setShowRating(showRating); - options.setShowTitleAndDescription(showTitleAndDescription); + options.setShowTitle(showTitle); + options.setShowDescription(showDescription); options.setShowPoster(true); options.setShowQuestions(true); options.setShowAnnotations(true); @@ -74,7 +76,8 @@ public class VideoDisplayOptions { options.setReadOnly(false); options.setShowComments(false); options.setShowRating(false); - options.setShowTitleAndDescription(false); + options.setShowTitle(false); + options.setShowDescription(false); options.setShowPoster(true); options.setShowQuestions(false); options.setShowAnnotations(false); @@ -149,14 +152,22 @@ public class VideoDisplayOptions { this.showQuestions = showQuestions; } - public boolean isShowTitleAndDescription() { - return showTitleAndDescription; + public boolean isShowTitle() { + return showTitle; } - public void setShowTitleAndDescription(boolean showTitleAndDescription) { - this.showTitleAndDescription = showTitleAndDescription; + public void setShowTitle(boolean showTitle) { + this.showTitle = showTitle; } + public boolean isShowDescription() { + return showDescription; + } + + public void setShowDescription(boolean showDescription) { + this.showDescription = showDescription; + } + public boolean isCustomDescription() { return customDescription; } diff --git a/src/main/java/org/olat/modules/video/ui/VideoListingController.java b/src/main/java/org/olat/modules/video/ui/VideoListingController.java index ffc266d06782deca710ac63f703e53ccc7f5be46..2f8c1cfe8d34a0a817750f53268e5efd02b290c4 100644 --- a/src/main/java/org/olat/modules/video/ui/VideoListingController.java +++ b/src/main/java/org/olat/modules/video/ui/VideoListingController.java @@ -166,7 +166,7 @@ public class VideoListingController extends FormBasicController implements Activ RepositoryEntrySecurity reSecurity = repositoryManager.isAllowed(ureq, videoEntry); if (reSecurity.canLaunch()) {// no booking implemented for video boolean readOnly = videoEntry.getEntryStatus().decommissioned(); - VideoDisplayOptions options = VideoDisplayOptions.valueOf(true, true, true, true, false, true, null, false, readOnly); + VideoDisplayOptions options = VideoDisplayOptions.valueOf(true, true, true, true, true, false, true, null, false, readOnly); VideoDisplayController videoDisplayCtr = new VideoDisplayController(ureq, getWindowControl(), videoEntry, null, null, options); listenTo(videoDisplayCtr); toolbarPanel.pushController(videoEntry.getDisplayname(), videoDisplayCtr); diff --git a/src/main/java/org/olat/modules/video/ui/_content/video_run.html b/src/main/java/org/olat/modules/video/ui/_content/video_run.html index 36d48973cea7eb94f13a99eca11501eaac2c8ff0..3b00fdb4bcc9e37d2801ff1b510c83aea93bc535 100644 --- a/src/main/java/org/olat/modules/video/ui/_content/video_run.html +++ b/src/main/java/org/olat/modules/video/ui/_content/video_run.html @@ -137,7 +137,7 @@ </script> </div> - #if($showTitleAndDescription && $title) + #if($r.isTrue($showTitle) && $r.isNotEmpty($title)) <h1>$title</h1> #end @@ -147,10 +147,8 @@ $r.escapeHtml($authors) </div> #end - #if($showTitleAndDescription && $description) - <div class="o_desc clearfix"> - $description - </div> + #if($r.isTrue($showDescription) && $r.isNotEmpty($description)) + <div class="o_desc clearfix">$description</div> #end #if($r.available("commentsAndRating")) $r.render("commentsAndRating")