Subversion Repositories SmartDukaan

Rev

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

Rev 23784 Rev 23945
Line 5... Line 5...
5
import java.io.FileNotFoundException;
5
import java.io.FileNotFoundException;
6
import java.util.Map;
6
import java.util.Map;
7
 
7
 
8
import javax.servlet.http.HttpServletRequest;
8
import javax.servlet.http.HttpServletRequest;
9
 
9
 
10
import org.apache.logging.log4j.Logger;
-
 
11
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.LogManager;
-
 
11
import org.apache.logging.log4j.Logger;
12
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.core.io.InputStreamResource;
13
import org.springframework.core.io.InputStreamResource;
14
import org.springframework.http.HttpHeaders;
14
import org.springframework.http.HttpHeaders;
15
import org.springframework.http.HttpStatus;
15
import org.springframework.http.HttpStatus;
16
import org.springframework.http.ResponseEntity;
16
import org.springframework.http.ResponseEntity;
Line 22... Line 22...
22
import org.springframework.web.bind.annotation.RequestMethod;
22
import org.springframework.web.bind.annotation.RequestMethod;
23
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.RequestParam;
24
 
24
 
25
import com.spice.profitmandi.common.enumuration.ContentType;
25
import com.spice.profitmandi.common.enumuration.ContentType;
26
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
26
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
27
import com.spice.profitmandi.common.model.Location;
27
import com.spice.profitmandi.common.model.ProfitMandiConstants;
28
import com.spice.profitmandi.common.model.ProfitMandiConstants;
28
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
29
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
29
import com.spice.profitmandi.common.web.util.ResponseSender;
30
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.Document;
31
import com.spice.profitmandi.dao.entity.dtr.Retailer;
32
import com.spice.profitmandi.dao.entity.dtr.Retailer;
32
import com.spice.profitmandi.dao.entity.dtr.Shop;
33
import com.spice.profitmandi.dao.entity.dtr.Shop;
-
 
34
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
33
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
35
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
-
 
36
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
34
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
37
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
35
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
38
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
36
import com.spice.profitmandi.service.user.RetailerService;
39
import com.spice.profitmandi.service.user.RetailerService;
-
 
40
import com.spice.profitmandi.web.model.LoginDetails;
-
 
41
import com.spice.profitmandi.web.util.CookiesProcessor;
37
 
42
 
38
@Controller
43
@Controller
39
@Transactional(rollbackFor=Throwable.class)
44
@Transactional(rollbackFor = Throwable.class)
40
public class RetailerController {
45
public class RetailerController {
41
 
46
 
42
	private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
47
	private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
43
	
48
 
44
	@Autowired
49
	@Autowired
45
	private RetailerService retailerService;
50
	private RetailerService retailerService;
46
	
51
 
47
	@Autowired
52
	@Autowired
48
	private RetailerRepository retailerRepository;
53
	private RetailerRepository retailerRepository;
49
	
54
 
50
	@Autowired
55
	@Autowired
51
	private ShopRepository shopRepository;
56
	private ShopRepository shopRepository;
52
	
57
	
53
	@Autowired
58
	@Autowired
-
 
59
	private FofoStoreRepository fofoStoreRepository;
-
 
60
 
-
 
61
	@Autowired
54
	private DocumentRepository documentRepository;
62
	private DocumentRepository documentRepository;
55
	
63
 
56
	@Autowired
64
	@Autowired
57
	private ResponseSender<?> responseSender;
65
	private ResponseSender<?> responseSender;
58
	
66
	
-
 
67
	@Autowired
-
 
68
	private CookiesProcessor cookiesProcessor;
-
 
69
 
59
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.GET)
70
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.GET)
-
 
71
	public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request,
60
	public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber, Model model)  throws ProfitMandiBusinessException{
72
			@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber,
-
 
73
			Model model) throws ProfitMandiBusinessException {
61
		LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(), emailIdOrMobileNumber);
74
		LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(),
-
 
75
				emailIdOrMobileNumber);
62
		Map<String, Object> map = retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber);
76
		Map<String, Object> map = retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber);
63
		model.addAllAttributes(map);
77
		model.addAllAttributes(map);
64
		return "retailer-details";
78
		return "retailer-details";
65
	}
79
	}
66
	
80
 
67
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.PUT)
81
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.PUT)
-
 
82
	public String updateRetailerDetails(HttpServletRequest request,
68
	public String updateRetailerDetails(HttpServletRequest request, @RequestBody UpdateRetailerRequest updateRetailerRequest, Model model)  throws ProfitMandiBusinessException{
83
			@RequestBody UpdateRetailerRequest updateRetailerRequest, Model model) throws ProfitMandiBusinessException {
69
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), updateRetailerRequest);
84
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), updateRetailerRequest);
70
		Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
85
		Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
71
		model.addAllAttributes(map);
86
		model.addAllAttributes(map);
72
		return "retailer-details";
87
		return "retailer-details";
73
	}
88
	}
74
	
-
 
75
 
89
 
76
	@RequestMapping(value = "/retailerInfo", method = RequestMethod.GET)
90
	@RequestMapping(value = "/retailerInfo", method = RequestMethod.GET)
77
	public String retailerInfo(HttpServletRequest request)  throws Exception{
91
	public String retailerInfo(HttpServletRequest request) throws Exception {
78
		return "retailer-info";
92
		return "retailer-info";
79
	}
93
	}
80
	
94
 
81
	@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
95
	@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
82
	public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName){
96
	public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName) {
83
		return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
97
		return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
84
	}
98
	}
85
	
99
 
86
	@RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
100
	@RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
-
 
101
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
-
 
102
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId,
87
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException{
103
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
88
		Document document = documentRepository.selectById(documentId);
104
		Document document = documentRepository.selectById(documentId);
89
		Retailer retailer = retailerRepository.selectById(retailerId);
105
		Retailer retailer = retailerRepository.selectById(retailerId);
90
		
106
 
91
		if(retailer.getDocumentId() == null) {
107
		if (retailer.getDocumentId() == null) {
92
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
108
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
93
		}
109
		}
94
		if(retailer.getDocumentId() != documentId) {
110
		if (retailer.getDocumentId() != documentId) {
95
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
111
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
96
		}
112
		}
97
		return responseSender.ok(document);
113
		return responseSender.ok(document);
98
	}
114
	}
99
	
115
 
100
	@RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
116
	@RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
-
 
117
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request,
101
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model) throws ProfitMandiBusinessException{
118
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
-
 
119
			throws ProfitMandiBusinessException {
102
		
120
 
103
		Retailer retailer = retailerRepository.selectById(retailerId);
121
		Retailer retailer = retailerRepository.selectById(retailerId);
104
		
122
 
105
		if(retailer.getDocumentId() == null) {
123
		if (retailer.getDocumentId() == null) {
106
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
124
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
107
		}
125
		}
108
		
126
 
109
		Document document = documentRepository.selectById(retailer.getDocumentId());
127
		Document document = documentRepository.selectById(retailer.getDocumentId());
110
		
128
 
111
		FileInputStream file = null;
129
		FileInputStream file = null;
112
		try {
130
		try {
113
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
131
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
114
		} catch (FileNotFoundException e) {
132
		} catch (FileNotFoundException e) {
115
			LOGGER.error("Retailer Document file not found : ", e);
133
			LOGGER.error("Retailer Document file not found : ", e);
116
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
134
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
117
		}
135
		}
118
		//ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
136
		// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
119
		//ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
137
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
120
		
138
 
121
		final HttpHeaders headers=new HttpHeaders();
139
		final HttpHeaders headers = new HttpHeaders();
122
		String contentType = "";
140
		String contentType = "";
123
		if(document.getContentType() == ContentType.JPEG) {
141
		if (document.getContentType() == ContentType.JPEG) {
124
			contentType = "image/jpeg";
142
			contentType = "image/jpeg";
125
		}else if(document.getContentType() == ContentType.PNG) {
143
		} else if (document.getContentType() == ContentType.PNG) {
126
			contentType = "image/png";
144
			contentType = "image/png";
127
		}else if(document.getContentType() == ContentType.PDF) {
145
		} else if (document.getContentType() == ContentType.PDF) {
128
			contentType = "application/pdf";
146
			contentType = "application/pdf";
129
		}
147
		}
130
        headers.set("Content-Type", contentType);
148
		headers.set("Content-Type", contentType);
131
		headers.set("Content-disposition", "inline; filename="+document.getName());
149
		headers.set("Content-disposition", "inline; filename=" + document.getName());
132
        headers.setContentLength(document.getSize());
150
		headers.setContentLength(document.getSize());
133
        final InputStreamResource inputStreamResource=new InputStreamResource(file);
151
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
134
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
152
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
135
		
153
 
136
		//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
154
		// return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
137
	}
155
	}
138
	
156
 
139
	@RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
157
	@RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
-
 
158
	public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request,
-
 
159
			@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
140
	public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId, @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException{
160
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
141
		Shop shop = shopRepository.selectById(shopId);
161
		Shop shop = shopRepository.selectById(shopId);
142
		
162
 
143
		if(shop.getRetailerId() != retailerId) {
163
		if (shop.getRetailerId() != retailerId) {
144
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
164
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
145
		}
165
		}
146
		
166
 
147
		if(shop.getDocumentId() == null) {
167
		if (shop.getDocumentId() == null) {
148
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
168
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
149
		}
169
		}
150
		
170
 
151
		Document document = documentRepository.selectById(shop.getDocumentId());
171
		Document document = documentRepository.selectById(shop.getDocumentId());
152
		return responseSender.ok(document);
172
		return responseSender.ok(document);
153
	}
173
	}
154
	
174
 
155
	@RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
175
	@RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
-
 
176
	public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request,
-
 
177
			@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
156
	public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId, @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model) throws ProfitMandiBusinessException{
178
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
-
 
179
			throws ProfitMandiBusinessException {
157
		
180
 
158
		Shop shop = shopRepository.selectById(shopId);
181
		Shop shop = shopRepository.selectById(shopId);
159
		
182
 
160
		if(shop.getRetailerId() != retailerId) {
183
		if (shop.getRetailerId() != retailerId) {
161
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
184
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
162
		}
185
		}
163
		
186
 
164
		if(shop.getDocumentId() == null) {
187
		if (shop.getDocumentId() == null) {
165
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
188
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
166
		}
189
		}
167
		
190
 
168
		Document document = documentRepository.selectById(shop.getDocumentId());
191
		Document document = documentRepository.selectById(shop.getDocumentId());
169
		
192
 
170
		FileInputStream file = null;
193
		FileInputStream file = null;
171
		try {
194
		try {
172
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
195
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
173
		} catch (FileNotFoundException e) {
196
		} catch (FileNotFoundException e) {
174
			LOGGER.error("Retailer Document file not found : ", e);
197
			LOGGER.error("Retailer Document file not found : ", e);
175
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
198
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
176
		}
199
		}
177
		//ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
200
		// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
178
		//ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
201
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
179
		
202
 
180
		final HttpHeaders headers=new HttpHeaders();
203
		final HttpHeaders headers = new HttpHeaders();
181
		String contentType = "";
204
		String contentType = "";
182
		if(document.getContentType() == ContentType.JPEG) {
205
		if (document.getContentType() == ContentType.JPEG) {
183
			contentType = "image/jpeg";
206
			contentType = "image/jpeg";
184
		}else if(document.getContentType() == ContentType.PNG) {
207
		} else if (document.getContentType() == ContentType.PNG) {
185
			contentType = "image/png";
208
			contentType = "image/png";
186
		}else if(document.getContentType() == ContentType.PDF) {
209
		} else if (document.getContentType() == ContentType.PDF) {
187
			contentType = "application/pdf";
210
			contentType = "application/pdf";
188
		}
211
		}
189
        headers.set("Content-Type", contentType);
212
		headers.set("Content-Type", contentType);
190
		headers.set("Content-disposition", "inline; filename="+document.getName());
213
		headers.set("Content-disposition", "inline; filename=" + document.getName());
191
        headers.setContentLength(document.getSize());
214
		headers.setContentLength(document.getSize());
192
        final InputStreamResource inputStreamResource=new InputStreamResource(file);
215
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
193
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
216
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
194
		
217
 
195
		//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
218
		// return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
-
 
219
	}
-
 
220
 
-
 
221
	@RequestMapping(value = "/partner/location", method = RequestMethod.PUT)
-
 
222
	public ResponseEntity<?> updateLocation(HttpServletRequest request, @RequestBody Location location) throws ProfitMandiBusinessException{
-
 
223
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
224
		FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoDetails.getFofoId());
-
 
225
		fs.setLatitude(location.getLatitude());
-
 
226
		fs.setLongitude(location.getLongitude());
-
 
227
		fofoStoreRepository.persist(fs);
-
 
228
		return responseSender.ok(true);
196
	}
229
	}
197
}
230
}
198
231