1 package org.kuali.ole.service;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.rice.kim.api.permission.PermissionService;
5 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
6 import org.kuali.rice.krad.uif.component.Component;
7 import org.kuali.rice.krad.uif.field.Field;
8 import org.kuali.rice.krad.uif.view.LookupView;
9 import org.kuali.rice.krad.uif.view.View;
10 import org.kuali.rice.krad.util.GlobalVariables;
11
12 import java.util.List;
13
14
15
16
17
18
19
20
21 public class OleLookupView extends LookupView {
22
23
24
25
26
27
28
29 @Override
30 public void performApplyModel(View view, Object model, Component parent) {
31 Class className = this.getDataObjectClassName();
32 String principalId = GlobalVariables.getUserSession().getPrincipalId();
33 super.performApplyModel(view, model, parent);
34 if(className.getName().equalsIgnoreCase(OLEConstants.PATRON)) {
35 boolean canCreate = canCreate(principalId);
36 if(!canCreate){
37 if (!isSuppressActions() && isShowMaintenanceLinks()) {
38
39 }
40 }
41 }
42
43 if(className.getName().equalsIgnoreCase(OLEConstants.PATRON)) {
44 for(int resultSize=0; resultSize < getResultFields().size(); resultSize++) {
45 boolean hasDisplayBillRole = canDisplayBill(principalId);
46 boolean hasCreateBillRole = canCreateBill(principalId);
47 if(!hasDisplayBillRole || !hasCreateBillRole) {
48 if(getResultFields().get(resultSize).getId().equalsIgnoreCase(OLEConstants.VIEWBILL) || getResultFields().get(resultSize).getId().equalsIgnoreCase(OLEConstants.CREATEBILL)){
49 ((List<Field>) getResultsGroup().getItems()).remove(getResultFields().get(resultSize));
50 }
51 }
52 }
53
54 }
55 }
56
57 private boolean canDisplayBill(String principalId){
58 PermissionService service= KimApiServiceLocator.getPermissionService();
59 return service.hasPermission(principalId, OLEConstants.OlePatron.PATRON_NAMESPACE,OLEConstants.CAN_DISPLAY_BILL);
60 }
61
62 private boolean canCreateBill(String principalId){
63 PermissionService service= KimApiServiceLocator.getPermissionService();
64 return service.hasPermission(principalId, OLEConstants.OlePatron.PATRON_NAMESPACE,OLEConstants.CAN_CREATEORUPDATE_BILL);
65 }
66
67 private boolean canCreate(String principalId){
68 PermissionService service= KimApiServiceLocator.getPermissionService();
69 return service.hasPermission(principalId, OLEConstants.OlePatron.PATRON_NAMESPACE,OLEConstants.EDIT_PATRON_DOCUMENT);
70 }
71 }