use of org.olat.course.certificate.model.CertificateInfos 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.model.CertificateInfos 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.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificatesSelectionController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
;
int colPos = 0;
if (isAdministrativeUser) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.name", CertificatesSelectionDataModel.USERNAME_COL));
}
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(AssessedIdentitiesTableDataModel.usageIdentifyer, isAdministrativeUser);
List<UserPropertyHandler> resultingPropertyHandlers = new ArrayList<UserPropertyHandler>();
// followed by the users fields
for (int i = 0; i < userPropertyHandlers.size(); i++) {
UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
boolean visible = userManager.isMandatoryUserProperty(AssessedIdentitiesTableDataModel.usageIdentifyer, userPropertyHandler);
resultingPropertyHandlers.add(userPropertyHandler);
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos++, false, null));
}
if (hasAssessableNodes) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.passed", CertificatesSelectionDataModel.PASSED_COL, new PassedCellRenderer()));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.score", CertificatesSelectionDataModel.SCORE_COL));
}
tableModel = new CertificatesSelectionDataModel(columnsModel, resultingPropertyHandlers);
Set<Integer> preselectedRows = new HashSet<>();
ICourse course = CourseFactory.loadCourse(courseEntry);
CourseNode rootNode = course.getRunStructure().getRootNode();
List<CertificateInfos> infos = new ArrayList<>(datas.size());
int count = 0;
for (AssessedIdentityWrapper data : datas) {
ScoreEvaluation scoreEval = data.getUserCourseEnvironment().getScoreAccounting().getScoreEvaluation(rootNode);
Float score = scoreEval == null ? null : scoreEval.getScore();
Boolean passed = scoreEval == null ? null : scoreEval.getPassed();
Identity assessedIdentity = data.getIdentity();
infos.add(new CertificateInfos(assessedIdentity, score, passed));
if (passed != null && passed.booleanValue()) {
preselectedRows.add(new Integer(count));
}
count++;
}
tableModel.setObjects(infos);
tableEl = uifactory.addTableElement(getWindowControl(), "selection", tableModel, getTranslator(), formLayout);
tableEl.setMultiSelect(true);
tableEl.setSelectAllEnable(true);
tableEl.setMultiSelectedIndex(preselectedRows);
}
use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificatesManagerTest method loadCertificate.
@Test
public void loadCertificate() {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
dbInstance.commitAndCloseSession();
CertificateInfos certificateInfos = new CertificateInfos(identity, 5.0f, Boolean.TRUE);
Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
Assert.assertNotNull(certificate);
dbInstance.commitAndCloseSession();
// full
Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
Assert.assertNotNull(reloadedCertificate);
Assert.assertEquals(certificate, reloadedCertificate);
Assert.assertNotNull(reloadedCertificate.getUuid());
Assert.assertEquals(certificate.getUuid(), reloadedCertificate.getUuid());
Assert.assertEquals(entry.getDisplayname(), reloadedCertificate.getCourseTitle());
Assert.assertEquals(identity, reloadedCertificate.getIdentity());
// light
CertificateLight reloadedLight = certificatesManager.getCertificateLightById(certificate.getKey());
Assert.assertNotNull(reloadedLight);
Assert.assertEquals(certificate.getKey(), reloadedLight.getKey());
Assert.assertEquals(entry.getDisplayname(), reloadedLight.getCourseTitle());
Assert.assertEquals(identity.getKey(), reloadedLight.getIdentityKey());
Assert.assertEquals(entry.getOlatResource().getKey(), reloadedLight.getOlatResourceKey());
// uuid
Certificate reloadedUuid = certificatesManager.getCertificateByUuid(certificate.getUuid());
Assert.assertNotNull(reloadedUuid);
Assert.assertEquals(certificate, reloadedUuid);
Assert.assertEquals(entry.getDisplayname(), reloadedUuid.getCourseTitle());
Assert.assertEquals(identity, reloadedUuid.getIdentity());
// boolean
boolean has = certificatesManager.hasCertificate(identity, entry.getOlatResource().getKey());
Assert.assertTrue(has);
}
use of org.olat.course.certificate.model.CertificateInfos in project OpenOLAT by OpenOLAT.
the class CertificatesManagerTest method loadLastCertificate.
@Test
public void loadLastCertificate() {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-1");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
dbInstance.commitAndCloseSession();
CertificateInfos certificateInfos = new CertificateInfos(identity, 5.0f, Boolean.TRUE);
Certificate certificate = certificatesManager.generateCertificate(certificateInfos, entry, null, false);
Assert.assertNotNull(certificate);
dbInstance.commitAndCloseSession();
// per resource
Certificate reloadedCertificate = certificatesManager.getLastCertificate(identity, entry.getOlatResource().getKey());
Assert.assertNotNull(reloadedCertificate);
Assert.assertEquals(certificate, reloadedCertificate);
// all
List<CertificateLight> allCertificates = certificatesManager.getLastCertificates(identity);
Assert.assertNotNull(allCertificates);
Assert.assertEquals(1, allCertificates.size());
CertificateLight allCertificate = allCertificates.get(0);
Assert.assertEquals(certificate.getKey(), allCertificate.getKey());
Assert.assertEquals(entry.getDisplayname(), allCertificate.getCourseTitle());
Assert.assertEquals(identity.getKey(), allCertificate.getIdentityKey());
Assert.assertEquals(entry.getOlatResource().getKey(), allCertificate.getOlatResourceKey());
}
Aggregations