| 35289 |
amit |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 35340 |
aman |
4 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
5 |
import com.spice.profitmandi.dao.entity.fofo.TrialBrandPotential;
|
| 35289 |
amit |
6 |
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
|
| 35340 |
aman |
7 |
import com.spice.profitmandi.dao.repository.fofo.TrialBrandPotentialRepository;
|
| 35289 |
amit |
8 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
|
|
|
9 |
import org.apache.logging.log4j.LogManager;
|
|
|
10 |
import org.apache.logging.log4j.Logger;
|
|
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 35340 |
aman |
12 |
import org.springframework.http.ResponseEntity;
|
| 35289 |
amit |
13 |
import org.springframework.stereotype.Controller;
|
|
|
14 |
import org.springframework.ui.Model;
|
|
|
15 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
18 |
|
|
|
19 |
import javax.servlet.http.HttpServletRequest;
|
|
|
20 |
import javax.transaction.Transactional;
|
|
|
21 |
import java.util.List;
|
|
|
22 |
|
|
|
23 |
@Controller
|
|
|
24 |
@Transactional(rollbackOn = Throwable.class)
|
|
|
25 |
public class TrialController {
|
|
|
26 |
|
| 35340 |
aman |
27 |
@Autowired
|
|
|
28 |
TrialBrandPotentialRepository trialBrandPotentialRepository;
|
|
|
29 |
|
|
|
30 |
@Autowired
|
|
|
31 |
ResponseSender responseSender;
|
|
|
32 |
|
| 35289 |
amit |
33 |
private static final Logger LOGGER = LogManager.getLogger(TrialController.class);
|
|
|
34 |
@Autowired
|
|
|
35 |
TrialFormRepository trialFormRepository;
|
|
|
36 |
|
|
|
37 |
@RequestMapping(value = "/trial/pending", method = RequestMethod.GET)
|
|
|
38 |
public String getTrialPending(HttpServletRequest request, Model model) throws Exception {
|
|
|
39 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.PENDING);
|
|
|
40 |
LOGGER.info("trialForms {}", trialForms.size());
|
|
|
41 |
model.addAttribute("trialForms", trialForms);
|
|
|
42 |
return "trial-form";
|
|
|
43 |
}
|
|
|
44 |
|
| 35340 |
aman |
45 |
@RequestMapping(value = "/trial/verified", method = RequestMethod.GET)
|
|
|
46 |
public String verifiedTrial(HttpServletRequest request, Model model) throws Exception {
|
|
|
47 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.VERIFIED);
|
|
|
48 |
LOGGER.info("trialForms {}", trialForms.size());
|
|
|
49 |
model.addAttribute("trialForms", trialForms);
|
|
|
50 |
return "trial-verified";
|
|
|
51 |
}
|
|
|
52 |
|
| 35289 |
amit |
53 |
@RequestMapping(value = "/trial/create/{trialFormId}", method = RequestMethod.GET)
|
|
|
54 |
public String getTrialPending(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
55 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
56 |
|
|
|
57 |
return "trial-form";
|
|
|
58 |
}
|
| 35340 |
aman |
59 |
|
|
|
60 |
@RequestMapping(value = "/trial/cancel/{trialFormId}", method = RequestMethod.POST)
|
|
|
61 |
public String rejectTrialUser(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
62 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
63 |
trialForm.setStatus(ProfitMandiConstants.Status.REJECTED);
|
|
|
64 |
|
|
|
65 |
return "trial-form";
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
@RequestMapping(value = "/trial/brand-Potential", method = RequestMethod.POST)
|
|
|
69 |
public ResponseEntity<?> brandPotential(HttpServletRequest request) throws Exception {
|
|
|
70 |
|
|
|
71 |
int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));
|
|
|
72 |
int row = 1;
|
|
|
73 |
while (true) {
|
|
|
74 |
String brand = request.getParameter("brand_" + row);
|
|
|
75 |
String potential = request.getParameter("potential_" + row);
|
|
|
76 |
|
|
|
77 |
if (brand == null && potential == null) {
|
|
|
78 |
break;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
if (brand != null && !brand.trim().isEmpty()
|
|
|
82 |
&& potential != null && !potential.trim().isEmpty()) {
|
|
|
83 |
|
|
|
84 |
TrialBrandPotential tbp = new TrialBrandPotential();
|
|
|
85 |
tbp.setTrialFormId(trialFormId);
|
|
|
86 |
tbp.setBrandName(brand.trim());
|
|
|
87 |
tbp.setPotential(Integer.parseInt(potential));
|
|
|
88 |
|
|
|
89 |
trialBrandPotentialRepository.persist(tbp);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
row++;
|
|
|
93 |
}
|
|
|
94 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
95 |
trialForm.setStatus(ProfitMandiConstants.Status.VERIFIED);
|
|
|
96 |
return responseSender.ok("Saved Successfully");
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
|
| 35289 |
amit |
100 |
}
|