Coverage Report - org.kuali.rice.kim.impl.responsibility.ResponsibilityInquirableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ResponsibilityInquirableImpl
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 responsibilitys and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kim.impl.responsibility;
 17  
 
 18  
 import org.apache.commons.beanutils.PropertyUtils;
 19  
 import org.kuali.rice.core.impl.namespace.NamespaceBo;
 20  
 import org.kuali.rice.kim.api.responsibility.ResponsibilityService;
 21  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 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.RoleResponsibilityImpl;
 25  
 import org.kuali.rice.kim.impl.responsibility.ResponsibilityAttributeBo;
 26  
 import org.kuali.rice.kim.impl.responsibility.ResponsibilityBo;
 27  
 import org.kuali.rice.kim.impl.responsibility.UberResponsibilityBo;
 28  
 import org.kuali.rice.kim.impl.role.RoleBo;
 29  
 import org.kuali.rice.kim.inquiry.RoleMemberInquirableImpl;
 30  
 import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl;
 31  
 import org.kuali.rice.kim.service.RoleService;
 32  
 import org.kuali.rice.kim.util.KimConstants;
 33  
 import org.kuali.rice.kns.bo.BusinessObject;
 34  
 import org.kuali.rice.kns.lookup.HtmlData;
 35  
 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
 36  
 import org.kuali.rice.kns.lookup.HtmlData.MultipleAnchorHtmlData;
 37  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 38  
 import org.kuali.rice.kns.uif.widget.Inquiry;
 39  
 import org.kuali.rice.kns.util.ObjectUtils;
 40  
 
 41  
 import java.util.ArrayList;
 42  
 import java.util.Collections;
 43  
 import java.util.HashMap;
 44  
 import java.util.List;
 45  
 import java.util.Map;
 46  
 
 47  0
 public class ResponsibilityInquirableImpl extends RoleMemberInquirableImpl {
 48  
 
 49  0
         protected final String KIM_RESPONSIBILITY_REQUIRED_ATTRIBUTE_ID = "kimResponsibilityRequiredAttributeId";
 50  0
         protected final String RESPONSIBILITY_ID = "responsibilityId";
 51  
         transient private static ResponsibilityService responsibilityService;
 52  
 
 53  
         @Override
 54  
         public void buildInquirableLink(Object dataObject, String propertyName, Inquiry inquiry){
 55  
 
 56  0
                 if(NAME.equals(propertyName) || NAME_TO_DISPLAY.equals(propertyName)){
 57  0
                         Map<String, String> primaryKeys = new HashMap<String, String>();
 58  0
                         primaryKeys.put(RESPONSIBILITY_ID, RESPONSIBILITY_ID);
 59  0
                         inquiry.buildInquiryLink(dataObject, propertyName, UberResponsibilityBo.class, primaryKeys);
 60  0
             } else if(NAMESPACE_CODE.equals(propertyName) || TEMPLATE_NAMESPACE_CODE.equals(propertyName)){
 61  0
                     Map<String, String> primaryKeys = new HashMap<String, String>();
 62  0
                         primaryKeys.put(propertyName, "code");
 63  0
                         inquiry.buildInquiryLink(dataObject, propertyName, NamespaceBo.class, primaryKeys);
 64  0
         } else if(DETAIL_OBJECTS.equals(propertyName)){
 65  
                 //return getAttributesInquiryUrl(businessObject, DETAIL_OBJECTS);
 66  0
                 super.buildInquirableLink(dataObject, propertyName, inquiry);
 67  0
         } else if(ASSIGNED_TO_ROLES.equals(propertyName)){
 68  
 //                return getAssignedRoleInquiryUrl(dataObject);
 69  0
                 super.buildInquirableLink(dataObject, propertyName, inquiry);
 70  
         }else{
 71  0
                 super.buildInquirableLink(dataObject, propertyName, inquiry);
 72  
         }
 73  0
         }
 74  
 
 75  
     @Override
 76  
     public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
 77  
             /*
 78  
              *  - responsibility detail values (attribute name and value separated by colon, commas between attributes)
 79  
                  *        - required role qualifiers (attribute name and value separated by colon, commas between attributes)
 80  
                  *        - list of roles assigned: role type, role namespace, role name
 81  
              */
 82  0
             if(NAME.equals(attributeName) || NAME_TO_DISPLAY.equals(attributeName)){
 83  0
                         List<String> primaryKeys = new ArrayList<String>();
 84  0
                         primaryKeys.add(RESPONSIBILITY_ID);
 85  0
                         return getInquiryUrlForPrimaryKeys(UberResponsibilityBo.class, businessObject, primaryKeys, null);
 86  0
             } else if(NAMESPACE_CODE.equals(attributeName) || TEMPLATE_NAMESPACE_CODE.equals(attributeName)){
 87  0
                         List<String> primaryKeys = new ArrayList<String>();
 88  0
                         primaryKeys.add("code");
 89  0
                         NamespaceBo parameterNamespace = new NamespaceBo();
 90  0
                         parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName));
 91  0
                         return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null);
 92  0
         } else if(DETAIL_OBJECTS.equals(attributeName)){
 93  
                 //return getAttributesInquiryUrl(businessObject, DETAIL_OBJECTS);
 94  0
         } else if(ASSIGNED_TO_ROLES.equals(attributeName)){
 95  0
                 return getAssignedRoleInquiryUrl(businessObject);
 96  
         }
 97  
 
 98  0
         return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
 99  
     }
 100  
 
 101  
     @SuppressWarnings("unchecked")
 102  
         protected HtmlData getAttributesInquiryUrl(BusinessObject businessObject, String attributeName){
 103  0
             List<ResponsibilityAttributeBo> responsibilityAttributeData =
 104  
                     (List<ResponsibilityAttributeBo>)ObjectUtils.getPropertyValue(businessObject, attributeName);
 105  0
             List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>();
 106  0
                 List<String> primaryKeys = new ArrayList<String>();
 107  0
                 primaryKeys.add(ATTRIBUTE_DATA_ID);
 108  0
             for(ResponsibilityAttributeBo responsibilityAttributeDataImpl: responsibilityAttributeData){
 109  0
                     htmlData.add(getInquiryUrlForPrimaryKeys(ResponsibilityAttributeBo.class, responsibilityAttributeDataImpl, primaryKeys,
 110  
                             getKimAttributeLabelFromDD(responsibilityAttributeDataImpl.getKimAttribute().getAttributeName())+KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+
 111  
                             responsibilityAttributeDataImpl.getAttributeValue()));
 112  
             }
 113  0
             return new MultipleAnchorHtmlData(htmlData);
 114  
     }
 115  
 
 116  
     @SuppressWarnings("unchecked")
 117  
         protected HtmlData getAssignedRoleInquiryUrl(BusinessObject businessObject){
 118  0
             UberResponsibilityBo responsibility = (UberResponsibilityBo)businessObject;
 119  0
             List<RoleBo> assignedToRoles = responsibility.getAssignedToRoles();
 120  0
             List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>();
 121  0
                 if(assignedToRoles!=null && !assignedToRoles.isEmpty()){
 122  0
                         List<String> primaryKeys = Collections.singletonList(ROLE_ID);
 123  0
                         RoleService roleService = KimApiServiceLocator.getRoleService();
 124  0
                         for(RoleBo roleImpl: assignedToRoles){
 125  0
                                 KimRoleInfo roleInfo = roleService.getRole(roleImpl.getId());
 126  0
                                 AnchorHtmlData inquiryHtmlData = getInquiryUrlForPrimaryKeys(RoleImpl.class, roleInfo, primaryKeys,
 127  
                                         roleInfo.getNamespaceCode()+" "+
 128  
                                         roleInfo.getRoleName());
 129  0
                                 inquiryHtmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(inquiryHtmlData.getHref()));
 130  0
                         htmlData.add(inquiryHtmlData);
 131  0
                 }
 132  
                 }
 133  0
             return new MultipleAnchorHtmlData(htmlData);
 134  
     }
 135  
 
 136  
     @Override
 137  
         public Object getDataObject(Map fieldValues){
 138  0
             return getBusinessObject(fieldValues);
 139  
     }
 140  
 
 141  
         /**
 142  
          * This overridden method ...
 143  
          *
 144  
          * @see org.kuali.rice.kns.inquiry.KualiInquirableImpl#getBusinessObject(java.util.Map)
 145  
          */
 146  
         @SuppressWarnings("unchecked")
 147  
         @Override
 148  
         public BusinessObject getBusinessObject(Map fieldValues) {
 149  0
                 Map<String, String> criteria = new HashMap<String, String>();
 150  0
                 criteria.put("responsibilityId", fieldValues.get("responsibilityId").toString());
 151  0
                 ResponsibilityBo responsibilityImpl = KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(ResponsibilityBo.class, criteria);
 152  0
                 return getResponsibilitiesSearchResultsCopy(responsibilityImpl);
 153  
         }
 154  
 
 155  
         public ResponsibilityService getResponsibilityService() {
 156  0
                 if (responsibilityService == null ) {
 157  0
                         responsibilityService = KimApiServiceLocator.getResponsibilityService();
 158  
                 }
 159  0
                 return responsibilityService;
 160  
         }
 161  
 
 162  
         @SuppressWarnings("unchecked")
 163  
         private ResponsibilityBo getResponsibilitiesSearchResultsCopy(ResponsibilityBo responsibilitySearchResult){
 164  0
                 UberResponsibilityBo responsibilitySearchResultCopy = new UberResponsibilityBo();
 165  
                 try{
 166  0
                         PropertyUtils.copyProperties(responsibilitySearchResultCopy, responsibilitySearchResult);
 167  0
                 } catch(Exception ex){
 168  
                         //TODO: remove this
 169  0
                         ex.printStackTrace();
 170  0
                 }
 171  0
                 Map<String, String> criteria = new HashMap<String, String>();
 172  0
                 criteria.put("id", responsibilitySearchResultCopy.getId());
 173  0
                 List<RoleResponsibilityImpl> roleResponsibilitys =
 174  
                         (List<RoleResponsibilityImpl>) KNSServiceLocator.getBusinessObjectService().findMatching(RoleResponsibilityImpl.class, criteria);
 175  0
                 List<RoleBo> assignedToRoles = new ArrayList<RoleBo>();
 176  0
                 for(RoleResponsibilityImpl roleResponsibilityImpl: roleResponsibilitys){
 177  0
                         assignedToRoles.add(getRoleImpl(roleResponsibilityImpl.getRoleId()));
 178  
                 }
 179  0
                 responsibilitySearchResultCopy.setAssignedToRoles(assignedToRoles);
 180  0
                 return responsibilitySearchResultCopy;
 181  
         }
 182  
 
 183  
 }