use of org.olat.core.id.Identity 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.core.id.Identity 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);
}
use of org.olat.core.id.Identity 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.core.id.Identity in project OpenOLAT by OpenOLAT.
the class IdentityListCourseNodeController method doSetVisibility.
private void doSetVisibility(UserRequest ureq, Boolean visibility, List<AssessedIdentityElementRow> rows) {
ICourse course = CourseFactory.loadCourse(courseEntry);
AssessableCourseNode assessableCourseNode = (AssessableCourseNode) courseNode;
for (AssessedIdentityElementRow row : rows) {
Identity assessedIdentity = securityManager.loadIdentityByKey(row.getIdentityKey());
Roles roles = securityManager.getRoles(assessedIdentity);
IdentityEnvironment identityEnv = new IdentityEnvironment(assessedIdentity, roles);
UserCourseEnvironment assessedUserCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment(), coachCourseEnv.isCourseReadOnly());
assessedUserCourseEnv.getScoreAccounting().evaluateAll();
ScoreEvaluation scoreEval = assessableCourseNode.getUserScoreEvaluation(assessedUserCourseEnv);
ScoreEvaluation doneEval = new ScoreEvaluation(scoreEval.getScore(), scoreEval.getPassed(), scoreEval.getAssessmentStatus(), visibility, scoreEval.getFullyAssessed(), scoreEval.getCurrentRunCompletion(), scoreEval.getCurrentRunStatus(), scoreEval.getAssessmentID());
assessableCourseNode.updateUserScoreEvaluation(doneEval, assessedUserCourseEnv, getIdentity(), false, Role.coach);
}
loadModel(ureq);
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class IdentityListCourseNodeController method doSelect.
private Controller doSelect(UserRequest ureq, AssessedIdentityElementRow row) {
removeAsListenerAndDispose(currentIdentityCtrl);
Identity assessedIdentity = securityManager.loadIdentityByKey(row.getIdentityKey());
String fullName = userManager.getUserDisplayName(assessedIdentity);
OLATResourceable ores = OresHelper.createOLATResourceableInstance("Identity", assessedIdentity.getKey());
WindowControl bwControl = addToHistory(ureq, ores, null);
if (courseNode.getParent() == null) {
currentIdentityCtrl = new AssessmentIdentityCourseController(ureq, bwControl, stackPanel, courseEntry, coachCourseEnv, assessedIdentity);
} else {
currentIdentityCtrl = new AssessmentIdentityCourseNodeController(ureq, getWindowControl(), stackPanel, courseEntry, courseNode, coachCourseEnv, assessedIdentity, true);
}
listenTo(currentIdentityCtrl);
stackPanel.pushController(fullName, currentIdentityCtrl);
previousLink = LinkFactory.createToolLink("previouselement", "", this, "o_icon_previous_toolbar");
previousLink.setTitle(translate("command.previous"));
stackPanel.addTool(previousLink, Align.rightEdge, false, "o_tool_previous");
nextLink = LinkFactory.createToolLink("nextelement", "", this, "o_icon_next_toolbar");
nextLink.setTitle(translate("command.next"));
stackPanel.addTool(nextLink, Align.rightEdge, false, "o_tool_next");
return currentIdentityCtrl;
}
Aggregations