Search in sources :

Example 6 with AccessMethod

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

the class ACMethodManagerTest method testStandardMethods.

@Test
public void testStandardMethods() {
    List<AccessMethod> methods = acMethodManager.getAvailableMethods();
    assertNotNull(methods);
    assertTrue(methods.size() >= 2);
    Set<String> duplicateTypes = new HashSet<>();
    boolean foundFree = false;
    boolean foundToken = false;
    for (AccessMethod method : methods) {
        Assert.assertFalse(duplicateTypes.contains(method.getType()));
        if (method instanceof FreeAccessMethod) {
            foundFree = true;
        } else if (method instanceof TokenAccessMethod) {
            foundToken = true;
        }
        assertTrue(method.isEnabled());
        assertTrue(method.isValid());
        duplicateTypes.add(method.getType());
    }
    assertTrue(foundFree);
    assertTrue(foundToken);
}
Also used : TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with AccessMethod

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

the class AccessMethodRenderer method render.

@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
    if (val instanceof AccessTransaction) {
        AccessTransaction transaction = (AccessTransaction) val;
        Set<String> uniqueType = new HashSet<String>(3);
        render(sb, transaction, uniqueType, locale);
    } else if (val instanceof Collection) {
        Collection<?> transactions = (Collection<?>) val;
        Set<String> uniqueType = new HashSet<String>((transactions.size() * 2) + 1);
        for (Object transaction : transactions) {
            if (transaction instanceof AccessTransaction) {
                render(sb, (AccessTransaction) transaction, uniqueType, locale);
            } else if (transaction instanceof AccessMethod) {
                render(sb, (AccessMethod) transaction, uniqueType, locale);
            }
        }
    }
}
Also used : AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) Set(java.util.Set) HashSet(java.util.HashSet) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 8 with AccessMethod

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

the class AccessMethodRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Object val, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
    if (val instanceof AccessTransaction) {
        AccessTransaction transaction = (AccessTransaction) val;
        Set<String> uniqueType = new HashSet<String>(3);
        render(sb, transaction, uniqueType, translator.getLocale());
    } else if (val instanceof Collection) {
        Collection<?> transactions = (Collection<?>) val;
        Set<String> uniqueType = new HashSet<String>((transactions.size() * 2) + 1);
        for (Object transaction : transactions) {
            if (transaction instanceof AccessTransaction) {
                render(sb, (AccessTransaction) transaction, uniqueType, translator.getLocale());
            } else if (transaction instanceof AccessMethod) {
                render(sb, (AccessMethod) transaction, uniqueType, translator.getLocale());
            }
        }
    }
}
Also used : AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) Set(java.util.Set) HashSet(java.util.HashSet) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 9 with AccessMethod

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

the class ACFrontendManager method findOrderItems.

@Override
public List<OrderTableItem> findOrderItems(OLATResource resource, IdentityRef delivery, Long orderNr, Date from, Date to, OrderStatus[] status, int firstResult, int maxResults, List<UserPropertyHandler> userPropertyHandlers, SortKey... orderBy) {
    List<AccessMethod> methods = methodManager.getAllMethods();
    Map<String, AccessMethod> methodMap = new HashMap<>();
    for (AccessMethod method : methods) {
        methodMap.put(method.getKey().toString(), method);
    }
    List<RawOrderItem> rawOrders = orderManager.findNativeOrderItems(resource, delivery, orderNr, from, to, status, firstResult, maxResults, userPropertyHandlers, orderBy);
    List<OrderTableItem> items = new ArrayList<>(rawOrders.size());
    for (RawOrderItem rawOrder : rawOrders) {
        String orderStatusStr = rawOrder.getOrderStatus();
        OrderStatus orderStatus = OrderStatus.valueOf(orderStatusStr);
        Status finalStatus = getStatus(orderStatusStr, rawOrder.getTrxStatus(), rawOrder.getPspTrxStatus());
        String methodIds = rawOrder.getTrxMethodIds();
        List<AccessMethod> orderMethods = new ArrayList<>(2);
        if (StringHelper.containsNonWhitespace(methodIds)) {
            String[] methodIdArr = methodIds.split(",");
            for (String methodId : methodIdArr) {
                if (methodMap.containsKey(methodId)) {
                    orderMethods.add(methodMap.get(methodId));
                }
            }
        }
        OrderTableItem item = new OrderTableItem(rawOrder.getOrderKey(), rawOrder.getOrderNr(), rawOrder.getTotal(), rawOrder.getCreationDate(), orderStatus, finalStatus, rawOrder.getDeliveryKey(), rawOrder.getUsername(), rawOrder.getUserProperties(), orderMethods);
        item.setResourceDisplayname(rawOrder.getResourceName());
        items.add(item);
    }
    return items;
}
Also used : OrderStatus(org.olat.resource.accesscontrol.OrderStatus) Status(org.olat.resource.accesscontrol.ui.OrderTableItem.Status) AccessTransactionStatus(org.olat.resource.accesscontrol.model.AccessTransactionStatus) PSPTransactionStatus(org.olat.resource.accesscontrol.model.PSPTransactionStatus) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RawOrderItem(org.olat.resource.accesscontrol.model.RawOrderItem) OrderStatus(org.olat.resource.accesscontrol.OrderStatus) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) OrderTableItem(org.olat.resource.accesscontrol.ui.OrderTableItem)

Example 10 with AccessMethod

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

the class ACMethodDAO method isValidMethodAvailable.

public boolean isValidMethodAvailable(OLATResource resource, Date atDate) {
    StringBuilder sb = new StringBuilder();
    sb.append("select access.method from acofferaccess access ").append(" inner join access.offer offer").append(" inner join offer.resource oResource").append(" where access.valid=true").append(" and offer.valid=true").append(" and oResource.key=:resourceKey");
    if (atDate != null) {
        sb.append(" and (offer.validFrom is null or offer.validFrom<=:atDate)").append(" and (offer.validTo is null or offer.validTo>=:atDate)");
    }
    TypedQuery<AccessMethod> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class);
    query.setParameter("resourceKey", resource.getKey());
    if (atDate != null) {
        query.setParameter("atDate", atDate, TemporalType.TIMESTAMP);
    }
    List<AccessMethod> methods = query.getResultList();
    List<AccessMethod> guiMethods = new ArrayList<>();
    for (AccessMethod method : methods) {
        if (method.isVisibleInGui()) {
            guiMethods.add(method);
        }
    }
    return !guiMethods.isEmpty();
}
Also used : ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) AbstractAccessMethod(org.olat.resource.accesscontrol.model.AbstractAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) ArrayList(java.util.ArrayList)

Aggregations

AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)92 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)62 Test (org.junit.Test)56 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)54 OLATResource (org.olat.resource.OLATResource)40 Identity (org.olat.core.id.Identity)22 ShibbolethAutoAccessMethod (org.olat.shibboleth.manager.ShibbolethAutoAccessMethod)22 BusinessGroup (org.olat.group.BusinessGroup)18 PaypalAccessMethod (org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)12 Offer (org.olat.resource.accesscontrol.Offer)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)10 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)10 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)10 AbstractAccessMethod (org.olat.resource.accesscontrol.model.AbstractAccessMethod)10 HashSet (java.util.HashSet)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 OLATResourceable (org.olat.core.id.OLATResourceable)6