Search in sources :

Example 1 with GroupConfigurationVO

use of org.olat.restapi.support.vo.GroupConfigurationVO 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);
}
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 2 with GroupConfigurationVO

use of org.olat.restapi.support.vo.GroupConfigurationVO 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 3 with GroupConfigurationVO

use of org.olat.restapi.support.vo.GroupConfigurationVO 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 4 with GroupConfigurationVO

use of org.olat.restapi.support.vo.GroupConfigurationVO in project OpenOLAT by OpenOLAT.

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());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) GroupConfigurationVO(org.olat.restapi.support.vo.GroupConfigurationVO) 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 5 with GroupConfigurationVO

use of org.olat.restapi.support.vo.GroupConfigurationVO in project OpenOLAT by OpenOLAT.

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)

Aggregations

URI (java.net.URI)6 HttpResponse (org.apache.http.HttpResponse)6 HttpPost (org.apache.http.client.methods.HttpPost)6 HttpPut (org.apache.http.client.methods.HttpPut)6 Test (org.junit.Test)6 CollaborationTools (org.olat.collaboration.CollaborationTools)6 BusinessGroup (org.olat.group.BusinessGroup)6 GroupConfigurationVO (org.olat.restapi.support.vo.GroupConfigurationVO)6 GroupVO (org.olat.restapi.support.vo.GroupVO)6 HashMap (java.util.HashMap)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2