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 org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.sys.OLEKeyConstants;
20 import org.kuali.ole.sys.OLEPropertyConstants;
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.kns.service.DataDictionaryService;
25 import org.kuali.rice.krad.datadictionary.BusinessObjectEntry;
26 import org.kuali.rice.krad.util.GlobalVariables;
27
28 public class PreEncumbranceRequiredReferenceFieldValidation extends GenericValidation {
29 private DataDictionaryService dataDictionaryService;
30 private AccountingLine accountingLineForValidation;
31
32 public boolean validate(AttributedDocumentEvent event) {
33 boolean valid = true;
34 if (this.getAccountingLineForValidation().isTargetAccountingLine()) {
35 final BusinessObjectEntry boe = getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(getAccountingLineForValidation().getClass().getName());
36
37 if (StringUtils.isEmpty(getAccountingLineForValidation().getReferenceNumber())) {
38 putRequiredPropertyError(boe, OLEPropertyConstants.REFERENCE_NUMBER);
39 valid = false;
40 }
41 }
42 return valid;
43 }
44
45
46
47
48
49
50
51
52 protected void putRequiredPropertyError(BusinessObjectEntry boe, String propertyName) {
53 final String label = boe.getAttributeDefinition(propertyName).getShortLabel();
54 GlobalVariables.getMessageMap().putError(propertyName, OLEKeyConstants.ERROR_REQUIRED, label);
55 }
56
57
58
59
60
61 public DataDictionaryService getDataDictionaryService() {
62 return dataDictionaryService;
63 }
64
65
66
67
68
69 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
70 this.dataDictionaryService = dataDictionaryService;
71 }
72
73
74
75
76
77 public AccountingLine getAccountingLineForValidation() {
78 return accountingLineForValidation;
79 }
80
81
82
83
84
85 public void setAccountingLineForValidation(AccountingLine accoutingLineForValidation) {
86 this.accountingLineForValidation = accoutingLineForValidation;
87 }
88 }