use of org.olat.course.certificate.Certificate 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);
}
use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
the class CertificatesManagerTest method uploadCertificate.
@Test
public void uploadCertificate() throws URISyntaxException {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
dbInstance.commitAndCloseSession();
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.uploadCertificate(identity, creationDate, entry.getOlatResource(), certificateFile);
Assert.assertNotNull(certificate);
Assert.assertNotNull(certificate.getKey());
Assert.assertNotNull(certificate.getUuid());
Assert.assertEquals(entry.getDisplayname(), certificate.getCourseTitle());
Assert.assertEquals(identity, certificate.getIdentity());
dbInstance.commitAndCloseSession();
// double check
Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
Assert.assertNotNull(reloadedCertificate);
Assert.assertNotNull(reloadedCertificate.getUuid());
Assert.assertEquals(entry.getDisplayname(), reloadedCertificate.getCourseTitle());
Assert.assertEquals(identity, reloadedCertificate.getIdentity());
Assert.assertEquals(entry.getOlatResource().getKey(), reloadedCertificate.getArchivedResourceKey());
Assert.assertEquals(creationDate, reloadedCertificate.getCreationDate());
// the file
VFSLeaf savedCertificateFile = certificatesManager.getCertificateLeaf(reloadedCertificate);
Assert.assertNotNull(savedCertificateFile);
Assert.assertTrue(savedCertificateFile.exists());
// load last
Certificate lastCertificate = certificatesManager.getLastCertificate(identity, entry.getOlatResource().getKey());
Assert.assertNotNull(lastCertificate);
Assert.assertEquals(certificate, lastCertificate);
}
use of org.olat.course.certificate.Certificate 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));
}
use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
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());
}
Aggregations