Search in sources :

Example 1 with HomePageConfigManager

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

the class IdentityDocument method createDocument.

/**
 * Factory method to create a new IdentityDocument
 * @param searchResourceContext
 * @param wikiPage
 * @return
 */
public static Document createDocument(SearchResourceContext searchResourceContext, Identity identity) {
    UserManager userMgr = UserManager.getInstance();
    User user = identity.getUser();
    HomePageConfigManager homepageMgr = HomePageConfigManagerImpl.getInstance();
    HomePageConfig publishConfig = homepageMgr.loadConfigFor(identity.getName());
    IdentityDocument identityDocument = new IdentityDocument();
    identityDocument.setTitle(identity.getName());
    identityDocument.setCreatedDate(user.getCreationDate());
    // loop through all user properties and collect the content string and the last modified
    List<UserPropertyHandler> userPropertyHanders = userMgr.getUserPropertyHandlersFor(IdentityDocument.class.getName(), false);
    StringBuilder content = new StringBuilder();
    for (UserPropertyHandler userPropertyHandler : userPropertyHanders) {
        String propertyName = userPropertyHandler.getName();
        // only index fields the user has published!
        if (publishConfig.isEnabled(propertyName)) {
            String value = user.getProperty(propertyName, I18nModule.getDefaultLocale());
            if (value != null) {
                content.append(value).append(" ");
            }
        }
    }
    // user text
    String text = publishConfig.getTextAboutMe();
    if (StringHelper.containsNonWhitespace(text)) {
        text = FilterFactory.getHtmlTagsFilter().filter(text);
        content.append(text).append(' ');
    }
    // finally use the properties as the content for this identity
    if (content.length() > 0) {
        identityDocument.setContent(content.toString());
    }
    identityDocument.setResourceUrl(searchResourceContext.getResourceUrl());
    identityDocument.setDocumentType(searchResourceContext.getParentContextType());
    identityDocument.setCssIcon(CSSHelper.CSS_CLASS_USER);
    if (log.isDebug())
        log.debug(identityDocument.toString());
    return identityDocument.getLuceneDocument();
}
Also used : HomePageConfig(org.olat.user.HomePageConfig) User(org.olat.core.id.User) UserManager(org.olat.user.UserManager) HomePageConfigManager(org.olat.user.HomePageConfigManager) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 2 with HomePageConfigManager

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

the class IdentityDocument method createDocument.

/**
 * Factory method to create a new IdentityDocument
 * @param searchResourceContext
 * @param wikiPage
 * @return
 */
public static Document createDocument(SearchResourceContext searchResourceContext, Identity identity) {
    UserManager userMgr = UserManager.getInstance();
    User user = identity.getUser();
    HomePageConfigManager homepageMgr = HomePageConfigManagerImpl.getInstance();
    HomePageConfig publishConfig = homepageMgr.loadConfigFor(identity.getName());
    IdentityDocument identityDocument = new IdentityDocument();
    identityDocument.setTitle(identity.getName());
    identityDocument.setCreatedDate(user.getCreationDate());
    // loop through all user properties and collect the content string and the last modified
    List<UserPropertyHandler> userPropertyHanders = userMgr.getUserPropertyHandlersFor(IdentityDocument.class.getName(), false);
    StringBuilder content = new StringBuilder();
    for (UserPropertyHandler userPropertyHandler : userPropertyHanders) {
        String propertyName = userPropertyHandler.getName();
        // only index fields the user has published!
        if (publishConfig.isEnabled(propertyName)) {
            String value = user.getProperty(propertyName, I18nModule.getDefaultLocale());
            if (value != null) {
                content.append(value).append(" ");
            }
        }
    }
    // user text
    String text = publishConfig.getTextAboutMe();
    if (StringHelper.containsNonWhitespace(text)) {
        text = FilterFactory.getHtmlTagsFilter().filter(text);
        content.append(text).append(' ');
    }
    // finally use the properties as the content for this identity
    if (content.length() > 0) {
        identityDocument.setContent(content.toString());
    }
    identityDocument.setResourceUrl(searchResourceContext.getResourceUrl());
    identityDocument.setDocumentType(searchResourceContext.getParentContextType());
    identityDocument.setCssIcon(CSSHelper.CSS_CLASS_USER);
    if (log.isDebug())
        log.debug(identityDocument.toString());
    return identityDocument.getLuceneDocument();
}
Also used : HomePageConfig(org.olat.user.HomePageConfig) User(org.olat.core.id.User) UserManager(org.olat.user.UserManager) HomePageConfigManager(org.olat.user.HomePageConfigManager) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

User (org.olat.core.id.User)2 HomePageConfig (org.olat.user.HomePageConfig)2 HomePageConfigManager (org.olat.user.HomePageConfigManager)2 UserManager (org.olat.user.UserManager)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2