use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class BusinessGroupServiceTest method testAcceptPendingParticipation_coach.
@Test
public void testAcceptPendingParticipation_coach() {
// 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);
// check that the user is not participant
Assert.assertFalse(businessGroupService.hasRoles(id, group, GroupRoles.coach.name()));
// accept reservation
acService.acceptReservationToResource(id, reservation);
dbInstance.commitAndCloseSession();
// check that the user is participant
Assert.assertTrue(businessGroupService.hasRoles(id, group, GroupRoles.coach.name()));
// 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 BusinessGroupServiceTest method testCancelPendingParticipation_deletedGroup.
@Test
public void testCancelPendingParticipation_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_participant", cal.getTime(), group.getResource());
dbInstance.commitAndCloseSession();
Assert.assertNotNull(reservation);
// delete the group
businessGroupService.deleteBusinessGroup(group);
dbInstance.commitAndCloseSession();
// accept reservation
acService.removeReservation(id, id, reservation);
dbInstance.commitAndCloseSession();
// check that the user is not participant
boolean participant2 = businessGroupService.hasRoles(id, group, GroupRoles.participant.name());
Assert.assertFalse(participant2);
// 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 AbstractMemberListController method updateTableModel.
protected List<MemberView> updateTableModel(SearchMembersParams params) {
// course membership
boolean managedMembersRepo = RepositoryEntryManagedFlag.isManaged(repoEntry, RepositoryEntryManagedFlag.membersmanagement);
List<RepositoryEntryMembership> repoMemberships = repoEntry == null ? Collections.<RepositoryEntryMembership>emptyList() : repositoryManager.getRepositoryEntryMembership(repoEntry);
// groups membership
List<BusinessGroup> groups = repoEntry == null ? Collections.singletonList(businessGroup) : businessGroupService.findBusinessGroups(null, repoEntry, 0, -1);
List<Long> groupKeys = new ArrayList<Long>();
Map<Long, BusinessGroupShort> keyToGroupMap = new HashMap<>();
for (BusinessGroup group : groups) {
groupKeys.add(group.getKey());
keyToGroupMap.put(group.getKey(), group);
}
List<BusinessGroupMembership> memberships = groups.isEmpty() ? Collections.<BusinessGroupMembership>emptyList() : businessGroupService.getBusinessGroupsMembership(groups);
// get identities
Set<Long> identityKeys = new HashSet<>();
for (RepositoryEntryMembership membership : repoMemberships) {
identityKeys.add(membership.getIdentityKey());
}
for (BusinessGroupMembership membership : memberships) {
identityKeys.add(membership.getIdentityKey());
}
List<Identity> identities;
if (identityKeys.isEmpty()) {
identities = new ArrayList<>(0);
} else {
identities = filterIdentities(params, identityKeys);
}
Map<Long, MemberView> keyToMemberMap = new HashMap<>();
List<MemberView> memberList = new ArrayList<>();
Locale locale = getLocale();
// reservations
if (params.isPending()) {
List<OLATResource> resourcesForReservations = new ArrayList<>();
if (repoEntry != null) {
resourcesForReservations.add(repoEntry.getOlatResource());
}
for (BusinessGroup group : groups) {
resourcesForReservations.add(group.getResource());
}
List<ResourceReservation> reservations = acService.getReservations(resourcesForReservations);
List<Long> pendingIdentityKeys = new ArrayList<>(reservations.size());
for (ResourceReservation reservation : reservations) {
pendingIdentityKeys.add(reservation.getIdentity().getKey());
}
if (StringHelper.containsNonWhitespace(params.getSearchString()) || StringHelper.containsNonWhitespace(params.getLogin()) || (params.getUserPropertiesSearch() != null && !params.getUserPropertiesSearch().isEmpty())) {
List<Identity> pendingIdentities = filterIdentities(params, pendingIdentityKeys);
pendingIdentityKeys.retainAll(PersistenceHelper.toKeys(pendingIdentities));
}
for (ResourceReservation reservation : reservations) {
Identity identity = reservation.getIdentity();
if (pendingIdentityKeys.contains(identity.getKey())) {
MemberView member = new MemberView(identity, userPropertyHandlers, locale);
member.getMembership().setPending(true);
memberList.add(member);
forgeLinks(member);
keyToMemberMap.put(identity.getKey(), member);
}
}
}
Long me = getIdentity().getKey();
Set<Long> loadStatus = new HashSet<>();
for (Identity identity : identities) {
MemberView member = new MemberView(identity, userPropertyHandlers, locale);
if (chatEnabled) {
if (identity.getKey().equals(me)) {
member.setOnlineStatus("me");
} else if (sessionManager.isOnline(identity.getKey())) {
loadStatus.add(identity.getKey());
} else {
member.setOnlineStatus(Presence.unavailable.name());
}
}
memberList.add(member);
forgeLinks(member);
keyToMemberMap.put(identity.getKey(), member);
}
if (loadStatus.size() > 0) {
List<Long> statusToLoadList = new ArrayList<>(loadStatus);
Map<Long, String> statusMap = imService.getBuddyStatus(statusToLoadList);
for (Long toLoad : statusToLoadList) {
String status = statusMap.get(toLoad);
MemberView member = keyToMemberMap.get(toLoad);
if (status == null) {
member.setOnlineStatus(Presence.available.name());
} else {
member.setOnlineStatus(status);
}
}
}
for (BusinessGroupMembership membership : memberships) {
Long identityKey = membership.getIdentityKey();
MemberView memberView = keyToMemberMap.get(identityKey);
if (memberView != null) {
memberView.setFirstTime(membership.getCreationDate());
memberView.setLastTime(membership.getLastModified());
if (membership.isOwner()) {
memberView.getMembership().setGroupTutor(true);
}
if (membership.isParticipant()) {
memberView.getMembership().setGroupParticipant(true);
}
if (membership.isWaiting()) {
memberView.getMembership().setGroupWaiting(true);
}
Long groupKey = membership.getGroupKey();
BusinessGroupShort group = keyToGroupMap.get(groupKey);
memberView.addGroup(group);
}
}
for (RepositoryEntryMembership membership : repoMemberships) {
Long identityKey = membership.getIdentityKey();
MemberView memberView = keyToMemberMap.get(identityKey);
if (memberView != null) {
memberView.setFirstTime(membership.getCreationDate());
memberView.setLastTime(membership.getLastModified());
memberView.getMembership().setManagedMembersRepo(managedMembersRepo);
if (membership.isOwner()) {
memberView.getMembership().setRepoOwner(true);
}
if (membership.isCoach()) {
memberView.getMembership().setRepoTutor(true);
}
if (membership.isParticipant()) {
memberView.getMembership().setRepoParticipant(true);
}
}
}
if (repoEntry != null) {
Map<Long, Date> lastLaunchDates = userInfosMgr.getRecentLaunchDates(repoEntry.getOlatResource());
for (MemberView memberView : keyToMemberMap.values()) {
Long identityKey = memberView.getIdentityKey();
Date date = lastLaunchDates.get(identityKey);
memberView.setLastTime(date);
}
}
// the order of the filter is important
filterByRoles(memberList, params);
filterByOrigin(memberList, params);
memberListModel.setObjects(memberList);
membersTable.reset(true, true, true);
return memberList;
}
use of org.olat.resource.accesscontrol.ResourceReservation in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceImpl method addOwner.
private boolean addOwner(Identity ureqIdentity, Roles ureqRoles, Identity identityToAdd, BusinessGroup group, MailPackage mailing, List<BusinessGroupModifiedEvent.Deferred> events) {
if (!businessGroupRelationDAO.hasRole(identityToAdd, group, 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 = groupModule.isAcceptMembership(ureqRoles);
}
if (mustAccept) {
ResourceReservation olderReservation = reservationDao.loadReservation(identityToAdd, group.getResource());
if (olderReservation == null) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, 6);
Date expiration = cal.getTime();
ResourceReservation reservation = reservationDao.createReservation(identityToAdd, "group_coach", expiration, group.getResource());
if (reservation != null) {
BusinessGroupMailing.sendEmail(ureqIdentity, identityToAdd, group, MailType.addCoach, mailing);
// logging
log.audit("Identity(.key):" + ureqIdentity.getKey() + " added identity '" + identityToAdd.getName() + "' to group with key " + group.getKey());
}
}
} else {
internalAddCoach(ureqIdentity, identityToAdd, group, events);
BusinessGroupMailing.sendEmail(ureqIdentity, identityToAdd, group, MailType.addCoach, mailing);
}
return true;
}
return false;
}
Aggregations