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.PurapConstants;
19  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
20  import org.kuali.ole.select.OleSelectConstant;
21  import org.kuali.ole.select.constants.OleSelectPropertyConstants;
22  import org.kuali.ole.sys.businessobject.AccountingLine;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  public class PurchasingAccountingLinePercentValidation extends GenericValidation {
28  
29      private AccountingLine updatedAccountingLine;
30  
31      @Override
32      public boolean validate(AttributedDocumentEvent event) {
33          boolean valid = true;
34          //   PurApAccountingLine purapAccountingLine = (PurApAccountingLine)updatedAccountingLine;
35  
36          // make sure it's a whole number
37          //  if (purapAccountingLine.getAccountLinePercent().stripTrailingZeros().scale() > 0) {
38          //      GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ACCOUNTS, PurapKeyConstants.ERROR_PURCHASING_PERCENT_NOT_WHOLE, purapAccountingLine.getAccountLinePercent().toPlainString());
39  //
40          //     valid &= false;
41          //  }
42  
43          return valid;
44      }
45  
46      public AccountingLine getUpdatedAccountingLine() {
47          return updatedAccountingLine;
48      }
49  
50      public void setUpdatedAccountingLine(AccountingLine updatedAccountingLine) {
51          this.updatedAccountingLine = updatedAccountingLine;
52      }
53      // added for jira OLE-2112.
54  
55      /**
56       * Method to validate accountingLinePercent field
57       *
58       * @return boolean.
59       */
60      public boolean validatePercent() {
61          boolean valid = true;
62          PurApAccountingLine purapAccountingLine = (PurApAccountingLine) updatedAccountingLine;
63          // accounting line percent should not be greater than 100.
64          if (purapAccountingLine.getAccountLinePercent().intValue() > OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED) {
65              GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ACCOUNTINGLINE_PERCENT_GT_HUNDRED);
66              valid = false;
67          }
68          return valid;
69  
70      }
71  
72  }