Search in sources :

Example 1 with Entity

use of com.salesmanager.shop.model.entity.Entity 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 Entity

use of com.salesmanager.shop.model.entity.Entity 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);
    }
}
Also used : Entity(com.salesmanager.shop.model.entity.Entity) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with Entity

use of com.salesmanager.shop.model.entity.Entity 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());
}
Also used : TaxRateDescription(com.salesmanager.shop.model.tax.TaxRateDescription) 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) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Entity

use of com.salesmanager.shop.model.entity.Entity in project shopizer by shopizer-ecommerce.

the class ProductAttributeOptionApi method createAttribute.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = { "/private/product/{id}/attribute" }, method = RequestMethod.POST)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public Entity createAttribute(@PathVariable Long id, @Valid @RequestBody PersistableProductAttribute attribute, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
    ReadableProductAttributeEntity attributeEntity = productOptionFacade.saveAttribute(id, attribute, merchantStore, language);
    Entity entity = new Entity();
    entity.setId(attributeEntity.getId());
    return entity;
}
Also used : ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) Entity(com.salesmanager.shop.model.entity.Entity) PersistableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.PersistableProductOptionEntity) CodeEntity(com.salesmanager.shop.model.entity.CodeEntity) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ResponseEntity(org.springframework.http.ResponseEntity) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with Entity

use of com.salesmanager.shop.model.entity.Entity in project shopizer by shopizer-ecommerce.

the class ProductTypeApi method create.

@PostMapping(value = "/private/products/type", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(httpMethod = "POST", value = "Create product type", notes = "", produces = "application/json", response = Entity.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public Entity create(@RequestBody PersistableProductType type, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    Long id = productTypeFacade.save(type, merchantStore, language);
    Entity entity = new Entity();
    entity.setId(id);
    return entity;
}
Also used : Entity(com.salesmanager.shop.model.entity.Entity) ResponseEntity(org.springframework.http.ResponseEntity) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Entity (com.salesmanager.shop.model.entity.Entity)10 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)6 ResponseEntity (org.springframework.http.ResponseEntity)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)5 ApiOperation (io.swagger.annotations.ApiOperation)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 PersistableContentEntity (com.salesmanager.shop.model.content.PersistableContentEntity)2 ReadableContentEntity (com.salesmanager.shop.model.content.ReadableContentEntity)2 EntityExists (com.salesmanager.shop.model.entity.EntityExists)2 PersistableTaxClass (com.salesmanager.shop.model.tax.PersistableTaxClass)2 PersistableTaxRate (com.salesmanager.shop.model.tax.PersistableTaxRate)2 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 HttpEntity (org.springframework.http.HttpEntity)2 TaxClass (com.salesmanager.core.model.tax.taxclass.TaxClass)1 TaxRate (com.salesmanager.core.model.tax.taxrate.TaxRate)1