001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.purap.rules;
017:
018: import org.kuali.core.document.MaintenanceDocument;
019: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
020: import org.kuali.core.service.BusinessObjectService;
021: import org.kuali.core.util.ErrorMap;
022: import org.kuali.core.util.GlobalVariables;
023: import org.kuali.core.util.ObjectUtils;
024: import org.kuali.kfs.KFSPropertyConstants;
025: import org.kuali.kfs.context.SpringContext;
026: import org.kuali.module.chart.bo.Chart;
027: import org.kuali.module.chart.bo.Org;
028: import org.kuali.module.chart.service.ChartService;
029: import org.kuali.module.chart.service.OrganizationService;
030: import org.kuali.module.purap.PurapKeyConstants;
031: import org.kuali.module.purap.bo.OrganizationParameter;
032:
033: /**
034: * Business rule(s) applicable to Organization Parameter maintenance document.
035: */
036: public class OrganizationParameterRule extends
037: MaintenanceDocumentRuleBase {
038:
039: private OrganizationParameter newOrganizationParameter;
040: private BusinessObjectService boService;
041:
042: /**
043: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
044: */
045: @Override
046: public void setupConvenienceObjects() {
047: // setup newDelegateChange convenience objects, make sure all possible sub-objects are populated
048: newOrganizationParameter = (OrganizationParameter) super
049: .getNewBo();
050: boService = (BusinessObjectService) super .getBoService();
051: super .setupConvenienceObjects();
052: }
053:
054: /**
055: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
056: */
057: protected boolean processCustomApproveDocumentBusinessRules(
058: MaintenanceDocument document) {
059: LOG.info("processCustomApproveDocumentBusinessRules called");
060: this .setupConvenienceObjects();
061: boolean success = true;
062: success &= this .checkChartOfAccountsCode();
063: success &= this .checkOrganizationCode();
064: return success
065: && super
066: .processCustomApproveDocumentBusinessRules(document);
067: }
068:
069: /**
070: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
071: */
072: protected boolean processCustomRouteDocumentBusinessRules(
073: MaintenanceDocument document) {
074: LOG.info("processCustomRouteDocumentBusinessRules called");
075: this .setupConvenienceObjects();
076: boolean success = true;
077: success &= this .checkChartOfAccountsCode();
078: success &= this .checkOrganizationCode();
079: return success
080: && super
081: .processCustomRouteDocumentBusinessRules(document);
082: }
083:
084: /**
085: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
086: */
087: protected boolean processCustomSaveDocumentBusinessRules(
088: MaintenanceDocument document) {
089: LOG.info("processCustomSaveDocumentBusinessRules called");
090: this .setupConvenienceObjects();
091: boolean success = true;
092: success &= this .checkChartOfAccountsCode();
093: success &= this .checkOrganizationCode();
094: return success
095: && super
096: .processCustomSaveDocumentBusinessRules(document);
097: }
098:
099: /**
100: * Validate chart of accounts code
101: *
102: * @return Boolean indicating if validation succeeded
103: */
104: protected boolean checkChartOfAccountsCode() {
105: LOG.info("checkChartOfAccountsCode called");
106: ErrorMap errorMap = GlobalVariables.getErrorMap();
107: boolean success = true;
108: Chart chart = SpringContext.getBean(ChartService.class)
109: .getByPrimaryId(
110: newOrganizationParameter
111: .getChartOfAccountsCode());
112: if (ObjectUtils.isNull(chart)) {
113: success &= false;
114: errorMap
115: .putError(
116: KFSPropertyConstants.DOCUMENT
117: + "."
118: + KFSPropertyConstants.NEW_MAINTAINABLE_OBJECT
119: + "."
120: + KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
121: PurapKeyConstants.ERROR_INVALID_CHART_OF_ACCOUNTS_CODE);
122: }
123: return success;
124: }
125:
126: /**
127: * Validate organization code
128: *
129: * @return Boolean indicating if validation succeeded
130: */
131: protected boolean checkOrganizationCode() {
132: LOG.info("checkOrganizationCode called");
133: ErrorMap errorMap = GlobalVariables.getErrorMap();
134: boolean success = true;
135: Org org = SpringContext.getBean(OrganizationService.class)
136: .getByPrimaryId(
137: newOrganizationParameter
138: .getChartOfAccountsCode(),
139: newOrganizationParameter.getOrganizationCode());
140: if (ObjectUtils.isNull(org)) {
141: success &= false;
142: errorMap.putError(KFSPropertyConstants.DOCUMENT + "."
143: + KFSPropertyConstants.NEW_MAINTAINABLE_OBJECT
144: + "." + KFSPropertyConstants.ORGANIZATION_CODE,
145: PurapKeyConstants.ERROR_INVALID_ORGANIZATION_CODE);
146: }
147: return success;
148: }
149:
150: }
|