1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.validation.impl;
17
18 import java.util.Map;
19
20 import org.kuali.ole.sys.OLEPropertyConstants;
21 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.ole.sys.document.GeneralLedgerPostingDocumentBase;
24 import org.kuali.ole.sys.document.datadictionary.FinancialSystemTransactionalDocumentEntry;
25 import org.kuali.ole.sys.document.validation.AccountingRuleEngineRule;
26 import org.kuali.ole.sys.document.validation.Validation;
27 import org.kuali.ole.sys.document.validation.event.AttributedAddAdHocRoutePersonEvent;
28 import org.kuali.ole.sys.document.validation.event.AttributedAddAdHocRouteWorkgroupEvent;
29 import org.kuali.ole.sys.document.validation.event.AttributedAddNoteEvent;
30 import org.kuali.ole.sys.document.validation.event.AttributedApproveDocumentEvent;
31 import org.kuali.ole.sys.document.validation.event.AttributedBlanketApproveDocumentEvent;
32 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
33 import org.kuali.ole.sys.document.validation.event.AttributedRouteDocumentEvent;
34 import org.kuali.ole.sys.document.validation.event.AttributedSaveDocumentEvent;
35 import org.kuali.rice.kns.service.DataDictionaryService;
36 import org.kuali.rice.krad.bo.AdHocRoutePerson;
37 import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
38 import org.kuali.rice.krad.bo.Note;
39 import org.kuali.rice.krad.document.Document;
40 import org.kuali.rice.krad.document.TransactionalDocument;
41 import org.kuali.rice.kns.rules.DocumentRuleBase;
42 import org.kuali.rice.krad.rules.rule.event.ApproveDocumentEvent;
43 import org.kuali.rice.krad.rules.rule.event.BlanketApproveDocumentEvent;
44
45
46
47
48 public class AccountingRuleEngineRuleBase extends DocumentRuleBase implements AccountingRuleEngineRule {
49 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountingRuleEngineRuleBase.class);
50
51
52
53
54 public AccountingRuleEngineRuleBase() {
55 super();
56 }
57
58
59
60
61 public boolean validateForEvent(AttributedDocumentEvent event) {
62 final FinancialSystemTransactionalDocumentEntry documentEntry = getDataDictionaryEntryForDocument((TransactionalDocument)event.getDocument());
63 final Map<Class, String> validationMap = documentEntry.getValidationMap();
64
65 if (validationMap == null || !validationMap.containsKey(event.getClass())) {
66 return true;
67 } else {
68 final String beanName = validationMap.get(event.getClass());
69 Validation validationBean = SpringContext.getBean(Validation.class, beanName);
70
71 final boolean valid = validationBean.stageValidation(event);
72 return valid;
73 }
74 }
75
76
77
78
79
80
81 protected FinancialSystemTransactionalDocumentEntry getDataDictionaryEntryForDocument(TransactionalDocument document) {
82 return (FinancialSystemTransactionalDocumentEntry)SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getDictionaryObjectEntry(document.getClass().getName());
83 }
84
85
86
87
88 @Override
89 protected boolean processCustomAddAdHocRoutePersonBusinessRules(Document document, AdHocRoutePerson person) {
90 boolean result = super.processCustomAddAdHocRoutePersonBusinessRules(document, person);
91
92 result &= validateForEvent(new AttributedAddAdHocRoutePersonEvent(document, person));
93
94 return result;
95 }
96
97
98
99
100 @Override
101 protected boolean processCustomAddAdHocRouteWorkgroupBusinessRules(Document document, AdHocRouteWorkgroup workgroup) {
102 boolean result = super.processCustomAddAdHocRouteWorkgroupBusinessRules(document, workgroup);
103
104 result &= validateForEvent(new AttributedAddAdHocRouteWorkgroupEvent(document, workgroup));
105
106 return result;
107 }
108
109
110
111
112 @Override
113 protected boolean processCustomAddNoteBusinessRules(Document document, Note note) {
114 boolean result = super.processCustomAddNoteBusinessRules(document, note);
115
116 result &= validateForEvent(new AttributedAddNoteEvent(document, note));
117
118 return result;
119 }
120
121
122
123
124 @Override
125 protected boolean processCustomApproveDocumentBusinessRules(ApproveDocumentEvent approveEvent) {
126 boolean result = super.processCustomApproveDocumentBusinessRules(approveEvent);
127
128 if (approveEvent instanceof BlanketApproveDocumentEvent) {
129 result &= validateForEvent(new AttributedBlanketApproveDocumentEvent(approveEvent.getErrorPathPrefix(), approveEvent.getDocument()));
130 } else {
131 result &= validateForEvent(new AttributedApproveDocumentEvent(approveEvent.getErrorPathPrefix(), approveEvent.getDocument()));
132 }
133
134 return result;
135 }
136
137
138
139
140 @Override
141 protected boolean processCustomRouteDocumentBusinessRules(Document document) {
142 boolean result = super.processCustomRouteDocumentBusinessRules(document);
143
144 AttributedRouteDocumentEvent event = new AttributedRouteDocumentEvent(document);
145 result &= validateForEvent(event);
146
147 return result;
148 }
149
150
151
152
153 @Override
154 protected boolean processCustomSaveDocumentBusinessRules(Document document) {
155 boolean result = super.processCustomSaveDocumentBusinessRules(document);
156
157 result &= validateForEvent(new AttributedSaveDocumentEvent(document));
158
159 return result;
160 }
161
162
163
164
165 @Override
166 public boolean isDocumentAttributesValid(Document document, boolean validateRequired) {
167 FinancialSystemTransactionalDocumentEntry documentEntry = getDataDictionaryEntryForDocument((TransactionalDocument)document);
168 Integer maxDictionaryValidationDepth = documentEntry.getMaxDictionaryValidationDepth();
169
170 if(maxDictionaryValidationDepth != null) {
171 this.setMaxDictionaryValidationDepth(maxDictionaryValidationDepth);
172 }
173
174
175 document.refreshNonUpdateableReferences();
176
177
178 if (document instanceof GeneralLedgerPostingDocumentBase) {
179 GeneralLedgerPostingDocumentBase glpeDocument = (GeneralLedgerPostingDocumentBase) document;
180 for (GeneralLedgerPendingEntry glpe : glpeDocument.getGeneralLedgerPendingEntries()) {
181 glpe.refreshReferenceObject(OLEPropertyConstants.FINANCIAL_OBJECT);
182 }
183 }
184
185 return super.isDocumentAttributesValid(document, validateRequired);
186 }
187 }