use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.
the class CourseGroupWebService method putNewGroup.
/**
* Creates a new group for the course.
* @response.representation.qname {http://www.example.com}groupVO
* @response.representation.mediaType application/xml, application/json
* @response.representation.doc A group to save
* @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 persisted 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
* @param group The group's metadatas
* @param request The HTTP request
* @return
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response putNewGroup(GroupVO group, @Context HttpServletRequest request) {
if (!RestSecurityHelper.isGroupManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
BusinessGroupService bgm = CoreSpringFactory.getImpl(BusinessGroupService.class);
RepositoryEntry courseRe = RepositoryManager.getInstance().lookupRepositoryEntry(course, false);
BusinessGroup bg;
if (group.getKey() != null && group.getKey() > 0) {
// group already exists
bg = bgm.loadBusinessGroup(group.getKey());
bgm.addResourceTo(bg, courseRe);
} else {
Integer min = normalize(group.getMinParticipants());
Integer max = normalize(group.getMaxParticipants());
bg = bgm.createBusinessGroup(ureq.getIdentity(), group.getName(), group.getDescription(), group.getExternalId(), group.getManagedFlags(), min, max, false, false, courseRe);
}
GroupVO savedVO = ObjectFactory.get(bg);
return Response.ok(savedVO).build();
}
use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.
the class LearningGroupWebService method postGroup.
/**
* Updates 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
*/
@POST
@Path("{groupKey}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response postGroup(@PathParam("groupKey") Long groupKey, final GroupVO group, @Context HttpServletRequest request) {
if (!isGroupManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
final BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
if (bg == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
if (!StringHelper.containsNonWhitespace(group.getName())) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
}
Identity identity = RestSecurityHelper.getIdentity(request);
BusinessGroup mergedBg = bgs.updateBusinessGroup(identity, bg, group.getName(), group.getDescription(), group.getExternalId(), group.getManagedFlags(), normalize(group.getMinParticipants()), normalize(group.getMaxParticipants()));
// save the updated group
GroupVO savedVO = ObjectFactory.get(mergedBg);
return Response.ok(savedVO).build();
}
use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.
the class LearningGroupWebService method findById.
/**
* Return the group specified by the key of the group.
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc A business group in the OLAT system
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVO}
* @param groupKey The key of the group
* @param request The REST request
* @param httpRequest The HTTP request
* @return
*/
@GET
@Path("{groupKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response findById(@PathParam("groupKey") Long groupKey, @Context Request request, @Context HttpServletRequest httpRequest) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey);
if (bg == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Identity identity = RestSecurityHelper.getIdentity(httpRequest);
if (!isGroupManager(httpRequest) && !bgs.isIdentityInBusinessGroup(identity, bg)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
Date lastModified = bg.getLastModified();
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
GroupVO vo = ObjectFactory.get(bg);
response = Response.ok(vo);
}
return response.build();
}
use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.
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();
}
Aggregations