Search in sources :

Example 11 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef 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 12 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef in project OpenOLAT by OpenOLAT.

the class RepositoryEntryMembershipProcessor method processIdentityRemoved.

private void processIdentityRemoved(Long repoKey, Long identityKey) {
    IdentityRef identity = new IdentityRefImpl(identityKey);
    RepositoryEntryRef re = new RepositoryEntryRefImpl(repoKey);
    List<String> remainingRoles = repositoryEntryRelationDao.getRoles(identity, re);
    if (remainingRoles.isEmpty()) {
        OLATResource resource = repositoryManager.lookupRepositoryEntryResource(repoKey);
        notificationsManager.unsubscribeAllForIdentityAndResId(identity, resource.getResourceableId());
    }
}
Also used : IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) IdentityRef(org.olat.basesecurity.IdentityRef) RepositoryEntryRefImpl(org.olat.repository.model.RepositoryEntryRefImpl) OLATResource(org.olat.resource.OLATResource) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 13 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef in project OpenOLAT by OpenOLAT.

the class ACFrontendManager method denyAccesToResource.

@Override
public boolean denyAccesToResource(Identity identity, Offer offer) {
    // check if offer is ok: key is stupid but further check as date, validity...
    if (offer.getKey() == null) {
        return false;
    }
    // check the resource
    OLATResource resource = offer.getResource();
    if (resource == null || resource.getKey() == null || resource.getResourceableId() == null || resource.getResourceableTypeName() == null) {
        return false;
    }
    String resourceType = resource.getResourceableTypeName();
    if ("BusinessGroup".equals(resourceType)) {
        BusinessGroup group = businessGroupService.loadBusinessGroup(resource);
        if (group != null) {
            if (businessGroupService.hasRoles(identity, group, GroupRoles.participant.name())) {
                businessGroupRelationDao.removeRole(identity, group, GroupRoles.participant.name());
            }
            return true;
        }
    } else {
        RepositoryEntryRef entry = repositoryManager.lookupRepositoryEntry(resource, false);
        if (entry != null) {
            if (repositoryEntryRelationDao.hasRole(identity, entry, GroupRoles.participant.name())) {
                repositoryEntryRelationDao.removeRole(identity, entry, GroupRoles.participant.name());
            }
            return true;
        }
    }
    return false;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef)

Example 14 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef in project OpenOLAT by OpenOLAT.

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 15 with RepositoryEntryRef

use of org.olat.repository.RepositoryEntryRef in project OpenOLAT by OpenOLAT.

the class BusinessGroupMembershipProcessor method processIdentityRemoved.

private void processIdentityRemoved(Long groupKey, Long identityKey) {
    IdentityRef identityRef = new IdentityRefImpl(identityKey);
    BusinessGroupRef groupRef = new BusinessGroupRefImpl(groupKey);
    if (!businessGroupRelationDao.hasAnyRole(identityRef, groupRef)) {
        infoMessageManager.updateInfoMessagesOfIdentity(groupRef, identityRef);
        notificationsManager.unsubscribeAllForIdentityAndResId(identityRef, groupRef.getKey());
        List<BGRepositoryEntryRelation> relations = businessGroupRelationDao.findRelationToRepositoryEntries(Collections.singletonList(groupKey), 0, -1);
        for (BGRepositoryEntryRelation relation : relations) {
            Long repositoryEntryKey = relation.getRepositoryEntryKey();
            RepositoryEntryRef entryRef = new RepositoryEntryRefImpl(repositoryEntryKey);
            List<String> remaingRoles = repositoryEntryRelationDao.getRoles(identityRef, entryRef);
            if (remaingRoles.isEmpty()) {
                OLATResource resource = repositoryManager.lookupRepositoryEntryResource(entryRef.getKey());
                notificationsManager.unsubscribeAllForIdentityAndResId(identityRef, resource.getResourceableId());
            }
        }
    }
}
Also used : IdentityRefImpl(org.olat.basesecurity.model.IdentityRefImpl) BusinessGroupRef(org.olat.group.BusinessGroupRef) IdentityRef(org.olat.basesecurity.IdentityRef) RepositoryEntryRefImpl(org.olat.repository.model.RepositoryEntryRefImpl) OLATResource(org.olat.resource.OLATResource) BusinessGroupRefImpl(org.olat.group.model.BusinessGroupRefImpl) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef) BGRepositoryEntryRelation(org.olat.group.model.BGRepositoryEntryRelation)

Aggregations

RepositoryEntryRef (org.olat.repository.RepositoryEntryRef)22 RepositoryEntryRefImpl (org.olat.repository.model.RepositoryEntryRefImpl)12 OLATResource (org.olat.resource.OLATResource)10 IdentityRef (org.olat.basesecurity.IdentityRef)6 IdentityRefImpl (org.olat.basesecurity.model.IdentityRefImpl)6 UserEfficiencyStatement (org.olat.course.assessment.UserEfficiencyStatement)6 ArrayList (java.util.ArrayList)4 EfficiencyStatementManager (org.olat.course.assessment.manager.EfficiencyStatementManager)4 ArgumentParseException (org.olat.course.condition.interpreter.ArgumentParseException)4 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)4 BusinessGroup (org.olat.group.BusinessGroup)4 BusinessGroupRef (org.olat.group.BusinessGroupRef)4 BusinessGroupRefImpl (org.olat.group.model.BusinessGroupRefImpl)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 BGRepositoryEntryRelation (org.olat.group.model.BGRepositoryEntryRelation)2 BusinessGroupMembershipViewImpl (org.olat.group.model.BusinessGroupMembershipViewImpl)2 BusinessGroupModifiedEvent (org.olat.group.ui.edit.BusinessGroupModifiedEvent)2