use of com.salesmanager.shop.model.tax.PersistableTaxRate 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.shop.model.tax.PersistableTaxRate in project shopizer by shopizer-ecommerce.
the class TaxRateIntegrationTest method manageTaxRates.
@Test
public void manageTaxRates() throws Exception {
// create tax class
PersistableTaxRate taxRate = new PersistableTaxRate();
taxRate.setCode("taxcode1");
taxRate.setCountry("US");
taxRate.setPriority(0);
taxRate.setRate(new BigDecimal(5));
taxRate.setStore("DEFAULT");
taxRate.setTaxClass("DEFAULT");
taxRate.setZone("NY");
// descriptions
TaxRateDescription en = new TaxRateDescription();
en.setLanguage("en");
en.setName("TaxCode1EN");
en.setDescription("TaxCode1EN description");
TaxRateDescription fr = new TaxRateDescription();
fr.setLanguage("fr");
fr.setName("TaxCode1FR");
fr.setDescription("TaxCode1fr description");
taxRate.getDescriptions().add(en);
taxRate.getDescriptions().add(fr);
final HttpEntity<PersistableTaxRate> taxClassEntity = new HttpEntity<>(taxRate, getHeader());
final ResponseEntity<Entity> response = testRestTemplate.postForEntity(String.format("/api/v1/private/tax/rate/"), taxClassEntity, Entity.class);
Entity e = response.getBody();
assertNotNull(e.getId());
assertTrue(e.getId() > 0);
final HttpEntity<String> httpEntity = new HttpEntity<>(getHeader());
// tax class exists
final ResponseEntity<EntityExists> exists = testRestTemplate.exchange(String.format("/api/v1/private/tax/rate/unique?code=" + taxRate.getCode()), HttpMethod.GET, httpEntity, EntityExists.class);
assertTrue(exists.getBody().isExists());
}
use of com.salesmanager.shop.model.tax.PersistableTaxRate in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method updateTaxRate.
@Override
public void updateTaxRate(Long id, PersistableTaxRate taxRate, MerchantStore store, Language language) {
Validate.notNull(taxRate, "TaxRate cannot be null");
Validate.notNull(id, "TaxRate id cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
TaxRate model = taxRateById(id, store, language);
model = persistableTaxRateMapper.merge(taxRate, model, store, language);
try {
model = taxRateService.saveOrUpdate(model);
} 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);
}
}
Aggregations