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

OO-4345: distinct count the courses

parent fbbd6488
No related branches found
No related tags found
No related merge requests found
...@@ -73,7 +73,7 @@ public class RepositoryEntryQueries { ...@@ -73,7 +73,7 @@ public class RepositoryEntryQueries {
QueryBuilder query = new QueryBuilder(2048); QueryBuilder query = new QueryBuilder(2048);
if(Number.class.equals(type)) { 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"); query.append(" inner join v.olatResource as res");
} else if(params.getParentEntry() != null) { } else if(params.getParentEntry() != null) {
query.append("select distinct v from ").append(CatalogEntry.class.getName()).append(" cei ") query.append("select distinct v from ").append(CatalogEntry.class.getName()).append(" cei ")
......
...@@ -64,6 +64,7 @@ import org.olat.core.util.Formatter; ...@@ -64,6 +64,7 @@ import org.olat.core.util.Formatter;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
import org.olat.core.util.coordinate.LockResult; import org.olat.core.util.coordinate.LockResult;
import org.olat.core.util.resource.OresHelper; import org.olat.core.util.resource.OresHelper;
import org.olat.course.CorruptedCourseException;
import org.olat.course.CourseFactory; import org.olat.course.CourseFactory;
import org.olat.course.CourseModule; import org.olat.course.CourseModule;
import org.olat.course.ICourse; import org.olat.course.ICourse;
...@@ -159,8 +160,7 @@ public class CoursesWebService { ...@@ -159,8 +160,7 @@ public class CoursesWebService {
@GET @GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getCourseList(@QueryParam("start") @DefaultValue("0") Integer start, public Response getCourseList(@QueryParam("start") @DefaultValue("0") Integer start,
@QueryParam("limit") @DefaultValue("25") Integer limit, @QueryParam("limit") Integer limit, @QueryParam("managed") Boolean managed,
@QueryParam("managed") Boolean managed,
@QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef, @QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef,
@QueryParam("repositoryEntryKey") String repositoryEntryKey, @QueryParam("repositoryEntryKey") String repositoryEntryKey,
@Context HttpServletRequest httpRequest, @Context Request request) { @Context HttpServletRequest httpRequest, @Context Request request) {
...@@ -179,7 +179,7 @@ public class CoursesWebService { ...@@ -179,7 +179,7 @@ public class CoursesWebService {
try { try {
params.setRepositoryEntryKeys(Collections.singletonList(Long.valueOf(repositoryEntryKey))); params.setRepositoryEntryKeys(Collections.singletonList(Long.valueOf(repositoryEntryKey)));
} catch (NumberFormatException e) { } 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 { ...@@ -205,12 +205,14 @@ public class CoursesWebService {
for (RepositoryEntry repoEntry : repoEntries) { for (RepositoryEntry repoEntry : repoEntries) {
try { try {
ICourse course = loadCourse(repoEntry.getOlatResource().getResourceableId()); ICourse course = loadCourse(repoEntry.getOlatResource().getResourceableId());
voList.add(ObjectFactory.get(repoEntry, course)); if(course != null) {
if(count++ % 33 == 0) { voList.add(ObjectFactory.get(repoEntry, course));
dbInstance.commitAndCloseSession(); if(count++ % 33 == 0) {
dbInstance.commitAndCloseSession();
}
} }
} catch (Exception e) { } 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 { ...@@ -433,8 +435,11 @@ public class CoursesWebService {
public static ICourse loadCourse(Long courseId) { public static ICourse loadCourse(Long courseId) {
try { try {
return CourseFactory.loadCourse(courseId); return CourseFactory.loadCourse(courseId);
} catch(CorruptedCourseException ex) {
log.error("Corrupted course with id: {}", courseId);
return null;
} catch(Exception ex) { } catch(Exception ex) {
log.error("cannot load course with id: " + courseId, ex); log.error("cannot load course with id: {}", courseId, ex);
return null; return null;
} }
} }
...@@ -442,7 +447,7 @@ public class CoursesWebService { ...@@ -442,7 +447,7 @@ public class CoursesWebService {
private ICourse importCourse(UserRequest ureq, Identity identity, File fCourseImportZIP, String displayName, private ICourse importCourse(UserRequest ureq, Identity identity, File fCourseImportZIP, String displayName,
String softKey, RepositoryEntryStatusEnum status, boolean allUsers, boolean guests, Long organisationKey) { 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)) { if(!StringHelper.containsNonWhitespace(displayName)) {
displayName = "import-" + UUID.randomUUID(); displayName = "import-" + UUID.randomUUID();
} }
...@@ -470,13 +475,13 @@ public class CoursesWebService { ...@@ -470,13 +475,13 @@ public class CoursesWebService {
re.setSoftkey(softKey); re.setSoftkey(softKey);
re = repositoryService.update(re); re = repositoryService.update(re);
} }
log.info("REST Import course " + displayName + " END"); log.info("REST Import course {} END", displayName);
//publish //publish
log.info("REST Publish course " + displayName + " START"); log.info("REST Publish course {} START", displayName);
ICourse course = CourseFactory.loadCourse(re); ICourse course = CourseFactory.loadCourse(re);
CourseFactory.publishCourse(course, status, allUsers, guests, identity, ureq.getLocale()); 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; return course;
} }
...@@ -491,7 +496,7 @@ public class CoursesWebService { ...@@ -491,7 +496,7 @@ public class CoursesWebService {
src = repositoryManager.lookupRepositoryEntry(copyFrom, false); src = repositoryManager.lookupRepositoryEntry(copyFrom, false);
} }
if(src == null) { if(src == null) {
log.warn("Cannot find course to copy from: " + copyFrom); log.warn("Cannot find course to copy from: {}", copyFrom);
return null; return null;
} }
OLATResource originalOres = olatResourceManager.findResourceable(src.getOlatResource()); OLATResource originalOres = olatResourceManager.findResourceable(src.getOlatResource());
......
...@@ -186,10 +186,10 @@ public class ObjectFactory { ...@@ -186,10 +186,10 @@ public class ObjectFactory {
public static CourseConfigVO getConfig(ICourse course) { public static CourseConfigVO getConfig(ICourse course) {
CourseConfigVO vo = new CourseConfigVO(); CourseConfigVO vo = new CourseConfigVO();
CourseConfig config = course.getCourseEnvironment().getCourseConfig(); CourseConfig config = course.getCourseEnvironment().getCourseConfig();
vo.setCalendar(new Boolean(config.isCalendarEnabled())); vo.setCalendar(Boolean.valueOf(config.isCalendarEnabled()));
vo.setChat(new Boolean(config.isChatEnabled())); vo.setChat(Boolean.valueOf(config.isChatEnabled()));
vo.setCssLayoutRef(config.getCssLayoutRef()); vo.setCssLayoutRef(config.getCssLayoutRef());
vo.setEfficencyStatement(new Boolean(config.isEfficencyStatementEnabled())); vo.setEfficencyStatement(Boolean.valueOf(config.isEfficencyStatementEnabled()));
vo.setGlossarySoftkey(config.getGlossarySoftKey()); vo.setGlossarySoftkey(config.getGlossarySoftKey());
vo.setSharedFolderSoftKey(config.getSharedFolderSoftkey()); vo.setSharedFolderSoftKey(config.getSharedFolderSoftkey());
return vo; return vo;
......
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