1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.document.validation.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.coa.businessobject.Account;
20 import org.kuali.ole.coa.businessobject.Organization;
21 import org.kuali.ole.coa.businessobject.OrganizationExtension;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.rice.core.api.datetime.DateTimeService;
24 import org.kuali.rice.kns.document.MaintenanceDocument;
25 import org.kuali.rice.krad.util.ObjectUtils;
26 import org.kuali.rice.location.api.postalcode.PostalCode;
27 import org.kuali.rice.location.api.postalcode.PostalCodeService;
28
29
30
31
32
33 public class OrgPreRules extends MaintenancePreRulesBase {
34 protected Organization newOrg;
35 protected PostalCodeService postalZipCodeService = SpringContext.getBean(PostalCodeService.class);
36
37
38
39
40
41
42 @Override
43 protected boolean doCustomPreRules(MaintenanceDocument document) {
44 setupConvenienceObjects(document);
45 checkForContinuationAccounts();
46
47 LOG.debug("done with continuation account, proceeeding with remaining pre rules");
48
49
50
51
52
53 return true;
54 }
55
56
57
58
59 protected void checkForContinuationAccounts() {
60 LOG.debug("entering checkForContinuationAccounts()");
61
62 if (StringUtils.isNotBlank(newOrg.getOrganizationDefaultAccountNumber())) {
63 Account account = checkForContinuationAccount("Account Number", newOrg.getChartOfAccountsCode(), newOrg.getOrganizationDefaultAccountNumber(), "");
64 if (ObjectUtils.isNotNull(account)) {
65 newOrg.setOrganizationDefaultAccountNumber(account.getAccountNumber());
66 newOrg.setChartOfAccountsCode(account.getChartOfAccountsCode());
67 }
68 }
69 }
70
71
72
73
74
75
76
77
78 protected void setupConvenienceObjects(MaintenanceDocument document) {
79
80
81 newOrg = (Organization) document.getNewMaintainableObject().getBusinessObject();
82 }
83
84
85
86
87
88
89
90 protected void updateHRMSUpdateDate(Organization oldData, Organization newData) {
91 if (oldData != null) {
92 OrganizationExtension oldExt = oldData.getOrganizationExtension();
93 OrganizationExtension newExt = newData.getOrganizationExtension();
94 if (oldExt != null) {
95 if (!StringUtils.equals(oldExt.getHrmsCompany(), newExt.getHrmsCompany()) || !StringUtils.equals(oldExt.getHrmsIuOrganizationAddress2(), newExt.getHrmsIuOrganizationAddress2()) || !StringUtils.equals(oldExt.getHrmsIuOrganizationAddress3(), newExt.getHrmsIuOrganizationAddress3()) || !StringUtils.equals(oldExt.getHrmsIuCampusCode(), newExt.getHrmsIuCampusCode()) || !StringUtils.equals(oldExt.getHrmsIuCampusBuilding(), newExt.getHrmsIuCampusBuilding()) || !StringUtils.equals(oldExt.getHrmsIuCampusRoom(), newExt.getHrmsIuCampusRoom()) || oldExt.isHrmsIuPositionAllowedFlag() != newExt.isHrmsIuPositionAllowedFlag() || oldExt.isHrmsIuTenureAllowedFlag() != newExt.isHrmsIuTenureAllowedFlag() || oldExt.isHrmsIuTitleAllowedFlag() != newExt.isHrmsIuTitleAllowedFlag() || oldExt.isHrmsIuOccupationalUnitAllowedFlag() != newExt.isHrmsIuOccupationalUnitAllowedFlag()
96 || !StringUtils.equals(oldExt.getHrmsPersonnelApproverUniversalId(), newExt.getHrmsPersonnelApproverUniversalId()) || !StringUtils.equals(oldExt.getFiscalApproverUniversalId(), newExt.getFiscalApproverUniversalId())) {
97 newExt.setHrmsLastUpdateDate(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
98 }
99 }
100 else {
101 newExt.setHrmsLastUpdateDate(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
102 }
103 }
104 else {
105 newData.getOrganizationExtension().setHrmsLastUpdateDate(SpringContext.getBean(DateTimeService.class).getCurrentTimestamp());
106 }
107 }
108
109
110
111
112
113
114 protected void setLocationFromZip(MaintenanceDocument maintenanceDocument) {
115
116
117
118 if (StringUtils.isNotBlank(newOrg.getOrganizationZipCode()) && StringUtils.isNotBlank(newOrg.getOrganizationCountryCode())) {
119 PostalCode zip = postalZipCodeService.getPostalCode(newOrg.getOrganizationCountryCode(), newOrg.getOrganizationZipCode());
120
121
122 if (ObjectUtils.isNotNull(zip)) {
123 newOrg.setOrganizationCityName(zip.getCityName());
124 newOrg.setOrganizationStateCode(zip.getStateCode());
125 }
126 }
127 }
128
129
130 }