use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class CustomerEntityPopulator method populate.
@Override
public CustomerEntity populate(final Customer source, final CustomerEntity target, final MerchantStore merchantStore, final Language language) throws ConversionException {
try {
target.setId(source.getId());
if (StringUtils.isNotBlank(source.getEmailAddress())) {
target.setEmailAddress(source.getEmailAddress());
}
if (source.getBilling() != null) {
Address address = new Address();
address.setCity(source.getBilling().getCity());
address.setAddress(source.getBilling().getAddress());
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());
}
address.setStateProvince(source.getBilling().getState());
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());
}
address.setStateProvince(source.getDelivery().getState());
target.setDelivery(address);
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class PersistableCustomerOptionPopulator method populate.
@Override
public CustomerOption populate(PersistableCustomerOption source, CustomerOption target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(languageService, "Requires to set LanguageService");
try {
target.setCode(source.getCode());
target.setMerchantStore(store);
target.setSortOrder(source.getOrder());
if (!StringUtils.isBlank(source.getType())) {
target.setCustomerOptionType(source.getType());
} else {
target.setCustomerOptionType("TEXT");
}
target.setPublicOption(true);
if (!CollectionUtils.isEmpty(source.getDescriptions())) {
Set<com.salesmanager.core.model.customer.attribute.CustomerOptionDescription> descriptions = new HashSet<com.salesmanager.core.model.customer.attribute.CustomerOptionDescription>();
for (CustomerOptionDescription desc : source.getDescriptions()) {
com.salesmanager.core.model.customer.attribute.CustomerOptionDescription description = new com.salesmanager.core.model.customer.attribute.CustomerOptionDescription();
Language lang = languageService.getByCode(desc.getLanguage());
if (lang == null) {
throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]");
}
description.setLanguage(lang);
description.setName(desc.getName());
description.setTitle(desc.getTitle());
description.setCustomerOption(target);
descriptions.add(description);
}
target.setDescriptions(descriptions);
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class PersistableCustomerOptionValuePopulator method populate.
@Override
public CustomerOptionValue populate(PersistableCustomerOptionValue source, CustomerOptionValue target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(languageService, "Requires to set LanguageService");
try {
target.setCode(source.getCode());
target.setMerchantStore(store);
target.setSortOrder(source.getOrder());
if (!CollectionUtils.isEmpty(source.getDescriptions())) {
Set<com.salesmanager.core.model.customer.attribute.CustomerOptionValueDescription> descriptions = new HashSet<com.salesmanager.core.model.customer.attribute.CustomerOptionValueDescription>();
for (CustomerOptionValueDescription desc : source.getDescriptions()) {
com.salesmanager.core.model.customer.attribute.CustomerOptionValueDescription description = new com.salesmanager.core.model.customer.attribute.CustomerOptionValueDescription();
Language lang = languageService.getByCode(desc.getLanguage());
if (lang == null) {
throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]");
}
description.setLanguage(lang);
description.setName(desc.getName());
description.setTitle(desc.getTitle());
description.setCustomerOptionValue(target);
descriptions.add(description);
}
target.setDescriptions(descriptions);
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class ReadableCustomerDeliveryAddressPopulator method populate.
@Override
public ReadableDelivery populate(Delivery source, ReadableDelivery target, MerchantStore store, Language language) throws ConversionException {
if (countryService == null) {
throw new ConversionException("countryService must be set");
}
if (zoneService == null) {
throw new ConversionException("zoneService must be set");
}
target.setLatitude(source.getLatitude());
target.setLongitude(source.getLongitude());
if (StringUtils.isNotBlank(source.getCity())) {
target.setCity(source.getCity());
}
if (StringUtils.isNotBlank(source.getCompany())) {
target.setCompany(source.getCompany());
}
if (StringUtils.isNotBlank(source.getAddress())) {
target.setAddress(source.getAddress());
}
if (StringUtils.isNotBlank(source.getFirstName())) {
target.setFirstName(source.getFirstName());
}
if (StringUtils.isNotBlank(source.getLastName())) {
target.setLastName(source.getLastName());
}
if (StringUtils.isNotBlank(source.getPostalCode())) {
target.setPostalCode(source.getPostalCode());
}
if (StringUtils.isNotBlank(source.getTelephone())) {
target.setPhone(source.getTelephone());
}
target.setStateProvince(source.getState());
if (source.getTelephone() == null) {
target.setPhone(source.getTelephone());
}
target.setAddress(source.getAddress());
if (source.getCountry() != null) {
target.setCountry(source.getCountry().getIsoCode());
// resolve country name
try {
Map<String, Country> countries = countryService.getCountriesMap(language);
Country c = countries.get(source.getCountry().getIsoCode());
if (c != null) {
target.setCountryName(c.getName());
}
} catch (ServiceException e) {
// TODO Auto-generated catch block
throw new ConversionException(e);
}
}
if (source.getZone() != null) {
target.setZone(source.getZone().getCode());
// resolve zone name
try {
Map<String, Zone> zones = zoneService.getZones(language);
Zone z = zones.get(source.getZone().getCode());
if (z != null) {
target.setProvinceName(z.getName());
}
} catch (ServiceException e) {
// TODO Auto-generated catch block
throw new ConversionException(e);
}
}
return target;
}
use of com.salesmanager.core.business.exception.ConversionException 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;
}
Aggregations