Search in sources :

Example 16 with CertificateTemplate

use of org.olat.course.certificate.CertificateTemplate in project openolat by klemens.

the class CourseAssessmentManagerImpl method saveScoreEvaluation.

@Override
public void saveScoreEvaluation(AssessableCourseNode courseNode, Identity identity, Identity assessedIdentity, ScoreEvaluation scoreEvaluation, UserCourseEnvironment userCourseEnv, boolean incrementUserAttempts, Role by) {
    final ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
    final CourseEnvironment courseEnv = userCourseEnv.getCourseEnvironment();
    Float score = scoreEvaluation.getScore();
    Boolean passed = scoreEvaluation.getPassed();
    Long assessmentId = scoreEvaluation.getAssessmentID();
    String subIdent = courseNode.getIdent();
    RepositoryEntry referenceEntry = courseNode.getReferencedRepositoryEntry();
    AssessmentEntry assessmentEntry = getOrCreate(assessedIdentity, subIdent, referenceEntry);
    if (referenceEntry != null && !referenceEntry.equals(assessmentEntry.getReferenceEntry())) {
        assessmentEntry.setReferenceEntry(referenceEntry);
    }
    if (by == Role.coach) {
        assessmentEntry.setLastCoachModified(new Date());
    } else if (by == Role.user) {
        assessmentEntry.setLastUserModified(new Date());
    }
    if (score == null) {
        assessmentEntry.setScore(null);
    } else {
        assessmentEntry.setScore(new BigDecimal(Float.toString(score)));
    }
    assessmentEntry.setPassed(passed);
    assessmentEntry.setFullyAssessed(scoreEvaluation.getFullyAssessed());
    if (assessmentId != null) {
        assessmentEntry.setAssessmentId(assessmentId);
    }
    if (scoreEvaluation.getAssessmentStatus() != null) {
        assessmentEntry.setAssessmentStatus(scoreEvaluation.getAssessmentStatus());
    }
    if (scoreEvaluation.getUserVisible() != null) {
        assessmentEntry.setUserVisibility(scoreEvaluation.getUserVisible());
    }
    if (scoreEvaluation.getCurrentRunCompletion() != null) {
        assessmentEntry.setCurrentRunCompletion(scoreEvaluation.getCurrentRunCompletion());
    }
    if (scoreEvaluation.getCurrentRunStatus() != null) {
        assessmentEntry.setCurrentRunStatus(scoreEvaluation.getCurrentRunStatus());
    }
    Integer attempts = null;
    if (incrementUserAttempts) {
        attempts = assessmentEntry.getAttempts() == null ? 1 : assessmentEntry.getAttempts().intValue() + 1;
        assessmentEntry.setAttempts(attempts);
    }
    assessmentEntry = assessmentService.updateAssessmentEntry(assessmentEntry);
    // commit before sending events
    DBFactory.getInstance().commit();
    // reevalute the tree
    ScoreAccounting scoreAccounting = userCourseEnv.getScoreAccounting();
    scoreAccounting.evaluateAll(true);
    // commit before sending events
    DBFactory.getInstance().commit();
    // node log
    UserNodeAuditManager am = courseEnv.getAuditManager();
    am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "score set to: " + String.valueOf(scoreEvaluation.getScore()));
    if (scoreEvaluation.getPassed() != null) {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "passed set to: " + scoreEvaluation.getPassed().toString());
    } else {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "passed set to \"undefined\"");
    }
    if (scoreEvaluation.getAssessmentID() != null) {
        am.appendToUserNodeLog(courseNode, assessedIdentity, assessedIdentity, "assessmentId set to: " + scoreEvaluation.getAssessmentID().toString());
    }
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_SCORE_EVAL_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    // user activity logging
    if (scoreEvaluation.getScore() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_SCORE_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiScore, "", String.valueOf(scoreEvaluation.getScore())));
    }
    if (scoreEvaluation.getPassed() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", String.valueOf(scoreEvaluation.getPassed())));
    } else {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", "undefined"));
    }
    if (incrementUserAttempts && attempts != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_ATTEMPTS_UPDATED, getClass(), LoggingResourceable.wrap(identity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiAttempts, "", String.valueOf(attempts)));
    }
    // write only when enabled for this course
    if (courseEnv.getCourseConfig().isEfficencyStatementEnabled()) {
        List<AssessmentNodeData> data = new ArrayList<AssessmentNodeData>(50);
        AssessmentNodesLastModified lastModifications = new AssessmentNodesLastModified();
        AssessmentHelper.getAssessmentNodeDataList(0, courseEnv.getRunStructure().getRootNode(), scoreAccounting, userCourseEnv, true, true, true, data, lastModifications);
        efficiencyStatementManager.updateUserEfficiencyStatement(assessedIdentity, courseEnv, data, lastModifications, cgm.getCourseEntry());
    }
    if (course.getCourseConfig().isAutomaticCertificationEnabled()) {
        CourseNode rootNode = courseEnv.getRunStructure().getRootNode();
        ScoreEvaluation rootEval = scoreAccounting.evalCourseNode((AssessableCourseNode) rootNode);
        if (rootEval != null && rootEval.getPassed() != null && rootEval.getPassed().booleanValue() && certificatesManager.isCertificationAllowed(assessedIdentity, cgm.getCourseEntry())) {
            CertificateTemplate template = null;
            Long templateId = course.getCourseConfig().getCertificateTemplate();
            if (templateId != null) {
                template = certificatesManager.getTemplateById(templateId);
            }
            CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, rootEval.getScore(), rootEval.getPassed());
            certificatesManager.generateCertificate(certificateInfos, cgm.getCourseEntry(), template, true);
        }
    }
}
Also used : AssessmentNodesLastModified(org.olat.course.assessment.model.AssessmentNodesLastModified) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Date(java.util.Date) BigDecimal(java.math.BigDecimal) AssessmentNodeData(org.olat.course.assessment.model.AssessmentNodeData) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode)

Example 17 with CertificateTemplate

use of org.olat.course.certificate.CertificateTemplate in project openolat by klemens.

the class IdentityCertificatesController method doGenerateCertificate.

private void doGenerateCertificate(UserRequest ureq) {
    ICourse course = CourseFactory.loadCourse(courseEntry);
    CourseNode rootNode = course.getRunStructure().getRootNode();
    Roles roles = securityManager.getRoles(assessedIdentity);
    IdentityEnvironment identityEnv = new IdentityEnvironment(assessedIdentity, roles);
    UserCourseEnvironment assessedUserCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
    ScoreAccounting scoreAccounting = assessedUserCourseEnv.getScoreAccounting();
    scoreAccounting.evaluateAll();
    ScoreEvaluation scoreEval = scoreAccounting.evalCourseNode((AssessableCourseNode) rootNode);
    CertificateTemplate template = null;
    Long templateKey = course.getCourseConfig().getCertificateTemplate();
    if (templateKey != null) {
        template = certificatesManager.getTemplateById(templateKey);
    }
    Float score = scoreEval == null ? null : scoreEval.getScore();
    Boolean passed = scoreEval == null ? null : scoreEval.getPassed();
    CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
    certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
    loadList();
    showInfo("msg.certificate.pending");
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 18 with CertificateTemplate

use of org.olat.course.certificate.CertificateTemplate in project openolat by klemens.

the class CertificationWebService method putCertificate.

/**
 * Generate a new certificate.
 *
 * @response.representation.200.doc If the certificate was created
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The identity or the resource cannot be found
 * @response.representation.500.doc An unexpected error happened during the creation of the certificate
 * @param identityKey The owner of the certificate
 * @param resourceKey The primary key of the resource of the repository entry of the course.
 * @param score The score which appears in the certificate
 * @param passed The passed/failed which appears in the certificate (true/false)
 * @param creationDate The date of the certification
 * @param request The request
 * @return Nothing special
 */
@PUT
@Path("{identityKey}")
public Response putCertificate(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @QueryParam("score") Float score, @QueryParam("passed") Boolean passed, @QueryParam("creationDate") String creationDate, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity assessedIdentity = baseSecurity.loadIdentityByKey(identityKey);
    if (assessedIdentity == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
    OLATResource resource = resourceManager.findResourceById(resourceKey);
    if (resource == null) {
        resource = resourceManager.findResourceable(resourceKey, "CourseModule");
    }
    if (resource == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    } else {
        CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
        ICourse course = CourseFactory.loadCourse(resource);
        RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        CertificateTemplate template = null;
        Long templateId = course.getCourseConfig().getCertificateTemplate();
        if (templateId != null) {
            template = certificatesManager.getTemplateById(templateId);
        }
        CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
        if (StringHelper.containsNonWhitespace(creationDate)) {
            Date date = ObjectFactory.parseDate(creationDate);
            certificateInfos.setCreationDate(date);
        }
        Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, template, false);
        if (certificate != null) {
            return Response.ok().build();
        }
        return Response.serverError().status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) CertificatesManager(org.olat.course.certificate.CertificatesManager) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Date(java.util.Date) BaseSecurity(org.olat.basesecurity.BaseSecurity) Certificate(org.olat.course.certificate.Certificate) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Aggregations

CertificateTemplate (org.olat.course.certificate.CertificateTemplate)18 ICourse (org.olat.course.ICourse)10 CertificateInfos (org.olat.course.certificate.model.CertificateInfos)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 File (java.io.File)6 Date (java.util.Date)6 Identity (org.olat.core.id.Identity)6 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)6 CourseNode (org.olat.course.nodes.CourseNode)6 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)6 AssessmentChangedEvent (org.olat.course.assessment.AssessmentChangedEvent)4 UserNodeAuditManager (org.olat.course.auditing.UserNodeAuditManager)4 CertificatesManager (org.olat.course.certificate.CertificatesManager)4 ScoreAccounting (org.olat.course.run.scoring.ScoreAccounting)4 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)4 OLATResource (org.olat.resource.OLATResource)4 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2