Search in sources :

Example 6 with AccessTransaction

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

the class ACFrontendManager method accessResource.

@Override
public AccessResult accessResource(Identity identity, OfferAccess link, Object argument) {
    if (link == null || link.getOffer() == null || link.getMethod() == null) {
        log.audit("Access refused (no offer) to: " + link + " for " + identity);
        return new AccessResult(false);
    }
    AccessMethodHandler handler = accessModule.getAccessMethodHandler(link.getMethod().getType());
    if (handler == null) {
        log.audit("Access refused (no handler method) to: " + link + " for " + identity);
        return new AccessResult(false);
    }
    if (handler.checkArgument(link, argument)) {
        if (allowAccesToResource(identity, link.getOffer())) {
            Order order = orderManager.saveOneClick(identity, link);
            AccessTransaction transaction = transactionManager.createTransaction(order, order.getParts().get(0), link.getMethod());
            transactionManager.save(transaction);
            dbInstance.commit();
            log.audit("Access granted to: " + link + " for " + identity);
            return new AccessResult(true);
        } else {
            log.audit("Access error to: " + link + " for " + identity);
        }
    } else {
        log.audit("Access refused to: " + link + " for " + identity);
    }
    return new AccessResult(false);
}
Also used : Order(org.olat.resource.accesscontrol.Order) AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) AccessResult(org.olat.resource.accesscontrol.AccessResult) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 7 with AccessTransaction

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

the class PaypalManagerImpl method completeDeniedTransaction.

private void completeDeniedTransaction(PaypalTransaction trx) {
    updateTransaction(trx, PaypalTransactionStatus.DENIED);
    Order order = orderManager.loadOrderByNr(trx.getRefNo());
    order = orderManager.save(order, OrderStatus.ERROR);
    PaypalAccessMethod method = getMethodSecure(trx.getMethodId());
    if (order.getKey().equals(trx.getOrderId())) {
        // make accessible
        Identity identity = order.getDelivery();
        for (OrderPart part : order.getParts()) {
            if (part.getKey().equals(trx.getOrderPartId())) {
                AccessTransaction transaction = transactionManager.createTransaction(order, part, method);
                transaction = transactionManager.update(transaction, AccessTransactionStatus.ERROR);
                for (OrderLine line : part.getOrderLines()) {
                    acService.denyAccesToResource(identity, line.getOffer());
                    log.audit("Paypal payed access revoked for: " + buildLogMessage(line, method) + " to " + identity, null);
                    ResourceReservation reservation = reservationDao.loadReservation(identity, line.getOffer().getResource());
                    if (reservation != null) {
                        acService.removeReservation(identity, identity, reservation);
                        log.audit("Remove reservation after cancellation for: " + reservation + " to " + identity, null);
                    }
                }
            }
        }
    } else {
        log.error("Order not in sync with PaypalTransaction", null);
    }
}
Also used : Order(org.olat.resource.accesscontrol.Order) AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) OrderLine(org.olat.resource.accesscontrol.OrderLine) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) OrderPart(org.olat.resource.accesscontrol.OrderPart) Identity(org.olat.core.id.Identity) PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)

Example 8 with AccessTransaction

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

the class PaypalManagerImpl method completeTransactionSucessfully.

private void completeTransactionSucessfully(PaypalTransaction trx, String trxStatus) {
    Order order = orderManager.loadOrderByNr(trx.getRefNo());
    if ("PENDING".equalsIgnoreCase(trxStatus)) {
        updateTransaction(trx, PaypalTransactionStatus.PENDING);
    } else {
        updateTransaction(trx, PaypalTransactionStatus.SUCCESS);
    }
    order = orderManager.save(order, OrderStatus.PAYED);
    PaypalAccessMethod method = getMethodSecure(trx.getMethodId());
    if (order.getKey().equals(trx.getOrderId())) {
        // make accessible
        Identity identity = order.getDelivery();
        for (OrderPart part : order.getParts()) {
            if (part.getKey().equals(trx.getOrderPartId())) {
                AccessTransaction transaction = transactionManager.createTransaction(order, part, method);
                transaction = transactionManager.save(transaction);
                for (OrderLine line : part.getOrderLines()) {
                    if (acService.allowAccesToResource(identity, line.getOffer())) {
                        log.audit("Paypal payed access granted for: " + buildLogMessage(line, method) + " to " + identity, null);
                        transaction = transactionManager.update(transaction, AccessTransactionStatus.SUCCESS);
                    } else {
                        log.error("Paypal payed access refused for: " + buildLogMessage(line, method) + " to " + identity, null);
                        transaction = transactionManager.update(transaction, AccessTransactionStatus.ERROR);
                    }
                }
            }
        }
    } else {
        log.error("Order not in sync with PaypalTransaction", null);
    }
}
Also used : Order(org.olat.resource.accesscontrol.Order) AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) OrderLine(org.olat.resource.accesscontrol.OrderLine) OrderPart(org.olat.resource.accesscontrol.OrderPart) Identity(org.olat.core.id.Identity) PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)

Example 9 with AccessTransaction

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

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 10 with AccessTransaction

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

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)

Aggregations

AccessTransaction (org.olat.resource.accesscontrol.AccessTransaction)14 Order (org.olat.resource.accesscontrol.Order)6 OrderLine (org.olat.resource.accesscontrol.OrderLine)6 OrderPart (org.olat.resource.accesscontrol.OrderPart)6 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)6 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Identity (org.olat.core.id.Identity)4 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)4 PaypalAccessMethod (org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)4 ArrayList (java.util.ArrayList)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 OLATResource (org.olat.resource.OLATResource)2 AccessResult (org.olat.resource.accesscontrol.AccessResult)2 ResourceReservation (org.olat.resource.accesscontrol.ResourceReservation)2