Search in sources :

Example 1 with DatePropertyHandler

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

the class UserVOFactory method post.

public static void post(User dbUser, UserVO user, Locale locale) {
    UserManager um = UserManager.getInstance();
    List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
    dbUser.setProperty(UserConstants.FIRSTNAME, user.getFirstName());
    dbUser.setProperty(UserConstants.LASTNAME, user.getLastName());
    dbUser.setProperty(UserConstants.EMAIL, user.getEmail());
    for (UserPropertyVO entry : user.getProperties()) {
        for (UserPropertyHandler propertyHandler : propertyHandlers) {
            if (entry.getName().equals(propertyHandler.getName())) {
                String value = parseUserProperty(entry.getValue(), propertyHandler, locale);
                String parsedValue;
                if (propertyHandler instanceof DatePropertyHandler) {
                    parsedValue = formatDbDate(value, locale);
                } else if (propertyHandler instanceof GenderPropertyHandler) {
                    parsedValue = parseGender(value, (GenderPropertyHandler) propertyHandler, locale);
                } else {
                    parsedValue = propertyHandler.getStringValue(value, locale);
                }
                dbUser.setProperty(entry.getName(), parsedValue);
                break;
            }
        }
    }
}
Also used : GenderPropertyHandler(org.olat.user.propertyhandlers.GenderPropertyHandler) UserManager(org.olat.user.UserManager) DatePropertyHandler(org.olat.user.propertyhandlers.DatePropertyHandler) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 2 with DatePropertyHandler

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

the class CertificatesManagerImpl method getPreviewIdentity.

private Identity getPreviewIdentity() {
    TransientIdentity identity = new TransientIdentity();
    identity.setName("username");
    List<UserPropertyHandler> userPropertyHandlers = userManager.getAllUserPropertyHandlers();
    for (UserPropertyHandler handler : userPropertyHandlers) {
        if (handler instanceof DatePropertyHandler) {
            identity.getUser().setProperty(handler.getName(), Formatter.formatDatetime(new Date()));
        } else {
            identity.getUser().setProperty(handler.getName(), handler.getName());
        }
    }
    return identity;
}
Also used : TransientIdentity(org.olat.admin.user.imp.TransientIdentity) DatePropertyHandler(org.olat.user.propertyhandlers.DatePropertyHandler) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) Date(java.util.Date)

Example 3 with DatePropertyHandler

use of org.olat.user.propertyhandlers.DatePropertyHandler in project openolat by klemens.

the class UserVOFactory method post.

public static void post(User dbUser, UserVO user, Locale locale) {
    UserManager um = UserManager.getInstance();
    List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
    dbUser.setProperty(UserConstants.FIRSTNAME, user.getFirstName());
    dbUser.setProperty(UserConstants.LASTNAME, user.getLastName());
    dbUser.setProperty(UserConstants.EMAIL, user.getEmail());
    for (UserPropertyVO entry : user.getProperties()) {
        for (UserPropertyHandler propertyHandler : propertyHandlers) {
            if (entry.getName().equals(propertyHandler.getName())) {
                String value = parseUserProperty(entry.getValue(), propertyHandler, locale);
                String parsedValue;
                if (propertyHandler instanceof DatePropertyHandler) {
                    parsedValue = formatDbDate(value, locale);
                } else if (propertyHandler instanceof GenderPropertyHandler) {
                    parsedValue = parseGender(value, (GenderPropertyHandler) propertyHandler, locale);
                } else {
                    parsedValue = propertyHandler.getStringValue(value, locale);
                }
                dbUser.setProperty(entry.getName(), parsedValue);
                break;
            }
        }
    }
}
Also used : GenderPropertyHandler(org.olat.user.propertyhandlers.GenderPropertyHandler) UserManager(org.olat.user.UserManager) DatePropertyHandler(org.olat.user.propertyhandlers.DatePropertyHandler) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 4 with DatePropertyHandler

use of org.olat.user.propertyhandlers.DatePropertyHandler in project openolat by klemens.

the class CertificatesManagerImpl method getPreviewIdentity.

private Identity getPreviewIdentity() {
    TransientIdentity identity = new TransientIdentity();
    identity.setName("username");
    List<UserPropertyHandler> userPropertyHandlers = userManager.getAllUserPropertyHandlers();
    for (UserPropertyHandler handler : userPropertyHandlers) {
        if (handler instanceof DatePropertyHandler) {
            identity.getUser().setProperty(handler.getName(), Formatter.formatDatetime(new Date()));
        } else {
            identity.getUser().setProperty(handler.getName(), handler.getName());
        }
    }
    return identity;
}
Also used : TransientIdentity(org.olat.admin.user.imp.TransientIdentity) DatePropertyHandler(org.olat.user.propertyhandlers.DatePropertyHandler) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) Date(java.util.Date)

Aggregations

DatePropertyHandler (org.olat.user.propertyhandlers.DatePropertyHandler)4 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)4 Date (java.util.Date)2 TransientIdentity (org.olat.admin.user.imp.TransientIdentity)2 UserManager (org.olat.user.UserManager)2 GenderPropertyHandler (org.olat.user.propertyhandlers.GenderPropertyHandler)2