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