Subversion Repositories SmartDukaan

Rev

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

Rev 24123 Rev 24124
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;
3
import java.io.File;
4
import java.io.FileInputStream;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
5
import java.io.FileNotFoundException;
-
 
6
import java.util.ArrayList;
-
 
7
import java.util.List;
6
import java.util.Map;
8
import java.util.Map;
7
 
9
 
8
import javax.servlet.http.HttpServletRequest;
10
import javax.servlet.http.HttpServletRequest;
9
 
11
 
10
import org.apache.logging.log4j.Logger;
12
import org.apache.logging.log4j.Logger;
Line 15... Line 17...
15
import org.springframework.http.HttpStatus;
17
import org.springframework.http.HttpStatus;
16
import org.springframework.http.ResponseEntity;
18
import org.springframework.http.ResponseEntity;
17
import org.springframework.stereotype.Controller;
19
import org.springframework.stereotype.Controller;
18
import org.springframework.transaction.annotation.Transactional;
20
import org.springframework.transaction.annotation.Transactional;
19
import org.springframework.ui.Model;
21
import org.springframework.ui.Model;
-
 
22
import org.springframework.web.bind.annotation.GetMapping;
-
 
23
import org.springframework.web.bind.annotation.PostMapping;
20
import org.springframework.web.bind.annotation.RequestBody;
24
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestMapping;
25
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestMethod;
26
import org.springframework.web.bind.annotation.RequestMethod;
23
import org.springframework.web.bind.annotation.RequestParam;
27
import org.springframework.web.bind.annotation.RequestParam;
24
 
28
 
25
import com.spice.profitmandi.common.enumuration.ContentType;
29
import com.spice.profitmandi.common.enumuration.ContentType;
26
import com.spice.profitmandi.common.enumuration.CounterSize;
30
import com.spice.profitmandi.common.enumuration.CounterSize;
27
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
31
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
28
import com.spice.profitmandi.common.model.AddLocationModel;
32
import com.spice.profitmandi.common.model.AddLocationModel;
-
 
33
import com.spice.profitmandi.common.model.CustomRetailer;
29
import com.spice.profitmandi.common.model.ProfitMandiConstants;
34
import com.spice.profitmandi.common.model.ProfitMandiConstants;
30
import com.spice.profitmandi.common.model.SendNotificationModel;
35
import com.spice.profitmandi.common.model.SendNotificationModel;
31
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
36
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
32
import com.spice.profitmandi.common.util.Utils;
37
import com.spice.profitmandi.common.util.Utils;
33
import com.spice.profitmandi.common.web.util.ResponseSender;
38
import com.spice.profitmandi.common.web.util.ResponseSender;
34
import com.spice.profitmandi.dao.entity.dtr.Document;
39
import com.spice.profitmandi.dao.entity.dtr.Document;
35
import com.spice.profitmandi.dao.entity.dtr.Retailer;
40
import com.spice.profitmandi.dao.entity.dtr.Retailer;
36
import com.spice.profitmandi.dao.entity.dtr.Shop;
41
import com.spice.profitmandi.dao.entity.dtr.Shop;
-
 
42
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
43
import com.spice.profitmandi.dao.entity.fofo.InActiveFofoStore;
37
import com.spice.profitmandi.dao.entity.user.User;
44
import com.spice.profitmandi.dao.entity.user.User;
38
import com.spice.profitmandi.dao.entity.user.Location;
45
import com.spice.profitmandi.dao.entity.user.Location;
39
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
46
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
-
 
47
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
40
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
48
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
41
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
49
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
42
import com.spice.profitmandi.dao.repository.user.LocationRepository;
50
import com.spice.profitmandi.dao.repository.user.LocationRepository;
43
import com.spice.profitmandi.dao.repository.user.UserRepository;
51
import com.spice.profitmandi.dao.repository.user.UserRepository;
44
import com.spice.profitmandi.service.user.RetailerService;
52
import com.spice.profitmandi.service.user.RetailerService;
45
import com.spice.profitmandi.web.util.MVCResponseSender;
53
import com.spice.profitmandi.web.util.MVCResponseSender;
46
 
54
 
47
@Controller
55
@Controller
48
@Transactional(rollbackFor=Throwable.class)
56
@Transactional(rollbackFor = Throwable.class)
49
public class RetailerController {
57
public class RetailerController {
50
 
58
 
51
	private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
59
	private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
52
	
60
 
53
	@Autowired
61
	@Autowired
54
	private RetailerService retailerService;
62
	private RetailerService retailerService;
55
	
63
 
56
	@Autowired
64
	@Autowired
57
	private RetailerRepository retailerRepository;
65
	private RetailerRepository retailerRepository;
58
	
66
 
59
	@Autowired
67
	@Autowired
60
	private ShopRepository shopRepository;
68
	private ShopRepository shopRepository;
-
 
69
 
-
 
70
	@Autowired
-
 
71
	private FofoStoreRepository fofoStoreRepository;
61
	
72
 
62
	@Autowired
73
	@Autowired
63
	private DocumentRepository documentRepository;
74
	private DocumentRepository documentRepository;
64
	
75
 
65
	@Autowired
76
	@Autowired
66
	private UserRepository userRepository;
77
	private UserRepository userRepository;
67
	
78
 
68
	@Autowired
79
	@Autowired
69
	private LocationRepository locationRepository;
80
	private LocationRepository locationRepository;
70
	
81
 
71
	@Autowired
82
	@Autowired
72
	private ResponseSender<?> responseSender;
83
	private ResponseSender<?> responseSender;
73
	
84
 
74
	@Autowired
85
	@Autowired
75
	private MVCResponseSender mvcResponseSender;
86
	private MVCResponseSender mvcResponseSender;
76
	
87
 
77
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.GET)
88
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.GET)
-
 
89
	public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request,
78
	public String retailerInfoByEmailIdOrMobileNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber, Model model)  throws ProfitMandiBusinessException{
90
			@RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber,
-
 
91
			Model model) throws ProfitMandiBusinessException {
79
		LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(), emailIdOrMobileNumber);
92
		LOGGER.info("Request Received at url {} with emailIdOrMobileNumber {}", request.getRequestURI(),
-
 
93
				emailIdOrMobileNumber);
80
		Map<String, Object> map = retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber);
94
		Map<String, Object> map = retailerService.getByEmailIdOrMobileNumber(emailIdOrMobileNumber);
81
		model.addAllAttributes(map);
95
		model.addAllAttributes(map);
82
		model.addAttribute("counterSizes", CounterSize.values());
96
		model.addAttribute("counterSizes", CounterSize.values());
83
		User user = userRepository.selectByEmailId(emailIdOrMobileNumber);
97
		User user = userRepository.selectByEmailId(emailIdOrMobileNumber);
84
		if(user.getLocation() != null){
98
		if (user.getLocation() != null) {
85
		Location location = locationRepository.selectById(user.getLocation());
99
			Location location = locationRepository.selectById(user.getLocation());
86
		model.addAttribute("locationdetail",location);
100
			model.addAttribute("locationdetail", location);
87
		 LOGGER.info("location"+location );
101
			LOGGER.info("location" + location);
88
		}
102
		}
89
		LOGGER.info("map detail"+ map) ;
103
		LOGGER.info("map detail" + map);
90
      
104
 
91
		return "retailer-details";
105
		return "retailer-details";
92
	}
106
	}
93
	
107
 
94
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.PUT)
108
	@RequestMapping(value = "/retailerDetails", method = RequestMethod.PUT)
-
 
109
	public String updateRetailerDetails(HttpServletRequest request,
95
	public String updateRetailerDetails(HttpServletRequest request, @RequestBody UpdateRetailerRequest updateRetailerRequest, Model model)  throws ProfitMandiBusinessException{
110
			@RequestBody UpdateRetailerRequest updateRetailerRequest, Model model) throws ProfitMandiBusinessException {
96
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), updateRetailerRequest);
111
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), updateRetailerRequest);
97
		Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
112
		Map<String, Object> map = retailerService.updateRetailerDetails(updateRetailerRequest);
98
		model.addAllAttributes(map);
113
		model.addAllAttributes(map);
99
		model.addAttribute("counterSizes", CounterSize.values());
114
		model.addAttribute("counterSizes", CounterSize.values());
100
		return "retailer-details";
115
		return "retailer-details";
101
	}
116
	}
102
	
-
 
103
 
117
 
104
	@RequestMapping(value = "/retailerInfo", method = RequestMethod.GET)
118
	@RequestMapping(value = "/retailerInfo", method = RequestMethod.GET)
105
	public String retailerInfo(HttpServletRequest request)  throws Exception{
119
	public String retailerInfo(HttpServletRequest request) throws Exception {
106
		return "retailer-info";
120
		return "retailer-info";
107
	}
121
	}
108
	
122
 
109
	@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
123
	@RequestMapping(value = "/district/all/stateName", method = RequestMethod.GET)
110
	public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName){
124
	public ResponseEntity<?> getAllDistrict(@RequestParam(name = "stateName") String stateName) {
111
		return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
125
		return responseSender.ok(retailerService.getAllDistrictMaster(stateName));
112
	}
126
	}
113
	
127
 
114
	@RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
128
	@RequestMapping(value = "/retailerDocument/documentId", method = RequestMethod.GET)
-
 
129
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
-
 
130
			@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId,
115
	public ResponseEntity<?> retailerDocumentById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException{
131
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
116
		Document document = documentRepository.selectById(documentId);
132
		Document document = documentRepository.selectById(documentId);
117
		Retailer retailer = retailerRepository.selectById(retailerId);
133
		Retailer retailer = retailerRepository.selectById(retailerId);
118
		
134
 
119
		if(retailer.getDocumentId() == null) {
135
		if (retailer.getDocumentId() == null) {
120
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
136
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
121
		}
137
		}
122
		if(retailer.getDocumentId() != documentId) {
138
		if (retailer.getDocumentId() != documentId) {
123
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
139
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
124
		}
140
		}
125
		return responseSender.ok(document);
141
		return responseSender.ok(document);
126
	}
142
	}
127
	
143
 
128
	@RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
144
	@RequestMapping(value = "/retailerDocument/download", method = RequestMethod.GET)
-
 
145
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request,
129
	public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model) throws ProfitMandiBusinessException{
146
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
-
 
147
			throws ProfitMandiBusinessException {
130
		
148
 
131
		Retailer retailer = retailerRepository.selectById(retailerId);
149
		Retailer retailer = retailerRepository.selectById(retailerId);
132
		
150
 
133
		if(retailer.getDocumentId() == null) {
151
		if (retailer.getDocumentId() == null) {
134
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
152
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "RTLR_1012");
135
		}
153
		}
136
		
154
 
137
		Document document = documentRepository.selectById(retailer.getDocumentId());
155
		Document document = documentRepository.selectById(retailer.getDocumentId());
138
		
156
 
139
		FileInputStream file = null;
157
		FileInputStream file = null;
140
		try {
158
		try {
141
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
159
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
142
		} catch (FileNotFoundException e) {
160
		} catch (FileNotFoundException e) {
143
			LOGGER.error("Retailer Document file not found : ", e);
161
			LOGGER.error("Retailer Document file not found : ", e);
144
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
162
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
145
		}
163
		}
146
		//ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
164
		// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
147
		//ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
165
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
148
		
166
 
149
		final HttpHeaders headers=new HttpHeaders();
167
		final HttpHeaders headers = new HttpHeaders();
150
		String contentType = "";
168
		String contentType = "";
151
		if(document.getContentType() == ContentType.JPEG) {
169
		if (document.getContentType() == ContentType.JPEG) {
152
			contentType = "image/jpeg";
170
			contentType = "image/jpeg";
153
		}else if(document.getContentType() == ContentType.PNG) {
171
		} else if (document.getContentType() == ContentType.PNG) {
154
			contentType = "image/png";
172
			contentType = "image/png";
155
		}else if(document.getContentType() == ContentType.PDF) {
173
		} else if (document.getContentType() == ContentType.PDF) {
156
			contentType = "application/pdf";
174
			contentType = "application/pdf";
157
		}
175
		}
158
        headers.set("Content-Type", contentType);
176
		headers.set("Content-Type", contentType);
159
		headers.set("Content-disposition", "inline; filename="+document.getName());
177
		headers.set("Content-disposition", "inline; filename=" + document.getName());
160
        headers.setContentLength(document.getSize());
178
		headers.setContentLength(document.getSize());
161
        final InputStreamResource inputStreamResource=new InputStreamResource(file);
179
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
162
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
180
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
163
		
181
 
164
		//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
182
		// return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
165
	}
183
	}
166
	
184
 
167
	@RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
185
	@RequestMapping(value = "/retailerShopDocument/shopId", method = RequestMethod.GET)
-
 
186
	public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request,
-
 
187
			@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
168
	public ResponseEntity<?> retailerShopDocumentById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId, @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException{
188
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId) throws ProfitMandiBusinessException {
169
		Shop shop = shopRepository.selectById(shopId);
189
		Shop shop = shopRepository.selectById(shopId);
170
		
190
 
171
		if(shop.getRetailerId() != retailerId) {
191
		if (shop.getRetailerId() != retailerId) {
172
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
192
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
173
		}
193
		}
174
		
194
 
175
		if(shop.getDocumentId() == null) {
195
		if (shop.getDocumentId() == null) {
176
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
196
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
177
		}
197
		}
178
		
198
 
179
		Document document = documentRepository.selectById(shop.getDocumentId());
199
		Document document = documentRepository.selectById(shop.getDocumentId());
180
		return responseSender.ok(document);
200
		return responseSender.ok(document);
181
	}
201
	}
182
	
202
 
183
	@RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
203
	@RequestMapping(value = "/retailerShopDocument/download", method = RequestMethod.GET)
-
 
204
	public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request,
-
 
205
			@RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId,
184
	public ResponseEntity<?> downloadRetailerShopDocument(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SHOP_ID) int shopId, @RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model) throws ProfitMandiBusinessException{
206
			@RequestParam(name = ProfitMandiConstants.RETAILER_ID) int retailerId, Model model)
-
 
207
			throws ProfitMandiBusinessException {
185
		
208
 
186
		Shop shop = shopRepository.selectById(shopId);
209
		Shop shop = shopRepository.selectById(shopId);
187
		
210
 
188
		if(shop.getRetailerId() != retailerId) {
211
		if (shop.getRetailerId() != retailerId) {
189
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
212
			throw new ProfitMandiBusinessException(ProfitMandiConstants.SHOP_ID, shop.getId(), "SHP_1004");
190
		}
213
		}
191
		
214
 
192
		if(shop.getDocumentId() == null) {
215
		if (shop.getDocumentId() == null) {
193
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
216
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, shop.getId(), "SHP_1005");
194
		}
217
		}
195
		
218
 
196
		Document document = documentRepository.selectById(shop.getDocumentId());
219
		Document document = documentRepository.selectById(shop.getDocumentId());
197
		
220
 
198
		FileInputStream file = null;
221
		FileInputStream file = null;
199
		try {
222
		try {
200
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
223
			file = new FileInputStream(document.getPath() + File.separator + document.getName());
201
		} catch (FileNotFoundException e) {
224
		} catch (FileNotFoundException e) {
202
			LOGGER.error("Retailer Document file not found : ", e);
225
			LOGGER.error("Retailer Document file not found : ", e);
203
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
226
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
204
		}
227
		}
205
		//ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
228
		// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
206
		//ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
229
		// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
207
		
230
 
208
		final HttpHeaders headers=new HttpHeaders();
231
		final HttpHeaders headers = new HttpHeaders();
209
		String contentType = "";
232
		String contentType = "";
210
		if(document.getContentType() == ContentType.JPEG) {
233
		if (document.getContentType() == ContentType.JPEG) {
211
			contentType = "image/jpeg";
234
			contentType = "image/jpeg";
212
		}else if(document.getContentType() == ContentType.PNG) {
235
		} else if (document.getContentType() == ContentType.PNG) {
213
			contentType = "image/png";
236
			contentType = "image/png";
214
		}else if(document.getContentType() == ContentType.PDF) {
237
		} else if (document.getContentType() == ContentType.PDF) {
215
			contentType = "application/pdf";
238
			contentType = "application/pdf";
216
		}
239
		}
217
        headers.set("Content-Type", contentType);
240
		headers.set("Content-Type", contentType);
218
		headers.set("Content-disposition", "inline; filename="+document.getName());
241
		headers.set("Content-disposition", "inline; filename=" + document.getName());
219
        headers.setContentLength(document.getSize());
242
		headers.setContentLength(document.getSize());
220
        final InputStreamResource inputStreamResource=new InputStreamResource(file);
243
		final InputStreamResource inputStreamResource = new InputStreamResource(file);
221
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
244
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
222
		
245
 
223
		//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
246
		// return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
224
	}
247
	}
225
	
248
 
226
	@RequestMapping(value = "/getAddLocation", method = RequestMethod.GET)
249
	@RequestMapping(value = "/getAddLocation", method = RequestMethod.GET)
227
	public String getAddLocationModal(HttpServletRequest request , Model model)  throws ProfitMandiBusinessException{
250
	public String getAddLocationModal(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
228
		model.addAttribute("stateNames", Utils.getAllStateNames());
251
		model.addAttribute("stateNames", Utils.getAllStateNames());
229
      
252
 
230
		return "add-location-modal";
253
		return "add-location-modal";
231
	}
254
	}
232
	
255
 
233
	@RequestMapping(value = "/addLocation", method = RequestMethod.POST)
256
	@RequestMapping(value = "/addLocation", method = RequestMethod.POST)
234
	public String addLocation(HttpServletRequest request , @RequestBody AddLocationModel addLocationModel,Model model)  throws Exception{
257
	public String addLocation(HttpServletRequest request, @RequestBody AddLocationModel addLocationModel, Model model)
-
 
258
			throws Exception {
235
		
259
 
236
        Location location = new Location();
260
		Location location = new Location();
237
        location.setName(addLocationModel.getName());
261
		location.setName(addLocationModel.getName());
238
        location.setLine1(addLocationModel.getLine1());
262
		location.setLine1(addLocationModel.getLine1());
239
        location.setLine2(addLocationModel.getLine2());
263
		location.setLine2(addLocationModel.getLine2());
240
        location.setCity(addLocationModel.getCity());
264
		location.setCity(addLocationModel.getCity());
241
        location.setState(addLocationModel.getState());
265
		location.setState(addLocationModel.getState());
242
        location.setPin(addLocationModel.getPin());
266
		location.setPin(addLocationModel.getPin());
243
        
267
 
244
        LOGGER.info("PostLocation"+location);
268
		LOGGER.info("PostLocation" + location);
245
       locationRepository.persist(location);
269
		locationRepository.persist(location);
246
        
270
 
247
        model.addAttribute("response", mvcResponseSender.createResponseString(true));
271
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
248
		return "response";
272
		return "response";
249
      
273
 
250
	}
274
	}
251
}
-
 
252
275
 
-
 
276
	@GetMapping(value = "/getAllStores")
-
 
277
	public String getAllStores(HttpServletRequest request, Model model) {
-
 
278
 
-
 
279
		List<FofoStore> fofoStores = fofoStoreRepository.selectAll();
-
 
280
 
-
 
281
		LOGGER.info(this.getFofoIds(fofoStores));
-
 
282
 
-
 
283
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(this.getFofoIds(fofoStores));
-
 
284
 
-
 
285
		model.addAttribute("fofoStores", fofoStores);
-
 
286
 
-
 
287
		model.addAttribute("customRetailers", customRetailers);
-
 
288
 
-
 
289
		return "store";
-
 
290
 
-
 
291
	}
-
 
292
 
-
 
293
	@PostMapping(value = "/deactivateStore")
-
 
294
	public String deActivateStore(HttpServletRequest request,
-
 
295
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model) throws Exception {
-
 
296
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
297
 
-
 
298
		InActiveFofoStore inActiveFofoStore = new InActiveFofoStore();
-
 
299
		inActiveFofoStore.setId(fofoStore.getId());
-
 
300
		inActiveFofoStore.setCode(fofoStore.getCode());
-
 
301
		inActiveFofoStore.setCounterSize(fofoStore.getCounterSize());
-
 
302
		inActiveFofoStore.setLatitude(fofoStore.getLatitude());
-
 
303
		inActiveFofoStore.setLongitude(fofoStore.getLongitude());
-
 
304
 
-
 
305
		inActiveFofoStore.setMinimumInvestment(fofoStore.getMinimumInvestment());
-
 
306
 
-
 
307
		inActiveFofoStore.setUserAddress(fofoStore.getUserAddress());
-
 
308
 
-
 
309
		fofoStoreRepository.saveInActiveStore(inActiveFofoStore);
-
 
310
 
-
 
311
		LOGGER.info("inserted into InActiveFofoStore successfully");
-
 
312
 
-
 
313
		fofoStoreRepository.delete(fofoStore);
-
 
314
 
-
 
315
		LOGGER.info("Deleted from fofoStore successfully");
-
 
316
 
-
 
317
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
318
 
-
 
319
		return "response";
-
 
320
 
-
 
321
	}
-
 
322
 
-
 
323
	private List<Integer> getFofoIds(List<FofoStore> fofoStores) {
-
 
324
 
-
 
325
		List<Integer> fofoIds = new ArrayList<>();
-
 
326
 
-
 
327
		for (FofoStore fofoStore : fofoStores) {
-
 
328
 
-
 
329
			fofoIds.add(fofoStore.getId());
-
 
330
 
-
 
331
		}
-
 
332
 
-
 
333
		return fofoIds;
-
 
334
 
-
 
335
	}
-
 
336
 
-
 
337
}
-
 
338