use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class LearningGroupWebService method postGroupConfiguration.
@POST
@Path("{groupKey}/configuration")
public Response postGroupConfiguration(@PathParam("groupKey") Long groupKey, final GroupConfigurationVO group, @Context HttpServletRequest request) {
if (!isGroupManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
if (bg == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
String[] selectedTools = group.getTools();
if (selectedTools == null) {
selectedTools = new String[0];
}
String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
for (int i = availableTools.length; i-- > 0; ) {
boolean enable = false;
String tool = availableTools[i];
for (String selectedTool : selectedTools) {
if (tool.equals(selectedTool)) {
enable = true;
}
}
tools.setToolEnabled(tool, enable);
}
Map<String, Integer> toolsAccess = group.getToolsAccess();
if (toolsAccess != null) {
// ignore null for backward compatibility, don't change current configuration
for (String tool : toolsAccess.keySet()) {
tools.setToolAccess(tool, toolsAccess.get(tool));
}
}
if (StringHelper.containsNonWhitespace(group.getNews())) {
tools.saveNews(group.getNews());
}
boolean ownersIntern = bg.isOwnersVisibleIntern();
if (group.getOwnersVisible() != null) {
ownersIntern = group.getOwnersVisible().booleanValue();
}
boolean participantsIntern = bg.isParticipantsVisibleIntern();
if (group.getParticipantsVisible() != null) {
participantsIntern = group.getParticipantsVisible().booleanValue();
}
boolean waitingListIntern = bg.isWaitingListVisibleIntern();
if (group.getWaitingListVisible() != null) {
waitingListIntern = group.getWaitingListVisible().booleanValue();
}
boolean ownersPublic = bg.isOwnersVisiblePublic();
if (group.getOwnersPublic() != null) {
ownersPublic = group.getOwnersPublic().booleanValue();
}
boolean participantsPublic = bg.isParticipantsVisiblePublic();
if (group.getParticipantsPublic() != null) {
participantsPublic = group.getParticipantsPublic().booleanValue();
}
boolean waitingListPublic = bg.isWaitingListVisiblePublic();
if (group.getWaitingListPublic() != null) {
waitingListPublic = group.getWaitingListPublic().booleanValue();
}
bg = bgs.updateDisplayMembers(bg, ownersIntern, participantsIntern, waitingListIntern, ownersPublic, participantsPublic, waitingListPublic, bg.isDownloadMembersLists());
return Response.ok().build();
}
use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class BusinessGroupImportExport method importGroups.
public BusinessGroupEnvironment importGroups(RepositoryEntry re, File fGroupExportXML) {
if (!fGroupExportXML.exists())
return new BusinessGroupEnvironment();
// start with a new connection
dbInstance.commitAndCloseSession();
OLATGroupExport groupConfig = null;
try {
groupConfig = xstream.fromXML(fGroupExportXML);
} catch (Exception ce) {
throw new OLATRuntimeException("Error importing group config.", ce);
}
if (groupConfig == null) {
throw new AssertException("Invalid group export file. Root does not match.");
}
BusinessGroupEnvironment env = new BusinessGroupEnvironment();
Set<BGArea> areaSet = new HashSet<BGArea>();
// get areas
int dbCount = 0;
if (groupConfig.getAreas() != null && groupConfig.getAreas().getGroups() != null) {
for (Area area : groupConfig.getAreas().getGroups()) {
String areaName = area.name;
String areaDesc = (area.description != null && !area.description.isEmpty()) ? area.description.get(0) : "";
BGArea newArea = areaManager.createAndPersistBGArea(areaName, areaDesc, re.getOlatResource());
if (areaSet.add(newArea)) {
env.getAreas().add(new BGAreaReference(newArea, area.key, area.name));
}
if (dbCount++ % 25 == 0) {
dbInstance.commitAndCloseSession();
}
}
}
// get groups
if (groupConfig.getGroups() != null && groupConfig.getGroups().getGroups() != null) {
for (Group group : groupConfig.getGroups().getGroups()) {
// create group
String groupName = group.name;
String groupDesc = (group.description != null && !group.description.isEmpty()) ? group.description.get(0) : "";
// get min/max participants
int groupMinParticipants = group.minParticipants == null ? -1 : group.minParticipants.intValue();
int groupMaxParticipants = group.maxParticipants == null ? -1 : group.maxParticipants.intValue();
// waiting list configuration
boolean waitingList = false;
if (group.waitingList != null) {
waitingList = group.waitingList.booleanValue();
}
boolean enableAutoCloseRanks = false;
if (group.autoCloseRanks != null) {
enableAutoCloseRanks = group.autoCloseRanks.booleanValue();
}
// get properties
boolean showOwners = true;
boolean showParticipants = true;
boolean showWaitingList = true;
if (group.showOwners != null) {
showOwners = group.showOwners;
}
if (group.showParticipants != null) {
showParticipants = group.showParticipants;
}
if (group.showWaitingList != null) {
showWaitingList = group.showWaitingList;
}
BusinessGroup newGroup = businessGroupService.createBusinessGroup(null, groupName, groupDesc, groupMinParticipants, groupMaxParticipants, waitingList, enableAutoCloseRanks, re);
// map the group
env.getGroups().add(new BusinessGroupReference(newGroup, group.key, group.name));
// get tools config
String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
CollabTools toolsConfig = group.tools;
CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(newGroup);
for (int i = 0; i < availableTools.length; i++) {
try {
Field field = toolsConfig.getClass().getField(availableTools[i]);
Boolean val = field.getBoolean(toolsConfig);
if (val != null) {
ct.setToolEnabled(availableTools[i], val);
}
} catch (NoSuchFieldException e) {
// hasOpenMeetings compatibility
} catch (Exception e) {
log.error("", e);
}
}
if (group.calendarAccess != null) {
Long calendarAccess = group.calendarAccess;
ct.saveCalendarAccess(calendarAccess);
}
if (group.folderAccess != null) {
ct.saveFolderAccess(group.folderAccess);
}
if (group.info != null) {
ct.saveNews(group.info);
}
// get memberships
List<String> memberships = group.areaRelations;
if (memberships != null && memberships.size() > 0) {
Set<String> uniqueMemberships = new HashSet<>(memberships);
for (String membership : uniqueMemberships) {
BGArea area = areaManager.findBGArea(membership, re.getOlatResource());
if (area != null) {
areaManager.addBGToBGArea(newGroup, area);
} else {
log.error("Area not found", null);
}
}
}
boolean download = groupModule.isUserListDownloadDefaultAllowed();
newGroup = businessGroupService.updateDisplayMembers(newGroup, showOwners, showParticipants, showWaitingList, false, false, false, download);
if (dbCount++ % 3 == 0) {
dbInstance.commitAndCloseSession();
}
}
}
dbInstance.commitAndCloseSession();
return env;
}
use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class BusinessGroupServiceImpl method copyBusinessGroup.
@Override
public BusinessGroup copyBusinessGroup(Identity identity, BusinessGroup sourceBusinessGroup, String targetName, String targetDescription, Integer targetMin, Integer targetMax, boolean copyAreas, boolean copyCollabToolConfig, boolean copyRights, boolean copyOwners, boolean copyParticipants, boolean copyMemberVisibility, boolean copyWaitingList, boolean copyRelations) {
// 1. create group, set waitingListEnabled, enableAutoCloseRanks like source business-group
BusinessGroup newGroup = createBusinessGroup(null, targetName, targetDescription, targetMin, targetMax, sourceBusinessGroup.getWaitingListEnabled(), sourceBusinessGroup.getAutoCloseRanksEnabled(), null);
// return immediately with null value to indicate an already take groupname
if (newGroup == null) {
return null;
}
// 2. copy tools
if (copyCollabToolConfig) {
CollaborationToolsFactory toolsF = CollaborationToolsFactory.getInstance();
// get collab tools from original group and the new group
CollaborationTools oldTools = toolsF.getOrCreateCollaborationTools(sourceBusinessGroup);
CollaborationTools newTools = toolsF.getOrCreateCollaborationTools(newGroup);
// copy the collab tools settings
String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
for (int i = 0; i < availableTools.length; i++) {
String tool = availableTools[i];
newTools.setToolEnabled(tool, oldTools.isToolEnabled(tool));
}
String oldNews = oldTools.lookupNews();
newTools.saveNews(oldNews);
}
// 3. copy member visibility
if (copyMemberVisibility) {
newGroup.setOwnersVisibleIntern(sourceBusinessGroup.isOwnersVisibleIntern());
newGroup.setOwnersVisiblePublic(sourceBusinessGroup.isOwnersVisiblePublic());
newGroup.setParticipantsVisibleIntern(sourceBusinessGroup.isParticipantsVisibleIntern());
newGroup.setParticipantsVisiblePublic(sourceBusinessGroup.isParticipantsVisiblePublic());
newGroup.setWaitingListVisibleIntern(sourceBusinessGroup.isWaitingListVisibleIntern());
newGroup.setWaitingListVisiblePublic(sourceBusinessGroup.isWaitingListVisiblePublic());
newGroup.setDownloadMembersLists(sourceBusinessGroup.isDownloadMembersLists());
}
// 4. copy areas
if (copyAreas) {
List<BGArea> areas = areaManager.findBGAreasOfBusinessGroup(sourceBusinessGroup);
for (BGArea area : areas) {
// reference target group to source groups areas
areaManager.addBGToBGArea(newGroup, area);
}
}
// 5. copy owners
if (copyOwners) {
List<Identity> owners = businessGroupRelationDAO.getMembers(sourceBusinessGroup, GroupRoles.coach.name());
if (owners.isEmpty()) {
businessGroupRelationDAO.addRole(identity, newGroup, GroupRoles.coach.name());
} else {
for (Identity owner : owners) {
businessGroupRelationDAO.addRole(owner, newGroup, GroupRoles.coach.name());
}
}
} else {
businessGroupRelationDAO.addRole(identity, newGroup, GroupRoles.coach.name());
}
// 6. copy participants
if (copyParticipants) {
List<Identity> participants = businessGroupRelationDAO.getMembers(sourceBusinessGroup, GroupRoles.participant.name());
for (Identity participant : participants) {
businessGroupRelationDAO.addRole(participant, newGroup, GroupRoles.participant.name());
}
}
// 7. copy rights
if (copyRights) {
List<String> participantRights = rightManager.findBGRights(sourceBusinessGroup, BGRightsRole.participant);
for (String sourceRight : participantRights) {
rightManager.addBGRight(sourceRight, newGroup, BGRightsRole.participant);
}
List<String> tutorRights = rightManager.findBGRights(sourceBusinessGroup, BGRightsRole.tutor);
for (String sourceRight : tutorRights) {
rightManager.addBGRight(sourceRight, newGroup, BGRightsRole.tutor);
}
}
// 8. copy waiting-lisz
if (copyWaitingList) {
List<Identity> waitingList = getMembers(sourceBusinessGroup, GroupRoles.waiting.name());
for (Identity waiting : waitingList) {
businessGroupRelationDAO.addRole(waiting, newGroup, GroupRoles.waiting.name());
}
}
// 9. copy relations
if (copyRelations) {
List<RepositoryEntry> resources = businessGroupRelationDAO.findRepositoryEntries(Collections.singletonList(sourceBusinessGroup), 0, -1);
addResourcesTo(Collections.singletonList(newGroup), resources);
}
return newGroup;
}
use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class BusinessGroupServiceImpl method deleteBusinessGroup.
@Override
public void deleteBusinessGroup(BusinessGroup group) {
try {
OLATResourceableJustBeforeDeletedEvent delEv = new OLATResourceableJustBeforeDeletedEvent(group);
// notify all (currently running) BusinessGroupXXXcontrollers
// about the deletion which will occur.
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(delEv, group);
// refresh object to avoid stale object exceptions
group = loadBusinessGroup(group);
// 0) Loop over all deletableGroupData
Map<String, DeletableGroupData> deleteListeners = CoreSpringFactory.getBeansOfType(DeletableGroupData.class);
for (DeletableGroupData deleteListener : deleteListeners.values()) {
if (log.isDebug()) {
log.debug("deleteBusinessGroup: call deleteListener=" + deleteListener);
}
deleteListener.deleteGroupDataFor(group);
}
// 1) Delete all group properties
CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
// deletes everything concerning properties&collabTools
ct.deleteTools(group);
// 1.c)delete user in security groups
// removeFromRepositoryEntrySecurityGroup(group);
// 2) Delete the group areas
areaManager.deleteBGtoAreaRelations(group);
// 3) Delete the relations
businessGroupRelationDAO.deleteRelationsToRepositoryEntry(group);
assessmentModeDao.deleteAssessmentModesToGroup(group);
// 4) delete properties
propertyManager.deleteProperties(null, group, null, null, null);
propertyManager.deleteProperties(null, null, group, null, null);
// 5) delete the publisher attached to this group (e.g. the forum and folder
// publisher)
notificationsManager.deletePublishersOf(group);
// 6) delete info messages and subscription context associated with this group
infoMessageManager.removeInfoMessagesAndSubscriptionContext(group);
// 7) the group
businessGroupDAO.delete(group);
// 8) delete the associated security groups
// TODO group
dbInstance.commit();
log.audit("Deleted Business Group", group.toString());
} catch (DBRuntimeException dbre) {
Throwable th = dbre.getCause();
if ((th instanceof ObjectNotFoundException) && th.getMessage().contains("org.olat.group.BusinessGroupImpl")) {
// group already deleted
return;
}
if ((th instanceof StaleObjectStateException) && (th.getMessage().startsWith("Row was updated or deleted by another transaction"))) {
// known issue OLAT-3654
log.info("Group was deleted by another user in the meantime. Known issue OLAT-3654");
throw new KnownIssueException("Group was deleted by another user in the meantime", 3654);
} else {
throw dbre;
}
}
}
use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class BusinessGroupServiceTest method testDeleteGroup.
/**
* test if removing a BuddyGroup really deletes everything it should.
*
* @throws Exception
*/
@Test
public void testDeleteGroup() throws Exception {
List<BusinessGroup> sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id2);
assertTrue("1 BuddyGroup owned by id2", sqlRes.size() == 1);
BusinessGroup found = sqlRes.get(0);
CollaborationTools myCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(found);
String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
for (int i = 0; i < availableTools.length; i++) {
myCTSMngr.setToolEnabled(availableTools[i], true);
}
businessGroupService.deleteBusinessGroup(found);
sqlRes = businessGroupService.findBusinessGroupsOwnedBy(id2);
assertTrue("0 BuddyGroup owned by id2", sqlRes.size() == 0);
}
Aggregations