Subversion Repositories SmartDukaan

Rev

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

Rev 22860 Rev 22927
Line 16... Line 16...
16
import org.springframework.web.bind.annotation.RequestParam;
16
import org.springframework.web.bind.annotation.RequestParam;
17
 
17
 
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.model.CreateSchemeRequest;
19
import com.spice.profitmandi.common.model.CreateSchemeRequest;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
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;
21
import com.spice.profitmandi.dao.entity.catalog.Scheme;
23
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
22
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
24
import com.spice.profitmandi.service.scheme.SchemeService;
23
import com.spice.profitmandi.service.scheme.SchemeService;
25
import com.spice.profitmandi.web.model.LoginDetails;
24
import com.spice.profitmandi.web.model.LoginDetails;
26
import com.spice.profitmandi.web.util.CookiesProcessor;
25
import com.spice.profitmandi.web.util.CookiesProcessor;
27
import com.spice.profitmandi.web.util.MVCResponseSender;
-
 
28
 
26
 
29
@Controller
27
@Controller
30
@Transactional(rollbackFor=Throwable.class)
28
@Transactional(rollbackFor=Throwable.class)
31
public class SchemeController {
29
public class SchemeController {
32
 
30
 
33
	private static final Logger LOGGER = LoggerFactory.getLogger(SchemeController.class);
31
	private static final Logger LOGGER = LoggerFactory.getLogger(SchemeController.class);
34
 
32
 
35
	@Autowired
33
	@Autowired
36
	SchemeService schemeService;
34
	private SchemeService schemeService;
37
	
35
	
38
	@Autowired
36
	@Autowired
39
	SchemeRepository schemeRepository;
37
	private SchemeRepository schemeRepository;
40
 
38
 
41
	@Autowired
39
	@Autowired
42
	MVCResponseSender mvcResponseSender;
-
 
43
 
-
 
44
	@Autowired
-
 
45
	CookiesProcessor cookiesProcessor;
40
	private CookiesProcessor cookiesProcessor;
46
	
-
 
47
	@Autowired
-
 
48
	ResponseSender<?> responseSender;
-
 
49
 
41
 
50
	@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
42
	@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
51
	public String createScheme(HttpServletRequest request, Model model)  throws Throwable{
43
	public String createScheme(HttpServletRequest request, Model model){
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";
44
		return "create-scheme";
59
	}
45
	}
60
	
46
	
61
	@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
47
	@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{
48
	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 ProfitMandiBusinessException{
63
		LoginDetails loginDetails = null;
-
 
64
		try {
-
 
65
			loginDetails = cookiesProcessor.getCookiesObject(request);
49
		LoginDetails 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);
50
		LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
71
		try{
-
 
72
			schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
51
		schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
73
			LOGGER.info("Scheme saved successfully");
52
		LOGGER.info("Scheme saved successfully");
-
 
53
		
74
			List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
54
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
75
			long count = schemeRepository.selectCount(offset, limit);
55
		long count = schemeRepository.selectCount(offset, limit);
76
			model.addAttribute("schemes", schemes);
56
		model.addAttribute("schemes", schemes);
77
			model.addAttribute("start", offset + 1);
57
		model.addAttribute("start", offset + 1);
78
			model.addAttribute("size", count);
58
		model.addAttribute("size", count);
79
			if (schemes.size() < limit){
59
		if (schemes.size() < limit){
80
				model.addAttribute("end", offset + schemes.size());
60
			model.addAttribute("end", offset + schemes.size());
81
			}
61
		}
82
			else{
62
		else{
83
				model.addAttribute("end", offset + limit);
63
			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
		}
64
		}
-
 
65
		return "schemes";
-
 
66
		
90
	}
67
	}
91
	
68
	
92
	@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
69
	@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{
70
	public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model){
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);
71
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
101
		long count = schemeRepository.selectCount(offset, limit);
72
		long count = schemeRepository.selectCount(offset, limit);
102
		model.addAttribute("schemes", schemes);
73
		model.addAttribute("schemes", schemes);
103
		model.addAttribute("start", offset + 1);
74
		model.addAttribute("start", offset + 1);
104
		model.addAttribute("size", count);
75
		model.addAttribute("size", count);
Line 110... Line 81...
110
		}
81
		}
111
		return "schemes";
82
		return "schemes";
112
	}
83
	}
113
	
84
	
114
	@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
85
	@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{
86
	public String getPaginatedSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model){
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);
87
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
123
		model.addAttribute("schemes", schemes);
88
		model.addAttribute("schemes", schemes);
124
		return "schemes-paginated";
89
		return "schemes-paginated";
125
	}
90
	}
126
	
91
	
127
	@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
92
	@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
128
	public String getSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)  throws Throwable{
93
	public String getSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)  throws ProfitMandiBusinessException{
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);
94
		Scheme scheme = schemeService.getSchemeById(schemeId);
136
		model.addAttribute("scheme", scheme);
95
		model.addAttribute("scheme", scheme);
137
		return "scheme-details";
96
		return "scheme-details";
138
	}
97
	}
139
	
98
	
140
	@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
99
	@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{
100
	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 ProfitMandiBusinessException{
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);
101
		schemeService.activeSchemeById(schemeId);
149
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
102
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
150
		model.addAttribute("schemes", schemes);
103
		model.addAttribute("schemes", schemes);
151
		return "schemes-paginated";
104
		return "schemes-paginated";
152
	}
105
	}
153
	
106
	
154
	
107
	
155
	@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
108
	@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{
109
	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 ProfitMandiBusinessException{
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);
110
		schemeService.expireSchemeById(schemeId);
164
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
111
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
165
		model.addAttribute("schemes", schemes);
112
		model.addAttribute("schemes", schemes);
166
		return "schemes-paginated";
113
		return "schemes-paginated";
167
	}
114
	}