Search in sources :

Example 41 with Language

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

the class TaxFacadeImpl method taxClasses.

@Override
public ReadableEntityList<ReadableTaxClass> taxClasses(MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        List<TaxClass> models = taxClassService.listByStore(store);
        List<ReadableTaxClass> taxClasses = models.stream().map(t -> convertToReadableTaxClass(t, store, language)).collect(Collectors.toList());
        ReadableEntityList<ReadableTaxClass> list = new ReadableEntityList<ReadableTaxClass>();
        list.setItems(taxClasses);
        list.setNumber(taxClasses.size());
        list.setTotalPages(1);
        list.setRecordsTotal(taxClasses.size());
        return list;
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxClasses for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxClasses for store [" + store.getCode() + "]", e);
    }
}
Also used : PersistableTaxClassMapper(com.salesmanager.shop.mapper.tax.PersistableTaxClassMapper) Entity(com.salesmanager.shop.model.entity.Entity) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) TaxRateService(com.salesmanager.core.business.services.tax.TaxRateService) PersistableTaxRateMapper(com.salesmanager.shop.mapper.tax.PersistableTaxRateMapper) TaxClassService(com.salesmanager.core.business.services.tax.TaxClassService) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) Logger(org.slf4j.Logger) TaxFacade(com.salesmanager.shop.store.controller.tax.facade.TaxFacade) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClassMapper(com.salesmanager.shop.mapper.tax.ReadableTaxClassMapper) Collectors(java.util.stream.Collectors) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) List(java.util.List) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) Validate(org.apache.commons.lang3.Validate) ReadableTaxRateMapper(com.salesmanager.shop.mapper.tax.ReadableTaxRateMapper) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 42 with Language

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

the class TaxFacadeImpl method taxRates.

@Override
public ReadableEntityList<ReadableTaxRate> taxRates(MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        List<TaxRate> rates = taxRateService.listByStore(store, language);
        List<ReadableTaxRate> readableRates = rates.stream().map(r -> readableTaxRateMapper.convert(r, store, language)).collect(Collectors.toList());
        ReadableEntityList<ReadableTaxRate> returnRates = new ReadableEntityList<ReadableTaxRate>();
        returnRates.setItems(readableRates);
        returnRates.setTotalPages(1);
        returnRates.setNumber(readableRates.size());
        returnRates.setRecordsTotal(readableRates.size());
        return returnRates;
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxRates for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxRates for store [" + store.getCode() + "]", e);
    }
}
Also used : PersistableTaxClassMapper(com.salesmanager.shop.mapper.tax.PersistableTaxClassMapper) Entity(com.salesmanager.shop.model.entity.Entity) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) TaxRateService(com.salesmanager.core.business.services.tax.TaxRateService) PersistableTaxRateMapper(com.salesmanager.shop.mapper.tax.PersistableTaxRateMapper) TaxClassService(com.salesmanager.core.business.services.tax.TaxClassService) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) Logger(org.slf4j.Logger) TaxFacade(com.salesmanager.shop.store.controller.tax.facade.TaxFacade) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClassMapper(com.salesmanager.shop.mapper.tax.ReadableTaxClassMapper) Collectors(java.util.stream.Collectors) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) List(java.util.List) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) Validate(org.apache.commons.lang3.Validate) ReadableTaxRateMapper(com.salesmanager.shop.mapper.tax.ReadableTaxRateMapper) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 43 with Language

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

the class ProductCommonFacadeImpl method addProductToCategory.

@Override
public ReadableProduct addProductToCategory(Category category, Product product, Language language) {
    Validate.notNull(category, "Category cannot be null");
    Validate.notNull(product, "Product cannot be null");
    // not alloweed if category already attached
    List<Category> assigned = product.getCategories().stream().filter(cat -> cat.getId().longValue() == category.getId().longValue()).collect(Collectors.toList());
    if (assigned.size() > 0) {
        throw new OperationNotAllowedException("Category with id [" + category.getId() + "] already attached to product [" + product.getId() + "]");
    }
    product.getCategories().add(category);
    ReadableProduct readableProduct = new ReadableProduct();
    try {
        productService.update(product);
        ReadableProductPopulator populator = new ReadableProductPopulator();
        populator.setPricingService(pricingService);
        populator.setimageUtils(imageUtils);
        populator.populate(product, readableProduct, product.getMerchantStore(), language);
    } catch (Exception e) {
        throw new RuntimeException("Exception when adding product [" + product.getId() + "] to category [" + category.getId() + "]", e);
    }
    return readableProduct;
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) Date(java.util.Date) DateUtil(com.salesmanager.shop.utils.DateUtil) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) PersistableProductPopulator(com.salesmanager.shop.populator.catalog.PersistableProductPopulator) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) CustomerService(com.salesmanager.core.business.services.customer.CustomerService) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductReviewService(com.salesmanager.core.business.services.catalog.product.review.ProductReviewService) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) ProductRelationshipService(com.salesmanager.core.business.services.catalog.product.relationship.ProductRelationshipService) PersistableProductReviewPopulator(com.salesmanager.shop.populator.catalog.PersistableProductReviewPopulator) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Collectors(java.util.stream.Collectors) ProductCommonFacade(com.salesmanager.shop.store.controller.product.facade.ProductCommonFacade) Category(com.salesmanager.core.model.catalog.category.Category) ReadableProductReviewPopulator(com.salesmanager.shop.populator.catalog.ReadableProductReviewPopulator) List(java.util.List) Validate(org.apache.commons.lang3.Validate) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ProductPriceEntity(com.salesmanager.shop.model.catalog.product.ProductPriceEntity) Category(com.salesmanager.core.model.catalog.category.Category) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 44 with Language

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

the class ProductOptionSetFacadeImpl method list.

@Override
public List<ReadableProductOptionSet> list(MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    try {
        List<ProductOptionSet> optionSets = productOptionSetService.listByStore(store, language);
        return optionSets.stream().map(opt -> this.convert(opt, store, language)).collect(Collectors.toList());
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while listing ProductOptionSet", e);
    }
}
Also used : OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductOptionSetFacade(com.salesmanager.shop.store.controller.product.facade.ProductOptionSetFacade) ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ProductOptionSetService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionSetService) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) List(java.util.List) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Validate(org.apache.commons.lang3.Validate) ReadableProductOptionSetMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionSetMapper) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) PersistableProductOptionSetMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionSetMapper) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) ProductTypeFacade(com.salesmanager.shop.store.controller.product.facade.ProductTypeFacade) ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 45 with Language

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

the class InitializationDatabaseImpl method createMerchant.

private void createMerchant() throws ServiceException {
    LOGGER.info(String.format("%s : Creating merchant ", name));
    Date date = new Date(System.currentTimeMillis());
    Language en = languageService.getByCode("en");
    Country ca = countryService.getByCode("CA");
    Currency currency = currencyService.getByCode("CAD");
    Zone qc = zoneService.getByCode("QC");
    List<Language> supportedLanguages = new ArrayList<Language>();
    supportedLanguages.add(en);
    // create a merchant
    MerchantStore store = new MerchantStore();
    store.setCountry(ca);
    store.setCurrency(currency);
    store.setDefaultLanguage(en);
    store.setInBusinessSince(date);
    store.setZone(qc);
    store.setStorename("Default store");
    store.setStorephone("888-888-8888");
    store.setCode(MerchantStore.DEFAULT_STORE);
    store.setStorecity("My city");
    store.setStoreaddress("1234 Street address");
    store.setStorepostalcode("H2H-2H2");
    store.setStoreEmailAddress("john@test.com");
    store.setDomainName("localhost:8080");
    store.setStoreTemplate("december");
    store.setRetailer(true);
    store.setLanguages(supportedLanguages);
    merchantService.create(store);
    TaxClass taxclass = new TaxClass(TaxClass.DEFAULT_TAX_CLASS);
    taxclass.setMerchantStore(store);
    taxClassService.create(taxclass);
    // create default manufacturer
    Manufacturer defaultManufacturer = new Manufacturer();
    defaultManufacturer.setCode("DEFAULT");
    defaultManufacturer.setMerchantStore(store);
    ManufacturerDescription manufacturerDescription = new ManufacturerDescription();
    manufacturerDescription.setLanguage(en);
    manufacturerDescription.setName("DEFAULT");
    manufacturerDescription.setManufacturer(defaultManufacturer);
    manufacturerDescription.setDescription("DEFAULT");
    defaultManufacturer.getDescriptions().add(manufacturerDescription);
    manufacturerService.create(defaultManufacturer);
    Optin newsletter = new Optin();
    newsletter.setCode(OptinType.NEWSLETTER.name());
    newsletter.setMerchant(store);
    newsletter.setOptinType(OptinType.NEWSLETTER);
    optinService.create(newsletter);
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) Optin(com.salesmanager.core.model.system.optin.Optin) Zone(com.salesmanager.core.model.reference.zone.Zone) Currency(com.salesmanager.core.model.reference.currency.Currency) ArrayList(java.util.ArrayList) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) Country(com.salesmanager.core.model.reference.country.Country) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Date(java.sql.Date)

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