// Path: db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/CustomFieldSettingUtil.java
// public final class CustomFieldSettingUtil {
//     private static final Log LOG = LogFactoryUtil.getLog(CustomFieldSettingUtil.class);
// 
//     private CustomFieldSettingUtil() {
// 
//     }
// 
//     /**
//      * Auxiliary method that returns the expando value of a given expando field
//      * with a given key.
//      *
//      * @param user
//      *            The user whose expando field will be retrieved.
//      * @param key
//      *            The name of the expando field.
//      * @return Returns false, if the expando field or the value is not defined.
//      */
//     // CHECKSTYLE:OFF
//     public static void setExpandoValue(final String resolverHint, final long runAsUserId,
//             final long groupId, final long company, final Class clazz, final long id,
//             final String key, final String value) {
//         String valueCopy = value;
//         try {
// 
//             ExpandoValue ev = ExpandoValueLocalServiceUtil.getValue(company, clazz.getName(),
//                     "CUSTOM_FIELDS", key, id);
//             // resolve any values to be substituted
//             valueCopy = ResolverUtil.lookupAll(runAsUserId, groupId, company, valueCopy,
//                     resolverHint);
//             if (ev == null) {
//                 long classNameId = ClassNameLocalServiceUtil.getClassNameId(clazz.getName());
// 
//                 ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getTable(company,
//                         classNameId, "CUSTOM_FIELDS");
//                 ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(company,
//                         classNameId, expandoTable.getName(), key);
// 
//                 // In this we are adding MyUserColumnData for the column
//                 // MyUserColumn. See the
//                 // above line
//                 ev = ExpandoValueLocalServiceUtil.addValue(classNameId, expandoTable.getTableId(),
//                         expandoColumn.getColumnId(), id, valueCopy);
//             } else {
//                 ev.setData(valueCopy);
//                 ExpandoValueLocalServiceUtil.updateExpandoValue(ev);
//             }
//         } catch (Exception ex) {
//             LOG.error("Expando (custom field) not found or problem accessing it: " + key + " for "
//                     + "class " + clazz.getName() + " with id " + id, ex);
//         }
// 
//     }
//     // CHECKSTYLE:ON
// }


import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import com.liferay.portal.kernel.exception.NoSuchUserException;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.Organization;
import com.liferay.portal.kernel.model.Role;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.*;
import com.liferay.portal.kernel.util.PortalUtil;
import com.mimacom.liferay.portal.setup.core.util.CustomFieldSettingUtil;
import com.mimacom.liferay.portal.setup.domain.CustomFieldSetting;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.StringPool;
                LOG.info("User " + liferayUser.getEmailAddress()
                        + " already exist, not creating...");

            } catch (NoSuchUserException e) {
                liferayUser = addUser(user);

            } catch (Exception e) {
                LOG.error("Error by retrieving user " + user.getEmailAddress());
            }

            if( null != liferayUser ){
                addUserToOrganizations(user, liferayUser);
                addRolesToUser(user, liferayUser);
                if (user.getCustomFieldSetting() != null && !user.getCustomFieldSetting().isEmpty()) {
                    setCustomFields(runAsUser, groupId, COMPANY_ID, liferayUser, user);
                }
            } else {
                LOG.warn("Could not create user with screenName '" + user.getScreenName()+"'");
            }
        }
    }

    private static void setCustomFields(final long runAsUser, final long groupId,
            final long company, final User liferayUser,
            final com.mimacom.liferay.portal.setup.domain.User user) {
        Class clazz = User.class;
        for (CustomFieldSetting cfs : user.getCustomFieldSetting()) {
            String resolverHint = "Custom value for user " + user.getScreenName() + ", "
                    + user.getEmailAddress() + "" + " Key " + cfs.getKey() + ", value "
                    + cfs.getValue();
// Path: db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/CustomFieldSettingUtil.java
// public final class CustomFieldSettingUtil {
//     private static final Log LOG = LogFactoryUtil.getLog(CustomFieldSettingUtil.class);
// 
//     private CustomFieldSettingUtil() {
// 
//     }
// 
//     /**
//      * Auxiliary method that returns the expando value of a given expando field
//      * with a given key.
//      *
//      * @param user
//      *            The user whose expando field will be retrieved.
//      * @param key
//      *            The name of the expando field.
//      * @return Returns false, if the expando field or the value is not defined.
//      */
//     // CHECKSTYLE:OFF
//     public static void setExpandoValue(final String resolverHint, final long runAsUserId,
//             final long groupId, final long company, final Class clazz, final long id,
//             final String key, final String value) {
//         String valueCopy = value;
//         try {
// 
//             ExpandoValue ev = ExpandoValueLocalServiceUtil.getValue(company, clazz.getName(),
//                     "CUSTOM_FIELDS", key, id);
//             // resolve any values to be substituted
//             valueCopy = ResolverUtil.lookupAll(runAsUserId, groupId, company, valueCopy,
//                     resolverHint);
//             if (ev == null) {
//                 long classNameId = ClassNameLocalServiceUtil.getClassNameId(clazz.getName());
// 
//                 ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getTable(company,
//                         classNameId, "CUSTOM_FIELDS");
//                 ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil.getColumn(company,
//                         classNameId, expandoTable.getName(), key);
// 
//                 // In this we are adding MyUserColumnData for the column
//                 // MyUserColumn. See the
//                 // above line
//                 ev = ExpandoValueLocalServiceUtil.addValue(classNameId, expandoTable.getTableId(),
//                         expandoColumn.getColumnId(), id, valueCopy);
//             } else {
//                 ev.setData(valueCopy);
//                 ExpandoValueLocalServiceUtil.updateExpandoValue(ev);
//             }
//         } catch (Exception ex) {
//             LOG.error("Expando (custom field) not found or problem accessing it: " + key + " for "
//                     + "class " + clazz.getName() + " with id " + id, ex);
//         }
// 
//     }
//     // CHECKSTYLE:ON
// }


// Path: db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupUsers.java
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import com.liferay.portal.kernel.exception.NoSuchUserException;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.Organization;
import com.liferay.portal.kernel.model.Role;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.*;
import com.liferay.portal.kernel.util.PortalUtil;
import com.mimacom.liferay.portal.setup.core.util.CustomFieldSettingUtil;
import com.mimacom.liferay.portal.setup.domain.CustomFieldSetting;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.StringPool;

                LOG.info("User " + liferayUser.getEmailAddress()
                        + " already exist, not creating...");

            } catch (NoSuchUserException e) {
                liferayUser = addUser(user);

            } catch (Exception e) {
                LOG.error("Error by retrieving user " + user.getEmailAddress());
            }

            if( null != liferayUser ){
                addUserToOrganizations(user, liferayUser);
                addRolesToUser(user, liferayUser);
                if (user.getCustomFieldSetting() != null && !user.getCustomFieldSetting().isEmpty()) {
                    setCustomFields(runAsUser, groupId, COMPANY_ID, liferayUser, user);
                }
            } else {
                LOG.warn("Could not create user with screenName '" + user.getScreenName()+"'");
            }
        }
    }

    private static void setCustomFields(final long runAsUser, final long groupId,
            final long company, final User liferayUser,
            final com.mimacom.liferay.portal.setup.domain.User user) {
        Class clazz = User.class;
        for (CustomFieldSetting cfs : user.getCustomFieldSetting()) {
            String resolverHint = "Custom value for user " + user.getScreenName() + ", "
                    + user.getEmailAddress() + "" + " Key " + cfs.getKey() + ", value "
                    + cfs.getValue();
            CustomFieldSettingUtil.setExpandoValue(resolverHint, runAsUser, groupId, company, clazz,