use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class GroupMgmtTest method testCreateCourseGroupWithNewsAndContact.
@Test
public void testCreateCourseGroupWithNewsAndContact() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
// create the group
GroupVO vo = new GroupVO();
vo.setName("rest-g7-news");
vo.setDescription("rest-g7 with news");
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[] { "hasContactForm", "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);
assertTrue(configResponse.getStatusLine().getStatusCode() == 200 || configResponse.getStatusLine().getStatusCode() == 201);
EntityUtils.consume(configResponse.getEntity());
// check group
BusinessGroup bg = businessGroupService.loadBusinessGroup(newGroupVo.getKey());
assertNotNull(bg);
assertEquals(bg.getKey(), newGroupVo.getKey());
assertEquals(bg.getName(), "rest-g7-news");
assertEquals(bg.getDescription(), "rest-g7 with news");
// check collaboration tools configuration
CollaborationTools tools = CollaborationToolsFactory.getInstance().getCollaborationToolsIfExists(bg);
assertNotNull(tools);
assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_FOLDER));
assertTrue(tools.isToolEnabled(CollaborationTools.TOOL_NEWS));
assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_CALENDAR));
assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_CHAT));
assertTrue(tools.isToolEnabled(CollaborationTools.TOOL_CONTACT));
assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_FORUM));
assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_PORTFOLIO));
assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_WIKI));
// Check news tools access configuration
assertEquals("<p>News!</p>", tools.lookupNews());
}
use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class GroupMgmtTest method setUp.
/**
* Set up a course with learn group and group area
* @see org.olat.test.OlatJerseyTestCase#setUp()
*/
@Before
@Override
public void setUp() throws Exception {
super.setUp();
conn = new RestConnection();
// create a course with learn group
owner1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-one");
owner2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-two");
owner3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-three");
part1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-four");
part2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-five");
part3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-six");
OLATResourceManager rm = OLATResourceManager.getInstance();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
course = rm.findOrPersistResourceable(resourceable);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
DBFactory.getInstance().commit();
assertNotNull(re);
// create learn group
// 1) context one: learning groups
RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
// create groups without waiting list
g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, 0, 10, false, false, c1);
g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, 0, 10, false, false, c1);
DBFactory.getInstance().commit();
// permission to see owners and participants
businessGroupService.updateDisplayMembers(g1, false, false, false, false, false, false, false);
businessGroupService.updateDisplayMembers(g2, true, true, false, false, false, false, false);
// members g1
businessGroupRelationDao.addRole(owner1, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(owner2, g1, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g1, GroupRoles.participant.name());
businessGroupRelationDao.addRole(part2, g1, GroupRoles.participant.name());
// members g2
businessGroupRelationDao.addRole(owner1, g2, GroupRoles.coach.name());
businessGroupRelationDao.addRole(part1, g2, GroupRoles.participant.name());
// 2) context two: right groups
RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
// groups
g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, -1, -1, false, false, c2);
g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, -1, -1, false, false, c2);
DBFactory.getInstance().commit();
// members
businessGroupRelationDao.addRole(owner1, g3, GroupRoles.participant.name());
businessGroupRelationDao.addRole(owner2, g4, GroupRoles.participant.name());
// 3) collaboration tools
CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
collabTools1.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
collabTools1.setToolEnabled(CollaborationTools.TOOL_WIKI, true);
collabTools1.saveNews("<p>Hello world</p>");
try {
collabTools1.createForumController(null, null, true, false, null);
} catch (Exception e) {
// will fail but generate the forum key
}
CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
collabTools2.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
// simulate user clicks
DBFactory.getInstance().closeSession();
// 4) fill forum for g1
NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(g1);
Property forumKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
ForumManager fm = ForumManager.getInstance();
Forum forum = fm.loadForum(forumKeyProperty.getLongValue());
m1 = fm.createMessage(forum, owner1, false);
m1.setTitle("Thread-1");
m1.setBody("Body of Thread-1");
fm.addTopMessage(m1);
m2 = fm.createMessage(forum, owner2, false);
m2.setTitle("Thread-2");
m2.setBody("Body of Thread-2");
fm.addTopMessage(m2);
DBFactory.getInstance().intermediateCommit();
m3 = fm.createMessage(forum, owner3, false);
m3.setTitle("Message-1.1");
m3.setBody("Body of Message-1.1");
fm.replyToMessage(m3, m1);
m4 = fm.createMessage(forum, part1, false);
m4.setTitle("Message-1.1.1");
m4.setBody("Body of Message-1.1.1");
fm.replyToMessage(m4, m3);
m5 = fm.createMessage(forum, part2, false);
m5.setTitle("Message-1.2");
m5.setBody("Body of Message-1.2");
fm.replyToMessage(m5, m1);
DBFactory.getInstance().intermediateCommit();
}
use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class NotificationsTest method testGetBusinessGroupFolderNotifications.
@Test
public void testGetBusinessGroupFolderNotifications() throws IOException, URISyntaxException {
// create a business group with folder notifications
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("rest-not-5-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupService.createBusinessGroup(id, "Notifications 2", "REST folder notifications for group", null, null, false, false, null);
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
tools.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
String relPath = tools.getFolderRelPath();
dbInstance.commitAndCloseSession();
// publish
String businessPath = "[BusinessGroup:" + group.getKey() + "][toolfolder:0]";
SubscriptionContext folderSubContext = new SubscriptionContext("BusinessGroup", group.getKey(), "toolfolder");
PublisherData folderPdata = new PublisherData("FolderModule", relPath, businessPath);
notificationManager.subscribe(id, folderSubContext, folderPdata);
// add a file
OlatRootFolderImpl folder = tools.getSecuredFolder(group, folderSubContext, id, true);
String filename = addFile(folder);
// mark as published
notificationManager.markPublisherNews(folderSubContext, null, true);
dbInstance.commitAndCloseSession();
// get the notification
RestConnection conn = new RestConnection();
assertTrue(conn.login(id.getName(), "A6B7C8"));
UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications");
HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<SubscriptionInfoVO> infos = parseUserArray(response.getEntity().getContent());
Assert.assertNotNull(infos);
Assert.assertEquals(1, infos.size());
SubscriptionInfoVO infoVO = infos.get(0);
Assert.assertNotNull(infoVO.getItems());
Assert.assertEquals(1, infoVO.getItems().size());
SubscriptionListItemVO itemVO = infoVO.getItems().get(0);
Assert.assertNotNull(itemVO);
Assert.assertEquals(group.getKey(), itemVO.getGroupKey());
Assert.assertEquals("/" + filename, itemVO.getPath());
}
use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class NotificationsTest method testGetBusinessGroupForumNotifications.
@Test
public void testGetBusinessGroupForumNotifications() throws IOException, URISyntaxException {
// create a business group with forum notifications
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("rest-not-4-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupService.createBusinessGroup(id, "Notifications 1", "REST forum notifications for group", null, null, false, false, null);
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
tools.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
Forum groupForum = tools.getForum();
dbInstance.commitAndCloseSession();
// publish
String businessPath = "[BusinessGroup:" + group.getKey() + "][toolforum:0]";
SubscriptionContext forumSubContext = new SubscriptionContext("BusinessGroup", group.getKey(), "toolforum");
PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), groupForum.getKey().toString(), businessPath);
notificationManager.subscribe(id, forumSubContext, forumPdata);
Message message = createMessage(id, groupForum);
notificationManager.markPublisherNews(forumSubContext, null, true);
dbInstance.commitAndCloseSession();
// get the notification
RestConnection conn = new RestConnection();
assertTrue(conn.login(id.getName(), "A6B7C8"));
UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications");
HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<SubscriptionInfoVO> infos = parseUserArray(response.getEntity().getContent());
Assert.assertNotNull(infos);
Assert.assertEquals(1, infos.size());
SubscriptionInfoVO infoVO = infos.get(0);
Assert.assertNotNull(infoVO.getItems());
Assert.assertEquals(1, infoVO.getItems().size());
SubscriptionListItemVO itemVO = infoVO.getItems().get(0);
Assert.assertNotNull(itemVO);
Assert.assertEquals(group.getKey(), itemVO.getGroupKey());
Assert.assertEquals(message.getKey(), itemVO.getMessageKey());
}
use of org.olat.collaboration.CollaborationTools in project openolat by klemens.
the class OLATUpgrade_11_4_0 method processInfoMessage.
/**
* @param business group
* @return true if upgrade went well
*/
private boolean processInfoMessage(BusinessGroup businessGroup) {
// iterate all groups and translate their singular info message to the new standard
try {
String businessPath = "[BusinessGroup:" + businessGroup.getKey() + "][toolmsg:0]";
int messageCount = infoMessageManager.countInfoMessageByResource(businessGroup.getResource(), InfoMessageFrontendManager.businessGroupResSubPath, businessPath, null, null);
// only upgrade if business group has not any info messages of the new kind yet
if (1 > messageCount) {
CollaborationTools collabTools = toolsF.getOrCreateCollaborationTools(businessGroup);
Property property = collabTools.lookupNewsDBEntry();
if (property != null) {
// collabTools.lookupNews();
String oldNews = property.getTextValue();
Identity author;
List<Identity> members = groupService.getMembers(businessGroup, GroupRoles.owner.name(), GroupRoles.coach.name());
if (members == null || (members != null && members.isEmpty())) {
author = deletionManager.getAdminUserIdentity();
} else {
author = members.get(0);
}
InfoMessageImpl infoMessage = (InfoMessageImpl) infoMessageManager.createInfoMessage(businessGroup.getResource(), InfoMessageFrontendManager.businessGroupResSubPath, businessPath, author);
Translator trans = Util.createPackageTranslator(CollaborationTools.class, I18nModule.getDefaultLocale());
String title = trans.translate("news.content");
infoMessage.setTitle(title);
infoMessage.setMessage(oldNews);
infoMessage.setCreationDate(property.getCreationDate());
infoMessageManager.saveInfoMessage(infoMessage);
} else {
log.warn("The group " + businessGroup.getName() + " does not have an info message");
}
}
return true;
} catch (Exception e) {
log.warn("Update InfoMessage for " + businessGroup.getName() + " failed", e);
return false;
}
}
Aggregations