use of org.olat.restapi.support.vo.GroupVO in project OpenOLAT by OpenOLAT.
the class ENWebService method getGroups.
/**
* Retrieves the groups where the enrollment happens
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The groups
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or course node not found
* @param nodeId The node's id
* @param httpRequest The HTTP request
* @return An array of groups
*/
@GET
@Path("{nodeId}/groups")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getGroups(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest httpRequest) {
if (!isAuthor(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(course, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
CourseNode node = getParentNode(course, nodeId);
ModuleConfiguration config = node.getModuleConfiguration();
String groupNames = (String) config.get(ENCourseNode.CONFIG_GROUPNAME);
@SuppressWarnings("unchecked") List<Long> groupKeys = (List<Long>) config.get(ENCourseNode.CONFIG_GROUP_IDS);
if (groupKeys == null && StringHelper.containsNonWhitespace(groupNames)) {
groupKeys = bgs.toGroupKeys(groupNames, course.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
}
if (groupKeys == null || groupKeys.isEmpty()) {
return Response.ok(new GroupVO[0]).build();
}
List<GroupVO> voes = new ArrayList<GroupVO>();
List<BusinessGroup> groups = bgs.loadBusinessGroups(groupKeys);
for (BusinessGroup group : groups) {
voes.add(get(group));
}
GroupVO[] voArr = new GroupVO[voes.size()];
voes.toArray(voArr);
return Response.ok(voArr).build();
}
use of org.olat.restapi.support.vo.GroupVO 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());
}
use of org.olat.restapi.support.vo.GroupVO in project OpenOLAT by OpenOLAT.
the class GroupMgmtTest method testGetGroups.
@Test
public void testGetGroups() throws IOException, URISyntaxException {
assertTrue(conn.login("rest-four", "A6B7C8"));
URI request = UriBuilder.fromUri(getContextURI()).path("groups").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<GroupVO> groups = parseGroupArray(body);
assertNotNull(groups);
// g1, g2, g3 and g4 + from olat
assertTrue(groups.size() >= 2);
Set<Long> keys = new HashSet<Long>();
for (GroupVO vo : groups) {
keys.add(vo.getKey());
}
assertTrue(keys.contains(g1.getKey()));
assertTrue(keys.contains(g2.getKey()));
assertFalse(keys.contains(g3.getKey()));
assertFalse(keys.contains(g4.getKey()));
}
use of org.olat.restapi.support.vo.GroupVO in project OpenOLAT by OpenOLAT.
the class GroupMgmtTest method testGetGroupsAdmin.
@Test
public void testGetGroupsAdmin() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("groups").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<GroupVO> groups = parseGroupArray(body);
assertNotNull(groups);
// g1, g2, g3 and g4 + from olat
assertTrue(groups.size() >= 4);
Set<Long> keys = new HashSet<Long>();
for (GroupVO vo : groups) {
keys.add(vo.getKey());
}
assertTrue(keys.contains(g1.getKey()));
assertTrue(keys.contains(g2.getKey()));
assertTrue(keys.contains(g3.getKey()));
assertTrue(keys.contains(g4.getKey()));
}
use of org.olat.restapi.support.vo.GroupVO 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());
}
Aggregations