Search in sources :

Example 1 with AssessableResultsVO

use of org.olat.restapi.support.vo.AssessableResultsVO in project OpenOLAT by OpenOLAT.

the class CourseAssessmentWebService method getRootResult.

private AssessableResultsVO getRootResult(Identity identity, ICourse course, CourseNode courseNode) {
    AssessableResultsVO results = new AssessableResultsVO();
    results.setIdentityKey(identity.getKey());
    // create an identenv with no roles, no attributes, no locale
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(identity);
    UserCourseEnvironment userCourseEnvironment = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
    // Fetch all score and passed and calculate score accounting for the entire course
    ScoreAccounting scoreAccounting = userCourseEnvironment.getScoreAccounting();
    scoreAccounting.evaluateAll();
    if (courseNode instanceof AssessableCourseNode) {
        AssessableCourseNode assessableRootNode = (AssessableCourseNode) courseNode;
        ScoreEvaluation scoreEval = scoreAccounting.evalCourseNode(assessableRootNode);
        results.setScore(scoreEval.getScore());
        results.setPassed(scoreEval.getPassed());
        results.setLastModifiedDate(getLastModificationDate(identity, course, courseNode));
    }
    return results;
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessableResultsVO(org.olat.restapi.support.vo.AssessableResultsVO) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 2 with AssessableResultsVO

use of org.olat.restapi.support.vo.AssessableResultsVO in project OpenOLAT by OpenOLAT.

the class CourseAssessmentWebService method getCourseNodeResultsForNode.

/**
 * Returns the results of a student at a specific assessable node
 * @response.representation.200.qname {http://www.example.com}assessableResultsVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The result of a user at a specific node
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_ASSESSABLERESULTSVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The identity or the course not found
 * @param courseId The course resourceable's id
 * @param nodeId The ident of the course building block
 * @param identityKey The id of the user
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return
 */
@GET
@Path("{nodeId}/users/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseNodeResultsForNode(@PathParam("courseId") Long courseId, @PathParam("nodeId") Long nodeId, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest, @Context Request request) {
    if (!RestSecurityHelper.isAuthor(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    try {
        Identity userIdentity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
        if (userIdentity == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        ICourse course = CoursesWebService.loadCourse(courseId);
        if (course == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        AssessableResultsVO results = getNodeResult(userIdentity, course, nodeId);
        if (results.getLastModifiedDate() != null) {
            Response.ResponseBuilder response = request.evaluatePreconditions(results.getLastModifiedDate());
            if (response != null) {
                return response.build();
            }
            return Response.ok(results).lastModified(results.getLastModifiedDate()).cacheControl(cc).build();
        }
        return Response.ok(results).build();
    } catch (Throwable e) {
        throw new WebApplicationException(e);
    }
}
Also used : Response(javax.ws.rs.core.Response) AssessableResultsVO(org.olat.restapi.support.vo.AssessableResultsVO) WebApplicationException(javax.ws.rs.WebApplicationException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ICourse(org.olat.course.ICourse) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with AssessableResultsVO

use of org.olat.restapi.support.vo.AssessableResultsVO in project openolat by klemens.

the class CourseAssessmentWebService method getRootResult.

private AssessableResultsVO getRootResult(Identity identity, ICourse course, CourseNode courseNode) {
    AssessableResultsVO results = new AssessableResultsVO();
    results.setIdentityKey(identity.getKey());
    // create an identenv with no roles, no attributes, no locale
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(identity);
    UserCourseEnvironment userCourseEnvironment = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
    // Fetch all score and passed and calculate score accounting for the entire course
    ScoreAccounting scoreAccounting = userCourseEnvironment.getScoreAccounting();
    scoreAccounting.evaluateAll();
    if (courseNode instanceof AssessableCourseNode) {
        AssessableCourseNode assessableRootNode = (AssessableCourseNode) courseNode;
        ScoreEvaluation scoreEval = scoreAccounting.evalCourseNode(assessableRootNode);
        results.setScore(scoreEval.getScore());
        results.setPassed(scoreEval.getPassed());
        results.setLastModifiedDate(getLastModificationDate(identity, course, courseNode));
    }
    return results;
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessableResultsVO(org.olat.restapi.support.vo.AssessableResultsVO) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 4 with AssessableResultsVO

use of org.olat.restapi.support.vo.AssessableResultsVO in project openolat by klemens.

the class CourseAssessmentWebService method getCourseResultsOf.

/**
 * Returns the results of the course.
 * @response.representation.200.qname {http://www.example.com}assessableResultsVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The result of the course
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_ASSESSABLERESULTSVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The identity or the course not found
 * @param courseId The course resourceable's id
 * @param identityKey The id of the user
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return
 */
@GET
@Path("users/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseResultsOf(@PathParam("courseId") Long courseId, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest, @Context Request request) {
    if (!RestSecurityHelper.isAuthor(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    try {
        Identity userIdentity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
        if (userIdentity == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        ICourse course = CoursesWebService.loadCourse(courseId);
        if (course == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        AssessableResultsVO results = getRootResult(userIdentity, course);
        if (results.getLastModifiedDate() != null) {
            Response.ResponseBuilder response = request.evaluatePreconditions(results.getLastModifiedDate());
            if (response != null) {
                return response.build();
            }
        }
        ResponseBuilder response = Response.ok(results);
        if (results.getLastModifiedDate() != null) {
            response = response.lastModified(results.getLastModifiedDate()).cacheControl(cc);
        }
        return response.build();
    } catch (Throwable e) {
        throw new WebApplicationException(e);
    }
}
Also used : Response(javax.ws.rs.core.Response) AssessableResultsVO(org.olat.restapi.support.vo.AssessableResultsVO) WebApplicationException(javax.ws.rs.WebApplicationException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ICourse(org.olat.course.ICourse) Identity(org.olat.core.id.Identity) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with AssessableResultsVO

use of org.olat.restapi.support.vo.AssessableResultsVO in project openolat by klemens.

the class CourseAssessmentWebService method getAssessableResults.

/**
 * Exports results for an assessable course node for all students.
 * @response.representation.200.qname {http://www.example.com}assessableResultsVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc Export all results of all user of the course
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_ASSESSABLERESULTSVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param courseId The course resourceable's id
 * @param nodeId The id of the course building block
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return
 */
@GET
@Path("{nodeId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAssessableResults(@PathParam("courseId") Long courseId, @PathParam("nodeId") Long nodeId, @Context HttpServletRequest httpRequest, @Context Request request) {
    if (!RestSecurityHelper.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();
    } else if (!isAuthorEditor(course, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    // fxdiff VCRP-1,2: access control of resources
    List<Identity> courseUsers = loadUsers(course);
    int i = 0;
    Date lastModified = null;
    AssessableResultsVO[] results = new AssessableResultsVO[courseUsers.size()];
    for (Identity courseUser : courseUsers) {
        AssessableResultsVO result = getNodeResult(courseUser, course, nodeId);
        if (lastModified == null || (result.getLastModifiedDate() != null && lastModified.before(result.getLastModifiedDate()))) {
            lastModified = result.getLastModifiedDate();
        }
        results[i++] = result;
    }
    if (lastModified != null) {
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response != null) {
            return response.build();
        }
        return Response.ok(results).lastModified(lastModified).cacheControl(cc).build();
    }
    return Response.ok(results).build();
}
Also used : Response(javax.ws.rs.core.Response) AssessableResultsVO(org.olat.restapi.support.vo.AssessableResultsVO) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ICourse(org.olat.course.ICourse) Identity(org.olat.core.id.Identity) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

AssessableResultsVO (org.olat.restapi.support.vo.AssessableResultsVO)10 GET (javax.ws.rs.GET)8 Produces (javax.ws.rs.Produces)8 Response (javax.ws.rs.core.Response)8 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)8 Identity (org.olat.core.id.Identity)8 ICourse (org.olat.course.ICourse)8 Path (javax.ws.rs.Path)6 Date (java.util.Date)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)2 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)2 ScoreAccounting (org.olat.course.run.scoring.ScoreAccounting)2 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)2 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)2 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)2