use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CourseElementWebService method getTaskConfiguration.
/**
* Retrieves configuration of the task course node
* @response.representation.200.qname {http://www.example.com}surveyConfigVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node configuration
* @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 task node not found
* @param courseId
* @param nodeId
* @return the task course node configuration
*/
@GET
@Path("task/{nodeId}/configuration")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getTaskConfiguration(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest httpRequest) {
if (!isAuthor(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
TaskConfigVO config = new TaskConfigVO();
ICourse course = CoursesWebService.loadCourse(courseId);
CourseNode courseNode = getParentNode(course, nodeId);
ModuleConfiguration moduleConfig = courseNode.getModuleConfiguration();
// build configuration with fallback to default values
Boolean isAssignmentEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_TASK_ENABLED);
config.setIsAssignmentEnabled(isAssignmentEnabled == null ? Boolean.TRUE : isAssignmentEnabled);
String taskAssignmentType = moduleConfig.getStringValue(TACourseNode.CONF_TASK_TYPE);
config.setTaskAssignmentType(taskAssignmentType == null ? TaskController.TYPE_MANUAL : taskAssignmentType);
String taskAssignmentText = moduleConfig.getStringValue(TACourseNode.CONF_TASK_TEXT);
config.setTaskAssignmentText(taskAssignmentText == null ? "" : taskAssignmentText);
Boolean isTaskPreviewEnabled = moduleConfig.get(TACourseNode.CONF_TASK_PREVIEW) == null ? Boolean.FALSE : moduleConfig.getBooleanEntry(TACourseNode.CONF_TASK_PREVIEW);
config.setIsTaskPreviewEnabled(isTaskPreviewEnabled);
Boolean isTaskDeselectEnabled = moduleConfig.getBooleanEntry(TACourseNode.CONF_TASK_DESELECT);
config.setIsTaskDeselectEnabled(isTaskDeselectEnabled == null ? Boolean.FALSE : isTaskDeselectEnabled);
Boolean onlyOneUserPerTask = (Boolean) moduleConfig.get(TACourseNode.CONF_TASK_SAMPLING_WITH_REPLACEMENT);
config.setOnlyOneUserPerTask(onlyOneUserPerTask == null ? Boolean.TRUE : onlyOneUserPerTask);
Boolean isDropboxEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_DROPBOX_ENABLED);
config.setIsDropboxEnabled(isDropboxEnabled == null ? Boolean.TRUE : isDropboxEnabled);
Boolean isDropboxConfirmationMailEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_DROPBOX_ENABLEMAIL);
config.setIsDropboxConfirmationMailEnabled(isDropboxConfirmationMailEnabled == null ? Boolean.FALSE : isDropboxConfirmationMailEnabled);
String dropboxConfirmationText = moduleConfig.getStringValue(TACourseNode.CONF_DROPBOX_CONFIRMATION);
config.setDropboxConfirmationText(dropboxConfirmationText == null ? "" : dropboxConfirmationText);
Boolean isReturnboxEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_RETURNBOX_ENABLED);
config.setIsReturnboxEnabled(isReturnboxEnabled == null ? Boolean.TRUE : isReturnboxEnabled);
Boolean isScoringEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_SCORING_ENABLED);
config.setIsScoringEnabled(isScoringEnabled == null ? Boolean.TRUE : isScoringEnabled);
Boolean isScoringGranted = (Boolean) moduleConfig.get(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD);
config.setIsScoringGranted(isScoringGranted == null ? Boolean.FALSE : isScoringGranted);
Float minScore = (Float) moduleConfig.get(MSCourseNode.CONFIG_KEY_SCORE_MIN);
config.setMinScore(minScore);
Float maxScore = (Float) moduleConfig.get(MSCourseNode.CONFIG_KEY_SCORE_MAX);
config.setMaxScore(maxScore);
Boolean isPassingGranted = (Boolean) moduleConfig.get(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD);
config.setIsPassingGranted(isPassingGranted == null ? Boolean.FALSE : isPassingGranted);
Float passingScoreThreshold = (Float) moduleConfig.get(MSCourseNode.CONFIG_KEY_PASSED_CUT_VALUE);
config.setPassingScoreThreshold(passingScoreThreshold);
Boolean hasCommentField = (Boolean) moduleConfig.get(MSCourseNode.CONFIG_KEY_HAS_COMMENT_FIELD);
config.setHasCommentField(hasCommentField == null ? Boolean.FALSE : hasCommentField);
String commentForUser = moduleConfig.getStringValue(MSCourseNode.CONFIG_KEY_INFOTEXT_USER);
config.setCommentForUser(commentForUser == null ? "" : commentForUser);
String commentForCoaches = moduleConfig.getStringValue(MSCourseNode.CONFIG_KEY_INFOTEXT_COACH);
config.setCommentForCoaches(commentForCoaches == null ? "" : commentForCoaches);
Boolean isSolutionEnabled = (Boolean) moduleConfig.get(TACourseNode.CONF_SOLUTION_ENABLED);
config.setIsSolutionEnabled(isSolutionEnabled == null ? Boolean.TRUE : isSolutionEnabled);
// get the conditions
List<ConditionExpression> lstConditions = courseNode.getConditionExpressions();
for (ConditionExpression cond : lstConditions) {
String id = cond.getId();
String expression = cond.getExptressionString();
if (id.equals(TACourseNode.ACCESS_TASK))
config.setConditionTask(expression);
else if (// TACourseNode uses "drop" instead the static ACCESS_DROPBOX, very bad!
id.equals("drop"))
config.setConditionDropbox(expression);
else if (id.equals(TACourseNode.ACCESS_RETURNBOX))
config.setConditionReturnbox(expression);
else if (id.equals(TACourseNode.ACCESS_SCORING))
config.setConditionScoring(expression);
else if (id.equals(TACourseNode.ACCESS_SOLUTION))
config.setConditionSolution(expression);
}
return Response.ok(config).build();
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CourseResourceFolderWebService method getFiles.
public Response getFiles(Long courseId, List<PathSegment> path, FolderType type, UriInfo uriInfo, HttpServletRequest httpRequest, Request request) {
if (!isAuthor(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
VFSContainer container = null;
RepositoryEntry re = null;
switch(type) {
case COURSE_FOLDER:
container = course.getCourseFolderContainer();
break;
case SHARED_FOLDER:
{
container = null;
String sfSoftkey = course.getCourseConfig().getSharedFolderSoftkey();
OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class).loadRepositoryEntryResourceBySoftKey(sfSoftkey);
if (sharedResource != null) {
re = CoreSpringFactory.getImpl(RepositoryService.class).loadByResourceKey(sharedResource.getKey());
container = SharedFolderManager.getInstance().getNamedSharedFolder(re, true);
CourseConfig courseConfig = course.getCourseConfig();
if (courseConfig.isSharedFolderReadOnlyMount()) {
container.setLocalSecurityCallback(new ReadOnlyCallback());
}
}
break;
}
}
if (container == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
VFSLeaf leaf = null;
for (PathSegment seg : path) {
VFSItem item = container.resolve(seg.getPath());
if (item instanceof VFSLeaf) {
leaf = (VFSLeaf) item;
break;
} else if (item instanceof VFSContainer) {
container = (VFSContainer) item;
}
}
if (leaf != null) {
Date lastModified = new Date(leaf.getLastModified());
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
String mimeType = WebappHelper.getMimeType(leaf.getName());
if (mimeType == null)
mimeType = MediaType.APPLICATION_OCTET_STREAM;
response = Response.ok(leaf.getInputStream(), mimeType).lastModified(lastModified).cacheControl(cc);
}
return response.build();
}
List<VFSItem> items = container.getItems(new SystemItemFilter());
int count = 0;
LinkVO[] links = new LinkVO[items.size()];
for (VFSItem item : items) {
UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
UriBuilder repoUri = baseUriBuilder.path(CourseResourceFolderWebService.class).path("files");
if (type.equals(FolderType.SHARED_FOLDER) && re != null) {
repoUri = baseUriBuilder.replacePath("restapi").path(SharedFolderWebService.class).path(re.getKey().toString()).path("files");
}
for (PathSegment pathSegment : path) {
repoUri.path(pathSegment.getPath());
}
String uri = repoUri.path(item.getName()).build(courseId).toString();
links[count++] = new LinkVO("self", uri, item.getName());
}
return Response.ok(links).build();
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CoursesInfosWebService method getCourseInfo.
/**
* Get course informations viewable by the authenticated user
* @response.representation.200.qname {http://www.example.com}courseVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc Course informations
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEINFOVO}
* @param courseId The course id
* @param httpRequest The HTTP request
* @return
*/
@GET
@Path("{courseId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseInfo(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
Identity identity = getIdentity(httpRequest);
if (identity != null && roles != null) {
Set<Long> forumNotified = new HashSet<Long>();
Map<Long, Set<String>> courseNotified = new HashMap<Long, Set<String>>();
collectSubscriptions(identity, forumNotified, courseNotified);
ICourse course = CourseFactory.loadCourse(courseId);
RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
CourseInfoVO info = collect(identity, roles, entry, forumNotified, courseNotified);
return Response.ok(info).build();
} else {
return Response.serverError().status(Status.FORBIDDEN).build();
}
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class AbstractCourseNodeWebService method updateCourseNode.
// fxdiff FXOLAT-122: course management
private CourseNodeVO updateCourseNode(String nodeId, String shortTitle, String longTitle, String learningObjectives, String visibilityExpertRules, String accessExpertRules, CustomConfigDelegate delegateConfig, CourseEditSession editSession) {
ICourse course = editSession.getCourse();
TreeNode updateEditorNode = course.getEditorTreeModel().getNodeById(nodeId);
CourseNode updatedNode = course.getEditorTreeModel().getCourseNode(nodeId);
if (StringHelper.containsNonWhitespace(shortTitle)) {
updatedNode.setShortTitle(shortTitle);
}
if (StringHelper.containsNonWhitespace(longTitle)) {
updatedNode.setLongTitle(longTitle);
}
if (StringHelper.containsNonWhitespace(learningObjectives)) {
updatedNode.setLearningObjectives(learningObjectives);
}
if (visibilityExpertRules != null) {
Condition cond = createExpertCondition(CONDITION_ID_VISIBILITY, visibilityExpertRules);
updatedNode.setPreConditionVisibility(cond);
}
if (StringHelper.containsNonWhitespace(accessExpertRules) && updatedNode instanceof AbstractAccessableCourseNode) {
Condition cond = createExpertCondition(CONDITION_ID_ACCESS, accessExpertRules);
((AbstractAccessableCourseNode) updatedNode).setPreConditionAccess(cond);
}
if (delegateConfig != null) {
ModuleConfiguration moduleConfig = updatedNode.getModuleConfiguration();
delegateConfig.configure(course, updatedNode, moduleConfig);
}
course.getEditorTreeModel().nodeConfigChanged(updateEditorNode);
CourseEditorTreeNode editorNode = course.getEditorTreeModel().getCourseEditorNodeContaining(updatedNode);
CourseNodeVO vo = get(updatedNode);
vo.setParentId(editorNode.getParent() == null ? null : editorNode.getParent().getIdent());
return vo;
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class AbstractCourseNodeWebService method attach.
protected Response attach(Long courseId, String parentNodeId, String nodeId, String type, Integer position, String shortTitle, String longTitle, String objectives, String visibilityExpertRules, String accessExpertRules, CustomConfigDelegate config, HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
if (config != null && !config.isValid()) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
}
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(course, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseEditSession editSession = null;
try {
editSession = openEditSession(course, getIdentity(request));
if (!editSession.canEdit()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseNodeVO node;
if (nodeId != null) {
node = updateCourseNode(nodeId, shortTitle, longTitle, objectives, visibilityExpertRules, accessExpertRules, config, editSession);
} else {
CourseNode parentNode = getParentNode(course, parentNodeId);
if (parentNode == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
node = createCourseNode(type, shortTitle, longTitle, objectives, visibilityExpertRules, accessExpertRules, config, editSession, parentNode, position);
}
return Response.ok(node).build();
} catch (Exception ex) {
log.error("Error while adding an enrolment building block", ex);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
saveAndCloseCourse(editSession);
}
}
Aggregations