Search in sources :

Example 56 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class PersistableInventoryMapper method getDescription.

private ProductPriceDescription getDescription(com.salesmanager.shop.model.catalog.product.ProductPriceDescription desc) throws ConversionException {
    ProductPriceDescription target = new ProductPriceDescription();
    target.setDescription(desc.getDescription());
    target.setName(desc.getName());
    target.setTitle(desc.getTitle());
    target.setId(null);
    if (isPositive(desc.getId())) {
        target.setId(desc.getId());
    }
    Language lang = getLanguage(desc);
    target.setLanguage(lang);
    return target;
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)

Example 57 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class CustomerPopulator method populate.

/**
 * Creates a Customer entity ready to be saved
 */
@Override
public Customer populate(PersistableCustomer source, Customer target, MerchantStore store, Language language) throws ConversionException {
    try {
        if (source.getId() != null && source.getId() > 0) {
            target.setId(source.getId());
        }
        if (!StringUtils.isBlank(source.getPassword())) {
            target.setPassword(passwordEncoder.encode(source.getPassword()));
            target.setNick(source.getUserName());
            target.setAnonymous(false);
        }
        if (source.getBilling() != null) {
            target.setBilling(new Billing());
            if (!StringUtils.isEmpty(source.getFirstName())) {
                target.getBilling().setFirstName(source.getFirstName());
            }
            if (!StringUtils.isEmpty(source.getLastName())) {
                target.getBilling().setLastName(source.getLastName());
            }
        }
        if (!StringUtils.isBlank(source.getProvider())) {
            target.setProvider(source.getProvider());
        }
        if (!StringUtils.isBlank(source.getEmailAddress())) {
            target.setEmailAddress(source.getEmailAddress());
        }
        if (source.getGender() != null && target.getGender() == null) {
            target.setGender(com.salesmanager.core.model.customer.CustomerGender.valueOf(source.getGender()));
        }
        if (target.getGender() == null) {
            target.setGender(com.salesmanager.core.model.customer.CustomerGender.M);
        }
        Map<String, Country> countries = countryService.getCountriesMap(language);
        Map<String, Zone> zones = zoneService.getZones(language);
        target.setMerchantStore(store);
        Address sourceBilling = source.getBilling();
        if (sourceBilling != null) {
            Billing billing = target.getBilling();
            billing.setAddress(sourceBilling.getAddress());
            billing.setCity(sourceBilling.getCity());
            billing.setCompany(sourceBilling.getCompany());
            // billing.setCountry(country);
            if (!StringUtils.isEmpty(sourceBilling.getFirstName()))
                billing.setFirstName(sourceBilling.getFirstName());
            if (!StringUtils.isEmpty(sourceBilling.getLastName()))
                billing.setLastName(sourceBilling.getLastName());
            billing.setTelephone(sourceBilling.getPhone());
            billing.setPostalCode(sourceBilling.getPostalCode());
            billing.setState(sourceBilling.getStateProvince());
            Country billingCountry = null;
            if (!StringUtils.isBlank(sourceBilling.getCountry())) {
                billingCountry = countries.get(sourceBilling.getCountry());
                if (billingCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
                }
                billing.setCountry(billingCountry);
            }
            if (billingCountry != null && !StringUtils.isBlank(sourceBilling.getZone())) {
                Zone zone = zoneService.getByCode(sourceBilling.getZone());
                if (zone == null) {
                    throw new ConversionException("Unsuported zone code " + sourceBilling.getZone());
                }
                Zone zoneDescription = zones.get(zone.getCode());
                billing.setZone(zoneDescription);
            }
        // target.setBilling(billing);
        }
        if (target.getBilling() == null && source.getBilling() != null) {
            LOG.info("Setting default values for billing");
            Billing billing = new Billing();
            Country billingCountry = null;
            if (StringUtils.isNotBlank(source.getBilling().getCountry())) {
                billingCountry = countries.get(source.getBilling().getCountry());
                if (billingCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
                }
                billing.setCountry(billingCountry);
                target.setBilling(billing);
            }
        }
        Address sourceShipping = source.getDelivery();
        if (sourceShipping != null) {
            Delivery delivery = new Delivery();
            delivery.setAddress(sourceShipping.getAddress());
            delivery.setCity(sourceShipping.getCity());
            delivery.setCompany(sourceShipping.getCompany());
            delivery.setFirstName(sourceShipping.getFirstName());
            delivery.setLastName(sourceShipping.getLastName());
            delivery.setTelephone(sourceShipping.getPhone());
            delivery.setPostalCode(sourceShipping.getPostalCode());
            delivery.setState(sourceShipping.getStateProvince());
            Country deliveryCountry = null;
            if (!StringUtils.isBlank(sourceShipping.getCountry())) {
                deliveryCountry = countries.get(sourceShipping.getCountry());
                if (deliveryCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
                }
                delivery.setCountry(deliveryCountry);
            }
            if (deliveryCountry != null && !StringUtils.isBlank(sourceShipping.getZone())) {
                Zone zone = zoneService.getByCode(sourceShipping.getZone());
                if (zone == null) {
                    throw new ConversionException("Unsuported zone code " + sourceShipping.getZone());
                }
                Zone zoneDescription = zones.get(zone.getCode());
                delivery.setZone(zoneDescription);
            }
            target.setDelivery(delivery);
        }
        if (source.getRating() != null && source.getRating().doubleValue() > 0) {
            target.setCustomerReviewAvg(new BigDecimal(source.getRating().doubleValue()));
        }
        if (source.getRatingCount() > 0) {
            target.setCustomerReviewCount(source.getRatingCount());
        }
        if (target.getDelivery() == null && source.getDelivery() != null) {
            LOG.info("Setting default value for delivery");
            Delivery delivery = new Delivery();
            Country deliveryCountry = null;
            if (StringUtils.isNotBlank(source.getDelivery().getCountry())) {
                deliveryCountry = countries.get(source.getDelivery().getCountry());
                if (deliveryCountry == null) {
                    throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
                }
                delivery.setCountry(deliveryCountry);
                target.setDelivery(delivery);
            }
        }
        if (source.getAttributes() != null) {
            for (PersistableCustomerAttribute attr : source.getAttributes()) {
                CustomerOption customerOption = customerOptionService.getById(attr.getCustomerOption().getId());
                if (customerOption == null) {
                    throw new ConversionException("Customer option id " + attr.getCustomerOption().getId() + " does not exist");
                }
                CustomerOptionValue customerOptionValue = customerOptionValueService.getById(attr.getCustomerOptionValue().getId());
                if (customerOptionValue == null) {
                    throw new ConversionException("Customer option value id " + attr.getCustomerOptionValue().getId() + " does not exist");
                }
                if (customerOption.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Invalid customer option id ");
                }
                if (customerOptionValue.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Invalid customer option value id ");
                }
                CustomerAttribute attribute = new CustomerAttribute();
                attribute.setCustomer(target);
                attribute.setCustomerOption(customerOption);
                attribute.setCustomerOptionValue(customerOptionValue);
                attribute.setTextValue(attr.getTextValue());
                target.getAttributes().add(attribute);
            }
        }
        if (target.getDefaultLanguage() == null) {
            Language lang = source.getLanguage() == null ? language : languageService.getByCode(source.getLanguage());
            target.setDefaultLanguage(lang);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Address(com.salesmanager.shop.model.customer.address.Address) Zone(com.salesmanager.core.model.reference.zone.Zone) BigDecimal(java.math.BigDecimal) ConversionException(com.salesmanager.core.business.exception.ConversionException) CustomerOption(com.salesmanager.core.model.customer.attribute.CustomerOption) CustomerOptionValue(com.salesmanager.core.model.customer.attribute.CustomerOptionValue) Language(com.salesmanager.core.model.reference.language.Language) PersistableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.PersistableCustomerAttribute) CustomerAttribute(com.salesmanager.core.model.customer.attribute.CustomerAttribute) Billing(com.salesmanager.core.model.common.Billing) Country(com.salesmanager.core.model.reference.country.Country) Delivery(com.salesmanager.core.model.common.Delivery) PersistableCustomerAttribute(com.salesmanager.shop.model.customer.attribute.PersistableCustomerAttribute)

Example 58 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class PersistableCustomerReviewPopulator method populate.

@Override
public CustomerReview populate(PersistableCustomerReview source, CustomerReview target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(customerService, "customerService cannot be null");
    Validate.notNull(languageService, "languageService cannot be null");
    Validate.notNull(source.getRating(), "Rating cannot bot be null");
    try {
        if (target == null) {
            target = new CustomerReview();
        }
        if (source.getDate() == null) {
            String date = DateUtil.formatDate(new Date());
            source.setDate(date);
        }
        target.setReviewDate(DateUtil.getDate(source.getDate()));
        if (source.getId() != null && source.getId().longValue() == 0) {
            source.setId(null);
        } else {
            target.setId(source.getId());
        }
        Customer reviewer = customerService.getById(source.getCustomerId());
        Customer reviewed = customerService.getById(source.getReviewedCustomer());
        target.setReviewRating(source.getRating());
        target.setCustomer(reviewer);
        target.setReviewedCustomer(reviewed);
        Language lang = languageService.getByCode(language.getCode());
        if (lang == null) {
            throw new ConversionException("Invalid language code, use iso codes (en, fr ...)");
        }
        CustomerReviewDescription description = new CustomerReviewDescription();
        description.setDescription(source.getDescription());
        description.setLanguage(lang);
        description.setName("-");
        description.setCustomerReview(target);
        Set<CustomerReviewDescription> descriptions = new HashSet<CustomerReviewDescription>();
        descriptions.add(description);
        target.setDescriptions(descriptions);
    } catch (Exception e) {
        throw new ConversionException("Cannot populate CustomerReview", e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) Date(java.util.Date) ConversionException(com.salesmanager.core.business.exception.ConversionException) CustomerReviewDescription(com.salesmanager.core.model.customer.review.CustomerReviewDescription) HashSet(java.util.HashSet)

Example 59 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class PersistableCategoryPopulator method buildDescription.

private com.salesmanager.core.model.catalog.category.CategoryDescription buildDescription(com.salesmanager.shop.model.catalog.category.CategoryDescription source, com.salesmanager.core.model.catalog.category.CategoryDescription target) throws Exception {
    // com.salesmanager.core.model.catalog.category.CategoryDescription desc = new com.salesmanager.core.model.catalog.category.CategoryDescription();
    target.setCategoryHighlight(source.getHighlights());
    target.setDescription(source.getDescription());
    target.setName(source.getName());
    target.setMetatagDescription(source.getMetaDescription());
    target.setMetatagTitle(source.getTitle());
    target.setSeUrl(source.getFriendlyUrl());
    Language lang = languageService.getByCode(source.getLanguage());
    if (lang == null) {
        throw new ConversionException("Language is null for code " + source.getLanguage() + " use language ISO code [en, fr ...]");
    }
    // description.setId(description.getId());
    target.setLanguage(lang);
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language)

Example 60 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class PersistableProductOptionValuePopulator method populate.

@Override
public ProductOptionValue populate(PersistableProductOptionValue source, ProductOptionValue target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(languageService, "Requires to set LanguageService");
    try {
        target.setMerchantStore(store);
        target.setProductOptionValueSortOrder(source.getOrder());
        target.setCode(source.getCode());
        if (!CollectionUtils.isEmpty(source.getDescriptions())) {
            Set<com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription> descriptions = new HashSet<com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription>();
            for (ProductOptionValueDescription desc : source.getDescriptions()) {
                com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription description = new com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription();
                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.setProductOptionValue(target);
                descriptions.add(description);
            }
            target.setDescriptions(descriptions);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language) ProductOptionValueDescription(com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription) HashSet(java.util.HashSet)

Aggregations

Language (com.salesmanager.core.model.reference.language.Language)148 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)115 ArrayList (java.util.ArrayList)58 List (java.util.List)56 ServiceException (com.salesmanager.core.business.exception.ServiceException)55 Collectors (java.util.stream.Collectors)50 Product (com.salesmanager.core.model.catalog.product.Product)45 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)42 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)38 Autowired (org.springframework.beans.factory.annotation.Autowired)35 ConversionException (com.salesmanager.core.business.exception.ConversionException)30 Category (com.salesmanager.core.model.catalog.category.Category)30 Validate (org.apache.commons.lang3.Validate)29 Customer (com.salesmanager.core.model.customer.Customer)28 Optional (java.util.Optional)28 Inject (javax.inject.Inject)28 Service (org.springframework.stereotype.Service)28 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)27 ImageFilePath (com.salesmanager.shop.utils.ImageFilePath)25