1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.cg.document.validation.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.cg.businessobject.SubContractor;
20 import org.kuali.ole.sys.OLEKeyConstants;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.rice.kns.document.MaintenanceDocument;
23 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
24 import org.kuali.rice.location.api.country.Country;
25 import org.kuali.rice.location.api.country.CountryService;
26 import org.kuali.rice.location.api.state.State;
27 import org.kuali.rice.location.api.state.StateService;
28
29
30
31
32 public class SubcontractorRule extends MaintenanceDocumentRuleBase {
33
34 protected SubContractor newSubcontractor;
35
36
37
38
39
40
41
42
43 @Override
44 protected boolean validateMaintenanceDocument(MaintenanceDocument maintenanceDocument) {
45 boolean success = true;
46
47 success = super.validateMaintenanceDocument(maintenanceDocument);
48
49 newSubcontractor = (SubContractor) super.getNewBo();
50 success &= validateCountryCode(newSubcontractor.getSubcontractorCountryCode());
51 success &= validateStateCode(newSubcontractor.getSubcontractorCountryCode(), newSubcontractor.getSubcontractorStateCode());
52
53 return success;
54 }
55
56
57
58
59
60
61
62
63
64 protected boolean validateStateCode(String countryCode, String stateCode) {
65 boolean valid = true;
66
67
68 if ( StringUtils.isNotBlank(stateCode) && StringUtils.isNotBlank(countryCode) ) {
69 State state = SpringContext.getBean(StateService.class).getState(countryCode, stateCode);
70
71
72 if (state== null) {
73 putFieldError("subcontractorStateCode", OLEKeyConstants.ERROR_STATE_CODE_INVALID, stateCode);
74 valid = false;
75 }
76 }
77
78 return valid;
79 }
80
81
82
83
84
85
86
87
88 protected boolean validateCountryCode(String countryCode) {
89 boolean valid = true;
90
91 if ( StringUtils.isNotBlank(countryCode) ) {
92 Country country = SpringContext.getBean(CountryService.class).getCountry(countryCode);
93
94
95 if (country == null) {
96 putFieldError("subcontractorCountryCode", OLEKeyConstants.ERROR_COUNTRY_CODE_INVALID, countryCode);
97 valid = false;
98 }
99 }
100
101 return valid;
102 }
103
104 }