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.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.module.purap.PurapKeyConstants;
19  import org.kuali.ole.module.purap.PurapPropertyConstants;
20  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
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.krad.util.GlobalVariables;
25  
26  public class PurchasingUpdateAccountingLineValidation extends GenericValidation {
27  
28      private AccountingLine updatedAccountingLine;
29  
30      public boolean validate(AttributedDocumentEvent event) {
31          //this is necessary because sometimes this method is called for baseline accounts, should not be needed once baseline is removed
32          if (updatedAccountingLine instanceof PurApAccountingLine) {
33              return verifyAccountingLinePercent((PurApAccountingLine) updatedAccountingLine);
34          }//else
35          return true;
36      }
37  
38      /**
39       * Verifies that the accounting line percent is a whole number.
40       *
41       * @param purapAccountingLine the accounting line to be validated
42       * @return boolean false if the accounting line percent is not a whole number.
43       */
44      protected boolean verifyAccountingLinePercent(PurApAccountingLine purapAccountingLine) {
45          // make sure it's a whole number
46          if (purapAccountingLine.getAccountLinePercent().stripTrailingZeros().scale() > 0) {
47              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ACCOUNTS, PurapKeyConstants.ERROR_PURCHASING_PERCENT_NOT_WHOLE, purapAccountingLine.getAccountLinePercent().toPlainString());
48  
49              return false;
50          }
51  
52          return true;
53      }
54  
55      public AccountingLine getUpdatedAccountingLine() {
56          return updatedAccountingLine;
57      }
58  
59      public void setUpdatedAccountingLine(AccountingLine updatedAccountingLine) {
60          this.updatedAccountingLine = updatedAccountingLine;
61      }
62  
63  }