Search in sources :

Example 1 with PersistableTaxClass

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);
    }
}
Also used : Entity(com.salesmanager.shop.model.entity.Entity) 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) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with PersistableTaxClass

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);
}
Also used : TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass)

Example 3 with PersistableTaxClass

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);
    }
}
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 4 with PersistableTaxClass

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);
 */
}
Also used : Entity(com.salesmanager.shop.model.entity.Entity) HttpEntity(org.springframework.http.HttpEntity) ResponseEntity(org.springframework.http.ResponseEntity) HttpEntity(org.springframework.http.HttpEntity) EntityExists(com.salesmanager.shop.model.entity.EntityExists) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PersistableTaxClass (com.salesmanager.shop.model.tax.PersistableTaxClass)4 TaxClass (com.salesmanager.core.model.tax.taxclass.TaxClass)3 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 Entity (com.salesmanager.shop.model.entity.Entity)2 ReadableTaxClass (com.salesmanager.shop.model.tax.ReadableTaxClass)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 EntityExists (com.salesmanager.shop.model.entity.EntityExists)1 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 HttpEntity (org.springframework.http.HttpEntity)1 ResponseEntity (org.springframework.http.ResponseEntity)1