use of org.olat.restapi.support.vo.GroupVO in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method createGroup.
/**
* Create a group.
* @response.representation.qname {http://www.example.com}groupVO
* @response.representation.mediaType application/xml, application/json
* @response.representation.doc A business group in the OLAT system
* @response.representation.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVO}
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The saved business group
* @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 business group cannot be found
* @param groupKey The key of the group
* @param group The group
* @param request The HTTP request
* @return
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createGroup(final GroupVO group, @Context HttpServletRequest request) {
Identity identity = RestSecurityHelper.getIdentity(request);
if (identity == null || !isGroupManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
if (group.getKey() != null && group.getKey().longValue() > 0) {
return postGroup(group.getKey(), group, request);
}
if (!StringHelper.containsNonWhitespace(group.getName())) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
}
Integer minPart = normalize(group.getMinParticipants());
Integer maxPart = normalize(group.getMaxParticipants());
BusinessGroup newBG = bgs.createBusinessGroup(identity, group.getName(), group.getDescription(), group.getExternalId(), group.getManagedFlags(), minPart, maxPart, false, false, null);
GroupVO savedVO = ObjectFactory.get(newBG);
return Response.ok(savedVO).build();
}
use of org.olat.restapi.support.vo.GroupVO in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method getGroupList.
/**
* Return the list of all groups if you have group manager permission, or all
* learning group that you particip with or owne.
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc This is the list of all groups in OLAT system
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVOes}
* @param externalId Search with an external ID
* @param managed (true / false) Search only managed / not managed groups
* @param request The HTTP Request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getGroupList(@QueryParam("externalId") String externalId, @QueryParam("managed") Boolean managed, @Context HttpServletRequest request) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<BusinessGroup> groups;
SearchBusinessGroupParams params;
if (isGroupManager(request)) {
params = new SearchBusinessGroupParams();
} else {
Identity identity = RestSecurityHelper.getIdentity(request);
params = new SearchBusinessGroupParams(identity, true, true);
}
if (StringHelper.containsNonWhitespace(externalId)) {
params.setExternalId(externalId);
}
params.setManaged(managed);
groups = bgs.findBusinessGroups(params, null, 0, -1);
int count = 0;
GroupVO[] groupVOs = new GroupVO[groups.size()];
for (BusinessGroup bg : groups) {
groupVOs[count++] = ObjectFactory.get(bg);
}
return Response.ok(groupVOs).build();
}
use of org.olat.restapi.support.vo.GroupVO in project OpenOLAT by OpenOLAT.
the class ObjectFactory method get.
public static GroupVO get(BusinessGroup grp) {
GroupVO vo = new GroupVO();
vo.setKey(grp.getKey());
vo.setName(grp.getName());
vo.setDescription(grp.getDescription());
vo.setMaxParticipants(grp.getMaxParticipants());
vo.setMinParticipants(grp.getMinParticipants());
vo.setExternalId(grp.getExternalId());
vo.setManagedFlags(grp.getManagedFlagsString());
vo.setType("LearningGroup");
return vo;
}
use of org.olat.restapi.support.vo.GroupVO in project OpenOLAT by OpenOLAT.
the class GroupMgmtTest method testCreateCourseGroup.
@Test
public void testCreateCourseGroup() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
GroupVO vo = new GroupVO();
vo.setName("rest-g5-new");
vo.setDescription("rest-g5 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);
BusinessGroup bg = businessGroupService.loadBusinessGroup(newGroupVo.getKey());
assertNotNull(bg);
assertEquals(bg.getKey(), newGroupVo.getKey());
assertEquals(bg.getName(), "rest-g5-new");
assertEquals(bg.getDescription(), "rest-g5 description");
}
use of org.olat.restapi.support.vo.GroupVO 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);
}
Aggregations