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