Search in sources :

Example 16 with CertificateInfos

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

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

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

the class CertificatesManagerImpl method generateCertificates.

@Override
public void generateCertificates(List<CertificateInfos> certificateInfos, RepositoryEntry entry, CertificateTemplate template, boolean sendMail) {
    int count = 0;
    for (CertificateInfos certificateInfo : certificateInfos) {
        generateCertificate(certificateInfo, entry, template, sendMail);
        if (++count % 10 == 0) {
            dbInstance.commitAndCloseSession();
        }
    }
    markPublisherNews(null, entry.getOlatResource());
}
Also used : CertificateInfos(org.olat.course.certificate.model.CertificateInfos)

Example 18 with CertificateInfos

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

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

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

the class CertificationTest method deleteCertificate.

@Test
public void deleteCertificate() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("cert-15");
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("cert-5");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
    CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, 2.0f, true);
    Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(certificate);
    // wait until certificate is generated
    waitForCondition(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
            return CertificateStatus.ok.equals(reloadedCertificate.getStatus());
        }
    }, 30000);
    // check that there is a real certificate with its file
    Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
    VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(reloadedCertificate);
    Assert.assertNotNull(certificateFile);
    Assert.assertTrue(certificateFile.exists());
    // delete the certificate
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(entry.getOlatResource().getKey().toString()).path("certificates").path(assessedIdentity.getKey().toString()).build();
    HttpDelete method = conn.createDelete(uri, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    conn.shutdown();
    // check that the file and the database record are deleted
    VFSLeaf deletedFile = certificatesManager.getCertificateLeaf(reloadedCertificate);
    Assert.assertNull(deletedFile);
    Certificate deletedCertificate = certificatesManager.getCertificateById(certificate.getKey());
    Assert.assertNull(deletedCertificate);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HttpDelete(org.apache.http.client.methods.HttpDelete) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) Certificate(org.olat.course.certificate.Certificate) Test(org.junit.Test)

Example 20 with CertificateInfos

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

the class CertificatesManagerTest method certificateNotifications_courseCoach.

@Test
public void certificateNotifications_courseCoach() throws URISyntaxException {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-2");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-3");
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-4");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-4");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(owner);
    repositoryEntryRelationDao.addRole(coach, entry, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(participant1, entry, GroupRoles.participant.name());
    repositoryEntryRelationDao.addRole(participant2, entry, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    CertificateInfos certificateInfos1 = new CertificateInfos(participant1, null, null);
    Certificate certificate1 = certificatesManager.generateCertificate(certificateInfos1, entry, null, false);
    Assert.assertNotNull(certificate1);
    CertificateInfos certificateInfos2 = new CertificateInfos(participant2, null, null);
    Certificate certificate2 = certificatesManager.generateCertificate(certificateInfos2, entry, null, false);
    Assert.assertNotNull(certificate2);
    dbInstance.commitAndCloseSession();
    Calendar lastestNews = Calendar.getInstance();
    lastestNews.add(Calendar.HOUR_OF_DAY, -1);
    // check the notifications of the author ( entry admin )
    List<Certificate> authorNotifications = certificatesManager.getCertificatesForNotifications(owner, entry, lastestNews.getTime());
    Assert.assertNotNull(authorNotifications);
    Assert.assertEquals(2, authorNotifications.size());
    // check the notifications of the coach
    List<Certificate> coachNotifications = certificatesManager.getCertificatesForNotifications(coach, entry, lastestNews.getTime());
    Assert.assertNotNull(coachNotifications);
    Assert.assertEquals(2, coachNotifications.size());
    // check the notifications of the participant
    List<Certificate> participantNotifications = certificatesManager.getCertificatesForNotifications(participant1, entry, lastestNews.getTime());
    Assert.assertNotNull(participantNotifications);
    Assert.assertEquals(1, participantNotifications.size());
    Assert.assertTrue(participantNotifications.contains(certificate1));
}
Also used : CertificateInfos(org.olat.course.certificate.model.CertificateInfos) Calendar(java.util.Calendar) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) 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