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);
}
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);
}
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());
}
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);
}
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);
}
}
Aggregations