Search in sources :

Example 16 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class UserManagerImpl method getUserDisplayNamesByKey.

@Override
public Map<Long, String> getUserDisplayNamesByKey(Collection<Long> identityKeys) {
    if (identityKeys == null || identityKeys.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<Long, String> fullNames = new HashMap<>();
    List<Long> newIdentityKeys = new ArrayList<>();
    for (Long identityKey : identityKeys) {
        String fullName = userToFullnameCache.get(identityKey);
        if (fullName != null) {
            fullNames.put(identityKey, fullName);
        } else {
            newIdentityKeys.add(identityKey);
        }
    }
    List<IdentityShort> identities = securityManager.loadIdentityShortByKeys(newIdentityKeys);
    for (IdentityShort identity : identities) {
        String fullName = getUserDisplayName(identity);
        updateUsernameCache(identity.getKey(), identity.getName(), fullName);
        fullNames.put(identity.getKey(), fullName);
    }
    return fullNames;
}
Also used : HashMap(java.util.HashMap) IdentityShort(org.olat.basesecurity.IdentityShort) ArrayList(java.util.ArrayList)

Example 17 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class UserManagerImpl method getUserDisplayNamesByUserName.

@Override
public Map<String, String> getUserDisplayNamesByUserName(Collection<String> usernames) {
    if (usernames == null || usernames.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<String, String> fullNames = new HashMap<>();
    List<String> newUsernames = new ArrayList<>();
    for (String username : usernames) {
        String fullName = userToFullnameCache.get(username);
        if (fullName != null) {
            fullNames.put(username, fullName);
        } else {
            newUsernames.add(username);
        }
    }
    List<IdentityShort> identities = securityManager.findShortIdentitiesByName(newUsernames);
    for (IdentityShort identity : identities) {
        String fullName = getUserDisplayName(identity);
        fullNames.put(identity.getName(), fullName);
        newUsernames.remove(identity.getName());
    }
    // not found
    for (String notFound : newUsernames) {
        userToFullnameCache.put(notFound, notFound);
    }
    return fullNames;
}
Also used : HashMap(java.util.HashMap) IdentityShort(org.olat.basesecurity.IdentityShort) ArrayList(java.util.ArrayList)

Example 18 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class UserManagerImpl method getUserDisplayName.

@Override
public String getUserDisplayName(Long identityKey) {
    if (identityKey == null || identityKey.longValue() <= 0) {
        return "";
    }
    String fullName = userToFullnameCache.get(identityKey);
    if (fullName == null) {
        IdentityShort identity = securityManager.loadIdentityShortByKey(identityKey);
        fullName = getUserDisplayName(identity);
    }
    return fullName;
}
Also used : IdentityShort(org.olat.basesecurity.IdentityShort)

Example 19 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class SearchControllerFactory method getBusinessPathLabel.

@Override
public String getBusinessPathLabel(String token, List<String> allTokens, Locale locale) {
    try {
        String[] splitted = token.split("[:]");
        if (splitted != null && splitted.length == 2) {
            String tokenType = splitted[0];
            String tokenKey = splitted[1];
            if ("RepositoryEntry".equals(tokenType)) {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(Long.parseLong(tokenKey));
                return re.getDisplayname();
            }
            if ("CourseNode".equals(tokenType)) {
                String repoKey = allTokens.get(0).split("[:]")[1];
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(Long.parseLong(repoKey));
                if (re != null) {
                    ICourse course = CourseFactory.loadCourse(re);
                    CourseNode courseNode = course.getRunStructure().getNode(tokenKey);
                    return courseNode.getShortTitle();
                }
            }
            if ("Identity".equals(tokenType)) {
                IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(Long.parseLong(tokenKey));
                return UserManager.getInstance().getUserDisplayName(identity);
            }
            if ("BusinessGroup".equals(tokenType)) {
                BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(Long.parseLong(tokenKey));
                return bg == null ? "" : bg.getName();
            }
            if ("Taxonomy".equals(tokenType)) {
                Taxonomy taxonomy = CoreSpringFactory.getImpl(TaxonomyService.class).getTaxonomy(new TaxonomyRefImpl(Long.parseLong(tokenKey)));
                return taxonomy == null ? "" : taxonomy.getDisplayName();
            }
            if ("TaxonomyLevel".equals(tokenType)) {
                TaxonomyLevel level = CoreSpringFactory.getImpl(TaxonomyService.class).getTaxonomyLevel(new TaxonomyLevelRefImpl(Long.parseLong(tokenKey)));
                return level == null ? "" : level.getDisplayName();
            }
            Translator translator = Util.createPackageTranslator(this.getClass(), locale);
            if ("DocumentPool".equals(tokenType)) {
                return translator.translate("DocumentPool");
            }
            if ("Templates".equals(tokenType)) {
                return translator.translate("Templates");
            }
            if ("userfolder".equals(tokenType)) {
                return translator.translate("type.identity.publicfolder");
            }
            String translated = translator.translate(tokenType);
            if (translated == null || translated.length() > 64) {
                // no translation, translator return an error
                return token;
            }
            return translated;
        }
    } catch (Exception ex) {
        log.warn("Problem to decipher business path token: " + token, ex);
    }
    return token;
}
Also used : TaxonomyService(org.olat.modules.taxonomy.TaxonomyService) TaxonomyRefImpl(org.olat.modules.taxonomy.model.TaxonomyRefImpl) BusinessGroup(org.olat.group.BusinessGroup) Taxonomy(org.olat.modules.taxonomy.Taxonomy) IdentityShort(org.olat.basesecurity.IdentityShort) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) BusinessGroupService(org.olat.group.BusinessGroupService) Translator(org.olat.core.gui.translator.Translator) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) CourseNode(org.olat.course.nodes.CourseNode)

Example 20 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class StandardResultController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer formLayoutCont = (FormLayoutContainer) formLayout;
        formLayoutCont.contextPut("result", document);
        formLayoutCont.contextPut("id", hashCode());
        formLayoutCont.contextPut("formatter", Formatter.getInstance(getLocale()));
        String author = document.getAuthor();
        if (StringHelper.containsNonWhitespace(author)) {
            List<IdentityShort> identities = BaseSecurityManager.getInstance().findShortIdentitiesByName(Collections.singleton(author));
            if (identities.size() > 0) {
                author = UserManager.getInstance().getUserDisplayName(identities.get(0));
            }
        }
        formLayoutCont.contextPut("author", author);
        if (StringHelper.containsNonWhitespace(document.getLicenseTypeKey())) {
            LicenseType licenseType = licenseService.loadLicenseTypeByKey(document.getLicenseTypeKey());
            if (!licenseService.isNoLicense(licenseType)) {
                formLayoutCont.contextPut("licenseIcon", LicenseUIFactory.getCssOrDefault(licenseType));
                formLayoutCont.contextPut("license", LicenseUIFactory.translate(licenseType, getLocale()));
            }
        }
    }
    String icon = document.getCssIcon();
    if (!StringHelper.containsNonWhitespace(icon)) {
        icon = "o_sp_icon";
    }
    String label = document.getTitle();
    if (label != null) {
        label = label.trim();
    }
    if (label.length() > 128) {
        label = FilterFactory.getHtmlTagsFilter().filter(label);
        label = Formatter.truncate(label, 128);
    }
    label = StringHelper.escapeHtml(label);
    docLink = uifactory.addFormLink("open_doc", label, label, formLayout, Link.NONTRANSLATED);
    docLink.setIconLeftCSS("o_icon o_icon-fw " + icon);
    String highlightLabel = document.getHighlightTitle();
    if (!StringHelper.containsNonWhitespace(highlightLabel)) {
        highlightLabel = label;
    }
    docHighlightLink = uifactory.addFormLink("open_doc_highlight", highlightLabel, highlightLabel, formLayout, Link.NONTRANSLATED);
    docHighlightLink.setIconLeftCSS("o_icon o_icon-fw " + icon);
}
Also used : IdentityShort(org.olat.basesecurity.IdentityShort) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) LicenseType(org.olat.core.commons.services.license.LicenseType)

Aggregations

IdentityShort (org.olat.basesecurity.IdentityShort)32 File (java.io.File)8 HashMap (java.util.HashMap)8 Path (javax.ws.rs.Path)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 Produces (javax.ws.rs.Produces)6 HEAD (javax.ws.rs.HEAD)4 Identity (org.olat.core.id.Identity)4 ICourse (org.olat.course.ICourse)4 SearchAssessedIdentityParams (org.olat.course.assessment.model.SearchAssessedIdentityParams)4 BusinessGroup (org.olat.group.BusinessGroup)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 HashSet (java.util.HashSet)2 EntityManager (javax.persistence.EntityManager)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Response (javax.ws.rs.core.Response)2