use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method getNews.
/**
* Returns the news.
*
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The business group cannot be found or the news tool is not enabled
* @param groupKey The key of the group
* @param request The HTTP Request
* @return
*/
@GET
@Path("{groupKey}/news")
@Produces({ MediaType.TEXT_PLAIN })
public Response getNews(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
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();
}
if (!isGroupManager(request)) {
Identity identity = RestSecurityHelper.getIdentity(request);
if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
if (tools.isToolEnabled(CollaborationTools.TOOL_NEWS)) {
String news = tools.lookupNews();
if (news == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
return Response.ok(news).build();
} else {
return Response.serverError().status(Status.NOT_FOUND).build();
}
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method getForum.
/**
* Return the Forum web service
* @param groupKey The key of the group
* @param request The HTTP Request
* @return
*/
@Path("{groupKey}/forum")
public ForumWebService getForum(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey);
if (bg == null) {
return null;
}
if (!isGroupManager(request)) {
Identity identity = RestSecurityHelper.getIdentity(request);
if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
return null;
}
}
CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
if (collabTools.isToolEnabled(CollaborationTools.TOOL_FORUM)) {
Forum forum = collabTools.getForum();
return new ForumWebService(forum);
}
return null;
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
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.group.BusinessGroupService 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();
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class ContactsWebService method getMyContacts.
/**
* Retrieve the contacts of the logged in identity.
* @response.representation.200.doc The list of contacts
* @param start
* @param limit
* @param httpRequest The HTTP request
* @return The list of contacts
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getMyContacts(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest) {
Identity identity = getIdentity(httpRequest);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<Identity> contacts = bgs.findContacts(identity, start, limit);
int totalCount = bgs.countContacts(identity);
int count = 0;
ContactVO[] userVOs = new ContactVO[contacts.size()];
for (Identity contact : contacts) {
userVOs[count++] = new ContactVO(contact);
}
ContactVOes voes = new ContactVOes();
voes.setUsers(userVOs);
voes.setTotalCount(totalCount);
return Response.ok(voes).build();
}
Aggregations