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.apache.commons.lang.StringUtils;
019 import org.kuali.kfs.sys.businessobject.AccountingLine;
020 import org.kuali.kfs.sys.document.AccountingDocument;
021 import org.kuali.kfs.sys.document.validation.Validation;
022 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
023 import org.kuali.rice.kns.util.ObjectUtils;
024
025 /**
026 *
027 */
028 public class AccountingLineCheckValidationHutch implements Validation {
029 protected Validation lineAmountValidation;
030 protected Validation lineCheckValidation;
031 protected Validation lineValuesAllowedValidation;
032
033 protected String accountingDocumentParameterPropertyName;
034 protected String accountingLineParameterPropertyName;
035
036 protected AccountingDocument accountingDocumentForValidation;
037 protected AccountingLine accountingLineForValidation;
038
039 protected boolean quitOnFail;
040
041 /**
042 * @see org.kuali.kfs.sys.document.validation.Validation#shouldQuitOnFail()
043 */
044 public boolean shouldQuitOnFail() {
045 return quitOnFail;
046 }
047
048 /**
049 * Sets whether the validation hutch should quit on the failure of the entire validation case failing.
050 * @param b
051 */
052 public void setShouldQuitOnFail(boolean b) {
053 quitOnFail = b;
054 }
055
056 /**
057 * @see org.kuali.kfs.sys.document.validation.Validation#stageValidation(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
058 */
059 public boolean stageValidation(AttributedDocumentEvent event) {
060 grabDocumentAndLineForValidationFromEvent(event);
061 updateValidationsWithParameters();
062 return validate(event);
063 }
064
065 /**
066 * Using the parameter property names set, finds the accounting document and accounting line to be validate
067 * from the property.
068 * @param event the event to take properties from
069 */
070 protected void grabDocumentAndLineForValidationFromEvent(AttributedDocumentEvent event) {
071 if (StringUtils.isNotBlank(accountingDocumentParameterPropertyName)) {
072 accountingDocumentForValidation = (AccountingDocument)ObjectUtils.getPropertyValue(event, accountingDocumentParameterPropertyName);
073 }
074 if (StringUtils.isNotBlank(accountingLineParameterPropertyName)) {
075 accountingLineForValidation = (AccountingLine)ObjectUtils.getPropertyValue(event, accountingLineParameterPropertyName);
076 }
077 }
078
079 /**
080 * Updates the child validations with accounting document and accounting line information.
081 */
082 protected void updateValidationsWithParameters() {
083
084 }
085
086 /**
087 *
088 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
089 */
090 public boolean validate(AttributedDocumentEvent event) {
091 // TODO Auto-generated method stub
092 return false;
093 }
094
095 /**
096 * Gets the lineAmountValidation attribute.
097 * @return Returns the lineAmountValidation.
098 */
099 public Validation getLineAmountValidation() {
100 return lineAmountValidation;
101 }
102
103 /**
104 * Sets the lineAmountValidation attribute value.
105 * @param lineAmountValidation The lineAmountValidation to set.
106 */
107 public void setLineAmountValidation(Validation lineAmountValidation) {
108 this.lineAmountValidation = lineAmountValidation;
109 }
110
111 /**
112 * Gets the lineCheckValidation attribute.
113 * @return Returns the lineCheckValidation.
114 */
115 public Validation getLineCheckValidation() {
116 return lineCheckValidation;
117 }
118
119 /**
120 * Sets the lineCheckValidation attribute value.
121 * @param lineCheckValidation The lineCheckValidation to set.
122 */
123 public void setLineCheckValidation(Validation lineCheckValidation) {
124 this.lineCheckValidation = lineCheckValidation;
125 }
126
127 /**
128 * Gets the lineValuesAllowedValidation attribute.
129 * @return Returns the lineValuesAllowedValidation.
130 */
131 public Validation getLineValuesAllowedValidation() {
132 return lineValuesAllowedValidation;
133 }
134
135 /**
136 * Sets the lineValuesAllowedValidation attribute value.
137 * @param lineValuesAllowedValidation The lineValuesAllowedValidation to set.
138 */
139 public void setLineValuesAllowedValidation(Validation lineValuesAllowedValidation) {
140 this.lineValuesAllowedValidation = lineValuesAllowedValidation;
141 }
142 }