Search in sources :

Example 31 with Identity

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);
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity)

Example 32 with Identity

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);
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Link(org.olat.core.gui.components.link.Link) Certificate(org.olat.course.certificate.Certificate)

Example 33 with Identity

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);
}
Also used : Locale(java.util.Locale) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) MailerResult(org.olat.core.util.mail.MailerResult) OLATResource(org.olat.resource.OLATResource) CertificateImpl(org.olat.course.certificate.model.CertificateImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) CertificateEvent(org.olat.course.certificate.CertificateEvent) Identity(org.olat.core.id.Identity) TransientIdentity(org.olat.admin.user.imp.TransientIdentity) File(java.io.File)

Example 34 with Identity

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);
}
Also used : CalculatedAssessableCourseNode(org.olat.course.nodes.CalculatedAssessableCourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) AssessedIdentityElementRow(org.olat.modules.assessment.ui.AssessedIdentityElementRow) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 35 with Identity

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;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) Identity(org.olat.core.id.Identity) WindowControl(org.olat.core.gui.control.WindowControl)

Aggregations

Identity (org.olat.core.id.Identity)3749 Test (org.junit.Test)1956 RepositoryEntry (org.olat.repository.RepositoryEntry)898 BusinessGroup (org.olat.group.BusinessGroup)560 ArrayList (java.util.ArrayList)550 Date (java.util.Date)312 URI (java.net.URI)272 ICourse (org.olat.course.ICourse)266 HttpResponse (org.apache.http.HttpResponse)260 File (java.io.File)211 AssessmentManager (org.olat.course.assessment.AssessmentManager)210 Path (javax.ws.rs.Path)182 OLATResource (org.olat.resource.OLATResource)172 OLATResourceable (org.olat.core.id.OLATResourceable)156 Roles (org.olat.core.id.Roles)154 HashMap (java.util.HashMap)151 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)142 HashSet (java.util.HashSet)136 List (java.util.List)132 Produces (javax.ws.rs.Produces)130