View Javadoc
1   /*
2    * Copyright 2010 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.Organization;
19  import org.kuali.ole.coa.service.ChartService;
20  import org.kuali.ole.coa.service.OrganizationService;
21  import org.kuali.ole.module.purap.PurapKeyConstants;
22  import org.kuali.ole.module.purap.document.PurchasingDocumentBase;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  public class PurchasingChartOrgValidation extends GenericValidation {
28      private OrganizationService organizationService;
29      private ChartService chartService;
30  
31      /**
32       * Validate the chart and organization code prior to submitting the document.
33       * This has to be validated to protect against a person with an invalid
34       * primary department code.
35       *
36       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
37       */
38      public boolean validate(AttributedDocumentEvent event) {
39  
40          //GlobalVariables.getMessageMap().addToErrorPath("document");
41  
42          // Initialize the valid flag to true (we assume everything will be ok).
43          boolean valid = true;
44  
45          // Get the document.
46          PurchasingDocumentBase purapDoc = (PurchasingDocumentBase) event.getDocument();
47  
48          // Get the chart of accounts and organization code from the document.
49          String chartOfAccountsCode = purapDoc.getChartOfAccountsCode();
50          String organizationCode = purapDoc.getOrganizationCode();
51  
52          // Get organization business object from DB.  If a valid object is
53          // returned, we know that the COA and Org codes are valid; otherwise,
54          // display and error message to the user.
55          Organization organization = organizationService.getByPrimaryId(
56                  chartOfAccountsCode,
57                  organizationCode);
58  
59          if (organization == null) {
60              GlobalVariables.getMessageMap().putError(
61                      "document.documentHeader.*",
62                      PurapKeyConstants.ERROR_INVALID_COA_ORG_CODE);
63  
64              valid = false;
65          }
66  
67          return valid;
68      }
69  
70      /**
71       * Sets the organizationService attribute value.
72       *
73       * @param organizationService The organizationService to set.
74       */
75      public void setOrganizationService(OrganizationService organizationService) {
76          this.organizationService = organizationService;
77      }
78  
79      /**
80       * Sets the chartService attribute value.
81       *
82       * @param chartService The chartService to set.
83       */
84      public void setChartService(ChartService chartService) {
85          this.chartService = chartService;
86      }
87  
88  }