use of com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer in project shopizer by shopizer-ecommerce.
the class ManufacturerFacadeImpl method saveOrUpdateManufacturer.
@Override
public void saveOrUpdateManufacturer(PersistableManufacturer manufacturer, MerchantStore store, Language language) throws Exception {
PersistableManufacturerPopulator populator = new PersistableManufacturerPopulator();
populator.setLanguageService(languageService);
Manufacturer manuf = new Manufacturer();
if (manufacturer.getId() != null && manufacturer.getId().longValue() > 0) {
manuf = manufacturerService.getById(manufacturer.getId());
if (manuf == null) {
throw new ResourceNotFoundException("Manufacturer with id [" + manufacturer.getId() + "] not found");
}
if (manuf.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("Manufacturer with id [" + manufacturer.getId() + "] not found for store [" + store.getId() + "]");
}
}
populator.populate(manufacturer, manuf, store, language);
manufacturerService.saveOrUpdate(manuf);
manufacturer.setId(manuf.getId());
}
use of com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer in project shopizer by shopizer-ecommerce.
the class CategoryManagementAPIIntegrationTest method manufacturerForItemsInCategory.
@Test
public void manufacturerForItemsInCategory() throws Exception {
ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
// create first manufacturer
PersistableManufacturer m1 = super.manufacturer("BRAND1");
String json = writer.writeValueAsString(m1);
HttpEntity<String> entity = new HttpEntity<>(json, getHeader());
@SuppressWarnings("rawtypes") ResponseEntity response = testRestTemplate.postForEntity("/api/v1/private/manufacturer", entity, PersistableManufacturer.class);
assertThat(response.getStatusCode(), is(CREATED));
// create second manufacturer
PersistableManufacturer m2 = super.manufacturer("BRAND2");
json = writer.writeValueAsString(m2);
entity = new HttpEntity<>(json, getHeader());
response = testRestTemplate.postForEntity("/api/v1/private/manufacturer", entity, PersistableManufacturer.class);
assertThat(response.getStatusCode(), is(CREATED));
// create category
PersistableCategory category = super.category("TEST");
// to be used in product
Category cat = new Category();
cat.setCode("TEST");
json = writer.writeValueAsString(category);
entity = new HttpEntity<>(json, getHeader());
@SuppressWarnings("rawtypes") ResponseEntity categoryResponse = testRestTemplate.postForEntity("/api/v1/private/category", entity, PersistableCategory.class);
assertThat(categoryResponse.getStatusCode(), is(CREATED));
final PersistableCategory persistable = (PersistableCategory) categoryResponse.getBody();
Long id = persistable.getId();
// create first item
PersistableProduct product1 = super.product("PRODUCT1");
product1.getCategories().add(cat);
ProductSpecification specifications = new ProductSpecification();
specifications.setManufacturer("BRAND1");
product1.setProductSpecifications(specifications);
json = writer.writeValueAsString(product1);
entity = new HttpEntity<>(json, getHeader());
response = testRestTemplate.postForEntity("/api/v1/private/product?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
assertThat(response.getStatusCode(), is(CREATED));
// create second item
PersistableProduct product2 = super.product("PRODUCT2");
product2.getCategories().add(cat);
specifications = new ProductSpecification();
specifications.setManufacturer("BRAND2");
product2.setProductSpecifications(specifications);
json = writer.writeValueAsString(product2);
entity = new HttpEntity<>(json, getHeader());
response = testRestTemplate.postForEntity("/api/v1/private/product?store=" + Constants.DEFAULT_STORE, entity, PersistableProduct.class);
assertThat(response.getStatusCode(), is(CREATED));
entity = new HttpEntity<>(getHeader());
// get manufacturers in category
@SuppressWarnings("rawtypes") ResponseEntity<List> manufacturers = testRestTemplate.exchange(String.format("/api/v1/category/" + id + "/manufacturers"), HttpMethod.GET, entity, List.class);
assertThat(manufacturers.getStatusCode(), is(OK));
@SuppressWarnings("unchecked") List<ReadableManufacturer> manufacturerList = manufacturers.getBody();
// assertFalse(manufacturerList.isEmpty());
}
use of com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer in project shopizer by shopizer-ecommerce.
the class ServicesTestSupport method manufacturer.
protected PersistableManufacturer manufacturer(String code) {
PersistableManufacturer m = new PersistableManufacturer();
m.setCode(code);
m.setOrder(0);
ManufacturerDescription desc = new ManufacturerDescription();
desc.setLanguage("en");
desc.setName(code);
m.getDescriptions().add(desc);
return m;
}
use of com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer in project shopizer by shopizer-ecommerce.
the class ShopProductRESTController method createManufacturer.
/**
* Method for creating a manufacturer
* @param store
* @param manufacturer
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/private/{store}/manufacturer", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public PersistableManufacturer createManufacturer(@PathVariable final String store, @Valid @RequestBody PersistableManufacturer manufacturer, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
merchantStore = null;
}
}
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
response.sendError(503, "Merchant store is null for code " + store);
return null;
}
PersistableManufacturerPopulator populator = new PersistableManufacturerPopulator();
populator.setLanguageService(languageService);
com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer manuf = new com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer();
populator.populate(manufacturer, manuf, merchantStore, merchantStore.getDefaultLanguage());
manufacturerService.save(manuf);
manufacturer.setId(manuf.getId());
return manufacturer;
} catch (Exception e) {
LOGGER.error("Error while saving product", e);
try {
response.sendError(503, "Error while saving product " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations