use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
the class CertificationNotificationHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher p = subscriber.getPublisher();
if (!NotificationsUpgradeHelper.checkCourse(p)) {
// course don't exist anymore
NotificationsManager.getInstance().deactivate(p);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
try {
Date latestNews = p.getLatestNewsDate();
Identity identity = subscriber.getIdentity();
Translator trans = Util.createPackageTranslator(CertificateController.class, locale);
// can't be loaded when already deleted
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
Long courseId = new Long(p.getData());
final ICourse course = CourseFactory.loadCourse(courseId);
if (courseStatus(course)) {
// course admins or users with the course right to have full access to
// the assessment tool will have full access to user tests
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
List<Certificate> certificates = certificatesManager.getCertificatesForNotifications(identity, entry, latestNews);
for (Certificate certificate : certificates) {
Date modDate = certificate.getCreationDate();
Identity assessedIdentity = certificate.getIdentity();
String fullname = userManager.getUserDisplayName(assessedIdentity);
String desc = trans.translate("notifications.desc", new String[] { fullname });
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = p.getBusinessPath() + "[assessmentTool:0][Identity:" + assessedIdentity.getKey() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, "o_icon_certificate");
if (si == null) {
String title = trans.translate("notifications.header", new String[] { course.getCourseTitle() });
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, "o_icon_certificate"), null);
}
si.addSubscriptionListItem(subListItem);
}
}
}
if (si == null) {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Error while creating assessment notifications", e);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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());
}
use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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());
}
Aggregations