Search in sources :

Example 6 with ActionType

use of org.olat.core.logging.activity.ActionType in project openolat by klemens.

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 7 with ActionType

use of org.olat.core.logging.activity.ActionType in project openolat by klemens.

the class RepositoryManager method addInternalParticipant.

/**
 * This is for internal usage only. The method dosn't make any check.
 * @param ureqIdentity
 * @param identity
 * @param re
 */
private void addInternalParticipant(Identity ureqIdentity, Identity identity, RepositoryEntry re) {
    repositoryEntryRelationDao.addRole(identity, re, GroupRoles.participant.name());
    ActionType actionType = ThreadLocalUserActivityLogger.getStickyActionType();
    ThreadLocalUserActivityLogger.setStickyActionType(ActionType.admin);
    try {
        ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_OWNER_ADDED, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry), LoggingResourceable.wrap(identity));
    } finally {
        ThreadLocalUserActivityLogger.setStickyActionType(actionType);
    }
    log.audit("Identity(.key):" + ureqIdentity.getKey() + " added identity '" + identity.getName() + "' to repositoryentry with key " + re.getKey());
}
Also used : ActionType(org.olat.core.logging.activity.ActionType)

Example 8 with ActionType

use of org.olat.core.logging.activity.ActionType in project openolat by klemens.

the class BusinessGroupServiceImpl method transferFirstIdentityFromWaitingToParticipant.

/**
 * Don't forget to lock the business group before calling this method.
 * @param ureqIdentity
 * @param group
 * @param mailing
 * @param syncIM
 */
private void transferFirstIdentityFromWaitingToParticipant(Identity ureqIdentity, BusinessGroup group, MailPackage mailing, List<BusinessGroupModifiedEvent.Deferred> events) {
    // Check if waiting-list is enabled and auto-rank-up
    if (group.getWaitingListEnabled() != null && group.getWaitingListEnabled().booleanValue() && group.getAutoCloseRanksEnabled() != null && group.getAutoCloseRanksEnabled().booleanValue()) {
        // Check if participant is not full
        Integer maxSize = group.getMaxParticipants();
        int reservations = reservationDao.countReservations(group.getResource());
        int partipiciantSize = businessGroupRelationDAO.countRoles(group, GroupRoles.participant.name());
        if (maxSize != null && (partipiciantSize + reservations) < maxSize.intValue()) {
            // ok it has free places => get first identities from waiting list
            List<Identity> identities = businessGroupRelationDAO.getMembersOrderByDate(group, GroupRoles.waiting.name());
            int counter = 0;
            int freeSlot = maxSize - (partipiciantSize + reservations);
            for (Identity firstWaitingListIdentity : identities) {
                if (counter >= freeSlot) {
                    break;
                }
                // Check if firstWaitingListIdentity is not allready in participant-group
                if (!businessGroupRelationDAO.hasRole(firstWaitingListIdentity, group, GroupRoles.participant.name())) {
                    // move the identity from the waitinglist to the participant group
                    ActionType formerStickyActionType = ThreadLocalUserActivityLogger.getStickyActionType();
                    try {
                        // OLAT-4955: force add-participant and remove-from-waitinglist logging actions
                        // that get triggered in the next two methods to be of ActionType admin
                        // This is needed to make sure the targetIdentity ends up in the o_loggingtable
                        ThreadLocalUserActivityLogger.setStickyActionType(ActionType.admin);
                        // Don't send mails for the sub-actions "adding to group" and "remove from waiting list", instead
                        // send a specific "graduate from waiting list" mailing a few lines below
                        MailPackage subMailing = new MailPackage(false);
                        addParticipant(ureqIdentity, null, firstWaitingListIdentity, group, subMailing, events);
                        removeFromWaitingList(ureqIdentity, firstWaitingListIdentity, group, subMailing, events);
                    } finally {
                        ThreadLocalUserActivityLogger.setStickyActionType(formerStickyActionType);
                    }
                    // Send mail to let user know he is now in group
                    if (mailing == null) {
                        mailing = new MailPackage(true);
                    }
                    BusinessGroupMailing.sendEmail(null, firstWaitingListIdentity, group, MailType.graduateFromWaitingListToParticpant, mailing);
                    counter++;
                }
            }
        }
    }
}
Also used : ActionType(org.olat.core.logging.activity.ActionType) MailPackage(org.olat.core.util.mail.MailPackage) Identity(org.olat.core.id.Identity)

Example 9 with ActionType

use of org.olat.core.logging.activity.ActionType in project OpenOLAT by OpenOLAT.

the class RepositoryManager method addInternalParticipant.

/**
 * This is for internal usage only. The method dosn't make any check.
 * @param ureqIdentity
 * @param identity
 * @param re
 */
private void addInternalParticipant(Identity ureqIdentity, Identity identity, RepositoryEntry re) {
    repositoryEntryRelationDao.addRole(identity, re, GroupRoles.participant.name());
    ActionType actionType = ThreadLocalUserActivityLogger.getStickyActionType();
    ThreadLocalUserActivityLogger.setStickyActionType(ActionType.admin);
    try {
        ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_OWNER_ADDED, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry), LoggingResourceable.wrap(identity));
    } finally {
        ThreadLocalUserActivityLogger.setStickyActionType(actionType);
    }
    log.audit("Identity(.key):" + ureqIdentity.getKey() + " added identity '" + identity.getName() + "' to repositoryentry with key " + re.getKey());
}
Also used : ActionType(org.olat.core.logging.activity.ActionType)

Example 10 with ActionType

use of org.olat.core.logging.activity.ActionType in project OpenOLAT by OpenOLAT.

the class RepositoryManager method addOwners.

/**
 * add provided list of identities as owners to the repo entry. silently ignore
 * if some identities were already owners before.
 * @param ureqIdentity
 * @param addIdentities
 * @param re
 * @param userActivityLogger
 */
public void addOwners(Identity ureqIdentity, IdentitiesAddEvent iae, RepositoryEntry re, MailPackage mailing) {
    List<Identity> addIdentities = iae.getAddIdentities();
    List<Identity> reallyAddedId = new ArrayList<Identity>();
    for (Identity identity : addIdentities) {
        if (!repositoryEntryRelationDao.hasRole(identity, re, GroupRoles.owner.name())) {
            repositoryEntryRelationDao.addRole(identity, re, GroupRoles.owner.name());
            reallyAddedId.add(identity);
            ActionType actionType = ThreadLocalUserActivityLogger.getStickyActionType();
            ThreadLocalUserActivityLogger.setStickyActionType(ActionType.admin);
            try {
                ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_OWNER_ADDED, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry), LoggingResourceable.wrap(identity));
            } finally {
                ThreadLocalUserActivityLogger.setStickyActionType(actionType);
            }
            RepositoryMailing.sendEmail(ureqIdentity, identity, re, RepositoryMailing.Type.addOwner, mailing);
            log.audit("Identity(.key):" + ureqIdentity.getKey() + " added identity '" + identity.getName() + "' to repoentry with key " + re.getKey());
        }
    // else silently ignore already owner identities
    }
    iae.setIdentitiesAddedEvent(reallyAddedId);
}
Also used : ActionType(org.olat.core.logging.activity.ActionType) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Aggregations

ActionType (org.olat.core.logging.activity.ActionType)16 Identity (org.olat.core.id.Identity)6 ArrayList (java.util.ArrayList)4 MailPackage (org.olat.core.util.mail.MailPackage)2 RepositoryEntryMembershipModifiedEvent (org.olat.repository.model.RepositoryEntryMembershipModifiedEvent)2 ResourceReservation (org.olat.resource.accesscontrol.ResourceReservation)2