use of com.salesmanager.shop.model.tax.PersistableTaxClass in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method createTaxClass.
@Override
public Entity createTaxClass(PersistableTaxClass taxClass, MerchantStore store, Language language) {
Validate.notNull(taxClass, "TaxClass cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
if (this.existsTaxClass(taxClass.getCode(), store, language)) {
throw new OperationNotAllowedException("Tax class [" + taxClass.getCode() + "] already exist for store [" + store.getCode() + "]");
}
taxClass.setStore(store.getCode());
TaxClass model = persistableTaxClassMapper.convert(taxClass, store, language);
model = taxClassService.saveOrUpdate(model);
;
Entity id = new Entity();
id.setId(model.getId());
return id;
} catch (ServiceException e) {
LOGGER.error("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.shop.model.tax.PersistableTaxClass in project shopizer by shopizer-ecommerce.
the class PersistableTaxClassMapper method convert.
@Override
public TaxClass convert(PersistableTaxClass source, MerchantStore store, Language language) {
Validate.notNull(source, "PersistableTaxClass cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
TaxClass taxClass = new TaxClass();
taxClass.setMerchantStore(store);
taxClass.setTitle(source.getName());
taxClass.setId(source.getId());
return this.merge(source, taxClass, store, language);
}
use of com.salesmanager.shop.model.tax.PersistableTaxClass in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method updateTaxClass.
@Override
public void updateTaxClass(Long id, PersistableTaxClass taxClass, MerchantStore store, Language language) {
Validate.notNull(taxClass, "TaxClass cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
TaxClass model = taxClassService.getById(id);
if (model == null) {
throw new ResourceNotFoundException("TaxClass not found [" + id + "] for store [" + store.getCode() + "]");
} else {
if (!model.getMerchantStore().getCode().equals(store.getCode())) {
throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot update tax class [" + taxClass.getCode() + "]");
}
}
model = persistableTaxClassMapper.convert(taxClass, store, language);
taxClassService.saveOrUpdate(model);
} catch (ServiceException e) {
LOGGER.error("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.shop.model.tax.PersistableTaxClass in project shopizer by shopizer-ecommerce.
the class TaxRateIntegrationTest method manageTaxClass.
@Test
public void manageTaxClass() throws Exception {
// create tax class
PersistableTaxClass taxClass = new PersistableTaxClass();
taxClass.setCode("TESTTX");
taxClass.setName("Test tax class");
final HttpEntity<PersistableTaxClass> taxClassEntity = new HttpEntity<>(taxClass, getHeader());
final ResponseEntity<Entity> response = testRestTemplate.postForEntity(String.format("/api/v1/private/tax/class/"), 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/class/unique?code=" + taxClass.getCode()), HttpMethod.GET, httpEntity, EntityExists.class);
assertTrue(exists.getBody().isExists());
/**
* //list 1 taxClass
* @SuppressWarnings("rawtypes")
* final ResponseEntity<ReadableEntityList> listOfTaxClasses = testRestTemplate.exchange(String.format("/private/tax/class"), HttpMethod.GET,
* httpEntity, ReadableEntityList.class);
*
* assertTrue(listOfTaxClasses.getBody().getRecordsTotal() == 1);
*/
}
Aggregations