001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.sys.document.validation.impl;
017
018 import org.kuali.kfs.sys.KFSKeyConstants;
019 import org.kuali.kfs.sys.document.validation.GenericValidation;
020 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
021 import org.kuali.rice.kns.bo.PersistableBusinessObject;
022 import org.kuali.rice.kns.service.DataDictionaryService;
023 import org.kuali.rice.kns.service.DictionaryValidationService;
024 import org.kuali.rice.kns.util.GlobalVariables;
025
026 /**
027 * Validation to check if a reference of a validation
028 */
029 public class ReferenceExistsValidation extends GenericValidation {
030 private PersistableBusinessObject businessObjectToValidate;
031 private DictionaryValidationService dictionaryValidationService;
032 private DataDictionaryService dataDictionaryService;
033 private String referenceName;
034 private String responsibleProperty;
035
036 /**
037 *
038 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
039 */
040 public boolean validate(AttributedDocumentEvent event) {
041 boolean result = true;
042 if (dictionaryValidationService.validateReferenceExists(businessObjectToValidate, referenceName)) {
043 GlobalVariables.getMessageMap().putError(responsibleProperty, KFSKeyConstants.ERROR_EXISTENCE, new String[] { dataDictionaryService.getAttributeLabel(businessObjectToValidate.getClass(), responsibleProperty) });
044 result = false;
045 }
046 return result;
047 }
048
049 /**
050 * Gets the businessObjectToValidate attribute.
051 * @return Returns the businessObjectToValidate.
052 */
053 public PersistableBusinessObject getBusinessObjectToValidate() {
054 return businessObjectToValidate;
055 }
056
057 /**
058 * Sets the businessObjectToValidate attribute value.
059 * @param businessObjectToValidate The businessObjectToValidate to set.
060 */
061 public void setBusinessObjectToValidate(PersistableBusinessObject businessObjectToValidate) {
062 this.businessObjectToValidate = businessObjectToValidate;
063 }
064
065 /**
066 * Gets the referenceName attribute.
067 * @return Returns the referenceName.
068 */
069 public String getReferenceName() {
070 return referenceName;
071 }
072
073 /**
074 * Sets the referenceName attribute value.
075 * @param referenceName The referenceName to set.
076 */
077 public void setReferenceName(String referenceName) {
078 this.referenceName = referenceName;
079 }
080
081 /**
082 * Gets the responsibleProperty attribute.
083 * @return Returns the responsibleProperty.
084 */
085 public String getResponsibleProperty() {
086 return responsibleProperty;
087 }
088
089 /**
090 * Sets the responsibleProperty attribute value.
091 * @param responsibleProperty The responsibleProperty to set.
092 */
093 public void setResponsibleProperty(String responsibleProperty) {
094 this.responsibleProperty = responsibleProperty;
095 }
096
097 /**
098 * Sets the dictionaryValidationService attribute value.
099 * @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 }