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