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.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
19  import org.kuali.ole.module.purap.businessobject.PurApItem;
20  import org.kuali.ole.sys.document.validation.GenericValidation;
21  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
22  import org.kuali.rice.krad.util.ObjectUtils;
23  
24  public class PurchasingAccountsPayableProcessAccountValidation extends GenericValidation {
25  
26      private PurchasingAccountsPayableHasAccountsValidation hasAccountsValidation;
27      private PurchasingAccountsPayableAccountPercentValidation accountPercentValidation;
28      private PurchasingAccountsPayableUniqueAccountingStringsValidation accountingStringsValidation;
29      private PurApItem itemForValidation;
30      private PurchasingAccountsPayableAccountAtleastOneLineHasPercentValidation accountHasAtleastOnePercentValidation;
31      private PurchasingAccountingLineAmountValidation accountLineAmountValidation;
32      private PurchasingAccountsPayableAccountTotalValidation accountTotalValidation;
33  
34      @Override
35      public boolean validate(AttributedDocumentEvent event) {
36          boolean valid = true;
37  
38          if (ObjectUtils.isNull(itemForValidation)) {
39              return valid;
40          }
41  
42          hasAccountsValidation.setItemForValidation(itemForValidation);
43          valid &= hasAccountsValidation.validate(event);
44  
45          if (valid) {
46              getAccountHasAtlestOnePercentValidation().setItemForValidation(itemForValidation);
47              valid &= getAccountHasAtlestOnePercentValidation().validate(event);
48          }
49  
50          if (valid) {
51              for (PurApAccountingLine account : itemForValidation.getSourceAccountingLines()) {
52                  getAccountLineAmountValidation().setUpdatedAccountingLine(account);
53                  valid &= getAccountLineAmountValidation().validate(event);
54                  if (!valid) {
55                      break;
56                  }
57              }
58          }
59  
60          if (valid) {
61              accountPercentValidation.setItemForValidation(itemForValidation);
62              valid &= accountPercentValidation.validate(event);
63          }
64  
65          if (valid) {
66              accountTotalValidation.setItemForValidation(itemForValidation);
67              valid &= accountTotalValidation.validate(event);
68          }
69  
70          if (valid) {
71              accountingStringsValidation.setItemForValidation(itemForValidation);
72              valid &= accountingStringsValidation.validate(event);
73          }
74  
75          return valid;
76      }
77  
78      public PurchasingAccountsPayableHasAccountsValidation getHasAccountsValidation() {
79          return hasAccountsValidation;
80      }
81  
82      public void setHasAccountsValidation(PurchasingAccountsPayableHasAccountsValidation hasAccountsValidation) {
83          this.hasAccountsValidation = hasAccountsValidation;
84      }
85  
86      public PurchasingAccountsPayableAccountPercentValidation getAccountPercentValidation() {
87          return accountPercentValidation;
88      }
89  
90      public void setAccountPercentValidation(PurchasingAccountsPayableAccountPercentValidation accountPercentValidation) {
91          this.accountPercentValidation = accountPercentValidation;
92      }
93  
94      public PurchasingAccountsPayableUniqueAccountingStringsValidation getAccountingStringsValidation() {
95          return accountingStringsValidation;
96      }
97  
98      public void setAccountingStringsValidation(PurchasingAccountsPayableUniqueAccountingStringsValidation accountingStringsValidation) {
99          this.accountingStringsValidation = accountingStringsValidation;
100     }
101 
102     public PurApItem getItemForValidation() {
103         return itemForValidation;
104     }
105 
106     public void setItemForValidation(PurApItem itemForValidation) {
107         this.itemForValidation = itemForValidation;
108     }
109 
110     /**
111      * @return Returns the accountHasAtleastOnePercentValidation
112      */
113 
114     public PurchasingAccountsPayableAccountAtleastOneLineHasPercentValidation getAccountHasAtlestOnePercentValidation() {
115         return accountHasAtleastOnePercentValidation;
116     }
117 
118     /**
119      * Sets the accountHasAtleastOnePercentValidation attribute.
120      *
121      * @param accountHasAtleastOnePercentValidation
122      *         The accountHasAtleastOnePercentValidation to set.
123      */
124     public void setAccountHasAtleastOnePercentValidation(PurchasingAccountsPayableAccountAtleastOneLineHasPercentValidation accountHasAtleastOnePercentValidation) {
125         this.accountHasAtleastOnePercentValidation = accountHasAtleastOnePercentValidation;
126     }
127 
128     /**
129      * Gets the accountLineAmountValidation attribute.
130      *
131      * @return Returns the accountLineAmountValidation
132      */
133 
134     public PurchasingAccountingLineAmountValidation getAccountLineAmountValidation() {
135         return accountLineAmountValidation;
136     }
137 
138     /**
139      * Sets the accountLineAmountValidation attribute.
140      *
141      * @param accountLineAmountValidation The accountLineAmountValidation to set.
142      */
143     public void setAccountLineAmountValidation(PurchasingAccountingLineAmountValidation accountLineAmountValidation) {
144         this.accountLineAmountValidation = accountLineAmountValidation;
145     }
146 
147     /**
148      * Gets the accountTotalValidation attribute.
149      *
150      * @return Returns the accountTotalValidation
151      */
152 
153     public PurchasingAccountsPayableAccountTotalValidation getAccountTotalValidation() {
154         return accountTotalValidation;
155     }
156 
157     /**
158      * Sets the accountTotalValidation attribute.
159      *
160      * @param accountTotalValidation The accountTotalValidation to set.
161      */
162     public void setAccountTotalValidation(PurchasingAccountsPayableAccountTotalValidation accountTotalValidation) {
163         this.accountTotalValidation = accountTotalValidation;
164     }
165 }