use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.
the class CourseCalendars method addCalendars.
private static void addCalendars(UserRequest ureq, UserCourseEnvironment courseEnv, List<BusinessGroup> groups, boolean isOwner, LinkProvider linkProvider, List<KalendarRenderWrapper> calendars) {
if (groups == null || groups.isEmpty())
return;
CollaborationToolsFactory collabFactory = CollaborationToolsFactory.getInstance();
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
Map<CalendarKey, CalendarUserConfiguration> configMap = calendarManager.getCalendarUserConfigurationsMap(ureq.getIdentity(), CalendarManager.TYPE_GROUP);
for (BusinessGroup bGroup : groups) {
CollaborationTools collabTools = collabFactory.getOrCreateCollaborationTools(bGroup);
if (!collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR)) {
continue;
}
boolean member = courseEnv.isIdentityInCourseGroup(bGroup.getKey());
KalendarRenderWrapper groupCalendarWrapper = calendarManager.getGroupCalendar(bGroup);
groupCalendarWrapper.setPrivateEventsVisible(member || isOwner);
// set calendar access
int iCalAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS;
Long lCalAccess = collabTools.lookupCalendarAccess();
if (lCalAccess != null)
iCalAccess = lCalAccess.intValue();
if (iCalAccess == CollaborationTools.CALENDAR_ACCESS_OWNERS && !isOwner) {
groupCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
} else {
groupCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
}
CalendarUserConfiguration config = configMap.get(groupCalendarWrapper.getCalendarKey());
if (config != null) {
groupCalendarWrapper.setConfiguration(config);
}
groupCalendarWrapper.setLinkProvider(linkProvider);
calendars.add(groupCalendarWrapper);
}
}
use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.
the class AbstractBusinessGroupListController method doConfiguration.
/**
* @param ureq
* @param items
*/
private void doConfiguration(UserRequest ureq, List<? extends BusinessGroupRef> selectedItems) {
removeAsListenerAndDispose(businessGroupWizard);
if (selectedItems == null || selectedItems.isEmpty()) {
showWarning("error.select.one");
return;
}
final List<BusinessGroup> groups = toBusinessGroups(ureq, selectedItems, true);
if (groups.isEmpty()) {
showWarning("msg.alleastone.editable.group");
return;
}
if (selectedItems.size() != groups.size()) {
showWarning("msg.only.editable.group");
return;
}
if (CollaborationToolsFactory.getInstance().getAvailableTools() == null) {
// init the available tools
CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(groups.get(0));
}
StringBuilder managedNames = new StringBuilder();
for (BusinessGroup group : groups) {
String gname = group.getName() == null ? "???" : group.getName();
if (BusinessGroupManagedFlag.isManaged(group, BusinessGroupManagedFlag.resources) || BusinessGroupManagedFlag.isManaged(group, BusinessGroupManagedFlag.tools)) {
if (managedNames.length() > 0)
managedNames.append(", ");
managedNames.append(gname);
}
}
if (managedNames.length() > 0) {
showWarning("error.managed.group", managedNames.toString());
return;
}
boolean isAuthor = ureq.getUserSession().getRoles().isAuthor() || ureq.getUserSession().getRoles().isInstitutionalResourceManager();
Step start = new BGConfigToolsStep(ureq, isAuthor);
StepRunnerCallback finish = new StepRunnerCallback() {
@Override
public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
// configuration
BGConfigBusinessGroup configuration = (BGConfigBusinessGroup) runContext.get("configuration");
if (!configuration.getToolsToEnable().isEmpty() || !configuration.getToolsToDisable().isEmpty()) {
for (BusinessGroup group : groups) {
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
for (String enabledTool : configuration.getToolsToEnable()) {
tools.setToolEnabled(enabledTool, true);
if (CollaborationTools.TOOL_FOLDER.equals(enabledTool)) {
tools.saveFolderAccess(new Long(configuration.getFolderAccess()));
Quota quota = configuration.getQuota();
if (quota != null) {
String path = tools.getFolderRelPath();
Quota fQuota = QuotaManager.getInstance().createQuota(path, quota.getQuotaKB(), quota.getUlLimitKB());
QuotaManager.getInstance().setCustomQuotaKB(fQuota);
}
} else if (CollaborationTools.TOOL_CALENDAR.equals(enabledTool)) {
tools.saveCalendarAccess(new Long(configuration.getCalendarAccess()));
}
}
for (String disabledTool : configuration.getToolsToDisable()) {
tools.setToolEnabled(disabledTool, false);
}
}
}
if (configuration.getResources() != null && !configuration.getResources().isEmpty()) {
businessGroupService.addResourcesTo(groups, configuration.getResources());
}
return StepsMainRunController.DONE_MODIFIED;
}
};
businessGroupWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("config.group"), "o_sel_groups_config_wizard");
listenTo(businessGroupWizard);
getWindowControl().pushAsModalDialog(businessGroupWizard.getInitialComponent());
}
use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class UserMgmtTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
if (setuped)
return;
// create identities
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-zero");
assertNotNull(owner1);
id1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-one-" + UUID.randomUUID().toString());
id2 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-two");
dbInstance.intermediateCommit();
id2.getUser().setProperty("telMobile", "39847592");
id2.getUser().setProperty("gender", "female");
id2.getUser().setProperty("birthDay", "20091212");
dbInstance.updateObject(id2.getUser());
dbInstance.intermediateCommit();
id3 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-three");
OlatRootFolderImpl id3HomeFolder = new OlatRootFolderImpl(FolderConfig.getUserHome(id3.getName()), null);
VFSContainer id3PublicFolder = (VFSContainer) id3HomeFolder.resolve("public");
if (id3PublicFolder == null) {
id3PublicFolder = id3HomeFolder.createChildContainer("public");
}
VFSItem portrait = id3PublicFolder.resolve("portrait.jpg");
if (portrait == null) {
URL portraitUrl = CoursesElementsTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, ((LocalImpl) id3PublicFolder).getBasefile(), false);
}
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
OLATResource course = rm.createOLATResourceInstance(resourceable);
dbInstance.saveObject(course);
dbInstance.intermediateCommit();
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1externalId = UUID.randomUUID().toString();
g1 = businessGroupService.createBusinessGroup(null, "user-rest-g1", null, g1externalId, "all", 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "user-rest-g2", null, 0, 10, false, false, c1);
// members g1
businessGroupRelationDao.addRole(id1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(id2, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(id1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3ExternalId = UUID.randomUUID().toString();
g3 = businessGroupService.createBusinessGroup(null, "user-rest-g3", null, g3ExternalId, "all", -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "user-rest-g4", null, -1, -1, false, false, c2);
// members
businessGroupRelationDao.addRole(id1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, g4, GroupRoles.participant.name());
dbInstance.closeSession();
// add some collaboration tools
CollaborationTools g1CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
g1CTSMngr.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
// create the forum
Forum g1Forum = g1CTSMngr.getForum();
Message m1 = ForumManager.getInstance().createMessage(g1Forum, id1, false);
m1.setTitle("Thread-1");
m1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(m1);
dbInstance.commitAndCloseSession();
// add some folder tool
CollaborationTools g2CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
g2CTSMngr.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
OlatRootFolderImpl g2Folder = new OlatRootFolderImpl(g2CTSMngr.getFolderRelPath(), null);
g2Folder.getBasefile().mkdirs();
VFSItem groupPortrait = g2Folder.resolve("portrait.jpg");
if (groupPortrait == null) {
URL portraitUrl = UserMgmtTest.class.getResource("portrait.jpg");
File ioPortrait = new File(portraitUrl.toURI());
FileUtils.copyFileToDirectory(ioPortrait, g2Folder.getBasefile(), false);
}
dbInstance.commitAndCloseSession();
// prepare some courses
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("auth-" + UUID.randomUUID().toString());
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(author);
if (!repositoryService.hasRole(id1, entry, GroupRoles.participant.name())) {
repositoryService.addRole(id1, entry, GroupRoles.participant.name());
}
demoCourse = CourseFactory.loadCourse(entry);
TreeVisitor visitor = new TreeVisitor(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
if (demoForumNode == null) {
demoForumNode = (FOCourseNode) node;
Forum courseForum = demoForumNode.loadOrCreateForum(demoCourse.getCourseEnvironment());
Message message1 = ForumManager.getInstance().createMessage(courseForum, id1, false);
message1.setTitle("Thread-1");
message1.setBody("Body of Thread-1");
ForumManager.getInstance().addTopMessage(message1);
}
} else if (node instanceof BCCourseNode) {
if (demoBCCourseNode == null) {
demoBCCourseNode = (BCCourseNode) node;
OlatNamedContainerImpl container = BCCourseNode.getNodeFolderContainer(demoBCCourseNode, demoCourse.getCourseEnvironment());
VFSItem example = container.resolve("singlepage.html");
if (example == null) {
try {
InputStream htmlUrl = UserMgmtTest.class.getResourceAsStream("singlepage.html");
VFSLeaf htmlLeaf = container.createChildLeaf("singlepage.html");
IOUtils.copy(htmlUrl, htmlLeaf.getOutputStream(false));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}, demoCourse.getRunStructure().getRootNode(), false);
visitor.visitAll();
dbInstance.commitAndCloseSession();
setuped = true;
}
use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.
the class UserMgmtTest method testUserFolders.
@Test
public void testUserFolders() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("folders").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
FolderVOes folders = conn.parse(response, FolderVOes.class);
assertNotNull(folders);
assertNotNull(folders.getFolders());
assertTrue(folders.getFolders().length > 0);
boolean matchG2 = false;
for (FolderVO folder : folders.getFolders()) {
Long groupKey = folder.getGroupKey();
if (groupKey != null) {
BusinessGroup bg = businessGroupService.loadBusinessGroup(groupKey);
assertNotNull(bg);
CollaborationTools bgCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
assertTrue(bgCTSMngr.isToolEnabled(CollaborationTools.TOOL_FOLDER));
assertEquals(bg.getName(), folder.getName());
assertEquals(bg.getKey(), folder.getGroupKey());
assertTrue(businessGroupService.isIdentityInBusinessGroup(id1, bg));
if (g2.getKey().equals(groupKey)) {
matchG2 = true;
}
} else {
assertNotNull(folder.getCourseKey());
}
}
// id1 is participant of g2. Make sure it found the folder
assertTrue(matchG2);
conn.shutdown();
}
Aggregations