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