Search in sources :

Example 41 with Certificate

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

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)

Example 42 with Certificate

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

the class CertificatesManagerTest method uploadStandalone.

@Test
public void uploadStandalone() throws URISyntaxException {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
    dbInstance.commitAndCloseSession();
    String courseTitle = "Unkown course";
    Long resourceKey = 4l;
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.YEAR, 2012);
    Date creationDate = cal.getTime();
    URL certificateUrl = CertificatesManagerTest.class.getResource("template.pdf");
    Assert.assertNotNull(certificateUrl);
    File certificateFile = new File(certificateUrl.toURI());
    Certificate certificate = certificatesManager.uploadStandaloneCertificate(identity, creationDate, courseTitle, resourceKey, certificateFile);
    Assert.assertNotNull(certificate);
    Assert.assertNotNull(certificate.getKey());
    Assert.assertNotNull(certificate.getUuid());
    Assert.assertEquals(courseTitle, certificate.getCourseTitle());
    Assert.assertEquals(identity, certificate.getIdentity());
    dbInstance.commitAndCloseSession();
    // load by id
    Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
    Assert.assertNotNull(reloadedCertificate);
    Assert.assertNotNull(reloadedCertificate.getUuid());
    Assert.assertEquals(courseTitle, reloadedCertificate.getCourseTitle());
    Assert.assertEquals(identity, reloadedCertificate.getIdentity());
    Assert.assertEquals(resourceKey, reloadedCertificate.getArchivedResourceKey());
    Assert.assertEquals(creationDate, reloadedCertificate.getCreationDate());
    // load last
    Certificate lastCertificate = certificatesManager.getLastCertificate(identity, resourceKey);
    Assert.assertNotNull(lastCertificate);
    Assert.assertEquals(certificate.getKey(), lastCertificate.getKey());
    Assert.assertEquals(reloadedCertificate, lastCertificate);
}
Also used : Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) File(java.io.File) Date(java.util.Date) URL(java.net.URL) Certificate(org.olat.course.certificate.Certificate) Test(org.junit.Test)

Example 43 with Certificate

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

the class CertificatesManagerTest method createCertificate.

@Test
public void createCertificate() throws URISyntaxException {
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
    dbInstance.commitAndCloseSession();
    CertificateInfos certificateInfos = new CertificateInfos(identity, null, null);
    Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
    Assert.assertNotNull(certificate);
    Assert.assertNotNull(certificate.getKey());
    Assert.assertNotNull(certificate.getUuid());
    Assert.assertEquals(entry.getOlatResource().getKey(), certificate.getArchivedResourceKey());
    // check if the pdf exists / flush cache, reload the entry with the updated path
    dbInstance.commitAndCloseSession();
    waitCertificate(certificate.getKey());
    Certificate reloadCertificate = certificatesManager.getCertificateById(certificate.getKey());
    VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(reloadCertificate);
    Assert.assertNotNull(certificateFile);
    Assert.assertTrue(certificateFile.exists());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Certificate(org.olat.course.certificate.Certificate) Test(org.junit.Test)

Example 44 with Certificate

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

the class CertificatesManagerTest method deleteCourse_paranoiaCheck.

/**
 * Create 2 courses, add a certificate to them and delete the first course.
 * Check that a certificate loose the relation to the deleted course but not
 * the other. The two certificates stay.
 *
 * @throws URISyntaxException
 */
@Test
public void deleteCourse_paranoiaCheck() throws URISyntaxException {
    // create a course with a certificate
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-del-3");
    RepositoryEntry entryToDelete = JunitTestHelper.deployBasicCourse(identity);
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
    dbInstance.commitAndCloseSession();
    Long resourceKeyToDelete = entryToDelete.getOlatResource().getKey();
    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 linked to the course which will be deleted
    Certificate certificateDeletedCourse = certificatesManager.uploadCertificate(identity, cal.getTime(), entryToDelete.getOlatResource(), certificateFile);
    Assert.assertNotNull(certificateDeletedCourse);
    // certificate of the staying course
    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(entryToDelete, identity, roles, Locale.ENGLISH);
    dbInstance.commitAndCloseSession();
    // retrieve the certificate of the deleted course
    Certificate reloadedCertificateDeletedCourse = certificatesManager.getCertificateById(certificateDeletedCourse.getKey());
    Assert.assertNotNull(reloadedCertificateDeletedCourse);
    Assert.assertEquals(certificateDeletedCourse, reloadedCertificateDeletedCourse);
    Assert.assertNotNull(reloadedCertificateDeletedCourse.getArchivedResourceKey());
    Assert.assertNull(((CertificateImpl) reloadedCertificateDeletedCourse).getOlatResource());
    Assert.assertEquals(resourceKeyToDelete, reloadedCertificateDeletedCourse.getArchivedResourceKey());
    // retrieve the certificate of the staying course
    Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
    Assert.assertNotNull(reloadedCertificate);
    Assert.assertEquals(certificate, reloadedCertificate);
    Assert.assertNotNull(reloadedCertificate.getArchivedResourceKey());
    Assert.assertEquals(resourceKey, reloadedCertificate.getArchivedResourceKey());
    Assert.assertEquals(entry.getOlatResource(), ((CertificateImpl) reloadedCertificate).getOlatResource());
}
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 45 with Certificate

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

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

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