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