| 22860 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
|
|
5 |
import javax.servlet.http.HttpServletRequest;
|
|
|
6 |
|
|
|
7 |
import org.slf4j.Logger;
|
|
|
8 |
import org.slf4j.LoggerFactory;
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.stereotype.Controller;
|
|
|
11 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
12 |
import org.springframework.ui.Model;
|
|
|
13 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
14 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
17 |
|
|
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
19 |
import com.spice.profitmandi.common.model.CreateSchemeRequest;
|
|
|
20 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
21 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
22 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
|
|
24 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
|
|
25 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
26 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
27 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
28 |
|
|
|
29 |
@Controller
|
|
|
30 |
@Transactional(rollbackFor=Throwable.class)
|
|
|
31 |
public class SchemeController {
|
|
|
32 |
|
|
|
33 |
private static final Logger LOGGER = LoggerFactory.getLogger(SchemeController.class);
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
SchemeService schemeService;
|
|
|
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
SchemeRepository schemeRepository;
|
|
|
40 |
|
|
|
41 |
@Autowired
|
|
|
42 |
MVCResponseSender mvcResponseSender;
|
|
|
43 |
|
|
|
44 |
@Autowired
|
|
|
45 |
CookiesProcessor cookiesProcessor;
|
|
|
46 |
|
|
|
47 |
@Autowired
|
|
|
48 |
ResponseSender<?> responseSender;
|
|
|
49 |
|
|
|
50 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
|
|
51 |
public String createScheme(HttpServletRequest request, Model model) throws Throwable{
|
|
|
52 |
try {
|
|
|
53 |
cookiesProcessor.getCookiesObject(request);
|
|
|
54 |
} catch (ProfitMandiBusinessException e) {
|
|
|
55 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
56 |
return "response";
|
|
|
57 |
}
|
|
|
58 |
return "create-scheme";
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
|
|
|
62 |
public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Throwable{
|
|
|
63 |
LoginDetails loginDetails = null;
|
|
|
64 |
try {
|
|
|
65 |
loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
66 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
67 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
68 |
return "response";
|
|
|
69 |
}
|
|
|
70 |
LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
|
|
|
71 |
try{
|
|
|
72 |
schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
|
|
|
73 |
LOGGER.info("Scheme saved successfully");
|
|
|
74 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
75 |
long count = schemeRepository.selectCount(offset, limit);
|
|
|
76 |
model.addAttribute("schemes", schemes);
|
|
|
77 |
model.addAttribute("start", offset + 1);
|
|
|
78 |
model.addAttribute("size", count);
|
|
|
79 |
if (schemes.size() < limit){
|
|
|
80 |
model.addAttribute("end", offset + schemes.size());
|
|
|
81 |
}
|
|
|
82 |
else{
|
|
|
83 |
model.addAttribute("end", offset + limit);
|
|
|
84 |
}
|
|
|
85 |
return "schemes";
|
|
|
86 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
87 |
LOGGER.error("Unable to save Scheme : ", profitMandiBusinessException);
|
|
|
88 |
return "error";
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
|
|
|
93 |
public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Throwable{
|
|
|
94 |
try {
|
|
|
95 |
cookiesProcessor.getCookiesObject(request);
|
|
|
96 |
} catch (ProfitMandiBusinessException e) {
|
|
|
97 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
98 |
return "response";
|
|
|
99 |
}
|
|
|
100 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
101 |
long count = schemeRepository.selectCount(offset, limit);
|
|
|
102 |
model.addAttribute("schemes", schemes);
|
|
|
103 |
model.addAttribute("start", offset + 1);
|
|
|
104 |
model.addAttribute("size", count);
|
|
|
105 |
if (schemes.size() < limit){
|
|
|
106 |
model.addAttribute("end", offset + schemes.size());
|
|
|
107 |
}
|
|
|
108 |
else{
|
|
|
109 |
model.addAttribute("end", offset + limit);
|
|
|
110 |
}
|
|
|
111 |
return "schemes";
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
|
|
|
115 |
public String getPaginatedSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Throwable{
|
|
|
116 |
try {
|
|
|
117 |
cookiesProcessor.getCookiesObject(request);
|
|
|
118 |
} catch (ProfitMandiBusinessException e) {
|
|
|
119 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
120 |
return "response";
|
|
|
121 |
}
|
|
|
122 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
123 |
model.addAttribute("schemes", schemes);
|
|
|
124 |
return "schemes-paginated";
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
|
|
|
128 |
public String getSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model) throws Throwable{
|
|
|
129 |
try {
|
|
|
130 |
cookiesProcessor.getCookiesObject(request);
|
|
|
131 |
} catch (ProfitMandiBusinessException e) {
|
|
|
132 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
133 |
return "response";
|
|
|
134 |
}
|
|
|
135 |
Scheme scheme = schemeService.getSchemeById(schemeId);
|
|
|
136 |
model.addAttribute("scheme", scheme);
|
|
|
137 |
return "scheme-details";
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
|
|
|
141 |
public String activeSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Throwable{
|
|
|
142 |
try {
|
|
|
143 |
cookiesProcessor.getCookiesObject(request);
|
|
|
144 |
} catch (ProfitMandiBusinessException e) {
|
|
|
145 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
146 |
return "response";
|
|
|
147 |
}
|
|
|
148 |
schemeService.activeSchemeById(schemeId);
|
|
|
149 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
150 |
model.addAttribute("schemes", schemes);
|
|
|
151 |
return "schemes-paginated";
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
|
|
|
156 |
public String expireSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Throwable{
|
|
|
157 |
try {
|
|
|
158 |
cookiesProcessor.getCookiesObject(request);
|
|
|
159 |
} catch (ProfitMandiBusinessException e) {
|
|
|
160 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
161 |
return "response";
|
|
|
162 |
}
|
|
|
163 |
schemeService.expireSchemeById(schemeId);
|
|
|
164 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
165 |
model.addAttribute("schemes", schemes);
|
|
|
166 |
return "schemes-paginated";
|
|
|
167 |
}
|
|
|
168 |
}
|