public ProductUI findByProductname(String productName) {
return mapper.toUIBean(repository.findByProductName(productName));
}
public ProductUI update(ProductUI uiBean) {
Product existing = repository
.findByProductName(uiBean.getProductName());
if (existing == null) {
return null;
}
if (! existing.getGroup().getGroupName().equals(uiBean.getProductGroup()))
{
ProductGroup group = groupRepository.findByGroupName(uiBean.getProductGroup()) ;
existing.setGroup(group);
}
existing.setDescription(uiBean.getDescription());
existing.setPrice(uiBean.getPrice());
Product saved = null;
try {
saved = repository.save(existing);
} catch (Exception e) {
logger.error(e);