Search in sources :

Example 61 with UserManager

use of org.olat.user.UserManager in project openolat by klemens.

the class MailHelper method getMailFooter.

/**
 * Create a mail footer for the given locale and sender.
 *
 * @param locale Defines language of footer text. If null, the systems default
 *          locale is used
 * @param sender Details about sender embedded in mail footer. If null no such
 *          details are attached to the footer
 * @return The mail footer as string
 */
public static String getMailFooter(Locale locale, Identity sender) {
    if (locale == null) {
        locale = I18nModule.getDefaultLocale();
    }
    Translator trans = getTranslator(locale);
    if (sender == null) {
        // mail sent by plattform configured sender address
        return trans.translate("footer.no.userdata", new String[] { Settings.getServerContextPathURI() });
    }
    // mail sent by a system user
    User user = sender.getUser();
    // FXOLAT-356: separate context for mail footer
    // username / server-url are always first [0], [1].
    UserManager um = UserManager.getInstance();
    List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(MailHelper.class.getCanonicalName(), false);
    List<String> userPropList = new ArrayList<String>(userPropertyHandlers.size() + 2);
    String email = UserManager.getInstance().getUserDisplayEmail(sender, locale);
    userPropList.add(email);
    userPropList.add(Settings.getServerContextPathURI());
    for (Iterator<UserPropertyHandler> iterator = userPropertyHandlers.iterator(); iterator.hasNext(); ) {
        userPropList.add(iterator.next().getUserProperty(user, locale));
    }
    // add empty strings to prevent non-replaced wildcards like "{5}" etc. in emails.
    while (userPropList.size() < 15) {
        userPropList.add("");
    }
    String[] userPropArr = userPropList.toArray(new String[userPropList.size()]);
    for (int i = userPropArr.length; i-- > 0; ) {
        if (userPropArr[i] == null) {
            userPropArr[i] = "";
        }
    }
    return trans.translate("footer.with.userdata", userPropArr);
}
Also used : User(org.olat.core.id.User) Translator(org.olat.core.gui.translator.Translator) UserManager(org.olat.user.UserManager) ArrayList(java.util.ArrayList) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 62 with UserManager

use of org.olat.user.UserManager in project openolat by klemens.

the class BulkAssessmentTask method renderFeedback.

public static String renderFeedback(List<BulkAssessmentFeedback> feedbacks, Translator translator) {
    UserManager userManager = CoreSpringFactory.getImpl(UserManager.class);
    StringBuilder sb = new StringBuilder();
    for (BulkAssessmentFeedback feedback : feedbacks) {
        String errorKey = feedback.getErrorKey();
        String msg = translator.translate(errorKey);
        String assessedName;
        if (feedback.getAssessedIdentity() != null) {
            assessedName = userManager.getUserDisplayName(feedback.getAssessedIdentity());
        } else {
            assessedName = feedback.getAssessedId();
        }
        sb.append(assessedName).append(": ").append(msg).append("\n");
    }
    return sb.toString();
}
Also used : BulkAssessmentFeedback(org.olat.course.assessment.model.BulkAssessmentFeedback) UserManager(org.olat.user.UserManager)

Example 63 with UserManager

use of org.olat.user.UserManager in project openolat by klemens.

the class IQEditReplaceWizard method doStep2.

private void doStep2(UserRequest ureq) {
    String nodeTitle = courseNode.getShortTitle();
    if (results != null && !results.isEmpty()) {
        exportDir = CourseFactory.getOrCreateDataExportDirectory(ureq.getIdentity(), course.getCourseTitle());
        UserManager um = UserManager.getInstance();
        String charset = um.getUserCharset(ureq.getIdentity());
        QTIExportManager qem = QTIExportManager.getInstance();
        Long repositoryRef = results.get(0).getResultSet().getRepositoryRef();
        List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(repositoryRef);
        QTIExportFormatter formatter;
        if (courseNode instanceof IQTESTCourseNode) {
            formatter = new QTIExportFormatterCSVType1(ureq.getLocale(), "\t", "\"", "\r\n", false);
        } else if (courseNode instanceof IQSELFCourseNode) {
            formatter = new QTIExportFormatterCSVType1(ureq.getLocale(), "\t", "\"", "\r\n", false);
            ((QTIExportFormatterCSVType1) formatter).setAnonymous(true);
        } else {
            formatter = new QTIExportFormatterCSVType3(ureq.getLocale(), null, "\t", "\"", "\r\n", false);
        }
        Map<Class<?>, QTIExportItemFormatConfig> qtiItemConfigs = getQTIItemConfigs(qtiItemObjectList);
        formatter.setMapWithExportItemConfigs(qtiItemConfigs);
        resultExportFile = qem.exportResults(formatter, results, qtiItemObjectList, courseNode.getShortTitle(), exportDir, charset, ".xls");
        vcStep2 = createVelocityContainer("replacewizard_step2");
        String[] args1 = new String[] { Integer.toString(learners.size()) };
        vcStep2.contextPut("information", translate("replace.wizard.information.paragraph1", args1));
        String[] args2 = new String[] { exportDir.getName(), resultExportFile };
        vcStep2.contextPut("information_par2", translate("replace.wizard.information.paragraph2", args2));
        vcStep2.contextPut("nodetitle", nodeTitle);
        showFileButton = LinkFactory.createButton("replace.wizard.showfile", vcStep2, this);
    } else {
        // it exists no result
        String[] args = new String[] { Integer.toString(numberOfQtiSerEntries) };
        vcStep2 = createVelocityContainer("replacewizard_step2");
        vcStep2.contextPut("information", translate("replace.wizard.information.empty.results", args));
        vcStep2.contextPut("nodetitle", nodeTitle);
    }
    nextBtn = LinkFactory.createButton("replace.wizard.next", vcStep2, this);
    setNextWizardStep(translate("replace.wizard.title.step2"), vcStep2);
}
Also used : QTIExportFormatterCSVType1(org.olat.ims.qti.export.QTIExportFormatterCSVType1) QTIExportFormatterCSVType3(org.olat.ims.qti.export.QTIExportFormatterCSVType3) QTIExportFormatter(org.olat.ims.qti.export.QTIExportFormatter) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) UserManager(org.olat.user.UserManager) QTIExportManager(org.olat.ims.qti.export.QTIExportManager) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder) IQSELFCourseNode(org.olat.course.nodes.IQSELFCourseNode) QTIExportItemFormatConfig(org.olat.ims.qti.export.QTIExportItemFormatConfig)

Example 64 with UserManager

use of org.olat.user.UserManager in project openolat by klemens.

the class GTACourseNode method validateInternalConfiguration.

private List<StatusDescription> validateInternalConfiguration(CourseEditorEnv cev) {
    List<StatusDescription> sdList = new ArrayList<>(5);
    ModuleConfiguration config = getModuleConfiguration();
    boolean hasScoring = config.getBooleanSafe(GTASK_GRADING);
    if (hasScoring) {
        if (!config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_COMMENT_FIELD)) {
            addStatusErrorDescription("error.missing.score.config", GTAEditController.PANE_TAB_GRADING, sdList);
        }
    }
    if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
        List<Long> groupKeys = config.getList(GTACourseNode.GTASK_GROUPS, Long.class);
        List<Long> areaKeys = config.getList(GTACourseNode.GTASK_AREAS, Long.class);
        if (groupKeys.isEmpty() && areaKeys.isEmpty()) {
            addStatusErrorDescription("error.missing.group", GTAEditController.PANE_TAB_GRADING, sdList);
        }
    }
    // at least one step
    if (!config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT) && !config.getBooleanSafe(GTACourseNode.GTASK_SUBMIT) && !config.getBooleanSafe(GTACourseNode.GTASK_REVIEW_AND_CORRECTION) && !config.getBooleanSafe(GTACourseNode.GTASK_REVISION_PERIOD) && !config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION) && !config.getBooleanSafe(GTACourseNode.GTASK_GRADING)) {
        addStatusErrorDescription("error.select.atleastonestep", GTAEditController.PANE_TAB_WORKLOW, sdList);
    }
    if (cev != null) {
        // check assignment
        GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
        RepositoryEntry courseRe = cev.getCourseGroupManager().getCourseEntry();
        ICourse course = CourseFactory.loadCourse(courseRe);
        if (config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT)) {
            File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
            if (!TaskHelper.hasDocuments(taskDirectory)) {
                if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                    addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                } else {
                    addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                }
            } else {
                List<TaskDefinition> taskList = gtaManager.getTaskDefinitions(course.getCourseEnvironment(), this);
                if (taskList == null || taskList.isEmpty()) {
                    if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                        addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                    } else {
                        addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                    }
                } else {
                    String[] filenames = taskDirectory.list();
                    for (TaskDefinition taskDef : taskList) {
                        boolean found = false;
                        for (String filename : filenames) {
                            if (filename.equals(taskDef.getFilename())) {
                                found = true;
                                break;
                            }
                        }
                        if (!found) {
                            addStatusWarningDescription("error.missing.file", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
                        }
                    }
                }
            }
        }
        // check solutions
        if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
            File solutionDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
            if (!TaskHelper.hasDocuments(solutionDirectory)) {
                if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
                    addStatusWarningDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
                } else {
                    addStatusErrorDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
                }
            }
        }
        List<IdentityRef> participants = gtaManager.getDuplicatedMemberships(this);
        if (participants.size() > 0) {
            UserManager um = CoreSpringFactory.getImpl(UserManager.class);
            StringBuilder sb = new StringBuilder();
            for (IdentityRef participant : participants) {
                String fullname = um.getUserDisplayName(participant.getKey());
                if (sb.length() > 0)
                    sb.append(", ");
                sb.append(fullname);
            }
            String[] params = new String[] { getShortTitle(), sb.toString() };
            StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.duplicate.memberships", "error.duplicate.memberships", params, PACKAGE_GTA);
            sd.setDescriptionForUnit(getIdent());
            sd.setActivateableViewIdentifier(GTAEditController.PANE_TAB_WORKLOW);
            sdList.add(sd);
        }
    }
    return sdList;
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) TaskDefinition(org.olat.course.nodes.gta.model.TaskDefinition) StatusDescription(org.olat.course.editor.StatusDescription) UserManager(org.olat.user.UserManager) IdentityRef(org.olat.basesecurity.IdentityRef) GTAManager(org.olat.course.nodes.gta.GTAManager) File(java.io.File)

Aggregations

UserManager (org.olat.user.UserManager)64 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)22 Locale (java.util.Locale)12 Identity (org.olat.core.id.Identity)12 Date (java.util.Date)10 FormItem (org.olat.core.gui.components.form.flexible.FormItem)10 Translator (org.olat.core.gui.translator.Translator)10 User (org.olat.core.id.User)10 ArrayList (java.util.ArrayList)8 File (java.io.File)6 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)6 RestSecurityHelper.getLocale (org.olat.restapi.security.RestSecurityHelper.getLocale)6 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 ValidationError (org.olat.core.gui.components.form.ValidationError)4 SelectionElement (org.olat.core.gui.components.form.flexible.elements.SelectionElement)4 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)4 AssertException (org.olat.core.logging.AssertException)4 ICourse (org.olat.course.ICourse)4 RestSecurityHelper.isUserManager (org.olat.restapi.security.RestSecurityHelper.isUserManager)4