From 81c6eb6829fbbbc58621a17bb12e154a28cebcaa Mon Sep 17 00:00:00 2001 From: srosse <stephane.rosse@frentix.com> Date: Thu, 7 Nov 2019 08:52:27 +0100 Subject: [PATCH] OO-4345: distinct count the courses --- .../manager/RepositoryEntryQueries.java | 2 +- .../repository/course/CoursesWebService.java | 31 +++++++++++-------- .../olat/restapi/support/ObjectFactory.java | 6 ++-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/olat/repository/manager/RepositoryEntryQueries.java b/src/main/java/org/olat/repository/manager/RepositoryEntryQueries.java index ce2ffee0916..fbd6171d2f2 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryEntryQueries.java +++ b/src/main/java/org/olat/repository/manager/RepositoryEntryQueries.java @@ -73,7 +73,7 @@ public class RepositoryEntryQueries { QueryBuilder query = new QueryBuilder(2048); if(Number.class.equals(type)) { - query.append("select count(v.key) from repositoryentry v "); + query.append("select count(distinct v.key) from repositoryentry v "); query.append(" inner join v.olatResource as res"); } else if(params.getParentEntry() != null) { query.append("select distinct v from ").append(CatalogEntry.class.getName()).append(" cei ") diff --git a/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java b/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java index 05357dd7136..7b12cfc7f9d 100644 --- a/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java +++ b/src/main/java/org/olat/restapi/repository/course/CoursesWebService.java @@ -64,6 +64,7 @@ import org.olat.core.util.Formatter; import org.olat.core.util.StringHelper; import org.olat.core.util.coordinate.LockResult; import org.olat.core.util.resource.OresHelper; +import org.olat.course.CorruptedCourseException; import org.olat.course.CourseFactory; import org.olat.course.CourseModule; import org.olat.course.ICourse; @@ -159,8 +160,7 @@ public class CoursesWebService { @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response getCourseList(@QueryParam("start") @DefaultValue("0") Integer start, - @QueryParam("limit") @DefaultValue("25") Integer limit, - @QueryParam("managed") Boolean managed, + @QueryParam("limit") Integer limit, @QueryParam("managed") Boolean managed, @QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef, @QueryParam("repositoryEntryKey") String repositoryEntryKey, @Context HttpServletRequest httpRequest, @Context Request request) { @@ -179,7 +179,7 @@ public class CoursesWebService { try { params.setRepositoryEntryKeys(Collections.singletonList(Long.valueOf(repositoryEntryKey))); } catch (NumberFormatException e) { - log.error("Cannot parse the following repository entry key: " + repositoryEntryKey); + log.error("Cannot parse the following repository entry key: {}", repositoryEntryKey); } } @@ -205,12 +205,14 @@ public class CoursesWebService { for (RepositoryEntry repoEntry : repoEntries) { try { ICourse course = loadCourse(repoEntry.getOlatResource().getResourceableId()); - voList.add(ObjectFactory.get(repoEntry, course)); - if(count++ % 33 == 0) { - dbInstance.commitAndCloseSession(); + if(course != null) { + voList.add(ObjectFactory.get(repoEntry, course)); + if(count++ % 33 == 0) { + dbInstance.commitAndCloseSession(); + } } } catch (Exception e) { - log.error("Cannot load the course with this repository entry: " + repoEntry, e); + log.error("Cannot load the course with this repository entry: {}", repoEntry, e); } } @@ -433,8 +435,11 @@ public class CoursesWebService { public static ICourse loadCourse(Long courseId) { try { return CourseFactory.loadCourse(courseId); + } catch(CorruptedCourseException ex) { + log.error("Corrupted course with id: {}", courseId); + return null; } catch(Exception ex) { - log.error("cannot load course with id: " + courseId, ex); + log.error("cannot load course with id: {}", courseId, ex); return null; } } @@ -442,7 +447,7 @@ public class CoursesWebService { private ICourse importCourse(UserRequest ureq, Identity identity, File fCourseImportZIP, String displayName, String softKey, RepositoryEntryStatusEnum status, boolean allUsers, boolean guests, Long organisationKey) { - log.info("REST Import course " + displayName + " START"); + log.info("REST Import course {} START", displayName); if(!StringHelper.containsNonWhitespace(displayName)) { displayName = "import-" + UUID.randomUUID(); } @@ -470,13 +475,13 @@ public class CoursesWebService { re.setSoftkey(softKey); re = repositoryService.update(re); } - log.info("REST Import course " + displayName + " END"); + log.info("REST Import course {} END", displayName); //publish - log.info("REST Publish course " + displayName + " START"); + log.info("REST Publish course {} START", displayName); ICourse course = CourseFactory.loadCourse(re); CourseFactory.publishCourse(course, status, allUsers, guests, identity, ureq.getLocale()); - log.info("REST Publish course " + displayName + " END"); + log.info("REST Publish course {} END", displayName); return course; } @@ -491,7 +496,7 @@ public class CoursesWebService { src = repositoryManager.lookupRepositoryEntry(copyFrom, false); } if(src == null) { - log.warn("Cannot find course to copy from: " + copyFrom); + log.warn("Cannot find course to copy from: {}", copyFrom); return null; } OLATResource originalOres = olatResourceManager.findResourceable(src.getOlatResource()); diff --git a/src/main/java/org/olat/restapi/support/ObjectFactory.java b/src/main/java/org/olat/restapi/support/ObjectFactory.java index 16bb83c6677..5efc5329b36 100644 --- a/src/main/java/org/olat/restapi/support/ObjectFactory.java +++ b/src/main/java/org/olat/restapi/support/ObjectFactory.java @@ -186,10 +186,10 @@ public class ObjectFactory { public static CourseConfigVO getConfig(ICourse course) { CourseConfigVO vo = new CourseConfigVO(); CourseConfig config = course.getCourseEnvironment().getCourseConfig(); - vo.setCalendar(new Boolean(config.isCalendarEnabled())); - vo.setChat(new Boolean(config.isChatEnabled())); + vo.setCalendar(Boolean.valueOf(config.isCalendarEnabled())); + vo.setChat(Boolean.valueOf(config.isChatEnabled())); vo.setCssLayoutRef(config.getCssLayoutRef()); - vo.setEfficencyStatement(new Boolean(config.isEfficencyStatementEnabled())); + vo.setEfficencyStatement(Boolean.valueOf(config.isEfficencyStatementEnabled())); vo.setGlossarySoftkey(config.getGlossarySoftKey()); vo.setSharedFolderSoftKey(config.getSharedFolderSoftkey()); return vo; -- GitLab