use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.
the class GroupMgmtTest method updateDeleteNews.
@Test
public void updateDeleteNews() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
// create the group
GroupVO vo = new GroupVO();
vo.setName("rest-g8-news");
vo.setDescription("rest-g8 for news operations");
vo.setType("BuddyGroup");
URI request = UriBuilder.fromUri(getContextURI()).path("groups").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(method, vo);
HttpResponse response = conn.execute(method);
assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
GroupVO newGroupVo = conn.parse(response, GroupVO.class);
assertNotNull(newGroupVo);
// update the configuration
GroupConfigurationVO configVo = new GroupConfigurationVO();
configVo.setTools(new String[] { "hasNews" });
configVo.setNews("<p>News!</p>");
URI configRequest = UriBuilder.fromUri(getContextURI()).path("groups").path(newGroupVo.getKey().toString()).path("configuration").build();
HttpPost configMethod = conn.createPost(configRequest, MediaType.APPLICATION_JSON);
conn.addJsonEntity(configMethod, configVo);
HttpResponse configResponse = conn.execute(configMethod);
assertEquals(200, configResponse.getStatusLine().getStatusCode());
EntityUtils.consume(configResponse.getEntity());
// update the news an contact node
URI newsRequest = UriBuilder.fromUri(getContextURI()).path("groups").path(newGroupVo.getKey().toString()).path("news").build();
HttpPost updateNewsMethod = conn.createPost(newsRequest, MediaType.APPLICATION_JSON);
conn.addEntity(updateNewsMethod, new BasicNameValuePair("news", "<p>The last news</p>"));
HttpResponse updateResponse = conn.execute(updateNewsMethod);
assertEquals(200, updateResponse.getStatusLine().getStatusCode());
EntityUtils.consume(updateResponse.getEntity());
// check the last news
BusinessGroup bg = businessGroupService.loadBusinessGroup(newGroupVo.getKey());
CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
String news = collabTools.lookupNews();
assertEquals("<p>The last news</p>", news);
// delete the news
HttpDelete deleteNewsMethod = conn.createDelete(newsRequest, MediaType.APPLICATION_JSON);
HttpResponse deleteResponse = conn.execute(deleteNewsMethod);
assertEquals(200, deleteResponse.getStatusLine().getStatusCode());
EntityUtils.consume(deleteResponse.getEntity());
// reload and check the news are empty
dbInstance.commitAndCloseSession();
CollaborationTools reloadedCollabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
String deletedNews = reloadedCollabTools.lookupNews();
assertNull(deletedNews);
}
use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.
the class UserMgmtTest method testUserForums.
@Test
public void testUserForums() 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("forums").queryParam("start", 0).queryParam("limit", 20).build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
ForumVOes forums = conn.parse(response, ForumVOes.class);
assertNotNull(forums);
assertNotNull(forums.getForums());
assertTrue(forums.getForums().length > 0);
for (ForumVO forum : forums.getForums()) {
Long groupKey = forum.getGroupKey();
if (groupKey != null) {
BusinessGroup bg = businessGroupService.loadBusinessGroup(groupKey);
assertNotNull(bg);
CollaborationTools bgCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
assertTrue(bgCTSMngr.isToolEnabled(CollaborationTools.TOOL_FORUM));
assertNotNull(forum.getForumKey());
assertEquals(bg.getName(), forum.getName());
assertEquals(bg.getKey(), forum.getGroupKey());
assertTrue(businessGroupService.isIdentityInBusinessGroup(id1, bg));
} else {
assertNotNull(forum.getCourseKey());
}
}
conn.shutdown();
}
use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.
the class CourseCalendarController method addCalendars.
private void addCalendars(List<BusinessGroup> groups, boolean isOwner, LinkProvider linkProvider, List<KalendarRenderWrapper> calendars) {
CollaborationToolsFactory collabFactory = CollaborationToolsFactory.getInstance();
for (BusinessGroup bGroup : groups) {
CollaborationTools collabTools = collabFactory.getOrCreateCollaborationTools(bGroup);
if (!collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR))
continue;
KalendarRenderWrapper groupCalendarWrapper = calendarManager.getGroupCalendar(bGroup);
groupCalendarWrapper.setPrivateEventsVisible(true);
// 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 = calendarManager.findCalendarConfigForIdentity(groupCalendarWrapper.getKalendar(), getIdentity());
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 UserFoldersWebService method getFolders.
/**
* Retrieves a list of folders on a user base. All folders of groups
* where the user is participant/tutor + all folders in course where
* the user is a participant (owner, tutor or participant)
* @response.representation.200.qname {http://www.example.com}folderVOes
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The folders
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVOes}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param identityKey The key of the user (IdentityImpl)
* @param httpRequest The HTTP request
* @return The folders
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getFolders(@Context HttpServletRequest httpRequest) {
Roles roles;
Identity ureqIdentity = getIdentity(httpRequest);
if (ureqIdentity == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!identity.getKey().equals(ureqIdentity.getKey())) {
if (isAdmin(httpRequest)) {
ureqIdentity = identity;
roles = BaseSecurityManager.getInstance().getRoles(identity);
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
} else {
roles = getRoles(httpRequest);
}
final Map<Long, Long> groupNotified = new HashMap<Long, Long>();
final Map<Long, Collection<String>> courseNotified = new HashMap<Long, Collection<String>>();
NotificationsManager man = NotificationsManager.getInstance();
{
// collect subscriptions
List<String> notiTypes = Collections.singletonList("FolderModule");
List<Subscriber> subs = man.getSubscribers(ureqIdentity, notiTypes);
for (Subscriber sub : subs) {
String resName = sub.getPublisher().getResName();
if ("BusinessGroup".equals(resName)) {
Long groupKey = sub.getPublisher().getResId();
groupNotified.put(groupKey, sub.getPublisher().getResId());
} else if ("CourseModule".equals(resName)) {
Long courseKey = sub.getPublisher().getResId();
if (!courseNotified.containsKey(courseKey)) {
courseNotified.put(courseKey, new ArrayList<String>());
}
courseNotified.get(courseKey).add(sub.getPublisher().getSubidentifier());
}
}
}
final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
final IdentityEnvironment ienv = new IdentityEnvironment(ureqIdentity, roles);
for (Map.Entry<Long, Collection<String>> e : courseNotified.entrySet()) {
final Long courseKey = e.getKey();
final Collection<String> nodeKeys = e.getValue();
final ICourse course = CourseFactory.loadCourse(courseKey);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode) node;
if (nodeKeys.contains(bcNode.getIdent())) {
FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
folderVOs.add(folder);
}
}
}
}, new VisibleTreeFilter());
}
/*
RepositoryManager rm = RepositoryManager.getInstance();
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
repoParams.setOnlyExplicitMember(true);
List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
for(RepositoryEntry entry:entries) {
AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
if(result.isAccessible()) {
try {
final ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if(node instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode)node;
FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
folderVOs.add(folder);
}
}
});
} catch (Exception e) {
log.error("", e);
}
}
}*/
// start found forums in groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(ureqIdentity, true, true);
params.addTools(CollaborationTools.TOOL_FOLDER);
List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
for (BusinessGroup group : groups) {
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
VFSContainer container = tools.getSecuredFolder(group, null, ureqIdentity, false);
FolderVO folderVo = new FolderVO();
folderVo.setName(group.getName());
folderVo.setGroupKey(group.getKey());
folderVo.setSubscribed(groupNotified.containsKey(group.getKey()));
folderVo.setRead(container.getLocalSecurityCallback().canRead());
folderVo.setList(container.getLocalSecurityCallback().canList());
folderVo.setWrite(container.getLocalSecurityCallback().canWrite());
folderVo.setDelete(container.getLocalSecurityCallback().canDelete());
folderVOs.add(folderVo);
}
FolderVOes voes = new FolderVOes();
voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
voes.setTotalCount(folderVOs.size());
return Response.ok(voes).build();
}
use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.
the class BusinessGroupMainRunController method doFolder.
private Activateable2 doFolder(UserRequest ureq) {
addLoggingResourceable(LoggingResourceable.wrap(ORES_TOOLFOLDER, OlatResourceableType.sharedFolder));
SubscriptionContext sc = new SubscriptionContext(businessGroup, INITVIEW_TOOLFOLDER);
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ORES_TOOLFOLDER);
ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrapBusinessPath(ce.getOLATResourceable()));
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, getWindowControl());
addToHistory(ureq, bwControl);
CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup);
collabToolCtr = collabTools.createFolderController(ureq, bwControl, businessGroup, isAdmin, sc);
listenTo(collabToolCtr);
mainPanel.setContent(collabToolCtr.getInitialComponent());
return (Activateable2) collabToolCtr;
}
Aggregations