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 static org.kuali.ole.sys.OLEPropertyConstants.ENCUMBRANCE_UPDATE_CODE;
19 import static org.kuali.ole.sys.OLEPropertyConstants.REFERENCE_NUMBER;
20 import static org.kuali.ole.sys.OLEPropertyConstants.REFERENCE_ORIGIN_CODE;
21 import static org.kuali.ole.sys.OLEPropertyConstants.REFERENCE_TYPE_CODE;
22
23 import java.util.List;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.ole.coa.businessobject.AccountingPeriod;
27 import org.kuali.ole.coa.service.BalanceTypeService;
28 import org.kuali.ole.fp.businessobject.VoucherSourceAccountingLine;
29 import org.kuali.ole.fp.document.JournalVoucherDocument;
30 import org.kuali.ole.sys.OLEConstants;
31 import org.kuali.ole.sys.OLEKeyConstants;
32 import org.kuali.ole.sys.OLEPropertyConstants;
33 import org.kuali.ole.sys.businessobject.AccountingLine;
34 import org.kuali.ole.sys.context.SpringContext;
35 import org.kuali.ole.sys.document.validation.GenericValidation;
36 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
37 import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
38 import org.kuali.rice.kns.service.DataDictionaryService;
39 import org.kuali.rice.krad.util.GlobalVariables;
40
41
42
43
44 public class JournalVoucherAccountingLineEncumbranceReferenceValidation extends GenericValidation {
45 private JournalVoucherDocument journalVoucherForValidation;
46 private AccountingLine accountingLineForValidation;
47
48 private DataDictionaryService dataDictionaryService;
49
50
51
52
53
54
55
56
57
58 public boolean validate(AttributedDocumentEvent event) {
59 boolean valid = true;
60 if (isEncumbranceBalanceType(getAccountingLineForValidation().getBalanceTypeCode())) {
61 if (StringUtils.isBlank(getAccountingLineForValidation().getEncumbranceUpdateCode())) {
62 BusinessObjectEntry boe = (BusinessObjectEntry) getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(VoucherSourceAccountingLine.class.getName());
63 putRequiredPropertyError(boe, ENCUMBRANCE_UPDATE_CODE);
64 valid = false;
65 } else if (OLEConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(getAccountingLineForValidation().getEncumbranceUpdateCode())){
66
67 if (StringUtils.isBlank(getAccountingLineForValidation().getReferenceOriginCode())) {
68 BusinessObjectEntry boe = (BusinessObjectEntry) getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(VoucherSourceAccountingLine.class.getName());
69 putRequiredPropertyError(boe, REFERENCE_ORIGIN_CODE);
70 valid = false;
71 }
72 if (StringUtils.isBlank(getAccountingLineForValidation().getReferenceNumber())) {
73 BusinessObjectEntry boe = (BusinessObjectEntry) getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(VoucherSourceAccountingLine.class.getName());
74 putRequiredPropertyError(boe, REFERENCE_NUMBER);
75 valid = false;
76 }
77 if (StringUtils.isBlank(getAccountingLineForValidation().getReferenceTypeCode())) {
78 BusinessObjectEntry boe = (BusinessObjectEntry) getDataDictionaryService().getDataDictionary().getBusinessObjectEntry(VoucherSourceAccountingLine.class.getName());
79 putRequiredPropertyError(boe, REFERENCE_TYPE_CODE);
80 valid = false;
81 }
82 }
83 }
84 return valid;
85 }
86
87
88
89
90
91
92
93 private boolean isEncumbranceBalanceType(String balanceTypeCode){
94 getJournalVoucherForValidation().refreshReferenceObject(OLEPropertyConstants.ACCOUNTING_PERIOD);
95 AccountingPeriod accountingPeriod = getJournalVoucherForValidation().getAccountingPeriod();
96
97
98 BalanceTypeService balanceTypeService = SpringContext.getBean(BalanceTypeService.class);
99 List<String> encumbranceBalanceTypes = balanceTypeService.getEncumbranceBalanceTypes(accountingPeriod.getUniversityFiscalYear());
100
101 return encumbranceBalanceTypes.contains(balanceTypeCode);
102 }
103
104
105
106
107
108
109
110
111 protected void putRequiredPropertyError(BusinessObjectEntry boe, String propertyName) {
112 String label = boe.getAttributeDefinition(propertyName).getShortLabel();
113 GlobalVariables.getMessageMap().putError(propertyName, OLEKeyConstants.ERROR_REQUIRED, label);
114 }
115
116
117
118
119
120 public JournalVoucherDocument getJournalVoucherForValidation() {
121 return journalVoucherForValidation;
122 }
123
124
125
126
127
128 public void setJournalVoucherForValidation(JournalVoucherDocument journalVoucherForValidation) {
129 this.journalVoucherForValidation = journalVoucherForValidation;
130 }
131
132
133
134
135
136 public AccountingLine getAccountingLineForValidation() {
137 return accountingLineForValidation;
138 }
139
140
141
142
143
144 public void setAccountingLineForValidation(AccountingLine voucherSourceAccountingLine) {
145 this.accountingLineForValidation = voucherSourceAccountingLine;
146 }
147
148
149
150
151
152 public DataDictionaryService getDataDictionaryService() {
153 return dataDictionaryService;
154 }
155
156
157
158
159
160 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
161 this.dataDictionaryService = dataDictionaryService;
162 }
163 }