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.fp.document.authorization.ServiceBillingDocumentAuthorizer;
20 import org.kuali.ole.sys.OLEKeyConstants;
21 import org.kuali.ole.sys.OLEPropertyConstants;
22 import org.kuali.ole.sys.businessobject.AccountingLine;
23 import org.kuali.ole.sys.businessobject.FinancialSystemDocumentHeader;
24 import org.kuali.ole.sys.document.AccountingDocument;
25 import org.kuali.ole.sys.document.Correctable;
26 import org.kuali.ole.sys.document.validation.GenericValidation;
27 import org.kuali.ole.sys.document.validation.event.AddAccountingLineEvent;
28 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
29 import org.kuali.ole.sys.document.validation.event.DeleteAccountingLineEvent;
30 import org.kuali.ole.sys.document.validation.event.UpdateAccountingLineEvent;
31 import org.kuali.rice.kew.api.WorkflowDocument;
32 import org.kuali.rice.kim.api.identity.Person;
33 import org.kuali.rice.kns.service.DataDictionaryService;
34 import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
35 import org.kuali.rice.krad.util.GlobalVariables;
36
37
38
39
40 public class ServiceBillingAccountingLineAccessibleValidation extends GenericValidation {
41 private DataDictionaryService dataDictionaryService;
42 private AccountingDocument accountingDocumentForValidation;
43 private AccountingLine accountingLineForValidation;
44
45
46
47
48 public enum AccountingLineAction {
49 ADD(OLEKeyConstants.ERROR_ACCOUNTINGLINE_INACCESSIBLE_ADD), DELETE(OLEKeyConstants.ERROR_ACCOUNTINGLINE_INACCESSIBLE_DELETE), UPDATE(OLEKeyConstants.ERROR_ACCOUNTINGLINE_INACCESSIBLE_UPDATE);
50
51 public final String accessibilityErrorKey;
52
53 AccountingLineAction(String accessabilityErrorKey) {
54 this.accessibilityErrorKey = accessabilityErrorKey;
55 }
56 }
57
58
59
60
61
62
63 public boolean validate(AttributedDocumentEvent event) {
64 final Person currentUser = GlobalVariables.getUserSession().getPerson();
65
66 if (accountingDocumentForValidation instanceof Correctable) {
67 final String errorDocumentNumber = ((FinancialSystemDocumentHeader)accountingDocumentForValidation.getDocumentHeader()).getFinancialDocumentInErrorNumber();
68 if (StringUtils.isNotBlank(errorDocumentNumber))
69 return true;
70 }
71
72 final WorkflowDocument workflowDocument = accountingDocumentForValidation.getDocumentHeader().getWorkflowDocument();
73 if (accountingLineForValidation.isTargetAccountingLine() && (workflowDocument.isInitiated() || workflowDocument.isSaved())) {
74 return true;
75 }
76
77 final boolean isAccessible = new ServiceBillingDocumentAuthorizer().canModifyAccountingLine(accountingDocumentForValidation, accountingLineForValidation, currentUser);
78
79
80 if (!isAccessible) {
81 final String principalName = currentUser.getPrincipalName();
82
83 final String[] chartErrorParams = new String[] { getDataDictionaryService().getAttributeLabel(accountingLineForValidation.getClass(), OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE), accountingLineForValidation.getChartOfAccountsCode(), principalName};
84 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, convertEventToMessage(event), chartErrorParams);
85
86 final String[] accountErrorParams = new String[] { getDataDictionaryService().getAttributeLabel(accountingLineForValidation.getClass(), OLEPropertyConstants.ACCOUNT_NUMBER), accountingLineForValidation.getAccountNumber(), principalName };
87 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.ACCOUNT_NUMBER, convertEventToMessage(event), accountErrorParams);
88 }
89
90 return isAccessible;
91 }
92
93
94
95
96
97
98
99 protected String convertEventToMessage(KualiDocumentEvent event) {
100 if (event instanceof AddAccountingLineEvent) {
101 return AccountingLineAction.ADD.accessibilityErrorKey;
102 } else if (event instanceof UpdateAccountingLineEvent) {
103 return AccountingLineAction.UPDATE.accessibilityErrorKey;
104 } else if (event instanceof DeleteAccountingLineEvent) {
105 return AccountingLineAction.DELETE.accessibilityErrorKey;
106 } else {
107 return "";
108 }
109 }
110
111
112
113
114
115 public AccountingDocument getAccountingDocumentForValidation() {
116 return accountingDocumentForValidation;
117 }
118
119
120
121
122
123 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
124 this.accountingDocumentForValidation = accountingDocumentForValidation;
125 }
126
127
128
129
130
131 public AccountingLine getAccountingLineForValidation() {
132 return accountingLineForValidation;
133 }
134
135
136
137
138
139 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
140 this.accountingLineForValidation = accountingLineForValidation;
141 }
142
143
144
145
146
147 public DataDictionaryService getDataDictionaryService() {
148 return dataDictionaryService;
149 }
150
151
152
153
154
155 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
156 this.dataDictionaryService = dataDictionaryService;
157 }
158
159 }
160