Search in sources :

Example 21 with Certificate

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

the class CertificatesManagerTest method certificateNotifications_courseCoachByGroups.

@Test
public void certificateNotifications_courseCoachByGroups() throws URISyntaxException {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-5");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-6");
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-7");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-8");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(owner);
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "certified-group", "Group with certification", null, null, false, false, entry);
    businessGroupRelationDao.addRole(coach, group, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(participant1, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(participant2, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // make a certificate
    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();
    waitCertificate(certificate1.getKey());
    waitCertificate(certificate2.getKey());
    dbInstance.commitAndCloseSession();
    sleep(2000);
    Calendar lastestNews = Calendar.getInstance();
    lastestNews.add(Calendar.DATE, -1);
    // 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 : BusinessGroup(org.olat.group.BusinessGroup) 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)

Example 22 with Certificate

use of org.olat.course.certificate.Certificate 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 23 with Certificate

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

the class CertificatesManagerTest method deleteCourse.

/**
 * Create a course, add a certificate to it and delete the course.
 * The certificate stays.
 *
 * @throws URISyntaxException
 */
@Test
public void deleteCourse() throws URISyntaxException {
    // create a course with a certificate
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-del-2");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
    dbInstance.commitAndCloseSession();
    Long resourceKey = entry.getOlatResource().getKey();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    URL certificateUrl = CertificatesManagerTest.class.getResource("template.pdf");
    File certificateFile = new File(certificateUrl.toURI());
    Certificate certificate = certificatesManager.uploadCertificate(identity, cal.getTime(), entry.getOlatResource(), certificateFile);
    Assert.assertNotNull(certificate);
    dbInstance.commitAndCloseSession();
    // delete the course
    Roles roles = new Roles(true, false, false, false, false, false, false);
    repositoryService.deletePermanently(entry, identity, roles, Locale.ENGLISH);
    dbInstance.commitAndCloseSession();
    // retrieve the certificate
    Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
    Assert.assertNotNull(reloadedCertificate);
    Assert.assertEquals(certificate, reloadedCertificate);
    Assert.assertNotNull(reloadedCertificate.getArchivedResourceKey());
    Assert.assertEquals(resourceKey, reloadedCertificate.getArchivedResourceKey());
}
Also used : Calendar(java.util.Calendar) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) URL(java.net.URL) Certificate(org.olat.course.certificate.Certificate) Test(org.junit.Test)

Example 24 with Certificate

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

the class CertificatesManagerImpl method deleteCertificate.

@Override
public void deleteCertificate(Certificate certificate) {
    File certificateFile = getCertificateFile(certificate);
    if (certificateFile != null && certificateFile.exists()) {
        try {
            FileUtils.deleteDirsAndFiles(certificateFile.getParentFile().toPath());
        } catch (IOException e) {
            log.error("", e);
        }
    }
    CertificateImpl relaodedCertificate = dbInstance.getCurrentEntityManager().getReference(CertificateImpl.class, certificate.getKey());
    dbInstance.getCurrentEntityManager().remove(relaodedCertificate);
    // reorder the last flag
    List<Certificate> certificates = getCertificates(relaodedCertificate.getIdentity(), relaodedCertificate.getOlatResource());
    certificates.remove(relaodedCertificate);
    if (certificates.size() > 0) {
        boolean hasLast = false;
        for (Certificate cer : certificates) {
            if (((CertificateImpl) cer).isLast()) {
                hasLast = true;
            }
        }
        if (!hasLast) {
            CertificateImpl newLastCertificate = (CertificateImpl) certificates.get(0);
            newLastCertificate.setLast(true);
            dbInstance.getCurrentEntityManager().merge(newLastCertificate);
        }
    }
}
Also used : IOException(java.io.IOException) CertificateImpl(org.olat.course.certificate.model.CertificateImpl) File(java.io.File) Certificate(org.olat.course.certificate.Certificate)

Example 25 with Certificate

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

the class AssessedIdentityCertificatesController method loadList.

private void loadList() {
    Identity assessedIdentity = assessedUserCourseEnv.getIdentityEnvironment().getIdentity();
    List<Certificate> certificates = certificatesManager.getCertificates(assessedIdentity, resource);
    List<Links> certificatesLink = new ArrayList<>(certificates.size());
    int count = 0;
    for (Certificate certificate : certificates) {
        String displayName = formatter.formatDateAndTime(certificate.getCreationDate());
        String url = DownloadCertificateCellRenderer.getUrl(certificate);
        Links links = new Links(url, displayName, certificate.getStatus().name());
        certificatesLink.add(links);
        if (canDelete) {
            Link deleteLink = LinkFactory.createLink("delete." + count++, "delete", getTranslator(), mainVC, this, Link.NONTRANSLATED);
            deleteLink.setCustomDisplayText(" ");
            deleteLink.setElementCssClass("o_sel_certificate_delete");
            deleteLink.setIconLeftCSS("o_icon o_icon-lg o_icon_delete");
            deleteLink.setUserObject(certificate);
            links.setDelete(deleteLink);
        }
    }
    mainVC.contextPut("certificates", certificatesLink);
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Link(org.olat.core.gui.components.link.Link) Certificate(org.olat.course.certificate.Certificate)

Aggregations

Certificate (org.olat.course.certificate.Certificate)54 Identity (org.olat.core.id.Identity)42 Test (org.junit.Test)30 RepositoryEntry (org.olat.repository.RepositoryEntry)30 Date (java.util.Date)20 CertificateInfos (org.olat.course.certificate.model.CertificateInfos)18 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)16 File (java.io.File)14 Calendar (java.util.Calendar)14 URI (java.net.URI)12 URL (java.net.URL)12 HttpResponse (org.apache.http.HttpResponse)12 Path (javax.ws.rs.Path)8 BaseSecurity (org.olat.basesecurity.BaseSecurity)8 CertificatesManager (org.olat.course.certificate.CertificatesManager)8 IOException (java.io.IOException)6 Roles (org.olat.core.id.Roles)6 ICourse (org.olat.course.ICourse)6 OLATResource (org.olat.resource.OLATResource)6 OLATResourceManager (org.olat.resource.OLATResourceManager)6