Rev 35289 | Rev 35360 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.common.web.util.ResponseSender;import com.spice.profitmandi.dao.entity.fofo.TrialBrandPotential;import com.spice.profitmandi.dao.entity.fofo.TrialForm;import com.spice.profitmandi.dao.repository.fofo.TrialBrandPotentialRepository;import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import javax.servlet.http.HttpServletRequest;import javax.transaction.Transactional;import java.util.List;@Controller@Transactional(rollbackOn = Throwable.class)public class TrialController {@AutowiredTrialBrandPotentialRepository trialBrandPotentialRepository;@AutowiredResponseSender responseSender;private static final Logger LOGGER = LogManager.getLogger(TrialController.class);@AutowiredTrialFormRepository trialFormRepository;@RequestMapping(value = "/trial/pending", method = RequestMethod.GET)public String getTrialPending(HttpServletRequest request, Model model) throws Exception {List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.PENDING);LOGGER.info("trialForms {}", trialForms.size());model.addAttribute("trialForms", trialForms);return "trial-form";}@RequestMapping(value = "/trial/verified", method = RequestMethod.GET)public String verifiedTrial(HttpServletRequest request, Model model) throws Exception {List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.VERIFIED);LOGGER.info("trialForms {}", trialForms.size());model.addAttribute("trialForms", trialForms);return "trial-verified";}@RequestMapping(value = "/trial/create/{trialFormId}", method = RequestMethod.GET)public String getTrialPending(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {TrialForm trialForm = trialFormRepository.selectById(trialFormId);return "trial-form";}@RequestMapping(value = "/trial/cancel/{trialFormId}", method = RequestMethod.POST)public String rejectTrialUser(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {TrialForm trialForm = trialFormRepository.selectById(trialFormId);trialForm.setStatus(ProfitMandiConstants.Status.REJECTED);return "trial-form";}@RequestMapping(value = "/trial/brand-Potential", method = RequestMethod.POST)public ResponseEntity<?> brandPotential(HttpServletRequest request) throws Exception {int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));int row = 1;while (true) {String brand = request.getParameter("brand_" + row);String potential = request.getParameter("potential_" + row);if (brand == null && potential == null) {break;}if (brand != null && !brand.trim().isEmpty()&& potential != null && !potential.trim().isEmpty()) {TrialBrandPotential tbp = new TrialBrandPotential();tbp.setTrialFormId(trialFormId);tbp.setBrandName(brand.trim());tbp.setPotential(Integer.parseInt(potential));trialBrandPotentialRepository.persist(tbp);}row++;}TrialForm trialForm = trialFormRepository.selectById(trialFormId);trialForm.setStatus(ProfitMandiConstants.Status.VERIFIED);return responseSender.ok("Saved Successfully");}}