Skip to content
Snippets Groups Projects
Commit 5d99c2f7 authored by srosse's avatar srosse
Browse files

CL-155: add a REST method to configure a group

parent b5061bc0
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,7 @@ import org.olat.modules.fo.restapi.ForumWebService;
import org.olat.modules.wiki.restapi.GroupWikiWebService;
import org.olat.restapi.security.RestSecurityHelper;
import org.olat.restapi.support.ObjectFactory;
import org.olat.restapi.support.vo.GroupConfigurationVO;
import org.olat.restapi.support.vo.GroupInfoVO;
import org.olat.restapi.support.vo.GroupVO;
import org.olat.user.restapi.UserVO;
......@@ -263,6 +264,58 @@ public class LearningGroupWebService {
return Response.ok(savedVO).build();
}
@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);
final 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];
}
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
for (int i=CollaborationTools.TOOLS.length; i-->0; ) {
boolean enable = false;
String tool = CollaborationTools.TOOLS[i];
for(String selectedTool:selectedTools) {
if(tool.equals(selectedTool)) {
enable = true;
}
}
tools.setToolEnabled(tool, enable);
}
DisplayMembers displayMembers = bgs.getDisplayMembers(bg);
if(group.getOwnersVisible() != null) {
displayMembers.setShowOwners(group.getOwnersVisible().booleanValue());
}
if(group.getParticipantsVisible() != null) {
displayMembers.setShowParticipants(group.getParticipantsVisible().booleanValue());
}
if(group.getWaitingListVisible() != null) {
displayMembers.setShowWaitingList(group.getWaitingListVisible().booleanValue());
}
if(group.getOwnersPublic() != null) {
displayMembers.setOwnersPublic(group.getOwnersPublic().booleanValue());
}
if(group.getParticipantsPublic() != null) {
displayMembers.setParticipantsPublic(group.getParticipantsPublic().booleanValue());
}
if(group.getWaitingListPublic() != null) {
displayMembers.setWaitingListPublic(group.getWaitingListPublic().booleanValue());
}
bgs.updateDisplayMembers(bg, displayMembers);
return Response.ok().build();
}
/**
* Deletes the business group specified by the groupKey.
* @response.representation.200.doc The business group is deleted
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.restapi.support.vo;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author srosse
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "groupVO")
public class GroupConfigurationVO {
private String[] tools;
private Boolean ownersVisible;
private Boolean participantsVisible;
private Boolean waitingListVisible;
private Boolean ownersPublic;
private Boolean participantsPublic;
private Boolean waitingListPublic;
public String[] getTools() {
return tools;
}
public void setTools(String[] tools) {
this.tools = tools;
}
public Boolean getOwnersVisible() {
return ownersVisible;
}
public void setOwnersVisible(Boolean ownersVisible) {
this.ownersVisible = ownersVisible;
}
public Boolean getParticipantsVisible() {
return participantsVisible;
}
public void setParticipantsVisible(Boolean participantsVisible) {
this.participantsVisible = participantsVisible;
}
public Boolean getWaitingListVisible() {
return waitingListVisible;
}
public void setWaitingListVisible(Boolean waitingListVisible) {
this.waitingListVisible = waitingListVisible;
}
public Boolean getOwnersPublic() {
return ownersPublic;
}
public void setOwnersPublic(Boolean ownersPublic) {
this.ownersPublic = ownersPublic;
}
public Boolean getParticipantsPublic() {
return participantsPublic;
}
public void setParticipantsPublic(Boolean participantsPublic) {
this.participantsPublic = participantsPublic;
}
public Boolean getWaitingListPublic() {
return waitingListPublic;
}
public void setWaitingListPublic(Boolean waitingListPublic) {
this.waitingListPublic = waitingListPublic;
}
}
......@@ -48,6 +48,7 @@ import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.junit.After;
......@@ -78,6 +79,7 @@ import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryManager;
import org.olat.resource.OLATResource;
import org.olat.resource.OLATResourceManager;
import org.olat.restapi.support.vo.GroupConfigurationVO;
import org.olat.restapi.support.vo.GroupInfoVO;
import org.olat.restapi.support.vo.GroupVO;
import org.olat.test.JunitTestHelper;
......@@ -441,6 +443,60 @@ public class GroupMgmtTest extends OlatJerseyTestCase {
assertEquals(bg.getDescription(), "rest-g5 description");
}
@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" });
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, true);
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 display members
DisplayMembers displayMembers = businessGroupService.getDisplayMembers(bg);
assertTrue(displayMembers.isShowOwners());
assertFalse(displayMembers.isShowParticipants());
assertFalse(displayMembers.isShowWaitingList());
}
@Test
public void testDeleteCourseGroup() throws IOException, URISyntaxException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment