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