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 bd4ce7c38218e7a72315fe960b6abe71bbc979ac..ad82c3cfef83232f0298e43006dca8fd52d6f997 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 303dc5a50a1647f371f0f3bcd0496d3c524d7d69..35c441dc9f4349ea15ddaed7ad234df056479e9e 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 3555b285ed81bdfeb06f234b88cff0cde85db570..9048a5ff6c293410018067f47e03335b448c85c3 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 1e7911e6e30366bceda1bdc09f30e218dc54de99..221a598d996c081861eb41e21f8fcfb63cf57a3b 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 ca09f5b399dfe36f5734278ab48a00add497f485..8e0b502a295660fa23b86351697caba87a1cb7ad 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 f2d15afd631f531b1b422cc3ee416210a6af0728..3c9e8f2e1e770ac0df4993b7bfc97c8abfe4eb6b 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 90d8da109ff34bf8a31489cb14e03906c83793d0..f2d98ee8d4c39b8c5c81128aba625d6cacd98f90 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 d6f7627433fe0a51c6836df2869d8555274229f6..199ce7af53420f1720628c9b14c60a9ec1a3182f 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 c751d4c780f6d3aace19e39c984d9c2ad8346b7e..b469bb6527f69fb23c650dab68af4c01fa962faf 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 802f62e0abe565d66051109c0f1c49682c69973c..3d3635e40111056e400d52942913141c3f4d6fd5 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 2fdd148a3a1000f29e435c0405909c5ceceb105e..ae76e4a8869723a6e5ff83bf075b8c89e29d899f 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 648f66e201dba09033b4fe9b754f4ed407a0e5bf..2d21c3a5b13ba64952c16ed822b8b7724eff1f88 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 935fa7f550df9bad4ee4ac21bd212a7391b5c2a3..3f4b951c97d99d8cff279dd0bafc083cd3868579 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());