Coverage Report - org.kuali.rice.kim.impl.type.KimTypeLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KimTypeLookupableHelperServiceImpl
0%
0/51
0%
0/52
5.5
 
 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.impl.type;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.exception.RiceRemoteServiceConnectionException;
 20  
 import org.kuali.rice.kew.util.KEWConstants;
 21  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 22  
 import org.kuali.rice.kim.api.type.KimType;
 23  
 import org.kuali.rice.kim.api.type.KimTypeService;
 24  
 import org.kuali.rice.kim.framework.type.KimRoleTypeService;
 25  
 import org.kuali.rice.kim.service.KIMServiceLocatorWeb;
 26  
 import org.kuali.rice.kim.service.support.KimGroupTypeService;
 27  
 import org.kuali.rice.kim.util.KimCommonUtilsInternal;
 28  
 import org.kuali.rice.kim.util.KimConstants;
 29  
 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
 30  
 import org.kuali.rice.kns.web.struts.form.LookupForm;
 31  
 import org.kuali.rice.krad.bo.BusinessObject;
 32  
 import org.kuali.rice.krad.util.KRADConstants;
 33  
 import org.kuali.rice.krad.util.UrlFactory;
 34  
 import org.springframework.remoting.RemoteAccessException;
 35  
 
 36  
 import java.util.ArrayList;
 37  
 import java.util.List;
 38  
 import java.util.Map;
 39  
 import java.util.Properties;
 40  
 
 41  
 /**
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  *
 44  
  */
 45  0
 public class KimTypeLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
 46  
 
 47  
         private static final long serialVersionUID = 1L;
 48  
 
 49  
         @SuppressWarnings("unchecked")
 50  
         @Override
 51  
         protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) {
 52  0
                 List<KimTypeBo> searchResults = (List<KimTypeBo>)super.getSearchResultsHelper(fieldValues, unbounded);
 53  0
                 List<KimTypeBo> filteredSearchResults = new ArrayList<KimTypeBo>();
 54  0
                 if(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY.equals(fieldValues.get(KRADConstants.DOC_FORM_KEY))) {
 55  0
                         for(KimTypeBo kimTypeBo: searchResults){
 56  0
                                 if(hasRoleTypeService(KimTypeBo.to(kimTypeBo))) {
 57  0
                                         filteredSearchResults.add(kimTypeBo);
 58  
                                 }
 59  
                         }
 60  0
                         return filteredSearchResults;
 61  
                 }
 62  
                 
 63  0
                 if(KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_SHORT_KEY.equals(fieldValues.get(KRADConstants.DOC_FORM_KEY))) {
 64  0
                         for(KimTypeBo kimTypeBo: searchResults){
 65  0
                                 if(hasGroupTypeService(KimTypeBo.to(kimTypeBo))) {
 66  0
                                         filteredSearchResults.add(kimTypeBo);
 67  
                                 }
 68  
                         }
 69  0
                         return filteredSearchResults;
 70  
                 }
 71  0
                 return searchResults;
 72  
         }
 73  
         
 74  
         /**
 75  
      * @see org.kuali.rice.krad.lookup.AbstractLookupableHelperServiceImpl#getReturnUrl(org.kuali.rice.krad.bo.BusinessObject, java.util.Map,
 76  
      *      java.lang.String)
 77  
      */
 78  
     @SuppressWarnings("unchecked")
 79  
         @Override
 80  
     protected String getReturnHref(Properties parameters, LookupForm lookupForm, List returnKeys) {
 81  0
             KimType kimType = KimApiServiceLocator.getKimTypeInfoService().getKimType(parameters.getProperty(KimConstants.PrimaryKeyConstants.KIM_TYPE_ID));
 82  0
             String href = "";
 83  
             //TODO: clean this up.
 84  0
             boolean showReturnHref = true;
 85  0
             boolean refreshMe = false;
 86  0
             String docTypeName = "";
 87  0
             String docTypeAction = "";
 88  0
             if(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY.equals(lookupForm.getFormKey())){
 89  0
                     docTypeName = KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_TYPE_NAME;
 90  0
                     docTypeAction = KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_ACTION;
 91  
                     // show the create link when there is a type service AND
 92  
                     //    it has no service (default assignable role)
 93  
                     // OR it is not an application role
 94  0
                     showReturnHref = kimType!=null && 
 95  
                             ( StringUtils.isBlank( kimType.getServiceName() )
 96  
                                             || (KIMServiceLocatorWeb.getKimTypeService(kimType) instanceof KimRoleTypeService
 97  
                                                     &&!((KimRoleTypeService) KIMServiceLocatorWeb.getKimTypeService(kimType)).isApplicationRoleType() )
 98  
                                             );
 99  
             } else{
 100  0
                     docTypeName = KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_TYPE_NAME;
 101  0
                     docTypeAction = KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_ACTION;
 102  
 //                    showReturnHref = kimType!=null;
 103  0
                     refreshMe = true;
 104  
             }
 105  0
             if(showReturnHref){
 106  0
                     if (!refreshMe){
 107  0
                             parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.DOC_HANDLER_METHOD);
 108  0
                             parameters.put(KRADConstants.PARAMETER_COMMAND, KEWConstants.INITIATE_COMMAND);
 109  0
                             parameters.put(KRADConstants.DOCUMENT_TYPE_NAME, docTypeName);
 110  0
                     if (StringUtils.isNotBlank(getReturnLocation())) {
 111  0
                             parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation());
 112  
                             }
 113  
                     }
 114  0
                     href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+docTypeAction, parameters);
 115  
             }
 116  0
         return href;
 117  
     }
 118  
 
 119  
         public static boolean hasRoleTypeService(KimType kimType){
 120  0
                 return (kimType!=null && kimType.getServiceName()==null) ||
 121  
                                         (KIMServiceLocatorWeb.getKimTypeService(kimType) instanceof KimRoleTypeService);
 122  
         }
 123  
 
 124  
         public static boolean hasRoleTypeService(KimType kimType, KimTypeService kimTypeService){
 125  0
                 return (kimType!=null && kimType.getServiceName()==null) ||
 126  
                                         (kimTypeService instanceof KimRoleTypeService);
 127  
         }
 128  
         
 129  
     public static boolean hasGroupTypeService(KimType kimType){
 130  0
                 return (kimType!=null && kimType.getServiceName()==null) ||
 131  
                                         (KIMServiceLocatorWeb.getKimTypeService(kimType) instanceof KimGroupTypeService);
 132  
     }
 133  
 
 134  
         public static boolean hasDerivedRoleTypeService(KimType kimType){
 135  0
                 boolean hasDerivedRoleTypeService = false;
 136  0
                 KimTypeService kimTypeService = KIMServiceLocatorWeb.getKimTypeService(kimType);
 137  
                 //it is possible that the the roleTypeService is coming from a remote application 
 138  
             // and therefore it can't be guarenteed that it is up and working, so using a try/catch to catch this possibility.
 139  
                 try {
 140  0
                     if(hasRoleTypeService(kimType, kimTypeService))
 141  0
                         hasDerivedRoleTypeService = (kimType.getServiceName()!=null && ((KimRoleTypeService)kimTypeService).isApplicationRoleType());
 142  0
                 } catch (RiceRemoteServiceConnectionException ex) {
 143  0
                         LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Type: " + kimType.getName(), ex);
 144  0
                     return hasDerivedRoleTypeService;
 145  
                 }
 146  
                 // KULRICE-4403: catch org.springframework.remoting.RemoteAccessException
 147  0
                 catch (RemoteAccessException rae) {
 148  0
                         LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Type: " + kimType.getName(), rae);
 149  0
                         return hasDerivedRoleTypeService;
 150  0
                 }
 151  0
                 return hasDerivedRoleTypeService;
 152  
         }
 153  
 
 154  
 }