Search in sources :

Example 16 with TACourseNode

use of org.olat.course.nodes.TACourseNode in project openolat by klemens.

the class CourseElementWebService method attachTaskFile.

/**
 * This attaches a Task file onto a given task element.
 * @response.representation.mediaType application/x-www-form-urlencoded
 * @response.representation.doc The task 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
 * @response.representation.406.doc The course node is not of type task
 * @param courseId The course resourceable id
 * @param nodeId The node's id which will be the parent of this task file
 * @param request The HTTP request
 * @return The persisted task element (fully populated)
 */
@PUT
@Path("task/{nodeId}/file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response attachTaskFile(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest request) {
    ICourse course = CoursesWebService.loadCourse(courseId);
    CourseNode node = getParentNode(course, nodeId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (node == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!(node instanceof TACourseNode)) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    }
    if (!isAuthorEditor(course, request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    InputStream in = null;
    MultipartReader reader = null;
    try {
        reader = new MultipartReader(request);
        String filename = reader.getValue("filename", "task");
        String taskFolderPath = TACourseNode.getTaskFolderPathRelToFolderRoot(course, node);
        OlatRootFolderImpl taskFolder = new OlatRootFolderImpl(taskFolderPath, null);
        VFSLeaf singleFile = (VFSLeaf) taskFolder.resolve("/" + filename);
        if (singleFile == null) {
            singleFile = taskFolder.createChildLeaf("/" + filename);
        }
        File file = reader.getFile();
        if (file != null) {
            in = new FileInputStream(file);
            OutputStream out = singleFile.getOutputStream(false);
            IOUtils.copy(in, out);
            IOUtils.closeQuietly(out);
        } else {
            return Response.status(Status.NOT_ACCEPTABLE).build();
        }
    } catch (Exception e) {
        log.error("", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    } finally {
        MultipartReader.closeQuietly(reader);
        IOUtils.closeQuietly(in);
    }
    return Response.ok().build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) MSCourseNode(org.olat.course.nodes.MSCourseNode) AbstractFeedCourseNode(org.olat.course.nodes.AbstractFeedCourseNode) IQSURVCourseNode(org.olat.course.nodes.IQSURVCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) File(java.io.File) MultipartReader(org.olat.restapi.support.MultipartReader) FileInputStream(java.io.FileInputStream) MalformedURLException(java.net.MalformedURLException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 17 with TACourseNode

use of org.olat.course.nodes.TACourseNode in project openolat by klemens.

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();
}
Also used : TaskConfigVO(org.olat.restapi.support.vo.elements.TaskConfigVO) ModuleConfiguration(org.olat.modules.ModuleConfiguration) ConditionExpression(org.olat.course.condition.interpreter.ConditionExpression) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) MSCourseNode(org.olat.course.nodes.MSCourseNode) AbstractFeedCourseNode(org.olat.course.nodes.AbstractFeedCourseNode) IQSURVCourseNode(org.olat.course.nodes.IQSURVCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with TACourseNode

use of org.olat.course.nodes.TACourseNode in project openolat by klemens.

the class GenericArchiveController method doSelectNode.

private void doSelectNode(UserRequest ureq, AssessmentNodeData nodeData) {
    ICourse course = CourseFactory.loadCourse(ores);
    CourseNode node = course.getRunStructure().getNode(nodeData.getIdent());
    // some node can limit the archive to a business group
    if (node instanceof TACourseNode) {
        CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
        List<BusinessGroup> relatedGroups = cgm.getAllBusinessGroups();
        if (relatedGroups.isEmpty()) {
            archiveNode(ureq, node, null);
        } else {
            doSelectBusinessGroup(ureq, node, relatedGroups);
        }
    } else {
        archiveNode(ureq, node, null);
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) TACourseNode(org.olat.course.nodes.TACourseNode)

Aggregations

TACourseNode (org.olat.course.nodes.TACourseNode)18 CourseNode (org.olat.course.nodes.CourseNode)14 ICourse (org.olat.course.ICourse)12 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)12 MSCourseNode (org.olat.course.nodes.MSCourseNode)10 STCourseNode (org.olat.course.nodes.STCourseNode)10 GTACourseNode (org.olat.course.nodes.GTACourseNode)8 IQSURVCourseNode (org.olat.course.nodes.IQSURVCourseNode)8 File (java.io.File)6 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)6 ScormCourseNode (org.olat.course.nodes.ScormCourseNode)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 FOCourseNode (org.olat.course.nodes.FOCourseNode)4 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 AbstractFeedCourseNode (org.olat.course.nodes.AbstractFeedCourseNode)3 BasicLTICourseNode (org.olat.course.nodes.BasicLTICourseNode)3 PortfolioCourseNode (org.olat.course.nodes.PortfolioCourseNode)3