diff --git a/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java b/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java index c586dc81083c64c4a8713b834c289c45a3466975..f654fb2f79fe67b64239ab57602d0c896b1c10d3 100644 --- a/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java +++ b/src/main/java/org/olat/admin/user/groups/GroupOverviewController.java @@ -298,6 +298,7 @@ public class GroupOverviewController extends BasicController { // 2) remove as participant final BusinessGroup toRemFromGroup = currBusinessGroup; + //TODO gm sync CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(currBusinessGroup, new SyncerExecutor() { public void execute() { businessGroupService.removeParticipant(getIdentity(), identity, toRemFromGroup, flags); diff --git a/src/main/java/org/olat/collaboration/CollaborationTools.java b/src/main/java/org/olat/collaboration/CollaborationTools.java index 1565aaad6e467906058c579806b5babba4178877..80e2d9d95bf71086d93317683f675d3fc0dcb9c2 100644 --- a/src/main/java/org/olat/collaboration/CollaborationTools.java +++ b/src/main/java/org/olat/collaboration/CollaborationTools.java @@ -316,7 +316,7 @@ public class CollaborationTools implements Serializable { //final List<Forum> forumHolder = new ArrayList<Forum>(); Codepoint.codepoint(CollaborationTools.class, "pre_sync_enter"); - + //TODO gm sync Forum forum = coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<Forum>(){ public Forum execute() { @@ -536,7 +536,7 @@ public class CollaborationTools implements Serializable { public Controller createPortfolioController(final UserRequest ureq, WindowControl wControl, final BusinessGroup group) { final EPFrontendManager ePFMgr = (EPFrontendManager)CoreSpringFactory.getBean("epFrontendManager"); final NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores); - + //TODO gm sync PortfolioStructureMap map = coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<PortfolioStructureMap>(){ public PortfolioStructureMap execute() { PortfolioStructureMap aMap; @@ -675,7 +675,7 @@ public class CollaborationTools implements Serializable { // handle Boolean Values via String Field in Property DB Table final String toolValueStr = toolValue ? TRUE : FALSE; final PropertyManager pm = PropertyManager.getInstance(); - // + //TODO gm sync coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() { public void execute() { //was: synchronized (CollaborationTools.class) { diff --git a/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java b/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java index 4d7273f2ff9c14042b67105f38479f9c89155563..f76b3b58234074707db972ee15b8d96136aac37a 100644 --- a/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java +++ b/src/main/java/org/olat/collaboration/CollaborationToolsFactory.java @@ -76,6 +76,7 @@ public class CollaborationToolsFactory { if (ores == null) throw new AssertException("Null is not allowed here, you have to provide an existing ores here!"); final String cacheKey = Long.valueOf(ores.getResourceableId()).toString(); //sync operation cluster wide + //TODO gm sync return coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<CollaborationTools>() { public CollaborationTools execute() { diff --git a/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java b/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java index d73432782be4a0dd6c98ed9ac464331038160e5a..ab8af40080044373be30b84a472920085002fbd3 100644 --- a/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java +++ b/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java @@ -90,12 +90,13 @@ public class EnrollmentManager extends BasicManager { // the group was chosen, so why do we need the groupNames and areaNames here??? Codepoint.codepoint(EnrollmentManager.class, "beforeDoInSync"); + //TODO gm sync CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerExecutor(){ public void execute() { Tracing.logInfo("doEnroll start: group="+OresHelper.createStringRepresenting(group), identity.getName(), EnrollmentManager.class); Codepoint.codepoint(EnrollmentManager.class, "doInSync1"); // 6_1_0-RC15: reload group object here another node might have changed this in the meantime - BusinessGroup reloadedGroup = (BusinessGroup) DBFactory.getInstance().loadObject(group, true); + BusinessGroup reloadedGroup = businessGroupService.loadBusinessGroup(group); if (reloadedGroup.getMaxParticipants() != null && !reloadedGroup.getMaxParticipants().equals("")) { int participantsCounter = securityManager.countIdentitiesOfSecurityGroup(reloadedGroup.getPartipiciantGroup()); @@ -137,7 +138,7 @@ public class EnrollmentManager extends BasicManager { if (Tracing.isDebugEnabled(this.getClass())) Tracing.logDebug("doCancelEnrollment", this.getClass()); // 1. Remove group membership, fire events, do loggin etc. final BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - + //TODO gm sync CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(enrolledGroup, new SyncerExecutor(){ public void execute() { // Remove participant. This will also check if a waiting-list with auto-close-ranks is configurated @@ -166,6 +167,7 @@ public class EnrollmentManager extends BasicManager { public void doCancelEnrollmentInWaitingList(final Identity identity, final BusinessGroup enrolledWaitingListGroup, final ENCourseNode enNode, final CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) { // 1. Remove group membership, fire events, do loggin etc. + //TODO gm sync CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(enrolledWaitingListGroup, new SyncerExecutor(){ public void execute() { businessGroupService.removeFromWaitingList(identity, identity, enrolledWaitingListGroup); diff --git a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java index d5660cebf69ccc16cbc089bb2e41e7349f8a458a..5854d0dc10b75b9dcb8f82be0c5f64cd03acbcd1 100644 --- a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java +++ b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java @@ -156,9 +156,8 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou if (accountManagerGroup != null){ BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); BusinessGroup reloadedBusinessGroup = bgs.loadBusinessGroup(accountManagerGroup); - reloadedBusinessGroup.setName(groupName); - reloadedBusinessGroup.setDescription(groupDescription); - return bgs.mergeBusinessGroup(reloadedBusinessGroup); + return bgs.updateBusinessGroup(reloadedBusinessGroup, groupName, groupDescription, + reloadedBusinessGroup.getMinParticipants(), reloadedBusinessGroup.getMaxParticipants()); } return null; } @@ -206,7 +205,7 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou Set<String> names = new HashSet<String>(); names.add(groupName); int counter = 2; - while (bgs.checkIfOneOrMoreNameExistsInContext(names, courseResource)) { + while (bgs.checkIfOneOrMoreNameExists(names, courseResource)) { // a group with name already exist => look for an other one, append a number groupName = initialGroupName + " _" + counter++ ; logDebug("try groupName=" + groupName); @@ -215,13 +214,13 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou } logDebug("groupName=" + groupName); - reloadedBusinessGroup.setName(groupName); - reloadedBusinessGroup.setDescription(groupDescription); - return bgs.mergeBusinessGroup(reloadedBusinessGroup); + return bgs.updateBusinessGroup(reloadedBusinessGroup, groupName, groupDescription, + reloadedBusinessGroup.getMinParticipants(), reloadedBusinessGroup.getMaxParticipants()); } public List<Identity> addCandidates(final List<Identity> addIdentities, final Project project) { Codepoint.codepoint(ProjectBrokerManagerImpl.class, "beforeDoInSync"); + //TODO gm sync List<Identity> addedIdentities = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(project.getProjectGroup(), new SyncerCallback<List<Identity>>(){ public List<Identity> execute() { List<Identity> addedIdentities = new ArrayList<Identity>(); @@ -242,6 +241,7 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou public void removeCandidates(final List<Identity> addIdentities, final Project project) { Codepoint.codepoint(ProjectBrokerManagerImpl.class, "beforeDoInSync"); + //TODO gm sync CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(project.getProjectGroup(), new SyncerCallback<Boolean>(){ public Boolean execute() { Project reloadedProject = (Project) DBFactory.getInstance().loadObject(project, true); @@ -261,6 +261,7 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou final Project reloadedProject = (Project) DBFactory.getInstance().loadObject(project, true); final BusinessGroupAddResponse response = new BusinessGroupAddResponse(); final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); + //TODO gm sync Boolean result = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(project.getProjectGroup(), new SyncerCallback<Boolean>(){ public Boolean execute() { for (final Identity identity : identities) { @@ -320,8 +321,8 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); BusinessGroup reloadedBusinessGroup = bgs.loadBusinessGroup(projectGroup); logDebug("ProjectGroup.name=" + reloadedBusinessGroup.getName() + " setMaxParticipants=" + maxMembers); - reloadedBusinessGroup.setMaxParticipants(maxMembers); - return bgs.mergeBusinessGroup(reloadedBusinessGroup); + return bgs.updateBusinessGroup(reloadedBusinessGroup, null, null, reloadedBusinessGroup.getMinParticipants(), + maxMembers); } /////////////////// diff --git a/src/main/java/org/olat/group/BusinessGroupService.java b/src/main/java/org/olat/group/BusinessGroupService.java index 79985afe65c6eeeeffed0554d72b3531b7a8384e..9c8fe2edf75c0e4696be9c3beff8c7804d6b7f06 100644 --- a/src/main/java/org/olat/group/BusinessGroupService.java +++ b/src/main/java/org/olat/group/BusinessGroupService.java @@ -50,26 +50,93 @@ public interface BusinessGroupService { public static final String SEND_DELETE_EMAIL_ACTION = "sendDeleteEmail"; + /** + * Extension-point method to register objects which have deletable group-data. + * Listener will be called in method deleteBusinessGroup. + * @param listener + */ public void registerDeletableGroupDataListener(DeletableGroupData listener); public List<String> getDependingDeletablableListFor(BusinessGroup currentGroup, Locale locale); + /** + * Create a persistent BusinessGroup with the provided + * parameters. The BusinessGroup can have a waiting-list. + * @param creator + * @param name + * @param description + * @param minParticipants + * @param maxParticipants + * @param waitingListEnabled + * @param autoCloseRanksEnabled + * @param resource + * @return + */ public BusinessGroup createBusinessGroup(Identity creator, String name, String description, int minParticipants, int maxParticipants, boolean waitingListEnabled, boolean autoCloseRanksEnabled, OLATResource resource); + /** + * Creates business-groups with certain names when no group in a given resource's context + * with this names already exists. + * @param allNames + * @param description + * @param minParticipants + * @param maxParticipants + * @param waitingListEnabled + * @param autoCloseRanksEnabled + * @param resource + * @return + */ public Set<BusinessGroup> createUniqueBusinessGroupsFor(Set<String> allNames, String description, int minParticipants, int maxParticipants, boolean waitingListEnabled, boolean autoCloseRanksEnabled, OLATResource resource); - public BusinessGroup mergeBusinessGroup(BusinessGroup group); + /** + * Update the business group with the supplied arguments and do it in sync + * @param group + * @param name + * @param desc + * @param minParticipants + * @param maxParticipants + * @return + */ + public BusinessGroup updateBusinessGroup(BusinessGroup group, String name, String desc, Integer minParticipants, Integer maxParticipants); + /** + * Update the business group with the supplied arguments and do it in sync + * @param group + * @param name + * @param description + * @param minParticipants + * @param maxParticipants + * @param waitingList + * @param autoCloseRanks + * @return + */ + public BusinessGroup updateBusinessGroup(final BusinessGroup group, final String name, final String description, + final Integer minParticipants, final Integer maxParticipants, final Boolean waitingList, final Boolean autoCloseRanks); public DisplayMembers getDisplayMembers(BusinessGroup group); public void updateDisplayMembers(BusinessGroup group, DisplayMembers displayMembers); + /** + * Delete a business group from the persistence store + * @param group + */ public void deleteBusinessGroup(BusinessGroup group); + /** + * Delete a business group and send a mail to all users in the group + * @param group + * @param businessPath + * @param deletedBy + * @param locale + * @return + */ + public MailerResult deleteBusinessGroupWithMail(BusinessGroup group, String businessPath, Identity deletedBy, Locale locale); + + public void deleteGroupsAfterLifeCycle(List<BusinessGroup> groups); public List<BusinessGroup> getDeletableGroups(int lastLoginDuration); @@ -78,36 +145,107 @@ public interface BusinessGroupService { public List<BusinessGroup> getGroupsReadyToDelete(int deleteEmailDuration); - public MailerResult deleteBusinessGroupWithMail(BusinessGroup group, String businessPath, Identity deletedBy, Locale locale); - + public String sendDeleteEmailTo(List<BusinessGroup> selectedGroups, MailTemplate mailTemplate, boolean isTemplateChanged, String keyEmailSubject, String keyEmailBody, Identity sender, Translator pT); + /** + * Set certain business-group as active (set last-usage and delete time stamp for + * 'SEND_DELETE_EMAIL_ACTION' in LifeCycleManager): + * @param group + * @return + */ public BusinessGroup setLastUsageFor(BusinessGroup group); - + + /** + * Reload the business group + * @param group + * @return The reloaded business group + */ public BusinessGroup loadBusinessGroup(BusinessGroup group); + /** + * Reload the business group + * @param key + * @return The reloaded business group + */ public BusinessGroup loadBusinessGroup(Long key); + /** + * Load business groups by keys + * @param keys + * @return The list of business groups + */ public List<BusinessGroup> loadBusinessGroups(Collection<Long> keys); + /** + * Load all business groups (be cautious, it takes lot of times) + * @return The list of all business groups + */ public List<BusinessGroup> loadAllBusinessGroups(); + /** + * Load the business group by it's OLAT resource + * @param resource + * @return The business group + */ public BusinessGroup loadBusinessGroup(OLATResource resource); - + + /** + * Create and persist a new business group based on a source group. + * @param sourceBusinessGroup The group that will be used as the source group and everything + * @param targetName + * @param targetDescription + * @param targetMin + * @param targetMax + * @param targetResource + * @param areaLookupMap The area lookup map (the target group will references + * mapped areas) or null (target group will reference the same areas + * as the original group) + * @param copyAreas + * @param copyCollabToolConfig + * @param copyRights + * @param copyOwners + * @param copyParticipants + * @param copyMemberVisibility + * @param copyWaitingList + * @return The copied business group + */ public BusinessGroup copyBusinessGroup(BusinessGroup sourceBusinessGroup, String targetName, String targetDescription, Integer targetMin, Integer targetMax, OLATResource targetResource, Map<BGArea,BGArea> areaLookupMap, boolean copyAreas, boolean copyCollabToolConfig, boolean copyRights, boolean copyOwners, boolean copyParticipants, boolean copyMemberVisibility, boolean copyWaitingList); - - - + //search methods + /** + * Find the business group associated with this security group + * @param secGroup + * @return Return the business group or null if not found + */ public BusinessGroup findBusinessGroup(SecurityGroup secGroup); + /** + * Find the BusinessGroups list associated with the supplied identity, where the identity is an owner. + * @param identity + * @param resource + * @return + */ public List<BusinessGroup> findBusinessGroupsOwnedBy(Identity identity, OLATResource resource); + /** + * Find the list of BusinessGroups associated with the supplied identity, where + * the identity is a participant. + * @param identity + * @param resource + * @return + */ public List<BusinessGroup> findBusinessGroupsAttendedBy(Identity identity, OLATResource resource); + /** + * Find all business-groups where the identity is on the waiting-list. + * @param identity + * @param resource + * @return + */ public List<BusinessGroup> findBusinessGroupsWithWaitingListAttendedBy(Identity identity,OLATResource resource); public int countBusinessGroups(SearchBusinessGroupParams params, Identity identity, @@ -117,9 +255,9 @@ public interface BusinessGroupService { boolean ownedById, boolean attendedById, OLATResource resource, int firstResult, int maxResults); //check - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, OLATResource resource); + public boolean checkIfOneOrMoreNameExists(Set<String> names, OLATResource resource); - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, BusinessGroup group); + public boolean checkIfOneOrMoreNameExists(Set<String> names, BusinessGroup group); //retrieve repository entries @@ -145,33 +283,139 @@ public interface BusinessGroupService { public List<Identity> getMembersOf(OLATResource resource, boolean owner, boolean attendee); + /** + * Get position of an identity on a certain waiting-list + * @param identity + * @param businessGroup + * @return + */ public int getPositionInWaitingListFor(Identity identity, BusinessGroup businessGroup); //memberships - public void addOwner(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags); - + /** + * Adds a user to a group as owner and does all the magic that needs to be + * done: - add to security group (optional) - add to jabber roster - fire multi user event + * @param ureqIdentity + * @param addIdentities The users who should be added + * @param group + * @param flags + * @return + */ public BusinessGroupAddResponse addOwners(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup group, BGConfigFlags flags); - public void removeOwners(Identity ureqIdentity, Collection<Identity> identitiesToRemove, BusinessGroup currBusinessGroup, BGConfigFlags flags); + /** + * Remove a list of users from a group as owner and does all the magic that needs to be + * done: - remove from security group (optional) - remove from jabber roster - fire + * multi-user event + * @param ureqIdentity + * @param identitiesToRemove + * @param group + * @param flags + */ + public void removeOwners(Identity ureqIdentity, Collection<Identity> identitiesToRemove, BusinessGroup group, BGConfigFlags flags); - + /** + * Adds a user to a group as participant and does all the magic that needs to + * be done: - add to security group (optional) - add to jabber roster - fire + * multi-user event + * @param ureqIdentity + * @param identityToAdd The user who should be added + * @param group + * @param flags + */ public void addParticipant(Identity ureqIdentity, Identity identityToAdd, BusinessGroup group, BGConfigFlags flags); + /** + * Adds a list of users to a group as participant and does all the magic that needs to + * be done: - add to security group (optional) - add to jabber roster - fire multi-user + * event + * @param ureqIdentity + * @param addIdentities The users who should be added + * @param currBusinessGroup + * @param flags + * @return + */ public BusinessGroupAddResponse addParticipants(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + /** + * Remove a user from a group as participant and does all the magic that needs + * to be done: - remove from security group (optional) - remove from jabber roster - + * fire multi-user event + * @param ureqIdentity + * @param identity The user who should be removed + * @param group + * @param flags + */ public void removeParticipant(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags); + /** + * Remove a list of users from a group as participant and does all the magic that needs + * to be done: - remove from secgroup (optional) - remove from jabber roster - + * fire multi-user event + * @param ureqIdentity + * @param identities The user who should be removed + * @param group + * @param flags + */ public void removeParticipants(Identity ureqIdentity, List<Identity> identities, BusinessGroup group, BGConfigFlags flags); - + /** + * Adds a user to a waiting-list of a group and does all the magic that needs to + * be done: - add to security group (optional) - add to jabber roster - send + * notification email - fire multi-user event + * @param ureqIdentity + * @param identity + * @param group + */ public void addToWaitingList(Identity ureqIdentity, Identity identity, BusinessGroup group); + /** + * Adds a list of users to a waiting-list of a group and does all the magic that needs to + * be done: - add to security group (optional) - add to jabber roster - send + * notification email - fire multi user event + * @param ureqIdentity + * @param addIdentities + * @param currBusinessGroup + * @param flags + * @return + */ public BusinessGroupAddResponse addToWaitingList(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + + + /** + * Remove a user from a waiting-list as participant and does all the magic that needs + * to be done:<br/> + * - remove from security group (optional) <br/> + * - send notification email<br/> + * - fire multi user event + * @param ureqIdentity + * @param identity + * @param waitingListGroup + */ public void removeFromWaitingList(Identity ureqIdentity, Identity identity, BusinessGroup waitingListGroup); + /** + * Remove a list of users from a waiting-list as participant and does all the magic that needs + * to be done: + * - remove from security group (optional)<br/> + * - send notification email<br/> + * - fire multi-user event + * @param ureqIdentity + * @param identities + * @param currBusinessGroup + * @param flags + */ public void removeFromWaitingList(Identity ureqIdentity, List<Identity> identities, BusinessGroup currBusinessGroup, BGConfigFlags flags); + /** + * Move users from a waiting-list to participant-list. + * @param identities + * @param ureqIdentity + * @param currBusinessGroup + * @param flags + * @return + */ public BusinessGroupAddResponse moveIdentityFromWaitingListToParticipant(List<Identity> identities, Identity ureqIdentity, BusinessGroup currBusinessGroup, BGConfigFlags flags); @@ -183,22 +427,48 @@ public interface BusinessGroupService { //security + /** + * Checks if an identity is in a specific business group, either as owner or + * as participant + * @param identity + * @param businessGroup + * @return + */ public boolean isIdentityInBusinessGroup(Identity identity, BusinessGroup businessGroup); + /** + * Checks if an identity is in the list of business groups either as owner or as participant + * @param identity + * @param businessGroups + * @return The list of group keys where the identity is either participant or owner + */ public List<Long> isIdentityInBusinessGroups(Identity identity, List<BusinessGroup> businessGroups); + /** - * + * Checks if an identity is in a business group with a specific name (exact match), either as owner or + * as participant * @param identity * @param groupName + * @param ownedById + * @param attendedById * @param resource * @return */ public boolean isIdentityInBusinessGroup(Identity identity, String groupName, boolean ownedById, boolean attendedById, OLATResource resource); - //export - import + /** + * Export group definitions to file. + * @param groups + * @param fExportFile + */ public void exportGroups(List<BusinessGroup> groups, File fExportFile); + /** + * Import previously exported group definitions. + * @param resource + * @param fGroupExportXML + */ public void importGroups(OLATResource resource, File fGroupExportXML); public void archiveGroups(List<BusinessGroup> groups, File exportFile); diff --git a/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java b/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java index 229c9318c9cddd524e6f52dbd76c819823f19231..bdab7b06ba6fb81b2f669770671c20320b0b1049 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupArchiver.java @@ -54,7 +54,6 @@ import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; import org.olat.group.area.BGArea; import org.olat.group.area.BGAreaManager; -import org.olat.group.context.BGContext; import org.olat.resource.OLATResource; import org.olat.user.UserManager; import org.olat.user.propertyhandlers.UserPropertyHandler; diff --git a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java index ef1a87c141e2e72349f027859b45b002284030a8..0ef4ea6727d3e734631b4b03ebf134fd9037a621 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java @@ -31,8 +31,11 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import javax.annotation.PostConstruct; + import org.hibernate.ObjectNotFoundException; import org.hibernate.StaleObjectStateException; +import org.olat.admin.user.delete.service.UserDeletionManager; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.Constants; @@ -87,6 +90,7 @@ import org.olat.repository.RepositoryManager; import org.olat.resource.OLATResource; import org.olat.resource.OLATResourceImpl; import org.olat.testutils.codepoints.server.Codepoint; +import org.olat.user.UserDataDeletable; import org.olat.util.logging.activity.LoggingResourceable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -98,7 +102,7 @@ import org.springframework.transaction.annotation.Transactional; * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com */ @Service("businessGroupService") -public class BusinessGroupServiceImpl implements BusinessGroupService { +public class BusinessGroupServiceImpl implements BusinessGroupService, UserDataDeletable { private final OLog log = Tracing.createLoggerFor(BusinessGroupServiceImpl.class); @Autowired @@ -121,10 +125,15 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { private BusinessGroupDeletionManager businessGroupDeletionManager; @Autowired private BusinessGroupPropertyDAO businessGroupPropertyManager; + @Autowired + private UserDeletionManager userDeletionManager; - private List<DeletableGroupData> deleteListeners = new ArrayList<DeletableGroupData>(); + @PostConstruct + public void init() { + userDeletionManager.registerDeletableUserData(this); + } public void registerDeletableGroupDataListener(DeletableGroupData listener) { this.deleteListeners.add(listener); @@ -141,6 +150,35 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { return deletableList; } + @Override + public void deleteUserData(Identity identity, String newDeletedUserName) { + // remove as Participant + List<BusinessGroup> attendedGroups = findBusinessGroupsAttendedBy(identity, null); + for (Iterator<BusinessGroup> iter = attendedGroups.iterator(); iter.hasNext();) { + securityManager.removeIdentityFromSecurityGroup(identity, iter.next().getPartipiciantGroup()); + } + log.debug("Remove partipiciant identity=" + identity + " from " + attendedGroups.size() + " groups"); + // remove from waitinglist + List<BusinessGroup> waitingGroups = findBusinessGroupsWithWaitingListAttendedBy(identity, null); + for (Iterator<BusinessGroup> iter = waitingGroups.iterator(); iter.hasNext();) { + securityManager.removeIdentityFromSecurityGroup(identity, iter.next().getWaitingGroup()); + } + log.debug("Remove from waiting-list identity=" + identity + " in " + waitingGroups.size() + " groups"); + + // remove as owner + List<BusinessGroup> ownerGroups = findBusinessGroupsOwnedBy(identity, null); + for (Iterator<BusinessGroup> iter = ownerGroups.iterator(); iter.hasNext();) { + BusinessGroup businessGroup = iter.next(); + securityManager.removeIdentityFromSecurityGroup(identity, businessGroup.getOwnerGroup()); + if (securityManager.countIdentitiesOfSecurityGroup(businessGroup.getOwnerGroup()) == 0) { + securityManager.addIdentityToSecurityGroup(userDeletionManager.getAdminIdentity(), businessGroup.getOwnerGroup()); + log.info("Delete user-data, add Administrator-identity as owner of businessGroup=" + businessGroup.getName()); + } + } + log.debug("Remove owner identity=" + identity + " from " + ownerGroups.size() + " groups"); + log.debug("All entries in groups deleted for identity=" + identity); + } + @Override public BusinessGroup createBusinessGroup(Identity creator, String name, String description, int minParticipants, int maxParticipants, boolean waitingListEnabled, boolean autoCloseRanksEnabled, @@ -172,7 +210,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { //o_clusterOK by:cg Set<BusinessGroup> createdGroups = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(resource, new SyncerCallback<Set<BusinessGroup>>(){ public Set<BusinessGroup> execute() { - if(checkIfOneOrMoreNameExistsInContext(allNames, resource)){ + if(checkIfOneOrMoreNameExists(allNames, resource)){ // set error of non existing name return null; } else { @@ -192,8 +230,47 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { @Override @Transactional - public BusinessGroup mergeBusinessGroup(BusinessGroup group) { - return businessGroupDAO.merge(group); + public BusinessGroup updateBusinessGroup(final BusinessGroup group, final String name, final String description, + final Integer minParticipants, final Integer maxParticipants) { + + return CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerCallback<BusinessGroup>() { + public BusinessGroup execute() { + // refresh group to prevent stale object exception and context proxy issues + BusinessGroup bg = loadBusinessGroup(group); + bg.setName(name); + bg.setDescription(description); + bg.setMaxParticipants(minParticipants); + bg.setMinParticipants(maxParticipants); + bg.setLastUsage(new Date(System.currentTimeMillis())); + LifeCycleManager.createInstanceFor(bg).deleteTimestampFor(BusinessGroupService.SEND_DELETE_EMAIL_ACTION); + return businessGroupDAO.merge(bg); + } + }); + } + + public BusinessGroup updateBusinessGroup(final BusinessGroup group, final String name, final String description, + final Integer minParticipants, final Integer maxParticipants, final Boolean waitingList, final Boolean autoCloseRanks) { + + return CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerCallback<BusinessGroup>() { + public BusinessGroup execute() { + // refresh group to prevent stale object exception and context proxy issues + BusinessGroup bg = loadBusinessGroup(group); + bg.setName(name); + bg.setDescription(description); + bg.setMaxParticipants(new Integer(minParticipants)); + bg.setMinParticipants(new Integer(maxParticipants)); + bg.setWaitingListEnabled(waitingList); + if (waitingList.booleanValue() && (bg.getWaitingGroup() == null) ) { + // Waitinglist is enabled but not created => Create waitingGroup + SecurityGroup waitingGroup = securityManager.createAndPersistSecurityGroup(); + bg.setWaitingGroup(waitingGroup); + } + bg.setAutoCloseRanksEnabled(autoCloseRanks); + bg.setLastUsage(new Date(System.currentTimeMillis())); + LifeCycleManager.createInstanceFor(bg).deleteTimestampFor(BusinessGroupService.SEND_DELETE_EMAIL_ACTION); + return businessGroupDAO.merge(bg); + } + }); } @Override @@ -223,7 +300,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { BusinessGroup reloadedBusinessGroup = loadBusinessGroup(group); reloadedBusinessGroup.setLastUsage(new Date()); LifeCycleManager.createInstanceFor(reloadedBusinessGroup).deleteTimestampFor(SEND_DELETE_EMAIL_ACTION); - return mergeBusinessGroup(reloadedBusinessGroup); + return businessGroupDAO.merge(reloadedBusinessGroup); } catch(DBRuntimeException e) { if(e.getCause() instanceof ObjectNotFoundException) { //group deleted @@ -266,12 +343,12 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { } @Override - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, OLATResource resource) { + public boolean checkIfOneOrMoreNameExists(Set<String> names, OLATResource resource) { return businessGroupRelationDAO.checkIfOneOrMoreNameExistsInContext(names, resource); } @Override - public boolean checkIfOneOrMoreNameExistsInContext(Set<String> names, BusinessGroup group) { + public boolean checkIfOneOrMoreNameExists(Set<String> names, BusinessGroup group) { return businessGroupRelationDAO.checkIfOneOrMoreNameExistsInContext(names, group); } @@ -546,6 +623,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { } private void removeFromRepositoryEntrySecurityGroup(BusinessGroup group) { + //TODO /* BGContext context = group.getGroupContext(); if(context == null) return;//nothing to do @@ -592,30 +670,6 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { return businessGroupRelationDAO.getMembersOf(resource, owner, attendee); } - @Override - public void addOwner(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags) { - //fxdiff VCRP-1,2: access control of resources - List<RepositoryEntry> res = businessGroupRelationDAO.findRepositoryEntries(Collections.singletonList(group), 0, 1); - for(RepositoryEntry re:res) { - if(re.getTutorGroup() == null) { - repositoryManager.createTutorSecurityGroup(re); - repositoryManager.updateRepositoryEntry(re); - } - if(re.getTutorGroup() != null && !securityManager.isIdentityInSecurityGroup(identity, re.getTutorGroup())) { - securityManager.addIdentityToSecurityGroup(identity, re.getTutorGroup()); - } - } - securityManager.addIdentityToSecurityGroup(identity, group.getOwnerGroup()); - - // add user to buddies rosters - addToRoster(ureqIdentity, identity, group, flags); - // notify currently active users of this business group - BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.IDENTITY_ADDED_EVENT, group, identity); - // do logging - ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_OWNER_ADDED, getClass(), LoggingResourceable.wrap(group), LoggingResourceable.wrap(identity)); - // send notification mail in your controller! - } - @Override public BusinessGroupAddResponse addOwners(Identity ureqIdentity, List<Identity> addIdentities, BusinessGroup group, BGConfigFlags flags) { BusinessGroupAddResponse response = new BusinessGroupAddResponse(); @@ -639,6 +693,29 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { return response; } + private void addOwner(Identity ureqIdentity, Identity identity, BusinessGroup group, BGConfigFlags flags) { + //fxdiff VCRP-1,2: access control of resources + List<RepositoryEntry> res = businessGroupRelationDAO.findRepositoryEntries(Collections.singletonList(group), 0, 1); + for(RepositoryEntry re:res) { + if(re.getTutorGroup() == null) { + repositoryManager.createTutorSecurityGroup(re); + repositoryManager.updateRepositoryEntry(re); + } + if(re.getTutorGroup() != null && !securityManager.isIdentityInSecurityGroup(identity, re.getTutorGroup())) { + securityManager.addIdentityToSecurityGroup(identity, re.getTutorGroup()); + } + } + securityManager.addIdentityToSecurityGroup(identity, group.getOwnerGroup()); + + // add user to buddies rosters + addToRoster(ureqIdentity, identity, group, flags); + // notify currently active users of this business group + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.IDENTITY_ADDED_EVENT, group, identity); + // do logging + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_OWNER_ADDED, getClass(), LoggingResourceable.wrap(group), LoggingResourceable.wrap(identity)); + // send notification mail in your controller! + } + @Override public void addParticipant(Identity ureqIdentity, Identity identityToAdd, BusinessGroup group, BGConfigFlags flags) { CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(group); diff --git a/src/main/java/org/olat/group/right/BGRightManager.java b/src/main/java/org/olat/group/right/BGRightManager.java index 72287e605d5dffee8d6809641e0af15ff061aca2..2ba3fe1cf2086336c4549724a68843732f729db0 100644 --- a/src/main/java/org/olat/group/right/BGRightManager.java +++ b/src/main/java/org/olat/group/right/BGRightManager.java @@ -48,7 +48,9 @@ public interface BGRightManager { public static final String BG_RIGHT_PREFIX = "bgr."; /** - * Add a business group right to a business group + * Add a business group right to a business group. Don't forget + * that a right for business group must start with "bgr." and + * that a right must not be longer as 16 characters. * * @param bgRight * @param rightGroup @@ -63,19 +65,12 @@ public interface BGRightManager { */ public abstract void removeBGRight(String bgRight, BusinessGroup rightGroup); - /** - * @param bgRight - * @param rightGroup - * @return true if a group has this business group right, false otherwhise - */ - // public abstract boolean hasBGRight(String bgRight, BusinessGroup - // rightGroup); /** * @param bgRight * @param identity - * @param bgContext + * @param resource * @return true if an identity is in a group that has this business group - * right in the given group context + * right in the given resource */ public abstract boolean hasBGRight(String bgRight, Identity identity, OLATResource resource); diff --git a/src/main/java/org/olat/group/right/BGRightManagerImpl.java b/src/main/java/org/olat/group/right/BGRightManagerImpl.java index 65e14c946f9444cda2d8998a0186c975baa35f14..d8d976c790845d6e3ab2a50ae9d36ae9d4229679 100644 --- a/src/main/java/org/olat/group/right/BGRightManagerImpl.java +++ b/src/main/java/org/olat/group/right/BGRightManagerImpl.java @@ -76,10 +76,6 @@ public class BGRightManagerImpl extends BasicManager implements BGRightManager { } } - /** - * @see org.olat.group.right.BGRightManager#hasBGRight(java.lang.String, - * org.olat.core.id.Identity, org.olat.group.context.BGContext) - */ public boolean hasBGRight(String bgRight, Identity identity, OLATResource resource) { return securityManager.isIdentityPermittedOnResourceable(identity, bgRight, resource); } diff --git a/src/main/java/org/olat/group/ui/BusinessGroupFormController.java b/src/main/java/org/olat/group/ui/BusinessGroupFormController.java index e97a69305d79874a75ad0ae7d270c257b61aae91..28e3105481d1a34331ae34b5cfc870651a0c1ca2 100644 --- a/src/main/java/org/olat/group/ui/BusinessGroupFormController.java +++ b/src/main/java/org/olat/group/ui/BusinessGroupFormController.java @@ -341,7 +341,7 @@ public class BusinessGroupFormController extends FormBasicController { names.add(businessGroupName.getValue()); //group name changes to an already used name, and is a learning group if(businessGroup!=null && !businessGroup.getName().equals(businessGroupName.getValue()) - && businessGroupService.checkIfOneOrMoreNameExistsInContext(names, businessGroup)) { + && businessGroupService.checkIfOneOrMoreNameExists(names, businessGroup)) { return true; } return false; diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java index 92408d7908b21e910a6c70055a428b8ed86b6a78..61ec990bc3bbf70156738dea5bd11dc6a0bbf43b 100644 --- a/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java +++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java @@ -26,7 +26,6 @@ package org.olat.group.ui.edit; import java.util.Collections; -import java.util.Date; import java.util.Iterator; import java.util.List; @@ -36,13 +35,10 @@ import org.olat.admin.securitygroup.gui.IdentitiesAddEvent; import org.olat.admin.securitygroup.gui.IdentitiesMoveEvent; import org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent; import org.olat.admin.securitygroup.gui.WaitingGroupController; -import org.olat.basesecurity.BaseSecurity; -import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.SecurityGroup; import org.olat.collaboration.CollaborationTools; import org.olat.collaboration.CollaborationToolsFactory; import org.olat.collaboration.CollaborationToolsSettingsController; -import org.olat.commons.lifecycle.LifeCycleManager; import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; @@ -68,7 +64,6 @@ import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; import org.olat.core.util.Util; import org.olat.core.util.coordinate.CoordinatorManager; import org.olat.core.util.coordinate.LockResult; -import org.olat.core.util.coordinate.SyncerCallback; import org.olat.core.util.event.GenericEventListener; import org.olat.core.util.mail.MailContext; import org.olat.core.util.mail.MailContextImpl; @@ -404,40 +399,16 @@ public class BusinessGroupEditController extends BasicController implements Cont /** * persist the updates */ - //TODO gm private BusinessGroup updateBusinessGroup() { - final BusinessGroup businessGroup = currBusinessGroup; - return CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(businessGroup, new SyncerCallback<BusinessGroup>() { - public BusinessGroup execute() { - // refresh group to prevent stale object exception and context proxy issues - BusinessGroup bg = businessGroupService.loadBusinessGroup(businessGroup); - String bgName = modifyBusinessGroupController.getGroupName(); - String bgDesc = modifyBusinessGroupController.getGroupDescription(); - Integer bgMax = modifyBusinessGroupController.getGroupMax(); - Integer bgMin = modifyBusinessGroupController.getGroupMin(); - Boolean waitingListEnabled = modifyBusinessGroupController.isWaitingListEnabled(); - Boolean autoCloseRanksEnabled = modifyBusinessGroupController.isAutoCloseRanksEnabled(); - - bg.setName(bgName); - bg.setDescription(bgDesc); - bg.setMaxParticipants(bgMax); - bg.setMinParticipants(bgMin); - bg.setWaitingListEnabled(waitingListEnabled); - if (waitingListEnabled.booleanValue() && (bg.getWaitingGroup() == null) ) { - // Waitinglist is enabled but not created => Create waitingGroup - BaseSecurity securityManager = BaseSecurityManager.getInstance(); - SecurityGroup waitingGroup = securityManager.createAndPersistSecurityGroup(); - bg.setWaitingGroup(waitingGroup); - } - bg.setAutoCloseRanksEnabled(autoCloseRanksEnabled); - bg.setLastUsage(new Date(System.currentTimeMillis())); - LifeCycleManager.createInstanceFor(bg).deleteTimestampFor(BusinessGroupService.SEND_DELETE_EMAIL_ACTION); - // switch on/off waiting-list in member tab - vc_tab_grpmanagement.contextPut("hasWaitingGrp", waitingListEnabled); - - return businessGroupService.mergeBusinessGroup(bg); - } - }); + String bgName = modifyBusinessGroupController.getGroupName(); + String bgDesc = modifyBusinessGroupController.getGroupDescription(); + Integer bgMax = modifyBusinessGroupController.getGroupMax(); + Integer bgMin = modifyBusinessGroupController.getGroupMin(); + Boolean waitingListEnabled = modifyBusinessGroupController.isWaitingListEnabled(); + Boolean autoCloseRanksEnabled = modifyBusinessGroupController.isAutoCloseRanksEnabled(); + vc_tab_grpmanagement.contextPut("hasWaitingGrp", waitingListEnabled); + return businessGroupService.updateBusinessGroup(currBusinessGroup, bgName, bgDesc, + bgMin, bgMax, waitingListEnabled, autoCloseRanksEnabled); } /** @@ -511,7 +482,7 @@ public class BusinessGroupEditController extends BasicController implements Cont */ private VelocityContainer createTabAreas() { VelocityContainer tmp = createVelocityContainer("tab_bgAreas"); - List<BGArea> allAreas = areaManager.findBGAreasOfBusinessGroup(currBusinessGroup); //TODO gm areaManager.findBGAreasOfBGContext(currBusinessGroup.getGroupContext()); + List<BGArea> allAreas = areaManager.findBGAreasOfBusinessGroup(currBusinessGroup); selectedAreas = areaManager.findBGAreasOfBusinessGroup(currBusinessGroup); areaDataModel = new AreasToGroupDataModel(allAreas, selectedAreas); diff --git a/src/main/java/org/olat/restapi/group/LearningGroupWebService.java b/src/main/java/org/olat/restapi/group/LearningGroupWebService.java index ec2f52117ce34fc4b1216f80bb2c451897cef414..cf73834ab712e15853afb4200dc0ab09a31f67c5 100644 --- a/src/main/java/org/olat/restapi/group/LearningGroupWebService.java +++ b/src/main/java/org/olat/restapi/group/LearningGroupWebService.java @@ -216,19 +216,10 @@ public class LearningGroupWebService { return Response.serverError().status(Status.NOT_ACCEPTABLE).build(); } - BusinessGroup savedBg = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(bg, new SyncerCallback<BusinessGroup>(){ - public BusinessGroup execute() { - BusinessGroup reloadedBG = bgs.loadBusinessGroup(bg); - reloadedBG.setName(group.getName()); - reloadedBG.setDescription(group.getDescription()); - reloadedBG.setMinParticipants(normalize(group.getMinParticipants())); - reloadedBG.setMaxParticipants(normalize(group.getMaxParticipants())); - return bgs.mergeBusinessGroup(reloadedBG); - } - }); - + BusinessGroup mergedBg = bgs.updateBusinessGroup(bg, group.getName(), group.getDescription(), + normalize(group.getMinParticipants()), normalize(group.getMaxParticipants())); //save the updated group - GroupVO savedVO = ObjectFactory.get(savedBg); + GroupVO savedVO = ObjectFactory.get(mergedBg); return Response.ok(savedVO).build(); } @@ -489,11 +480,12 @@ public class LearningGroupWebService { if(identity == null || group == null) { return Response.serverError().status(Status.NOT_FOUND).build(); } - + //TODO gm sync CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerCallback<Boolean>(){ public Boolean execute() { BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - bgs.addOwner(ureq.getIdentity(), identity, group, flags); + List<Identity> identityToAdd = Collections.singletonList(identity); + bgs.addOwners(ureq.getIdentity(), identityToAdd, group, flags); return Boolean.TRUE; } });// end of doInSync @@ -548,7 +540,7 @@ public class LearningGroupWebService { if(identity == null || group == null) { return Response.serverError().status(Status.NOT_FOUND).build(); } - + //TODO gm sync CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerCallback<Boolean>(){ public Boolean execute() { BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); @@ -605,7 +597,7 @@ public class LearningGroupWebService { if(identity == null || group == null) { return Response.serverError().status(Status.NOT_FOUND).build(); } - + //TODO gm sync CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerCallback<Boolean>(){ public Boolean execute() { BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); @@ -662,7 +654,7 @@ public class LearningGroupWebService { if(identity == null || group == null) { return Response.serverError().status(Status.NOT_FOUND).build(); } - + //TODO gm sync CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(group, new SyncerExecutor(){ public void execute() { BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); diff --git a/src/test/java/org/olat/group/test/BGRightManagerTest.java b/src/test/java/org/olat/group/test/BGRightManagerTest.java index 6a5e5204178329f3ade4e0bbc9abeb41a7fb83b6..cde72c59831eacde57b43675c0fd47bf06cf79d1 100644 --- a/src/test/java/org/olat/group/test/BGRightManagerTest.java +++ b/src/test/java/org/olat/group/test/BGRightManagerTest.java @@ -30,6 +30,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.List; +import java.util.UUID; import junit.framework.Assert; @@ -40,8 +41,10 @@ import org.junit.Test; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.Policy; import org.olat.basesecurity.SecurityGroup; +import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.id.Identity; +import org.olat.core.logging.AssertException; import org.olat.course.groupsandrights.CourseRights; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; @@ -62,6 +65,8 @@ public class BGRightManagerTest extends OlatTestCase { private static Logger log = Logger.getLogger(BGRightManagerTest.class.getName()); private Identity id1, id2, id3, id4; + @Autowired + private DB dbInstance; @Autowired private BusinessGroupService businessGroupService; @Autowired @@ -102,6 +107,106 @@ public class BGRightManagerTest extends OlatTestCase { throw e; } } + + + /* + + + public abstract void removeBGRight(String bgRight, BusinessGroup rightGroup); + + + */ + + /** + * Test if the add right doesn't generate errors + */ + @Test + public void addRight() { + OLATResource c1 = JunitTestHelper.createRandomResource(); + BusinessGroup g1 = businessGroupService.createBusinessGroup(null, "addRight", null, -1, -1, false, false, c1); + rightManager.addBGRight("test-right", g1); + dbInstance.commitAndCloseSession(); + } + + @Test + public void hasBGRight() { + //create a right for the identity + Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("has-right-" + UUID.randomUUID().toString()); + OLATResource resource = JunitTestHelper.createRandomResource(); + BusinessGroup group = businessGroupService.createBusinessGroup(null, "hasBGRight", null, -1, -1, false, false, resource); + securityManager.addIdentityToSecurityGroup(identity, group.getPartipiciantGroup()); + rightManager.addBGRight("bgr.has-right", group); + dbInstance.commitAndCloseSession(); + + //check if the right is set + boolean right = rightManager.hasBGRight("bgr.has-right", identity, resource); + Assert.assertTrue(right); + //check if a dummy is not set + boolean notright = rightManager.hasBGRight("bgrblabla", identity, resource); + Assert.assertFalse(notright); + } + + @Test + public void findBGRights() { + //create 2 rights for the identity + Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("find-rights-" + UUID.randomUUID().toString()); + OLATResource resource = JunitTestHelper.createRandomResource(); + BusinessGroup group = businessGroupService.createBusinessGroup(null, "findBGRights", null, -1, -1, false, false, resource); + securityManager.addIdentityToSecurityGroup(identity, group.getPartipiciantGroup()); + rightManager.addBGRight("bgr.findright1", group); + rightManager.addBGRight("bgr.findright2", group); + dbInstance.commitAndCloseSession(); + + //check if the rights are set + List<String> rights = rightManager.findBGRights(group); + Assert.assertNotNull(rights); + Assert.assertEquals(2, rights.size()); + Assert.assertTrue(rights.contains("bgr.findright1")); + Assert.assertTrue(rights.contains("bgr.findright2")); + } + + @Test + public void removeBGRight() { + //create 2 rights for the identity + Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("remove-rights-" + UUID.randomUUID().toString()); + OLATResource resource = JunitTestHelper.createRandomResource(); + BusinessGroup group = businessGroupService.createBusinessGroup(null, "removeBGRight", null, -1, -1, false, false, resource); + securityManager.addIdentityToSecurityGroup(identity, group.getPartipiciantGroup()); + rightManager.addBGRight("bgr.removeright1", group); + rightManager.addBGRight("bgr.removeright2", group); + dbInstance.commitAndCloseSession(); + + //check if the rights are set + List<String> rights = rightManager.findBGRights(group); + Assert.assertEquals(2, rights.size()); + Assert.assertTrue(rightManager.hasBGRight("bgr.removeright1", identity, resource)); + Assert.assertTrue(rightManager.hasBGRight("bgr.removeright2", identity, resource)); + + //remove right 1 + rightManager.removeBGRight("bgr.removeright1", group); + dbInstance.commitAndCloseSession(); + + //check if there is only 1 right + List<String> rightsAfterDelete = rightManager.findBGRights(group); + Assert.assertEquals(1, rightsAfterDelete.size()); + Assert.assertTrue(rightsAfterDelete.contains("bgr.removeright2")); + Assert.assertFalse(rightManager.hasBGRight("bgr.removeright1", identity, resource)); + Assert.assertTrue(rightManager.hasBGRight("bgr.removeright2", identity, resource)); + } + + @Test(expected=AssertException.class) + public void removeUnkownRight() { + //create 2 rights for the identity + Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("remove-rights-" + UUID.randomUUID().toString()); + OLATResource resource = JunitTestHelper.createRandomResource(); + BusinessGroup group = businessGroupService.createBusinessGroup(null, "removeBGRight", null, -1, -1, false, false, resource); + securityManager.addIdentityToSecurityGroup(identity, group.getPartipiciantGroup()); + rightManager.addBGRight("bgr.removeright1", group); + dbInstance.commitAndCloseSession(); + + //remove a dummy right which doesn't exists + rightManager.removeBGRight("bgr.removeblabla", group); + } /** BGContextManagerImpl:deleteBGContext() * */ @Test @@ -124,8 +229,6 @@ public class BGRightManagerTest extends OlatTestCase { rightManager.addBGRight(CourseRights.RIGHT_COURSEEDITOR, g3); DBFactory.getInstance().closeSession(); // simulate user clicks - // secm.createAndPersistPolicy(rightGroup.getPartipiciantGroup(), bgRight, - // rightGroup.getGroupContext()); List<SecurityGroup> groups = securityManager.getGroupsWithPermissionOnOlatResourceable(CourseRights.RIGHT_ARCHIVING, c1); Assert.assertEquals(2, groups.size()); diff --git a/src/test/java/org/olat/group/test/BusinessGroupServiceImplTest.java b/src/test/java/org/olat/group/test/BusinessGroupServiceImplTest.java deleted file mode 100644 index 56262fc22b907a02b6835ae4799e31b12adc660a..0000000000000000000000000000000000000000 --- a/src/test/java/org/olat/group/test/BusinessGroupServiceImplTest.java +++ /dev/null @@ -1,591 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <p> -* Licensed under the Apache License, Version 2.0 (the "License"); <br> -* you may not use this file except in compliance with the License.<br> -* You may obtain a copy of the License at -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <p> -* Unless required by applicable law or agreed to in writing,<br> -* software distributed under the License is distributed on an "AS IS" BASIS, <br> -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> -* See the License for the specific language governing permissions and <br> -* limitations under the License. -* <p> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -* <p> -*/ - -package org.olat.group.test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.olat.basesecurity.BaseSecurityManager; -import org.olat.basesecurity.BaseSecurityModule; -import org.olat.basesecurity.SecurityGroup; -import org.olat.basesecurity.SecurityGroupImpl; -import org.olat.collaboration.CollaborationTools; -import org.olat.collaboration.CollaborationToolsFactory; -import org.olat.core.commons.persistence.DBFactory; -import org.olat.core.id.Identity; -import org.olat.core.id.User; -import org.olat.core.logging.OLog; -import org.olat.core.logging.Tracing; -import org.olat.core.util.Encoder; -import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupService; -import org.olat.group.ui.BGConfigFlags; -import org.olat.resource.OLATResource; -import org.olat.test.JunitTestHelper; -import org.olat.test.OlatTestCase; -import org.olat.user.UserManager; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * Description: <BR/> - * <P/> Initial Date: Jul 28, 2004 - * - * @author patrick, srosse - */ - -public class BusinessGroupServiceImplTest extends OlatTestCase { - // - private static OLog log = Tracing.createLoggerFor(BusinessGroupServiceImplTest.class); - /* - * ::Test Setup:: - */ - private static Identity id1 = null; - private static Identity id2 = null; - private static Identity id3 = null; - private static Identity id4 = null; - // For WaitingGroup tests - private static Identity wg1 = null; - private static Identity wg2 = null; - private static Identity wg3 = null; - private static Identity wg4 = null; - - /* - * BuddyGroup one - */ - private static BusinessGroup one = null; - private String oneName = "First BuddyGroup"; - private String oneDesc = "some short description for first buddygroup"; - // private String oneIntr = "bla blusch blip blup blep"; - /* - * BuddyGroup two - */ - private static BusinessGroup two = null; - private String twoName = "Second BuddyGroup"; - private String twoDesc = "some short description for second buddygroup"; - // private String twoIntr = "notting"; - /* - * BuddyGroup three - */ - private static BusinessGroup three = null; - private String threeName = "Third BuddyGroup"; - private String threeDesc = "some short description for second buddygroup"; - // private String threeIntr = "notting more"; - // - private static final int NROFTESTCASES = 3; - private static int nrOfTestCasesAlreadyRun = 0; - private static boolean suiteIsAborted = true; - // For WaitingGroup tests - private static BusinessGroup bgWithWaitingList = null; - - - @Autowired - private BusinessGroupService businessGroupService; - - private static boolean initialize = false; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Before - public void setUp() throws Exception { - if(initialize) return; - - // Identities - id1 = JunitTestHelper.createAndPersistIdentityAsUser("id1-bgs-" + UUID.randomUUID().toString()); - id2 = JunitTestHelper.createAndPersistIdentityAsUser("id2-bgs-" + UUID.randomUUID().toString()); - id3 = JunitTestHelper.createAndPersistIdentityAsUser("id3-bgs-" + UUID.randomUUID().toString()); - id4 = JunitTestHelper.createAndPersistIdentityAsUser("id4-bgs-" + UUID.randomUUID().toString()); - // buddyGroups without waiting-list: groupcontext is null - List<BusinessGroup> l = businessGroupService.findBusinessGroupsOwnedBy(id1, null); - if (l.size() == 0) { - one = businessGroupService.createBusinessGroup(id1, oneName, oneDesc, -1, -1, false, false, null); - } else { - List<BusinessGroup> groups = businessGroupService.findBusinessGroupsOwnedBy(id1, null); - for(BusinessGroup group:groups) { - if(oneName.equals(group.getName())) { - one = group; - } - } - } - l = businessGroupService.findBusinessGroupsOwnedBy(id2, null); - if (l.size() == 0) { - two = businessGroupService.createBusinessGroup(id2, twoName, twoDesc, -1, -1, false, false, null); - SecurityGroup twoPartips = two.getPartipiciantGroup(); - BaseSecurityManager.getInstance().addIdentityToSecurityGroup(id3, twoPartips); - BaseSecurityManager.getInstance().addIdentityToSecurityGroup(id4, twoPartips); - } else { - two = businessGroupService.findBusinessGroupsOwnedBy(id2, null).get(0); - } - l = businessGroupService.findBusinessGroupsOwnedBy(id3, null); - if (l.size() == 0) { - three = businessGroupService.createBusinessGroup(id3, threeName, threeDesc, -1, -1, false, false, null); - SecurityGroup threeOwner = three.getOwnerGroup(); - SecurityGroup threeOPartips = three.getPartipiciantGroup(); - BaseSecurityManager.getInstance().addIdentityToSecurityGroup(id2, threeOPartips); - BaseSecurityManager.getInstance().addIdentityToSecurityGroup(id1, threeOwner); - } else { - three = businessGroupService.findBusinessGroupsOwnedBy(id3, null).get(0); - } - /* - * Membership in ParticipiantGroups............................. id1 - * owns BuddyGroup one with participiantGroup:={}........... id2 owns - * BuddyGroup two with participiantGroup:={id3,id4} id3 owns BuddyGroup - * three participiantGroup:={id2}, ownerGroup:={id3,id1} - */ - - DBFactory.getInstance().closeSession(); - - // create business-group with waiting-list - String bgWithWaitingListName = "Group with WaitingList"; - String bgWithWaitingListDesc = "some short description for Group with WaitingList"; - Boolean enableWaitinglist = new Boolean(true); - Boolean enableAutoCloseRanks = new Boolean(true); - OLATResource resource = JunitTestHelper.createRandomResource(); - System.out.println("testAddToWaitingListAndFireEvent: resource=" + resource); - bgWithWaitingList = businessGroupService.createBusinessGroup(id1, bgWithWaitingListName, - bgWithWaitingListDesc, -1, -1, enableWaitinglist, enableAutoCloseRanks, resource); - bgWithWaitingList.setMaxParticipants(new Integer(2)); - // Identities - String suffix = UUID.randomUUID().toString(); - User UserWg1 = UserManager.getInstance().createAndPersistUser("FirstName_" + suffix, "LastName_" + suffix, suffix + "_junittest@olat.unizh.ch"); - wg1 = BaseSecurityManager.getInstance().createAndPersistIdentity(suffix, UserWg1, - BaseSecurityModule.getDefaultAuthProviderIdentifier(), suffix, Encoder.encrypt("wg1")); - suffix = UUID.randomUUID().toString(); - User UserWg2 = UserManager.getInstance().createAndPersistUser("FirstName_" + suffix, "LastName_" + suffix, suffix + "_junittest@olat.unizh.ch"); - wg2 = BaseSecurityManager.getInstance().createAndPersistIdentity(suffix, UserWg2, - BaseSecurityModule.getDefaultAuthProviderIdentifier(), suffix, Encoder.encrypt("wg2")); - suffix = UUID.randomUUID().toString(); - User UserWg3 = UserManager.getInstance().createAndPersistUser("FirstName_" + suffix, "LastName_" + suffix, suffix + "_junittest@olat.unizh.ch"); - wg3 = BaseSecurityManager.getInstance().createAndPersistIdentity(suffix, UserWg3, - BaseSecurityModule.getDefaultAuthProviderIdentifier(), suffix, Encoder.encrypt("wg3")); - suffix = UUID.randomUUID().toString(); - User UserWg4 = UserManager.getInstance().createAndPersistUser("FirstName_" + suffix, "LastName_" + suffix, suffix + "_junittest@olat.unizh.ch"); - wg4 = BaseSecurityManager.getInstance().createAndPersistIdentity(suffix, UserWg4, - BaseSecurityModule.getDefaultAuthProviderIdentifier(), suffix, Encoder.encrypt("wg4")); - - DBFactory.getInstance().closeSession(); - - initialize = true; - } - - @Test - public void testCheckIfNamesExistsInContext() throws Exception { - suiteIsAborted = true; - - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("id5-check-" + UUID.randomUUID().toString()); - - OLATResource ctxA = JunitTestHelper.createRandomResource(); - OLATResource ctxB = JunitTestHelper.createRandomResource(); - - String[] namesInCtxA = new String[] { "A-GroupOne", "A-GroupTwo", "A-GroupThree", "A-GroupFour", "A-GroupFive", "A-GroupSix" }; - String[] namesInCtxB = new String[] { "B-GroupAAA", "B-GroupBBB", "B-GroupCCC", "B-GroupDDD", "B-GroupEEE", "B-GroupFFF" }; - BusinessGroup[] ctxAgroups = new BusinessGroup[namesInCtxA.length]; - BusinessGroup[] ctxBgroups = new BusinessGroup[namesInCtxB.length]; - - for (int i = 0; i < namesInCtxA.length; i++) { - ctxAgroups[i] = businessGroupService.createBusinessGroup(id, namesInCtxA[i], null, 0, 0, false, - false, ctxA); - } - for (int i = 0; i < namesInCtxB.length; i++) { - ctxBgroups[i] = businessGroupService.createBusinessGroup(id, namesInCtxB[i], null, 0, 0, false, - false, ctxB); - } - // first click created two context and each of them containg groups - // evict all created and search - System.out.println("Test: ctxAgroups.length=" + ctxAgroups.length); - for (int i = 0; i < ctxAgroups.length; i++) { - System.out.println("Test: i=" + i); - System.out.println("Test: ctxAgroups[i]=" + ctxAgroups[i]); - } - DBFactory.getInstance().closeSession(); - - // next click needs to check of a set of groupnames already exists. - Set<String> subsetOkInA = new HashSet<String>(); - subsetOkInA.add("A-GroupTwo"); - subsetOkInA.add("A-GroupThree"); - subsetOkInA.add("A-GroupFour"); - - Set<String> subsetNOkInA = new HashSet<String>(); - subsetNOkInA.add("A-GroupTwo"); - subsetNOkInA.add("NOT-IN-A"); - subsetNOkInA.add("A-GroupThree"); - subsetNOkInA.add("A-GroupFour"); - - Set<String> subsetOkInB = new HashSet<String>(); - subsetOkInB.add("B-GroupCCC"); - subsetOkInB.add("B-GroupDDD"); - subsetOkInB.add("B-GroupEEE"); - subsetOkInB.add("B-GroupFFF"); - - Set<String> subsetNOkInB = new HashSet<String>(); - subsetNOkInB.add("B-GroupCCC"); - subsetNOkInB.add("NOT-IN-B"); - subsetNOkInB.add("B-GroupEEE"); - subsetNOkInB.add("B-GroupFFF"); - - Set<String> setSpansAandBNok = new HashSet<String>(); - setSpansAandBNok.add("B-GroupCCC"); - setSpansAandBNok.add("A-GroupTwo"); - setSpansAandBNok.add("A-GroupThree"); - setSpansAandBNok.add("B-GroupEEE"); - setSpansAandBNok.add("B-GroupFFF"); - - boolean allExist = false; - allExist = businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetOkInA, ctxA); - assertTrue("Three A-Group.. should find all", allExist); - // Check : one name does not exist, 3 exist - assertTrue("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetNOkInA, ctxA)); - // Check : no name exist in context - assertFalse("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetOkInB, ctxA)); - // - allExist = businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetOkInB, ctxB); - assertTrue("Three B-Group.. should find all", allExist); - // Check : one name does not exist, 3 exist - assertTrue("A 'NOT-IN-B'.. should not find all", businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetNOkInB, ctxB)); - // Check : no name exist in context - assertFalse("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExistsInContext(subsetOkInA, ctxB)); - // Mix A (2x) and B (3x) - allExist = businessGroupService.checkIfOneOrMoreNameExistsInContext(setSpansAandBNok, ctxA); - assertTrue("Groupnames spanning two context... should not find all in context A", allExist); - // Mix A (2x) and B (3x) - allExist = businessGroupService.checkIfOneOrMoreNameExistsInContext(setSpansAandBNok, ctxB); - assertTrue("Groupnames spanning two context... should not find all in context B", allExist); - // - - suiteIsAborted = false; - nrOfTestCasesAlreadyRun++; - } - - /** - * Test existence of BuddyGroups inserted in the setUp phase................ - * this test rather tests the findXXX methods............................... - * so if the setup was ok, and this test also fulfilled, then it means that - * createAndPersistBuddyGroup works, and also the findXXX methods. - * - * @throws Exception - */ - @Test - public void testCreateAndPersistBuddyGroup() throws Exception { - suiteIsAborted = true; - - // id1 - List<BusinessGroup> groupOwnedId1 = businessGroupService.findBusinessGroupsOwnedBy(id1, null); - Assert.assertEquals("2 BuddyGroups owned by id1", 3, groupOwnedId1.size()); - Assert.assertTrue(groupOwnedId1.contains(one)); - Assert.assertTrue(groupOwnedId1.contains(three)); - Assert.assertTrue(groupOwnedId1.contains(bgWithWaitingList)); - - List<BusinessGroup> groupAttendeeId1 = businessGroupService.findBusinessGroupsAttendedBy(id1, null); - Assert.assertEquals("0 BuddyGroup where id1 is partipicating", 0, groupAttendeeId1.size()); - - // id2 - List<BusinessGroup> groupOwnedId2 = businessGroupService.findBusinessGroupsOwnedBy(id2, null); - Assert.assertEquals("1 BuddyGroup owned by id2", 1, groupOwnedId2.size()); - Assert.assertTrue(groupOwnedId2.contains(two)); - - List<BusinessGroup> groupAttendeeId2 = businessGroupService.findBusinessGroupsAttendedBy(id2, null); - Assert.assertEquals("1 BuddyGroup where id2 is partipicating", 1, groupAttendeeId2.size()); - assertTrue("It's the correct BuddyGroup", groupAttendeeId2.contains(three)); - - // id3 - List<BusinessGroup> groupOwnedId3 = businessGroupService.findBusinessGroupsOwnedBy(id3, null); - Assert.assertEquals("1 BuddyGroup owned by id3", 1, groupOwnedId3.size()); - assertTrue("It's the correct BuddyGroup", groupOwnedId3.contains(three)); - - List<BusinessGroup> groupAttendeeId3 = businessGroupService.findBusinessGroupsAttendedBy(id3, null); - Assert.assertEquals("1 BuddyGroup where id3 is partipicating", 1, groupAttendeeId3.size()); - assertTrue("It's the correct BuddyGroup", groupAttendeeId3.contains(two)); - - // id4 - List<BusinessGroup> groupOwnedId4 = businessGroupService.findBusinessGroupsOwnedBy(id4, null); - Assert.assertEquals("0 BuddyGroup owned by id4", 0, groupOwnedId4.size()); - - List<BusinessGroup> groupAttendeeId4 = businessGroupService.findBusinessGroupsAttendedBy(id4, null); - Assert.assertEquals("1 BuddyGroup where id4 is partipicating", 1, groupAttendeeId4.size()); - assertTrue("It's the correct BuddyGroup", groupAttendeeId4.contains(two)); - - suiteIsAborted = false; - nrOfTestCasesAlreadyRun++; - } - - /** - * checks if tools can be enabled disabled or checked against being enabled. - * TOols are configured with the help of the generic properties storage. - * - * @throws Exception - */ - public void testEnableDisableAndCheckForTool() throws Exception { - suiteIsAborted = true; - /* - * - */ - List<BusinessGroup> sqlRes; - BusinessGroup found; - - /* - * id2 - */ - sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id2, null); - found = (BusinessGroup) sqlRes.get(0); - CollaborationTools myCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(found); - for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { - String msg = "Tool " + CollaborationTools.TOOLS[i] + " is enabled"; - boolean enabled = myCTSMngr.isToolEnabled(CollaborationTools.TOOLS[i]); - // all tools are disabled by default exept the news tool - assertTrue(msg, !enabled); - - } - // - for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { - myCTSMngr.setToolEnabled(CollaborationTools.TOOLS[i], true); - } - // - for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { - String msg = "Tool " + CollaborationTools.TOOLS[i] + " is enabled"; - boolean enabled = myCTSMngr.isToolEnabled(CollaborationTools.TOOLS[i]); - assertTrue(msg, enabled); - - } - // - for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { - myCTSMngr.setToolEnabled(CollaborationTools.TOOLS[i], false); - } - // - for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { - String msg = "Tool " + CollaborationTools.TOOLS[i] + " is disabled"; - boolean enabled = myCTSMngr.isToolEnabled(CollaborationTools.TOOLS[i]); - assertTrue(msg, !enabled); - - } - /* - * - */ - suiteIsAborted = false; - nrOfTestCasesAlreadyRun++; - } - - /** - * test if removing a BuddyGroup really deletes everything it should. - * - * @throws Exception - */ - @Test - public void testDeleteBuddyGroup() throws Exception { - suiteIsAborted = true; - /* - * - */ - List<BusinessGroup> sqlRes; - BusinessGroup found; - - /* - * id2 - */ - sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id2, null); - assertTrue("1 BuddyGroup owned by id2", sqlRes.size() == 1); - found = (BusinessGroup) sqlRes.get(0); - CollaborationTools myCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(found); - // - for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { - myCTSMngr.setToolEnabled(CollaborationTools.TOOLS[i], true); - } - /* - * - */ - businessGroupService.deleteBusinessGroup(found); - sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id2, null); - assertTrue("0 BuddyGroup owned by id2", sqlRes.size() == 0); - /* - * - */ - suiteIsAborted = false; - nrOfTestCasesAlreadyRun++; - } - - // Test for WaitingList - // ///////////////////// - /** - * Add 3 idenities to the waiting list and check the position. before test - * Waitinglist=[]<br> - * after test Waitinglist=[wg2,wg3,wg4] - */ - @Test - public void testAddToWaitingListAndFireEvent() throws Exception { - System.out.println("testAddToWaitingListAndFireEvent: start..."); - // Add wg2 - BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - List<Identity> identities = new ArrayList<Identity>(); - identities.add(wg2); - businessGroupService.addToWaitingList(wg2, identities, bgWithWaitingList, flags); - // Add wg3 - identities = new ArrayList<Identity>(); - identities.add(wg3); - businessGroupService.addToWaitingList(wg3, identities, bgWithWaitingList, flags); - // Add wg4 - identities = new ArrayList<Identity>(); - identities.add(wg4); - businessGroupService.addToWaitingList(wg4, identities, bgWithWaitingList, flags); - System.out.println("testAddToWaitingListAndFireEvent: 3 user added to waiting list"); - - // Check position of 'wg2' - int pos = businessGroupService.getPositionInWaitingListFor(wg2, bgWithWaitingList); - System.out.println("testAddToWaitingListAndFireEvent: wg2 pos=" + pos); - assertTrue("pos must be 1, bit is=" + pos, pos == 1); - // Check position of 'wg3' - pos = businessGroupService.getPositionInWaitingListFor(wg3, bgWithWaitingList); - System.out.println("testAddToWaitingListAndFireEvent wg3: pos=" + pos); - assertTrue("pos must be 2, bit is=" + pos, pos == 2); - // Check position of 'wg4' - pos = businessGroupService.getPositionInWaitingListFor(wg4, bgWithWaitingList); - System.out.println("testAddToWaitingListAndFireEvent wg4: pos=" + pos); - assertTrue("pos must be 3, bit is=" + pos, pos == 3); - } - - /** - * Remove identity 2 (wg3) from the waiting list and check the position of - * identity 2. before test Waitinglist=[wg2,wg3,wg4]<br> - * after test Waitinglist=[wg2,wg4] - */ - @Test - public void testRemoveFromWaitingListAndFireEvent() throws Exception { - System.out.println("testRemoveFromWaitingListAndFireEvent: start..."); - // Remove wg3 - BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - List<Identity> identities = new ArrayList<Identity>(); - identities.add(wg3); - businessGroupService.removeFromWaitingList(wg1, identities, bgWithWaitingList, flags); - // Check position of 'wg2' - int pos = businessGroupService.getPositionInWaitingListFor(wg2, bgWithWaitingList); - System.out.println("testRemoveFromWaitingListAndFireEvent: wg2 pos=" + pos); - assertTrue("pos must be 1, bit is=" + pos, pos == 1); - // Check position of 'wg4' - pos = businessGroupService.getPositionInWaitingListFor(wg4, bgWithWaitingList); - System.out.println("testRemoveFromWaitingListAndFireEvent wg4: pos=" + pos); - assertTrue("pos must be 2, bit is=" + pos, pos == 2); - - } - - /** - * Move identity 4 (wg4) from the waiting list to participant list. before - * test Waitinglist=[wg2,wg4]<br> - * after test Waitinglist=[wg2]<br> - * participant-list=[wg4] - */ - @Test - public void testMoveIdenityFromWaitingListToParticipant() throws Exception { - System.out.println("testMoveIdenityFromWaitingListToParticipant: start..."); - // Check that 'wg4' is not in participant list - assertFalse("Identity is allready in participant-list, remove it(dbsetup?)", businessGroupService - .isIdentityInBusinessGroup(wg4, bgWithWaitingList)); - - // Move wg4 from waiting-list to participant - BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - List<Identity> identities = new ArrayList<Identity>(); - identities.add(wg4); - businessGroupService.moveIdentityFromWaitingListToParticipant(identities, wg1, bgWithWaitingList, flags); - // Check position of 'wg2' - int pos = businessGroupService.getPositionInWaitingListFor(wg2, bgWithWaitingList); - System.out.println("testMoveIdenityFromWaitingListToParticipant: wg2 pos=" + pos); - assertTrue("pos must be 1, bit is=" + pos, pos == 1); - // Check if 'wg4' is in participant-list - assertTrue("Identity is not in participant-list", businessGroupService.isIdentityInBusinessGroup(wg4, bgWithWaitingList)); - } - @Test - public void testMoveRegisteredIdentityFromWaitingToParticipant() throws Exception { - System.out.println("testMoveRegisteredIdentityFromWaitingToParticipant: start..."); - // Add a user to waiting-list which is allready in participant-list and try - // and try to move this user => user will be removed from waiting-list - // Add again wg2 - BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); - List<Identity> identities = new ArrayList<Identity>(); - identities.add(wg1); - businessGroupService.addToWaitingList(wg4, identities, bgWithWaitingList, flags); - identities = new ArrayList<Identity>(); - identities.add(wg4); - businessGroupService.moveIdentityFromWaitingListToParticipant(identities, wg1, bgWithWaitingList, flags); - // Check position of 'wg4' - int pos = businessGroupService.getPositionInWaitingListFor(wg4, bgWithWaitingList); - System.out.println("testMoveIdenityFromWaitingListToParticipant: wg4 pos=" + pos); - assertTrue("pos must be 0, bit is=" + pos, pos == 0); - // Check if 'wg4' is still in participant-list - assertTrue("Identity is not in participant-list", businessGroupService.isIdentityInBusinessGroup(wg4, bgWithWaitingList)); - } - @Test - public void testDeleteBusinessGroupWithWaitingGroup() { - doTestDeleteBusinessGroup(true); - } - @Test - public void testDeleteBusinessGroupWithoutWaitingGroup() { - doTestDeleteBusinessGroup(false); - } - private void doTestDeleteBusinessGroup(boolean withWaitingList) { - OLATResource resource = JunitTestHelper.createRandomResource(); - - BusinessGroup deleteTestGroup = businessGroupService.createBusinessGroup(id1, "deleteTestGroup-1", - "deleteTestGroup-1", -1, -1, withWaitingList, true, resource); - - Long ownerGroupKey = deleteTestGroup.getOwnerGroup().getKey(); - Long partipiciantGroupKey = deleteTestGroup.getPartipiciantGroup().getKey(); - Long waitingGroupKey = deleteTestGroup.getWaitingGroup().getKey(); - - assertNotNull("Could not find owner-group",DBFactory.getInstance().findObject(SecurityGroupImpl.class, ownerGroupKey)); - assertNotNull("Could not find partipiciant-group",DBFactory.getInstance().findObject(SecurityGroupImpl.class, partipiciantGroupKey)); - assertNotNull("Could not find waiting-group",DBFactory.getInstance().findObject(SecurityGroupImpl.class, waitingGroupKey)); - businessGroupService.deleteBusinessGroup(deleteTestGroup); - assertNull("owner-group still exist after delete",DBFactory.getInstance().findObject(SecurityGroupImpl.class, ownerGroupKey)); - assertNull("partipiciant-group still exist after delete",DBFactory.getInstance().findObject(SecurityGroupImpl.class, partipiciantGroupKey)); - assertNull("waiting-group still exist after delete",DBFactory.getInstance().findObject(SecurityGroupImpl.class, waitingGroupKey)); - } - - /** - * @see junit.framework.TestCase#tearDown() - */ - @After - public void tearDown() throws Exception { - try { - if (suiteIsAborted || (NROFTESTCASES - nrOfTestCasesAlreadyRun) == 0) { - // DB.getInstance().clearDatabase(); - } - DBFactory.getInstance().closeSession(); - - } catch (Exception e) { - log.error("tearDown failed: ", e); - } - } -} \ No newline at end of file diff --git a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java index ee5b3b73cfad9b95660c08ec59c57bd549630b88..70f4284134f9de9721fb8843228c5959936f89e0 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java @@ -19,26 +19,43 @@ */ package org.olat.group.test; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.UUID; import junit.framework.Assert; import org.junit.After; +import org.junit.Before; import org.junit.Test; +import org.olat.basesecurity.BaseSecurity; +import org.olat.basesecurity.BaseSecurityModule; +import org.olat.basesecurity.SecurityGroup; +import org.olat.basesecurity.SecurityGroupImpl; +import org.olat.collaboration.CollaborationTools; +import org.olat.collaboration.CollaborationToolsFactory; import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DBFactory; +import org.olat.core.id.Identity; +import org.olat.core.id.User; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; +import org.olat.core.util.Encoder; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; import org.olat.group.model.SearchBusinessGroupParams; +import org.olat.group.ui.BGConfigFlags; import org.olat.resource.OLATResource; import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; +import org.olat.user.UserManager; import org.springframework.beans.factory.annotation.Autowired; /** @@ -48,12 +65,125 @@ import org.springframework.beans.factory.annotation.Autowired; public class BusinessGroupServiceTest extends OlatTestCase { private OLog log = Tracing.createLoggerFor(BusinessGroupServiceTest.class); + private static boolean initialize = false; @Autowired private DB dbInstance; @Autowired + private UserManager userManager; + @Autowired + private BaseSecurity securityManager; + @Autowired private BusinessGroupService businessGroupService; + // Identities for tests + private static Identity id1 = null; + private static Identity id2 = null; + private static Identity id3 = null; + private static Identity id4 = null; + // For WaitingGroup tests + private static Identity wg1 = null; + private static Identity wg2 = null; + private static Identity wg3 = null; + private static Identity wg4 = null; + + // Group one + private static BusinessGroup one = null; + private String oneName = "First BuddyGroup"; + private String oneDesc = "some short description for first buddygroup"; + // Group two + private static BusinessGroup two = null; + private String twoName = "Second BuddyGroup"; + private String twoDesc = "some short description for second buddygroup"; + // Group three + private static BusinessGroup three = null; + private String threeName = "Third BuddyGroup"; + private String threeDesc = "some short description for second buddygroup"; + // For WaitingGroup tests + private static BusinessGroup bgWithWaitingList = null; + + @Before + public void setUp() throws Exception { + if(initialize) return; + + // Identities + id1 = JunitTestHelper.createAndPersistIdentityAsUser("id1-bgs-" + UUID.randomUUID().toString()); + id2 = JunitTestHelper.createAndPersistIdentityAsUser("id2-bgs-" + UUID.randomUUID().toString()); + id3 = JunitTestHelper.createAndPersistIdentityAsUser("id3-bgs-" + UUID.randomUUID().toString()); + id4 = JunitTestHelper.createAndPersistIdentityAsUser("id4-bgs-" + UUID.randomUUID().toString()); + // buddyGroups without waiting-list: groupcontext is null + List<BusinessGroup> l = businessGroupService.findBusinessGroupsOwnedBy(id1, null); + if (l.size() == 0) { + one = businessGroupService.createBusinessGroup(id1, oneName, oneDesc, -1, -1, false, false, null); + } else { + List<BusinessGroup> groups = businessGroupService.findBusinessGroupsOwnedBy(id1, null); + for(BusinessGroup group:groups) { + if(oneName.equals(group.getName())) { + one = group; + } + } + } + l = businessGroupService.findBusinessGroupsOwnedBy(id2, null); + if (l.size() == 0) { + two = businessGroupService.createBusinessGroup(id2, twoName, twoDesc, -1, -1, false, false, null); + SecurityGroup twoPartips = two.getPartipiciantGroup(); + securityManager.addIdentityToSecurityGroup(id3, twoPartips); + securityManager.addIdentityToSecurityGroup(id4, twoPartips); + } else { + two = businessGroupService.findBusinessGroupsOwnedBy(id2, null).get(0); + } + l = businessGroupService.findBusinessGroupsOwnedBy(id3, null); + if (l.size() == 0) { + three = businessGroupService.createBusinessGroup(id3, threeName, threeDesc, -1, -1, false, false, null); + SecurityGroup threeOwner = three.getOwnerGroup(); + SecurityGroup threeOPartips = three.getPartipiciantGroup(); + securityManager.addIdentityToSecurityGroup(id2, threeOPartips); + securityManager.addIdentityToSecurityGroup(id1, threeOwner); + } else { + three = businessGroupService.findBusinessGroupsOwnedBy(id3, null).get(0); + } + /* + * Membership in ParticipiantGroups............................. id1 + * owns BuddyGroup one with participiantGroup:={}........... id2 owns + * BuddyGroup two with participiantGroup:={id3,id4} id3 owns BuddyGroup + * three participiantGroup:={id2}, ownerGroup:={id3,id1} + */ + + dbInstance.commitAndCloseSession(); + + // create business-group with waiting-list + String bgWithWaitingListName = "Group with WaitingList"; + String bgWithWaitingListDesc = "some short description for Group with WaitingList"; + Boolean enableWaitinglist = new Boolean(true); + Boolean enableAutoCloseRanks = new Boolean(true); + OLATResource resource = JunitTestHelper.createRandomResource(); + System.out.println("testAddToWaitingListAndFireEvent: resource=" + resource); + bgWithWaitingList = businessGroupService.createBusinessGroup(id1, bgWithWaitingListName, + bgWithWaitingListDesc, -1, -1, enableWaitinglist, enableAutoCloseRanks, resource); + bgWithWaitingList.setMaxParticipants(new Integer(2)); + // Identities + String suffix = UUID.randomUUID().toString(); + User UserWg1 = userManager.createAndPersistUser("FirstName_" + suffix, "LastName_" + suffix, suffix + "_junittest@olat.unizh.ch"); + wg1 = securityManager.createAndPersistIdentity(suffix, UserWg1, + BaseSecurityModule.getDefaultAuthProviderIdentifier(), suffix, Encoder.encrypt("wg1")); + suffix = UUID.randomUUID().toString(); + User UserWg2 = userManager.createAndPersistUser("FirstName_" + suffix, "LastName_" + suffix, suffix + "_junittest@olat.unizh.ch"); + wg2 = securityManager.createAndPersistIdentity(suffix, UserWg2, + BaseSecurityModule.getDefaultAuthProviderIdentifier(), suffix, Encoder.encrypt("wg2")); + suffix = UUID.randomUUID().toString(); + User UserWg3 = userManager.createAndPersistUser("FirstName_" + suffix, "LastName_" + suffix, suffix + "_junittest@olat.unizh.ch"); + wg3 = securityManager.createAndPersistIdentity(suffix, UserWg3, + BaseSecurityModule.getDefaultAuthProviderIdentifier(), suffix, Encoder.encrypt("wg3")); + suffix = UUID.randomUUID().toString(); + User UserWg4 = userManager.createAndPersistUser("FirstName_" + suffix, "LastName_" + suffix, suffix + "_junittest@olat.unizh.ch"); + wg4 = securityManager.createAndPersistIdentity(suffix, UserWg4, + BaseSecurityModule.getDefaultAuthProviderIdentifier(), suffix, Encoder.encrypt("wg4")); + + dbInstance.commitAndCloseSession(); + + initialize = true; + } + @After public void tearDown() throws Exception { try { @@ -98,11 +228,11 @@ public class BusinessGroupServiceTest extends OlatTestCase { OLATResource c1 = JunitTestHelper.createRandomResource(); OLATResource c2 = JunitTestHelper.createRandomResource(); - DBFactory.getInstance().closeSession(); // simulate user clicks + dbInstance.commitAndCloseSession(); // simulate user clicks assertTrue(businessGroupService.findBusinessGroups(null, null, false, false, c1, 0, -1).isEmpty()); assertTrue(businessGroupService.countBusinessGroups(null, null, false, false, c1) == 0); - DBFactory.getInstance().closeSession(); // simulate user clicks + dbInstance.commitAndCloseSession(); // simulate user clicks BusinessGroup g1 = businessGroupService.createBusinessGroup(null, "g1", null, 0, 10, false, false, c1); assertNotNull(g1); BusinessGroup g2 = businessGroupService.createBusinessGroup(null, "g2", null, 0, 10, false, false, c1); @@ -116,8 +246,340 @@ public class BusinessGroupServiceTest extends OlatTestCase { BusinessGroup g4 = businessGroupService.createBusinessGroup(null, "g2", null, 0, 10, false, false, c2); assertNotNull(g4); // name duplicate in other context allowed - DBFactory.getInstance().closeSession(); // simulate user clicks + dbInstance.commitAndCloseSession(); // simulate user clicks Assert.assertEquals(2, businessGroupService.findBusinessGroups(null, null, false, false, c1, 0, -1).size()); Assert.assertEquals(2, businessGroupService.countBusinessGroups(null, null, false, false, c1)); } + + @Test + public void testCheckIfNamesExistsInContext() throws Exception { + Identity id = JunitTestHelper.createAndPersistIdentityAsUser("id5-check-" + UUID.randomUUID().toString()); + + OLATResource ctxA = JunitTestHelper.createRandomResource(); + OLATResource ctxB = JunitTestHelper.createRandomResource(); + + String[] namesInCtxA = new String[] { "A-GroupOne", "A-GroupTwo", "A-GroupThree", "A-GroupFour", "A-GroupFive", "A-GroupSix" }; + String[] namesInCtxB = new String[] { "B-GroupAAA", "B-GroupBBB", "B-GroupCCC", "B-GroupDDD", "B-GroupEEE", "B-GroupFFF" }; + BusinessGroup[] ctxAgroups = new BusinessGroup[namesInCtxA.length]; + BusinessGroup[] ctxBgroups = new BusinessGroup[namesInCtxB.length]; + + for (int i = 0; i < namesInCtxA.length; i++) { + ctxAgroups[i] = businessGroupService.createBusinessGroup(id, namesInCtxA[i], null, 0, 0, false, + false, ctxA); + } + for (int i = 0; i < namesInCtxB.length; i++) { + ctxBgroups[i] = businessGroupService.createBusinessGroup(id, namesInCtxB[i], null, 0, 0, false, + false, ctxB); + } + // first click created two context and each of them containg groups + // evict all created and search + System.out.println("Test: ctxAgroups.length=" + ctxAgroups.length); + for (int i = 0; i < ctxAgroups.length; i++) { + System.out.println("Test: i=" + i); + System.out.println("Test: ctxAgroups[i]=" + ctxAgroups[i]); + } + dbInstance.commitAndCloseSession(); + + // next click needs to check of a set of groupnames already exists. + Set<String> subsetOkInA = new HashSet<String>(); + subsetOkInA.add("A-GroupTwo"); + subsetOkInA.add("A-GroupThree"); + subsetOkInA.add("A-GroupFour"); + + Set<String> subsetNOkInA = new HashSet<String>(); + subsetNOkInA.add("A-GroupTwo"); + subsetNOkInA.add("NOT-IN-A"); + subsetNOkInA.add("A-GroupThree"); + subsetNOkInA.add("A-GroupFour"); + + Set<String> subsetOkInB = new HashSet<String>(); + subsetOkInB.add("B-GroupCCC"); + subsetOkInB.add("B-GroupDDD"); + subsetOkInB.add("B-GroupEEE"); + subsetOkInB.add("B-GroupFFF"); + + Set<String> subsetNOkInB = new HashSet<String>(); + subsetNOkInB.add("B-GroupCCC"); + subsetNOkInB.add("NOT-IN-B"); + subsetNOkInB.add("B-GroupEEE"); + subsetNOkInB.add("B-GroupFFF"); + + Set<String> setSpansAandBNok = new HashSet<String>(); + setSpansAandBNok.add("B-GroupCCC"); + setSpansAandBNok.add("A-GroupTwo"); + setSpansAandBNok.add("A-GroupThree"); + setSpansAandBNok.add("B-GroupEEE"); + setSpansAandBNok.add("B-GroupFFF"); + + boolean allExist = false; + allExist = businessGroupService.checkIfOneOrMoreNameExists(subsetOkInA, ctxA); + assertTrue("Three A-Group.. should find all", allExist); + // Check : one name does not exist, 3 exist + assertTrue("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExists(subsetNOkInA, ctxA)); + // Check : no name exist in context + assertFalse("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExists(subsetOkInB, ctxA)); + // + allExist = businessGroupService.checkIfOneOrMoreNameExists(subsetOkInB, ctxB); + assertTrue("Three B-Group.. should find all", allExist); + // Check : one name does not exist, 3 exist + assertTrue("A 'NOT-IN-B'.. should not find all", businessGroupService.checkIfOneOrMoreNameExists(subsetNOkInB, ctxB)); + // Check : no name exist in context + assertFalse("A 'NOT-IN-A'.. should not find all", businessGroupService.checkIfOneOrMoreNameExists(subsetOkInA, ctxB)); + // Mix A (2x) and B (3x) + allExist = businessGroupService.checkIfOneOrMoreNameExists(setSpansAandBNok, ctxA); + assertTrue("Groupnames spanning two context... should not find all in context A", allExist); + // Mix A (2x) and B (3x) + allExist = businessGroupService.checkIfOneOrMoreNameExists(setSpansAandBNok, ctxB); + assertTrue("Groupnames spanning two context... should not find all in context B", allExist); + } + + /** + * Test existence of BuddyGroups inserted in the setUp phase................ + * this test rather tests the findXXX methods............................... + * so if the setup was ok, and this test also fulfilled, then it means that + * createAndPersistBuddyGroup works, and also the findXXX methods. + * + * @throws Exception + */ + @Test + public void testCreateAndPersistBuddyGroup() throws Exception { + // id1 + List<BusinessGroup> groupOwnedId1 = businessGroupService.findBusinessGroupsOwnedBy(id1, null); + Assert.assertEquals("2 BuddyGroups owned by id1", 3, groupOwnedId1.size()); + Assert.assertTrue(groupOwnedId1.contains(one)); + Assert.assertTrue(groupOwnedId1.contains(three)); + Assert.assertTrue(groupOwnedId1.contains(bgWithWaitingList)); + + List<BusinessGroup> groupAttendeeId1 = businessGroupService.findBusinessGroupsAttendedBy(id1, null); + Assert.assertEquals("0 BuddyGroup where id1 is partipicating", 0, groupAttendeeId1.size()); + + // id2 + List<BusinessGroup> groupOwnedId2 = businessGroupService.findBusinessGroupsOwnedBy(id2, null); + Assert.assertEquals("1 BuddyGroup owned by id2", 1, groupOwnedId2.size()); + Assert.assertTrue(groupOwnedId2.contains(two)); + + List<BusinessGroup> groupAttendeeId2 = businessGroupService.findBusinessGroupsAttendedBy(id2, null); + Assert.assertEquals("1 BuddyGroup where id2 is partipicating", 1, groupAttendeeId2.size()); + assertTrue("It's the correct BuddyGroup", groupAttendeeId2.contains(three)); + + // id3 + List<BusinessGroup> groupOwnedId3 = businessGroupService.findBusinessGroupsOwnedBy(id3, null); + Assert.assertEquals("1 BuddyGroup owned by id3", 1, groupOwnedId3.size()); + assertTrue("It's the correct BuddyGroup", groupOwnedId3.contains(three)); + + List<BusinessGroup> groupAttendeeId3 = businessGroupService.findBusinessGroupsAttendedBy(id3, null); + Assert.assertEquals("1 BuddyGroup where id3 is partipicating", 1, groupAttendeeId3.size()); + assertTrue("It's the correct BuddyGroup", groupAttendeeId3.contains(two)); + + // id4 + List<BusinessGroup> groupOwnedId4 = businessGroupService.findBusinessGroupsOwnedBy(id4, null); + Assert.assertEquals("0 BuddyGroup owned by id4", 0, groupOwnedId4.size()); + + List<BusinessGroup> groupAttendeeId4 = businessGroupService.findBusinessGroups(null, id4, false, true, null, 0, -1); + Assert.assertEquals("1 BuddyGroup where id4 is partipicating", 1, groupAttendeeId4.size()); + assertTrue("It's the correct BuddyGroup", groupAttendeeId4.contains(two)); + } + + /** + * checks if tools can be enabled disabled or checked against being enabled. + * TOols are configured with the help of the generic properties storage. + * + * @throws Exception + */ + public void testEnableDisableAndCheckForTool() throws Exception { + List<BusinessGroup> sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id2, null); + BusinessGroup found = (BusinessGroup) sqlRes.get(0); + CollaborationTools myCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(found); + for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { + String msg = "Tool " + CollaborationTools.TOOLS[i] + " is enabled"; + boolean enabled = myCTSMngr.isToolEnabled(CollaborationTools.TOOLS[i]); + // all tools are disabled by default exept the news tool + assertTrue(msg, !enabled); + + } + + for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { + myCTSMngr.setToolEnabled(CollaborationTools.TOOLS[i], true); + } + + for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { + String msg = "Tool " + CollaborationTools.TOOLS[i] + " is enabled"; + boolean enabled = myCTSMngr.isToolEnabled(CollaborationTools.TOOLS[i]); + assertTrue(msg, enabled); + + } + + for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { + myCTSMngr.setToolEnabled(CollaborationTools.TOOLS[i], false); + } + + for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { + String msg = "Tool " + CollaborationTools.TOOLS[i] + " is disabled"; + boolean enabled = myCTSMngr.isToolEnabled(CollaborationTools.TOOLS[i]); + assertTrue(msg, !enabled); + } + } + + /** + * test if removing a BuddyGroup really deletes everything it should. + * + * @throws Exception + */ + @Test + public void testDeleteBuddyGroup() throws Exception { + List<BusinessGroup> sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id2, null); + assertTrue("1 BuddyGroup owned by id2", sqlRes.size() == 1); + BusinessGroup found = (BusinessGroup) sqlRes.get(0); + CollaborationTools myCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(found); + + for (int i = 0; i < CollaborationTools.TOOLS.length; i++) { + myCTSMngr.setToolEnabled(CollaborationTools.TOOLS[i], true); + } + + businessGroupService.deleteBusinessGroup(found); + sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id2, null); + assertTrue("0 BuddyGroup owned by id2", sqlRes.size() == 0); + } + + /////////////////////// + // Test for WaitingList + /////////////////////// + /** + * Add 3 idenities to the waiting list and check the position. before test + * Waitinglist=[]<br> + * after test Waitinglist=[wg2,wg3,wg4] + */ + @Test + public void testAddToWaitingListAndFireEvent() throws Exception { + System.out.println("testAddToWaitingListAndFireEvent: start..."); + // Add wg2 + BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); + List<Identity> identities = new ArrayList<Identity>(); + identities.add(wg2); + businessGroupService.addToWaitingList(wg2, identities, bgWithWaitingList, flags); + // Add wg3 + identities = new ArrayList<Identity>(); + identities.add(wg3); + businessGroupService.addToWaitingList(wg3, identities, bgWithWaitingList, flags); + // Add wg4 + identities = new ArrayList<Identity>(); + identities.add(wg4); + businessGroupService.addToWaitingList(wg4, identities, bgWithWaitingList, flags); + System.out.println("testAddToWaitingListAndFireEvent: 3 user added to waiting list"); + + // Check position of 'wg2' + int pos = businessGroupService.getPositionInWaitingListFor(wg2, bgWithWaitingList); + System.out.println("testAddToWaitingListAndFireEvent: wg2 pos=" + pos); + assertTrue("pos must be 1, bit is=" + pos, pos == 1); + // Check position of 'wg3' + pos = businessGroupService.getPositionInWaitingListFor(wg3, bgWithWaitingList); + System.out.println("testAddToWaitingListAndFireEvent wg3: pos=" + pos); + assertTrue("pos must be 2, bit is=" + pos, pos == 2); + // Check position of 'wg4' + pos = businessGroupService.getPositionInWaitingListFor(wg4, bgWithWaitingList); + System.out.println("testAddToWaitingListAndFireEvent wg4: pos=" + pos); + assertTrue("pos must be 3, bit is=" + pos, pos == 3); + } + + /** + * Remove identity 2 (wg3) from the waiting list and check the position of + * identity 2. before test Waitinglist=[wg2,wg3,wg4]<br> + * after test Waitinglist=[wg2,wg4] + */ + @Test + public void testRemoveFromWaitingListAndFireEvent() throws Exception { + System.out.println("testRemoveFromWaitingListAndFireEvent: start..."); + // Remove wg3 + BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); + List<Identity> identities = new ArrayList<Identity>(); + identities.add(wg3); + businessGroupService.removeFromWaitingList(wg1, identities, bgWithWaitingList, flags); + // Check position of 'wg2' + int pos = businessGroupService.getPositionInWaitingListFor(wg2, bgWithWaitingList); + System.out.println("testRemoveFromWaitingListAndFireEvent: wg2 pos=" + pos); + assertTrue("pos must be 1, bit is=" + pos, pos == 1); + // Check position of 'wg4' + pos = businessGroupService.getPositionInWaitingListFor(wg4, bgWithWaitingList); + System.out.println("testRemoveFromWaitingListAndFireEvent wg4: pos=" + pos); + assertTrue("pos must be 2, bit is=" + pos, pos == 2); + + } + + /** + * Move identity 4 (wg4) from the waiting list to participant list. before + * test Waitinglist=[wg2,wg4]<br> + * after test Waitinglist=[wg2]<br> + * participant-list=[wg4] + */ + @Test + public void testMoveIdenityFromWaitingListToParticipant() throws Exception { + System.out.println("testMoveIdenityFromWaitingListToParticipant: start..."); + // Check that 'wg4' is not in participant list + assertFalse("Identity is allready in participant-list, remove it(dbsetup?)", businessGroupService + .isIdentityInBusinessGroup(wg4, bgWithWaitingList)); + + // Move wg4 from waiting-list to participant + BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); + List<Identity> identities = new ArrayList<Identity>(); + identities.add(wg4); + businessGroupService.moveIdentityFromWaitingListToParticipant(identities, wg1, bgWithWaitingList, flags); + // Check position of 'wg2' + int pos = businessGroupService.getPositionInWaitingListFor(wg2, bgWithWaitingList); + System.out.println("testMoveIdenityFromWaitingListToParticipant: wg2 pos=" + pos); + assertTrue("pos must be 1, bit is=" + pos, pos == 1); + // Check if 'wg4' is in participant-list + assertTrue("Identity is not in participant-list", businessGroupService.isIdentityInBusinessGroup(wg4, bgWithWaitingList)); + } + + @Test + public void testMoveRegisteredIdentityFromWaitingToParticipant() throws Exception { + System.out.println("testMoveRegisteredIdentityFromWaitingToParticipant: start..."); + // Add a user to waiting-list which is already in participant-list and try + // and try to move this user => user will be removed from waiting-list + // Add again wg2 + BGConfigFlags flags = BGConfigFlags.createLearningGroupDefaultFlags(); + List<Identity> identities = new ArrayList<Identity>(); + identities.add(wg1); + businessGroupService.addToWaitingList(wg4, identities, bgWithWaitingList, flags); + identities = new ArrayList<Identity>(); + identities.add(wg4); + businessGroupService.moveIdentityFromWaitingListToParticipant(identities, wg1, bgWithWaitingList, flags); + // Check position of 'wg4' + int pos = businessGroupService.getPositionInWaitingListFor(wg4, bgWithWaitingList); + System.out.println("testMoveIdenityFromWaitingListToParticipant: wg4 pos=" + pos); + assertTrue("pos must be 0, bit is=" + pos, pos == 0); + // Check if 'wg4' is still in participant-list + assertTrue("Identity is not in participant-list", businessGroupService.isIdentityInBusinessGroup(wg4, bgWithWaitingList)); + } + + @Test + public void testDeleteBusinessGroupWithWaitingGroup() { + doTestDeleteBusinessGroup(true); + } + + @Test + public void testDeleteBusinessGroupWithoutWaitingGroup() { + doTestDeleteBusinessGroup(false); + } + + private void doTestDeleteBusinessGroup(boolean withWaitingList) { + OLATResource resource = JunitTestHelper.createRandomResource(); + + BusinessGroup deleteTestGroup = businessGroupService.createBusinessGroup(id1, "deleteTestGroup-1", + "deleteTestGroup-1", -1, -1, withWaitingList, true, resource); + + Long ownerGroupKey = deleteTestGroup.getOwnerGroup().getKey(); + Long partipiciantGroupKey = deleteTestGroup.getPartipiciantGroup().getKey(); + Long waitingGroupKey = deleteTestGroup.getWaitingGroup().getKey(); + + assertNotNull("Could not find owner-group", dbInstance.findObject(SecurityGroupImpl.class, ownerGroupKey)); + assertNotNull("Could not find partipiciant-group", dbInstance.findObject(SecurityGroupImpl.class, partipiciantGroupKey)); + assertNotNull("Could not find waiting-group", dbInstance.findObject(SecurityGroupImpl.class, waitingGroupKey)); + businessGroupService.deleteBusinessGroup(deleteTestGroup); + assertNull("owner-group still exist after delete", dbInstance.findObject(SecurityGroupImpl.class, ownerGroupKey)); + assertNull("partipiciant-group still exist after delete", dbInstance.findObject(SecurityGroupImpl.class, partipiciantGroupKey)); + assertNull("waiting-group still exist after delete", dbInstance.findObject(SecurityGroupImpl.class, waitingGroupKey)); + } + + } \ No newline at end of file diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index eeb06bb08300cf4343cde12e011e1c6d0292a5fd..1b4b575c6c0eee1e802b06c303935a28045a45fd 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -77,7 +77,6 @@ import org.junit.runners.Suite; org.olat.group.test.BGRightManagerTest.class,//ok org.olat.group.test.BGAreaManagerTest.class,//ok org.olat.group.test.BusinessGroupServiceTest.class,//ok - org.olat.group.test.BusinessGroupServiceImplTest.class,//ok org.olat.group.test.BusinessGroupDAOTest.class,//ok org.olat.group.test.BusinessGroupRelationDAOTest.class,//ok org.olat.resource.lock.pessimistic.PLockTest.class,//ok