Search in sources :

Example 1 with ReadableTaxClass

use of com.salesmanager.shop.model.tax.ReadableTaxClass 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 2 with ReadableTaxClass

use of com.salesmanager.shop.model.tax.ReadableTaxClass in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method taxClass.

@Override
public ReadableTaxClass taxClass(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "TaxClass code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxClass model = taxClassService.getByCode(code, store);
        if (model == null) {
            throw new ResourceNotFoundException("TaxClass 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 class [" + code + "]");
            }
        }
        return readableTaxClassMapper.convert(model, store, language);
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxClass [" + code + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxClass [" + code + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with ReadableTaxClass

use of com.salesmanager.shop.model.tax.ReadableTaxClass in project shopizer by shopizer-ecommerce.

the class ReadableTaxClassMapper method convert.

@Override
public ReadableTaxClass convert(TaxClass source, MerchantStore store, Language language) {
    ReadableTaxClass taxClass = new ReadableTaxClass();
    taxClass.setId(source.getId());
    taxClass.setCode(source.getCode());
    taxClass.setName(source.getTitle());
    taxClass.setStore(store.getCode());
    return taxClass;
}
Also used : ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass)

Aggregations

ReadableTaxClass (com.salesmanager.shop.model.tax.ReadableTaxClass)3 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 TaxClass (com.salesmanager.core.model.tax.taxclass.TaxClass)2 PersistableTaxClass (com.salesmanager.shop.model.tax.PersistableTaxClass)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)2 TaxClassService (com.salesmanager.core.business.services.tax.TaxClassService)1 TaxRateService (com.salesmanager.core.business.services.tax.TaxRateService)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 TaxRate (com.salesmanager.core.model.tax.taxrate.TaxRate)1 PersistableTaxClassMapper (com.salesmanager.shop.mapper.tax.PersistableTaxClassMapper)1 PersistableTaxRateMapper (com.salesmanager.shop.mapper.tax.PersistableTaxRateMapper)1 ReadableTaxClassMapper (com.salesmanager.shop.mapper.tax.ReadableTaxClassMapper)1 ReadableTaxRateMapper (com.salesmanager.shop.mapper.tax.ReadableTaxRateMapper)1 Entity (com.salesmanager.shop.model.entity.Entity)1 ReadableEntityList (com.salesmanager.shop.model.entity.ReadableEntityList)1 PersistableTaxRate (com.salesmanager.shop.model.tax.PersistableTaxRate)1 ReadableTaxRate (com.salesmanager.shop.model.tax.ReadableTaxRate)1