Search in sources :

Example 1 with TaxRate

use of com.salesmanager.core.model.tax.taxrate.TaxRate 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 2 with TaxRate

use of com.salesmanager.core.model.tax.taxrate.TaxRate in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method taxRateById.

// get by id
private TaxRate taxRateById(Long id, MerchantStore store, Language language) {
    Validate.notNull(id, "TaxRate id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxRate model = taxRateService.getById(id, store);
        if (model == null) {
            throw new ResourceNotFoundException("TaxRate not found [" + id + "]");
        }
        return model;
    } catch (Exception e) {
        LOGGER.error("Error while getting taxRate [" + id + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxRate [" + id + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with TaxRate

use of com.salesmanager.core.model.tax.taxrate.TaxRate in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method createTaxRate.

@Override
public Entity createTaxRate(PersistableTaxRate taxRate, MerchantStore store, Language language) {
    Validate.notNull(taxRate, "TaxRate cannot be null");
    Validate.notNull(taxRate.getCode(), "TaxRate code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxRate model = taxRateService.getByCode(taxRate.getCode(), store);
        if (model != null) {
            throw new OperationNotAllowedException("Tax rate [" + taxRate.getCode() + "] already exist for store [" + store.getCode() + "]");
        }
        model = persistableTaxRateMapper.convert(taxRate, store, language);
        model = taxRateService.saveOrUpdate(model);
        Entity id = new Entity();
        id.setId(model.getId());
        return id;
    } catch (ServiceException e) {
        LOGGER.error("Error while saving taxRate [" + taxRate.getCode() + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while saving taxRate [" + taxRate.getCode() + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : Entity(com.salesmanager.shop.model.entity.Entity) 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) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with TaxRate

use of com.salesmanager.core.model.tax.taxrate.TaxRate in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method existsTaxRate.

@Override
public boolean existsTaxRate(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "TaxRate code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    TaxRate rate = taxRateByCode(code, store, language);
    if (rate == null) {
        return false;
    }
    return true;
}
Also used : TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate)

Example 5 with TaxRate

use of com.salesmanager.core.model.tax.taxrate.TaxRate in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method taxRateByCode.

// get by code
private TaxRate taxRateByCode(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "TaxRate code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxRate model = taxRateService.getByCode(code, store);
        if (model == null) {
            throw new ResourceNotFoundException("TaxRate not found [" + code + "] for store [" + store.getCode() + "]");
        }
        if (model != null) {
            if (!model.getMerchantStore().getCode().equals(store.getCode())) {
                throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot get tax rate [" + code + "]");
            }
        }
        return model;
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxRate [" + code + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxRate [" + code + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : 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) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

TaxRate (com.salesmanager.core.model.tax.taxrate.TaxRate)7 PersistableTaxRate (com.salesmanager.shop.model.tax.PersistableTaxRate)6 ReadableTaxRate (com.salesmanager.shop.model.tax.ReadableTaxRate)6 ServiceException (com.salesmanager.core.business.exception.ServiceException)5 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)5 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)3 TaxClass (com.salesmanager.core.model.tax.taxclass.TaxClass)2 Entity (com.salesmanager.shop.model.entity.Entity)2 TaxClassService (com.salesmanager.core.business.services.tax.TaxClassService)1 TaxRateService (com.salesmanager.core.business.services.tax.TaxRateService)1 Billing (com.salesmanager.core.model.common.Billing)1 Delivery (com.salesmanager.core.model.common.Delivery)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Country (com.salesmanager.core.model.reference.country.Country)1 Language (com.salesmanager.core.model.reference.language.Language)1 Zone (com.salesmanager.core.model.reference.zone.Zone)1 ShippingSummary (com.salesmanager.core.model.shipping.ShippingSummary)1 ShoppingCartItem (com.salesmanager.core.model.shoppingcart.ShoppingCartItem)1