Search in sources :

Example 1 with AssessedPage

use of org.olat.modules.portfolio.model.AssessedPage in project OpenOLAT by OpenOLAT.

the class SharedWithMeQueries method searchSharedPagesEntries.

public List<AssessedPage> searchSharedPagesEntries(Identity member, SearchSharePagesParameters params) {
    StringBuilder sb = new StringBuilder(2048);
    sb.append("select binder.key,").append("  section.key, section.endDate,").append("  page.key, page.title, page.status, page.lastModified,").append("  body.lastModified,").append("  (select max(part.lastModified) from pfpagepart as part").append("   where part.body.key=body.key").append("  ) as partLastModified,").append("  uinfos.userStatus, uinfos.mark,").append("  owner").append(" from pfbinder as binder").append(" inner join binder.baseGroup as baseGroup").append(" inner join baseGroup.members as ownership on (ownership.role='").append(PortfolioRoles.owner.name()).append("')").append(" inner join ownership.identity as owner").append(" inner join fetch owner.user as owneruser").append(" inner join binder.sections as section").append(" inner join section.pages as page").append(" inner join page.body as body").append(params.isBookmarkOnly() ? " inner" : " left").append(" join pfpageuserinfos as uinfos on (uinfos.page.key=page.key and uinfos.identity.key=:identityKey)").append(" where ");
    if (params.isBookmarkOnly()) {
        sb.append(" uinfos.mark=true and");
    }
    String searchString = params.getSearchString();
    if (StringHelper.containsNonWhitespace(searchString)) {
        searchString = makeFuzzyQueryString(searchString);
        sb.append(" (");
        appendFuzzyLike(sb, "page.title", "searchString", dbInstance.getDbVendor());
        sb.append(") and");
    }
    if (params.getExcludedPageStatus() != null && !params.getExcludedPageStatus().isEmpty()) {
        sb.append(" (page.status is null or page.status not in (:excludedPageStatus)) and");
    }
    if (params.getExcludedPageUserStatus() != null && !params.getExcludedPageUserStatus().isEmpty()) {
        sb.append(" (uinfos.userStatus is null or uinfos.userStatus not in (:excludedPageUserStatus)) and");
    }
    sb.append(" (exists (select membership.key from bgroupmember as membership").append("   where membership.group.key=binder.baseGroup.key and membership.identity.key=:identityKey and membership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("')").append(" ) or exists (select sectionMembership.key from bgroupmember as sectionMembership").append("   where sectionMembership.group.key=section.baseGroup.key and sectionMembership.identity.key=:identityKey and sectionMembership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("')").append(" ) or exists (select page.key from pfpage as coachedPage").append("   inner join coachedPage.baseGroup as pageGroup").append("   inner join pageGroup.members as pageMembership on (pageMembership.identity.key=:identityKey and pageMembership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("'))").append("   where coachedPage.key=page.key").append(" ))");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", member.getKey());
    if (StringHelper.containsNonWhitespace(searchString)) {
        query.setParameter("searchString", searchString.toLowerCase());
    }
    if (params.getExcludedPageStatus() != null && !params.getExcludedPageStatus().isEmpty()) {
        List<String> excludedPageStatus = params.getExcludedPageStatus().stream().map(s -> s.name()).collect(Collectors.toList());
        query.setParameter("excludedPageStatus", excludedPageStatus);
    }
    if (params.getExcludedPageUserStatus() != null && !params.getExcludedPageUserStatus().isEmpty()) {
        List<String> excludedPageUserStatus = params.getExcludedPageUserStatus().stream().map(s -> s.name()).collect(Collectors.toList());
        query.setParameter("excludedPageUserStatus", excludedPageUserStatus);
    }
    List<Object[]> objects = query.getResultList();
    List<AssessedPage> items = new ArrayList<>(objects.size());
    for (Object[] object : objects) {
        int pos = 0;
        Long binderKey = (Long) object[pos++];
        // Section key
        pos++;
        Date sectionDate = (Date) object[pos++];
        Long pageKey = (Long) object[pos++];
        String pageTitle = (String) object[pos++];
        PageStatus pageStatus = PageStatus.valueOfOrNull((String) object[pos++]);
        Date pageLastModified = (Date) object[pos++];
        Date bodyLastModified = (Date) object[pos++];
        Date partLastModified = (Date) object[pos++];
        PageUserStatus userStatus = PageUserStatus.valueOfWithDefault((String) object[pos++]);
        Boolean mark = (Boolean) object[pos++];
        Identity owner = (Identity) object[pos++];
        Date lastModified = pageLastModified;
        if (lastModified == null || (lastModified != null && partLastModified != null && partLastModified.after(lastModified))) {
            lastModified = partLastModified;
        }
        if (lastModified == null || (lastModified != null && bodyLastModified != null && bodyLastModified.after(lastModified))) {
            lastModified = bodyLastModified;
        }
        items.add(new AssessedPage(binderKey, sectionDate, pageKey, pageTitle, pageStatus, lastModified, mark, userStatus, owner));
    }
    return items;
}
Also used : PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) SearchSharePagesParameters(org.olat.modules.portfolio.model.SearchSharePagesParameters) AssessedBinderSection(org.olat.modules.portfolio.model.AssessedBinderSection) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) Service(org.springframework.stereotype.Service) Map(java.util.Map) SectionStatus(org.olat.modules.portfolio.SectionStatus) StringHelper(org.olat.core.util.StringHelper) PersistenceHelper.appendFuzzyLike(org.olat.core.commons.persistence.PersistenceHelper.appendFuzzyLike) PageUserStatus(org.olat.modules.portfolio.PageUserStatus) Set(java.util.Set) BinderStatus(org.olat.modules.portfolio.BinderStatus) Collectors(java.util.stream.Collectors) List(java.util.List) DB(org.olat.core.commons.persistence.DB) Identity(org.olat.core.id.Identity) AssessedBinder(org.olat.modules.portfolio.model.AssessedBinder) PortfolioRoles(org.olat.modules.portfolio.PortfolioRoles) PageStatus(org.olat.modules.portfolio.PageStatus) PageStatus(org.olat.modules.portfolio.PageStatus) ArrayList(java.util.ArrayList) PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) Date(java.util.Date) PageUserStatus(org.olat.modules.portfolio.PageUserStatus) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) Identity(org.olat.core.id.Identity)

Example 2 with AssessedPage

use of org.olat.modules.portfolio.model.AssessedPage in project OpenOLAT by OpenOLAT.

the class SharedPagesController method loadModel.

private void loadModel(boolean resetPage, boolean resetInternal) {
    searchParams.setSearchString(tableEl.getQuickSearchString());
    List<AssessedPage> sharedItems = portfolioService.searchSharedPagesWith(getIdentity(), searchParams);
    List<SharedPageRow> rows = new ArrayList<>(sharedItems.size());
    for (AssessedPage sharedItem : sharedItems) {
        SharedPageRow row = new SharedPageRow(sharedItem.getOwner(), userPropertyHandlers, getLocale());
        row.setPageKey(sharedItem.getPageKey());
        row.setPageTitle(sharedItem.getPageTitle());
        row.setStatus(sharedItem.getPageStatus());
        row.setMark(sharedItem.isMarked());
        row.setUserStatus(sharedItem.getUserStatus());
        row.setLastChanges(sharedItem.getLastModified());
        FormLink markLink = uifactory.addFormLink("mark_" + (counter++), "mark", "", null, flc, Link.NONTRANSLATED);
        markLink.setIconLeftCSS(sharedItem.isMarked() ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
        markLink.setTitle(translate(sharedItem.isMarked() ? "details.bookmark.remove" : "details.bookmark"));
        markLink.setUserObject(row);
        row.setBookmarkLink(markLink);
        rows.add(row);
    }
    model.setObjects(rows);
    tableEl.reset(resetPage, resetInternal, true);
}
Also used : ArrayList(java.util.ArrayList) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 3 with AssessedPage

use of org.olat.modules.portfolio.model.AssessedPage in project openolat by klemens.

the class SharedPagesController method loadModel.

private void loadModel(boolean resetPage, boolean resetInternal) {
    searchParams.setSearchString(tableEl.getQuickSearchString());
    List<AssessedPage> sharedItems = portfolioService.searchSharedPagesWith(getIdentity(), searchParams);
    List<SharedPageRow> rows = new ArrayList<>(sharedItems.size());
    for (AssessedPage sharedItem : sharedItems) {
        SharedPageRow row = new SharedPageRow(sharedItem.getOwner(), userPropertyHandlers, getLocale());
        row.setPageKey(sharedItem.getPageKey());
        row.setPageTitle(sharedItem.getPageTitle());
        row.setStatus(sharedItem.getPageStatus());
        row.setMark(sharedItem.isMarked());
        row.setUserStatus(sharedItem.getUserStatus());
        row.setLastChanges(sharedItem.getLastModified());
        FormLink markLink = uifactory.addFormLink("mark_" + (counter++), "mark", "", null, flc, Link.NONTRANSLATED);
        markLink.setIconLeftCSS(sharedItem.isMarked() ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
        markLink.setTitle(translate(sharedItem.isMarked() ? "details.bookmark.remove" : "details.bookmark"));
        markLink.setUserObject(row);
        row.setBookmarkLink(markLink);
        rows.add(row);
    }
    model.setObjects(rows);
    tableEl.reset(resetPage, resetInternal, true);
}
Also used : ArrayList(java.util.ArrayList) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 4 with AssessedPage

use of org.olat.modules.portfolio.model.AssessedPage in project openolat by klemens.

the class SharedWithMeQueries method searchSharedPagesEntries.

public List<AssessedPage> searchSharedPagesEntries(Identity member, SearchSharePagesParameters params) {
    StringBuilder sb = new StringBuilder(2048);
    sb.append("select binder.key,").append("  section.key, section.endDate,").append("  page.key, page.title, page.status, page.lastModified,").append("  body.lastModified,").append("  (select max(part.lastModified) from pfpagepart as part").append("   where part.body.key=body.key").append("  ) as partLastModified,").append("  uinfos.userStatus, uinfos.mark,").append("  owner").append(" from pfbinder as binder").append(" inner join binder.baseGroup as baseGroup").append(" inner join baseGroup.members as ownership on (ownership.role='").append(PortfolioRoles.owner.name()).append("')").append(" inner join ownership.identity as owner").append(" inner join fetch owner.user as owneruser").append(" inner join binder.sections as section").append(" inner join section.pages as page").append(" inner join page.body as body").append(params.isBookmarkOnly() ? " inner" : " left").append(" join pfpageuserinfos as uinfos on (uinfos.page.key=page.key and uinfos.identity.key=:identityKey)").append(" where ");
    if (params.isBookmarkOnly()) {
        sb.append(" uinfos.mark=true and");
    }
    String searchString = params.getSearchString();
    if (StringHelper.containsNonWhitespace(searchString)) {
        searchString = makeFuzzyQueryString(searchString);
        sb.append(" (");
        appendFuzzyLike(sb, "page.title", "searchString", dbInstance.getDbVendor());
        sb.append(") and");
    }
    if (params.getExcludedPageStatus() != null && !params.getExcludedPageStatus().isEmpty()) {
        sb.append(" (page.status is null or page.status not in (:excludedPageStatus)) and");
    }
    if (params.getExcludedPageUserStatus() != null && !params.getExcludedPageUserStatus().isEmpty()) {
        sb.append(" (uinfos.userStatus is null or uinfos.userStatus not in (:excludedPageUserStatus)) and");
    }
    sb.append(" (exists (select membership.key from bgroupmember as membership").append("   where membership.group.key=binder.baseGroup.key and membership.identity.key=:identityKey and membership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("')").append(" ) or exists (select sectionMembership.key from bgroupmember as sectionMembership").append("   where sectionMembership.group.key=section.baseGroup.key and sectionMembership.identity.key=:identityKey and sectionMembership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("')").append(" ) or exists (select page.key from pfpage as coachedPage").append("   inner join coachedPage.baseGroup as pageGroup").append("   inner join pageGroup.members as pageMembership on (pageMembership.identity.key=:identityKey and pageMembership.role in ('").append(PortfolioRoles.coach.name()).append("','").append(PortfolioRoles.reviewer.name()).append("'))").append("   where coachedPage.key=page.key").append(" ))");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", member.getKey());
    if (StringHelper.containsNonWhitespace(searchString)) {
        query.setParameter("searchString", searchString.toLowerCase());
    }
    if (params.getExcludedPageStatus() != null && !params.getExcludedPageStatus().isEmpty()) {
        List<String> excludedPageStatus = params.getExcludedPageStatus().stream().map(s -> s.name()).collect(Collectors.toList());
        query.setParameter("excludedPageStatus", excludedPageStatus);
    }
    if (params.getExcludedPageUserStatus() != null && !params.getExcludedPageUserStatus().isEmpty()) {
        List<String> excludedPageUserStatus = params.getExcludedPageUserStatus().stream().map(s -> s.name()).collect(Collectors.toList());
        query.setParameter("excludedPageUserStatus", excludedPageUserStatus);
    }
    List<Object[]> objects = query.getResultList();
    List<AssessedPage> items = new ArrayList<>(objects.size());
    for (Object[] object : objects) {
        int pos = 0;
        Long binderKey = (Long) object[pos++];
        // Section key
        pos++;
        Date sectionDate = (Date) object[pos++];
        Long pageKey = (Long) object[pos++];
        String pageTitle = (String) object[pos++];
        PageStatus pageStatus = PageStatus.valueOfOrNull((String) object[pos++]);
        Date pageLastModified = (Date) object[pos++];
        Date bodyLastModified = (Date) object[pos++];
        Date partLastModified = (Date) object[pos++];
        PageUserStatus userStatus = PageUserStatus.valueOfWithDefault((String) object[pos++]);
        Boolean mark = (Boolean) object[pos++];
        Identity owner = (Identity) object[pos++];
        Date lastModified = pageLastModified;
        if (lastModified == null || (lastModified != null && partLastModified != null && partLastModified.after(lastModified))) {
            lastModified = partLastModified;
        }
        if (lastModified == null || (lastModified != null && bodyLastModified != null && bodyLastModified.after(lastModified))) {
            lastModified = bodyLastModified;
        }
        items.add(new AssessedPage(binderKey, sectionDate, pageKey, pageTitle, pageStatus, lastModified, mark, userStatus, owner));
    }
    return items;
}
Also used : PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) SearchSharePagesParameters(org.olat.modules.portfolio.model.SearchSharePagesParameters) AssessedBinderSection(org.olat.modules.portfolio.model.AssessedBinderSection) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) Service(org.springframework.stereotype.Service) Map(java.util.Map) SectionStatus(org.olat.modules.portfolio.SectionStatus) StringHelper(org.olat.core.util.StringHelper) PersistenceHelper.appendFuzzyLike(org.olat.core.commons.persistence.PersistenceHelper.appendFuzzyLike) PageUserStatus(org.olat.modules.portfolio.PageUserStatus) Set(java.util.Set) BinderStatus(org.olat.modules.portfolio.BinderStatus) Collectors(java.util.stream.Collectors) List(java.util.List) DB(org.olat.core.commons.persistence.DB) Identity(org.olat.core.id.Identity) AssessedBinder(org.olat.modules.portfolio.model.AssessedBinder) PortfolioRoles(org.olat.modules.portfolio.PortfolioRoles) PageStatus(org.olat.modules.portfolio.PageStatus) PageStatus(org.olat.modules.portfolio.PageStatus) ArrayList(java.util.ArrayList) PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) Date(java.util.Date) PageUserStatus(org.olat.modules.portfolio.PageUserStatus) AssessedPage(org.olat.modules.portfolio.model.AssessedPage) Identity(org.olat.core.id.Identity)

Aggregations

ArrayList (java.util.ArrayList)4 AssessedPage (org.olat.modules.portfolio.model.AssessedPage)4 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 TypedQuery (javax.persistence.TypedQuery)2 DB (org.olat.core.commons.persistence.DB)2 PersistenceHelper.appendFuzzyLike (org.olat.core.commons.persistence.PersistenceHelper.appendFuzzyLike)2 PersistenceHelper.makeFuzzyQueryString (org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 Identity (org.olat.core.id.Identity)2 StringHelper (org.olat.core.util.StringHelper)2 BinderStatus (org.olat.modules.portfolio.BinderStatus)2 PageStatus (org.olat.modules.portfolio.PageStatus)2 PageUserStatus (org.olat.modules.portfolio.PageUserStatus)2 PortfolioRoles (org.olat.modules.portfolio.PortfolioRoles)2