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