use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class CourseWebService method removeCoach.
/**
* Remove a coach from the course
* @response.representation.200.doc The user was successfully removed as coach of the course
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or the user not found
* @param identityKey The user identifier
* @param httpRequest The HTTP request
* @return It returns 200 if the user is removed as coach of the course
*/
@DELETE
@Path("tutors/{identityKey}")
public Response removeCoach(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity coach = securityManager.loadIdentityByKey(identityKey, false);
if (coach == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Identity identity = getIdentity(httpRequest);
// remove the user as coach of the course
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
List<Identity> coaches = Collections.singletonList(coach);
rm.removeTutors(identity, coaches, repositoryEntry, new MailPackage(false));
return Response.ok().build();
}
use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class CourseWebService method removeParticipant.
/**
* Remove a participant from the course
* @response.representation.200.doc The user was successfully removed as participant of the course
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or the user not found
* @param identityKey The user identifier
* @param httpRequest The HTTP request
* @return It returns 200 if the user is removed as participant of the course
*/
@DELETE
@Path("participants/{identityKey}")
public Response removeParticipant(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity participant = securityManager.loadIdentityByKey(identityKey, false);
if (participant == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Identity identity = getIdentity(httpRequest);
// remove the user as participant of the course
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
List<Identity> participants = Collections.singletonList(participant);
rm.removeParticipants(identity, participants, repositoryEntry, new MailPackage(false), false);
return Response.ok().build();
}
use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class CoursesWebService method getCourseList.
/**
* Get all courses viewable by the authenticated user
* @response.representation.200.qname {http://www.example.com}courseVO
* @response.representation.200.mediaType application/xml, application/json, application/json;pagingspec=1.0
* @response.representation.200.doc List of visible courses
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVOes}
* @param start
* @param limit
* @param externalId Search with an external ID
* @param externalRef Search with an external reference
* @param managed (true / false) Search only managed / not managed groups
* @param httpRequest The HTTP request
* @param request The REST request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @QueryParam("managed") Boolean managed, @QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef, @QueryParam("repositoryEntryKey") String repositoryEntryKey, @Context HttpServletRequest httpRequest, @Context Request request) {
RepositoryManager rm = RepositoryManager.getInstance();
Roles roles = getRoles(httpRequest);
Identity identity = getIdentity(httpRequest);
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, CourseModule.getCourseTypeName());
params.setManaged(managed);
if (StringHelper.containsNonWhitespace(externalId)) {
params.setExternalId(externalId);
}
if (StringHelper.containsNonWhitespace(externalRef)) {
params.setExternalRef(externalRef);
}
if (StringHelper.containsNonWhitespace(repositoryEntryKey) && StringHelper.isLong(repositoryEntryKey)) {
try {
params.setRepositoryEntryKeys(Collections.singletonList(new Long(repositoryEntryKey)));
} catch (NumberFormatException e) {
log.error("Cannot parse the following repository entry key: " + repositoryEntryKey);
}
}
if (MediaTypeVariants.isPaged(httpRequest, request)) {
int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
CourseVO[] vos = toCourseVo(repoEntries);
CourseVOes voes = new CourseVOes();
voes.setCourses(vos);
voes.setTotalCount(totalCount);
return Response.ok(voes).build();
} else {
List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, 0, -1, false);
CourseVO[] vos = toCourseVo(repoEntries);
return Response.ok(vos).build();
}
}
use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class CourseElementWebService method attachSurvey.
/**
* Attaches an survey building block.
* @response.representation.mediaType application/x-www-form-urlencoded
* @response.representation.doc The assessment node metadatas
* @response.representation.200.qname {http://www.example.com}courseNodeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node metadatas
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSENODEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param parentNodeId The node's id which will be the parent of this assessment
* @param position The node's position relative to its sibling nodes (optional)
* @param shortTitle The node short title
* @param longTitle The node long title
* @param objectives The node learning objectives
* @param visibilityExpertRules The rules to view the node (optional)
* @param accessExpertRules The rules to access the node (optional)
* @param request The HTTP request
* @return
*/
@PUT
@Path("survey")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response attachSurvey(@PathParam("courseId") Long courseId, @QueryParam("parentNodeId") String parentNodeId, @QueryParam("position") Integer position, @QueryParam("shortTitle") @DefaultValue("undefined") String shortTitle, @QueryParam("longTitle") @DefaultValue("undefined") String longTitle, @QueryParam("objectives") @DefaultValue("undefined") String objectives, @QueryParam("visibilityExpertRules") String visibilityExpertRules, @QueryParam("accessExpertRules") String accessExpertRules, @QueryParam("surveyResourceableId") Long surveyResourceableId, @Context HttpServletRequest request) {
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry surveyRepoEntry = rm.lookupRepositoryEntry(surveyResourceableId);
if (surveyRepoEntry == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
CustomConfigDelegate config = CustomConfigFactory.getSurveyCustomConfig(surveyRepoEntry);
return attach(courseId, parentNodeId, "iqsurv", position, shortTitle, longTitle, objectives, visibilityExpertRules, accessExpertRules, config, request);
}
use of org.olat.repository.RepositoryManager in project OpenOLAT by OpenOLAT.
the class CourseElementWebService method updateTest.
/**
* This updates a Test Element onto a given course.
* @response.representation.mediaType application/x-www-form-urlencoded
* @response.representation.doc The course node metadatas
* @response.representation.200.qname {http://www.example.com}courseNodeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The test node metadatas
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSENODEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course, parentNode or test not found
* @param courseId The course resourceable id
* @param nodeId The node's id of this test
* @param testResourceableId The test node's id which is retorned in the
* response of the import test resource
* @param position The node's position relative to its sibling nodes (optional)
* @param shortTitle The node short title
* @param longTitle The node long title
* @param objectives The node learning objectives
* @param visibilityExpertRules The rules to view the node (optional)
* @param accessExpertRules The rules to access the node (optional)
* @param testResourceableId The repository entry key of the test
* @param request The HTTP request
* @return The persisted test element (fully populated)
*/
@POST
@Path("test/{nodeId}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public // fxdiff FXOLAT-122: course management
Response updateTest(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @FormParam("shortTitle") @DefaultValue("undefined") String shortTitle, @FormParam("longTitle") @DefaultValue("undefined") String longTitle, @FormParam("objectives") @DefaultValue("undefined") String objectives, @FormParam("visibilityExpertRules") String visibilityExpertRules, @FormParam("accessExpertRules") String accessExpertRules, @FormParam("testResourceableId") Long testResourceableId, @Context HttpServletRequest request) {
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry testRepoEntry = rm.lookupRepositoryEntry(testResourceableId);
if (testRepoEntry == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
CustomConfigDelegate config = CustomConfigFactory.getTestCustomConfig(testRepoEntry);
return update(courseId, nodeId, shortTitle, longTitle, objectives, visibilityExpertRules, accessExpertRules, config, request);
}
Aggregations