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);
}
}
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);
}
}
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;
}
Aggregations