use of org.olat.course.certificate.CertificateEvent in project OpenOLAT by OpenOLAT.
the class CertificatesManagerImpl method doCertificate.
private void doCertificate(JmsCertificateWork workUnit) {
CertificateImpl certificate = getCertificateById(workUnit.getCertificateKey());
CertificateTemplate template = null;
if (workUnit.getTemplateKey() != null) {
template = getTemplateById(workUnit.getTemplateKey());
}
OLATResource resource = certificate.getOlatResource();
Identity identity = certificate.getIdentity();
RepositoryEntry entry = repositoryService.loadByResourceKey(resource.getKey());
String dir = usersStorage.generateDir();
File dirFile = new File(getCertificateRoot(), dir);
dirFile.mkdirs();
Float score = workUnit.getScore();
String lang = identity.getUser().getPreferences().getLanguage();
Locale locale = i18nManager.getLocaleOrDefault(lang);
Boolean passed = workUnit.getPassed();
Date dateCertification = certificate.getCreationDate();
Date dateFirstCertification = getDateFirstCertification(identity, resource.getKey());
Date dateNextRecertification = certificate.getNextRecertificationDate();
File certificateFile;
// File name with user name
StringBuilder sb = new StringBuilder();
sb.append(identity.getUser().getProperty(UserConstants.LASTNAME, locale)).append("_").append(identity.getUser().getProperty(UserConstants.FIRSTNAME, locale)).append("_").append(entry.getDisplayname()).append("_").append(Formatter.formatShortDateFilesystem(dateCertification));
String filename = FileUtils.normalizeFilename(sb.toString()) + ".pdf";
// External URL to certificate as short as possible for QR-Code
sb = new StringBuilder();
sb.append(Settings.getServerContextPathURI()).append("/certificate/").append(certificate.getUuid()).append("/certificate.pdf");
String certUrl = sb.toString();
if (template == null || template.getPath().toLowerCase().endsWith("pdf")) {
CertificatePDFFormWorker worker = new CertificatePDFFormWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
certificateFile = worker.fill(template, dirFile, filename);
if (certificateFile == null) {
certificate.setStatus(CertificateStatus.error);
} else {
certificate.setStatus(CertificateStatus.ok);
}
} else {
CertificatePhantomWorker worker = new CertificatePhantomWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
certificateFile = worker.fill(template, dirFile, filename);
if (certificateFile == null) {
certificate.setStatus(CertificateStatus.error);
} else {
certificate.setStatus(CertificateStatus.ok);
}
}
certificate.setPath(dir + certificateFile.getName());
if (dateFirstCertification != null) {
// not the first certification, reset the last of the others certificates
removeLastFlag(identity, resource.getKey());
}
MailerResult result = sendCertificate(identity, entry, certificateFile);
if (result.isSuccessful()) {
certificate.setEmailStatus(EmailStatus.ok);
} else {
certificate.setEmailStatus(EmailStatus.error);
}
dbInstance.getCurrentEntityManager().merge(certificate);
dbInstance.commit();
CertificateEvent event = new CertificateEvent(identity.getKey(), certificate.getKey(), resource.getKey());
coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(event, ORES_CERTIFICATE_EVENT);
}
use of org.olat.course.certificate.CertificateEvent in project OpenOLAT by OpenOLAT.
the class GroupController method event.
@Override
public void event(Event event) {
if (event instanceof CertificateEvent) {
CertificateEvent ce = (CertificateEvent) event;
IdentityResourceKey key = new IdentityResourceKey(ce.getOwnerKey(), ce.getResourceKey());
if (model.contains(key)) {
updateCertificate(ce.getCertificateKey());
}
}
}
use of org.olat.course.certificate.CertificateEvent in project openolat by klemens.
the class CertificatesManagerImpl method doCertificate.
private void doCertificate(JmsCertificateWork workUnit) {
CertificateImpl certificate = getCertificateById(workUnit.getCertificateKey());
CertificateTemplate template = null;
if (workUnit.getTemplateKey() != null) {
template = getTemplateById(workUnit.getTemplateKey());
}
OLATResource resource = certificate.getOlatResource();
Identity identity = certificate.getIdentity();
RepositoryEntry entry = repositoryService.loadByResourceKey(resource.getKey());
String dir = usersStorage.generateDir();
File dirFile = new File(getCertificateRoot(), dir);
dirFile.mkdirs();
Float score = workUnit.getScore();
String lang = identity.getUser().getPreferences().getLanguage();
Locale locale = i18nManager.getLocaleOrDefault(lang);
Boolean passed = workUnit.getPassed();
Date dateCertification = certificate.getCreationDate();
Date dateFirstCertification = getDateFirstCertification(identity, resource.getKey());
Date dateNextRecertification = certificate.getNextRecertificationDate();
File certificateFile;
// File name with user name
StringBuilder sb = new StringBuilder();
sb.append(identity.getUser().getProperty(UserConstants.LASTNAME, locale)).append("_").append(identity.getUser().getProperty(UserConstants.FIRSTNAME, locale)).append("_").append(entry.getDisplayname()).append("_").append(Formatter.formatShortDateFilesystem(dateCertification));
String filename = FileUtils.normalizeFilename(sb.toString()) + ".pdf";
// External URL to certificate as short as possible for QR-Code
sb = new StringBuilder();
sb.append(Settings.getServerContextPathURI()).append("/certificate/").append(certificate.getUuid()).append("/certificate.pdf");
String certUrl = sb.toString();
if (template == null || template.getPath().toLowerCase().endsWith("pdf")) {
CertificatePDFFormWorker worker = new CertificatePDFFormWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
certificateFile = worker.fill(template, dirFile, filename);
if (certificateFile == null) {
certificate.setStatus(CertificateStatus.error);
} else {
certificate.setStatus(CertificateStatus.ok);
}
} else {
CertificatePhantomWorker worker = new CertificatePhantomWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
certificateFile = worker.fill(template, dirFile, filename);
if (certificateFile == null) {
certificate.setStatus(CertificateStatus.error);
} else {
certificate.setStatus(CertificateStatus.ok);
}
}
certificate.setPath(dir + certificateFile.getName());
if (dateFirstCertification != null) {
// not the first certification, reset the last of the others certificates
removeLastFlag(identity, resource.getKey());
}
MailerResult result = sendCertificate(identity, entry, certificateFile);
if (result.isSuccessful()) {
certificate.setEmailStatus(EmailStatus.ok);
} else {
certificate.setEmailStatus(EmailStatus.error);
}
dbInstance.getCurrentEntityManager().merge(certificate);
dbInstance.commit();
CertificateEvent event = new CertificateEvent(identity.getKey(), certificate.getKey(), resource.getKey());
coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(event, ORES_CERTIFICATE_EVENT);
}
use of org.olat.course.certificate.CertificateEvent in project openolat by klemens.
the class GroupController method event.
@Override
public void event(Event event) {
if (event instanceof CertificateEvent) {
CertificateEvent ce = (CertificateEvent) event;
IdentityResourceKey key = new IdentityResourceKey(ce.getOwnerKey(), ce.getResourceKey());
if (model.contains(key)) {
updateCertificate(ce.getCertificateKey());
}
}
}
Aggregations