Search in sources :

Example 1 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class ListRenderer method render.

/**
 * Render contents of directory to a html table.
 *
 * @param dir
 * @param secCallback
 * @param ubu
 * @param translator
 * @param iframePostEnabled
 * @return Render results.
 */
public void render(FolderComponent fc, StringOutput sb, URLBuilder ubu, Translator translator, boolean iframePostEnabled) {
    if (lockManager == null) {
        lockManager = CoreSpringFactory.getImpl(VFSLockManager.class);
    }
    if (userManager == null) {
        userManager = CoreSpringFactory.getImpl(UserManager.class);
    }
    LicenseModule licenseModule = CoreSpringFactory.getImpl(LicenseModule.class);
    LicenseHandler licenseHandler = CoreSpringFactory.getImpl(FolderLicenseHandler.class);
    licensesEnabled = licenseModule.isEnabled(licenseHandler);
    List<VFSItem> children = fc.getCurrentContainerChildren();
    // folder empty?
    if (children.size() == 0) {
        sb.append("<div class=\"o_bc_empty\"><i class='o_icon o_icon_warn'></i> ").append(translator.translate("NoFiles")).append("</div>");
        return;
    }
    boolean canVersion = FolderConfig.versionsEnabled(fc.getCurrentContainer());
    String sortOrder = fc.getCurrentSortOrder();
    boolean sortAsc = fc.isCurrentSortAsc();
    String sortCss = (sortAsc ? "o_orderby_asc" : "o_orderby_desc");
    sb.append("<table class=\"table table-condensed table-striped table-hover o_bc_table\">").append("<thead><tr><th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_NAME.equals(sortOrder)).append("' ");
    ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_NAME)).append(">").append(translator.translate("header.Name")).append("</a>").append("</th>");
    sb.append("<th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_SIZE.equals(sortOrder)).append("' ");
    ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_SIZE)).append(">").append(translator.translate("header.Size")).append("</a>").append("</th><th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_DATE.equals(sortOrder)).append("' ");
    ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_DATE)).append(">").append(translator.translate("header.Modified")).append("</a>");
    if (licensesEnabled) {
        sb.append("<th>").append(translator.translate("header.license")).append("</th>");
    }
    if (canVersion) {
        sb.append("</th><th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_REV.equals(sortOrder)).append("' ");
        // file size column
        ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_REV)).append("><i class=\"o_icon o_icon_version  o_icon-lg\" title=\"").append(translator.translate("versions")).append("\"></i></a>");
    }
    sb.append("</th><th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_LOCK.equals(sortOrder)).append("' ");
    ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_LOCK)).append("><i class=\"o_icon o_icon_locked  o_icon-lg\" title=\"").append(translator.translate("lock.title")).append("\"></i></a>").append("</th><th><i class=\"o_icon o_icon_edit_metadata o_icon-lg\" title=\"").append(translator.translate("mf.edit")).append("\"></i></th></tr></thead>");
    // render directory contents
    String currentContainerPath = fc.getCurrentContainerPath();
    if (currentContainerPath.length() > 0 && currentContainerPath.charAt(0) == '/') {
        currentContainerPath = currentContainerPath.substring(1);
    }
    sb.append("<tbody>");
    for (int i = 0; i < children.size(); i++) {
        VFSItem child = children.get(i);
        appendRenderedFile(fc, child, currentContainerPath, sb, ubu, translator, iframePostEnabled, canVersion, i);
    }
    sb.append("</tbody></table>");
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) FolderLicenseHandler(org.olat.core.commons.modules.bc.FolderLicenseHandler) LicenseHandler(org.olat.core.commons.services.license.LicenseHandler) UserManager(org.olat.user.UserManager) VFSItem(org.olat.core.util.vfs.VFSItem) VFSLockManager(org.olat.core.util.vfs.VFSLockManager) LicenseModule(org.olat.core.commons.services.license.LicenseModule)

Example 2 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

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 3 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class CourseLogsArchiveController method event.

public void event(UserRequest ureq, Controller source, Event event) {
    if (source == logFileChooserForm) {
        if (event == Event.DONE_EVENT) {
            final boolean logAdminChecked = logFileChooserForm.logAdminChecked();
            final boolean logUserChecked = logFileChooserForm.logUserChecked();
            final boolean logStatisticChecked = logFileChooserForm.logStatChecked();
            final Date begin = logFileChooserForm.getBeginDate();
            final Date end = logFileChooserForm.getEndDate();
            if (end != null) {
                // shift time from beginning to end of day
                end.setTime(end.getTime() + 24 * 60 * 60 * 1000);
            }
            UserManager um = UserManager.getInstance();
            final String charset = um.getUserCharset(ureq.getIdentity());
            ICourse course = CourseFactory.loadCourse(ores);
            final String courseTitle = course.getCourseTitle();
            final String targetDir = CourseFactory.getOrCreateDataExportDirectory(ureq.getIdentity(), courseTitle).getPath();
            final Long resId = ores.getResourceableId();
            final Locale theLocale = ureq.getLocale();
            final String email = ureq.getIdentity().getUser().getProperty(UserConstants.EMAIL, ureq.getLocale());
            AsyncExportManager.getInstance().asyncArchiveCourseLogFiles(ureq.getIdentity(), new Runnable() {

                @Override
                public void run() {
                    showExportFinished();
                }
            }, resId, targetDir, begin, end, logAdminChecked, logUserChecked, logStatisticChecked, charset, theLocale, email);
            showExportOngoing(true);
        } else if (event == Event.DONE_EVENT) {
            myPanel.setContent(myContent);
        }
    }
}
Also used : Locale(java.util.Locale) UserManager(org.olat.user.UserManager) ICourse(org.olat.course.ICourse) Date(java.util.Date)

Example 4 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

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 5 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class Wiki method getRecentChanges.

protected String getRecentChanges(Locale locale) {
    if (locale == null)
        throw new AssertException("param was null which is not allowed");
    final int MAX_RESULTS = 5;
    List<WikiPage> pages = new ArrayList<>(wikiPages.values());
    Collections.sort(pages, WikiPageSort.MODTIME_ORDER);
    StringBuilder sb = new StringBuilder(512);
    int counter = 0;
    Formatter f = Formatter.getInstance(locale);
    UserManager userManager = CoreSpringFactory.getImpl(UserManager.class);
    for (Iterator<WikiPage> iter = pages.iterator(); iter.hasNext(); ) {
        if (counter > MAX_RESULTS)
            break;
        WikiPage page = iter.next();
        if (!page.getPageName().startsWith("O_") && !page.getPageName().startsWith(WikiPage.WIKI_MENU_PAGE)) {
            sb.append("* [[");
            sb.append(page.getPageName());
            sb.append("]] ");
            sb.append(f.formatDateAndTime(new Date(page.getModificationTime())));
            sb.append(" Author: ");
            long author = page.getModifyAuthor();
            if (author != 0) {
                String authorFullname = userManager.getUserDisplayName(author);
                if (StringHelper.containsNonWhitespace(authorFullname)) {
                    sb.append(" Author: ").append(authorFullname);
                } else {
                    sb.append("???");
                }
            }
            sb.append("\n");
            counter++;
        }
    }
    return sb.toString();
}
Also used : AssertException(org.olat.core.logging.AssertException) Formatter(org.olat.core.util.Formatter) UserManager(org.olat.user.UserManager) ArrayList(java.util.ArrayList) Date(java.util.Date)

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