1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.fp.document.validation.impl;
17  
18  import java.util.List;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.ole.fp.document.DisbursementVoucherConstants;
22  import org.kuali.ole.fp.document.DisbursementVoucherDocument;
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.sys.OLEKeyConstants;
25  import org.kuali.ole.sys.OLEPropertyConstants;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.ole.sys.document.AccountingDocument;
28  import org.kuali.ole.sys.document.validation.GenericValidation;
29  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
30  import org.kuali.rice.kns.service.DictionaryValidationService;
31  import org.kuali.rice.krad.bo.Note;
32  import org.kuali.rice.krad.service.NoteService;
33  import org.kuali.rice.krad.util.GlobalVariables;
34  import org.kuali.rice.krad.util.MessageMap;
35  
36  public class DisbursementVoucherDocumentFieldValidation extends GenericValidation {
37      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherDocumentFieldValidation.class);
38  
39      private AccountingDocument accountingDocumentForValidation;
40  
41      
42  
43  
44      public boolean validate(AttributedDocumentEvent event) {
45          LOG.debug("validate start");
46          boolean isValid = true;
47  
48          DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
49  
50          MessageMap errors = GlobalVariables.getMessageMap();
51  
52          
53          SpringContext.getBean(DictionaryValidationService.class).validateDocument(document);
54  
55          
56          errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
57          errors.addToErrorPath(OLEPropertyConstants.DV_PAYEE_DETAIL);
58          SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(document.getDvPayeeDetail());
59          errors.removeFromErrorPath(OLEPropertyConstants.DV_PAYEE_DETAIL);
60          errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
61  
62          
63          if (errors.hasErrors()) {
64              return false;
65          }
66  
67          
68          if (document.isDisbVchrSpecialHandlingCode()) {
69              if (StringUtils.isBlank(document.getDvPayeeDetail().getDisbVchrSpecialHandlingPersonName()) || StringUtils.isBlank(document.getDvPayeeDetail().getDisbVchrSpecialHandlingLine1Addr())) {
70                  errors.putErrorWithoutFullErrorPath(OLEConstants.GENERAL_SPECHAND_TAB_ERRORS, OLEKeyConstants.ERROR_DV_SPECIAL_HANDLING);
71                  isValid = false;
72              }
73          }
74  
75          boolean hasNoNotes = this.hasNoNotes(document);
76  
77          
78          if (DisbursementVoucherConstants.NO_DOCUMENTATION_LOCATION.equals(document.getDisbursementVoucherDocumentationLocationCode()) && hasNoNotes) {
79              errors.putError(OLEPropertyConstants.DISBURSEMENT_VOUCHER_DOCUMENTATION_LOCATION_CODE, OLEKeyConstants.ERROR_DV_NO_DOCUMENTATION_NOTE_MISSING);
80              isValid = false;
81          }
82  
83          
84          if (document.isDisbVchrSpecialHandlingCode() && hasNoNotes) {
85              errors.putErrorWithoutFullErrorPath(OLEConstants.GENERAL_PAYMENT_TAB_ERRORS, OLEKeyConstants.ERROR_DV_SPECIAL_HANDLING_NOTE_MISSING);
86              isValid = false;
87          }
88  
89          
90          if (document.isExceptionIndicator() && hasNoNotes) {
91              errors.putErrorWithoutFullErrorPath(OLEConstants.GENERAL_PAYMENT_TAB_ERRORS, OLEKeyConstants.ERROR_DV_EXCEPTION_ATTACHED_NOTE_MISSING);
92              isValid = false;
93          }
94  
95          return isValid;
96      }
97  
98      
99  
100 
101 
102 
103 
104     protected boolean hasNoNotes(DisbursementVoucherDocument document) {
105         List<Note> notes = document.getNotes();
106 
107         return (notes == null || notes.isEmpty());
108     }
109 
110     
111 
112 
113 
114 
115     public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
116         this.accountingDocumentForValidation = accountingDocumentForValidation;
117     }
118 
119     
120 
121 
122 
123 
124     public AccountingDocument getAccountingDocumentForValidation() {
125         return accountingDocumentForValidation;
126     }
127 }