Search in sources :

Example 6 with CertificateImpl

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);
        }
    }
}
Also used : IOException(java.io.IOException) CertificateImpl(org.olat.course.certificate.model.CertificateImpl) File(java.io.File) Certificate(org.olat.course.certificate.Certificate)

Example 7 with CertificateImpl

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;
}
Also used : InputStream(java.io.InputStream) CertificateImpl(org.olat.course.certificate.model.CertificateImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) Date(java.util.Date) CorruptedCourseException(org.olat.course.CorruptedCourseException) IOException(java.io.IOException) JMSException(javax.jms.JMSException)

Example 8 with CertificateImpl

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;
}
Also used : OLATResource(org.olat.resource.OLATResource) CertificateImpl(org.olat.course.certificate.model.CertificateImpl) Identity(org.olat.core.id.Identity) TransientIdentity(org.olat.admin.user.imp.TransientIdentity) Date(java.util.Date)

Aggregations

CertificateImpl (org.olat.course.certificate.model.CertificateImpl)8 File (java.io.File)6 Date (java.util.Date)6 IOException (java.io.IOException)4 TransientIdentity (org.olat.admin.user.imp.TransientIdentity)4 Identity (org.olat.core.id.Identity)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 OLATResource (org.olat.resource.OLATResource)4 InputStream (java.io.InputStream)2 Locale (java.util.Locale)2 JMSException (javax.jms.JMSException)2 MailerResult (org.olat.core.util.mail.MailerResult)2 CorruptedCourseException (org.olat.course.CorruptedCourseException)2 Certificate (org.olat.course.certificate.Certificate)2 CertificateEvent (org.olat.course.certificate.CertificateEvent)2 CertificateTemplate (org.olat.course.certificate.CertificateTemplate)2