View Javadoc
1   package org.kuali.ole.deliver.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   * Created with IntelliJ IDEA.
22   * User: ?
23   * Date: 9/5/12
24   * Time: 4:23 PM
25   * To change this template use File | Settings | File Templates.
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      private boolean isTitleSet;
32  
33      public void populateParametersList() {
34          isListPopulated = true;
35          BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
36          Map<String, String> criteriaMap = new HashMap<String, String>();
37          criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.OlePatron.PATRON_NAMESPACE);
38          criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.OlePatron.PATRON);
39          parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
40          for (int i = 0; i < parametersList.size(); i++) {
41              labelMap.put(parametersList.get(i).getName(), parametersList.get(i).getValue());
42          }
43      }
44  
45  
46      @Override
47      public boolean canViewField(View view, ViewModel model, Field field, String propertyName, Person user) {
48          // check view authz flag is set
49          if (!isTitleSet && view.getHeader().getHeaderText().contains(OLEConstants.OlePatron.PATRON)) {
50              if (!isListPopulated) {
51                  populateParametersList();
52              }
53              view.getHeader().setHeaderText(view.getHeader().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          return isAuthorizedByTemplate(view, field, model, KimConstants.PermissionTemplateNames.VIEW_FIELD, user, null,
66                  null, false);
67      }
68  
69      @Override
70      public boolean canViewLineField(View view, ViewModel model, CollectionGroup collectionGroup,
71                                      String collectionPropertyName, Object line, Field field, String propertyName, Person user) {
72          // check view line field authz flag is set
73          if (!((FieldSecurity) field.getComponentSecurity()).isViewInLineAuthz()) {
74              if (labelMap.containsKey(field.getLabel())) {
75                  field.setLabel(labelMap.get(field.getLabel()));
76              }
77              return true;
78          }
79  
80          Map<String, String> additionalPermissionDetails = new HashMap<String, String>();
81          additionalPermissionDetails.put(KimConstants.AttributeConstants.GROUP_ID, collectionGroup.getId());
82          additionalPermissionDetails.put(KimConstants.AttributeConstants.COLLECTION_PROPERTY_NAME,
83                  collectionGroup.getPropertyName());
84  
85          return isAuthorizedByTemplate(view, field, model,
86                  KimConstants.PermissionTemplateNames.VIEW_LINE_FIELD, user, additionalPermissionDetails, null, false);
87      }
88  }