1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.authorization;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Set;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.ole.coa.service.AccountService;
24 import org.kuali.ole.sys.OLEConstants;
25 import org.kuali.ole.sys.OLEConstants.RouteLevelNames;
26 import org.kuali.ole.sys.OleAuthorizationConstants;
27 import org.kuali.ole.sys.businessobject.AccountingLine;
28 import org.kuali.ole.sys.businessobject.FinancialSystemDocumentHeader;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.document.AccountingDocument;
31 import org.kuali.rice.kew.api.WorkflowDocument;
32 import org.kuali.rice.kim.api.identity.Person;
33 import org.kuali.rice.krad.document.Document;
34 import org.kuali.rice.krad.util.GlobalVariables;
35 import org.kuali.rice.krad.util.ObjectUtils;
36
37 public class AccountingDocumentPresentationControllerBase extends LedgerPostingDocumentPresentationControllerBase {
38
39
40
41
42 @Override
43 public Set<String> getEditModes(Document document) {
44 Set<String> editModes = super.getEditModes(document);
45
46 this.addExpenseEntryEditMode(document, editModes);
47
48 return editModes;
49 }
50
51
52 protected void addExpenseEntryEditMode(Document document, Set<String> editModes) {
53 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
54 Set<String> currentRouteLevels = workflowDocument.getCurrentNodeNames();
55
56 if (workflowDocument.isEnroute() && currentRouteLevels.contains(OLEConstants.RouteLevelNames.ACCOUNT)) {
57 AccountingDocument accountingDocument = (AccountingDocument) document;
58
59 List<AccountingLine> lineList = new ArrayList<AccountingLine>();
60 lineList.addAll(accountingDocument.getSourceAccountingLines());
61 lineList.addAll(accountingDocument.getTargetAccountingLines());
62
63 Person currentUser = GlobalVariables.getUserSession().getPerson();
64 if (workflowDocument.isApprovalRequested() && userOwnsAnyAccountingLine(currentUser, lineList)) {
65 editModes.add(OleAuthorizationConstants.TransactionalEditMode.EXPENSE_ENTRY);
66 }
67 }
68 }
69
70
71
72
73 @Override
74 public boolean canEdit(Document document) {
75 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
76 FinancialSystemDocumentHeader documentheader = (FinancialSystemDocumentHeader) (document.getDocumentHeader());
77
78 if (workflowDocument.isCanceled() || documentheader.getFinancialDocumentInErrorNumber() != null) {
79 return false;
80 }
81 else if (workflowDocument.isEnroute()) {
82 Set<String> currentRouteLevels = workflowDocument.getCurrentNodeNames();
83
84 if (currentRouteLevels.contains(RouteLevelNames.ACCOUNTING_ORGANIZATION_HIERARCHY)) {
85 return false;
86 }
87 }
88
89 return super.canEdit(document);
90 }
91
92
93
94
95
96
97 protected boolean userOwnsAnyAccountingLine(Person user, List<AccountingLine> accountingLines) {
98 for (AccountingLine accountingLine : accountingLines) {
99 if (StringUtils.isNotEmpty(accountingLine.getAccountNumber()) && ObjectUtils.isNotNull(accountingLine.getAccount()))
100 if (SpringContext.getBean(AccountService.class).hasResponsibilityOnAccount(user, accountingLine.getAccount())) {
101 return true;
102 }
103 }
104 return false;
105 }
106 }