View Javadoc
1   /*
2    * Copyright 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 org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.sys.OLEKeyConstants;
20  import org.kuali.ole.sys.OLEPropertyConstants;
21  import org.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.ole.sys.document.validation.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.rice.kns.service.DataDictionaryService;
25  import org.kuali.rice.krad.datadictionary.BusinessObjectEntry;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  
28  public class PreEncumbranceRequiredReferenceFieldValidation extends GenericValidation {
29      private DataDictionaryService dataDictionaryService;
30      private AccountingLine accountingLineForValidation;
31  
32      public boolean validate(AttributedDocumentEvent event) {
33          boolean valid = true;
34          if (this.getAccountingLineForValidation().isTargetAccountingLine()) {
35              final BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(getAccountingLineForValidation().getClass().getName());
36              
37              if (StringUtils.isEmpty(getAccountingLineForValidation().getReferenceNumber())) {
38                  putRequiredPropertyError(boe, OLEPropertyConstants.REFERENCE_NUMBER);
39                  valid = false;
40              }
41          }
42          return valid;
43      }
44  
45      /**
46       * Adds a global error for a missing required property. This is used for properties, such as reference origin code, which cannot
47       * be required by the DataDictionary validation because not all documents require them.
48       * 
49       * @param boe
50       * @param propertyName
51       */
52      protected void putRequiredPropertyError(BusinessObjectEntry boe, String propertyName) {
53          final String label = boe.getAttributeDefinition(propertyName).getShortLabel();
54          GlobalVariables.getMessageMap().putError(propertyName, OLEKeyConstants.ERROR_REQUIRED, label);
55      }
56  
57      /**
58       * Gets the dataDictionaryService attribute. 
59       * @return Returns the dataDictionaryService.
60       */
61      public DataDictionaryService getDataDictionaryService() {
62          return dataDictionaryService;
63      }
64  
65      /**
66       * Sets the dataDictionaryService attribute value.
67       * @param dataDictionaryService The dataDictionaryService to set.
68       */
69      public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
70          this.dataDictionaryService = dataDictionaryService;
71      }
72  
73      /**
74       * Gets the accountingLineForValidation attribute. 
75       * @return Returns the accountingLineForValidation.
76       */
77      public AccountingLine getAccountingLineForValidation() {
78          return accountingLineForValidation;
79      }
80  
81      /**
82       * Sets the accountingLineForValidation attribute value.
83       * @param accountingLineForValidation The accountingLineForValidation to set.
84       */
85      public void setAccountingLineForValidation(AccountingLine accoutingLineForValidation) {
86          this.accountingLineForValidation = accoutingLineForValidation;
87      }
88  }