View Javadoc
1   /*
2    * Copyright 2008 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.sys.document.validation.impl;
17  
18  import org.kuali.ole.sys.OLEKeyConstants;
19  import org.kuali.ole.sys.document.validation.GenericValidation;
20  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
21  import org.kuali.rice.kns.service.DataDictionaryService;
22  import org.kuali.rice.kns.service.DictionaryValidationService;
23  import org.kuali.rice.krad.bo.PersistableBusinessObject;
24  import org.kuali.rice.krad.util.GlobalVariables;
25  
26  /**
27   * Validation to check if a reference of a validation 
28   */
29  public class ReferenceExistsValidation extends GenericValidation {
30      private PersistableBusinessObject businessObjectToValidate;
31      private DictionaryValidationService dictionaryValidationService;
32      private DataDictionaryService dataDictionaryService;
33      private String referenceName;
34      private String responsibleProperty;
35  
36      /**
37       * 
38       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
39       */
40      public boolean validate(AttributedDocumentEvent event) {
41          boolean result = true;
42          if (dictionaryValidationService.validateReferenceExists(businessObjectToValidate, referenceName)) {
43              GlobalVariables.getMessageMap().putError(responsibleProperty, OLEKeyConstants.ERROR_EXISTENCE, new String[] { dataDictionaryService.getAttributeLabel(businessObjectToValidate.getClass(), responsibleProperty) });
44              result = false;
45          }
46          return result;
47      }
48  
49      /**
50       * Gets the businessObjectToValidate attribute. 
51       * @return Returns the businessObjectToValidate.
52       */
53      public PersistableBusinessObject getBusinessObjectToValidate() {
54          return businessObjectToValidate;
55      }
56  
57      /**
58       * Sets the businessObjectToValidate attribute value.
59       * @param businessObjectToValidate The businessObjectToValidate to set.
60       */
61      public void setBusinessObjectToValidate(PersistableBusinessObject businessObjectToValidate) {
62          this.businessObjectToValidate = businessObjectToValidate;
63      }
64  
65      /**
66       * Gets the referenceName attribute. 
67       * @return Returns the referenceName.
68       */
69      public String getReferenceName() {
70          return referenceName;
71      }
72  
73      /**
74       * Sets the referenceName attribute value.
75       * @param referenceName The referenceName to set.
76       */
77      public void setReferenceName(String referenceName) {
78          this.referenceName = referenceName;
79      }
80  
81      /**
82       * Gets the responsibleProperty attribute. 
83       * @return Returns the responsibleProperty.
84       */
85      public String getResponsibleProperty() {
86          return responsibleProperty;
87      }
88  
89      /**
90       * Sets the responsibleProperty attribute value.
91       * @param responsibleProperty The responsibleProperty to set.
92       */
93      public void setResponsibleProperty(String responsibleProperty) {
94          this.responsibleProperty = responsibleProperty;
95      }
96  
97      /**
98       * Sets the dictionaryValidationService attribute value.
99       * @param dictionaryValidationService The dictionaryValidationService to set.
100      */
101     public void setDictionaryValidationService(DictionaryValidationService dictionaryValidationService) {
102         this.dictionaryValidationService = dictionaryValidationService;
103     }
104 
105     /**
106      * Sets the dataDictionaryService attribute value.
107      * @param dataDictionaryService The dataDictionaryService to set.
108      */
109     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
110         this.dataDictionaryService = dataDictionaryService;
111     }
112 }