Coverage Report - org.kuali.rice.kim.inquiry.PermissionInquirableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionInquirableImpl
0%
0/71
0%
0/36
3.75
 
 1  
 /*
 2  
  * Copyright 2007-2009 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kim.inquiry;
 17  
 
 18  
 import org.apache.commons.beanutils.PropertyUtils;
 19  
 import org.kuali.rice.core.impl.namespace.NamespaceBo;
 20  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 21  
 import org.kuali.rice.kim.bo.impl.PermissionImpl;
 22  
 import org.kuali.rice.kim.bo.impl.RoleImpl;
 23  
 import org.kuali.rice.kim.bo.role.dto.KimRoleInfo;
 24  
 import org.kuali.rice.kim.bo.role.impl.KimPermissionImpl;
 25  
 import org.kuali.rice.kim.bo.role.impl.PermissionAttributeDataImpl;
 26  
 import org.kuali.rice.kim.bo.role.impl.RolePermissionImpl;
 27  
 import org.kuali.rice.kim.impl.role.RoleBo;
 28  
 import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl;
 29  
 import org.kuali.rice.kim.service.PermissionService;
 30  
 import org.kuali.rice.kim.service.RoleService;
 31  
 import org.kuali.rice.kim.util.KimConstants;
 32  
 import org.kuali.rice.kns.bo.BusinessObject;
 33  
 import org.kuali.rice.kns.lookup.HtmlData;
 34  
 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
 35  
 import org.kuali.rice.kns.lookup.HtmlData.MultipleAnchorHtmlData;
 36  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 37  
 import org.kuali.rice.kns.uif.widget.Inquiry;
 38  
 import org.kuali.rice.kns.util.ObjectUtils;
 39  
 
 40  
 import java.util.ArrayList;
 41  
 import java.util.HashMap;
 42  
 import java.util.List;
 43  
 import java.util.Map;
 44  
 
 45  
 /**
 46  
  * This is a description of what this class does - bhargavp don't forget to fill this in. 
 47  
  * 
 48  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 49  
  *
 50  
  */
 51  0
 public class PermissionInquirableImpl extends RoleMemberInquirableImpl {
 52  
 
 53  
         transient private static PermissionService permissionService;
 54  
 
 55  
         @Override
 56  
         public void buildInquirableLink(Object dataObject, String propertyName, Inquiry inquiry){
 57  
                 
 58  0
                 if(NAME.equals(propertyName) || NAME_TO_DISPLAY.equals(propertyName)){
 59  0
                         Map<String, String> primaryKeys = new HashMap<String, String>();
 60  0
                         primaryKeys.put(KimConstants.PrimaryKeyConstants.PERMISSION_ID, KimConstants.PrimaryKeyConstants.PERMISSION_ID);
 61  0
                         inquiry.buildInquiryLink(dataObject, propertyName, PermissionImpl.class, primaryKeys);
 62  0
                 } else if(NAMESPACE_CODE.equals(propertyName) || TEMPLATE_NAMESPACE_CODE.equals(propertyName)){
 63  0
                         Map<String, String> primaryKeys = new HashMap<String, String>();
 64  0
                         primaryKeys.put(propertyName, "code");
 65  0
                         inquiry.buildInquiryLink(dataObject, propertyName, NamespaceBo.class, primaryKeys);
 66  0
         } else if(DETAIL_OBJECTS.equals(propertyName)){
 67  
                 //return getAttributesInquiryUrl(businessObject, DETAIL_OBJECTS);
 68  0
                 super.buildInquirableLink(dataObject, propertyName, inquiry);
 69  0
         } else if(ASSIGNED_TO_ROLES.equals(propertyName)){
 70  
 //                return getAssignedRoleInquiryUrl(businessObject);
 71  0
                 super.buildInquirableLink(dataObject, propertyName, inquiry);
 72  
         }else{
 73  0
                 super.buildInquirableLink(dataObject, propertyName, inquiry);
 74  
         }
 75  0
         }
 76  
         
 77  
     @Override
 78  
     public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
 79  
             /*
 80  
              *  - permission detail values (attribute name and value separated by colon, commas between attributes)
 81  
                  *        - required role qualifiers (attribute name and value separated by colon, commas between attributes)
 82  
                  *        - list of roles assigned: role type, role namespace, role name
 83  
              */
 84  0
                 if(NAME.equals(attributeName) || NAME_TO_DISPLAY.equals(attributeName)){
 85  0
                         List<String> primaryKeys = new ArrayList<String>();
 86  0
                         primaryKeys.add(KimConstants.PrimaryKeyConstants.PERMISSION_ID);
 87  0
                         return getInquiryUrlForPrimaryKeys(PermissionImpl.class, businessObject, primaryKeys, null);
 88  0
                 } else if(NAMESPACE_CODE.equals(attributeName) || TEMPLATE_NAMESPACE_CODE.equals(attributeName)){
 89  0
                         List<String> primaryKeys = new ArrayList<String>();
 90  0
                         primaryKeys.add("code");
 91  0
                         NamespaceBo parameterNamespace = new NamespaceBo();
 92  0
                         parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName));
 93  0
                         return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null);
 94  0
         } else if(DETAIL_OBJECTS.equals(attributeName)){
 95  
                 //return getAttributesInquiryUrl(businessObject, DETAIL_OBJECTS);
 96  0
         } else if(ASSIGNED_TO_ROLES.equals(attributeName)){
 97  0
                 return getAssignedRoleInquiryUrl(businessObject);
 98  
         }
 99  
                 
 100  0
         return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
 101  
     }
 102  
 
 103  
     protected HtmlData getAttributesInquiryUrl(BusinessObject businessObject, String attributeName){
 104  0
             List<PermissionAttributeDataImpl> permissionAttributeData =
 105  
                     (List<PermissionAttributeDataImpl>)ObjectUtils.getPropertyValue(businessObject, attributeName);
 106  0
             List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>();
 107  0
                 List<String> primaryKeys = new ArrayList<String>();
 108  0
                 primaryKeys.add(ATTRIBUTE_DATA_ID);
 109  0
             for(PermissionAttributeDataImpl permissionAttributeDataImpl: permissionAttributeData){
 110  0
                     htmlData.add(getInquiryUrlForPrimaryKeys(PermissionAttributeDataImpl.class, permissionAttributeDataImpl, primaryKeys,
 111  
                             getKimAttributeLabelFromDD(permissionAttributeDataImpl.getKimAttribute().getAttributeName())+
 112  
                             KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+
 113  
                             permissionAttributeDataImpl.getAttributeValue()));
 114  
             }
 115  0
             return new MultipleAnchorHtmlData(htmlData);
 116  
     }
 117  
 
 118  
     protected HtmlData getAssignedRoleInquiryUrl(BusinessObject businessObject){
 119  0
             PermissionImpl permission = (PermissionImpl)businessObject;
 120  0
             List<RoleBo> assignedToRoles = permission.getAssignedToRoles();
 121  0
             List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>();
 122  0
                 List<String> primaryKeys = new ArrayList<String>();
 123  0
                 primaryKeys.add(ROLE_ID);
 124  0
                 if(assignedToRoles!=null && !assignedToRoles.isEmpty()){
 125  0
                         RoleService roleService = KimApiServiceLocator.getRoleService();
 126  
                         KimRoleInfo roleInfo;
 127  
                         AnchorHtmlData inquiryHtmlData;
 128  0
                         for(RoleBo roleImpl: assignedToRoles){
 129  0
                                 roleInfo = roleService.getRole(roleImpl.getId());
 130  0
                                 inquiryHtmlData = getInquiryUrlForPrimaryKeys(RoleImpl.class, roleInfo, primaryKeys, 
 131  
                                         roleInfo.getNamespaceCode()+" "+
 132  
                                         roleInfo.getRoleName());
 133  0
                                 inquiryHtmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(inquiryHtmlData.getHref()));
 134  0
                                 inquiryHtmlData.setTarget(AnchorHtmlData.TARGET_BLANK);
 135  0
                         htmlData.add(inquiryHtmlData);
 136  
                 }
 137  
                 }
 138  0
             return new MultipleAnchorHtmlData(htmlData);
 139  
     }
 140  
 
 141  
         @Override
 142  
         public Object getDataObject(Map fieldValues){
 143  0
             return getBusinessObject(fieldValues);
 144  
     }
 145  
     
 146  
         /**
 147  
          * This overridden method ...
 148  
          * 
 149  
          * @see org.kuali.rice.kns.inquiry.KualiInquirableImpl#getBusinessObject(java.util.Map)
 150  
          */
 151  
         @SuppressWarnings("unchecked")
 152  
         @Override
 153  
         public BusinessObject getBusinessObject(Map fieldValues) {
 154  0
                 Map<String, String> criteria = new HashMap<String, String>();
 155  0
                 criteria.put("permissionId", fieldValues.get("permissionId").toString());
 156  0
                 KimPermissionImpl permissionImpl = (KimPermissionImpl) KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(KimPermissionImpl.class, criteria);
 157  0
                 return getPermissionsSearchResultsCopy(permissionImpl);
 158  
         }
 159  
 
 160  
         public PermissionService getPermissionService() {
 161  0
                 if (permissionService == null ) {
 162  0
                         permissionService = KimApiServiceLocator.getPermissionService();
 163  
                 }
 164  0
                 return permissionService;
 165  
         }
 166  
         
 167  
         private PermissionImpl getPermissionsSearchResultsCopy(KimPermissionImpl permissionSearchResult){
 168  0
                 PermissionImpl permissionSearchResultCopy = new PermissionImpl();
 169  
                 try{
 170  0
                         PropertyUtils.copyProperties(permissionSearchResultCopy, permissionSearchResult);
 171  0
                 } catch(Exception ex){
 172  
                         //TODO: remove this
 173  0
                         ex.printStackTrace();
 174  0
                 }
 175  0
                 Map<String, String> criteria = new HashMap<String, String>();
 176  0
                 criteria.put("permissionId", permissionSearchResultCopy.getPermissionId());
 177  0
                 List<RolePermissionImpl> rolePermissions = 
 178  
                         (List<RolePermissionImpl>) KNSServiceLocator.getBusinessObjectService().findMatching(RolePermissionImpl.class, criteria);
 179  0
                 List<RoleBo> assignedToRoles = new ArrayList<RoleBo>();
 180  0
                 for(RolePermissionImpl rolePermissionImpl: rolePermissions){
 181  0
                         assignedToRoles.add(getRoleImpl(rolePermissionImpl.getRoleId()));
 182  
                 }
 183  0
                 permissionSearchResultCopy.setAssignedToRoles(assignedToRoles);
 184  0
                 return permissionSearchResultCopy;
 185  
         }
 186  
 
 187  
 }