View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
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.ole.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.coa.businessobject.Chart;
19  import org.kuali.ole.coa.businessobject.Organization;
20  import org.kuali.ole.coa.service.ChartService;
21  import org.kuali.ole.coa.service.OrganizationService;
22  import org.kuali.ole.module.purap.PurapKeyConstants;
23  import org.kuali.ole.module.purap.businessobject.OrganizationParameter;
24  import org.kuali.ole.sys.OLEPropertyConstants;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.rice.kns.document.MaintenanceDocument;
27  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
28  import org.kuali.rice.krad.service.BusinessObjectService;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  import org.kuali.rice.krad.util.MessageMap;
31  import org.kuali.rice.krad.util.ObjectUtils;
32  
33  /**
34   * Business rule(s) applicable to Organization Parameter maintenance document.
35   */
36  public class OrganizationParameterRule extends MaintenanceDocumentRuleBase {
37  
38      protected OrganizationParameter newOrganizationParameter;
39      protected BusinessObjectService boService;
40  
41      /**
42       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
43       */
44      @Override
45      public void setupConvenienceObjects() {
46          // setup newDelegateChange convenience objects, make sure all possible sub-objects are populated
47          newOrganizationParameter = (OrganizationParameter) super.getNewBo();
48          boService = (BusinessObjectService) super.getBoService();
49          super.setupConvenienceObjects();
50      }
51  
52      /**
53       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
54       */
55      protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
56          LOG.info("processCustomApproveDocumentBusinessRules called");
57          this.setupConvenienceObjects();
58          boolean success = true;
59          success &= this.checkChartOfAccountsCode();
60          success &= this.checkOrganizationCode();
61          return success && super.processCustomApproveDocumentBusinessRules(document);
62      }
63  
64      /**
65       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
66       */
67      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
68          LOG.info("processCustomRouteDocumentBusinessRules called");
69          this.setupConvenienceObjects();
70          boolean success = true;
71          success &= this.checkChartOfAccountsCode();
72          success &= this.checkOrganizationCode();
73          return success && super.processCustomRouteDocumentBusinessRules(document);
74      }
75  
76      /**
77       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
78       */
79      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
80          LOG.info("processCustomSaveDocumentBusinessRules called");
81          this.setupConvenienceObjects();
82          boolean success = true;
83          success &= this.checkChartOfAccountsCode();
84          success &= this.checkOrganizationCode();
85          return success && super.processCustomSaveDocumentBusinessRules(document);
86      }
87  
88      /**
89       * Validate chart of accounts code
90       *
91       * @return Boolean indicating if validation succeeded
92       */
93      protected boolean checkChartOfAccountsCode() {
94          LOG.info("checkChartOfAccountsCode called");
95          MessageMap errorMap = GlobalVariables.getMessageMap();
96          boolean success = true;
97          Chart chart = SpringContext.getBean(ChartService.class).getByPrimaryId(newOrganizationParameter.getChartOfAccountsCode());
98          if (ObjectUtils.isNull(chart)) {
99              success &= false;
100             errorMap.putError(OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.NEW_MAINTAINABLE_OBJECT + "." + OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, PurapKeyConstants.ERROR_INVALID_CHART_OF_ACCOUNTS_CODE);
101         }
102         return success;
103     }
104 
105     /**
106      * Validate organization code
107      *
108      * @return Boolean indicating if validation succeeded
109      */
110     protected boolean checkOrganizationCode() {
111         LOG.info("checkOrganizationCode called");
112         MessageMap errorMap = GlobalVariables.getMessageMap();
113         boolean success = true;
114         Organization org = SpringContext.getBean(OrganizationService.class).getByPrimaryId(newOrganizationParameter.getChartOfAccountsCode(), newOrganizationParameter.getOrganizationCode());
115         if (ObjectUtils.isNull(org)) {
116             success &= false;
117             errorMap.putError(OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.NEW_MAINTAINABLE_OBJECT + "." + OLEPropertyConstants.ORGANIZATION_CODE, PurapKeyConstants.ERROR_INVALID_ORGANIZATION_CODE);
118         }
119         return success;
120     }
121 
122 }