Search in sources :

Example 6 with CertificateTemplate

use of org.olat.course.certificate.CertificateTemplate in project OpenOLAT by OpenOLAT.

the class NewCachePersistingAssessmentManager method saveScoreEvaluation.

/**
 * @see org.olat.course.assessment.AssessmentManager#saveScoreEvaluation(org.olat.course.nodes.CourseNode, org.olat.core.id.Identity, org.olat.core.id.Identity, org.olat.course.run.scoring.ScoreEvaluation)
 */
public void saveScoreEvaluation(final CourseNode courseNode, final Identity identity, final Identity assessedIdentity, final ScoreEvaluation scoreEvaluation, final UserCourseEnvironment userCourseEnv, final boolean incrementUserAttempts) {
    final ICourse course = CourseFactory.loadCourse(ores);
    final CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    final RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    // o_clusterREVIEW we could sync on a element finer than course, e.g. the composite course+assessIdentity.
    // +: concurrency would be higher
    // -: many entries (num of courses * visitors of given course) in the locktable.
    // we could also sync on the assessedIdentity.
    Long attempts = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(createOLATResourceableForLocking(assessedIdentity), new SyncerCallback<Long>() {

        public Long execute() {
            Long attempts = null;
            Float score = scoreEvaluation.getScore();
            Boolean passed = scoreEvaluation.getPassed();
            saveNodeScore(courseNode, assessedIdentity, score, cpm);
            saveNodePassed(courseNode, assessedIdentity, passed, cpm);
            saveAssessmentID(courseNode, assessedIdentity, scoreEvaluation.getAssessmentID(), cpm);
            if (incrementUserAttempts) {
                attempts = incrementNodeAttemptsProperty(courseNode, assessedIdentity, cpm);
            }
            if (courseNode instanceof AssessableCourseNode) {
                userCourseEnv.getScoreAccounting().evaluateAll();
                // Update users efficiency statement
                EfficiencyStatementManager esm = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
                esm.updateUserEfficiencyStatement(userCourseEnv);
            }
            if (passed != null && passed.booleanValue() && course.getCourseConfig().isAutomaticCertificationEnabled()) {
                CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
                if (certificatesManager.isCertificationAllowed(assessedIdentity, courseEntry)) {
                    CertificateTemplate template = null;
                    Long templateId = course.getCourseConfig().getCertificateTemplate();
                    if (templateId != null) {
                        template = certificatesManager.getTemplateById(templateId);
                    }
                    CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
                    certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
                }
            }
            return attempts;
        }
    });
    // node log
    UserNodeAuditManager am = course.getCourseEnvironment().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, ASSESSMENT_ID + " 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)));
    }
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) CertificatesManager(org.olat.course.certificate.CertificatesManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 7 with CertificateTemplate

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

the class NewCachePersistingAssessmentManager method saveScoreEvaluation.

/**
 * @see org.olat.course.assessment.AssessmentManager#saveScoreEvaluation(org.olat.course.nodes.CourseNode, org.olat.core.id.Identity, org.olat.core.id.Identity, org.olat.course.run.scoring.ScoreEvaluation)
 */
public void saveScoreEvaluation(final CourseNode courseNode, final Identity identity, final Identity assessedIdentity, final ScoreEvaluation scoreEvaluation, final UserCourseEnvironment userCourseEnv, final boolean incrementUserAttempts) {
    final ICourse course = CourseFactory.loadCourse(ores);
    final CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    final RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    // o_clusterREVIEW we could sync on a element finer than course, e.g. the composite course+assessIdentity.
    // +: concurrency would be higher
    // -: many entries (num of courses * visitors of given course) in the locktable.
    // we could also sync on the assessedIdentity.
    Long attempts = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(createOLATResourceableForLocking(assessedIdentity), new SyncerCallback<Long>() {

        public Long execute() {
            Long attempts = null;
            Float score = scoreEvaluation.getScore();
            Boolean passed = scoreEvaluation.getPassed();
            saveNodeScore(courseNode, assessedIdentity, score, cpm);
            saveNodePassed(courseNode, assessedIdentity, passed, cpm);
            saveAssessmentID(courseNode, assessedIdentity, scoreEvaluation.getAssessmentID(), cpm);
            if (incrementUserAttempts) {
                attempts = incrementNodeAttemptsProperty(courseNode, assessedIdentity, cpm);
            }
            if (courseNode instanceof AssessableCourseNode) {
                userCourseEnv.getScoreAccounting().evaluateAll();
                // Update users efficiency statement
                EfficiencyStatementManager esm = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
                esm.updateUserEfficiencyStatement(userCourseEnv);
            }
            if (passed != null && passed.booleanValue() && course.getCourseConfig().isAutomaticCertificationEnabled()) {
                CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
                if (certificatesManager.isCertificationAllowed(assessedIdentity, courseEntry)) {
                    CertificateTemplate template = null;
                    Long templateId = course.getCourseConfig().getCertificateTemplate();
                    if (templateId != null) {
                        template = certificatesManager.getTemplateById(templateId);
                    }
                    CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
                    certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
                }
            }
            return attempts;
        }
    });
    // node log
    UserNodeAuditManager am = course.getCourseEnvironment().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, ASSESSMENT_ID + " 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)));
    }
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) CertificatesManager(org.olat.course.certificate.CertificatesManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 8 with CertificateTemplate

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

the class CertificatesManagerImpl method doCertificate.

private void doCertificate(JmsCertificateWork workUnit) {
    CertificateImpl certificate = getCertificateById(workUnit.getCertificateKey());
    CertificateTemplate template = null;
    if (workUnit.getTemplateKey() != null) {
        template = getTemplateById(workUnit.getTemplateKey());
    }
    OLATResource resource = certificate.getOlatResource();
    Identity identity = certificate.getIdentity();
    RepositoryEntry entry = repositoryService.loadByResourceKey(resource.getKey());
    String dir = usersStorage.generateDir();
    File dirFile = new File(getCertificateRoot(), dir);
    dirFile.mkdirs();
    Float score = workUnit.getScore();
    String lang = identity.getUser().getPreferences().getLanguage();
    Locale locale = i18nManager.getLocaleOrDefault(lang);
    Boolean passed = workUnit.getPassed();
    Date dateCertification = certificate.getCreationDate();
    Date dateFirstCertification = getDateFirstCertification(identity, resource.getKey());
    Date dateNextRecertification = certificate.getNextRecertificationDate();
    File certificateFile;
    // File name with user name
    StringBuilder sb = new StringBuilder();
    sb.append(identity.getUser().getProperty(UserConstants.LASTNAME, locale)).append("_").append(identity.getUser().getProperty(UserConstants.FIRSTNAME, locale)).append("_").append(entry.getDisplayname()).append("_").append(Formatter.formatShortDateFilesystem(dateCertification));
    String filename = FileUtils.normalizeFilename(sb.toString()) + ".pdf";
    // External URL to certificate as short as possible for QR-Code
    sb = new StringBuilder();
    sb.append(Settings.getServerContextPathURI()).append("/certificate/").append(certificate.getUuid()).append("/certificate.pdf");
    String certUrl = sb.toString();
    if (template == null || template.getPath().toLowerCase().endsWith("pdf")) {
        CertificatePDFFormWorker worker = new CertificatePDFFormWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
        certificateFile = worker.fill(template, dirFile, filename);
        if (certificateFile == null) {
            certificate.setStatus(CertificateStatus.error);
        } else {
            certificate.setStatus(CertificateStatus.ok);
        }
    } else {
        CertificatePhantomWorker worker = new CertificatePhantomWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
        certificateFile = worker.fill(template, dirFile, filename);
        if (certificateFile == null) {
            certificate.setStatus(CertificateStatus.error);
        } else {
            certificate.setStatus(CertificateStatus.ok);
        }
    }
    certificate.setPath(dir + certificateFile.getName());
    if (dateFirstCertification != null) {
        // not the first certification, reset the last of the others certificates
        removeLastFlag(identity, resource.getKey());
    }
    MailerResult result = sendCertificate(identity, entry, certificateFile);
    if (result.isSuccessful()) {
        certificate.setEmailStatus(EmailStatus.ok);
    } else {
        certificate.setEmailStatus(EmailStatus.error);
    }
    dbInstance.getCurrentEntityManager().merge(certificate);
    dbInstance.commit();
    CertificateEvent event = new CertificateEvent(identity.getKey(), certificate.getKey(), resource.getKey());
    coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(event, ORES_CERTIFICATE_EVENT);
}
Also used : Locale(java.util.Locale) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) MailerResult(org.olat.core.util.mail.MailerResult) OLATResource(org.olat.resource.OLATResource) CertificateImpl(org.olat.course.certificate.model.CertificateImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) CertificateEvent(org.olat.course.certificate.CertificateEvent) Identity(org.olat.core.id.Identity) TransientIdentity(org.olat.admin.user.imp.TransientIdentity) File(java.io.File)

Example 9 with CertificateTemplate

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

the class CertificatesManagerImpl method deleteTemplate.

@Override
public void deleteTemplate(CertificateTemplate template) {
    File templateFile = getTemplateFile(template);
    if (templateFile != null && templateFile.getParent() != null && templateFile.getParentFile().exists()) {
        try {
            FileUtils.deleteDirsAndFiles(templateFile.getParentFile().toPath());
        } catch (IOException e) {
            log.error("", e);
        }
    }
    // delete in db
    CertificateTemplate reloadedTemplate = dbInstance.getCurrentEntityManager().getReference(CertificateTemplateImpl.class, template.getKey());
    dbInstance.getCurrentEntityManager().remove(reloadedTemplate);
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) IOException(java.io.IOException) File(java.io.File)

Example 10 with CertificateTemplate

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

the class CertificateChooserController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    List<CertificateTemplate> templates = certificatesManager.getTemplates();
    templatesKeys = new String[templates.size() + 1];
    templatesValues = new String[templates.size() + 1];
    templatesKeys[0] = "def";
    templatesValues[0] = "Default";
    int count = 1;
    for (CertificateTemplate template : templates) {
        templatesKeys[count] = template.getKey().toString();
        templatesValues[count++] = template.getName();
    }
    publicTemplatesEl = uifactory.addDropdownSingleselect("public.templates", formLayout, templatesKeys, templatesValues, null);
    FormLayoutContainer selectButtonCont = FormLayoutContainer.createButtonLayout("selectButton", getTranslator());
    selectButtonCont.setRootForm(mainForm);
    formLayout.add(selectButtonCont);
    selectLink = uifactory.addFormLink("select", selectButtonCont, Link.BUTTON);
    uifactory.addSpacerElement("spaceman", formLayout, false);
    fileEl = uifactory.addFileElement(getWindowControl(), "template.file", formLayout);
    fileEl.addActionListener(FormEvent.ONCHANGE);
    String[] orientationValues = new String[] { translate("portrait"), translate("landscape") };
    orientationEl = uifactory.addRadiosVertical("orientation", formLayout, orientationKeys, orientationValues);
    orientationEl.select(orientationKeys[0], true);
    orientationEl.setVisible(false);
    formatEl = uifactory.addRadiosVertical("format", formLayout, formatKeys, formatKeys);
    formatEl.select(formatKeys[0], true);
    formatEl.setVisible(false);
    FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonCont.setRootForm(mainForm);
    formLayout.add(buttonCont);
    uploadLink = uifactory.addFormLink("upload", buttonCont, Link.BUTTON);
    uifactory.addFormCancelButton("cancel", buttonCont, ureq, getWindowControl());
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

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