use of org.olat.course.certificate.model.CertificateImpl in project OpenOLAT by OpenOLAT.
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.model.CertificateImpl in project OpenOLAT by OpenOLAT.
the class CertificatesManagerImpl method uploadCertificate.
@Override
public Certificate uploadCertificate(Identity identity, Date creationDate, OLATResource resource, File certificateFile) {
CertificateImpl certificate = new CertificateImpl();
certificate.setOlatResource(resource);
certificate.setArchivedResourceKey(resource.getKey());
if (creationDate != null) {
certificate.setCreationDate(creationDate);
}
RepositoryEntry entry = repositoryService.loadByResourceKey(resource.getKey());
if (entry != null) {
certificate.setCourseTitle(entry.getDisplayname());
}
certificate.setLastModified(certificate.getCreationDate());
certificate.setIdentity(identity);
certificate.setUuid(UUID.randomUUID().toString());
certificate.setLast(true);
certificate.setStatus(CertificateStatus.ok);
String dir = usersStorage.generateDir();
try (InputStream in = Files.newInputStream(certificateFile.toPath())) {
File dirFile = new File(getCertificateRoot(), dir);
dirFile.mkdirs();
File storedCertificateFile = new File(dirFile, "Certificate.pdf");
Files.copy(in, storedCertificateFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
certificate.setPath(dir + storedCertificateFile.getName());
Date dateFirstCertification = getDateFirstCertification(identity, resource.getKey());
if (dateFirstCertification != null) {
removeLastFlag(identity, resource.getKey());
}
dbInstance.getCurrentEntityManager().persist(certificate);
} catch (Exception e) {
log.error("", e);
}
return certificate;
}
use of org.olat.course.certificate.model.CertificateImpl in project openolat by klemens.
the class CertificatesManagerImpl method persistCertificate.
private Certificate persistCertificate(CertificateInfos certificateInfos, RepositoryEntry entry, CertificateTemplate template, boolean sendMail) {
OLATResource resource = entry.getOlatResource();
Identity identity = certificateInfos.getAssessedIdentity();
CertificateImpl certificate = new CertificateImpl();
certificate.setOlatResource(resource);
certificate.setArchivedResourceKey(resource.getKey());
if (certificateInfos.getCreationDate() != null) {
certificate.setCreationDate(certificateInfos.getCreationDate());
} else {
certificate.setCreationDate(new Date());
}
certificate.setLastModified(certificate.getCreationDate());
certificate.setIdentity(identity);
certificate.setUuid(UUID.randomUUID().toString());
certificate.setLast(true);
certificate.setCourseTitle(entry.getDisplayname());
certificate.setStatus(CertificateStatus.pending);
Date nextCertification = getDateNextRecertification(certificate, entry);
certificate.setNextRecertificationDate(nextCertification);
dbInstance.getCurrentEntityManager().persist(certificate);
dbInstance.commit();
// send message
sendJmsCertificateFile(certificate, template, certificateInfos.getScore(), certificateInfos.getPassed(), sendMail);
return certificate;
}
Aggregations