Search in sources :

Example 1 with UserBulkChangeManager

use of org.olat.admin.user.bulkChange.UserBulkChangeManager in project OpenOLAT by OpenOLAT.

the class EmailProperty method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, final User user, String usageIdentifyer, final boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.TextElement tElem = null;
    tElem = (org.olat.core.gui.components.form.flexible.elements.TextElement) super.addFormItem(locale, user, usageIdentifyer, isAdministrativeUser, formItemContainer);
    // to validate the input a special isValidValue is used.
    if (usageIdentifyer.equals(UserBulkChangeStep00.class.getCanonicalName())) {
        tElem.setItemValidatorProvider(new ItemValidatorProvider() {

            @Override
            public boolean isValidValue(String value, ValidationError validationError, Locale locale2) {
                UserBulkChangeManager ubcMan = CoreSpringFactory.getImpl(UserBulkChangeManager.class);
                Context vcContext = new VelocityContext();
                if (user == null) {
                    vcContext = ubcMan.getDemoContext(locale2);
                } else // should be used if user-argument !=null --> move to right place
                {
                    Long userKey = user.getKey();
                    Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(userKey);
                    ubcMan.setUserContext(identity, vcContext);
                }
                value = value.replace("$", "$!");
                String evaluatedValue = ubcMan.evaluateValueWithUserContext(value, vcContext);
                return EmailProperty.this.isValidValue(user, evaluatedValue, validationError, locale2);
            }
        });
    }
    return tElem;
}
Also used : Locale(java.util.Locale) VelocityContext(org.apache.velocity.VelocityContext) Context(org.apache.velocity.context.Context) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) VelocityContext(org.apache.velocity.VelocityContext) UserBulkChangeStep00(org.olat.admin.user.bulkChange.UserBulkChangeStep00) UserBulkChangeManager(org.olat.admin.user.bulkChange.UserBulkChangeManager) ValidationError(org.olat.core.gui.components.form.ValidationError) Identity(org.olat.core.id.Identity)

Example 2 with UserBulkChangeManager

use of org.olat.admin.user.bulkChange.UserBulkChangeManager in project openolat by klemens.

the class EmailProperty method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale, org.olat.core.id.User, java.lang.String, boolean, org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, final User user, String usageIdentifyer, final boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    org.olat.core.gui.components.form.flexible.elements.TextElement tElem = null;
    tElem = (org.olat.core.gui.components.form.flexible.elements.TextElement) super.addFormItem(locale, user, usageIdentifyer, isAdministrativeUser, formItemContainer);
    // to validate the input a special isValidValue is used.
    if (usageIdentifyer.equals(UserBulkChangeStep00.class.getCanonicalName())) {
        tElem.setItemValidatorProvider(new ItemValidatorProvider() {

            @Override
            public boolean isValidValue(String value, ValidationError validationError, Locale locale2) {
                UserBulkChangeManager ubcMan = CoreSpringFactory.getImpl(UserBulkChangeManager.class);
                Context vcContext = new VelocityContext();
                if (user == null) {
                    vcContext = ubcMan.getDemoContext(locale2);
                } else // should be used if user-argument !=null --> move to right place
                {
                    Long userKey = user.getKey();
                    Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(userKey);
                    ubcMan.setUserContext(identity, vcContext);
                }
                value = value.replace("$", "$!");
                String evaluatedValue = ubcMan.evaluateValueWithUserContext(value, vcContext);
                return EmailProperty.this.isValidValue(user, evaluatedValue, validationError, locale2);
            }
        });
    }
    return tElem;
}
Also used : Locale(java.util.Locale) VelocityContext(org.apache.velocity.VelocityContext) Context(org.apache.velocity.context.Context) ItemValidatorProvider(org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider) VelocityContext(org.apache.velocity.VelocityContext) UserBulkChangeStep00(org.olat.admin.user.bulkChange.UserBulkChangeStep00) UserBulkChangeManager(org.olat.admin.user.bulkChange.UserBulkChangeManager) ValidationError(org.olat.core.gui.components.form.ValidationError) Identity(org.olat.core.id.Identity)

Aggregations

Locale (java.util.Locale)2 VelocityContext (org.apache.velocity.VelocityContext)2 Context (org.apache.velocity.context.Context)2 UserBulkChangeManager (org.olat.admin.user.bulkChange.UserBulkChangeManager)2 UserBulkChangeStep00 (org.olat.admin.user.bulkChange.UserBulkChangeStep00)2 ValidationError (org.olat.core.gui.components.form.ValidationError)2 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)2 Identity (org.olat.core.id.Identity)2