Search in sources :

Example 31 with OLATResourceManager

use of org.olat.resource.OLATResourceManager in project openolat by klemens.

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 32 with OLATResourceManager

use of org.olat.resource.OLATResourceManager in project openolat by klemens.

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)

Aggregations

OLATResourceManager (org.olat.resource.OLATResourceManager)32 OLATResource (org.olat.resource.OLATResource)30 OLATResourceable (org.olat.core.id.OLATResourceable)14 Identity (org.olat.core.id.Identity)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 Path (javax.ws.rs.Path)10 BaseSecurity (org.olat.basesecurity.BaseSecurity)10 CertificatesManager (org.olat.course.certificate.CertificatesManager)8 Date (java.util.Date)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 Certificate (org.olat.course.certificate.Certificate)6 File (java.io.File)4 IOException (java.io.IOException)4 Consumes (javax.ws.rs.Consumes)4 PUT (javax.ws.rs.PUT)4 Produces (javax.ws.rs.Produces)4 Before (org.junit.Before)4 CollaborationTools (org.olat.collaboration.CollaborationTools)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 Forum (org.olat.modules.fo.Forum)4