use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.
the class CourseTest method getAuthors.
@Test
public void getAuthors() throws IOException, URISyntaxException {
// make auth1 and auth2 authors
SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
if (!securityManager.isIdentityInSecurityGroup(auth1, authorGroup)) {
securityManager.addIdentityToSecurityGroup(auth1, authorGroup);
}
if (!securityManager.isIdentityInSecurityGroup(auth2, authorGroup)) {
securityManager.addIdentityToSecurityGroup(auth2, authorGroup);
}
dbInstance.intermediateCommit();
// make auth1 and auth2 owner
RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
List<Identity> authors = new ArrayList<Identity>();
authors.add(auth1);
authors.add(auth2);
IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
repositoryManager.addOwners(admin, identitiesAddedEvent, repositoryEntry, null);
dbInstance.intermediateCommit();
// get them
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
assertNotNull(body);
List<UserVO> authorVOs = parseUserArray(body);
assertNotNull(authorVOs);
}
use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.
the class CourseTest method getParticipants.
@Test
public void getParticipants() throws IOException, URISyntaxException {
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("Course-participant");
RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
repositoryService.addRole(participant, repositoryEntry, GroupRoles.participant.name());
dbInstance.intermediateCommit();
// get them
Assert.assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/participants").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
Assert.assertNotNull(body);
List<UserVO> participantVOs = parseUserArray(body);
Assert.assertNotNull(participantVOs);
boolean found = false;
for (UserVO participantVo : participantVOs) {
if (participantVo.getKey().equals(participant.getKey())) {
found = true;
}
}
Assert.assertTrue(found);
}
use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.
the class CourseWebService method getTutors.
/**
* Get all coaches of the course (don't follow the groups)
* @response.representation.200.qname {http://www.example.com}userVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The array of coaches
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param httpRequest The HTTP request
* @return It returns an array of <code>UserVO</code>
*/
@GET
@Path("tutors")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getTutors(@Context HttpServletRequest httpRequest) {
if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
List<Identity> coachList = repositoryService.getMembers(repositoryEntry, GroupRoles.coach.name());
int count = 0;
UserVO[] coaches = new UserVO[coachList.size()];
for (Identity coach : coachList) {
coaches[count++] = UserVOFactory.get(coach);
}
return Response.ok(coaches).build();
}
use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.
the class CourseWebService method getParticipants.
/**
* Get all participants of the course (don't follow the groups)
* @response.representation.200.qname {http://www.example.com}userVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The array of participants
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param httpRequest The HTTP request
* @return It returns an array of <code>UserVO</code>
*/
@GET
@Path("participants")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getParticipants(@Context HttpServletRequest httpRequest) {
if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
List<Identity> participantList = repositoryService.getMembers(repositoryEntry, GroupRoles.participant.name());
int count = 0;
UserVO[] participants = new UserVO[participantList.size()];
for (Identity participant : participantList) {
participants[count++] = UserVOFactory.get(participant);
}
return Response.ok(participants).build();
}
use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.
the class CourseWebService method getAuthor.
/**
* Get this specific author and owner of the course
* @response.representation.200.qname {http://www.example.com}userVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The author
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found or the user is not an onwer or author of the course
* @param identityKey The user identifier
* @param httpRequest The HTTP request
* @return It returns an <code>UserVO</code>
*/
@GET
@Path("authors/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthor(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
BaseSecurity securityManager = BaseSecurityManager.getInstance();
SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
Identity author = securityManager.loadIdentityByKey(identityKey, false);
if (repositoryService.hasRole(author, repositoryEntry, GroupRoles.owner.name()) && securityManager.isIdentityInSecurityGroup(author, authorGroup)) {
UserVO vo = UserVOFactory.get(author);
return Response.ok(vo).build();
}
return Response.ok(author).build();
}
Aggregations