public ModelAndView submitRetailerComment(final HttpServletRequest request, @PathVariable(RequestConstants.URL_PATTERN_RETAILER_CODE) final String retailerCode,
@Valid @ModelAttribute("retailerCommentForm") RetailerCommentForm retailerCommentForm,
BindingResult result, final Model model) throws Exception {
final RequestData requestData = requestUtil.getRequestData(request);
final MarketArea currentMarketArea = requestData.getMarketArea();
final Retailer currentRetailer = requestData.getMarketAreaRetailer();
final Locale locale = requestData.getLocale();
if (result.hasErrors()) {
return displayRetailerCommentForm(request, retailerCode, model, retailerCommentForm);
}
int qualityOfService = 0;
int ratioQualityPrice = 0;
int priceScore = 0;
try {
qualityOfService = Integer.parseInt(retailerCommentForm.getQualityOfService());
} catch (Exception e) {
logger.warn("Retailer Vote qualityOfService value can't be parse: " + retailerCommentForm.getQualityOfService());
}
try {
ratioQualityPrice = Integer.parseInt(retailerCommentForm.getRatioQualityPrice());
} catch (Exception e) {
logger.warn("Retailer Vote ratioQualityPrice value can't be parse: " + retailerCommentForm.getRatioQualityPrice());
}
try {
priceScore = Integer.parseInt(retailerCommentForm.getPriceScore());
} catch (Exception e) {
logger.warn("Retailer Vote priceScore value can't be parse: " + retailerCommentForm.getPriceScore());
}
if (StringUtils.isEmpty(retailerCommentForm.getComment())
&& qualityOfService == 0
&& ratioQualityPrice == 0
&& priceScore == 0) {
// WARNING
addInfoMessage(request, getSpecificMessage(ScopeWebMessage.RETAILER, "comment_form_empty_warning_message", locale));
return displayRetailerCommentForm(request, retailerCode, model, retailerCommentForm);
}
final Retailer retailer = retailerService.getRetailerByCode(currentMarketArea.getId(), currentRetailer.getId(), retailerCode);
final Customer customer = requestData.getCustomer();
if (qualityOfService != 0) {
RetailerCustomerRate retailerCustomerRate = new RetailerCustomerRate();
retailerCustomerRate.setRate(qualityOfService);
retailerCustomerRate.setRetailerId(retailer.getId());
retailerCustomerRate.setCustomerId(customer.getId());
retailerCustomerRate.setType("QUALITY_OF_SERVICE");
retailerService.saveOrUpdateRetailerCustomerRate(retailerCustomerRate);
}
if (ratioQualityPrice != 0) {
RetailerCustomerRate retailerCustomerRate = new RetailerCustomerRate();
retailerCustomerRate.setRate(ratioQualityPrice);
retailerCustomerRate.setRetailerId(retailer.getId());
retailerCustomerRate.setCustomerId(customer.getId());
retailerCustomerRate.setType("RATIO_QUALITY_PRICE");
retailerService.saveOrUpdateRetailerCustomerRate(retailerCustomerRate);
}
if (priceScore != 0) {
RetailerCustomerRate retailerCustomerRate = new RetailerCustomerRate();
retailerCustomerRate.setRate(priceScore);
retailerCustomerRate.setRetailerId(retailer.getId());
retailerCustomerRate.setCustomerId(customer.getId());
retailerCustomerRate.setType("PRICE_SCORE");
retailerService.saveOrUpdateRetailerCustomerRate(retailerCustomerRate);
}
if (StringUtils.isNotEmpty(retailerCommentForm.getComment())) {
RetailerCustomerComment retailerCustomerComment = new RetailerCustomerComment();
retailerCustomerComment.setComment(retailerCommentForm.getComment());
retailerCustomerComment.setRetailerId(retailer.getId());
retailerCustomerComment.setCustomer(customer);
retailerService.saveOrUpdateRetailerCustomerComment(retailerCustomerComment);
}
addSuccessMessage(request, getSpecificMessage(ScopeWebMessage.RETAILER, "comment_form_success_message", locale));