Search in sources :

Example 31 with Certificate

use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.

the class CertificatesManagerImpl method generateCertificate.

@Override
public Certificate generateCertificate(CertificateInfos certificateInfos, RepositoryEntry entry, CertificateTemplate template, boolean sendMail) {
    Certificate certificate = persistCertificate(certificateInfos, entry, template, sendMail);
    markPublisherNews(null, entry.getOlatResource());
    return certificate;
}
Also used : Certificate(org.olat.course.certificate.Certificate)

Example 32 with Certificate

use of org.olat.course.certificate.Certificate 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 33 with Certificate

use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.

the class CertificationWebService method getCertificate.

/**
 * Return the certificate as PDF file.
 *
 * @response.representation.200.mediaType application/pdf
 * @response.representation.200.doc The certificate as file
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The owner or the certificate cannot be found
 * @param identityKey The owner of the certificate
 * @param resourceKey The primary key of the resource of the repository entry of the course.
 * @param request The request
 * @return The certificate
 */
@GET
@Path("{identityKey}")
@Produces({ "application/pdf" })
public Response getCertificate(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
    BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity identity = baseSecurity.loadIdentityByKey(identityKey);
    if (identity == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    Certificate certificate = certificatesManager.getLastCertificate(identity, resourceKey);
    if (certificate == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(certificate);
    if (certificateFile == null || !certificateFile.exists()) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    return Response.ok(certificateFile.getInputStream()).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CertificatesManager(org.olat.course.certificate.CertificatesManager) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Certificate(org.olat.course.certificate.Certificate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 34 with Certificate

use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.

the class CertificationWebService method putCertificate.

/**
 * Generate a new certificate.
 *
 * @response.representation.200.doc If the certificate was created
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The identity or the resource cannot be found
 * @response.representation.500.doc An unexpected error happened during the creation of the certificate
 * @param identityKey The owner of the certificate
 * @param resourceKey The primary key of the resource of the repository entry of the course.
 * @param score The score which appears in the certificate
 * @param passed The passed/failed which appears in the certificate (true/false)
 * @param creationDate The date of the certification
 * @param request The request
 * @return Nothing special
 */
@PUT
@Path("{identityKey}")
public Response putCertificate(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @QueryParam("score") Float score, @QueryParam("passed") Boolean passed, @QueryParam("creationDate") String creationDate, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
    Identity assessedIdentity = baseSecurity.loadIdentityByKey(identityKey);
    if (assessedIdentity == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
    OLATResource resource = resourceManager.findResourceById(resourceKey);
    if (resource == null) {
        resource = resourceManager.findResourceable(resourceKey, "CourseModule");
    }
    if (resource == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    } else {
        CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
        ICourse course = CourseFactory.loadCourse(resource);
        RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        CertificateTemplate template = null;
        Long templateId = course.getCourseConfig().getCertificateTemplate();
        if (templateId != null) {
            template = certificatesManager.getTemplateById(templateId);
        }
        CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
        if (StringHelper.containsNonWhitespace(creationDate)) {
            Date date = ObjectFactory.parseDate(creationDate);
            certificateInfos.setCreationDate(date);
        }
        Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, template, false);
        if (certificate != null) {
            return Response.ok().build();
        }
        return Response.serverError().status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) CertificatesManager(org.olat.course.certificate.CertificatesManager) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Date(java.util.Date) BaseSecurity(org.olat.basesecurity.BaseSecurity) Certificate(org.olat.course.certificate.Certificate) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 35 with Certificate

use of org.olat.course.certificate.Certificate in project OpenOLAT by OpenOLAT.

the class IdentityCertificatesController method loadList.

private void loadList() {
    List<Certificate> certificates = certificatesManager.getCertificates(assessedIdentity, courseEntry.getOlatResource());
    List<Links> certificatesLink = new ArrayList<>(certificates.size());
    int count = 0;
    Date now = new Date();
    for (Certificate certificate : certificates) {
        String displayName = formatter.formatDateAndTime(certificate.getCreationDate());
        String url = DownloadCertificateCellRenderer.getUrl(certificate);
        boolean needRecertification = false;
        if (certificate.getNextRecertificationDate() != null && certificate.getNextRecertificationDate().compareTo(now) < 0) {
            // only check the last one???
            needRecertification = true;
        }
        Links links = new Links(url, displayName, certificate.getStatus().name(), needRecertification);
        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);
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) Link(org.olat.core.gui.components.link.Link) Certificate(org.olat.course.certificate.Certificate)

Aggregations

Certificate (org.olat.course.certificate.Certificate)54 Identity (org.olat.core.id.Identity)42 Test (org.junit.Test)30 RepositoryEntry (org.olat.repository.RepositoryEntry)30 Date (java.util.Date)20 CertificateInfos (org.olat.course.certificate.model.CertificateInfos)18 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)16 File (java.io.File)14 Calendar (java.util.Calendar)14 URI (java.net.URI)12 URL (java.net.URL)12 HttpResponse (org.apache.http.HttpResponse)12 Path (javax.ws.rs.Path)8 BaseSecurity (org.olat.basesecurity.BaseSecurity)8 CertificatesManager (org.olat.course.certificate.CertificatesManager)8 IOException (java.io.IOException)6 Roles (org.olat.core.id.Roles)6 ICourse (org.olat.course.ICourse)6 OLATResource (org.olat.resource.OLATResource)6 OLATResourceManager (org.olat.resource.OLATResourceManager)6