use of org.olat.group.area.BGArea 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.group.area.BGArea 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.group.area.BGArea in project openolat by klemens.
the class AssessmentModeManagerTest method loadAssessmentMode_identityInArea_coach.
/**
* Check an assessment linked to an area with one participant
*/
@Test
public void loadAssessmentMode_identityInArea_coach() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-12");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-13");
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-14");
BusinessGroup businessGroup = businessGroupService.createBusinessGroup(null, "as-mode-3", "", null, null, null, null, false, false, entry);
businessGroupRelationDao.addRole(participant, businessGroup, GroupRoles.participant.name());
businessGroupRelationDao.addRole(coach, businessGroup, GroupRoles.coach.name());
BGArea area = areaMgr.createAndPersistBGArea("area for people", "", entry.getOlatResource());
areaMgr.addBGToBGArea(businessGroup, area);
AssessmentMode mode = createMinimalAssessmentmode(entry);
mode.setTargetAudience(AssessmentMode.Target.courseAndGroups);
mode.setApplySettingsForCoach(true);
mode = assessmentModeMgr.persist(mode);
AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(mode, area);
mode.getAreas().add(modeToArea);
mode = assessmentModeMgr.merge(mode, true);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(mode);
// check participant
List<AssessmentMode> currentModes = assessmentModeMgr.getAssessmentModeFor(participant);
Assert.assertNotNull(currentModes);
Assert.assertEquals(1, currentModes.size());
Assert.assertTrue(currentModes.contains(mode));
// check coach
List<AssessmentMode> currentCoachModes = assessmentModeMgr.getAssessmentModeFor(coach);
Assert.assertNotNull(currentCoachModes);
Assert.assertEquals(1, currentCoachModes.size());
Assert.assertTrue(currentCoachModes.contains(mode));
// check author
List<AssessmentMode> currentAuthorModes = assessmentModeMgr.getAssessmentModeFor(author);
Assert.assertNotNull(currentAuthorModes);
Assert.assertTrue(currentAuthorModes.isEmpty());
}
use of org.olat.group.area.BGArea in project openolat by klemens.
the class AssessmentModeManagerTest method loadAssessmentMode_identityInArea.
/**
* Check an assessment linked to an area with one participant
*/
@Test
public void loadAssessmentMode_identityInArea() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-12");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-13");
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-14");
BusinessGroup businessGroup = businessGroupService.createBusinessGroup(author, "as-mode-3", "", null, null, null, null, false, false, entry);
businessGroupRelationDao.addRole(participant, businessGroup, GroupRoles.participant.name());
businessGroupRelationDao.addRole(coach, businessGroup, GroupRoles.coach.name());
BGArea area = areaMgr.createAndPersistBGArea("area for people", "", entry.getOlatResource());
areaMgr.addBGToBGArea(businessGroup, area);
AssessmentMode mode = createMinimalAssessmentmode(entry);
mode.setTargetAudience(AssessmentMode.Target.courseAndGroups);
mode.setApplySettingsForCoach(false);
mode = assessmentModeMgr.persist(mode);
AssessmentModeToGroup modeToGroup = assessmentModeMgr.createAssessmentModeToGroup(mode, businessGroup);
mode.getGroups().add(modeToGroup);
mode = assessmentModeMgr.merge(mode, true);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(mode);
// check participant
List<AssessmentMode> currentModes = assessmentModeMgr.getAssessmentModeFor(participant);
Assert.assertNotNull(currentModes);
Assert.assertEquals(1, currentModes.size());
Assert.assertTrue(currentModes.contains(mode));
// check coach
List<AssessmentMode> currentCoachModes = assessmentModeMgr.getAssessmentModeFor(coach);
Assert.assertNotNull(currentCoachModes);
Assert.assertTrue(currentCoachModes.isEmpty());
// check author
List<AssessmentMode> currentAuthorModes = assessmentModeMgr.getAssessmentModeFor(author);
Assert.assertNotNull(currentAuthorModes);
Assert.assertTrue(currentAuthorModes.isEmpty());
}
use of org.olat.group.area.BGArea in project openolat by klemens.
the class AssessmentModeManagerTest method createAssessmentModeToArea.
@Test
public void createAssessmentModeToArea() {
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-1");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
BusinessGroup businessGroup = businessGroupService.createBusinessGroup(author, "as_mode_1", "", null, null, null, null, false, false, null);
BGArea area = areaMgr.createAndPersistBGArea("little area", "My little secret area", entry.getOlatResource());
areaMgr.addBGToBGArea(businessGroup, area);
AssessmentMode mode = createMinimalAssessmentmode(entry);
mode = assessmentModeMgr.persist(mode);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(mode);
AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(mode, area);
mode.getAreas().add(modeToArea);
AssessmentMode savedMode = assessmentModeMgr.merge(mode, true);
dbInstance.commitAndCloseSession();
AssessmentMode reloadedMode = assessmentModeMgr.getAssessmentModeById(mode.getKey());
Assert.assertEquals(mode, reloadedMode);
Assert.assertEquals(savedMode, reloadedMode);
Assert.assertNotNull(reloadedMode.getAreas());
Assert.assertEquals(1, reloadedMode.getAreas().size());
Assert.assertEquals(modeToArea, reloadedMode.getAreas().iterator().next());
dbInstance.commitAndCloseSession();
}
Aggregations