Search in sources :

Example 1 with Certificate

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

the class AssessedIdentityCertificatesController method loadList.

private void loadList() {
    Identity assessedIdentity = assessedUserCourseEnv.getIdentityEnvironment().getIdentity();
    List<Certificate> certificates = certificatesManager.getCertificates(assessedIdentity, resource);
    List<Links> certificatesLink = new ArrayList<>(certificates.size());
    int count = 0;
    for (Certificate certificate : certificates) {
        String displayName = formatter.formatDateAndTime(certificate.getCreationDate());
        String url = DownloadCertificateCellRenderer.getUrl(certificate);
        Links links = new Links(url, displayName, certificate.getStatus().name());
        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) Identity(org.olat.core.id.Identity) Link(org.olat.core.gui.components.link.Link) Certificate(org.olat.course.certificate.Certificate)

Example 2 with Certificate

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

the class CertificatesManagerImpl method getCertificatesForNotifications.

@Override
public List<Certificate> getCertificatesForNotifications(Identity identity, RepositoryEntry entry, Date lastNews) {
    Roles roles = securityManager.getRoles(identity);
    RepositoryEntrySecurity security = repositoryManager.isAllowed(identity, roles, entry);
    if (!security.isEntryAdmin() && !security.isCourseCoach() && !security.isGroupCoach() && !security.isCourseParticipant() && !security.isGroupParticipant()) {
        return Collections.emptyList();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select cer from certificate cer").append(" inner join fetch cer.identity ident").append(" where cer.olatResource.key=:resourceKey and cer.last=true ");
    // must be some kind of restrictions
    boolean securityCheck = false;
    List<Long> baseGroupKeys = null;
    if (!security.isEntryAdmin()) {
        sb.append(" and (");
        boolean or = false;
        if (security.isCourseCoach()) {
            or = or(sb, or);
            sb.append(" exists (select membership.identity.key from repoentrytogroup as rel, bgroup as reBaseGroup, bgroupmember membership ").append("   where ident.key=membership.identity.key and rel.entry.key=:repoKey and rel.group=reBaseGroup and membership.group=reBaseGroup and membership.role='").append(GroupRole.participant).append("'").append(" )");
            securityCheck = true;
        }
        if (security.isGroupCoach()) {
            SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
            List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, entry, 0, -1);
            if (groups.size() > 0) {
                or = or(sb, or);
                sb.append(" exists (select membership.identity.key from bgroupmember membership ").append("   where ident.key=membership.identity.key and membership.group.key in (:groups) and membership.role='").append(GroupRole.participant).append("'").append(" )");
                baseGroupKeys = new ArrayList<>(groups.size());
                for (BusinessGroup group : groups) {
                    baseGroupKeys.add(group.getBaseGroup().getKey());
                }
                securityCheck = true;
            }
        }
        if (security.isCourseParticipant() || security.isGroupParticipant()) {
            or = or(sb, or);
            sb.append(" ident.key=:identityKey");
            securityCheck = true;
        }
        sb.append(")");
    } else {
        securityCheck = true;
    }
    if (!securityCheck) {
        return Collections.emptyList();
    }
    sb.append(" order by cer.creationDate");
    TypedQuery<Certificate> certificates = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Certificate.class).setParameter("resourceKey", entry.getOlatResource().getKey());
    if (!security.isEntryAdmin()) {
        if (security.isCourseCoach()) {
            certificates.setParameter("repoKey", entry.getKey());
        }
        if (security.isCourseParticipant() || security.isGroupParticipant()) {
            certificates.setParameter("identityKey", identity.getKey());
        }
    }
    if (baseGroupKeys != null && !baseGroupKeys.isEmpty()) {
        certificates.setParameter("groups", baseGroupKeys);
    }
    return certificates.getResultList();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) Roles(org.olat.core.id.Roles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Certificate(org.olat.course.certificate.Certificate)

Example 3 with Certificate

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

the class CertificatesManagerImpl method isCertificationAllowed.

@Override
public boolean isCertificationAllowed(Identity identity, RepositoryEntry entry) {
    boolean allowed = false;
    try {
        ICourse course = CourseFactory.loadCourse(entry);
        CourseConfig config = course.getCourseEnvironment().getCourseConfig();
        if (config.isRecertificationEnabled()) {
            Certificate certificate = getLastCertificate(identity, entry.getOlatResource().getKey());
            if (certificate == null) {
                allowed = true;
            } else {
                Calendar cal = Calendar.getInstance();
                Date now = cal.getTime();
                Date nextCertificationDate = getDateNextRecertification(certificate, config);
                allowed = (nextCertificationDate != null ? nextCertificationDate.before(now) : false);
            }
        } else {
            allowed = !hasCertificate(identity, entry.getOlatResource().getKey());
        }
    } catch (CorruptedCourseException e) {
        log.error("", e);
    }
    return allowed;
}
Also used : CorruptedCourseException(org.olat.course.CorruptedCourseException) Calendar(java.util.Calendar) ICourse(org.olat.course.ICourse) Date(java.util.Date) CourseConfig(org.olat.course.config.CourseConfig) Certificate(org.olat.course.certificate.Certificate)

Example 4 with Certificate

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

the class CertificationWebService method deleteCertificateInfo.

@DELETE
@Path("{identityKey}")
public Response deleteCertificateInfo(@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();
    }
    OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", resourceKey);
    OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
    OLATResource resource = resourceManager.findResourceable(courseOres);
    if (resource == null) {
        resource = resourceManager.findResourceById(resourceKey);
    }
    if (resource == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    Certificate certificate = certificatesManager.getLastCertificate(identity, resource.getKey());
    if (certificate == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    certificatesManager.deleteCertificate(certificate);
    return Response.ok().build();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) CertificatesManager(org.olat.course.certificate.CertificatesManager) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Certificate(org.olat.course.certificate.Certificate) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 5 with Certificate

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

the class CertificationWebService method getCertificateInfo.

@HEAD
@Path("{identityKey}")
@Produces({ "application/pdf" })
public Response getCertificateInfo(@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();
    }
    OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", resourceKey);
    OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
    OLATResource resource = resourceManager.findResourceable(courseOres);
    if (resource == null) {
        resource = resourceManager.findResourceById(resourceKey);
    }
    if (resource == null) {
        return Response.serverError().status(Response.Status.NOT_FOUND).build();
    }
    Certificate certificate = certificatesManager.getLastCertificate(identity, resource.getKey());
    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().build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATResourceable(org.olat.core.id.OLATResourceable) CertificatesManager(org.olat.course.certificate.CertificatesManager) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Certificate(org.olat.course.certificate.Certificate) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) Produces(javax.ws.rs.Produces)

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