Search in sources :

Example 1 with ReadableCustomerAttribute

use of com.salesmanager.shop.model.customer.attribute.ReadableCustomerAttribute in project shopizer by shopizer-ecommerce.

the class ReadableCustomerMapper method merge.

@Override
public ReadableCustomer merge(Customer source, ReadableCustomer target, MerchantStore store, Language language) {
    if (source.getId() != null && source.getId() > 0) {
        target.setId(source.getId());
    }
    target.setEmailAddress(source.getEmailAddress());
    if (StringUtils.isNotEmpty(source.getNick())) {
        target.setUserName(source.getNick());
    }
    if (source.getDefaultLanguage() != null) {
        target.setLanguage(source.getDefaultLanguage().getCode());
    }
    if (source.getGender() != null) {
        target.setGender(source.getGender().name());
    }
    if (StringUtils.isNotEmpty(source.getProvider())) {
        target.setProvider(source.getProvider());
    }
    if (source.getBilling() != null) {
        Address address = new Address();
        address.setAddress(source.getBilling().getAddress());
        address.setCity(source.getBilling().getCity());
        address.setCompany(source.getBilling().getCompany());
        address.setFirstName(source.getBilling().getFirstName());
        address.setLastName(source.getBilling().getLastName());
        address.setPostalCode(source.getBilling().getPostalCode());
        address.setPhone(source.getBilling().getTelephone());
        if (source.getBilling().getCountry() != null) {
            address.setCountry(source.getBilling().getCountry().getIsoCode());
        }
        if (source.getBilling().getZone() != null) {
            address.setZone(source.getBilling().getZone().getCode());
        }
        if (source.getBilling().getState() != null) {
            address.setStateProvince(source.getBilling().getState());
        }
        target.setFirstName(address.getFirstName());
        target.setLastName(address.getLastName());
        target.setBilling(address);
    }
    if (source.getCustomerReviewAvg() != null) {
        target.setRating(source.getCustomerReviewAvg().doubleValue());
    }
    if (source.getCustomerReviewCount() != null) {
        target.setRatingCount(source.getCustomerReviewCount().intValue());
    }
    if (source.getDelivery() != null) {
        Address address = new Address();
        address.setCity(source.getDelivery().getCity());
        address.setAddress(source.getDelivery().getAddress());
        address.setCompany(source.getDelivery().getCompany());
        address.setFirstName(source.getDelivery().getFirstName());
        address.setLastName(source.getDelivery().getLastName());
        address.setPostalCode(source.getDelivery().getPostalCode());
        address.setPhone(source.getDelivery().getTelephone());
        if (source.getDelivery().getCountry() != null) {
            address.setCountry(source.getDelivery().getCountry().getIsoCode());
        }
        if (source.getDelivery().getZone() != null) {
            address.setZone(source.getDelivery().getZone().getCode());
        }
        if (source.getDelivery().getState() != null) {
            address.setStateProvince(source.getDelivery().getState());
        }
        target.setDelivery(address);
    } else {
        target.setDelivery(target.getBilling());
    }
    if (source.getAttributes() != null) {
        for (CustomerAttribute attribute : source.getAttributes()) {
            ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute();
            readableAttribute.setId(attribute.getId());
            readableAttribute.setTextValue(attribute.getTextValue());
            ReadableCustomerOption option = new ReadableCustomerOption();
            option.setId(attribute.getCustomerOption().getId());
            option.setCode(attribute.getCustomerOption().getCode());
            CustomerOptionDescription d = new CustomerOptionDescription();
            d.setDescription(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getDescription());
            d.setName(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getName());
            option.setDescription(d);
            readableAttribute.setCustomerOption(option);
            ReadableCustomerOptionValue optionValue = new ReadableCustomerOptionValue();
            optionValue.setId(attribute.getCustomerOptionValue().getId());
            CustomerOptionValueDescription vd = new CustomerOptionValueDescription();
            vd.setDescription(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getDescription());
            vd.setName(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getName());
            optionValue.setCode(attribute.getCustomerOptionValue().getCode());
            optionValue.setDescription(vd);
            readableAttribute.setCustomerOptionValue(optionValue);
            target.getAttributes().add(readableAttribute);
        }
        if (source.getGroups() != null) {
            for (Group group : source.getGroups()) {
                ReadableGroup readableGroup = new ReadableGroup();
                readableGroup.setId(group.getId().longValue());
                readableGroup.setName(group.getGroupName());
                readableGroup.setType(group.getGroupType().name());
                target.getGroups().add(readableGroup);
            }
        }
    }
    return target;
}
Also used : CustomerOptionDescription(com.salesmanager.shop.model.customer.attribute.CustomerOptionDescription) ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) Group(com.salesmanager.core.model.user.Group) ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) Address(com.salesmanager.shop.model.customer.address.Address) ReadableCustomerOptionValue(com.salesmanager.shop.model.customer.attribute.ReadableCustomerOptionValue) ReadableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.ReadableCustomerAttribute) CustomerAttribute(com.salesmanager.core.model.customer.attribute.CustomerAttribute) ReadableCustomerOption(com.salesmanager.shop.model.customer.attribute.ReadableCustomerOption) CustomerOptionValueDescription(com.salesmanager.shop.model.customer.attribute.CustomerOptionValueDescription) ReadableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.ReadableCustomerAttribute)

Example 2 with ReadableCustomerAttribute

use of com.salesmanager.shop.model.customer.attribute.ReadableCustomerAttribute in project shopizer by shopizer-ecommerce.

the class ReadableCustomerPopulator method populate.

@Override
public ReadableCustomer populate(Customer source, ReadableCustomer target, MerchantStore store, Language language) throws ConversionException {
    try {
        if (target == null) {
            target = new ReadableCustomer();
        }
        if (source.getId() != null && source.getId() > 0) {
            target.setId(source.getId());
        }
        target.setEmailAddress(source.getEmailAddress());
        if (StringUtils.isNotEmpty(source.getNick())) {
            target.setUserName(source.getNick());
        }
        if (source.getDefaultLanguage() != null) {
            target.setLanguage(source.getDefaultLanguage().getCode());
        }
        if (source.getGender() != null) {
            target.setGender(source.getGender().name());
        }
        if (StringUtils.isNotEmpty(source.getProvider())) {
            target.setProvider(source.getProvider());
        }
        if (source.getBilling() != null) {
            Address address = new Address();
            address.setAddress(source.getBilling().getAddress());
            address.setCity(source.getBilling().getCity());
            address.setCompany(source.getBilling().getCompany());
            address.setFirstName(source.getBilling().getFirstName());
            address.setLastName(source.getBilling().getLastName());
            address.setPostalCode(source.getBilling().getPostalCode());
            address.setPhone(source.getBilling().getTelephone());
            if (source.getBilling().getCountry() != null) {
                address.setCountry(source.getBilling().getCountry().getIsoCode());
            }
            if (source.getBilling().getZone() != null) {
                address.setZone(source.getBilling().getZone().getCode());
            }
            if (source.getBilling().getState() != null) {
                address.setStateProvince(source.getBilling().getState());
            }
            target.setFirstName(address.getFirstName());
            target.setLastName(address.getLastName());
            target.setBilling(address);
        }
        if (source.getCustomerReviewAvg() != null) {
            target.setRating(source.getCustomerReviewAvg().doubleValue());
        }
        if (source.getCustomerReviewCount() != null) {
            target.setRatingCount(source.getCustomerReviewCount().intValue());
        }
        if (source.getDelivery() != null) {
            Address address = new Address();
            address.setCity(source.getDelivery().getCity());
            address.setAddress(source.getDelivery().getAddress());
            address.setCompany(source.getDelivery().getCompany());
            address.setFirstName(source.getDelivery().getFirstName());
            address.setLastName(source.getDelivery().getLastName());
            address.setPostalCode(source.getDelivery().getPostalCode());
            address.setPhone(source.getDelivery().getTelephone());
            if (source.getDelivery().getCountry() != null) {
                address.setCountry(source.getDelivery().getCountry().getIsoCode());
            }
            if (source.getDelivery().getZone() != null) {
                address.setZone(source.getDelivery().getZone().getCode());
            }
            if (source.getDelivery().getState() != null) {
                address.setStateProvince(source.getDelivery().getState());
            }
            target.setDelivery(address);
        }
        if (source.getAttributes() != null) {
            for (CustomerAttribute attribute : source.getAttributes()) {
                ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute();
                readableAttribute.setId(attribute.getId());
                readableAttribute.setTextValue(attribute.getTextValue());
                ReadableCustomerOption option = new ReadableCustomerOption();
                option.setId(attribute.getCustomerOption().getId());
                option.setCode(attribute.getCustomerOption().getCode());
                CustomerOptionDescription d = new CustomerOptionDescription();
                d.setDescription(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getDescription());
                d.setName(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getName());
                option.setDescription(d);
                readableAttribute.setCustomerOption(option);
                ReadableCustomerOptionValue optionValue = new ReadableCustomerOptionValue();
                optionValue.setId(attribute.getCustomerOptionValue().getId());
                CustomerOptionValueDescription vd = new CustomerOptionValueDescription();
                vd.setDescription(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getDescription());
                vd.setName(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getName());
                optionValue.setCode(attribute.getCustomerOptionValue().getCode());
                optionValue.setDescription(vd);
                readableAttribute.setCustomerOptionValue(optionValue);
                target.getAttributes().add(readableAttribute);
            }
            if (source.getGroups() != null) {
                for (Group group : source.getGroups()) {
                    ReadableGroup readableGroup = new ReadableGroup();
                    readableGroup.setId(group.getId().longValue());
                    readableGroup.setName(group.getGroupName());
                    readableGroup.setType(group.getGroupType().name());
                    target.getGroups().add(readableGroup);
                }
            }
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : CustomerOptionDescription(com.salesmanager.shop.model.customer.attribute.CustomerOptionDescription) ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) ConversionException(com.salesmanager.core.business.exception.ConversionException) Group(com.salesmanager.core.model.user.Group) ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) Address(com.salesmanager.shop.model.customer.address.Address) ReadableCustomerOptionValue(com.salesmanager.shop.model.customer.attribute.ReadableCustomerOptionValue) ReadableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.ReadableCustomerAttribute) CustomerAttribute(com.salesmanager.core.model.customer.attribute.CustomerAttribute) ReadableCustomerOption(com.salesmanager.shop.model.customer.attribute.ReadableCustomerOption) CustomerOptionValueDescription(com.salesmanager.shop.model.customer.attribute.CustomerOptionValueDescription) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ReadableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.ReadableCustomerAttribute) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Aggregations

CustomerAttribute (com.salesmanager.core.model.customer.attribute.CustomerAttribute)2 Group (com.salesmanager.core.model.user.Group)2 Address (com.salesmanager.shop.model.customer.address.Address)2 CustomerOptionDescription (com.salesmanager.shop.model.customer.attribute.CustomerOptionDescription)2 CustomerOptionValueDescription (com.salesmanager.shop.model.customer.attribute.CustomerOptionValueDescription)2 ReadableCustomerAttribute (com.salesmanager.shop.model.customer.attribute.ReadableCustomerAttribute)2 ReadableCustomerOption (com.salesmanager.shop.model.customer.attribute.ReadableCustomerOption)2 ReadableCustomerOptionValue (com.salesmanager.shop.model.customer.attribute.ReadableCustomerOptionValue)2 ReadableGroup (com.salesmanager.shop.model.security.ReadableGroup)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)1