Search in sources :

Example 1 with RepositoryEntryAuthorView

use of org.olat.repository.RepositoryEntryAuthorView in project OpenOLAT by OpenOLAT.

the class RepositoryEntryAuthorQueriesTest method searchViews.

@Test
public void searchViews() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("view-");
    dbInstance.commit();
    Roles roles = securityManager.getRoles(id);
    SearchAuthorRepositoryEntryViewParams params = new SearchAuthorRepositoryEntryViewParams(id, roles);
    params.setMarked(Boolean.TRUE);
    List<RepositoryEntryAuthorView> views = repositoryEntryAuthorViewQueries.searchViews(params, 0, 10);
    Assert.assertNotNull(views);
}
Also used : RepositoryEntryAuthorView(org.olat.repository.RepositoryEntryAuthorView) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) SearchAuthorRepositoryEntryViewParams(org.olat.repository.model.SearchAuthorRepositoryEntryViewParams) Test(org.junit.Test)

Example 2 with RepositoryEntryAuthorView

use of org.olat.repository.RepositoryEntryAuthorView in project OpenOLAT by OpenOLAT.

the class RepositoryEntryAuthorQueriesTest method searchViews_orderBy.

@Test
public void searchViews_orderBy() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("view-");
    dbInstance.commit();
    Roles roles = securityManager.getRoles(id);
    SearchAuthorRepositoryEntryViewParams params = new SearchAuthorRepositoryEntryViewParams(id, roles);
    params.setMarked(Boolean.TRUE);
    for (OrderBy orderBy : OrderBy.values()) {
        params.setOrderBy(orderBy);
        params.setOrderByAsc(true);
        List<RepositoryEntryAuthorView> viewAsc = repositoryEntryAuthorViewQueries.searchViews(params, 0, 10);
        Assert.assertNotNull(viewAsc);
        params.setOrderByAsc(false);
        List<RepositoryEntryAuthorView> viewDesc = repositoryEntryAuthorViewQueries.searchViews(params, 0, 10);
        Assert.assertNotNull(viewDesc);
    }
}
Also used : OrderBy(org.olat.repository.model.SearchAuthorRepositoryEntryViewParams.OrderBy) RepositoryEntryAuthorView(org.olat.repository.RepositoryEntryAuthorView) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) SearchAuthorRepositoryEntryViewParams(org.olat.repository.model.SearchAuthorRepositoryEntryViewParams) Test(org.junit.Test)

Example 3 with RepositoryEntryAuthorView

use of org.olat.repository.RepositoryEntryAuthorView in project OpenOLAT by OpenOLAT.

the class AuthoringEntryDataSource method getRows.

@Override
public final ResultInfos<AuthoringEntryRow> getRows(String query, List<FlexiTableFilter> filters, List<String> condQueries, int firstResult, int maxResults, SortKey... orderBy) {
    if (filters != null && filters.size() > 0) {
        String filter = filters.get(0).getFilter();
        if (StringHelper.containsNonWhitespace(filter)) {
            searchParams.setResourceTypes(Collections.singletonList(filter));
        } else {
            searchParams.setResourceTypes(null);
        }
    } else if (useFilters) {
        searchParams.setResourceTypes(null);
    }
    if (orderBy != null && orderBy.length > 0 && orderBy[0] != null) {
        OrderBy o = OrderBy.valueOf(orderBy[0].getKey());
        searchParams.setOrderBy(o);
        searchParams.setOrderByAsc(orderBy[0].isAsc());
    }
    if (StringHelper.containsNonWhitespace(query)) {
        searchParams.setIdRefsAndTitle(query);
    } else {
        searchParams.setIdRefsAndTitle(null);
    }
    List<RepositoryEntryAuthorView> views = repositoryService.searchAuthorView(searchParams, firstResult, maxResults);
    List<AuthoringEntryRow> rows = processViewModel(views);
    ResultInfos<AuthoringEntryRow> results = new DefaultResultInfos<>(firstResult + rows.size(), -1, rows);
    if (firstResult == 0 && views.size() < maxResults) {
        count = new Integer(views.size());
    }
    return results;
}
Also used : OrderBy(org.olat.repository.model.SearchAuthorRepositoryEntryViewParams.OrderBy) DefaultResultInfos(org.olat.core.commons.persistence.DefaultResultInfos) RepositoryEntryAuthorView(org.olat.repository.RepositoryEntryAuthorView)

Example 4 with RepositoryEntryAuthorView

use of org.olat.repository.RepositoryEntryAuthorView in project OpenOLAT by OpenOLAT.

the class AuthoringEntryDataSource method processViewModel.

private List<AuthoringEntryRow> processViewModel(List<RepositoryEntryAuthorView> repoEntries) {
    Set<String> newNames = new HashSet<>();
    List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
    for (RepositoryEntryAuthorView entry : repoEntries) {
        if (entry.isOfferAvailable()) {
            resourcesWithAC.add(entry.getOlatResource());
        }
        final String author = entry.getAuthor();
        if (StringHelper.containsNonWhitespace(author)) {
            newNames.add(author);
        }
    }
    Map<String, String> fullNames = userManager.getUserDisplayNamesByUserName(newNames);
    List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
    Collection<OLATResourceable> resources = repoEntries.stream().map(RepositoryEntryAuthorView::getOlatResource).collect(Collectors.toList());
    List<ResourceLicense> licenses = licenseService.loadLicenses(resources);
    List<AuthoringEntryRow> items = new ArrayList<>();
    for (RepositoryEntryAuthorView entry : repoEntries) {
        String fullname = fullNames.get(entry.getAuthor());
        if (fullname == null) {
            fullname = entry.getAuthor();
        }
        AuthoringEntryRow row = new AuthoringEntryRow(entry, fullname);
        // bookmark
        row.setMarked(entry.isMarked());
        // access control
        List<PriceMethod> types = new ArrayList<>();
        if (entry.isMembersOnly()) {
            // members only always show lock icon
            types.add(new PriceMethod("", "o_ac_membersonly_icon", uifactory.getTranslator().translate("cif.access.membersonly.short")));
        } else {
            // collect access control method icons
            OLATResource resource = entry.getOlatResource();
            for (OLATResourceAccess resourceAccess : resourcesWithOffer) {
                if (resource.getKey().equals(resourceAccess.getResource().getKey())) {
                    for (PriceMethodBundle bundle : resourceAccess.getMethods()) {
                        String type = (bundle.getMethod().getMethodCssClass() + "_icon").intern();
                        String price = bundle.getPrice() == null || bundle.getPrice().isEmpty() ? "" : PriceFormat.fullFormat(bundle.getPrice());
                        AccessMethodHandler amh = acModule.getAccessMethodHandler(bundle.getMethod().getType());
                        String displayName = amh.getMethodName(uifactory.getTranslator().getLocale());
                        types.add(new PriceMethod(price, type, displayName));
                    }
                }
            }
        }
        if (!types.isEmpty()) {
            row.setAccessTypes(types);
        }
        // license
        for (ResourceLicense license : licenses) {
            OLATResource resource = entry.getOlatResource();
            if (license.getResId().equals(resource.getResourceableId()) && license.getResName().equals(resource.getResourceableTypeName())) {
                row.setLicense(license);
            }
        }
        uifactory.forgeLinks(row);
        items.add(row);
    }
    return items;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) PriceMethod(org.olat.repository.ui.PriceMethod) RepositoryEntryAuthorView(org.olat.repository.RepositoryEntryAuthorView) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle) HashSet(java.util.HashSet)

Example 5 with RepositoryEntryAuthorView

use of org.olat.repository.RepositoryEntryAuthorView in project OpenOLAT by OpenOLAT.

the class RepositoryEntryAuthorQueries method searchViews.

public List<RepositoryEntryAuthorView> searchViews(SearchAuthorRepositoryEntryViewParams params, int firstResult, int maxResults) {
    if (params.getIdentity() == null) {
        log.error("No identity defined for query");
        return Collections.emptyList();
    }
    TypedQuery<Object[]> query = createViewQuery(params, Object[].class);
    query.setFirstResult(firstResult);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    List<Object[]> objects = query.getResultList();
    List<RepositoryEntryAuthorView> views = new ArrayList<>(objects.size());
    for (Object[] object : objects) {
        RepositoryEntry re = (RepositoryEntry) object[0];
        Number numOfMarks = (Number) object[1];
        boolean hasMarks = numOfMarks == null ? false : numOfMarks.longValue() > 0;
        Number numOffers = (Number) object[2];
        long offers = numOffers == null ? 0l : numOffers.longValue();
        Number numOfReferences = (Number) object[3];
        int references = numOfReferences == null ? 0 : numOfReferences.intValue();
        String deletedByName = null;
        if (params.isDeleted()) {
            Identity deletedBy = re.getDeletedBy();
            if (deletedBy != null) {
                deletedByName = userManager.getUserDisplayName(deletedBy);
            }
        }
        views.add(new RepositoryEntryAuthorImpl(re, hasMarks, offers, references, deletedByName));
    }
    return views;
}
Also used : ArrayList(java.util.ArrayList) RepositoryEntryAuthorImpl(org.olat.repository.model.RepositoryEntryAuthorImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryAuthorView(org.olat.repository.RepositoryEntryAuthorView) Identity(org.olat.core.id.Identity)

Aggregations

RepositoryEntryAuthorView (org.olat.repository.RepositoryEntryAuthorView)10 Identity (org.olat.core.id.Identity)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Roles (org.olat.core.id.Roles)4 SearchAuthorRepositoryEntryViewParams (org.olat.repository.model.SearchAuthorRepositoryEntryViewParams)4 OrderBy (org.olat.repository.model.SearchAuthorRepositoryEntryViewParams.OrderBy)4 HashSet (java.util.HashSet)2 DefaultResultInfos (org.olat.core.commons.persistence.DefaultResultInfos)2 ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryEntryAuthorImpl (org.olat.repository.model.RepositoryEntryAuthorImpl)2 PriceMethod (org.olat.repository.ui.PriceMethod)2 OLATResource (org.olat.resource.OLATResource)2 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)2 OLATResourceAccess (org.olat.resource.accesscontrol.model.OLATResourceAccess)2 PriceMethodBundle (org.olat.resource.accesscontrol.model.PriceMethodBundle)2