Coverage Report - org.kuali.rice.kim.lookup.KimTypeLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KimTypeLookupableHelperServiceImpl
0%
0/49
0%
0/50
5.333
 
 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 java.util.ArrayList;
 19  
 import java.util.List;
 20  
 import java.util.Map;
 21  
 import java.util.Properties;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.kuali.rice.core.exception.RiceRemoteServiceConnectionException;
 25  
 import org.kuali.rice.kew.util.KEWConstants;
 26  
 import org.kuali.rice.kim.bo.KimType;
 27  
 import org.kuali.rice.kim.bo.types.dto.KimTypeInfo;
 28  
 import org.kuali.rice.kim.bo.types.impl.KimTypeImpl;
 29  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 30  
 import org.kuali.rice.kim.service.support.KimGroupTypeService;
 31  
 import org.kuali.rice.kim.service.support.KimRoleTypeService;
 32  
 import org.kuali.rice.kim.service.support.KimTypeService;
 33  
 import org.kuali.rice.kim.util.KimCommonUtils;
 34  
 import org.kuali.rice.kim.util.KimConstants;
 35  
 import org.kuali.rice.kns.bo.BusinessObject;
 36  
 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
 37  
 import org.kuali.rice.kns.util.KNSConstants;
 38  
 import org.kuali.rice.kns.util.UrlFactory;
 39  
 import org.kuali.rice.kns.web.struts.form.LookupForm;
 40  
 import org.springframework.remoting.RemoteAccessException;
 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  
         protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) {
 52  0
                 List<KimTypeImpl> searchResults = (List<KimTypeImpl>)super.getSearchResultsHelper(fieldValues, unbounded);
 53  0
                 List<KimTypeImpl> filteredSearchResults = new ArrayList<KimTypeImpl>();
 54  0
                 if(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY.equals(fieldValues.get(KNSConstants.DOC_FORM_KEY))) {
 55  0
                         for(KimTypeImpl kimTypeImpl: searchResults){
 56  0
                                 if(hasRoleTypeService(kimTypeImpl.toInfo())) {
 57  0
                                         filteredSearchResults.add(kimTypeImpl);
 58  
                                 }
 59  
                         }
 60  0
                         return filteredSearchResults;
 61  
                 }
 62  
                 
 63  0
                 if(KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_SHORT_KEY.equals(fieldValues.get(KNSConstants.DOC_FORM_KEY))) {
 64  0
                         for(KimTypeImpl kimTypeImpl: searchResults){
 65  0
                                 if(hasGroupTypeService(kimTypeImpl.toInfo())) {
 66  0
                                         filteredSearchResults.add(kimTypeImpl);
 67  
                                 }
 68  
                         }
 69  0
                         return filteredSearchResults;
 70  
                 }
 71  0
                 return searchResults;
 72  
         }
 73  
         
 74  
         /**
 75  
      * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getReturnUrl(org.kuali.rice.kns.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
             KimTypeInfo kimType = KIMServiceLocator.getTypeInfoService().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.getKimTypeServiceName() )
 96  
                                             || (KimCommonUtils.getKimTypeService(kimType) instanceof KimRoleTypeService
 97  
                                                     &&!((KimRoleTypeService)KimCommonUtils.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(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.DOC_HANDLER_METHOD);
 108  0
                             parameters.put(KNSConstants.PARAMETER_COMMAND, KEWConstants.INITIATE_COMMAND);
 109  0
                             parameters.put(KNSConstants.DOCUMENT_TYPE_NAME, docTypeName);
 110  
                     }
 111  0
                     href = UrlFactory.parameterizeUrl(KimCommonUtils.getKimBasePath()+docTypeAction, parameters);
 112  
             }
 113  0
         return href;
 114  
     }
 115  
 
 116  
         static boolean hasRoleTypeService(KimType kimType){
 117  0
                 return (kimType!=null && kimType.getKimTypeServiceName()==null) || 
 118  
                                         (KimCommonUtils.getKimTypeService(kimType) instanceof KimRoleTypeService);
 119  
         }
 120  
 
 121  
         static boolean hasRoleTypeService(KimType kimType, KimTypeService kimTypeService){
 122  0
                 return (kimType!=null && kimType.getKimTypeServiceName()==null) || 
 123  
                                         (kimTypeService instanceof KimRoleTypeService);
 124  
         }
 125  
         
 126  
     static boolean hasGroupTypeService(KimType kimType){
 127  0
                 return (kimType!=null && kimType.getKimTypeServiceName()==null) || 
 128  
                                         (KimCommonUtils.getKimTypeService(kimType) instanceof KimGroupTypeService);
 129  
     }
 130  
 
 131  
         public static boolean hasDerivedRoleTypeService(KimType kimType){
 132  0
                 boolean hasDerivedRoleTypeService = false;
 133  0
                 KimTypeService kimTypeService = KimCommonUtils.getKimTypeService(kimType);
 134  
                 //it is possible that the the roleTypeService is coming from a remote application 
 135  
             // and therefore it can't be guarenteed that it is up and working, so using a try/catch to catch this possibility.
 136  
                 try {
 137  0
                     if(hasRoleTypeService(kimType, kimTypeService))
 138  0
                         hasDerivedRoleTypeService = (kimType.getKimTypeServiceName()!=null && ((KimRoleTypeService)kimTypeService).isApplicationRoleType());
 139  0
                 } catch (RiceRemoteServiceConnectionException ex) {
 140  0
                         LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Type: " + kimType.getName(), ex);
 141  0
                     return hasDerivedRoleTypeService;
 142  
                 }
 143  
                 // KULRICE-4403: catch org.springframework.remoting.RemoteAccessException
 144  0
                 catch (RemoteAccessException rae) {
 145  0
                         LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Type: " + kimType.getName(), rae);
 146  0
                         return hasDerivedRoleTypeService;
 147  0
                 }
 148  0
                 return hasDerivedRoleTypeService;
 149  
         }
 150  
 
 151  
 }