Subversion Repositories SmartDukaan

Rev

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

Rev 21763 Rev 21777
Line 49... Line 49...
49
	RetailerTagRepository fofoTagRepository;
49
	RetailerTagRepository fofoTagRepository;
50
	
50
	
51
	@Autowired
51
	@Autowired
52
	ResponseSender<?> responseSender;
52
	ResponseSender<?> responseSender;
53
	
53
	
54
	@RequestMapping(value = ProfitMandiConstants.URL_PIN_CODE_TAG, method = RequestMethod.POST)
54
	@RequestMapping(value = ProfitMandiConstants.URL_TAG, method = RequestMethod.POST)
55
	public ResponseEntity<?> createPinCodeTag(HttpServletRequest request, @RequestBody CreateTagRequest createTagRequest) {
55
	public ResponseEntity<?> createPinCodeTag(HttpServletRequest request, @RequestBody CreateTagRequest createTagRequest) {
56
		Set<String> invalidPinCodes = new HashSet<>();
56
		Set<String> invalidPinCodes = new HashSet<>();
57
		for(String pinCode : createTagRequest.getRejectedPinCodes()){
57
		for(String pinCode : createTagRequest.getPinCodes()){
58
			if(!StringUtils.isValidPinCode(pinCode)){
58
			if(!StringUtils.isValidPinCode(pinCode)){
59
				invalidPinCodes.add(pinCode);
59
				invalidPinCodes.add(pinCode);
60
			}
60
			}
61
		}
61
		}
62
		if(!invalidPinCodes.isEmpty()){
62
		if(!invalidPinCodes.isEmpty()){
63
			ProfitMandiBusinessException profitMandiBusinessException =  new ProfitMandiBusinessException(ProfitMandiConstants.PIN_CODE, invalidPinCodes, "PNCD_VE_1000");
63
			ProfitMandiBusinessException profitMandiBusinessException =  new ProfitMandiBusinessException(ProfitMandiConstants.PIN_CODE, invalidPinCodes, "PNCD_VE_1000");
64
			return responseSender.badRequest(profitMandiBusinessException);
64
			return responseSender.badRequest(profitMandiBusinessException);
65
		}
65
		}
66
		
66
		
67
		Set<Integer> foundRetailerIds = new HashSet<>();
67
		Set<Integer> foundRetailerIds = new HashSet<>();
68
		List<Retailer> retailers = retailerRepository.selectByIds(createTagRequest.getRejectedRetailerIds());
68
		List<Retailer> retailers = retailerRepository.selectByIds(createTagRequest.getRetailerIds());
69
		if(retailers.size() != createTagRequest.getRejectedRetailerIds().size()){
69
		if(retailers.size() != createTagRequest.getRetailerIds().size()){
70
			for(Retailer retailer : retailers){
70
			for(Retailer retailer : retailers){
71
				foundRetailerIds.add(retailer.getId());
71
				foundRetailerIds.add(retailer.getId());
72
			}
72
			}
73
			Collection<?> notFoundRetailerId = CollectionUtils.subtract(createTagRequest.getRejectedRetailerIds(), foundRetailerIds);
73
			Collection<?> notFoundRetailerId = CollectionUtils.subtract(createTagRequest.getRetailerIds(), foundRetailerIds);
74
			ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ProfitMandiConstants.REJECTED_USER_IDS, notFoundRetailerId, "RTLR_1000");
74
			ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ProfitMandiConstants.REJECTED_USER_IDS, notFoundRetailerId, "RTLR_1000");
75
			return responseSender.badRequest(profitMandiBusinessException);
75
			return responseSender.badRequest(profitMandiBusinessException);
76
		}else{
76
		}else{
77
			// given retailer ids are fofo user id's or not
77
			// given retailer ids are fofo user id's or not
78
			Set<Integer> notFofoRetailerIds = new HashSet<>();
78
			Set<Integer> notFofoRetailerIds = new HashSet<>();
Line 99... Line 99...
99
			tag.setUserAll(createTagRequest.isUserAll());
99
			tag.setUserAll(createTagRequest.isUserAll());
100
			tag.setCreatedBy(1);
100
			tag.setCreatedBy(1);
101
			tagRepository.persist(tag);
101
			tagRepository.persist(tag);
102
			//return responseSender.badRequest(profitMandiBusinessException);
102
			//return responseSender.badRequest(profitMandiBusinessException);
103
		}
103
		}
104
		for(int retailerId : createTagRequest.getRejectedRetailerIds()){
104
		for(int retailerId : createTagRequest.getRetailerIds()){
105
			RetailerTag fofoTag = new RetailerTag();
105
			RetailerTag fofoTag = new RetailerTag();
106
			fofoTag.setRetailerId(retailerId);
106
			fofoTag.setRetailerId(retailerId);
107
			fofoTag.setTagId(tag.getId());
107
			fofoTag.setTagId(tag.getId());
108
			fofoTag.setActive(true);
108
			fofoTag.setActive(true);
109
			fofoTagRepository.persist(fofoTag);
109
			fofoTagRepository.persist(fofoTag);
110
		}
110
		}
111
		for(String pinCode : createTagRequest.getRejectedPinCodes()){
111
		for(String pinCode : createTagRequest.getPinCodes()){
112
			PinCodeTag pinCodeTag = new PinCodeTag();
112
			PinCodeTag pinCodeTag = new PinCodeTag();
113
			pinCodeTag.setPinCode(pinCode);
113
			pinCodeTag.setPinCode(pinCode);
114
			pinCodeTag.setTagId(tag.getId());
114
			pinCodeTag.setTagId(tag.getId());
115
			pinCodeTag.setActive(true);
115
			pinCodeTag.setActive(true);
116
			pinCodeTagRepository.persist(pinCodeTag);
116
			pinCodeTagRepository.persist(pinCodeTag);