Search in sources :

Example 1 with PriceMethodBundle

use of org.olat.resource.accesscontrol.model.PriceMethodBundle 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 2 with PriceMethodBundle

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

the class RepositoryEntryACColumnDescriptor method render.

@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
    if (val instanceof Collection) {
        Collection<?> accessTypes = (Collection<?>) val;
        for (Object accessType : accessTypes) {
            if (accessType instanceof String) {
                String type = (String) accessType;
                sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
            }
        }
    } else if (val instanceof Boolean) {
        boolean acessControlled = ((Boolean) val).booleanValue();
        if (acessControlled) {
            sb.append("<i class='o_icon o_ac_group_icon o_icon-lg'></i>");
        }
    } else if (val instanceof OLATResourceAccess) {
        OLATResourceAccess access = (OLATResourceAccess) val;
        for (PriceMethodBundle bundle : access.getMethods()) {
            Price price = bundle.getPrice();
            String type = bundle.getMethod().getMethodCssClass();
            if (price == null || price.isEmpty()) {
                sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
            } else {
                String p = PriceFormat.fullFormat(price);
                sb.append("<span class='o_nowrap'><i class='o_icon ").append(type).append("_icon o_icon-lg'></i> ").append(p).append("</span>");
            }
        }
    }
}
Also used : Price(org.olat.resource.accesscontrol.Price) Collection(java.util.Collection) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 3 with PriceMethodBundle

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

the class BusinessGroupDAO method loadOfferAccess.

public void loadOfferAccess(Map<Long, ? extends BusinessGroupRow> resourceKeyToGroup) {
    if (resourceKeyToGroup.isEmpty())
        return;
    final int OFFERS_IN_LIMIT = 255;
    // offers
    StringBuilder so = new StringBuilder();
    so.append("select access.method, resource.key, offer.price from acofferaccess access ").append(" inner join access.offer offer").append(" inner join offer.resource resource");
    if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
        so.append(" where resource.key in (:resourceKeys)");
    } else {
        so.append(" where exists (select bgi.key from businessgroup bgi where bgi.resource=resource)");
    }
    TypedQuery<Object[]> offersQuery = dbInstance.getCurrentEntityManager().createQuery(so.toString(), Object[].class);
    if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
        List<Long> resourceKeys = new ArrayList<>(resourceKeyToGroup.size());
        for (Long resourceKey : resourceKeyToGroup.keySet()) {
            resourceKeys.add(resourceKey);
        }
        offersQuery.setParameter("resourceKeys", resourceKeys);
    }
    List<Object[]> offers = offersQuery.getResultList();
    for (Object[] offer : offers) {
        Long resourceKey = (Long) offer[1];
        BusinessGroupRow row = resourceKeyToGroup.get(resourceKey);
        if (row != null) {
            AccessMethod method = (AccessMethod) offer[0];
            Price price = (Price) offer[2];
            if (row.getBundles() == null) {
                row.setBundles(new ArrayList<>(3));
            }
            row.getBundles().add(new PriceMethodBundle(price, method));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Price(org.olat.resource.accesscontrol.Price) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 4 with PriceMethodBundle

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

the class RepositoryEntryACColumnDescriptor method render.

@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
    if (val instanceof Collection) {
        Collection<?> accessTypes = (Collection<?>) val;
        for (Object accessType : accessTypes) {
            if (accessType instanceof String) {
                String type = (String) accessType;
                sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
            }
        }
    } else if (val instanceof Boolean) {
        boolean acessControlled = ((Boolean) val).booleanValue();
        if (acessControlled) {
            sb.append("<i class='o_icon o_ac_group_icon o_icon-lg'></i>");
        }
    } else if (val instanceof OLATResourceAccess) {
        OLATResourceAccess access = (OLATResourceAccess) val;
        for (PriceMethodBundle bundle : access.getMethods()) {
            Price price = bundle.getPrice();
            String type = bundle.getMethod().getMethodCssClass();
            if (price == null || price.isEmpty()) {
                sb.append("<i class='o_icon ").append(type).append("_icon o_icon-lg'></i>");
            } else {
                String p = PriceFormat.fullFormat(price);
                sb.append("<span class='o_nowrap'><i class='o_icon ").append(type).append("_icon o_icon-lg'></i> ").append(p).append("</span>");
            }
        }
    }
}
Also used : Price(org.olat.resource.accesscontrol.Price) Collection(java.util.Collection) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 5 with PriceMethodBundle

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

the class BusinessGroupDAO method loadOfferAccess.

public void loadOfferAccess(Map<Long, ? extends BusinessGroupRow> resourceKeyToGroup) {
    if (resourceKeyToGroup.isEmpty())
        return;
    final int OFFERS_IN_LIMIT = 255;
    // offers
    StringBuilder so = new StringBuilder();
    so.append("select access.method, resource.key, offer.price from acofferaccess access ").append(" inner join access.offer offer").append(" inner join offer.resource resource");
    if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
        so.append(" where resource.key in (:resourceKeys)");
    } else {
        so.append(" where exists (select bgi.key from businessgroup bgi where bgi.resource=resource)");
    }
    TypedQuery<Object[]> offersQuery = dbInstance.getCurrentEntityManager().createQuery(so.toString(), Object[].class);
    if (resourceKeyToGroup.size() < OFFERS_IN_LIMIT) {
        List<Long> resourceKeys = new ArrayList<>(resourceKeyToGroup.size());
        for (Long resourceKey : resourceKeyToGroup.keySet()) {
            resourceKeys.add(resourceKey);
        }
        offersQuery.setParameter("resourceKeys", resourceKeys);
    }
    List<Object[]> offers = offersQuery.getResultList();
    for (Object[] offer : offers) {
        Long resourceKey = (Long) offer[1];
        BusinessGroupRow row = resourceKeyToGroup.get(resourceKey);
        if (row != null) {
            AccessMethod method = (AccessMethod) offer[0];
            Price price = (Price) offer[2];
            if (row.getBundles() == null) {
                row.setBundles(new ArrayList<>(3));
            }
            row.getBundles().add(new PriceMethodBundle(price, method));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Price(org.olat.resource.accesscontrol.Price) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

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