01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.module.chart.rules;
17:
18: import org.apache.commons.lang.StringUtils;
19: import org.kuali.core.document.MaintenanceDocument;
20: import org.kuali.module.chart.bo.OrganizationReversion;
21: import org.kuali.module.chart.bo.OrganizationReversionDetail;
22:
23: /**
24: * PreRules checks for the {@link OrganizationReversion} that needs to occur while still in the Struts processing. This includes defaults
25: */
26: public class OrganizationReversionPreRules extends
27: MaintenancePreRulesBase {
28:
29: public OrganizationReversionPreRules() {
30:
31: }
32:
33: /**
34: * This calls the {@link OrganizationReversionPreRules#copyKeyAttributesToDetail(OrganizationReversion)}
35: * @see org.kuali.module.chart.rules.MaintenancePreRulesBase#doCustomPreRules(org.kuali.core.document.MaintenanceDocument)
36: */
37: @Override
38: protected boolean doCustomPreRules(MaintenanceDocument document) {
39:
40: OrganizationReversion orgRev = (OrganizationReversion) document
41: .getNewMaintainableObject().getBusinessObject();
42: // copy year and chart to detail records
43: copyKeyAttributesToDetail(orgRev);
44:
45: return true;
46: }
47:
48: /**
49: *
50: * This copies the chart of accounts, and the fiscal year from the parent {@link OrganizationReversion} to the
51: * {@link OrganizationReversionDetail} objects and refreshes the reference object on them if the values have
52: * been filled out
53: * @param orgRev
54: */
55: protected void copyKeyAttributesToDetail(
56: OrganizationReversion orgRev) {
57: if (orgRev.getUniversityFiscalYear() != null
58: && orgRev.getUniversityFiscalYear().intValue() != 0
59: && StringUtils.isNotBlank(orgRev
60: .getChartOfAccountsCode())) {
61: // loop over detail records, copying their details
62: for (OrganizationReversionDetail dtl : orgRev
63: .getOrganizationReversionDetail()) {
64: dtl.setChartOfAccountsCode(orgRev
65: .getChartOfAccountsCode());
66: dtl.setUniversityFiscalYear(orgRev
67: .getUniversityFiscalYear());
68: // load the object, if possible
69: if (StringUtils.isNotBlank(dtl
70: .getOrganizationReversionObjectCode())) {
71: dtl
72: .refreshReferenceObject("organizationReversionObject");
73: }
74: }
75: }
76:
77: }
78:
79: }
|