}
public Item createItem(String name, String price, String description, Long categoryId) {
Category category = categoryService.findCategoryById(categoryId);
Item item = new Item();
item.setName(name);
item.setCategory(category);
try {
item.setPrice(Float.parseFloat(price));
}
catch (NumberFormatException ex) {
LOG.error("parse error occured while parsing price!");
item.setPrice(0.0f);
}
item.setShortDescription(description);
Item savedItem = null;
try {
savedItem = itemRepository.saveAndFlush(item);
}
catch (Exception ex) {
LOG.error("Item could not be saved due to an error");
}
if (savedItem != null && savedItem.getId() != null) {
LOG.info("nieuwe Item aangemaakt " + savedItem.getId() + "/" + savedItem.getName() + "/" + savedItem.getPrice() + "/"
+ savedItem.getShortDescription());
return savedItem;
} else {
LOG.error("Item niet aangemaakt!");
return null;
}