1 package org.kuali.ole.deliver.inquiry;
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.inquiry.InquiryViewAuthorizerBase;
8 import org.kuali.rice.krad.service.BusinessObjectService;
9 import org.kuali.rice.krad.service.KRADServiceLocator;
10 import org.kuali.rice.krad.uif.field.Field;
11 import org.kuali.rice.krad.uif.view.View;
12 import org.kuali.rice.krad.uif.view.ViewModel;
13
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
17
18
19
20
21
22
23
24
25 public class OlePatronInquiryViewAuthorizer extends InquiryViewAuthorizerBase {
26 private List<ParameterBo> parametersList;
27 private Map<String, String> labelMap = new HashMap<String, String>();
28 private boolean isListPopulated;
29 private boolean isTitleSet;
30
31 public void populateParametersList() {
32 isListPopulated = true;
33 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
34 Map<String, String> criteriaMap = new HashMap<String, String>();
35 criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.OlePatron.PATRON_NAMESPACE);
36 criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.OlePatron.PATRON);
37 parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
38 for (int i = 0; i < parametersList.size(); i++) {
39 labelMap.put(parametersList.get(i).getName(), parametersList.get(i).getValue());
40 }
41 }
42
43
44 @Override
45 public boolean canViewField(View view, ViewModel model, Field field, String propertyName, Person user) {
46
47 if (!isTitleSet && view.getHeader().getHeaderText().contains(OLEConstants.OlePatron.PATRON)) {
48 if (!isListPopulated) {
49 populateParametersList();
50 }
51 view.getHeader().setHeaderText(view.getHeader().getHeaderText().replace(OLEConstants.OlePatron.PATRON, labelMap.get(OLEConstants.OlePatron.PATRON)));
52 isTitleSet = true;
53 }
54 if (!field.getComponentSecurity().isViewAuthz()) {
55 if (!isListPopulated) {
56 populateParametersList();
57 }
58 if (labelMap.containsKey(field.getLabel())) {
59 field.setLabel(labelMap.get(field.getLabel()));
60 }
61 return true;
62 }
63
64 return isAuthorizedByTemplate(view, field, model, KimConstants.PermissionTemplateNames.VIEW_FIELD, user, null,
65 null, false);
66 }
67 }