Coverage Report - org.kuali.rice.kim.inquiry.PermissionInquirableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionInquirableImpl
0%
0/56
0%
0/24
3.667
 
 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 java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.commons.beanutils.PropertyUtils;
 24  
 import org.kuali.rice.kim.bo.impl.PermissionImpl;
 25  
 import org.kuali.rice.kim.bo.impl.RoleImpl;
 26  
 import org.kuali.rice.kim.bo.role.dto.KimRoleInfo;
 27  
 import org.kuali.rice.kim.bo.role.impl.KimPermissionImpl;
 28  
 import org.kuali.rice.kim.bo.role.impl.PermissionAttributeDataImpl;
 29  
 import org.kuali.rice.kim.bo.role.impl.RolePermissionImpl;
 30  
 import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl;
 31  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 32  
 import org.kuali.rice.kim.service.PermissionService;
 33  
 import org.kuali.rice.kim.service.RoleService;
 34  
 import org.kuali.rice.kim.util.KimConstants;
 35  
 import org.kuali.rice.kns.bo.BusinessObject;
 36  
 import org.kuali.rice.kns.bo.Namespace;
 37  
 import org.kuali.rice.kns.lookup.HtmlData;
 38  
 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
 39  
 import org.kuali.rice.kns.lookup.HtmlData.MultipleAnchorHtmlData;
 40  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 41  
 import org.kuali.rice.kns.util.ObjectUtils;
 42  
 
 43  
 /**
 44  
  * This is a description of what this class does - bhargavp don't forget to fill this in. 
 45  
  * 
 46  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 47  
  *
 48  
  */
 49  0
 public class PermissionInquirableImpl extends RoleMemberInquirableImpl {
 50  
 
 51  
         transient private static PermissionService permissionService;
 52  
 
 53  
         
 54  
     /**
 55  
      * @see org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl#getInquiryUrl(org.kuali.rice.kns.bo.BusinessObject,
 56  
      *      java.lang.String, boolean)
 57  
      */
 58  
     @Override
 59  
     public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
 60  
             /*
 61  
              *  - permission detail values (attribute name and value separated by colon, commas between attributes)
 62  
                  *        - required role qualifiers (attribute name and value separated by colon, commas between attributes)
 63  
                  *        - list of roles assigned: role type, role namespace, role name
 64  
              */
 65  0
                 if(NAME.equals(attributeName) || NAME_TO_DISPLAY.equals(attributeName)){
 66  0
                         List<String> primaryKeys = new ArrayList<String>();
 67  0
                         primaryKeys.add(KimConstants.PrimaryKeyConstants.PERMISSION_ID);
 68  0
                         return getInquiryUrlForPrimaryKeys(PermissionImpl.class, businessObject, primaryKeys, null);
 69  0
                 } else if(NAMESPACE_CODE.equals(attributeName) || TEMPLATE_NAMESPACE_CODE.equals(attributeName)){
 70  0
                         List<String> primaryKeys = new ArrayList<String>();
 71  0
                         primaryKeys.add("code");
 72  0
                         Namespace parameterNamespace = new Namespace();
 73  0
                         parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName));
 74  0
                         return getInquiryUrlForPrimaryKeys(Namespace.class, parameterNamespace, primaryKeys, null);
 75  0
         } else if(DETAIL_OBJECTS.equals(attributeName)){
 76  
                 //return getAttributesInquiryUrl(businessObject, DETAIL_OBJECTS);
 77  0
         } else if(ASSIGNED_TO_ROLES.equals(attributeName)){
 78  0
                 return getAssignedRoleInquiryUrl(businessObject);
 79  
         }
 80  
                 
 81  0
         return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
 82  
     }
 83  
 
 84  
     protected HtmlData getAttributesInquiryUrl(BusinessObject businessObject, String attributeName){
 85  0
             List<PermissionAttributeDataImpl> permissionAttributeData = 
 86  
                     (List<PermissionAttributeDataImpl>)ObjectUtils.getPropertyValue(businessObject, attributeName);
 87  0
             List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>();
 88  0
                 List<String> primaryKeys = new ArrayList<String>();
 89  0
                 primaryKeys.add(ATTRIBUTE_DATA_ID);
 90  0
             for(PermissionAttributeDataImpl permissionAttributeDataImpl: permissionAttributeData){
 91  0
                     htmlData.add(getInquiryUrlForPrimaryKeys(PermissionAttributeDataImpl.class, permissionAttributeDataImpl, primaryKeys, 
 92  
                             getKimAttributeLabelFromDD(permissionAttributeDataImpl.getKimAttribute().getAttributeName())+
 93  
                             KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+
 94  
                             permissionAttributeDataImpl.getAttributeValue()));
 95  
             }
 96  0
             return new MultipleAnchorHtmlData(htmlData);
 97  
     }
 98  
 
 99  
     protected HtmlData getAssignedRoleInquiryUrl(BusinessObject businessObject){
 100  0
             PermissionImpl permission = (PermissionImpl)businessObject;
 101  0
             List<RoleImpl> assignedToRoles = permission.getAssignedToRoles();
 102  0
             List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>();
 103  0
                 List<String> primaryKeys = new ArrayList<String>();
 104  0
                 primaryKeys.add(ROLE_ID);
 105  0
                 if(assignedToRoles!=null && !assignedToRoles.isEmpty()){
 106  0
                         RoleService roleService = KIMServiceLocator.getRoleService();
 107  
                         KimRoleInfo roleInfo;
 108  
                         AnchorHtmlData inquiryHtmlData;
 109  0
                         for(RoleImpl roleImpl: assignedToRoles){
 110  0
                                 roleInfo = roleService.getRole(roleImpl.getRoleId());
 111  0
                                 inquiryHtmlData = getInquiryUrlForPrimaryKeys(RoleImpl.class, roleInfo, primaryKeys, 
 112  
                                         roleInfo.getNamespaceCode()+" "+
 113  
                                         roleInfo.getRoleName());
 114  0
                                 inquiryHtmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(inquiryHtmlData.getHref()));
 115  0
                                 inquiryHtmlData.setTarget(AnchorHtmlData.TARGET_BLANK);
 116  0
                         htmlData.add(inquiryHtmlData);
 117  
                 }
 118  
                 }
 119  0
             return new MultipleAnchorHtmlData(htmlData);
 120  
     }
 121  
 
 122  
 
 123  
         /**
 124  
          * This overridden method ...
 125  
          * 
 126  
          * @see org.kuali.rice.kns.inquiry.KualiInquirableImpl#getBusinessObject(java.util.Map)
 127  
          */
 128  
         @SuppressWarnings("unchecked")
 129  
         @Override
 130  
         public BusinessObject getBusinessObject(Map fieldValues) {
 131  0
                 Map<String, String> criteria = new HashMap<String, String>();
 132  0
                 criteria.put("permissionId", fieldValues.get("permissionId").toString());
 133  0
                 KimPermissionImpl permissionImpl = (KimPermissionImpl)KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(KimPermissionImpl.class, criteria);
 134  0
                 return getPermissionsSearchResultsCopy(permissionImpl);
 135  
         }
 136  
 
 137  
         public PermissionService getPermissionService() {
 138  0
                 if (permissionService == null ) {
 139  0
                         permissionService = KIMServiceLocator.getPermissionService();
 140  
                 }
 141  0
                 return permissionService;
 142  
         }
 143  
         
 144  
         private PermissionImpl getPermissionsSearchResultsCopy(KimPermissionImpl permissionSearchResult){
 145  0
                 PermissionImpl permissionSearchResultCopy = new PermissionImpl();
 146  
                 try{
 147  0
                         PropertyUtils.copyProperties(permissionSearchResultCopy, permissionSearchResult);
 148  0
                 } catch(Exception ex){
 149  
                         //TODO: remove this
 150  0
                         ex.printStackTrace();
 151  0
                 }
 152  0
                 Map<String, String> criteria = new HashMap<String, String>();
 153  0
                 criteria.put("permissionId", permissionSearchResultCopy.getPermissionId());
 154  0
                 List<RolePermissionImpl> rolePermissions = 
 155  
                         (List<RolePermissionImpl>)KNSServiceLocator.getBusinessObjectService().findMatching(RolePermissionImpl.class, criteria);
 156  0
                 List<RoleImpl> assignedToRoles = new ArrayList<RoleImpl>();
 157  0
                 for(RolePermissionImpl rolePermissionImpl: rolePermissions){
 158  0
                         assignedToRoles.add(getRoleImpl(rolePermissionImpl.getRoleId()));
 159  
                 }
 160  0
                 permissionSearchResultCopy.setAssignedToRoles(assignedToRoles);
 161  0
                 return permissionSearchResultCopy;
 162  
         }
 163  
 
 164  
 }