use of org.olat.course.certificate.CertificateTemplate 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)));
}
}
use of org.olat.course.certificate.CertificateTemplate in project OpenOLAT by OpenOLAT.
the class CourseAssessmentManagerImpl method saveScoreEvaluation.
@Override
public void saveScoreEvaluation(AssessableCourseNode courseNode, Identity identity, Identity assessedIdentity, ScoreEvaluation scoreEvaluation, UserCourseEnvironment userCourseEnv, boolean incrementUserAttempts, Role by) {
final ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
final CourseEnvironment courseEnv = userCourseEnv.getCourseEnvironment();
Float score = scoreEvaluation.getScore();
Boolean passed = scoreEvaluation.getPassed();
Long assessmentId = scoreEvaluation.getAssessmentID();
String subIdent = courseNode.getIdent();
RepositoryEntry referenceEntry = courseNode.getReferencedRepositoryEntry();
AssessmentEntry assessmentEntry = getOrCreate(assessedIdentity, subIdent, referenceEntry);
if (referenceEntry != null && !referenceEntry.equals(assessmentEntry.getReferenceEntry())) {
assessmentEntry.setReferenceEntry(referenceEntry);
}
if (by == Role.coach) {
assessmentEntry.setLastCoachModified(new Date());
} else if (by == Role.user) {
assessmentEntry.setLastUserModified(new Date());
}
if (score == null) {
assessmentEntry.setScore(null);
} else {
assessmentEntry.setScore(new BigDecimal(Float.toString(score)));
}
assessmentEntry.setPassed(passed);
assessmentEntry.setFullyAssessed(scoreEvaluation.getFullyAssessed());
if (assessmentId != null) {
assessmentEntry.setAssessmentId(assessmentId);
}
if (scoreEvaluation.getAssessmentStatus() != null) {
assessmentEntry.setAssessmentStatus(scoreEvaluation.getAssessmentStatus());
}
if (scoreEvaluation.getUserVisible() != null) {
assessmentEntry.setUserVisibility(scoreEvaluation.getUserVisible());
}
if (scoreEvaluation.getCurrentRunCompletion() != null) {
assessmentEntry.setCurrentRunCompletion(scoreEvaluation.getCurrentRunCompletion());
}
if (scoreEvaluation.getCurrentRunStatus() != null) {
assessmentEntry.setCurrentRunStatus(scoreEvaluation.getCurrentRunStatus());
}
Integer attempts = null;
if (incrementUserAttempts) {
attempts = assessmentEntry.getAttempts() == null ? 1 : assessmentEntry.getAttempts().intValue() + 1;
assessmentEntry.setAttempts(attempts);
}
assessmentEntry = assessmentService.updateAssessmentEntry(assessmentEntry);
// commit before sending events
DBFactory.getInstance().commit();
// reevalute the tree
ScoreAccounting scoreAccounting = userCourseEnv.getScoreAccounting();
scoreAccounting.evaluateAll(true);
// commit before sending events
DBFactory.getInstance().commit();
// node log
UserNodeAuditManager am = courseEnv.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, "assessmentId 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)));
}
// write only when enabled for this course
if (courseEnv.getCourseConfig().isEfficencyStatementEnabled()) {
List<AssessmentNodeData> data = new ArrayList<AssessmentNodeData>(50);
AssessmentNodesLastModified lastModifications = new AssessmentNodesLastModified();
AssessmentHelper.getAssessmentNodeDataList(0, courseEnv.getRunStructure().getRootNode(), scoreAccounting, userCourseEnv, true, true, true, data, lastModifications);
efficiencyStatementManager.updateUserEfficiencyStatement(assessedIdentity, courseEnv, data, lastModifications, cgm.getCourseEntry());
}
if (course.getCourseConfig().isAutomaticCertificationEnabled()) {
CourseNode rootNode = courseEnv.getRunStructure().getRootNode();
ScoreEvaluation rootEval = scoreAccounting.evalCourseNode((AssessableCourseNode) rootNode);
if (rootEval != null && rootEval.getPassed() != null && rootEval.getPassed().booleanValue() && certificatesManager.isCertificationAllowed(assessedIdentity, cgm.getCourseEntry())) {
CertificateTemplate template = null;
Long templateId = course.getCourseConfig().getCertificateTemplate();
if (templateId != null) {
template = certificatesManager.getTemplateById(templateId);
}
CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, rootEval.getScore(), rootEval.getPassed());
certificatesManager.generateCertificate(certificateInfos, cgm.getCourseEntry(), template, true);
}
}
}
use of org.olat.course.certificate.CertificateTemplate in project OpenOLAT by OpenOLAT.
the class AssessedIdentityCertificatesController method doGenerateCertificate.
private void doGenerateCertificate(UserRequest ureq) {
ICourse course = CourseFactory.loadCourse(resource);
CourseNode rootNode = course.getRunStructure().getRootNode();
Identity assessedIdentity = assessedUserCourseEnv.getIdentityEnvironment().getIdentity();
ScoreEvaluation scoreEval = assessedUserCourseEnv.getScoreAccounting().getScoreEvaluation(rootNode);
RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
CertificateTemplate template = null;
Long templateKey = course.getCourseConfig().getCertificateTemplate();
if (templateKey != null) {
template = certificatesManager.getTemplateById(templateKey);
}
Float score = scoreEval == null ? null : scoreEval.getScore();
Boolean passed = scoreEval == null ? null : scoreEval.getPassed();
CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
loadList();
showInfo("msg.certificate.pending");
fireEvent(ureq, Event.CHANGED_EVENT);
}
use of org.olat.course.certificate.CertificateTemplate in project OpenOLAT by OpenOLAT.
the class CertificatesManagerImpl method doCertificate.
private void doCertificate(JmsCertificateWork workUnit) {
CertificateImpl certificate = getCertificateById(workUnit.getCertificateKey());
CertificateTemplate template = null;
if (workUnit.getTemplateKey() != null) {
template = getTemplateById(workUnit.getTemplateKey());
}
OLATResource resource = certificate.getOlatResource();
Identity identity = certificate.getIdentity();
RepositoryEntry entry = repositoryService.loadByResourceKey(resource.getKey());
String dir = usersStorage.generateDir();
File dirFile = new File(getCertificateRoot(), dir);
dirFile.mkdirs();
Float score = workUnit.getScore();
String lang = identity.getUser().getPreferences().getLanguage();
Locale locale = i18nManager.getLocaleOrDefault(lang);
Boolean passed = workUnit.getPassed();
Date dateCertification = certificate.getCreationDate();
Date dateFirstCertification = getDateFirstCertification(identity, resource.getKey());
Date dateNextRecertification = certificate.getNextRecertificationDate();
File certificateFile;
// File name with user name
StringBuilder sb = new StringBuilder();
sb.append(identity.getUser().getProperty(UserConstants.LASTNAME, locale)).append("_").append(identity.getUser().getProperty(UserConstants.FIRSTNAME, locale)).append("_").append(entry.getDisplayname()).append("_").append(Formatter.formatShortDateFilesystem(dateCertification));
String filename = FileUtils.normalizeFilename(sb.toString()) + ".pdf";
// External URL to certificate as short as possible for QR-Code
sb = new StringBuilder();
sb.append(Settings.getServerContextPathURI()).append("/certificate/").append(certificate.getUuid()).append("/certificate.pdf");
String certUrl = sb.toString();
if (template == null || template.getPath().toLowerCase().endsWith("pdf")) {
CertificatePDFFormWorker worker = new CertificatePDFFormWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
certificateFile = worker.fill(template, dirFile, filename);
if (certificateFile == null) {
certificate.setStatus(CertificateStatus.error);
} else {
certificate.setStatus(CertificateStatus.ok);
}
} else {
CertificatePhantomWorker worker = new CertificatePhantomWorker(identity, entry, score, passed, dateCertification, dateFirstCertification, dateNextRecertification, certUrl, locale, userManager, this);
certificateFile = worker.fill(template, dirFile, filename);
if (certificateFile == null) {
certificate.setStatus(CertificateStatus.error);
} else {
certificate.setStatus(CertificateStatus.ok);
}
}
certificate.setPath(dir + certificateFile.getName());
if (dateFirstCertification != null) {
// not the first certification, reset the last of the others certificates
removeLastFlag(identity, resource.getKey());
}
MailerResult result = sendCertificate(identity, entry, certificateFile);
if (result.isSuccessful()) {
certificate.setEmailStatus(EmailStatus.ok);
} else {
certificate.setEmailStatus(EmailStatus.error);
}
dbInstance.getCurrentEntityManager().merge(certificate);
dbInstance.commit();
CertificateEvent event = new CertificateEvent(identity.getKey(), certificate.getKey(), resource.getKey());
coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(event, ORES_CERTIFICATE_EVENT);
}
use of org.olat.course.certificate.CertificateTemplate in project OpenOLAT by OpenOLAT.
the class CertificatesManagerImpl method deleteTemplate.
@Override
public void deleteTemplate(CertificateTemplate template) {
File templateFile = getTemplateFile(template);
if (templateFile != null && templateFile.getParent() != null && templateFile.getParentFile().exists()) {
try {
FileUtils.deleteDirsAndFiles(templateFile.getParentFile().toPath());
} catch (IOException e) {
log.error("", e);
}
}
// delete in db
CertificateTemplate reloadedTemplate = dbInstance.getCurrentEntityManager().getReference(CertificateTemplateImpl.class, template.getKey());
dbInstance.getCurrentEntityManager().remove(reloadedTemplate);
}
Aggregations