Subversion Repositories SmartDukaan

Rev

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

Rev 22037 Rev 22548
Line 24... Line 24...
24
import com.spice.profitmandi.common.web.util.ResponseSender;
24
import com.spice.profitmandi.common.web.util.ResponseSender;
25
import com.spice.profitmandi.dao.entity.catalog.PinCodeTag;
25
import com.spice.profitmandi.dao.entity.catalog.PinCodeTag;
26
import com.spice.profitmandi.dao.entity.catalog.RetailerTag;
26
import com.spice.profitmandi.dao.entity.catalog.RetailerTag;
27
import com.spice.profitmandi.dao.entity.catalog.Tag;
27
import com.spice.profitmandi.dao.entity.catalog.Tag;
28
import com.spice.profitmandi.dao.entity.dtr.Retailer;
28
import com.spice.profitmandi.dao.entity.dtr.Retailer;
-
 
29
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
29
import com.spice.profitmandi.dao.enumuration.fofo.TagType;
30
import com.spice.profitmandi.dao.enumuration.fofo.TagType;
30
import com.spice.profitmandi.dao.repository.catalog.PinCodeTagRepository;
31
import com.spice.profitmandi.dao.repository.catalog.PinCodeTagRepository;
31
import com.spice.profitmandi.dao.repository.catalog.RetailerTagRepository;
32
import com.spice.profitmandi.dao.repository.catalog.RetailerTagRepository;
32
import com.spice.profitmandi.dao.repository.catalog.TagRepository;
33
import com.spice.profitmandi.dao.repository.catalog.TagRepository;
33
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
34
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
-
 
35
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
-
 
36
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
-
 
37
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
34
import com.spice.profitmandi.web.request.CreateTagRequest;
38
import com.spice.profitmandi.web.request.CreateTagRequest;
35
 
39
 
36
@Controller
40
@Controller
37
@Transactional(rollbackFor=Throwable.class)
41
@Transactional(rollbackFor=Throwable.class)
38
public class TagController {
42
public class TagController {
Line 43... Line 47...
43
	@Autowired
47
	@Autowired
44
	PinCodeTagRepository pinCodeTagRepository;
48
	PinCodeTagRepository pinCodeTagRepository;
45
	
49
	
46
	@Autowired
50
	@Autowired
47
	RetailerRepository retailerRepository;
51
	RetailerRepository retailerRepository;
-
 
52
 
-
 
53
	@Autowired
-
 
54
	UserAccountRepository userAccountRepoitory;
-
 
55
	
-
 
56
	
-
 
57
	@Autowired
-
 
58
	UserRoleRepository userRoleRepository;
-
 
59
 
-
 
60
	
-
 
61
	@Autowired
-
 
62
	UserRepository userRepoitory;
48
	
63
	
49
	@Autowired
64
	@Autowired
50
	RetailerTagRepository fofoTagRepository;
65
	RetailerTagRepository fofoTagRepository;
51
	
66
	
52
	@Autowired
67
	@Autowired
53
	ResponseSender<?> responseSender;
68
	ResponseSender<?> responseSender;
54
	
69
	
55
	@RequestMapping(value = ProfitMandiConstants.URL_TAG, method = RequestMethod.POST)
70
	@RequestMapping(value = ProfitMandiConstants.URL_TAG, method = RequestMethod.POST)
56
	public ResponseEntity<?> createPinCodeTag(HttpServletRequest request, @RequestBody CreateTagRequest createTagRequest) {
71
	public ResponseEntity<?> createPinCodeTag(HttpServletRequest request, @RequestBody CreateTagRequest createTagRequest) throws Throwable {
57
		Set<String> invalidPinCodes = new HashSet<>();
72
		Set<String> invalidPinCodes = new HashSet<>();
58
		for(String pinCode : createTagRequest.getPinCodes()){
73
		for(String pinCode : createTagRequest.getPinCodes()){
59
			if(!StringUtils.isValidPinCode(pinCode)){
74
			if(!StringUtils.isValidPinCode(pinCode)){
60
				invalidPinCodes.add(pinCode);
75
				invalidPinCodes.add(pinCode);
61
			}
76
			}
Line 76... Line 91...
76
				ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ProfitMandiConstants.REJECTED_USER_IDS, notFoundRetailerId, "RTLR_1000");
91
				ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ProfitMandiConstants.REJECTED_USER_IDS, notFoundRetailerId, "RTLR_1000");
77
				return responseSender.badRequest(profitMandiBusinessException);
92
				return responseSender.badRequest(profitMandiBusinessException);
78
			}else{
93
			}else{
79
				if(createTagRequest.getTagType() == TagType.FOFO){
94
				if(createTagRequest.getTagType() == TagType.FOFO){
80
					// given retailer ids are fofo user id's or not
95
					// given retailer ids are fofo user id's or not
81
					Set<Integer> notFofoRetailerIds = new HashSet<>();
-
 
82
					for(Retailer retailer : retailers){
96
					for(Retailer retailer : retailers){
-
 
97
						int userId = userAccountRepoitory.selectUserIdByRetailerId(retailer.getId());
-
 
98
						List<RoleType> roleTypes = userRoleRepository.selectRoleTypesByUserId(userId);
83
						if(!retailer.isFofo()){
99
						if(!roleTypes.contains(RoleType.FOFO)){
-
 
100
							ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ProfitMandiConstants.REJECTED_USER_IDS, retailer.getId(), "RTLR_1010");
84
							notFofoRetailerIds.add(retailer.getId());
101
							return responseSender.badRequest(profitMandiBusinessException);
85
						}
102
						}
86
					}
103
					}
87
					if(!notFofoRetailerIds.isEmpty()){
-
 
88
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(ProfitMandiConstants.REJECTED_USER_IDS, notFofoRetailerIds, "RTLR_1010");
-
 
89
						return responseSender.badRequest(profitMandiBusinessException);
-
 
90
					}
-
 
91
				}
104
				}
92
			}
105
			}
93
		}
106
		}
94
		Tag tag = null;
107
		Tag tag = null;
95
		/*try{
108
		/*try{