View Javadoc
1   package org.kuali.ole.deliver.maintenance;
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.maintenance.MaintenanceViewAuthorizerBase;
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   * Created with IntelliJ IDEA.
20   * User: ?
21   * Date: 9/4/12
22   * Time: 5:26 PM
23   * To change this template use File | Settings | File Templates.
24   */
25  public class OlePatronMaintenanceViewAuthorizer extends MaintenanceViewAuthorizerBase {
26  
27      private List<ParameterBo> parametersList;
28      private Map<String, String> labelMap = new HashMap<String, String>();
29      private boolean isListPopulated;
30      private boolean isTitleSet;
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          List<ParameterBo> 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          // check view authz flag is set
48  
49          if (!isTitleSet && view.getHeaderText().contains(OLEConstants.OlePatron.PATRON)) {
50              if (!isListPopulated) {
51                  populateParametersList();
52              }
53              view.setHeaderText(view.getHeaderText().replace(OLEConstants.OlePatron.PATRON, labelMap.get(OLEConstants.OlePatron.PATRON)));
54              isTitleSet = true;
55          }
56          if (!field.getComponentSecurity().isViewAuthz()) {
57              if (!isListPopulated) {
58                  populateParametersList();
59              }
60              if (labelMap.containsKey(field.getLabel())) {
61                  field.setLabel(labelMap.get(field.getLabel()));
62              }
63              return true;
64  
65          }
66  
67          return isAuthorizedByTemplate(view, field, model, KimConstants.PermissionTemplateNames.VIEW_FIELD, user, null,
68                  null, false);
69      }
70  
71  
72  }