Subversion Repositories SmartDukaan

Rev

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

Rev 22876 Rev 22931
Line 83... Line 83...
83
	
83
	
84
	private static final Logger LOGGER=LoggerFactory.getLogger(RetailerController.class);
84
	private static final Logger LOGGER=LoggerFactory.getLogger(RetailerController.class);
85
	
85
	
86
	@Autowired
86
	@Autowired
87
	@Qualifier("userRepository")
87
	@Qualifier("userRepository")
88
	UserRepository userRepository;
88
	private UserRepository userRepository;
89
	
89
	
90
	@Autowired
90
	@Autowired
91
	@Qualifier("userUserRepository")
91
	@Qualifier("userUserRepository")
92
	com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
92
	private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
93
	
93
	
94
	@Autowired
94
	@Autowired
95
	UserRoleRepository userRoleRepository;
95
	private UserRoleRepository userRoleRepository;
96
	
96
	
97
	@Autowired
97
	@Autowired
98
	ResponseSender<?> responseSender;
98
	private ResponseSender<?> responseSender;
99
	
99
	
100
	@Autowired
100
	@Autowired
101
	RetailerRepository retailerRepository;
101
	private RetailerRepository retailerRepository;
102
	
102
	
103
	@Autowired
103
	@Autowired
104
	BrandRepository brandRepository;
104
	private BrandRepository brandRepository;
105
	
105
	
106
	@Autowired
106
	@Autowired
107
	AddressRepository addressRepository;
107
	private AddressRepository addressRepository;
108
	
108
	
109
	@Autowired
109
	@Autowired
110
	DocumentRepository documentRepository;
110
	private DocumentRepository documentRepository;
111
	
111
	
112
	@Autowired
112
	@Autowired
113
	ShopRepository shopRepository;
113
	private ShopRepository shopRepository;
114
	
114
	
115
	@Autowired
115
	@Autowired
116
	UserAccountRepository userAccountRepository;
116
	private UserAccountRepository userAccountRepository;
117
	
117
	
118
	@Autowired
118
	@Autowired
119
	RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
119
	private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
120
	
120
	
121
	@Autowired
121
	@Autowired
122
	RetailerAddressRepository retailerAddressRepository;
122
	private RetailerAddressRepository retailerAddressRepository;
123
	
123
	
124
	@Autowired
124
	@Autowired
125
	ShopAddressRepository shopAddressRepository;
125
	private ShopAddressRepository shopAddressRepository;
126
	
126
	
127
	@Autowired
127
	@Autowired
128
	RetailerBrandRepository retailerBrandRepository;
128
	private RetailerBrandRepository retailerBrandRepository;
129
	
129
	
130
	@Autowired
130
	@Autowired
131
	CounterRepository counterRepository;
131
	private CounterRepository counterRepository;
132
	
132
	
133
	@Autowired
133
	@Autowired
134
	PrivateDealUserRepository privateDealUserRepository;
134
	private PrivateDealUserRepository privateDealUserRepository;
135
	
135
	
136
	@Autowired
136
	@Autowired
137
	PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
137
	private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
138
	
138
	
139
	@Autowired
139
	@Autowired
140
	CartRepository cartRepository;
140
	private CartRepository cartRepository;
141
	
141
	
142
	@Autowired
142
	@Autowired
143
	DistrictMasterRepository districtMasterRepository;
143
	private DistrictMasterRepository districtMasterRepository;
144
	
144
	
145
	@Autowired
145
	@Autowired
146
	FofoStoreRepository fofoStoreRepository;
146
	private FofoStoreRepository fofoStoreRepository;
147
	
147
	
148
	@Autowired
148
	@Autowired
149
	private Mongo mongoClient;
149
	private Mongo mongoClient;
150
	
150
	
151
	@Autowired
151
	@Autowired
152
	FofoStoreSequenceGenerationRepository fofoStoreSequenceGenerationRepository;
152
	private FofoStoreSequenceGenerationRepository fofoStoreSequenceGenerationRepository;
153
	
153
	
154
	@ApiImplicitParams({
154
	@ApiImplicitParams({
155
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
155
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
156
				required = true, dataType = "string", paramType = "header")
156
				required = true, dataType = "string", paramType = "header")
157
	})
157
	})
158
	
158
	
159
	@ApiOperation(value = "Create Retailer")
159
	@ApiOperation(value = "Create Retailer")
160
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER, method=RequestMethod.POST)
160
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER, method=RequestMethod.POST)
161
	public ResponseEntity<?> createRetailer(HttpServletRequest request, @RequestBody CreateRetailerRequest createRetailerRequest) throws ProfitMandiBusinessException, Exception{
161
	public ResponseEntity<?> createRetailer(HttpServletRequest request, @RequestBody CreateRetailerRequest createRetailerRequest) throws ProfitMandiBusinessException{
162
		LOGGER.info("request received with body [{}] at url {{}}: ", createRetailerRequest, request.getRequestURL().toString());
162
		LOGGER.info("request received with body [{}] at url {{}}: ", createRetailerRequest, request.getRequestURL().toString());
163
		try{
-
 
164
			UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
163
		UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
165
			LOGGER.info("requestAttribute [userInfo={}]", userInfo);
164
		LOGGER.info("requestAttribute [userInfo={}]", userInfo);
166
			User user = userRepository.selectById(userInfo.getUserId());
165
		User user = userRepository.selectById(userInfo.getUserId());
167
			this.createRetailer(user, createRetailerRequest);
166
		this.createRetailer(user, createRetailerRequest);
168
			return responseSender.ok(ResponseCodeHolder.getMessage("RTLR_OK_1000"));
167
		return responseSender.ok(ResponseCodeHolder.getMessage("RTLR_OK_1000"));
169
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
170
			LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
-
 
171
			throw profitMandiBusinessException;
-
 
172
			//return responseSender.badRequest(profitMandiBusinessException);
-
 
173
		}
168
		
174
	}
169
	}
175
	
170
	
176
	private void createRetailer(User user, CreateRetailerRequest createRetailerRequest) 
171
	private void createRetailer(User user, CreateRetailerRequest createRetailerRequest) 
177
			throws ProfitMandiBusinessException, Exception{
172
			throws ProfitMandiBusinessException{
178
		Retailer retailer = new Retailer();
173
		Retailer retailer = new Retailer();
179
		retailer.setName(createRetailerRequest.getName());
174
		retailer.setName(createRetailerRequest.getName());
180
		retailer.setNumber(createRetailerRequest.getNumber());
175
		retailer.setNumber(createRetailerRequest.getNumber());
181
		retailer.setType(createRetailerRequest.getType());
176
		retailer.setType(createRetailerRequest.getType());
182
		retailer.setMonthlySaleValue(createRetailerRequest.getMonthlySaleValue());
177
		retailer.setMonthlySaleValue(createRetailerRequest.getMonthlySaleValue());
Line 330... Line 325...
330
			privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
325
			privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
331
			
326
			
332
			saholicUser.setAddressId(addressRetailer.getId());
327
			saholicUser.setAddressId(addressRetailer.getId());
333
			userUserRepository.persist(saholicUser);
328
			userUserRepository.persist(saholicUser);
334
		}
329
		}
335
		/*StateInfo stateInfo = Utils.getStateInfo(addressRetailer.getState());
-
 
336
		DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(createRetailerRequest.getDistrict(), stateInfo.getShortName());
-
 
337
		FofoStoreSequenceGeneration fofoStoreSequenceGeneration = null;
-
 
338
		boolean foundFofoStoreSequence = false;
-
 
339
		try{
-
 
340
			fofoStoreSequenceGeneration = fofoStoreSequenceGenerationRepository.selectByStateShortName(stateInfo.getShortName());
-
 
341
			foundFofoStoreSequence = true;
-
 
342
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
343
			fofoStoreSequenceGeneration = new FofoStoreSequenceGeneration();
-
 
344
			fofoStoreSequenceGeneration.setSequence(1);
-
 
345
			fofoStoreSequenceGeneration.setStateShortName(stateInfo.getShortName());
-
 
346
			fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
347
		}
-
 
348
		FofoStore fofoStore = new FofoStore();
-
 
349
		fofoStore.setId(retailer.getId());
-
 
350
		String fofoStoreCode = StringUtils.generateFofoStoreSequence(districtMaster.getStateShortName() + districtMaster.getShortName(), fofoStoreSequenceGeneration.getSequence());
-
 
351
		if(foundFofoStoreSequence){
-
 
352
			fofoStoreSequenceGeneration.setSequence(fofoStoreSequenceGeneration.getSequence() + 1);
-
 
353
			fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
354
		}
-
 
355
		fofoStore.setCode(fofoStoreCode);
-
 
356
		fofoStoreRepository.persist(fofoStore);*/
-
 
357
	}
330
	}
358
	
331
	
359
	private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId){
332
	private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId){
360
		if(gstNumber != null && !gstNumber.isEmpty()){
333
		if(gstNumber != null && !gstNumber.isEmpty()){
361
			Counter counter = new Counter();
334
			Counter counter = new Counter();
Line 386... Line 359...
386
	}
359
	}
387
	
360
	
388
	@ApiOperation(value = "Create Fofo Store")
361
	@ApiOperation(value = "Create Fofo Store")
389
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_FOFO_FOFO_STORE, method=RequestMethod.POST)
362
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_FOFO_FOFO_STORE, method=RequestMethod.POST)
390
	public ResponseEntity<?> createFofoStore(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.DISTRICT_NAME) String districtName) throws ProfitMandiBusinessException, Exception{
363
	public ResponseEntity<?> createFofoStore(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.DISTRICT_NAME) String districtName) throws ProfitMandiBusinessException, Exception{
-
 
364
		UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
-
 
365
		LOGGER.info("requestAttribute [userInfo={}]", userInfo);
-
 
366
		User user = userRepository.selectById(userInfo.getUserId());
-
 
367
		// = userAccountRepository.selectRetailerIdByUserId(user.getId());
-
 
368
		UserAccounts userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
-
 
369
		Retailer retailer = retailerRepository.selectById(Integer.parseInt(userAccounts.getAccount_key()));
391
		try{
370
		try{
392
			UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
-
 
393
			LOGGER.info("requestAttribute [userInfo={}]", userInfo);
-
 
394
			User user = userRepository.selectById(userInfo.getUserId());
-
 
395
			// = userAccountRepository.selectRetailerIdByUserId(user.getId());
-
 
396
			UserAccounts userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
-
 
397
			Retailer retailer = retailerRepository.selectById(Integer.parseInt(userAccounts.getAccount_key()));
-
 
398
			try{
-
 
399
				userRoleRepository.selectByUserIdAndRoleType(user.getId(), RoleType.FOFO);
371
			userRoleRepository.selectByUserIdAndRoleType(user.getId(), RoleType.FOFO);
400
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
372
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
401
				throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
373
			throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
402
			}
374
		}
403
			
375
		
404
			boolean foundFofoStore = false;
376
		boolean foundFofoStore = false;
405
			try{
377
		try{
406
				fofoStoreRepository.selectByRetailerId(retailer.getId());
378
			fofoStoreRepository.selectByRetailerId(retailer.getId());
407
				foundFofoStore = true;
379
			foundFofoStore = true;
408
			}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
409
				
-
 
410
			}
-
 
411
			
-
 
412
			if(foundFofoStore){
-
 
413
				throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "USR_1014");
-
 
414
			}			
-
 
415
			
-
 
416
			int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
-
 
417
			Address retailerAddress = addressRepository.selectById(retailerAddressId);
-
 
418
			
-
 
419
			StateInfo stateInfo = Utils.getStateInfo(retailerAddress.getState());
-
 
420
			DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName, stateInfo.getShortName());
-
 
421
			FofoStoreSequenceGeneration fofoStoreSequenceGeneration = null;
-
 
422
			boolean foundFofoStoreSequence = false;
-
 
423
			try{
-
 
424
				fofoStoreSequenceGeneration = fofoStoreSequenceGenerationRepository.selectByStateShortName(stateInfo.getShortName());
-
 
425
				foundFofoStoreSequence = true;
-
 
426
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
427
				fofoStoreSequenceGeneration = new FofoStoreSequenceGeneration();
-
 
428
				fofoStoreSequenceGeneration.setSequence(1);
-
 
429
				fofoStoreSequenceGeneration.setStateShortName(stateInfo.getShortName());
-
 
430
				fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
431
			}
-
 
432
			
-
 
433
			FofoStore fofoStore = new FofoStore();
-
 
434
			fofoStore.setId(retailer.getId());
-
 
435
			String fofoStoreCode = StringUtils.generateFofoStoreSequence(districtMaster.getStateShortName() + districtMaster.getShortName(), fofoStoreSequenceGeneration.getSequence());
-
 
436
			if(foundFofoStoreSequence){
-
 
437
				fofoStoreSequenceGeneration.setSequence(fofoStoreSequenceGeneration.getSequence() + 1);
-
 
438
				fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
439
			}
-
 
440
			fofoStore.setCode(fofoStoreCode);
-
 
441
			fofoStoreRepository.persist(fofoStore);
-
 
442
			
-
 
443
			return responseSender.ok(ResponseCodeHolder.getMessage("RTLR_OK_1003"));
-
 
444
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
380
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
381
			
-
 
382
		}
-
 
383
		
-
 
384
		if(foundFofoStore){
-
 
385
			throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailer.getId(), "USR_1014");
-
 
386
		}			
-
 
387
		
-
 
388
		int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
-
 
389
		Address retailerAddress = addressRepository.selectById(retailerAddressId);
-
 
390
		
-
 
391
		StateInfo stateInfo = Utils.getStateInfo(retailerAddress.getState());
-
 
392
		DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName, stateInfo.getShortName());
-
 
393
		FofoStoreSequenceGeneration fofoStoreSequenceGeneration = null;
-
 
394
		boolean foundFofoStoreSequence = false;
-
 
395
		try{
-
 
396
			fofoStoreSequenceGeneration = fofoStoreSequenceGenerationRepository.selectByStateShortName(stateInfo.getShortName());
-
 
397
			foundFofoStoreSequence = true;
445
			LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
398
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
399
			fofoStoreSequenceGeneration = new FofoStoreSequenceGeneration();
446
			throw profitMandiBusinessException;
400
			fofoStoreSequenceGeneration.setSequence(1);
-
 
401
			fofoStoreSequenceGeneration.setStateShortName(stateInfo.getShortName());
447
			//return responseSender.badRequest(profitMandiBusinessException);
402
			fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
448
		}
403
		}
-
 
404
		
-
 
405
		FofoStore fofoStore = new FofoStore();
-
 
406
		fofoStore.setId(retailer.getId());
-
 
407
		String fofoStoreCode = StringUtils.generateFofoStoreSequence(districtMaster.getStateShortName() + districtMaster.getShortName(), fofoStoreSequenceGeneration.getSequence());
-
 
408
		if(foundFofoStoreSequence){
-
 
409
			fofoStoreSequenceGeneration.setSequence(fofoStoreSequenceGeneration.getSequence() + 1);
-
 
410
			fofoStoreSequenceGenerationRepository.persist(fofoStoreSequenceGeneration);
-
 
411
		}
-
 
412
		fofoStore.setCode(fofoStoreCode);
-
 
413
		fofoStoreRepository.persist(fofoStore);
-
 
414
		
-
 
415
		return responseSender.ok(ResponseCodeHolder.getMessage("RTLR_OK_1003"));
-
 
416
		
449
	}
417
	}
450
	
418
	
451
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)
419
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)
452
	public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
420
	public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
453
		LOGGER.info("requested url : "+request.getRequestURL().toString());
421
		LOGGER.info("requested url : "+request.getRequestURL().toString());
454
		return responseSender.ok(retailerRepository.selectAll(pageNumber, pageSize));
422
		return responseSender.ok(retailerRepository.selectAll(pageNumber, pageSize));
455
	}
423
	}
456
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
424
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
457
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
425
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id) throws ProfitMandiBusinessException{
458
		LOGGER.info("requested url : "+request.getRequestURL().toString());
426
		LOGGER.info("requested url : "+request.getRequestURL().toString());
459
		try {
-
 
460
			return responseSender.ok(retailerRepository.selectById(id));
427
		return responseSender.ok(retailerRepository.selectById(id));
461
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
462
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
463
			return responseSender.badRequest(profitMandiBusinessException);
-
 
464
		}
-
 
465
	}
428
	}
466
	
429
	
467
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_NAME, method=RequestMethod.GET)
430
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_NAME, method=RequestMethod.GET)
468
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
431
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name) throws ProfitMandiBusinessException{
469
		LOGGER.info("requested url : "+request.getRequestURL().toString());
432
		LOGGER.info("requested url : "+request.getRequestURL().toString());
470
		try {
-
 
471
			return responseSender.ok(retailerRepository.selectByName(name));
433
		return responseSender.ok(retailerRepository.selectByName(name));
472
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
473
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
474
			return responseSender.badRequest(profitMandiBusinessException);
-
 
475
		}
-
 
476
	}
434
	}
477
		
435
		
478
	
436
	
479
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
437
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
480
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
438
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id) throws ProfitMandiBusinessException{
481
		LOGGER.info("requested url : "+request.getRequestURL().toString());
439
		LOGGER.info("requested url : "+request.getRequestURL().toString());
482
		try {
-
 
483
			retailerRepository.deleteById(id);
440
		retailerRepository.deleteById(id);
484
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
441
		return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
485
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
486
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
487
			return responseSender.badRequest(profitMandiBusinessException);
-
 
488
		}
-
 
489
	}
442
	}
490
	
443
	
491
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ADD, method=RequestMethod.POST)
444
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ADD, method=RequestMethod.POST)
492
	public ResponseEntity<?> addShop(HttpServletRequest request, @RequestBody com.spice.profitmandi.web.req.Shop createShop, @RequestParam(name = "retailerId") int retailerId){
445
	public ResponseEntity<?> addShop(HttpServletRequest request, @RequestBody com.spice.profitmandi.web.req.Shop createShop, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{
493
		LOGGER.info("requested url : "+request.getRequestURL().toString());
446
		LOGGER.info("requested url : "+request.getRequestURL().toString());
494
		try {
-
 
495
			Document document = documentRepository.selectById(createShop.getDocumentId());
447
		Document document = documentRepository.selectById(createShop.getDocumentId());
496
			if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){
448
		if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){
497
				LOGGER.error("documet is already mapped with another shop");
449
			LOGGER.error("documet is already mapped with another shop");
498
				throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "");
450
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "");
499
			}
-
 
500
			retailerRepository.selectById(retailerId);
-
 
501
			Shop shop = new Shop();
-
 
502
			shop.setRetailerId(retailerId);
-
 
503
			Address address = this.createAddress(createShop.getAddress());
-
 
504
			addressRepository.persist(address);
-
 
505
			shop.setAddressId(address.getId());
-
 
506
			shop.setDocumentId(document.getId());
-
 
507
			shopRepository.persist(shop);
-
 
508
			ShopAddress shopAddress = new ShopAddress();
-
 
509
			shopAddress.setAddressId(address.getId());
-
 
510
			shopAddress.setShopId(shop.getId());
-
 
511
			shopAddressRepository.persist(shopAddress);
-
 
512
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
-
 
513
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
514
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
515
			return responseSender.badRequest(profitMandiBusinessException);
-
 
516
		}
451
		}
-
 
452
		retailerRepository.selectById(retailerId);
-
 
453
		Shop shop = new Shop();
-
 
454
		shop.setRetailerId(retailerId);
-
 
455
		Address address = this.createAddress(createShop.getAddress());
-
 
456
		addressRepository.persist(address);
-
 
457
		shop.setAddressId(address.getId());
-
 
458
		shop.setDocumentId(document.getId());
-
 
459
		shopRepository.persist(shop);
-
 
460
		ShopAddress shopAddress = new ShopAddress();
-
 
461
		shopAddress.setAddressId(address.getId());
-
 
462
		shopAddress.setShopId(shop.getId());
-
 
463
		shopAddressRepository.persist(shopAddress);
-
 
464
		return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
-
 
465
		
517
	}
466
	}
518
	
467
	
519
	
468
	
520
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
469
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
521
	public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") int shopId, @RequestParam(name = "retailerId") int retailerId){
470
	public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") int shopId, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{
522
		LOGGER.info("requested url : "+request.getRequestURL().toString());
471
		LOGGER.info("requested url : "+request.getRequestURL().toString());
523
		try {
-
 
524
			retailerRepository.removeShop(shopId, retailerId);
472
		retailerRepository.removeShop(shopId, retailerId);
525
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
473
		return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
526
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
527
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
528
			return responseSender.badRequest(profitMandiBusinessException);
-
 
529
		}
-
 
530
	}
474
	}
531
	
475
	
532
	private Address createAddress(com.spice.profitmandi.web.req.Address createAddress){
476
	private Address createAddress(com.spice.profitmandi.web.req.Address createAddress){
533
		Address address = new Address();
477
		Address address = new Address();
534
		address.setName(createAddress.getName());
478
		address.setName(createAddress.getName());
Line 543... Line 487...
543
		
487
		
544
		return address;
488
		return address;
545
	}
489
	}
546
	
490
	
547
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ADD, method=RequestMethod.POST)
491
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ADD, method=RequestMethod.POST)
548
	public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CreateRetailerAddressRequest createRetailerAddress){
492
	public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CreateRetailerAddressRequest createRetailerAddress) throws ProfitMandiBusinessException{
549
		LOGGER.info("requested url : "+request.getRequestURL().toString());
493
		LOGGER.info("requested url : "+request.getRequestURL().toString());
550
		try {
-
 
551
			retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());
494
		retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());
552
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
495
		return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
553
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
554
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
555
			return responseSender.badRequest(profitMandiBusinessException);
-
 
556
		}
496
		
557
	}
497
	}
558
	
498
	
559
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_REMOVE, method=RequestMethod.DELETE)
499
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_REMOVE, method=RequestMethod.DELETE)
560
	public ResponseEntity<?> removeAddress(HttpServletRequest request, @RequestParam(name = "addressId") int addressId, @RequestParam(name = "retailerId") int retailerId){
500
	public ResponseEntity<?> removeAddress(HttpServletRequest request, @RequestParam(name = "addressId") int addressId, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{
561
		LOGGER.info("requested url : "+request.getRequestURL().toString());
501
		LOGGER.info("requested url : "+request.getRequestURL().toString());
562
		try {
-
 
563
			retailerRepository.removeAddress(addressId, retailerId);
502
		retailerRepository.removeAddress(addressId, retailerId);
564
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
503
		return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
565
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
566
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
567
			return responseSender.badRequest(profitMandiBusinessException);
-
 
568
		}
-
 
569
	}
504
	}
570
	
505
	
571
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ADD, method=RequestMethod.POST)
506
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ADD, method=RequestMethod.POST)
572
	public ResponseEntity<?> addBrand(HttpServletRequest request, @RequestBody RetailerAddBrandRequest retailerAddBrandRequest){
507
	public ResponseEntity<?> addBrand(HttpServletRequest request, @RequestBody RetailerAddBrandRequest retailerAddBrandRequest) throws ProfitMandiBusinessException{
573
		LOGGER.info("requested url : "+request.getRequestURL().toString());
508
		LOGGER.info("requested url : "+request.getRequestURL().toString());
574
		try {
-
 
575
			retailerRepository.selectById(retailerAddBrandRequest.getRetailerId());
509
		retailerRepository.selectById(retailerAddBrandRequest.getRetailerId());
576
			this.addBrandWithRetailer(retailerAddBrandRequest.getRetailerId(), retailerAddBrandRequest.getCategories());
510
		this.addBrandWithRetailer(retailerAddBrandRequest.getRetailerId(), retailerAddBrandRequest.getCategories());
577
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
511
		return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
578
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
579
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
580
			return responseSender.badRequest(profitMandiBusinessException);
-
 
581
		}
512
		
582
	}
513
	}
583
	
514
	
584
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_REMOVE, method=RequestMethod.DELETE)
515
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_REMOVE, method=RequestMethod.DELETE)
585
	public ResponseEntity<?> removeBrand(HttpServletRequest request, @RequestParam(name = "brandId") int brandId, @RequestParam(name = "retailerId") int retailerId){
516
	public ResponseEntity<?> removeBrand(HttpServletRequest request, @RequestParam(name = "brandId") int brandId, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{
586
		LOGGER.info("requested url : "+request.getRequestURL().toString());
517
		LOGGER.info("requested url : "+request.getRequestURL().toString());
587
		try {
-
 
588
			brandRepository.selectById(brandId);
518
		brandRepository.selectById(brandId);
589
			retailerRepository.selectById(retailerId);
519
		retailerRepository.selectById(retailerId);
590
			retailerBrandRepository.deleteByRetailerAndBrandId(retailerId, brandId);
520
		retailerBrandRepository.deleteByRetailerAndBrandId(retailerId, brandId);
591
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
521
		return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
592
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
593
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
594
			return responseSender.badRequest(profitMandiBusinessException);
-
 
595
		}
522
		
596
	}
523
	}
597
	
524
	
598
	
525
	
599
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT, method=RequestMethod.GET)
526
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT, method=RequestMethod.GET)
600
	public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId){
527
	public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{
601
		LOGGER.info("requested url : "+request.getRequestURL().toString());
528
		LOGGER.info("requested url : "+request.getRequestURL().toString());
602
		try {
-
 
603
			return responseSender.ok(retailerRepository.selectDocumentById(retailerId));
529
		return responseSender.ok(retailerRepository.selectDocumentById(retailerId));
604
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
605
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
606
			return responseSender.badRequest(profitMandiBusinessException);
-
 
607
		}
530
		
608
	}
531
	}
609
	
532
	
610
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_REGISTERED_ADDRESS, method=RequestMethod.GET)
533
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_REGISTERED_ADDRESS, method=RequestMethod.GET)
611
	public ResponseEntity<?> getRegisteredAddressById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId){
534
	public ResponseEntity<?> getRegisteredAddressById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId) throws ProfitMandiBusinessException{
612
		LOGGER.info("requested url : "+request.getRequestURL().toString());
535
		LOGGER.info("requested url : "+request.getRequestURL().toString());
613
		try {
-
 
614
			return responseSender.ok(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId));
536
		return responseSender.ok(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId));
615
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
616
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
617
			return responseSender.badRequest(profitMandiBusinessException);
-
 
618
		}
537
		
619
	}
538
	}
620
	
539
	
621
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)
540
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)
622
	public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") int id){
541
	public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") int id)throws ProfitMandiBusinessException{
623
		LOGGER.info("requested url : "+request.getRequestURL().toString());
542
		LOGGER.info("requested url : "+request.getRequestURL().toString());
624
		try {
-
 
625
			return responseSender.ok(shopRepository.selectByRetailerId(id));
543
		return responseSender.ok(shopRepository.selectByRetailerId(id));
626
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
627
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
628
			return responseSender.badRequest(profitMandiBusinessException);
-
 
629
		}
544
		
630
	}
545
	}
631
	
546
	
632
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)
547
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)
633
	public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") int id){
548
	public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") int id){
634
		LOGGER.info("requested url : "+request.getRequestURL().toString());
549
		LOGGER.info("requested url : "+request.getRequestURL().toString());
Line 641... Line 556...
641
		LOGGER.info("requested url : "+request.getRequestURL().toString());
556
		LOGGER.info("requested url : "+request.getRequestURL().toString());
642
		return responseSender.ok(retailerBrandRepository.selectBrandNamesByRetailerId(id));
557
		return responseSender.ok(retailerBrandRepository.selectBrandNamesByRetailerId(id));
643
	}
558
	}
644
 
559
 
645
	@RequestMapping(value = "/retailer/showFofoInterest", method=RequestMethod.GET)
560
	@RequestMapping(value = "/retailer/showFofoInterest", method=RequestMethod.GET)
646
	public ResponseEntity<?> showFofoInterest(HttpServletRequest request) throws Throwable{
561
	public ResponseEntity<?> showFofoInterest(HttpServletRequest request) throws ProfitMandiBusinessException{
647
		UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
562
		UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
648
		User user = userRepository.selectById(userInfo.getUserId());
563
		User user = userRepository.selectById(userInfo.getUserId());
649
		RetailerFofoInterest retailerInterest = new RetailerFofoInterest();
564
		RetailerFofoInterest retailerInterest = new RetailerFofoInterest();
650
		retailerInterest.setCity(user.getCity());
565
		retailerInterest.setCity(user.getCity());
651
		retailerInterest.setMobile(user.getMobileNumber());
566
		retailerInterest.setMobile(user.getMobileNumber());