Search in sources :

Example 21 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project openolat by klemens.

the class GroupFoldersTest method setUp.

/**
 * Set up a course with learn group and group area
 * EXACTLY THE SAME AS GroupMgmTest
 * @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");
    part1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-four");
    part2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-five");
    // create course and persist as OLATResourceImpl
    OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
    course = OLATResourceManager.getInstance().findOrPersistResourceable(resourceable);
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
    repositoryService.update(re);
    DBFactory.getInstance().commit();
    // 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().commitAndCloseSession();
    // 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());
    // 3) collaboration tools
    CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
    collabTools1.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
    CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
    collabTools2.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
    // simulate user clicks
    DBFactory.getInstance().commitAndCloseSession();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) CollaborationTools(org.olat.collaboration.CollaborationTools) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryService(org.olat.repository.RepositoryService) Before(org.junit.Before)

Example 22 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project openolat by klemens.

the class GroupFoldersTest method testGetSubFolder.

@Test
public void testGetSubFolder() throws IOException, URISyntaxException {
    // create some sub folders
    CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
    String folderRelPath = collabTools1.getFolderRelPath();
    OlatRootFolderImpl folder = new OlatRootFolderImpl(folderRelPath, null);
    VFSContainer newFolder1 = folder.createChildContainer("New folder 1");
    if (newFolder1 == null) {
        newFolder1 = (VFSContainer) folder.resolve("New folder 1");
    }
    assertNotNull(newFolder1);
    VFSContainer newFolder11 = newFolder1.createChildContainer("New folder 1_1");
    if (newFolder11 == null) {
        newFolder11 = (VFSContainer) newFolder1.resolve("New folder 1_1");
    }
    assertNotNull(newFolder11);
    assertTrue(conn.login("rest-one", "A6B7C8"));
    // get root folder
    URI request0 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/").build();
    HttpGet method0 = conn.createGet(request0, MediaType.APPLICATION_JSON, true);
    HttpResponse code0 = conn.execute(method0);
    assertEquals(200, code0.getStatusLine().getStatusCode());
    InputStream body0 = code0.getEntity().getContent();
    assertNotNull(body0);
    List<FileVO> fileVos0 = parseFileArray(body0);
    assertNotNull(fileVos0);
    assertEquals(1, fileVos0.size());
    // get sub folder
    URI request1 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1").build();
    HttpGet method1 = conn.createGet(request1, MediaType.APPLICATION_JSON, true);
    HttpResponse code1 = conn.execute(method1);
    assertEquals(200, code1.getStatusLine().getStatusCode());
    InputStream body1 = code1.getEntity().getContent();
    assertNotNull(body1);
    List<FileVO> fileVos1 = parseFileArray(body1);
    assertNotNull(fileVos1);
    assertEquals(1, fileVos1.size());
    // get sub folder by link
    FileVO fileVO = fileVos1.get(0);
    URI fileUri = new URI(fileVO.getHref());
    HttpGet brutMethod = conn.createGet(fileUri, "*/*", true);
    brutMethod.addHeader("Accept", MediaType.APPLICATION_JSON);
    HttpResponse codeBrut = conn.execute(brutMethod);
    assertEquals(200, codeBrut.getStatusLine().getStatusCode());
    EntityUtils.consume(codeBrut.getEntity());
    // get sub sub folder
    URI request2 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1/New_folder_1_1").build();
    HttpGet method2 = conn.createGet(request2, MediaType.APPLICATION_JSON, true);
    HttpResponse code2 = conn.execute(method2);
    assertEquals(200, code2.getStatusLine().getStatusCode());
    InputStream body2 = code2.getEntity().getContent();
    assertNotNull(body2);
    EntityUtils.consume(code2.getEntity());
    // get sub folder with end /
    URI request3 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1/").build();
    HttpGet method3 = conn.createGet(request3, MediaType.APPLICATION_JSON, true);
    HttpResponse code3 = conn.execute(method3);
    assertEquals(200, code3.getStatusLine().getStatusCode());
    InputStream body3 = code3.getEntity().getContent();
    assertNotNull(body3);
    List<FileVO> fileVos3 = parseFileArray(body3);
    assertNotNull(fileVos3);
    assertEquals(1, fileVos3.size());
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpGet(org.apache.http.client.methods.HttpGet) CollaborationTools(org.olat.collaboration.CollaborationTools) FileVO(org.olat.restapi.support.vo.FileVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 23 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project openolat by klemens.

the class GroupMgmtTest method testCreateCourseGroupWithConfiguration.

@Test
public void testCreateCourseGroupWithConfiguration() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    // create the group
    GroupVO vo = new GroupVO();
    vo.setName("rest-g6-new");
    vo.setDescription("rest-g6 description");
    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[] { "hasFolder", "hasNews" });
    HashMap<String, Integer> toolsAccess = new HashMap<String, Integer>();
    toolsAccess.put("hasFolder", new Integer(CollaborationTools.FOLDER_ACCESS_OWNERS));
    configVo.setToolsAccess(toolsAccess);
    configVo.setOwnersVisible(Boolean.TRUE);
    configVo.setParticipantsVisible(Boolean.FALSE);
    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-g6-new");
    assertEquals(bg.getDescription(), "rest-g6 description");
    // check collaboration tools configuration
    CollaborationTools tools = CollaborationToolsFactory.getInstance().getCollaborationToolsIfExists(bg);
    assertNotNull(tools);
    assertTrue(tools.isToolEnabled(CollaborationTools.TOOL_FOLDER));
    assertTrue(tools.isToolEnabled(CollaborationTools.TOOL_NEWS));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_CALENDAR));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_CHAT));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_CONTACT));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_FORUM));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_PORTFOLIO));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_WIKI));
    // Check collab tools access configuration
    // modified
    assertTrue(tools.lookupFolderAccess().intValue() == CollaborationTools.FOLDER_ACCESS_OWNERS);
    // not explicitly initialized -> null
    assertNull(tools.lookupCalendarAccess());
    // check display members
    assertTrue(bg.isOwnersVisibleIntern());
    assertFalse(bg.isParticipantsVisibleIntern());
    assertFalse(bg.isWaitingListVisibleIntern());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) GroupConfigurationVO(org.olat.restapi.support.vo.GroupConfigurationVO) HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) HttpResponse(org.apache.http.HttpResponse) GroupVO(org.olat.restapi.support.vo.GroupVO) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 24 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project openolat by klemens.

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);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) GroupConfigurationVO(org.olat.restapi.support.vo.GroupConfigurationVO) HttpDelete(org.apache.http.client.methods.HttpDelete) BusinessGroup(org.olat.group.BusinessGroup) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CollaborationTools(org.olat.collaboration.CollaborationTools) HttpResponse(org.apache.http.HttpResponse) GroupVO(org.olat.restapi.support.vo.GroupVO) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 25 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project openolat by klemens.

the class ObjectFactory method getInformation.

public static GroupInfoVO getInformation(Identity identity, BusinessGroup grp) {
    GroupInfoVO vo = new GroupInfoVO();
    vo.setKey(grp.getKey());
    vo.setName(grp.getName());
    vo.setDescription(grp.getDescription());
    vo.setMaxParticipants(grp.getMaxParticipants());
    vo.setMinParticipants(grp.getMinParticipants());
    vo.setType("LearningGroup");
    CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(grp);
    if (collabTools.isToolEnabled(CollaborationTools.TOOL_FORUM)) {
        vo.setForumKey(collabTools.getForum().getKey());
    }
    String news = collabTools.lookupNews();
    vo.setNews(news);
    boolean hasWiki = collabTools.isToolEnabled(CollaborationTools.TOOL_WIKI);
    vo.setHasWiki(hasWiki);
    boolean hasFolder = collabTools.isToolEnabled(CollaborationTools.TOOL_FOLDER);
    vo.setHasFolder(hasFolder);
    boolean hasFolderWrite = hasFolder;
    if (hasFolder) {
        Long access = collabTools.lookupFolderAccess();
        if (access != null && access.intValue() == CollaborationTools.FOLDER_ACCESS_OWNERS) {
            // is owner?
            hasFolderWrite = CoreSpringFactory.getImpl(BusinessGroupService.class).hasRoles(identity, grp, GroupRoles.coach.name());
        }
    }
    vo.setFolderWrite(hasFolderWrite);
    return vo;
}
Also used : GroupInfoVO(org.olat.restapi.support.vo.GroupInfoVO) CollaborationTools(org.olat.collaboration.CollaborationTools)

Aggregations

CollaborationTools (org.olat.collaboration.CollaborationTools)98 BusinessGroup (org.olat.group.BusinessGroup)58 Identity (org.olat.core.id.Identity)30 Test (org.junit.Test)28 HttpResponse (org.apache.http.HttpResponse)22 BusinessGroupService (org.olat.group.BusinessGroupService)22 Path (javax.ws.rs.Path)18 WindowControl (org.olat.core.gui.control.WindowControl)18 URI (java.net.URI)16 HttpGet (org.apache.http.client.methods.HttpGet)16 ContextEntry (org.olat.core.id.context.ContextEntry)16 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)14 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)14 Forum (org.olat.modules.fo.Forum)12 Activateable2 (org.olat.core.gui.control.generic.dtabs.Activateable2)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 IOException (java.io.IOException)8 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 InputStream (java.io.InputStream)7 ArrayList (java.util.ArrayList)6