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.HashMap;
19 import java.util.Map;
20 import java.util.Set;
21
22 import org.kuali.ole.sys.OLEConstants;
23 import org.kuali.ole.sys.businessobject.AccountingLine;
24 import org.kuali.ole.sys.document.AccountingDocument;
25 import org.kuali.ole.sys.document.authorization.AccountingDocumentAuthorizerBase;
26 import org.kuali.ole.sys.identity.OleKimAttributes;
27 import org.kuali.rice.kim.api.KimConstants;
28 import org.kuali.rice.kim.api.identity.Person;
29 import org.kuali.rice.kns.document.authorization.DocumentAuthorizerBase;
30 import org.kuali.rice.krad.document.Document;
31 import org.kuali.rice.krad.util.KRADConstants;
32
33
34
35
36 public class ServiceBillingDocumentAuthorizer extends AccountingDocumentAuthorizerBase {
37 protected static String serviceBillingDocumentTypeName;
38
39
40
41
42
43 @Override
44 public Set<String> getDocumentActions(Document document, Person user, Set<String> documentActionsFromPresentationController) {
45 Set<String> documentActions = super.getDocumentActions(document, user, documentActionsFromPresentationController);
46
47 boolean canCopyOrErrorCorrect = (documentActions.contains(KRADConstants.KUALI_ACTION_CAN_COPY) || documentActions.contains(OLEConstants.KFS_ACTION_CAN_ERROR_CORRECT)) ? canModifyAllSourceAccountingLines(document, user) : true;
48
49 if (documentActions.contains(KRADConstants.KUALI_ACTION_CAN_COPY)) {
50 if (!canCopyOrErrorCorrect) {
51 documentActions.remove(KRADConstants.KUALI_ACTION_CAN_COPY);
52 }
53 }
54 if (documentActions.contains(OLEConstants.KFS_ACTION_CAN_ERROR_CORRECT)) {
55 if (!canCopyOrErrorCorrect) {
56 documentActions.remove(OLEConstants.KFS_ACTION_CAN_ERROR_CORRECT);
57 }
58 }
59 return documentActions;
60 }
61
62
63
64
65
66
67
68 protected boolean canModifyAllSourceAccountingLines(Document document, Person user) {
69 for (Object accountingLineAsObject : ((AccountingDocument)document).getSourceAccountingLines()) {
70 if (!canModifyAccountingLine(document, ((AccountingLine)accountingLineAsObject), user)) {
71 return false;
72 }
73 }
74 return true;
75 }
76
77
78
79
80
81
82
83
84 public boolean canModifyAccountingLine(Document document, AccountingLine accountingLine, Person user) {
85 return isAuthorizedByTemplate(document, OLEConstants.CoreModuleNamespaces.OLE, OLEConstants.PermissionTemplate.MODIFY_ACCOUNTING_LINES.name, user.getPrincipalId(), buildPermissionDetails(document), buildRoleQualifiers(accountingLine));
86 }
87
88
89
90
91
92
93 protected Map<String, String> buildPermissionDetails(Document document) {
94 Map<String, String> permissionDetails = new HashMap<String, String>();
95 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, getDocumentTypeName(document));
96 permissionDetails.put(OleKimAttributes.ROUTE_NODE_NAME, DocumentAuthorizerBase.PRE_ROUTING_ROUTE_NAME);
97 permissionDetails.put(KimConstants.AttributeConstants.PROPERTY_NAME, "sourceAccountingLines");
98 return permissionDetails;
99 }
100
101
102
103
104
105
106 protected String getDocumentTypeName(Document document) {
107 if (serviceBillingDocumentTypeName == null) {
108 serviceBillingDocumentTypeName = getDataDictionaryService().getDocumentTypeNameByClass(document.getClass());
109 }
110 return serviceBillingDocumentTypeName;
111 }
112
113
114
115
116
117
118 protected Map<String, String> buildRoleQualifiers(AccountingLine accountingLine) {
119 Map<String, String> roleQualifiers = new HashMap<String, String>();
120 roleQualifiers.put(OleKimAttributes.CHART_OF_ACCOUNTS_CODE, accountingLine.getChartOfAccountsCode());
121 roleQualifiers.put(OleKimAttributes.ACCOUNT_NUMBER, accountingLine.getAccountNumber());
122 return roleQualifiers;
123 }
124 }