001package org.kuali.ole.deliver.inquiry; 002 003import org.kuali.ole.OLEConstants; 004import org.kuali.rice.coreservice.impl.parameter.ParameterBo; 005import org.kuali.rice.kim.api.KimConstants; 006import org.kuali.rice.kim.api.identity.Person; 007import org.kuali.rice.krad.inquiry.InquiryViewAuthorizerBase; 008import org.kuali.rice.krad.service.BusinessObjectService; 009import org.kuali.rice.krad.service.KRADServiceLocator; 010import org.kuali.rice.krad.uif.field.Field; 011import org.kuali.rice.krad.uif.view.View; 012import org.kuali.rice.krad.uif.view.ViewModel; 013 014import java.util.HashMap; 015import java.util.List; 016import java.util.Map; 017 018/** 019 * Created with IntelliJ IDEA. 020 * User: ? 021 * Date: 9/5/12 022 * Time: 4:25 PM 023 * To change this template use File | Settings | File Templates. 024 */ 025public class OlePatronInquiryViewAuthorizer extends InquiryViewAuthorizerBase { 026 private List<ParameterBo> parametersList; 027 private Map<String, String> labelMap = new HashMap<String, String>(); 028 private boolean isListPopulated; 029 private boolean isTitleSet; 030 031 public void populateParametersList() { 032 isListPopulated = true; 033 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService(); 034 Map<String, String> criteriaMap = new HashMap<String, String>(); 035 criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.OlePatron.PATRON_NAMESPACE); 036 criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.OlePatron.PATRON); 037 parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap); 038 for (int i = 0; i < parametersList.size(); i++) { 039 labelMap.put(parametersList.get(i).getName(), parametersList.get(i).getValue()); 040 } 041 } 042 043 044 @Override 045 public boolean canViewField(View view, ViewModel model, Field field, String propertyName, Person user) { 046 // check view authz flag is set 047 if (!isTitleSet && view.getHeader().getHeaderText().contains(OLEConstants.OlePatron.PATRON)) { 048 if (!isListPopulated) { 049 populateParametersList(); 050 } 051 view.getHeader().setHeaderText(view.getHeader().getHeaderText().replace(OLEConstants.OlePatron.PATRON, labelMap.get(OLEConstants.OlePatron.PATRON))); 052 isTitleSet = true; 053 } 054 if (!field.getComponentSecurity().isViewAuthz()) { 055 if (!isListPopulated) { 056 populateParametersList(); 057 } 058 if (labelMap.containsKey(field.getLabel())) { 059 field.setLabel(labelMap.get(field.getLabel())); 060 } 061 return true; 062 } 063 064 return isAuthorizedByTemplate(view, field, model, KimConstants.PermissionTemplateNames.VIEW_FIELD, user, null, 065 null, false); 066 } 067}