Subversion Repositories SmartDukaan

Rev

Rev 35289 | Rev 35360 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35289 Rev 35340
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import com.spice.profitmandi.common.model.ProfitMandiConstants;
3
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
4
import com.spice.profitmandi.common.web.util.ResponseSender;
-
 
5
import com.spice.profitmandi.dao.entity.fofo.TrialBrandPotential;
4
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
6
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
-
 
7
import com.spice.profitmandi.dao.repository.fofo.TrialBrandPotentialRepository;
5
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
8
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
6
import org.apache.logging.log4j.LogManager;
9
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
10
import org.apache.logging.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.beans.factory.annotation.Autowired;
-
 
12
import org.springframework.http.ResponseEntity;
9
import org.springframework.stereotype.Controller;
13
import org.springframework.stereotype.Controller;
10
import org.springframework.ui.Model;
14
import org.springframework.ui.Model;
11
import org.springframework.web.bind.annotation.PathVariable;
15
import org.springframework.web.bind.annotation.PathVariable;
12
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMapping;
13
import org.springframework.web.bind.annotation.RequestMethod;
17
import org.springframework.web.bind.annotation.RequestMethod;
Line 18... Line 22...
18
 
22
 
19
@Controller
23
@Controller
20
@Transactional(rollbackOn = Throwable.class)
24
@Transactional(rollbackOn = Throwable.class)
21
public class TrialController {
25
public class TrialController {
22
 
26
 
-
 
27
    @Autowired
-
 
28
    TrialBrandPotentialRepository trialBrandPotentialRepository;
-
 
29
 
-
 
30
    @Autowired
-
 
31
    ResponseSender responseSender;
-
 
32
 
23
    private static final Logger LOGGER = LogManager.getLogger(TrialController.class);
33
    private static final Logger LOGGER = LogManager.getLogger(TrialController.class);
24
    @Autowired
34
    @Autowired
25
    TrialFormRepository trialFormRepository;
35
    TrialFormRepository trialFormRepository;
26
 
36
 
27
    @RequestMapping(value = "/trial/pending", method = RequestMethod.GET)
37
    @RequestMapping(value = "/trial/pending", method = RequestMethod.GET)
Line 30... Line 40...
30
        LOGGER.info("trialForms {}", trialForms.size());
40
        LOGGER.info("trialForms {}", trialForms.size());
31
        model.addAttribute("trialForms", trialForms);
41
        model.addAttribute("trialForms", trialForms);
32
        return "trial-form";
42
        return "trial-form";
33
    }
43
    }
34
 
44
 
-
 
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
 
35
    @RequestMapping(value = "/trial/create/{trialFormId}", method = RequestMethod.GET)
53
    @RequestMapping(value = "/trial/create/{trialFormId}", method = RequestMethod.GET)
36
    public String getTrialPending(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
54
    public String getTrialPending(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
37
        TrialForm trialForm = trialFormRepository.selectById(trialFormId);
55
        TrialForm trialForm = trialFormRepository.selectById(trialFormId);
38
 
56
 
39
        return "trial-form";
57
        return "trial-form";
40
    }
58
    }
-
 
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
 
41
}
100
}