Search in sources :

Example 1 with CertificatesManager

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

use of org.olat.course.certificate.CertificatesManager 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)

Example 3 with CertificatesManager

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

the class UserCourseEnvironmentImpl method hasEfficiencyStatementOrCertificate.

@Override
public boolean hasEfficiencyStatementOrCertificate(boolean update) {
    if (certification == null || update) {
        EfficiencyStatementManager efficiencyStatementManager = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
        boolean hasStatement = efficiencyStatementManager.hasUserEfficiencyStatement(getCourseRepositoryEntry().getKey(), identityEnvironment.getIdentity());
        if (hasStatement) {
            certification = Boolean.TRUE;
        } else {
            CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
            certification = certificatesManager.hasCertificate(identityEnvironment.getIdentity(), getCourseRepositoryEntry().getOlatResource().getKey());
        }
    }
    return certification.booleanValue();
}
Also used : EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) CertificatesManager(org.olat.course.certificate.CertificatesManager)

Example 4 with CertificatesManager

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

the class NewCachePersistingAssessmentManager method saveScoreEvaluation.

/**
 * @see org.olat.course.assessment.AssessmentManager#saveScoreEvaluation(org.olat.course.nodes.CourseNode, org.olat.core.id.Identity, org.olat.core.id.Identity, org.olat.course.run.scoring.ScoreEvaluation)
 */
public void saveScoreEvaluation(final CourseNode courseNode, final Identity identity, final Identity assessedIdentity, final ScoreEvaluation scoreEvaluation, final UserCourseEnvironment userCourseEnv, final boolean incrementUserAttempts) {
    final ICourse course = CourseFactory.loadCourse(ores);
    final CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    final RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    // o_clusterREVIEW we could sync on a element finer than course, e.g. the composite course+assessIdentity.
    // +: concurrency would be higher
    // -: many entries (num of courses * visitors of given course) in the locktable.
    // we could also sync on the assessedIdentity.
    Long attempts = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(createOLATResourceableForLocking(assessedIdentity), new SyncerCallback<Long>() {

        public Long execute() {
            Long attempts = null;
            Float score = scoreEvaluation.getScore();
            Boolean passed = scoreEvaluation.getPassed();
            saveNodeScore(courseNode, assessedIdentity, score, cpm);
            saveNodePassed(courseNode, assessedIdentity, passed, cpm);
            saveAssessmentID(courseNode, assessedIdentity, scoreEvaluation.getAssessmentID(), cpm);
            if (incrementUserAttempts) {
                attempts = incrementNodeAttemptsProperty(courseNode, assessedIdentity, cpm);
            }
            if (courseNode instanceof AssessableCourseNode) {
                userCourseEnv.getScoreAccounting().evaluateAll();
                // Update users efficiency statement
                EfficiencyStatementManager esm = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
                esm.updateUserEfficiencyStatement(userCourseEnv);
            }
            if (passed != null && passed.booleanValue() && course.getCourseConfig().isAutomaticCertificationEnabled()) {
                CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
                if (certificatesManager.isCertificationAllowed(assessedIdentity, courseEntry)) {
                    CertificateTemplate template = null;
                    Long templateId = course.getCourseConfig().getCertificateTemplate();
                    if (templateId != null) {
                        template = certificatesManager.getTemplateById(templateId);
                    }
                    CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
                    certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
                }
            }
            return attempts;
        }
    });
    // node log
    UserNodeAuditManager am = course.getCourseEnvironment().getAuditManager();
    am.appendToUserNodeLog(courseNode, identity, assessedIdentity, SCORE + " set to: " + String.valueOf(scoreEvaluation.getScore()));
    if (scoreEvaluation.getPassed() != null) {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, PASSED + " set to: " + scoreEvaluation.getPassed().toString());
    } else {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, PASSED + " set to \"undefined\"");
    }
    if (scoreEvaluation.getAssessmentID() != null) {
        am.appendToUserNodeLog(courseNode, assessedIdentity, assessedIdentity, ASSESSMENT_ID + " set to: " + scoreEvaluation.getAssessmentID().toString());
    }
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_SCORE_EVAL_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    // user activity logging
    if (scoreEvaluation.getScore() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_SCORE_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiScore, "", String.valueOf(scoreEvaluation.getScore())));
    }
    if (scoreEvaluation.getPassed() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", String.valueOf(scoreEvaluation.getPassed())));
    } else {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", "undefined"));
    }
    if (incrementUserAttempts && attempts != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_ATTEMPTS_UPDATED, getClass(), LoggingResourceable.wrap(identity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiAttempts, "", String.valueOf(attempts)));
    }
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) CertificatesManager(org.olat.course.certificate.CertificatesManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 5 with CertificatesManager

use of org.olat.course.certificate.CertificatesManager in project openolat by klemens.

the class NewCachePersistingAssessmentManager method saveScoreEvaluation.

/**
 * @see org.olat.course.assessment.AssessmentManager#saveScoreEvaluation(org.olat.course.nodes.CourseNode, org.olat.core.id.Identity, org.olat.core.id.Identity, org.olat.course.run.scoring.ScoreEvaluation)
 */
public void saveScoreEvaluation(final CourseNode courseNode, final Identity identity, final Identity assessedIdentity, final ScoreEvaluation scoreEvaluation, final UserCourseEnvironment userCourseEnv, final boolean incrementUserAttempts) {
    final ICourse course = CourseFactory.loadCourse(ores);
    final CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    final RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    // o_clusterREVIEW we could sync on a element finer than course, e.g. the composite course+assessIdentity.
    // +: concurrency would be higher
    // -: many entries (num of courses * visitors of given course) in the locktable.
    // we could also sync on the assessedIdentity.
    Long attempts = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(createOLATResourceableForLocking(assessedIdentity), new SyncerCallback<Long>() {

        public Long execute() {
            Long attempts = null;
            Float score = scoreEvaluation.getScore();
            Boolean passed = scoreEvaluation.getPassed();
            saveNodeScore(courseNode, assessedIdentity, score, cpm);
            saveNodePassed(courseNode, assessedIdentity, passed, cpm);
            saveAssessmentID(courseNode, assessedIdentity, scoreEvaluation.getAssessmentID(), cpm);
            if (incrementUserAttempts) {
                attempts = incrementNodeAttemptsProperty(courseNode, assessedIdentity, cpm);
            }
            if (courseNode instanceof AssessableCourseNode) {
                userCourseEnv.getScoreAccounting().evaluateAll();
                // Update users efficiency statement
                EfficiencyStatementManager esm = CoreSpringFactory.getImpl(EfficiencyStatementManager.class);
                esm.updateUserEfficiencyStatement(userCourseEnv);
            }
            if (passed != null && passed.booleanValue() && course.getCourseConfig().isAutomaticCertificationEnabled()) {
                CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
                if (certificatesManager.isCertificationAllowed(assessedIdentity, courseEntry)) {
                    CertificateTemplate template = null;
                    Long templateId = course.getCourseConfig().getCertificateTemplate();
                    if (templateId != null) {
                        template = certificatesManager.getTemplateById(templateId);
                    }
                    CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
                    certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
                }
            }
            return attempts;
        }
    });
    // node log
    UserNodeAuditManager am = course.getCourseEnvironment().getAuditManager();
    am.appendToUserNodeLog(courseNode, identity, assessedIdentity, SCORE + " set to: " + String.valueOf(scoreEvaluation.getScore()));
    if (scoreEvaluation.getPassed() != null) {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, PASSED + " set to: " + scoreEvaluation.getPassed().toString());
    } else {
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, PASSED + " set to \"undefined\"");
    }
    if (scoreEvaluation.getAssessmentID() != null) {
        am.appendToUserNodeLog(courseNode, assessedIdentity, assessedIdentity, ASSESSMENT_ID + " set to: " + scoreEvaluation.getAssessmentID().toString());
    }
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_SCORE_EVAL_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
    // user activity logging
    if (scoreEvaluation.getScore() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_SCORE_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiScore, "", String.valueOf(scoreEvaluation.getScore())));
    }
    if (scoreEvaluation.getPassed() != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", String.valueOf(scoreEvaluation.getPassed())));
    } else {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_PASSED_UPDATED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiPassed, "", "undefined"));
    }
    if (incrementUserAttempts && attempts != null) {
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_ATTEMPTS_UPDATED, getClass(), LoggingResourceable.wrap(identity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.qtiAttempts, "", String.valueOf(attempts)));
    }
}
Also used : CertificateTemplate(org.olat.course.certificate.CertificateTemplate) EfficiencyStatementManager(org.olat.course.assessment.manager.EfficiencyStatementManager) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) CertificatesManager(org.olat.course.certificate.CertificatesManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Aggregations

CertificatesManager (org.olat.course.certificate.CertificatesManager)14 Path (javax.ws.rs.Path)10 BaseSecurity (org.olat.basesecurity.BaseSecurity)10 Identity (org.olat.core.id.Identity)10 Certificate (org.olat.course.certificate.Certificate)8 OLATResource (org.olat.resource.OLATResource)8 OLATResourceManager (org.olat.resource.OLATResourceManager)8 Date (java.util.Date)4 Produces (javax.ws.rs.Produces)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 ICourse (org.olat.course.ICourse)4 EfficiencyStatementManager (org.olat.course.assessment.manager.EfficiencyStatementManager)4 CertificateTemplate (org.olat.course.certificate.CertificateTemplate)4 CertificateInfos (org.olat.course.certificate.model.CertificateInfos)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 File (java.io.File)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2