Search in sources :

Example 46 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.

the class LearningGroupWebService method postGroupConfiguration.

@POST
@Path("{groupKey}/configuration")
public Response postGroupConfiguration(@PathParam("groupKey") Long groupKey, final GroupConfigurationVO group, @Context HttpServletRequest request) {
    if (!isGroupManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
    if (bg == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    String[] selectedTools = group.getTools();
    if (selectedTools == null) {
        selectedTools = new String[0];
    }
    String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
    CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    for (int i = availableTools.length; i-- > 0; ) {
        boolean enable = false;
        String tool = availableTools[i];
        for (String selectedTool : selectedTools) {
            if (tool.equals(selectedTool)) {
                enable = true;
            }
        }
        tools.setToolEnabled(tool, enable);
    }
    Map<String, Integer> toolsAccess = group.getToolsAccess();
    if (toolsAccess != null) {
        // ignore null for backward compatibility, don't change current configuration
        for (String tool : toolsAccess.keySet()) {
            tools.setToolAccess(tool, toolsAccess.get(tool));
        }
    }
    if (StringHelper.containsNonWhitespace(group.getNews())) {
        tools.saveNews(group.getNews());
    }
    boolean ownersIntern = bg.isOwnersVisibleIntern();
    if (group.getOwnersVisible() != null) {
        ownersIntern = group.getOwnersVisible().booleanValue();
    }
    boolean participantsIntern = bg.isParticipantsVisibleIntern();
    if (group.getParticipantsVisible() != null) {
        participantsIntern = group.getParticipantsVisible().booleanValue();
    }
    boolean waitingListIntern = bg.isWaitingListVisibleIntern();
    if (group.getWaitingListVisible() != null) {
        waitingListIntern = group.getWaitingListVisible().booleanValue();
    }
    boolean ownersPublic = bg.isOwnersVisiblePublic();
    if (group.getOwnersPublic() != null) {
        ownersPublic = group.getOwnersPublic().booleanValue();
    }
    boolean participantsPublic = bg.isParticipantsVisiblePublic();
    if (group.getParticipantsPublic() != null) {
        participantsPublic = group.getParticipantsPublic().booleanValue();
    }
    boolean waitingListPublic = bg.isWaitingListVisiblePublic();
    if (group.getWaitingListPublic() != null) {
        waitingListPublic = group.getWaitingListPublic().booleanValue();
    }
    bg = bgs.updateDisplayMembers(bg, ownersIntern, participantsIntern, waitingListIntern, ownersPublic, participantsPublic, waitingListPublic, bg.isDownloadMembersLists());
    return Response.ok().build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 47 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.

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)

Example 48 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.

the class GroupFoldersTest method testGetFileMetadata.

@Test
public void testGetFileMetadata() throws IOException, URISyntaxException {
    // create some sub folders and copy file
    CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
    String folderRelPath = collabTools2.getFolderRelPath();
    OlatRootFolderImpl folder = new OlatRootFolderImpl(folderRelPath, null);
    VFSContainer newFolder1 = folder.createChildContainer("Metadata folder");
    if (newFolder1 == null) {
        newFolder1 = (VFSContainer) folder.resolve("Metadata folder");
    }
    VFSLeaf file = (VFSLeaf) newFolder1.resolve("portrait.jpg");
    if (file == null) {
        file = newFolder1.createChildLeaf("portrait.jpg");
        OutputStream out = file.getOutputStream(true);
        InputStream in = GroupFoldersTest.class.getResourceAsStream("portrait.jpg");
        FileUtils.copy(in, out);
        FileUtils.closeSafely(in);
        FileUtils.closeSafely(out);
    }
    // get the file
    assertTrue(conn.login("rest-one", "A6B7C8"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g2.getKey() + "/folder/metadata/Metadata_folder/portrait.jpg").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    FileMetadataVO fileMetadataVO = conn.parse(response, FileMetadataVO.class);
    Assert.assertNotNull(fileMetadataVO);
    Assert.assertEquals("portrait.jpg", fileMetadataVO.getFileName());
    Assert.assertNotNull(fileMetadataVO.getSize());
    Assert.assertEquals(file.getSize(), fileMetadataVO.getSize().longValue());
    Assert.assertNotNull(fileMetadataVO.getHref());
    Assert.assertNotNull(fileMetadataVO.getLastModified());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) OutputStream(java.io.OutputStream) HttpGet(org.apache.http.client.methods.HttpGet) CollaborationTools(org.olat.collaboration.CollaborationTools) FileMetadataVO(org.olat.restapi.support.vo.FileMetadataVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 49 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.

the class GroupFoldersTest method testGetFile.

@Test
public void testGetFile() throws IOException, URISyntaxException {
    // create some sub folders and copy file
    CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
    String folderRelPath = collabTools2.getFolderRelPath();
    OlatRootFolderImpl folder = new OlatRootFolderImpl(folderRelPath, null);
    VFSContainer newFolder1 = folder.createChildContainer("New folder 2");
    if (newFolder1 == null) {
        newFolder1 = (VFSContainer) folder.resolve("New folder 2");
    }
    VFSLeaf file = (VFSLeaf) newFolder1.resolve("portrait.jpg");
    if (file == null) {
        file = newFolder1.createChildLeaf("portrait.jpg");
        OutputStream out = file.getOutputStream(true);
        InputStream in = GroupFoldersTest.class.getResourceAsStream("portrait.jpg");
        FileUtils.copy(in, out);
        FileUtils.closeSafely(in);
        FileUtils.closeSafely(out);
    }
    // get the file
    assertTrue(conn.login("rest-one", "A6B7C8"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g2.getKey() + "/folder/New_folder_2/portrait.jpg").build();
    HttpGet method = conn.createGet(request, "*/*", true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    byte[] byteArr = IOUtils.toByteArray(body);
    Assert.assertNotNull(byteArr);
    Assert.assertEquals(file.getSize(), byteArr.length);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) OutputStream(java.io.OutputStream) HttpGet(org.apache.http.client.methods.HttpGet) CollaborationTools(org.olat.collaboration.CollaborationTools) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 50 with CollaborationTools

use of org.olat.collaboration.CollaborationTools in project OpenOLAT by OpenOLAT.

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)

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