Search in sources :

Example 1 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.

the class PaypalManagerImpl method cancelTransaction.

private synchronized void cancelTransaction(PaypalTransaction trx) {
    if (trx.getStatus() == PaypalTransactionStatus.SUCCESS || trx.getStatus() == PaypalTransactionStatus.CANCELED) {
        // already completed: if successed -> let it in this state
        return;
    }
    updateTransaction(trx, PaypalTransactionStatus.CANCELED);
    Order order = orderManager.loadOrderByNr(trx.getRefNo());
    orderManager.save(order, OrderStatus.CANCELED);
    // cancel the reservations
    Identity identity = order.getDelivery();
    for (OrderPart part : order.getParts()) {
        if (part.getKey().equals(trx.getOrderPartId())) {
            for (OrderLine line : part.getOrderLines()) {
                OLATResource resource = line.getOffer().getResource();
                ResourceReservation reservation = acService.getReservation(identity, resource);
                if (reservation != null) {
                    acService.removeReservation(identity, identity, reservation);
                    log.audit("Remove reservation after cancellation for: " + reservation + " to " + identity, null);
                }
            }
        }
    }
}
Also used : Order(org.olat.resource.accesscontrol.Order) OrderLine(org.olat.resource.accesscontrol.OrderLine) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) OrderPart(org.olat.resource.accesscontrol.OrderPart) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity)

Example 2 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.

the class ACFrontendManager method reserveAccessToResource.

@Override
public boolean reserveAccessToResource(final Identity identity, final OfferAccess offer) {
    final OLATResource resource = offer.getOffer().getResource();
    String resourceType = resource.getResourceableTypeName();
    if ("BusinessGroup".equals(resourceType)) {
        boolean reserved = false;
        final BusinessGroup group = businessGroupDao.loadForUpdate(resource.getResourceableId());
        if (group.getMaxParticipants() == null && group.getMaxParticipants() <= 0) {
            // don't need reservation
            reserved = true;
        } else {
            BusinessGroup reloadedGroup = businessGroupService.loadBusinessGroup(resource);
            ResourceReservation reservation = reservationDao.loadReservation(identity, resource);
            if (reservation != null) {
                reserved = true;
            }
            int currentCount = businessGroupService.countMembers(reloadedGroup, GroupRoles.participant.name());
            int reservations = reservationDao.countReservations(resource);
            if (currentCount + reservations < reloadedGroup.getMaxParticipants().intValue()) {
                reservationDao.createReservation(identity, offer.getMethod().getType(), null, resource);
                reserved = true;
            }
        }
        return reserved;
    }
    return true;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) OLATResource(org.olat.resource.OLATResource)

Example 3 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.

the class ACFrontendManager method cleanupReservations.

@Override
public void cleanupReservations() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, -1);
    Date oneHourTimeout = cal.getTime();
    List<ResourceReservation> oldReservations = reservationDao.loadExpiredReservation(oneHourTimeout);
    for (ResourceReservation reservation : oldReservations) {
        log.audit("Remove reservation:" + reservation);
        reservationDao.deleteReservation(reservation);
    }
}
Also used : ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) Date(java.util.Date)

Example 4 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.

the class RepositoryManager method removeMembers.

/**
 * Remove the identities as members of the repository and from
 * all connected business groups.
 *
 * @param members
 * @param re
 */
public boolean removeMembers(Identity ureqIdentity, List<Identity> members, RepositoryEntry re, MailPackage mailing) {
    // log the action
    ActionType actionType = ThreadLocalUserActivityLogger.getStickyActionType();
    ThreadLocalUserActivityLogger.setStickyActionType(ActionType.admin);
    for (Identity identity : members) {
        try {
            ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_MEMBER_REMOVED, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry), LoggingResourceable.wrap(identity));
        } finally {
            ThreadLocalUserActivityLogger.setStickyActionType(actionType);
        }
    }
    List<ResourceReservation> reservations = reservationDao.loadReservations(Collections.singletonList(re.getOlatResource()));
    for (ResourceReservation reservation : reservations) {
        if (members.contains(reservation.getIdentity())) {
            reservationDao.deleteReservation(reservation);
        }
    }
    boolean allOk = repositoryEntryRelationDao.removeMembers(re, members);
    if (allOk) {
        int count = 0;
        List<RepositoryEntryMembershipModifiedEvent> deferredEvents = new ArrayList<>();
        for (Identity identity : members) {
            deferredEvents.add(RepositoryEntryMembershipModifiedEvent.removed(identity, re));
            if (++count % 100 == 0) {
                dbInstance.commitAndCloseSession();
            }
        }
        dbInstance.commit();
        sendDeferredEvents(deferredEvents, re);
    }
    if (allOk) {
        // do logging - not optimal but
        StringBuilder sb = new StringBuilder();
        sb.append("Identity(.key):").append(ureqIdentity.getKey()).append("removed multiple identities from security groups. Identities:: ");
        for (Identity member : members) {
            sb.append(member.getName()).append(", ");
        }
        log.audit(sb.toString());
    }
    for (Identity identity : members) {
        RepositoryMailing.sendEmail(ureqIdentity, identity, re, RepositoryMailing.Type.removeParticipant, mailing);
    }
    return allOk;
}
Also used : ActionType(org.olat.core.logging.activity.ActionType) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) RepositoryEntryMembershipModifiedEvent(org.olat.repository.model.RepositoryEntryMembershipModifiedEvent) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 5 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.

the class RepositoryManager method addParticipants.

/**
 * add provided list of identities as participant to the repo entry. silently ignore
 * if some identities were already participant before.
 * @param ureqIdentity
 * @param addIdentities
 * @param re
 * @param userActivityLogger
 */
public void addParticipants(Identity ureqIdentity, Roles ureqRoles, IdentitiesAddEvent iae, RepositoryEntry re, MailPackage mailing) {
    List<Identity> addIdentities = iae.getAddIdentities();
    List<Identity> reallyAddedId = new ArrayList<Identity>();
    for (Identity identityToAdd : addIdentities) {
        if (!repositoryEntryRelationDao.hasRole(identityToAdd, re, GroupRoles.participant.name())) {
            boolean mustAccept = true;
            if (ureqIdentity != null && ureqIdentity.equals(identityToAdd)) {
                // adding itself, we hope that he knows what he makes
                mustAccept = false;
            } else if (ureqRoles == null || ureqIdentity == null) {
                // administrative task
                mustAccept = false;
            } else {
                mustAccept = repositoryModule.isAcceptMembership(ureqRoles);
            }
            if (mustAccept) {
                ResourceReservation olderReservation = reservationDao.loadReservation(identityToAdd, re.getOlatResource());
                if (olderReservation == null) {
                    Calendar cal = Calendar.getInstance();
                    cal.add(Calendar.MONTH, 6);
                    Date expiration = cal.getTime();
                    ResourceReservation reservation = reservationDao.createReservation(identityToAdd, "repo_participant", expiration, re.getOlatResource());
                    if (reservation != null) {
                        RepositoryMailing.sendEmail(ureqIdentity, identityToAdd, re, RepositoryMailing.Type.addParticipant, mailing);
                    }
                }
            } else {
                addInternalParticipant(ureqIdentity, identityToAdd, re);
                reallyAddedId.add(identityToAdd);
                RepositoryMailing.sendEmail(ureqIdentity, identityToAdd, re, RepositoryMailing.Type.addParticipant, mailing);
            }
        }
    }
    iae.setIdentitiesAddedEvent(reallyAddedId);
}
Also used : ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Aggregations

ResourceReservation (org.olat.resource.accesscontrol.ResourceReservation)36 Identity (org.olat.core.id.Identity)24 Calendar (java.util.Calendar)20 BusinessGroup (org.olat.group.BusinessGroup)20 ArrayList (java.util.ArrayList)14 Date (java.util.Date)12 Test (org.junit.Test)10 OLATResource (org.olat.resource.OLATResource)8 BusinessGroupModifiedEvent (org.olat.group.ui.edit.BusinessGroupModifiedEvent)6 HashMap (java.util.HashMap)4 Order (org.olat.resource.accesscontrol.Order)4 OrderLine (org.olat.resource.accesscontrol.OrderLine)4 OrderPart (org.olat.resource.accesscontrol.OrderPart)4 HashSet (java.util.HashSet)2 Locale (java.util.Locale)2 ActionType (org.olat.core.logging.activity.ActionType)2 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)2 BusinessGroupShort (org.olat.group.BusinessGroupShort)2 BusinessGroupMembershipViewImpl (org.olat.group.model.BusinessGroupMembershipViewImpl)2 EnrollState (org.olat.group.model.EnrollState)2