1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.authorization;
17
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Set;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.ole.fp.document.DisbursementVoucherConstants;
24 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
25 import org.kuali.ole.sys.businessobject.AccountingLine;
26 import org.kuali.ole.sys.document.authorization.AccountingDocumentAuthorizerBase;
27 import org.kuali.ole.sys.identity.OleKimAttributes;
28 import org.kuali.rice.kew.api.WorkflowDocument;
29 import org.kuali.rice.kim.api.KimConstants;
30 import org.kuali.rice.kim.api.identity.Person;
31 import org.kuali.rice.krad.util.GlobalVariables;
32 import org.kuali.rice.krad.util.ObjectUtils;
33
34
35
36
37 public class DisbursementVoucherDocumentAuthorizer extends AccountingDocumentAuthorizerBase {
38
39
40
41
42
43 @Override
44 protected void addRoleQualification(Object dataObject, Map<String, String> attributes) {
45 super.addRoleQualification(dataObject, attributes);
46 final DisbursementVoucherDocument disbursementVoucherDocument = (DisbursementVoucherDocument)dataObject;
47
48
49 if (isAtAccountLevel(disbursementVoucherDocument)) {
50 addAccountQualification(getAccountingLines(disbursementVoucherDocument), attributes);
51 }
52
53
54 if (!StringUtils.isBlank(disbursementVoucherDocument.getCampusCode())) {
55 attributes.put(KimConstants.AttributeConstants.CAMPUS_CODE, disbursementVoucherDocument.getCampusCode());
56 }
57 }
58
59
60
61
62
63
64 protected List<? extends AccountingLine> getAccountingLines(DisbursementVoucherDocument disbursementVoucherDocument) {
65 return disbursementVoucherDocument.getSourceAccountingLines();
66 }
67
68
69
70
71
72
73
74 protected void addAccountQualification(List<? extends AccountingLine> accountingLines, Map<String, String> attributes) {
75 final Person currentUser = GlobalVariables.getUserSession().getPerson();
76 boolean foundQualification = false;
77 int count = 0;
78 while (!foundQualification && count < accountingLines.size()) {
79 AccountingLine accountingLine = accountingLines.get(count);
80 if (ObjectUtils.isNull(accountingLine.getAccount())) {
81 accountingLine.refreshReferenceObject("account");
82 }
83 if (!ObjectUtils.isNull(accountingLine.getAccount()) && currentUser.getPrincipalId().equalsIgnoreCase(accountingLine.getAccount().getAccountFiscalOfficerSystemIdentifier())) {
84 attributes.put(OleKimAttributes.CHART_OF_ACCOUNTS_CODE, accountingLine.getChartOfAccountsCode());
85 attributes.put(OleKimAttributes.ACCOUNT_NUMBER, accountingLine.getAccountNumber());
86 foundQualification = true;
87 }
88 count += 1;
89 }
90 }
91
92
93
94
95
96
97
98 protected Set<String> getCurrentRouteLevels(WorkflowDocument workflowDocument) {
99 return workflowDocument.getCurrentNodeNames();
100 }
101
102
103
104
105
106
107 protected boolean isAtAccountLevel(DisbursementVoucherDocument disbursementVoucherDocument) {
108 final WorkflowDocument workflowDocument = disbursementVoucherDocument.getDocumentHeader().getWorkflowDocument();
109
110 return getCurrentRouteLevels(workflowDocument).contains(DisbursementVoucherConstants.RouteLevelNames.ACCOUNT);
111 }
112 }