View Javadoc
1   /*
2    * Copyright 2008-2009 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.fp.document.validation.impl;
17  
18  import static org.kuali.ole.sys.OLEPropertyConstants.REFERENCE_NUMBER;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.ole.fp.document.NonCheckDisbursementDocument;
22  import org.kuali.ole.sys.OLEKeyConstants;
23  import org.kuali.ole.sys.businessobject.AccountingLine;
24  import org.kuali.ole.sys.document.validation.GenericValidation;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.rice.kns.service.DataDictionaryService;
27  import org.kuali.rice.krad.datadictionary.BusinessObjectEntry;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  
30  /**
31   * Validates that an accounting line has a reference number 
32   */
33  public class NonCheckDisbursementRequiredReferenceFieldValidation extends GenericValidation {
34      private DataDictionaryService dataDictionaryService;
35      private AccountingLine accountingLineForValidation;
36  
37      /**
38       * determines if a reference number has been added to the Accounting Line
39       * <strong>Expects an accounting line as the first a parameter</strong>
40       * @see org.kuali.ole.sys.document.validation.Validation#validate(java.lang.Object[])
41       */
42      
43      
44      public boolean validate(AttributedDocumentEvent event) {
45          
46          NonCheckDisbursementDocument document = (NonCheckDisbursementDocument)event.getDocument();
47          
48          boolean valid = true;
49          Class alclass = null;
50          BusinessObjectEntry boe;
51  
52          if (accountingLineForValidation.isSourceAccountingLine()) {
53              alclass = document.getSourceAccountingLineClass();
54          }
55          else if (accountingLineForValidation.isTargetAccountingLine()) {
56              alclass = document.getTargetAccountingLineClass();
57          }
58  
59          boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(alclass.getName());
60         
61          if (StringUtils.isEmpty(accountingLineForValidation.getReferenceNumber())) {
62              putRequiredPropertyError(boe, REFERENCE_NUMBER);
63              valid = false;
64          }
65          return valid;
66      }
67  
68      /**
69       * Adds a global error for a missing required property. This is used for properties, such as reference origin code, which cannot
70       * be required by the DataDictionary validation because not all documents require them.
71       * 
72       * @param boe
73       * @param propertyName
74       */
75      protected void putRequiredPropertyError(BusinessObjectEntry boe, String propertyName) {
76  
77          String label = boe.getAttributeDefinition(propertyName).getShortLabel();
78          GlobalVariables.getMessageMap().putError(propertyName, OLEKeyConstants.ERROR_REQUIRED, label);
79  
80      }
81  
82      /**
83       * Gets the accountingLineForValidation attribute. 
84       * @return Returns the accountingLineForValidation.
85       */
86      public AccountingLine getAccountingLineForValidation() {
87          return accountingLineForValidation;
88      }
89  
90      /**
91       * Sets the accountingLineForValidation attribute value.
92       * @param accountingLineForValidation The accountingLineForValidation to set.
93       */
94      public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
95          this.accountingLineForValidation = accountingLineForValidation;
96      }
97  
98      /**
99       * Gets the dataDictionaryService attribute. 
100      * @return Returns the dataDictionaryService.
101      */
102     public DataDictionaryService getDataDictionaryService() {
103         return dataDictionaryService;
104     }
105 
106     /**
107      * Sets the dataDictionaryService attribute value.
108      * @param dataDictionaryService The dataDictionaryService to set.
109      */
110     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
111         this.dataDictionaryService = dataDictionaryService;
112     }
113 }