Search in sources :

Example 46 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class BusinessGroupArchiver method appendIdentity.

private void appendIdentity(StringBuffer buf, Identity owner, Date addedTo, Translator translator) {
    Locale loc = translator.getLocale();
    // add the identities user name
    ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(owner);
    String uname = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
    buf.append(uname);
    buf.append(DELIMITER);
    // add all user properties
    for (UserPropertyHandler propertyHandler : getUserPropertyHandlers()) {
        String value = propertyHandler.getUserProperty(owner.getUser(), loc);
        if (StringHelper.containsNonWhitespace(value)) {
            buf.append(value);
        }
        buf.append(DELIMITER);
    }
    // add the added-to date
    buf.append(addedTo.toString());
    buf.append(EOL);
}
Also used : Locale(java.util.Locale) ContextEntry(org.olat.core.id.context.ContextEntry) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 47 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class BusinessGroupArchiver method appendIdentityTableHeader.

private void appendIdentityTableHeader(StringBuffer buf, Translator translator) {
    // first the identites name
    buf.append(translator.translate("table.user.url"));
    buf.append(DELIMITER);
    // second the users properties
    for (UserPropertyHandler propertyHandler : getUserPropertyHandlers()) {
        String label = translator.translate(propertyHandler.i18nColumnDescriptorLabelKey());
        buf.append(label);
        buf.append(DELIMITER);
    }
    // third the users added-to date
    buf.append(translator.translate("table.subject.addeddate"));
    buf.append(EOL);
}
Also used : UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 48 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class AbstractMemberListController method initColumns.

private SortKey initColumns(FlexiTableColumnModel columnsModel) {
    SortKey defaultSortKey = null;
    String editAction = readOnly ? null : TABLE_ACTION_EDIT;
    if (chatEnabled) {
        DefaultFlexiColumnModel chatCol = new DefaultFlexiColumnModel(Cols.online.i18n(), Cols.online.ordinal());
        chatCol.setExportable(false);
        columnsModel.addFlexiColumnModel(chatCol);
    }
    if (isAdministrativeUser) {
        FlexiCellRenderer renderer = new StaticFlexiCellRenderer(editAction, new TextFlexiCellRenderer());
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.username.i18n(), Cols.username.ordinal(), editAction, true, Cols.username.name(), renderer));
        defaultSortKey = new SortKey(Cols.username.name(), true);
    }
    int colPos = USER_PROPS_OFFSET;
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        String propName = userPropertyHandler.getName();
        boolean visible = userManager.isMandatoryUserProperty(USER_PROPS_ID, userPropertyHandler);
        FlexiColumnModel col;
        if (UserConstants.FIRSTNAME.equals(propName) || UserConstants.LASTNAME.equals(propName)) {
            col = new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, editAction, true, propName, new StaticFlexiCellRenderer(editAction, new TextFlexiCellRenderer()));
        } else {
            col = new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, true, propName);
        }
        columnsModel.addFlexiColumnModel(col);
        colPos++;
        if (defaultSortKey == null) {
            defaultSortKey = new SortKey(propName, true);
        }
    }
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.firstTime.i18n(), Cols.firstTime.ordinal(), true, Cols.firstTime.name()));
    if (isLastVisitVisible) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.lastTime.i18n(), Cols.lastTime.ordinal(), true, Cols.lastTime.name()));
    }
    CourseRoleCellRenderer roleRenderer = new CourseRoleCellRenderer(getLocale());
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.role.i18n(), Cols.role.ordinal(), true, Cols.role.name(), roleRenderer));
    if (repoEntry != null) {
        GroupCellRenderer groupRenderer = new GroupCellRenderer();
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.groups.i18n(), Cols.groups.ordinal(), true, Cols.groups.name(), groupRenderer));
    }
    DefaultFlexiColumnModel toolsCol = new DefaultFlexiColumnModel(Cols.tools.i18n(), Cols.tools.ordinal());
    toolsCol.setExportable(false);
    toolsCol.setAlwaysVisible(true);
    columnsModel.addFlexiColumnModel(toolsCol);
    return defaultSortKey;
}
Also used : StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) TextFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer) FlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) FlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel) SortKey(org.olat.core.commons.persistence.SortKey) TextFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 49 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class AbstractMemberListController method filterIdentities.

private List<Identity> filterIdentities(SearchMembersParams params, Collection<Long> identityKeys) {
    SearchIdentityParams idParams = new SearchIdentityParams();
    if (StringHelper.containsNonWhitespace(params.getSearchString())) {
        String searchString = params.getSearchString();
        Map<String, String> propertiesSearch = new HashMap<>();
        for (UserPropertyHandler handler : userPropertyHandlers) {
            propertiesSearch.put(handler.getName(), searchString);
        }
        idParams.setLogin(searchString);
        idParams.setUserProperties(propertiesSearch);
    } else {
        if (params.getUserPropertiesSearch() != null && !params.getUserPropertiesSearch().isEmpty()) {
            idParams.setUserProperties(params.getUserPropertiesSearch());
        }
        if (StringHelper.containsNonWhitespace(params.getLogin())) {
            idParams.setLogin(params.getLogin());
        }
    }
    List<Long> identityKeyList = new ArrayList<>(identityKeys);
    List<Identity> identities = new ArrayList<>(identityKeyList.size());
    int count = 0;
    int batch = 500;
    do {
        int toIndex = Math.min(count + batch, identityKeyList.size());
        List<Long> toLoad = identityKeyList.subList(count, toIndex);
        idParams.setIdentityKeys(toLoad);
        List<Identity> batchOfIdentities = securityManager.getIdentitiesByPowerSearch(idParams, 0, -1);
        identities.addAll(batchOfIdentities);
        count += batch;
    } while (count < identityKeyList.size());
    return identities;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) SearchIdentityParams(org.olat.basesecurity.SearchIdentityParams)

Example 50 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class RegistrationController method createNewUserAfterRegistration.

/**
 * OO-92
 * this will finally create the user, set all it's userproperties
 *
 * @return User the newly created, persisted User Object
 */
private Identity createNewUserAfterRegistration() {
    // create user with mandatory fields from registration-form
    UserManager um = UserManager.getInstance();
    User volatileUser = um.createUser(registrationForm.getFirstName(), registrationForm.getLastName(), tempKey.getEmailAddress());
    // set user configured language
    Preferences preferences = volatileUser.getPreferences();
    preferences.setLanguage(registrationForm.getLangKey());
    volatileUser.setPreferences(preferences);
    // create an identity with the given username / pwd and the user object
    String login = registrationForm.getLogin();
    String pwd = registrationForm.getPassword();
    Identity persistedIdentity = registrationManager.createNewUserAndIdentityFromTemporaryKey(login, pwd, volatileUser, tempKey);
    if (persistedIdentity == null) {
        showError("user.notregistered");
        return null;
    } else {
        // update other user properties from form
        List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false);
        User persistedUser = persistedIdentity.getUser();
        // add eventually static value
        UserPropertiesConfig userPropertiesConfig = CoreSpringFactory.getImpl(UserPropertiesConfig.class);
        if (registrationModule.isStaticPropertyMappingEnabled()) {
            String propertyName = registrationModule.getStaticPropertyMappingName();
            String propertyValue = registrationModule.getStaticPropertyMappingValue();
            if (StringHelper.containsNonWhitespace(propertyName) && StringHelper.containsNonWhitespace(propertyValue) && userPropertiesConfig.getPropertyHandler(propertyName) != null) {
                try {
                    persistedUser.setProperty(propertyName, propertyValue);
                } catch (Exception e) {
                    logError("Cannot set the static property value", e);
                }
            }
        }
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            FormItem fi = registrationForm.getPropFormItem(userPropertyHandler.getName());
            userPropertyHandler.updateUserFromFormItem(persistedUser, fi);
        }
        // persist changes in db
        um.updateUserFromIdentity(persistedIdentity);
        // send notification mail to sys admin
        String notiEmail = CoreSpringFactory.getImpl(RegistrationModule.class).getRegistrationNotificationEmail();
        if (notiEmail != null) {
            registrationManager.sendNewUserNotificationMessage(notiEmail, persistedIdentity);
        }
        // tell system that this user did accept the disclaimer
        registrationManager.setHasConfirmedDislaimer(persistedIdentity);
        return persistedIdentity;
    }
}
Also used : User(org.olat.core.id.User) UserManager(org.olat.user.UserManager) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Preferences(org.olat.core.id.Preferences) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) UserPropertiesConfig(org.olat.user.UserPropertiesConfig)

Aggregations

UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)319 Identity (org.olat.core.id.Identity)84 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)74 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)70 ArrayList (java.util.ArrayList)62 FormItem (org.olat.core.gui.components.form.flexible.FormItem)62 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)56 User (org.olat.core.id.User)52 HashMap (java.util.HashMap)40 StaticFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer)36 FlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel)34 Translator (org.olat.core.gui.translator.Translator)32 Date (java.util.Date)30 UserManager (org.olat.user.UserManager)28 TextFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer)24 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)24 File (java.io.File)22 BusinessGroup (org.olat.group.BusinessGroup)22 SortKey (org.olat.core.commons.persistence.SortKey)18 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)18