Search in sources :

Example 16 with ResourceReservation

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

the class BusinessGroupServiceImpl method removeMembers.

@Override
public void removeMembers(Identity ureqIdentity, List<Identity> identities, OLATResource resource, MailPackage mailing) {
    // nothing to do
    if (identities == null || identities.isEmpty() || resource == null)
        return;
    List<BusinessGroup> groups = null;
    if ("BusinessGroup".equals(resource.getResourceableTypeName())) {
        // it's a group resource
        BusinessGroup group = loadBusinessGroup(resource);
        if (group != null) {
            groups = Collections.singletonList(group);
        }
    } else {
        RepositoryEntryRef re = repositoryManager.lookupRepositoryEntry(resource, false);
        groups = findBusinessGroups(null, re, 0, -1);
    }
    if (groups == null || groups.isEmpty()) {
        // nothing to do
        return;
    }
    // remove managed groups
    for (Iterator<BusinessGroup> groupIt = groups.iterator(); groupIt.hasNext(); ) {
        boolean managed = BusinessGroupManagedFlag.isManaged(groupIt.next(), BusinessGroupManagedFlag.membersmanagement);
        if (managed) {
            groupIt.remove();
        }
    }
    if (groups.isEmpty()) {
        // nothing to do
        return;
    }
    List<OLATResource> groupResources = new ArrayList<OLATResource>();
    Map<Long, BusinessGroup> idToGroup = new HashMap<>();
    for (BusinessGroup group : groups) {
        groupResources.add(group.getResource());
        idToGroup.put(group.getKey(), group);
    }
    final Map<Long, Identity> keyToIdentityMap = new HashMap<Long, Identity>();
    for (Identity identity : identities) {
        keyToIdentityMap.put(identity.getKey(), identity);
    }
    List<BusinessGroupModifiedEvent.Deferred> events = new ArrayList<BusinessGroupModifiedEvent.Deferred>();
    List<BusinessGroupMembershipViewImpl> memberships = businessGroupDAO.getMembershipInfoInBusinessGroups(groups, identities);
    Collections.sort(memberships, new BusinessGroupMembershipViewComparator());
    BusinessGroupMembershipViewImpl nextGroupMembership = null;
    for (final Iterator<BusinessGroupMembershipViewImpl> itMembership = memberships.iterator(); nextGroupMembership != null || itMembership.hasNext(); ) {
        final BusinessGroupMembershipViewImpl currentMembership;
        if (nextGroupMembership == null) {
            currentMembership = itMembership.next();
        } else {
            currentMembership = nextGroupMembership;
            nextGroupMembership = null;
        }
        Long groupKey = currentMembership.getGroupKey();
        BusinessGroup nextGroup = businessGroupDAO.loadForUpdate(idToGroup.get(groupKey));
        nextGroupMembership = removeGroupMembers(ureqIdentity, currentMembership, nextGroup, keyToIdentityMap, itMembership, mailing, events);
        // release the lock
        dbInstance.commit();
    }
    List<ResourceReservation> reservations = reservationDao.loadReservations(groupResources);
    for (ResourceReservation reservation : reservations) {
        if (identities.contains(reservation.getIdentity())) {
            reservationDao.deleteReservation(reservation);
        }
    }
    dbInstance.commit();
    BusinessGroupModifiedEvent.fireDeferredEvents(events);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) BusinessGroupModifiedEvent(org.olat.group.ui.edit.BusinessGroupModifiedEvent) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef) Identity(org.olat.core.id.Identity) BusinessGroupMembershipViewImpl(org.olat.group.model.BusinessGroupMembershipViewImpl)

Example 17 with ResourceReservation

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

the class BusinessGroupServiceTest method testAcceptPendingParticipation_participant.

@Test
public void testAcceptPendingParticipation_participant() {
    // create a group
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Reserv-bg-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
    // create a reservation
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, 6);
    ResourceReservation reservation = reservationDao.createReservation(id, "group_participant", cal.getTime(), group.getResource());
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(reservation);
    Assert.assertEquals("group_participant", reservation.getType());
    Assert.assertEquals(group.getResource(), reservation.getResource());
    // check that the user is not participant
    Assert.assertFalse(businessGroupService.hasRoles(id, group, GroupRoles.participant.name()));
    // accept reservation
    businessGroupService.acceptPendingParticipation(id, id, group.getResource());
    dbInstance.commitAndCloseSession();
    // check that the user is participant
    boolean participant = businessGroupService.hasRoles(id, group, GroupRoles.participant.name());
    Assert.assertTrue(participant);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 18 with ResourceReservation

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

the class BusinessGroupServiceTest method testAcceptPendingParticipation_deletedGroup.

@Test
public void testAcceptPendingParticipation_deletedGroup() {
    // create a group
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Reserv-bg-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
    // create a reservation
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, 6);
    ResourceReservation reservation = reservationDao.createReservation(id, "group_coach", cal.getTime(), group.getResource());
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(reservation);
    // delete the group
    businessGroupService.deleteBusinessGroup(group);
    dbInstance.commitAndCloseSession();
    // accept reservation
    acService.acceptReservationToResource(id, reservation);
    dbInstance.commitAndCloseSession();
    // check that the reservations are deleted
    List<ResourceReservation> reservations = reservationDao.loadReservations(id);
    Assert.assertNotNull(reservations);
    Assert.assertTrue(reservations.isEmpty());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 19 with ResourceReservation

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

the class RepositoryManager method addTutors.

/**
 * add provided list of identities as tutor to the repo entry. silently ignore
 * if some identities were already tutor before.
 * @param ureqIdentity
 * @param addIdentities
 * @param re
 * @param userActivityLogger
 */
public void addTutors(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.coach.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_tutors", expiration, re.getOlatResource());
                    if (reservation != null) {
                        RepositoryMailing.sendEmail(ureqIdentity, identityToAdd, re, RepositoryMailing.Type.addTutor, mailing);
                    }
                }
            } else {
                addInternalTutors(ureqIdentity, identityToAdd, re, reallyAddedId);
                RepositoryMailing.sendEmail(ureqIdentity, identityToAdd, re, RepositoryMailing.Type.addTutor, mailing);
            }
        }
    // else silently ignore already owner identities
    }
    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)

Example 20 with ResourceReservation

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

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)

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