| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.io.File;
|
| - |
|
4 |
import java.io.FileInputStream;
|
| - |
|
5 |
import java.io.FileNotFoundException;
|
| 3 |
import java.util.Map;
|
6 |
import java.util.Map;
|
| 4 |
|
7 |
|
| 5 |
import javax.servlet.http.HttpServletRequest;
|
8 |
import javax.servlet.http.HttpServletRequest;
|
| 6 |
|
9 |
|
| 7 |
import org.slf4j.Logger;
|
10 |
import org.slf4j.Logger;
|
| 8 |
import org.slf4j.LoggerFactory;
|
11 |
import org.slf4j.LoggerFactory;
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
13 |
import org.springframework.core.io.InputStreamResource;
|
| - |
|
14 |
import org.springframework.http.HttpHeaders;
|
| - |
|
15 |
import org.springframework.http.HttpStatus;
|
| 10 |
import org.springframework.http.ResponseEntity;
|
16 |
import org.springframework.http.ResponseEntity;
|
| 11 |
import org.springframework.stereotype.Controller;
|
17 |
import org.springframework.stereotype.Controller;
|
| 12 |
import org.springframework.transaction.annotation.Transactional;
|
18 |
import org.springframework.transaction.annotation.Transactional;
|
| 13 |
import org.springframework.ui.Model;
|
19 |
import org.springframework.ui.Model;
|
| 14 |
import org.springframework.web.bind.annotation.RequestBody;
|
20 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 15 |
import org.springframework.web.bind.annotation.RequestMapping;
|
21 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 16 |
import org.springframework.web.bind.annotation.RequestMethod;
|
22 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 17 |
import org.springframework.web.bind.annotation.RequestParam;
|
23 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 18 |
|
24 |
|
| - |
|
25 |
import com.spice.profitmandi.common.enumuration.ContentType;
|
| 19 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
26 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 20 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
27 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21 |
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
|
28 |
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
|
| 22 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
29 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| - |
|
30 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| - |
|
31 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| - |
|
32 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
| - |
|
33 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| - |
|
34 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| - |
|
35 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
| 23 |
import com.spice.profitmandi.service.user.RetailerService;
|
36 |
import com.spice.profitmandi.service.user.RetailerService;
|
| - |
|
37 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| - |
|
38 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24 |
|
39 |
|
| 25 |
@Controller
|
40 |
@Controller
|
| 26 |
@Transactional(rollbackFor=Throwable.class)
|
41 |
@Transactional(rollbackFor=Throwable.class)
|
| 27 |
public class RetailerController {
|
42 |
public class RetailerController {
|
| 28 |
|
43 |
|
| Line 30... |
Line 45... |
| 30 |
|
45 |
|
| 31 |
@Autowired
|
46 |
@Autowired
|
| 32 |
private RetailerService retailerService;
|
47 |
private RetailerService retailerService;
|
| 33 |
|
48 |
|
| 34 |
@Autowired
|
49 |
@Autowired
|
| - |
|
50 |
private RetailerRepository retailerRepository;
|
| - |
|
51 |
|
| - |
|
52 |
@Autowired
|
| - |
|
53 |
private ShopRepository shopRepository;
|
| - |
|
54 |
|
| - |
|
55 |
@Autowired
|
| - |
|
56 |
private DocumentRepository documentRepository;
|
| - |
|
57 |
|
| - |
|
58 |
@Autowired
|
| - |
|
59 |
private CookiesProcessor cookiesProcessor;
|
| - |
|
60 |
|
| - |
|
61 |
@Autowired
|
| 35 |
private ResponseSender<?> responseSender;
|
62 |
private ResponseSender<?> responseSender;
|
| 36 |
|
63 |
|
| 37 |
@RequestMapping(value = "/retailerDetail", method = RequestMethod.GET)
|
64 |
@RequestMapping(value = "/retailerDetail", method = RequestMethod.GET)
|
| 38 |
public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber, Model model) throws ProfitMandiBusinessException{
|
65 |
public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber, Model model) throws ProfitMandiBusinessException{
|
| 39 |
LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(), emailIdOrMobileNumber);
|
66 |
LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(), emailIdOrMobileNumber);
|
| Line 58... |
Line 85... |
| 58 |
|
85 |
|
| 59 |
@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
|
86 |
@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
|
| 60 |
public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName){
|
87 |
public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName){
|
| 61 |
return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
|
88 |
return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
|
| 62 |
}
|
89 |
}
|
| - |
|
90 |
|
| - |
|
91 |
@RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
|
| - |
|
92 |
public ResponseEntity<?> retailerDocumentById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId) throws ProfitMandiBusinessException{
|
| - |
|
93 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
94 |
Document document = documentRepository.selectById(documentId);
|
| - |
|
95 |
Retailer retailer = retailerRepository.selectById(loginDetails.getFofoId());
|
| - |
|
96 |
|
| - |
|
97 |
if(retailer.getDocumentId() == null) {
|
| - |
|
98 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
|
| - |
|
99 |
}
|
| - |
|
100 |
if(retailer.getDocumentId() != documentId) {
|
| - |
|
101 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
|
| - |
|
102 |
}
|
| - |
|
103 |
return responseSender.ok(document);
|
| - |
|
104 |
}
|
| - |
|
105 |
|
| - |
|
106 |
@RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
|
| - |
|
107 |
public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, Model model) throws ProfitMandiBusinessException{
|
| - |
|
108 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
109 |
|
| - |
|
110 |
Retailer retailer = retailerRepository.selectById(loginDetails.getFofoId());
|
| - |
|
111 |
|
| - |
|
112 |
if(retailer.getDocumentId() == null) {
|
| - |
|
113 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
|
| - |
|
114 |
}
|
| - |
|
115 |
|
| - |
|
116 |
Document document = documentRepository.selectById(retailer.getDocumentId());
|
| - |
|
117 |
|
| - |
|
118 |
FileInputStream file = null;
|
| - |
|
119 |
try {
|
| - |
|
120 |
file = new FileInputStream(document.getPath() + File.separator + document.getName());
|
| - |
|
121 |
} catch (FileNotFoundException e) {
|
| - |
|
122 |
LOGGER.error("Retailer Document file not found : ", e);
|
| - |
|
123 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
|
| - |
|
124 |
}
|
| - |
|
125 |
//ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| - |
|
126 |
//ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
| - |
|
127 |
|
| - |
|
128 |
final HttpHeaders headers=new HttpHeaders();
|
| - |
|
129 |
String contentType = "";
|
| - |
|
130 |
if(document.getContentType() == ContentType.JPEG) {
|
| - |
|
131 |
contentType = "image/jpeg";
|
| - |
|
132 |
}else if(document.getContentType() == ContentType.PNG) {
|
| - |
|
133 |
contentType = "image/png";
|
| - |
|
134 |
}else if(document.getContentType() == ContentType.PDF) {
|
| - |
|
135 |
contentType = "application/pdf";
|
| - |
|
136 |
}
|
| - |
|
137 |
headers.set("Content-Type", contentType);
|
| - |
|
138 |
headers.set("Content-disposition", "inline; filename="+document.getName());
|
| - |
|
139 |
headers.setContentLength(document.getSize());
|
| - |
|
140 |
final InputStreamResource inputStreamResource=new InputStreamResource(file);
|
| - |
|
141 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| - |
|
142 |
|
| - |
|
143 |
//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| - |
|
144 |
}
|
| - |
|
145 |
|
| - |
|
146 |
@RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
|
| - |
|
147 |
public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId) throws ProfitMandiBusinessException{
|
| - |
|
148 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
149 |
Shop shop = shopRepository.selectById(shopId);
|
| - |
|
150 |
|
| - |
|
151 |
if(shop.getRetailerId() != loginDetails.getFofoId()) {
|
| - |
|
152 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
|
| - |
|
153 |
}
|
| - |
|
154 |
|
| - |
|
155 |
if(shop.getDocumentId() == null) {
|
| - |
|
156 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
|
| - |
|
157 |
}
|
| - |
|
158 |
|
| - |
|
159 |
Document document = documentRepository.selectById(shop.getDocumentId());
|
| - |
|
160 |
return responseSender.ok(document);
|
| - |
|
161 |
}
|
| - |
|
162 |
|
| - |
|
163 |
@RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
|
| - |
|
164 |
public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId, Model model) throws ProfitMandiBusinessException{
|
| - |
|
165 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
166 |
|
| - |
|
167 |
Shop shop = shopRepository.selectById(shopId);
|
| - |
|
168 |
|
| - |
|
169 |
if(shop.getRetailerId() != loginDetails.getFofoId()) {
|
| - |
|
170 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
|
| - |
|
171 |
}
|
| - |
|
172 |
|
| - |
|
173 |
if(shop.getDocumentId() == null) {
|
| - |
|
174 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
|
| - |
|
175 |
}
|
| - |
|
176 |
|
| - |
|
177 |
Document document = documentRepository.selectById(shop.getDocumentId());
|
| - |
|
178 |
|
| - |
|
179 |
FileInputStream file = null;
|
| - |
|
180 |
try {
|
| - |
|
181 |
file = new FileInputStream(document.getPath() + File.separator + document.getName());
|
| - |
|
182 |
} catch (FileNotFoundException e) {
|
| - |
|
183 |
LOGGER.error("Retailer Document file not found : ", e);
|
| - |
|
184 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
|
| - |
|
185 |
}
|
| - |
|
186 |
//ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| - |
|
187 |
//ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
| - |
|
188 |
|
| - |
|
189 |
final HttpHeaders headers=new HttpHeaders();
|
| - |
|
190 |
String contentType = "";
|
| - |
|
191 |
if(document.getContentType() == ContentType.JPEG) {
|
| - |
|
192 |
contentType = "image/jpeg";
|
| - |
|
193 |
}else if(document.getContentType() == ContentType.PNG) {
|
| - |
|
194 |
contentType = "image/png";
|
| - |
|
195 |
}else if(document.getContentType() == ContentType.PDF) {
|
| - |
|
196 |
contentType = "application/pdf";
|
| - |
|
197 |
}
|
| - |
|
198 |
headers.set("Content-Type", contentType);
|
| - |
|
199 |
headers.set("Content-disposition", "inline; filename="+document.getName());
|
| - |
|
200 |
headers.setContentLength(document.getSize());
|
| - |
|
201 |
final InputStreamResource inputStreamResource=new InputStreamResource(file);
|
| - |
|
202 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| - |
|
203 |
|
| - |
|
204 |
//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| - |
|
205 |
}
|
| 63 |
}
|
206 |
}
|
| 64 |
|
207 |
|