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 java.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.ole.coa.businessobject.OrganizationReversion;
22 import org.kuali.ole.coa.businessobject.OrganizationReversionDetail;
23 import org.kuali.ole.coa.service.OrganizationReversionService;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.rice.kns.document.MaintenanceDocument;
26 import org.kuali.rice.krad.util.ObjectUtils;
27
28
29
30
31 public class OrganizationReversionPreRules extends MaintenancePreRulesBase {
32
33 private transient OrganizationReversionService organizationReversionService;
34 public OrganizationReversionPreRules() {
35
36 }
37
38
39
40
41
42 @Override
43 protected boolean doCustomPreRules(MaintenanceDocument document) {
44
45 OrganizationReversion orgRev = (OrganizationReversion) document.getNewMaintainableObject().getBusinessObject();
46
47 copyKeyAttributesToDetail(orgRev);
48 copyDefaultObjectcodeIfNoCarryForwardByObjectCode(orgRev);
49 return true;
50 }
51
52
53
54
55
56
57
58
59 protected void copyKeyAttributesToDetail(OrganizationReversion orgRev) {
60 if (orgRev.getUniversityFiscalYear() != null && orgRev.getUniversityFiscalYear().intValue() != 0 && StringUtils.isNotBlank(orgRev.getChartOfAccountsCode())) {
61
62 for (OrganizationReversionDetail dtl : orgRev.getOrganizationReversionDetail()) {
63 dtl.setChartOfAccountsCode(orgRev.getChartOfAccountsCode());
64 dtl.setUniversityFiscalYear(orgRev.getUniversityFiscalYear());
65
66 if (StringUtils.isNotBlank(dtl.getOrganizationReversionObjectCode())) {
67 dtl.refreshReferenceObject("organizationReversionObject");
68 }
69 }
70 }
71
72 }
73
74
75
76
77
78
79
80 protected void copyDefaultObjectcodeIfNoCarryForwardByObjectCode(OrganizationReversion orgRev) {
81 if (orgRev.isCarryForwardByObjectCodeIndicator() == true) return;
82
83 if (organizationReversionService == null) {
84 organizationReversionService = SpringContext.getBean(OrganizationReversionService.class);
85 }
86 String objectCode = organizationReversionService.getOrganizationReversionDetaiFromSystemParameters();
87
88 List<OrganizationReversionDetail> details = orgRev.getOrganizationReversionDetail();
89 for (OrganizationReversionDetail dtl : details) {
90 if (ObjectUtils.isNull(dtl.getOrganizationReversionObjectCode())) {
91 dtl.setOrganizationReversionObjectCode(objectCode);
92 }
93 }
94 }
95 }