diff --git a/src/main/java/org/olat/repository/SearchAuthorRepositoryEntryViewParams.java b/src/main/java/org/olat/repository/SearchAuthorRepositoryEntryViewParams.java index 59cd269a7c83b8e534ce0b4ed650603a75409a90..9c3d3f97b6e6b7f1a0260feb281942ffd41cbaad 100644 --- a/src/main/java/org/olat/repository/SearchAuthorRepositoryEntryViewParams.java +++ b/src/main/java/org/olat/repository/SearchAuthorRepositoryEntryViewParams.java @@ -40,9 +40,9 @@ public class SearchAuthorRepositoryEntryViewParams { private String idAndRefs; private String author; private String displayname; + private String description; private OrderBy orderBy; - private List<Filter> filters; private List<String> resourceTypes; private List<Long> repoEntryKeys; @@ -75,6 +75,14 @@ public class SearchAuthorRepositoryEntryViewParams { this.displayname = displayname; } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + public List<Long> getRepoEntryKeys() { return repoEntryKeys; } @@ -90,20 +98,6 @@ public class SearchAuthorRepositoryEntryViewParams { public void setOrderBy(OrderBy orderBy) { this.orderBy = orderBy; } - - public List<Filter> getFilters() { - return filters; - } - - public void setFilters(List<Filter> filters) { - this.filters = filters; - } - - public boolean isLifecycleFilterDefined() { - return filters != null && (filters.contains(Filter.upcomingCourses) - || filters.contains(Filter.currentCourses) - || filters.contains(Filter.oldCourses)); - } public boolean isResourceTypesDefined() { return resourceTypes != null && resourceTypes.size() > 0; diff --git a/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorViewQueries.java b/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorViewQueries.java index c5e64ca8fda07612289482f9b467d75f631c5520..bae19c59271b229637dfc62cd662180d68ed3f9f 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorViewQueries.java +++ b/src/main/java/org/olat/repository/manager/RepositoryEntryAuthorViewQueries.java @@ -20,13 +20,15 @@ package org.olat.repository.manager; import java.util.Collections; -import java.util.Date; import java.util.List; import javax.persistence.TypedQuery; +import org.olat.basesecurity.GroupRoles; +import org.olat.basesecurity.IdentityImpl; 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; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; @@ -34,6 +36,7 @@ import org.olat.core.util.StringHelper; import org.olat.repository.RepositoryEntryAuthorView; import org.olat.repository.RepositoryEntryRef; import org.olat.repository.SearchAuthorRepositoryEntryViewParams; +import org.olat.user.UserImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -123,6 +126,42 @@ public class RepositoryEntryAuthorViewQueries { if(params.getMarked() != null) { sb.append(" and v.markKey ").append(params.getMarked().booleanValue() ? " is not null " : " is null "); } + + String author = params.getAuthor(); + if (StringHelper.containsNonWhitespace(author)) { // fuzzy author search + author = PersistenceHelper.makeFuzzyQueryString(author); + + sb.append(" and exists (select rel from repoentrytogroup as rel, bgroup as baseGroup, bgroupmember as membership, ") + .append(IdentityImpl.class.getName()).append(" as identity, ").append(UserImpl.class.getName()).append(" as user") + .append(" where rel.entry=v and rel.group=baseGroup and membership.group=baseGroup and membership.identity=identity and identity.user=user") + .append(" and membership.role='").append(GroupRoles.owner.name()).append("'") + .append(" and ("); + PersistenceHelper.appendFuzzyLike(sb, "user.userProperties['firstName']", "author", dbInstance.getDbVendor()); + sb.append(" or "); + PersistenceHelper.appendFuzzyLike(sb, "user.userProperties['lastName']", "author", dbInstance.getDbVendor()); + sb.append(" or "); + PersistenceHelper.appendFuzzyLike(sb, "identity.name", "author", dbInstance.getDbVendor()); + sb.append(" ))"); + } + + String displayname = params.getDisplayname(); + if (StringHelper.containsNonWhitespace(displayname)) { + //displayName = '%' + displayName.replace('*', '%') + '%'; + //query.append(" and v.displayname like :displayname"); + displayname = PersistenceHelper.makeFuzzyQueryString(displayname); + sb.append(" and "); + PersistenceHelper.appendFuzzyLike(sb, "v.displayname", "displayname", dbInstance.getDbVendor()); + } + + String desc = params.getDescription(); + if (StringHelper.containsNonWhitespace(desc)) { + //desc = '%' + desc.replace('*', '%') + '%'; + //query.append(" and v.description like :desc"); + desc = PersistenceHelper.makeFuzzyQueryString(desc); + sb.append(" and "); + PersistenceHelper.appendFuzzyLike(sb, "v.description", "desc", dbInstance.getDbVendor()); + } + Long id = null; String refs = null; if(StringHelper.containsNonWhitespace(params.getIdAndRefs())) { @@ -149,15 +188,22 @@ public class RepositoryEntryAuthorViewQueries { if (params.isResourceTypesDefined()) { dbQuery.setParameter("resourcetypes", resourceTypes); } - if(params.isLifecycleFilterDefined()) { - dbQuery.setParameter("now", new Date()); - } if(id != null) { dbQuery.setParameter("vKey", id); } if(refs != null) { dbQuery.setParameter("ref", refs); } + if (StringHelper.containsNonWhitespace(author)) { // fuzzy author search + dbQuery.setParameter("author", author); + } + if (StringHelper.containsNonWhitespace(displayname)) { + dbQuery.setParameter("displayname", displayname); + } + if (StringHelper.containsNonWhitespace(desc)) { + dbQuery.setParameter("desc", desc); + } + dbQuery.setParameter("identityKey", identity.getKey()); return dbQuery; } diff --git a/src/main/java/org/olat/repository/ui/author/AuthorListController.java b/src/main/java/org/olat/repository/ui/author/AuthorListController.java index effafb3dccbf38263e6c272d29cc0c24a8915cb0..5e97133341752c554cc353d34e80928c1355e476 100644 --- a/src/main/java/org/olat/repository/ui/author/AuthorListController.java +++ b/src/main/java/org/olat/repository/ui/author/AuthorListController.java @@ -64,6 +64,7 @@ import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.ContextEntry; import org.olat.core.id.context.StateEntry; import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; +import org.olat.core.util.StringHelper; import org.olat.core.util.Util; import org.olat.core.util.resource.OresHelper; import org.olat.repository.RepositoryEntry; @@ -428,7 +429,7 @@ public class AuthorListController extends FormBasicController implements Activat } private void doSearch(SearchEvent se) { - if(se.getType() != null) { + if(StringHelper.containsNonWhitespace(se.getType())) { searchParams.setResourceTypes(Collections.singletonList(se.getType())); } else { searchParams.setResourceTypes(null); @@ -437,6 +438,7 @@ public class AuthorListController extends FormBasicController implements Activat searchParams.setIdAndRefs(se.getId()); searchParams.setAuthor(se.getAuthor()); searchParams.setDisplayname(se.getDisplayname()); + searchParams.setDescription(se.getDescription()); tableEl.reset(); } diff --git a/src/main/java/org/olat/repository/ui/author/AuthorSearchController.java b/src/main/java/org/olat/repository/ui/author/AuthorSearchController.java index 0093e139ac92ea473c9dc1604cd5770f13db1356..d30e9cd7c44b036d1b0e447aa9376fcfce7babd0 100644 --- a/src/main/java/org/olat/repository/ui/author/AuthorSearchController.java +++ b/src/main/java/org/olat/repository/ui/author/AuthorSearchController.java @@ -196,6 +196,7 @@ public class AuthorSearchController extends FormBasicController implements Exten e.setId(getId()); e.setAuthor(getAuthor()); e.setDisplayname(getDisplayName()); + e.setDescription(getDescription()); e.setType(getRestrictedType()); fireEvent(ureq, e); } diff --git a/src/main/java/org/olat/repository/ui/author/AuthoringEntryDataSource.java b/src/main/java/org/olat/repository/ui/author/AuthoringEntryDataSource.java index dec3e275337da9ba9dd228a5b94329630b56f390..e5ebabeb6f3abc6fc23e8174179b5dbebcf54697 100644 --- a/src/main/java/org/olat/repository/ui/author/AuthoringEntryDataSource.java +++ b/src/main/java/org/olat/repository/ui/author/AuthoringEntryDataSource.java @@ -21,7 +21,10 @@ package org.olat.repository.ui.author; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import org.apache.lucene.queryparser.classic.ParseException; import org.olat.core.CoreSpringFactory; @@ -45,6 +48,7 @@ import org.olat.search.QueryException; import org.olat.search.ServiceNotAvailableException; import org.olat.search.service.searcher.SearchClient; import org.olat.search.service.searcher.SearchClientLocal; +import org.olat.user.UserManager; /** * @@ -58,8 +62,8 @@ public class AuthoringEntryDataSource implements FlexiTableDataSourceDelegate<Au private final SearchAuthorRepositoryEntryViewParams searchParams; - private final ACService acService; + private final UserManager userManager; private final SearchClient searchClient; private final RepositoryService repositoryService; private final AuthoringEntryDataSourceUIFactory uifactory; @@ -72,6 +76,7 @@ public class AuthoringEntryDataSource implements FlexiTableDataSourceDelegate<Au this.uifactory = uifactory; acService = CoreSpringFactory.getImpl(ACService.class); + userManager = CoreSpringFactory.getImpl(UserManager.class); searchClient = CoreSpringFactory.getImpl(SearchClientLocal.class); repositoryService = CoreSpringFactory.getImpl(RepositoryService.class); } @@ -125,17 +130,27 @@ public class AuthoringEntryDataSource implements FlexiTableDataSourceDelegate<Au } private List<AuthoringEntryRow> processViewModel(List<RepositoryEntryAuthorView> repoEntries) { + Set<String> newNames = new HashSet<String>(); List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size()); for(RepositoryEntryAuthorView entry:repoEntries) { if(entry.isValidOfferAvailable()) { resourcesWithAC.add(entry.getOlatResource()); } + final String author = entry.getAuthor(); + if(StringHelper.containsNonWhitespace(author)) { + newNames.add(author); + } } - List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC); + Map<String,String> fullNames = userManager.getUserDisplayNamesByUserName(newNames); + List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC); + List<AuthoringEntryRow> items = new ArrayList<AuthoringEntryRow>(); for(RepositoryEntryAuthorView entry:repoEntries) { - String fullname = ""; + String fullname = fullNames.get(entry.getAuthor()); + if(fullname == null) { + fullname = entry.getAuthor(); + } AuthoringEntryRow row = new AuthoringEntryRow(entry, fullname); //bookmark row.setMarked(entry.isMarked()); diff --git a/src/main/java/org/olat/repository/ui/author/SearchEvent.java b/src/main/java/org/olat/repository/ui/author/SearchEvent.java index 0bdfa78a2e5943b718b1703da163675aeacfaeec..aad7915587a524117347a9ca8009afcf739d6ad5 100644 --- a/src/main/java/org/olat/repository/ui/author/SearchEvent.java +++ b/src/main/java/org/olat/repository/ui/author/SearchEvent.java @@ -35,6 +35,7 @@ public class SearchEvent extends Event implements StateEntry { private String id; private String displayname; private String author; + private String description; private String type; public SearchEvent() { @@ -66,6 +67,15 @@ public class SearchEvent extends Event implements StateEntry { this.author = author; } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { return type; }