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));
}
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);
}
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());
}
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);
}
}
}
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);
}
Aggregations