Search in sources :

Example 6 with PriceMethodBundle

use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project OpenOLAT by OpenOLAT.

the class CatalogNodeManagerController method loadResources.

private void loadResources(UserRequest ureq) {
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(getIdentity(), ureq.getUserSession().getRoles());
    params.setParentEntry(catalogEntry);
    List<RepositoryEntry> repoEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, false);
    List<Long> resourceKeys = new ArrayList<>();
    for (RepositoryEntry entry : repoEntries) {
        resourceKeys.add(entry.getOlatResource().getKey());
    }
    List<OLATResourceAccess> resourcesWithOffer = acService.getAccessMethodForResources(resourceKeys, null, true, new Date());
    List<CatalogEntryRow> items = new ArrayList<>();
    List<CatalogEntryRow> closedItems = new ArrayList<>();
    for (RepositoryEntry entry : repoEntries) {
        CatalogEntryRow row = new CatalogEntryRow(entry);
        List<PriceMethod> types = new ArrayList<PriceMethod>();
        if (entry.isMembersOnly()) {
            // members only always show lock icon
            types.add(new PriceMethod("", "o_ac_membersonly_icon", 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(getLocale());
                        types.add(new PriceMethod(price, type, displayName));
                    }
                }
            }
        }
        if (!types.isEmpty()) {
            row.setAccessTypes(types);
        }
        if (entry.getRepositoryEntryStatus().isClosed()) {
            closedItems.add(row);
        } else {
            items.add(row);
        }
    }
    entriesModel.setObjects(items);
    entriesEl.reset();
    entriesEl.setVisible(entriesModel.getRowCount() > 0);
    closedEntriesModel.setObjects(closedItems);
    closedEntriesEl.reset();
    closedEntriesEl.setVisible(closedEntriesModel.getRowCount() > 0);
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) Date(java.util.Date) PriceMethod(org.olat.repository.ui.PriceMethod) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 7 with PriceMethodBundle

use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project OpenOLAT by OpenOLAT.

the class DefaultRepositoryEntryDataSource method processViewModel.

private List<RepositoryEntryRow> processViewModel(List<RepositoryEntryMyView> repoEntries) {
    List<Long> repoKeys = new ArrayList<>(repoEntries.size());
    List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
    for (RepositoryEntryMyView entry : repoEntries) {
        repoKeys.add(entry.getKey());
        if (entry.isValidOfferAvailable()) {
            resourcesWithAC.add(entry.getOlatResource());
        }
    }
    List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
    repositoryService.filterMembership(searchParams.getIdentity(), repoKeys);
    List<RepositoryEntryRow> items = new ArrayList<RepositoryEntryRow>();
    for (RepositoryEntryMyView entry : repoEntries) {
        RepositoryEntryRow row = new RepositoryEntryRow(entry);
        VFSLeaf image = repositoryManager.getImage(entry);
        if (image != null) {
            row.setThumbnailRelPath(uifactory.getMapperThumbnailUrl() + "/" + image.getName());
        }
        List<PriceMethod> types = new ArrayList<PriceMethod>();
        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));
                    }
                }
            }
        }
        row.setMember(repoKeys.contains(entry.getKey()));
        if (!types.isEmpty()) {
            row.setAccessTypes(types);
        }
        uifactory.forgeMarkLink(row);
        uifactory.forgeSelectLink(row);
        uifactory.forgeStartLink(row);
        uifactory.forgeDetails(row);
        uifactory.forgeRatings(row);
        uifactory.forgeComments(row);
        items.add(row);
    }
    return items;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) RepositoryEntryMyView(org.olat.repository.RepositoryEntryMyView) OLATResource(org.olat.resource.OLATResource) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) PriceMethod(org.olat.repository.ui.PriceMethod) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 8 with PriceMethodBundle

use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project openolat by klemens.

the class DefaultRepositoryEntryDataSource method processViewModel.

private List<RepositoryEntryRow> processViewModel(List<RepositoryEntryMyView> repoEntries) {
    List<Long> repoKeys = new ArrayList<>(repoEntries.size());
    List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
    for (RepositoryEntryMyView entry : repoEntries) {
        repoKeys.add(entry.getKey());
        if (entry.isValidOfferAvailable()) {
            resourcesWithAC.add(entry.getOlatResource());
        }
    }
    List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
    repositoryService.filterMembership(searchParams.getIdentity(), repoKeys);
    List<RepositoryEntryRow> items = new ArrayList<RepositoryEntryRow>();
    for (RepositoryEntryMyView entry : repoEntries) {
        RepositoryEntryRow row = new RepositoryEntryRow(entry);
        VFSLeaf image = repositoryManager.getImage(entry);
        if (image != null) {
            row.setThumbnailRelPath(uifactory.getMapperThumbnailUrl() + "/" + image.getName());
        }
        List<PriceMethod> types = new ArrayList<PriceMethod>();
        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));
                    }
                }
            }
        }
        row.setMember(repoKeys.contains(entry.getKey()));
        if (!types.isEmpty()) {
            row.setAccessTypes(types);
        }
        uifactory.forgeMarkLink(row);
        uifactory.forgeSelectLink(row);
        uifactory.forgeStartLink(row);
        uifactory.forgeDetails(row);
        uifactory.forgeRatings(row);
        uifactory.forgeComments(row);
        items.add(row);
    }
    return items;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) RepositoryEntryMyView(org.olat.repository.RepositoryEntryMyView) OLATResource(org.olat.resource.OLATResource) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) PriceMethod(org.olat.repository.ui.PriceMethod) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 9 with PriceMethodBundle

use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project openolat by klemens.

the class CatalogNodeManagerController method loadResources.

private void loadResources(UserRequest ureq) {
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(getIdentity(), ureq.getUserSession().getRoles());
    params.setParentEntry(catalogEntry);
    List<RepositoryEntry> repoEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, false);
    List<Long> resourceKeys = new ArrayList<>();
    for (RepositoryEntry entry : repoEntries) {
        resourceKeys.add(entry.getOlatResource().getKey());
    }
    List<OLATResourceAccess> resourcesWithOffer = acService.getAccessMethodForResources(resourceKeys, null, true, new Date());
    List<CatalogEntryRow> items = new ArrayList<>();
    List<CatalogEntryRow> closedItems = new ArrayList<>();
    for (RepositoryEntry entry : repoEntries) {
        CatalogEntryRow row = new CatalogEntryRow(entry);
        List<PriceMethod> types = new ArrayList<PriceMethod>();
        if (entry.isMembersOnly()) {
            // members only always show lock icon
            types.add(new PriceMethod("", "o_ac_membersonly_icon", 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(getLocale());
                        types.add(new PriceMethod(price, type, displayName));
                    }
                }
            }
        }
        if (!types.isEmpty()) {
            row.setAccessTypes(types);
        }
        if (entry.getRepositoryEntryStatus().isClosed()) {
            closedItems.add(row);
        } else {
            items.add(row);
        }
    }
    entriesModel.setObjects(items);
    entriesEl.reset();
    entriesEl.setVisible(entriesModel.getRowCount() > 0);
    closedEntriesModel.setObjects(closedItems);
    closedEntriesEl.reset();
    closedEntriesEl.setVisible(closedEntriesModel.getRowCount() > 0);
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) Date(java.util.Date) PriceMethod(org.olat.repository.ui.PriceMethod) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 10 with PriceMethodBundle

use of org.olat.resource.accesscontrol.model.PriceMethodBundle in project openolat by klemens.

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)

Aggregations

PriceMethodBundle (org.olat.resource.accesscontrol.model.PriceMethodBundle)10 ArrayList (java.util.ArrayList)8 OLATResourceAccess (org.olat.resource.accesscontrol.model.OLATResourceAccess)8 PriceMethod (org.olat.repository.ui.PriceMethod)6 OLATResource (org.olat.resource.OLATResource)6 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)6 Price (org.olat.resource.accesscontrol.Price)4 Collection (java.util.Collection)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)2 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)2 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryEntryAuthorView (org.olat.repository.RepositoryEntryAuthorView)2 RepositoryEntryMyView (org.olat.repository.RepositoryEntryMyView)2 SearchRepositoryEntryParameters (org.olat.repository.model.SearchRepositoryEntryParameters)2