1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.tem.document.validation.impl;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.kfs.module.tem.TemPropertyConstants;
23 import org.kuali.kfs.module.tem.businessobject.TravelPayment;
24 import org.kuali.kfs.sys.KFSKeyConstants;
25 import org.kuali.kfs.sys.KFSPropertyConstants;
26 import org.kuali.kfs.sys.document.validation.GenericValidation;
27 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
28 import org.kuali.rice.krad.service.DataDictionaryService;
29 import org.kuali.rice.krad.util.GlobalVariables;
30 import org.kuali.rice.krad.util.MessageMap;
31 import org.kuali.rice.location.api.state.State;
32 import org.kuali.rice.location.api.state.StateService;
33
34
35
36
37 public class TravelPaymentSpecialHandlingStateCodeValidation extends GenericValidation {
38 protected TravelPayment travelPaymentForValidation;
39 protected StateService stateService;
40 protected DataDictionaryService dataDictionaryService;
41
42
43
44
45
46 @Override
47 public boolean validate(AttributedDocumentEvent event) {
48 boolean isValid = true;
49
50 MessageMap errors = GlobalVariables.getMessageMap();
51 errors.addToErrorPath(KFSPropertyConstants.DOCUMENT+"."+TemPropertyConstants.TRAVEL_PAYMENT);
52
53 final String countryCode = getTravelPaymentForValidation().getSpecialHandlingCountryCode();
54 final String stateCode = getTravelPaymentForValidation().getSpecialHandlingStateCode();
55 if (getTravelPaymentForValidation().isSpecialHandlingCode() && StringUtils.isNotBlank(stateCode) && StringUtils.isNotBlank(countryCode)) {
56 final State state = getStateService().getState(countryCode, stateCode);
57 if (state == null) {
58 final String label = getDataDictionaryService().getAttributeLabel(TravelPayment.class, TemPropertyConstants.TravelPaymentProperties.SPECIAL_HANDLING_STATE_CODE);
59 final String propertyPath = "." + TemPropertyConstants.TravelPaymentProperties.SPECIAL_HANDLING_STATE_CODE;
60 errors.putError(propertyPath, KFSKeyConstants.ERROR_EXISTENCE, label);
61 isValid = false;
62 }
63 }
64
65 errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT+"."+TemPropertyConstants.TRAVEL_PAYMENT);
66
67 return isValid;
68 }
69
70
71
72
73 public TravelPayment getTravelPaymentForValidation() {
74 return travelPaymentForValidation;
75 }
76
77
78
79
80
81 public void setTravelPaymentForValidation(TravelPayment travelPaymentForValidation) {
82 this.travelPaymentForValidation = travelPaymentForValidation;
83 }
84
85
86
87
88 public StateService getStateService() {
89 return stateService;
90 }
91
92
93
94
95
96 public void setStateService(StateService stateService) {
97 this.stateService = stateService;
98 }
99
100
101
102
103 public DataDictionaryService getDataDictionaryService() {
104 return dataDictionaryService;
105 }
106
107
108
109
110
111 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
112 this.dataDictionaryService = dataDictionaryService;
113 }
114
115 }