class CustomerReviewServiceImpl extends
	SalesManagerEntityServiceImpl<Long, CustomerReview> implements CustomerReviewService {
	
	private CustomerReviewRepository customerReviewRepository;
	
	@Inject
	private CustomerService customerService;
	
	@Inject
	public CustomerReviewServiceImpl(
			CustomerReviewRepository customerReviewRepository) {
			super(customerReviewRepository);
			this.customerReviewRepository = customerReviewRepository;
	}
	
	
	private void saveOrUpdate(CustomerReview review) throws ServiceException {<FILL_FUNCTION_BODY>}
	
	public void update(CustomerReview review) throws ServiceException {
		this.saveOrUpdate(review);
	}
	
	public void create(CustomerReview review) throws ServiceException {
		this.saveOrUpdate(review);
	}
	
	

	@Override
	public List<CustomerReview> getByCustomer(Customer customer) {
		Validate.notNull(customer,"Customer cannot be null");
		return customerReviewRepository.findByReviewer(customer.getId());
	}

	@Override
	public List<CustomerReview> getByReviewedCustomer(Customer customer) {
		Validate.notNull(customer,"Customer cannot be null");
		return customerReviewRepository.findByReviewed(customer.getId());
	}


	@Override
	public CustomerReview getByReviewerAndReviewed(Long reviewer, Long reviewed) {
		Validate.notNull(reviewer,"Reviewer customer cannot be null");
		Validate.notNull(reviewed,"Reviewer customer cannot be null");
		return customerReviewRepository.findByRevieweAndReviewed(reviewer, reviewed);
	}

}

		

		Validate.notNull(review,"CustomerReview cannot be null");
		Validate.notNull(review.getCustomer(),"CustomerReview.customer cannot be null");
		Validate.notNull(review.getReviewedCustomer(),"CustomerReview.reviewedCustomer cannot be null");
		
		
		//refresh customer
		Customer customer = customerService.getById(review.getReviewedCustomer().getId());
		
		//ajust product rating
		Integer count = 0;
		if(customer.getCustomerReviewCount()!=null) {
			count = customer.getCustomerReviewCount();
		}
				
		
		

		BigDecimal averageRating = customer.getCustomerReviewAvg();
		if(averageRating==null) {
			averageRating = new BigDecimal(0);
		}
		//get reviews

		
		BigDecimal totalRating = averageRating.multiply(new BigDecimal(count));
		totalRating = totalRating.add(new BigDecimal(review.getReviewRating()));
		
		count = count + 1;
		double avg = totalRating.doubleValue() / count;
		
		customer.setCustomerReviewAvg(new BigDecimal(avg));
		customer.setCustomerReviewCount(count);
		super.save(review);
		
		customerService.update(customer);
		
		review.setReviewedCustomer(customer);

		
	
<methods>public void <init>(JpaRepository<com.salesmanager.core.model.customer.review.CustomerReview,java.lang.Long>) ,public java.lang.Long count() ,public void create(com.salesmanager.core.model.customer.review.CustomerReview) throws com.salesmanager.core.business.exception.ServiceException,public void delete(com.salesmanager.core.model.customer.review.CustomerReview) throws com.salesmanager.core.business.exception.ServiceException,public void flush() ,public com.salesmanager.core.model.customer.review.CustomerReview getById(java.lang.Long) ,public List<com.salesmanager.core.model.customer.review.CustomerReview> list() ,public void save(com.salesmanager.core.model.customer.review.CustomerReview) throws com.salesmanager.core.business.exception.ServiceException,public void saveAll(Iterable<com.salesmanager.core.model.customer.review.CustomerReview>) throws com.salesmanager.core.business.exception.ServiceException,public void update(com.salesmanager.core.model.customer.review.CustomerReview) throws com.salesmanager.core.business.exception.ServiceException<variables>private Class<com.salesmanager.core.model.customer.review.CustomerReview> objectClass,private JpaRepository<com.salesmanager.core.model.customer.review.CustomerReview,java.lang.Long> repository