From 6cf640ce36719bb0870f7a9057f56ef27f7246b9 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Thu, 7 Aug 2014 10:23:31 +0200 Subject: [PATCH] OO-984,OO-990: removed unused stuff in the search of my courses, enable real admin search for admin in authoring environment, don't show the resource list in catalog nodes without resources... --- .../persistence/PersistenceHelper.java | 6 +++- .../UserCourseInformationsManager.java | 9 +++-- .../UserCourseInformationsManagerImpl.java | 29 +++++++++++++--- .../repository/RepositoryEntryMyView.java | 11 ------ .../manager/RepositoryEntryAuthorQueries.java | 5 +++ .../RepositoryEntryMyCourseQueries.java | 21 +++--------- .../model/RepositoryEntryMyCourseImpl.java | 34 ------------------- .../ui/list/CatalogNodeController.java | 4 ++- .../RepositoryEntryDetailsController.java | 15 ++------ .../ui/list/RepositoryEntryRow.java | 34 ------------------- .../repository/ui/list/_content/node.html | 4 ++- src/main/webapp/static/themes/compiletheme.sh | 2 +- .../UserCourseInformationsManagerTest.java | 13 +++++++ 13 files changed, 68 insertions(+), 119 deletions(-) diff --git a/src/main/java/org/olat/core/commons/persistence/PersistenceHelper.java b/src/main/java/org/olat/core/commons/persistence/PersistenceHelper.java index bd4ce7c3821..ad82c3cfef8 100644 --- a/src/main/java/org/olat/core/commons/persistence/PersistenceHelper.java +++ b/src/main/java/org/olat/core/commons/persistence/PersistenceHelper.java @@ -150,7 +150,9 @@ public class PersistenceHelper { if (string.length() > 1 && string.startsWith("\"") && string.endsWith("\"")) { string = string.substring(1, string.length()-1); } else { - string = string + "%"; + if(!string.startsWith("*") && !string.endsWith("*")) { + string = "%" + string + "%"; + } string = string.replace('*', '%'); } // with 'LIKE' the character '_' is a wildcard which matches exactly one character. @@ -158,6 +160,8 @@ public class PersistenceHelper { string = string.replace("_", "\\_"); return string.toLowerCase(); } + + /** * diff --git a/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManager.java b/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManager.java index 303dc5a50a1..35c441dc9f4 100644 --- a/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManager.java +++ b/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManager.java @@ -23,6 +23,7 @@ import java.util.Date; import java.util.List; import java.util.Map; +import org.olat.basesecurity.IdentityRef; import org.olat.core.id.Identity; import org.olat.course.assessment.UserCourseInformations; import org.olat.repository.RepositoryEntry; @@ -34,16 +35,18 @@ import org.olat.resource.OLATResource; */ public interface UserCourseInformationsManager { - public UserCourseInformations getUserCourseInformations(Long courseResourceId, Identity identity); + public UserCourseInformations getUserCourseInformations(Long courseResourceId, IdentityRef identity); - public List<UserCourseInformations> getUserCourseInformations(Identity identity, List<OLATResource> resources); + public List<UserCourseInformations> getUserCourseInformations(IdentityRef identity, List<OLATResource> resources); public List<UserCourseInformations> getUserCourseInformations(List<Long> keys); public void updateUserCourseInformations(Long courseResId, Identity identity, boolean strict); - public Date getInitialLaunchDate(Long courseResourceId, Identity identity); + public Date getInitialLaunchDate(Long courseResourceId, IdentityRef identity); + + public Date getRecentLaunchDate(Long courseResourceId, IdentityRef identity); public Map<Long,Date> getInitialLaunchDates(Long courseResourceId, List<Identity> identities); diff --git a/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManagerImpl.java b/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManagerImpl.java index 3555b285ed8..9048a5ff6c2 100644 --- a/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManagerImpl.java +++ b/src/main/java/org/olat/course/assessment/manager/UserCourseInformationsManagerImpl.java @@ -30,6 +30,7 @@ import java.util.Set; import javax.persistence.FlushModeType; import javax.persistence.TypedQuery; +import org.olat.basesecurity.IdentityRef; import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.PersistenceHelper; import org.olat.core.id.Identity; @@ -61,7 +62,7 @@ public class UserCourseInformationsManagerImpl extends BasicManager implements U private OLATResourceManager resourceManager; @Override - public UserCourseInfosImpl getUserCourseInformations(Long courseResourceId, Identity identity) { + public UserCourseInfosImpl getUserCourseInformations(Long courseResourceId, IdentityRef identity) { try { StringBuilder sb = new StringBuilder(); sb.append("select infos from ").append(UserCourseInfosImpl.class.getName()).append(" as infos ") @@ -86,7 +87,7 @@ public class UserCourseInformationsManagerImpl extends BasicManager implements U } @Override - public List<UserCourseInformations> getUserCourseInformations(Identity identity, List<OLATResource> resources) { + public List<UserCourseInformations> getUserCourseInformations(IdentityRef identity, List<OLATResource> resources) { if(resources == null || resources.isEmpty()) { return Collections.emptyList(); } @@ -242,7 +243,26 @@ public class UserCourseInformationsManagerImpl extends BasicManager implements U } @Override - public Date getInitialLaunchDate(Long courseResourceId, Identity identity) { + public Date getRecentLaunchDate(Long courseResourceId, IdentityRef identity) { + StringBuilder sb = new StringBuilder(); + sb.append("select infos.recentLaunch from usercourseinfos as infos ") + .append(" inner join infos.resource as resource") + .append(" where infos.identity.key=:identityKey and resource.resId=:resId and resource.resName='CourseModule'"); + + List<Date> infoList = dbInstance.getCurrentEntityManager() + .createQuery(sb.toString(), Date.class) + .setParameter("identityKey", identity.getKey()) + .setParameter("resId", courseResourceId) + .getResultList(); + + if(infoList.isEmpty()) { + return null; + } + return infoList.get(0); + } + + @Override + public Date getInitialLaunchDate(Long courseResourceId, IdentityRef identity) { return getInitialLaunchDate(courseResourceId, identity.getKey()); } @@ -251,8 +271,7 @@ public class UserCourseInformationsManagerImpl extends BasicManager implements U StringBuilder sb = new StringBuilder(); sb.append("select infos.initialLaunch from ").append(UserCourseInfosImpl.class.getName()).append(" as infos ") .append(" inner join infos.resource as resource") - .append(" inner join infos.identity as identity") - .append(" where identity.key=:identityKey and resource.resId=:resId and resource.resName='CourseModule'"); + .append(" where infos.identity.key=:identityKey and resource.resId=:resId and resource.resName='CourseModule'"); List<Date> infoList = dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), Date.class) diff --git a/src/main/java/org/olat/repository/RepositoryEntryMyView.java b/src/main/java/org/olat/repository/RepositoryEntryMyView.java index 1e7911e6e30..221a598d996 100644 --- a/src/main/java/org/olat/repository/RepositoryEntryMyView.java +++ b/src/main/java/org/olat/repository/RepositoryEntryMyView.java @@ -19,8 +19,6 @@ */ package org.olat.repository; -import java.util.Date; - import org.olat.core.id.OLATResourceable; import org.olat.repository.model.RepositoryEntryLifecycle; import org.olat.resource.OLATResource; @@ -64,17 +62,8 @@ public interface RepositoryEntryMyView extends OLATResourceable { */ public boolean isMarked(); - /** - * @return The date of the first launch saved in the user course infos. - */ - public Date getInitialLaunch(); - - public Date getRecentLaunch(); - public Integer getVisit(); - public Long getTimeSpend(); - /** * @return The rating made by the user or null if the user has never rated the entry */ diff --git a/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorQueries.java b/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorQueries.java index ca09f5b399d..8e0b502a295 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorQueries.java +++ b/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorQueries.java @@ -31,6 +31,7 @@ import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.PersistenceHelper; import org.olat.core.commons.services.mark.impl.MarkImpl; import org.olat.core.id.Identity; +import org.olat.core.id.Roles; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.util.StringHelper; @@ -101,8 +102,10 @@ public class RepositoryEntryAuthorQueries { Class<T> type) { Identity identity = params.getIdentity(); + Roles roles = params.getRoles(); List<String> resourceTypes = params.getResourceTypes(); boolean oracle = "oracle".equals(dbInstance.getDbVendor()); + boolean admin = (roles != null && (roles.isInstitutionalResourceManager() || roles.isOLATAdmin())); boolean count = Number.class.equals(type); StringBuilder sb = new StringBuilder(); @@ -132,6 +135,8 @@ public class RepositoryEntryAuthorQueries { .append(" where rel.entry=v and rel.group=baseGroup and membership.group=baseGroup and membership.identity.key=ident.key") .append(" and membership.role='").append(GroupRoles.owner.name()).append("'") .append(" )"); + } else if(admin) { + sb.append(" and v.access>=").append(RepositoryEntry.ACC_OWNERS); } else { sb.append(" and (v.access>=").append(RepositoryEntry.ACC_OWNERS_AUTHORS) .append(" or (v.access=").append(RepositoryEntry.ACC_OWNERS) diff --git a/src/main/java/org/olat/repository/manager/RepositoryEntryMyCourseQueries.java b/src/main/java/org/olat/repository/manager/RepositoryEntryMyCourseQueries.java index f2d15afd631..3c9e8f2e1e7 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryEntryMyCourseQueries.java +++ b/src/main/java/org/olat/repository/manager/RepositoryEntryMyCourseQueries.java @@ -40,7 +40,6 @@ import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.util.StringHelper; import org.olat.course.assessment.EfficiencyStatementManager; -import org.olat.course.assessment.UserCourseInformations; import org.olat.course.assessment.manager.UserCourseInformationsManager; import org.olat.course.assessment.model.UserEfficiencyStatementImpl; import org.olat.course.assessment.model.UserEfficiencyStatementLight; @@ -101,7 +100,6 @@ public class RepositoryEntryMyCourseQueries { query.setMaxResults(maxResults); } - List<Long> infosKeys = new ArrayList<>(); List<Long> effKeys = new ArrayList<>(); List<Object[]> objects = query.getResultList(); List<RepositoryEntryMyView> views = new ArrayList<>(objects.size()); @@ -118,9 +116,9 @@ public class RepositoryEntryMyCourseQueries { views.add(view); viewsMap.put(re.getOlatResource(), view); - Long infosKey = (Long)object[4]; - if(infosKey != null) { - infosKeys.add(infosKey); + Integer visit = (Integer)object[4]; + if(visit != null && visit.intValue() >= 0) { + view.setVisit(visit); } Long effKey = (Long)object[5]; if(effKey != null) { @@ -138,15 +136,6 @@ public class RepositoryEntryMyCourseQueries { } } - if(infosKeys.size() > 0) { - List<UserCourseInformations> courseInfos = userCourseInformationsManager.getUserCourseInformations(infosKeys); - for(UserCourseInformations courseInfo:courseInfos) { - if(viewsMap.containsKey(courseInfo.getResource())) { - viewsMap.get(courseInfo.getResource()).setCourseInfos(courseInfo); - } - } - } - return views; } @@ -180,9 +169,9 @@ public class RepositoryEntryMyCourseQueries { .append(" where rating.resId=v.key and rating.creator=ident and rating.resName='RepositoryEntry'") .append(" ) as myrating") // user course informations - .append(" ,(select infos.key from usercourseinfos as infos") + .append(" ,(select infos.visit from usercourseinfos as infos") .append(" where infos.resource=res and infos.identity=ident") - .append(" ) as infosKey") + .append(" ) as visit") //efficiency statements .append(" ,(select eff.key from ").append(UserEfficiencyStatementImpl.class.getName()).append(" as eff") .append(" where eff.resource=res and eff.identity=ident") diff --git a/src/main/java/org/olat/repository/model/RepositoryEntryMyCourseImpl.java b/src/main/java/org/olat/repository/model/RepositoryEntryMyCourseImpl.java index 90d8da109ff..f2d98ee8d4c 100644 --- a/src/main/java/org/olat/repository/model/RepositoryEntryMyCourseImpl.java +++ b/src/main/java/org/olat/repository/model/RepositoryEntryMyCourseImpl.java @@ -63,11 +63,7 @@ public class RepositoryEntryMyCourseImpl implements RepositoryEntryMyView, Creat private Double averageRating; private long numOfRatings; private long numOfComments; - - private Date initialLaunch; - private Date recentLaunch; private Integer visit; - private Long timeSpend; private long offersAvailable; @@ -109,10 +105,7 @@ public class RepositoryEntryMyCourseImpl implements RepositoryEntryMyView, Creat public void setCourseInfos(UserCourseInformations courseInfos) { if(courseInfos != null) { - initialLaunch = courseInfos.getInitialLaunch(); - recentLaunch = courseInfos.getRecentLaunch(); visit = courseInfos.getVisit(); - timeSpend = courseInfos.getTimeSpend(); } } @@ -248,24 +241,6 @@ public class RepositoryEntryMyCourseImpl implements RepositoryEntryMyView, Creat return marked; } - @Override - public Date getInitialLaunch() { - return initialLaunch; - } - - public void setInitialLaunch(Date initialLaunch) { - this.initialLaunch = initialLaunch; - } - - @Override - public Date getRecentLaunch() { - return recentLaunch; - } - - public void setRecentLaunch(Date recentLaunch) { - this.recentLaunch = recentLaunch; - } - @Override public Integer getVisit() { return visit; @@ -275,15 +250,6 @@ public class RepositoryEntryMyCourseImpl implements RepositoryEntryMyView, Creat this.visit = visit; } - @Override - public Long getTimeSpend() { - return timeSpend; - } - - public void setTimeSpend(Long timeSpend) { - this.timeSpend = timeSpend; - } - public Integer getMyRating() { return myRating; } diff --git a/src/main/java/org/olat/repository/ui/list/CatalogNodeController.java b/src/main/java/org/olat/repository/ui/list/CatalogNodeController.java index d6f7627433f..199ce7af534 100644 --- a/src/main/java/org/olat/repository/ui/list/CatalogNodeController.java +++ b/src/main/java/org/olat/repository/ui/list/CatalogNodeController.java @@ -132,7 +132,9 @@ public class CatalogNodeController extends BasicController implements Activateab = new SearchMyRepositoryEntryViewParams(getIdentity(), ureq.getUserSession().getRoles(), "CourseModule"); searchParams.setParentEntry(catalogEntry); entryListController = new RepositoryEntryListController(ureq, wControl, searchParams, true, false, "catalog", stackPanel); - mainVC.put("entries", entryListController.getInitialComponent()); + if(!entryListController.isEmpty()) { + mainVC.put("entries", entryListController.getInitialComponent()); + } listenTo(entryListController); if(wrapInMainPanel) { diff --git a/src/main/java/org/olat/repository/ui/list/RepositoryEntryDetailsController.java b/src/main/java/org/olat/repository/ui/list/RepositoryEntryDetailsController.java index c751d4c780f..b469bb6527f 100644 --- a/src/main/java/org/olat/repository/ui/list/RepositoryEntryDetailsController.java +++ b/src/main/java/org/olat/repository/ui/list/RepositoryEntryDetailsController.java @@ -62,7 +62,6 @@ import org.olat.core.util.vfs.VFSLeaf; import org.olat.course.CorruptedCourseException; import org.olat.course.assessment.AssessmentHelper; import org.olat.course.assessment.EfficiencyStatementManager; -import org.olat.course.assessment.UserCourseInformations; import org.olat.course.assessment.UserEfficiencyStatement; import org.olat.course.assessment.manager.UserCourseInformationsManager; import org.olat.course.run.RunMainController; @@ -386,23 +385,15 @@ public class RepositoryEntryDetailsController extends FormBasicController { layoutCont.contextPut("failed", failed); layoutCont.contextPut("score", score); - Date recentLaunch = null; - if(row != null) { - recentLaunch = row.getRecentLaunch(); - } else { - Long courseResId = entry.getOlatResource().getResourceableId(); - UserCourseInformations infos = userCourseInfosManager.getUserCourseInformations(courseResId, getIdentity()); - if(infos != null) { - recentLaunch= infos.getRecentLaunch(); - } - } + Long courseResId = entry.getOlatResource().getResourceableId(); + Date recentLaunch = userCourseInfosManager.getRecentLaunchDate(courseResId, getIdentity()); layoutCont.contextPut("recentLaunch", recentLaunch); // show how many users are currently using this resource String numUsers; OLATResourceable ores = entry.getOlatResource(); int cnt = 0; - OLATResourceable courseRunOres = OresHelper.createOLATResourceableInstance(RunMainController.ORES_TYPE_COURSE_RUN, entry.getOlatResource().getResourceableId()); + OLATResourceable courseRunOres = OresHelper.createOLATResourceableInstance(RunMainController.ORES_TYPE_COURSE_RUN, courseResId); if (ores != null) cnt = coordinatorManager.getCoordinator().getEventBus().getListeningIdentityCntFor(courseRunOres); numUsers = String.valueOf(cnt); layoutCont.contextPut("numUsers", numUsers); diff --git a/src/main/java/org/olat/repository/ui/list/RepositoryEntryRow.java b/src/main/java/org/olat/repository/ui/list/RepositoryEntryRow.java index 802f62e0abe..3d3635e4011 100644 --- a/src/main/java/org/olat/repository/ui/list/RepositoryEntryRow.java +++ b/src/main/java/org/olat/repository/ui/list/RepositoryEntryRow.java @@ -58,9 +58,6 @@ public class RepositoryEntryRow implements RepositoryEntryRef { private boolean member; public int visit; - public long timeSpend; - public Date initialLaunch; - public Date recentLaunch; private Integer myRating; private Double averageRating; @@ -104,18 +101,11 @@ public class RepositoryEntryRow implements RepositoryEntryRef { setScore(AssessmentHelper.getRoundedScore(entry.getScore())); //user course infos - setInitialLaunch(entry.getInitialLaunch()); - setRecentLaunch(entry.getRecentLaunch()); if(entry.getVisit() != null) { setVisit(entry.getVisit().intValue()); } else { setVisit(0); } - if(entry.getTimeSpend() != null) { - setTimeSpend(entry.getTimeSpend().longValue()); - } else { - setTimeSpend(0l); - } //rating setMyRating(entry.getMyRating()); @@ -448,28 +438,4 @@ public class RepositoryEntryRow implements RepositoryEntryRef { public void setVisit(int visit) { this.visit = visit; } - - public long getTimeSpend() { - return timeSpend; - } - - public void setTimeSpend(long timeSpend) { - this.timeSpend = timeSpend; - } - - public Date getInitialLaunch() { - return initialLaunch; - } - - public void setInitialLaunch(Date initialLaunch) { - this.initialLaunch = initialLaunch; - } - - public Date getRecentLaunch() { - return recentLaunch; - } - - public void setRecentLaunch(Date recentLaunch) { - this.recentLaunch = recentLaunch; - } } \ No newline at end of file diff --git a/src/main/java/org/olat/repository/ui/list/_content/node.html b/src/main/java/org/olat/repository/ui/list/_content/node.html index 2fdd148a3a1..ae76e4a8869 100644 --- a/src/main/java/org/olat/repository/ui/list/_content/node.html +++ b/src/main/java/org/olat/repository/ui/list/_content/node.html @@ -54,7 +54,9 @@ </div> ## END o_catalog ## Render course list component - $r.render("entries") + #if($r.available("entries")) + $r.render("entries") + #end <script type="text/javascript"> /* <![CDATA[ */ diff --git a/src/main/webapp/static/themes/compiletheme.sh b/src/main/webapp/static/themes/compiletheme.sh index 648f66e201d..2d21c3a5b13 100755 --- a/src/main/webapp/static/themes/compiletheme.sh +++ b/src/main/webapp/static/themes/compiletheme.sh @@ -43,7 +43,7 @@ doCompile () { fi echo "Compiling SASS: $TARGET $STYLE" sass --version - sass --style $STYLE --update $TARGET:$TARGET --load-path light light/modules + sass --style $STYLE --no-cache --update $TARGET:$TARGET --load-path light light/modules echo "sass --style $STYLE --update $TARGET:$TARGET --load-path light light/modules" echo "done" } diff --git a/src/test/java/org/olat/course/assessment/manager/UserCourseInformationsManagerTest.java b/src/test/java/org/olat/course/assessment/manager/UserCourseInformationsManagerTest.java index 935fa7f550d..3f4b951c97d 100644 --- a/src/test/java/org/olat/course/assessment/manager/UserCourseInformationsManagerTest.java +++ b/src/test/java/org/olat/course/assessment/manager/UserCourseInformationsManagerTest.java @@ -95,6 +95,19 @@ public class UserCourseInformationsManagerTest extends OlatTestCase { Assert.assertNotNull(infos.getIdentity()); } + @Test + public void getRecentLaunchDate() { + Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-7-" + UUID.randomUUID().toString()); + ICourse course = CoursesWebService.createEmptyCourse(user, "course-launch-dates", "course long name", null); + dbInstance.commitAndCloseSession(); + + userCourseInformationsManager.updateUserCourseInformations(course.getResourceableId(), user, true); + dbInstance.commitAndCloseSession(); + + Date launchDate = userCourseInformationsManager.getRecentLaunchDate(course.getResourceableId(), user); + Assert.assertNotNull(launchDate); + } + @Test public void getInitialLaunchDate() { Identity user = JunitTestHelper.createAndPersistIdentityAsUser("user-launch-2-" + UUID.randomUUID().toString()); -- GitLab