<commit_before>/*******************************************************************************
 *                                                                              
 *  Copyright FUJITSU LIMITED 2016                                             
 *                                                                              
 *  Author: <NAME>                                                      
 *                                                                              
 *  Creation Date: 12.02.2009                                                      
 *                                                                              
 *  Completion Time: 17.06.2009                                              
 *                                                                              
 *******************************************************************************/

package org.oscm.identityservice.assembler;

import java.util.List;

import org.apache.commons.validator.GenericValidator;

import org.oscm.domobjects.OrganizationToRole;
import org.oscm.domobjects.PlatformUser;
import org.oscm.domobjects.RoleAssignment;
import org.oscm.domobjects.Tenant;
import org.oscm.validator.BLValidator;
import org.oscm.vo.BaseAssembler;
import org.oscm.internal.types.enumtypes.SettingType;
import org.oscm.internal.types.exception.ConcurrentModificationException;
import org.oscm.internal.types.exception.ValidationException;
import org.oscm.internal.vo.VOUser;
import org.oscm.internal.vo.VOUserDetails;

/**
 * Assembler to convert user related value objects to the according domain
 * objects and vice versa.
 * 
 * @author <NAME>uml;ger
 * 
 */
public class UserDataAssembler extends BaseAssembler {

    public static final String FIELD_NAME_ORGANIZATION_ID = "organizationId";

    public static final String FIELD_NAME_USER_ID = "userId";

    public static final String FIELD_NAME_ADDRESS = "address";

    public static final String FIELD_NAME_ADDITIONAL_NAME = "additionalName";

    public static final String FIELD_NAME_EMAIL = "email";

    public static final String FIELD_NAME_FIRST_NAME = "firstName";

    public static final String FIELD_NAME_LAST_NAME = "lastName";

    public static final String FIELD_NAME_LOCALE = "locale";

    public static final String FIELD_NAME_PHONE = "phone";

    private static final int LOCAL_LENGTH = 2;

    /**
     * Converts the given domain object to a value object containing the
     * identifying attributes.
     * 
     * @param platformUser
     *            The domain object containing the values to be set.
     * @return A value object reflecting the values of the given domain object.
     */
    public static VOUser toVOUser(PlatformUser platformUser) {
        if (platformUser == null) {
            return null;
        }
        VOUser voUser = new VOUser();
        updateVoUser(platformUser, voUser);
        return voUser;
    }

    static void updateVoUser(PlatformUser platformUser, VOUser voUser) {
        voUser.setOrganizationId(platformUser.getOrganization()
                .getOrganizationId());
        voUser.setOrganizationName(platformUser.getOrganization().getName());
        voUser.setUserId(platformUser.getUserId());
        voUser.setStatus(platformUser.getStatus());
        voUser.setTenantKey(String.valueOf(platformUser.getOrganization().getTenant().getKey()));
        updateOrganizationRoles(platformUser, voUser);
        updateUserRoles(platformUser, voUser);
        updateValueObject(voUser, platformUser);
    }

    /**
     * Converts the given domain object to a value object containing all
     * attributes.
     * <commit_msg>Added null check<commit_after>/*******************************************************************************
 *                                                                              
 *  Copyright FUJITSU LIMITED 2016                                             
 *                                                                              
 *  Author: <NAME>uml;ger                                                      
 *                                                                              
 *  Creation Date: 12.02.2009                                                      
 *                                                                              
 *  Completion Time: 17.06.2009                                              
 *                                                                              
 *******************************************************************************/

package org.oscm.identityservice.assembler;

import java.util.List;

import org.apache.commons.validator.GenericValidator;

import org.oscm.domobjects.OrganizationToRole;
import org.oscm.domobjects.PlatformUser;
import org.oscm.domobjects.RoleAssignment;
import org.oscm.domobjects.Tenant;
import org.oscm.validator.BLValidator;
import org.oscm.vo.BaseAssembler;
import org.oscm.internal.types.enumtypes.SettingType;
import org.oscm.internal.types.exception.ConcurrentModificationException;
import org.oscm.internal.types.exception.ValidationException;
import org.oscm.internal.vo.VOUser;
import org.oscm.internal.vo.VOUserDetails;

/**
 * Assembler to convert user related value objects to the according domain
 * objects and vice versa.
 * 
 * @author <NAME>uml;ger
 * 
 */
public class UserDataAssembler extends BaseAssembler {

    public static final String FIELD_NAME_ORGANIZATION_ID = "organizationId";

    public static final String FIELD_NAME_USER_ID = "userId";

    public static final String FIELD_NAME_ADDRESS = "address";

    public static final String FIELD_NAME_ADDITIONAL_NAME = "additionalName";

    public static final String FIELD_NAME_EMAIL = "email";

    public static final String FIELD_NAME_FIRST_NAME = "firstName";

    public static final String FIELD_NAME_LAST_NAME = "lastName";

    public static final String FIELD_NAME_LOCALE = "locale";

    public static final String FIELD_NAME_PHONE = "phone";

    private static final int LOCAL_LENGTH = 2;

    /**
     * Converts the given domain object to a value object containing the
     * identifying attributes.
     * 
     * @param platformUser
     *            The domain object containing the values to be set.
     * @return A value object reflecting the values of the given domain object.
     */
    public static VOUser toVOUser(PlatformUser platformUser) {
        if (platformUser == null) {
            return null;
        }
        VOUser voUser = new VOUser();
        updateVoUser(platformUser, voUser);
        return voUser;
    }

    static void updateVoUser(PlatformUser platformUser, VOUser voUser) {
        voUser.setOrganizationId(platformUser.getOrganization()
                .getOrganizationId());
        voUser.setOrganizationName(platformUser.getOrganization().getName());
        voUser.setUserId(platformUser.getUserId());
        voUser.setStatus(platformUser.getStatus());
        final Tenant tenant = platformUser.getOrganization().getTenant();
        if (tenant != null) {
            voUser.setTenantKey(String.valueOf(tenant.getKey()));
        }
        updateOrganizationRoles(platformUser, voUser);
        updateUserRoles(platformUser, voUser);
        updateValueObject(voUser, platformUser);
    }

    /**
     * Converts the given domain object to a value object containing all
     * attributes.
     * 
{'fraction_non_alphanumeric': 0.11142549178119106, 'fraction_numerical': 0.005658852061438965, 'mean_word_length': 1.9835209003215435, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5048344', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1700, 'n_words': 423}