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.SELECTED_ACCOUNTING_PERIOD;
19 import static org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
20
21 import org.kuali.ole.coa.businessobject.AccountingPeriod;
22 import org.kuali.ole.fp.document.JournalVoucherDocument;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.ole.sys.OLEPropertyConstants;
25 import org.kuali.ole.sys.document.validation.GenericValidation;
26 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27 import org.kuali.rice.kns.service.DataDictionaryService;
28 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
29 import org.kuali.rice.krad.datadictionary.DataDictionaryEntry;
30 import org.kuali.rice.krad.util.GlobalVariables;
31 import org.kuali.rice.krad.util.ObjectUtils;
32
33
34
35
36 public class JournalVoucherAccountingPeriodValidation extends GenericValidation {
37 private JournalVoucherDocument journalVoucherForValidation;
38 private DataDictionaryService dataDictionaryService;
39
40
41
42
43
44 public boolean validate(AttributedDocumentEvent event) {
45
46 String label = getLabelFromDataDictionary(JournalVoucherDocument.class, OLEPropertyConstants.ACCOUNTING_PERIOD);
47 getJournalVoucherForValidation().refreshReferenceObject(OLEPropertyConstants.ACCOUNTING_PERIOD);
48 AccountingPeriod accountingPeriod = getJournalVoucherForValidation().getAccountingPeriod();
49 if (ObjectUtils.isNull(accountingPeriod)) {
50 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + SELECTED_ACCOUNTING_PERIOD, OLEKeyConstants.ERROR_EXISTENCE, label);
51 return false;
52 }
53
54
55 if (!accountingPeriod.isActive()) {
56 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + SELECTED_ACCOUNTING_PERIOD, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_PERIOD_CLOSED);
57 return false;
58 }
59
60 return true;
61 }
62
63
64
65
66
67
68
69 protected String getLabelFromDataDictionary(Class entryClass, String attributeName) {
70 DataDictionaryEntry entry = getDataDictionaryService().getDataDictionary().getDictionaryObjectEntry(entryClass.getName());
71 if (entry == null) {
72 throw new IllegalArgumentException("Cannot find DataDictionary entry for " + entryClass);
73 }
74 AttributeDefinition attributeDefinition = entry.getAttributeDefinition(attributeName);
75 if (attributeDefinition == null) {
76 throw new IllegalArgumentException("Cannot find " + entryClass + " attribute with name " + attributeName);
77 }
78 return attributeDefinition.getLabel();
79 }
80
81
82
83
84
85 public JournalVoucherDocument getJournalVoucherForValidation() {
86 return journalVoucherForValidation;
87 }
88
89
90
91
92
93 public void setJournalVoucherForValidation(JournalVoucherDocument journalVoucherForValidation) {
94 this.journalVoucherForValidation = journalVoucherForValidation;
95 }
96
97
98
99
100
101 public DataDictionaryService getDataDictionaryService() {
102 return dataDictionaryService;
103 }
104
105
106
107
108
109 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
110 this.dataDictionaryService = dataDictionaryService;
111 }
112 }