Search in sources :

Example 1 with CertificateInfos

use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.

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 2 with CertificateInfos

use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.

the class AssessedIdentityCertificatesController method doGenerateCertificate.

private void doGenerateCertificate(UserRequest ureq) {
    ICourse course = CourseFactory.loadCourse(resource);
    CourseNode rootNode = course.getRunStructure().getRootNode();
    Identity assessedIdentity = assessedUserCourseEnv.getIdentityEnvironment().getIdentity();
    ScoreEvaluation scoreEval = assessedUserCourseEnv.getScoreAccounting().getScoreEvaluation(rootNode);
    RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    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) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity)

Example 3 with CertificateInfos

use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.

the class CertificatesSelectionController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    ;
    int colPos = 0;
    if (isAdministrativeUser) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.name", CertificatesSelectionDataModel.USERNAME_COL));
    }
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(AssessedIdentitiesTableDataModel.usageIdentifyer, isAdministrativeUser);
    List<UserPropertyHandler> resultingPropertyHandlers = new ArrayList<UserPropertyHandler>();
    // followed by the users fields
    for (int i = 0; i < userPropertyHandlers.size(); i++) {
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
        boolean visible = userManager.isMandatoryUserProperty(AssessedIdentitiesTableDataModel.usageIdentifyer, userPropertyHandler);
        resultingPropertyHandlers.add(userPropertyHandler);
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos++, false, null));
    }
    if (hasAssessableNodes) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.passed", CertificatesSelectionDataModel.PASSED_COL, new PassedCellRenderer()));
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.score", CertificatesSelectionDataModel.SCORE_COL));
    }
    tableModel = new CertificatesSelectionDataModel(columnsModel, resultingPropertyHandlers);
    Set<Integer> preselectedRows = new HashSet<>();
    ICourse course = CourseFactory.loadCourse(courseEntry);
    CourseNode rootNode = course.getRunStructure().getRootNode();
    List<CertificateInfos> infos = new ArrayList<>(datas.size());
    int count = 0;
    for (AssessedIdentityWrapper data : datas) {
        ScoreEvaluation scoreEval = data.getUserCourseEnvironment().getScoreAccounting().getScoreEvaluation(rootNode);
        Float score = scoreEval == null ? null : scoreEval.getScore();
        Boolean passed = scoreEval == null ? null : scoreEval.getPassed();
        Identity assessedIdentity = data.getIdentity();
        infos.add(new CertificateInfos(assessedIdentity, score, passed));
        if (passed != null && passed.booleanValue()) {
            preselectedRows.add(new Integer(count));
        }
        count++;
    }
    tableModel.setObjects(infos);
    tableEl = uifactory.addTableElement(getWindowControl(), "selection", tableModel, getTranslator(), formLayout);
    tableEl.setMultiSelect(true);
    tableEl.setSelectAllEnable(true);
    tableEl.setMultiSelectedIndex(preselectedRows);
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) AssessedIdentityWrapper(org.olat.course.assessment.AssessedIdentityWrapper) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) CourseNode(org.olat.course.nodes.CourseNode) PassedCellRenderer(org.olat.course.assessment.bulk.PassedCellRenderer) Identity(org.olat.core.id.Identity) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) HashSet(java.util.HashSet)

Example 4 with CertificateInfos

use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.

the class CertificatesManagerTest method loadCertificate.

@Test
public void loadCertificate() {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
    dbInstance.commitAndCloseSession();
    CertificateInfos certificateInfos = new CertificateInfos(identity, 5.0f, Boolean.TRUE);
    Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
    Assert.assertNotNull(certificate);
    dbInstance.commitAndCloseSession();
    // full
    Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
    Assert.assertNotNull(reloadedCertificate);
    Assert.assertEquals(certificate, reloadedCertificate);
    Assert.assertNotNull(reloadedCertificate.getUuid());
    Assert.assertEquals(certificate.getUuid(), reloadedCertificate.getUuid());
    Assert.assertEquals(entry.getDisplayname(), reloadedCertificate.getCourseTitle());
    Assert.assertEquals(identity, reloadedCertificate.getIdentity());
    // light
    CertificateLight reloadedLight = certificatesManager.getCertificateLightById(certificate.getKey());
    Assert.assertNotNull(reloadedLight);
    Assert.assertEquals(certificate.getKey(), reloadedLight.getKey());
    Assert.assertEquals(entry.getDisplayname(), reloadedLight.getCourseTitle());
    Assert.assertEquals(identity.getKey(), reloadedLight.getIdentityKey());
    Assert.assertEquals(entry.getOlatResource().getKey(), reloadedLight.getOlatResourceKey());
    // uuid
    Certificate reloadedUuid = certificatesManager.getCertificateByUuid(certificate.getUuid());
    Assert.assertNotNull(reloadedUuid);
    Assert.assertEquals(certificate, reloadedUuid);
    Assert.assertEquals(entry.getDisplayname(), reloadedUuid.getCourseTitle());
    Assert.assertEquals(identity, reloadedUuid.getIdentity());
    // boolean
    boolean has = certificatesManager.hasCertificate(identity, entry.getOlatResource().getKey());
    Assert.assertTrue(has);
}
Also used : CertificateInfos(org.olat.course.certificate.model.CertificateInfos) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) CertificateLight(org.olat.course.certificate.CertificateLight) Certificate(org.olat.course.certificate.Certificate) Test(org.junit.Test)

Example 5 with CertificateInfos

use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.

the class CertificatesManagerTest method loadLastCertificate.

@Test
public void loadLastCertificate() {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
    dbInstance.commitAndCloseSession();
    CertificateInfos certificateInfos = new CertificateInfos(identity, 5.0f, Boolean.TRUE);
    Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
    Assert.assertNotNull(certificate);
    dbInstance.commitAndCloseSession();
    // per resource
    Certificate reloadedCertificate = certificatesManager.getLastCertificate(identity, entry.getOlatResource().getKey());
    Assert.assertNotNull(reloadedCertificate);
    Assert.assertEquals(certificate, reloadedCertificate);
    // all
    List<CertificateLight> allCertificates = certificatesManager.getLastCertificates(identity);
    Assert.assertNotNull(allCertificates);
    Assert.assertEquals(1, allCertificates.size());
    CertificateLight allCertificate = allCertificates.get(0);
    Assert.assertEquals(certificate.getKey(), allCertificate.getKey());
    Assert.assertEquals(entry.getDisplayname(), allCertificate.getCourseTitle());
    Assert.assertEquals(identity.getKey(), allCertificate.getIdentityKey());
    Assert.assertEquals(entry.getOlatResource().getKey(), allCertificate.getOlatResourceKey());
}
Also used : CertificateInfos(org.olat.course.certificate.model.CertificateInfos) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) CertificateLight(org.olat.course.certificate.CertificateLight) Certificate(org.olat.course.certificate.Certificate) Test(org.junit.Test)

Aggregations

CertificateInfos (org.olat.course.certificate.model.CertificateInfos)34 Identity (org.olat.core.id.Identity)24 RepositoryEntry (org.olat.repository.RepositoryEntry)24 Certificate (org.olat.course.certificate.Certificate)18 Test (org.junit.Test)16 ICourse (org.olat.course.ICourse)12 CertificateTemplate (org.olat.course.certificate.CertificateTemplate)10 CourseNode (org.olat.course.nodes.CourseNode)8 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)8 URI (java.net.URI)6 ArrayList (java.util.ArrayList)6 HttpResponse (org.apache.http.HttpResponse)6 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)6 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)6 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 Calendar (java.util.Calendar)4 Date (java.util.Date)4 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)4 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)4