1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.module.purap.document.validation.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapKeyConstants;
20  import org.kuali.ole.module.purap.PurapPropertyConstants;
21  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
22  import org.kuali.ole.sys.OLEKeyConstants;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AddAccountingLineEvent;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.rice.kns.service.DataDictionaryService;
27  import org.kuali.rice.krad.bo.BusinessObject;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  import org.kuali.rice.krad.util.ObjectUtils;
30  
31  public class VendorCreditMemoAccountPercentBetween0And100Validation extends GenericValidation {
32  
33      private DataDictionaryService dataDictionaryService;
34  
35      public boolean validate(AttributedDocumentEvent event) {
36          boolean isValid = true;
37          PurApAccountingLine account = (PurApAccountingLine) ((AddAccountingLineEvent) event).getAccountingLine();
38  
39          if (validateRequiredField(account, PurapPropertyConstants.ACCOUNT_LINE_PERCENT)) {
40              double pct = account.getAccountLinePercent().doubleValue();
41              if (pct <= 0 || pct > 100) {
42                  GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ACCOUNT_LINE_PERCENT, PurapKeyConstants.ERROR_CREDIT_MEMO_LINE_PERCENT);
43                  isValid = false;
44              }
45          } else {
46              isValid = false;
47          }
48  
49          return isValid;
50      }
51  
52      
53  
54  
55  
56  
57  
58  
59  
60      protected boolean validateRequiredField(BusinessObject businessObject, String fieldName) {
61          boolean valid = true;
62  
63          Object fieldValue = ObjectUtils.getPropertyValue(businessObject, fieldName);
64          if (fieldValue == null || (fieldValue instanceof String && StringUtils.isBlank(fieldName))) {
65              String label = dataDictionaryService.getAttributeErrorLabel(businessObject.getClass(), fieldName);
66              GlobalVariables.getMessageMap().putError(fieldName, OLEKeyConstants.ERROR_REQUIRED, label);
67              valid = false;
68          }
69  
70          return valid;
71      }
72  
73      public DataDictionaryService getDataDictionaryService() {
74          return dataDictionaryService;
75      }
76  
77      public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
78          this.dataDictionaryService = dataDictionaryService;
79      }
80  
81  }