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.kuali.core.bo.user.UniversalUser;
19: import org.kuali.core.document.MaintenanceDocument;
20: import org.kuali.core.exceptions.UserNotFoundException;
21: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
22: import org.kuali.kfs.KFSKeyConstants;
23: import org.kuali.kfs.context.SpringContext;
24: import org.kuali.module.chart.bo.Chart;
25: import org.kuali.module.chart.bo.ChartUser;
26: import org.kuali.module.chart.service.ChartService;
27:
28: /**
29: * Business rule(s) applicable to {@link ChartMaintenance} documents.
30: */
31: public class ChartRule extends MaintenanceDocumentRuleBase {
32:
33: /**
34: * This method calls specific rules for routing on Chart Maintenance documents Specifically it checks to make sure that
35: * reportsToChart exists if it is not the same code as the newly created Chart and it checks to make sure that the chart manager
36: * is valid for the Chart Module
37: *
38: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
39: * @return false if reports to chart code doesn't exist or user is invalid for this module
40: */
41: protected boolean processCustomRouteDocumentBusinessRules(
42: MaintenanceDocument document) {
43:
44: boolean result = true;
45:
46: Chart chart = (Chart) document.getNewMaintainableObject()
47: .getBusinessObject();
48: ChartService chartService = SpringContext
49: .getBean(ChartService.class);
50:
51: String chartCode = chart.getChartOfAccountsCode();
52:
53: String reportsToChartCode = chart
54: .getReportsToChartOfAccountsCode();
55:
56: if (chartCode != null && !chartCode.equals(reportsToChartCode)) { // if not equal to this newly created chart, then must
57: // exist
58: Chart reportsToChart = chartService
59: .getByPrimaryId(reportsToChartCode);
60: if (reportsToChart == null) {
61: result = false;
62: putFieldError(
63: "reportsToChartOfAccountsCode",
64: KFSKeyConstants.ERROR_DOCUMENT_CHART_REPORTS_TO_CHART_MUST_EXIST);
65: }
66: }
67:
68: UniversalUser chartManager = null;
69: try {
70: chartManager = getUniversalUserService().getUniversalUser(
71: chart.getFinCoaManagerUniversalId());
72: } catch (UserNotFoundException e) {
73: result = false;
74: putFieldError(
75: "finCoaManagerUniversal.personUserIdentifier",
76: KFSKeyConstants.ERROR_DOCUMENT_CHART_MANAGER_MUST_EXIST);
77: }
78:
79: if (chartManager != null
80: && !chartManager.isActiveForModule(ChartUser.MODULE_ID)) {
81: result = false;
82: putFieldError(
83: "finCoaManagerUniversal.personUserIdentifier",
84: KFSKeyConstants.ERROR_DOCUMENT_CHART_MANAGER_MUST_BE_KUALI_USER);
85: }
86:
87: return result;
88:
89: }
90:
91: }
|