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