1 package org.kuali.ole.patron.lookup;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
5 import org.kuali.rice.kim.api.KimConstants;
6 import org.kuali.rice.kim.api.identity.Person;
7 import org.kuali.rice.krad.lookup.LookupViewAuthorizerBase;
8 import org.kuali.rice.krad.service.BusinessObjectService;
9 import org.kuali.rice.krad.service.KRADServiceLocator;
10 import org.kuali.rice.krad.uif.container.CollectionGroup;
11 import org.kuali.rice.krad.uif.field.Field;
12 import org.kuali.rice.krad.uif.field.FieldSecurity;
13 import org.kuali.rice.krad.uif.view.View;
14 import org.kuali.rice.krad.uif.view.ViewModel;
15
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
20
21
22
23
24
25
26
27 public class OlePatronLookupViewAuthorizer extends LookupViewAuthorizerBase {
28 private List<ParameterBo> parametersList;
29 private Map<String, String> labelMap = new HashMap<String, String>();
30 private boolean isListPopulated;
31
32 public void populateParametersList() {
33 isListPopulated = true;
34 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
35 Map<String, String> criteriaMap = new HashMap<String, String>();
36 criteriaMap.put(OLEConstants.NAMESPACE_CODE,OLEConstants.OlePatron.PATRON_NAMESPACE);
37 criteriaMap.put(OLEConstants.COMPONENT_CODE,OLEConstants.OlePatron.PATRON);
38 parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
39 for (int i = 0; i < parametersList.size(); i++) {
40 labelMap.put(parametersList.get(i).getName(), parametersList.get(i).getValue());
41 }
42 }
43
44
45 @Override
46 public boolean canViewField(View view, ViewModel model, Field field, String propertyName, Person user) {
47
48 if (!field.getComponentSecurity().isViewAuthz()) {
49 if (!isListPopulated) {
50 populateParametersList();
51 }
52 if (labelMap.containsKey(field.getLabel())) {
53 field.setLabel(labelMap.get(field.getLabel()));
54 }
55 return true;
56 }
57 return isAuthorizedByTemplate(view, field, model, KimConstants.PermissionTemplateNames.VIEW_FIELD, user, null,
58 null, false);
59 }
60
61 @Override
62 public boolean canViewLineField(View view, ViewModel model, CollectionGroup collectionGroup,
63 String collectionPropertyName, Object line, Field field, String propertyName, Person user) {
64
65 if (!((FieldSecurity) field.getComponentSecurity()).isViewInLineAuthz()) {
66 if (labelMap.containsKey(field.getLabel())) {
67 field.setLabel(labelMap.get(field.getLabel()));
68 }
69 return true;
70 }
71
72 Map<String, String> additionalPermissionDetails = new HashMap<String, String>();
73 additionalPermissionDetails.put(KimConstants.AttributeConstants.GROUP_ID, collectionGroup.getId());
74 additionalPermissionDetails.put(KimConstants.AttributeConstants.COLLECTION_PROPERTY_NAME,
75 collectionGroup.getPropertyName());
76
77 return isAuthorizedByTemplate(view, field, model,
78 KimConstants.PermissionTemplateNames.VIEW_LINE_FIELD, user, additionalPermissionDetails, null, false);
79 }
80 }