Coverage Report - org.kuali.rice.kim.service.impl.KimModuleService
 
Classes in this File Line Coverage Branch Coverage Complexity
KimModuleService
0%
0/76
0%
0/60
5.8
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.service.impl;
 17  
 
 18  
 import org.kuali.rice.kew.util.KEWConstants;
 19  
 import org.kuali.rice.kim.api.group.Group;
 20  
 import org.kuali.rice.kim.api.group.GroupService;
 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.KimTypeInfoService;
 24  
 import org.kuali.rice.kim.bo.Person;
 25  
 import org.kuali.rice.kim.bo.Role;
 26  
 import org.kuali.rice.kim.bo.reference.KimCode;
 27  
 import org.kuali.rice.kim.bo.role.dto.KimRoleInfo;
 28  
 import org.kuali.rice.kim.framework.group.GroupEbo;
 29  
 import org.kuali.rice.kim.service.PersonService;
 30  
 import org.kuali.rice.kim.service.RoleService;
 31  
 import org.kuali.rice.kim.util.KIMPropertyConstants;
 32  
 import org.kuali.rice.kim.util.KimCommonUtilsInternal;
 33  
 import org.kuali.rice.kim.util.KimConstants;
 34  
 import org.kuali.rice.kns.bo.ExternalizableBusinessObject;
 35  
 import org.kuali.rice.kns.service.impl.ModuleServiceBase;
 36  
 import org.kuali.rice.kns.util.KNSConstants;
 37  
 
 38  
 import java.util.Collections;
 39  
 import java.util.List;
 40  
 import java.util.Map;
 41  
 import java.util.Properties;
 42  
 
 43  
 /**
 44  
  * This is a description of what this class does - kellerj don't forget to fill this in.
 45  
  *
 46  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 47  
  *
 48  
  */
 49  0
 public class KimModuleService extends ModuleServiceBase {
 50  
 
 51  
         private PersonService personService;
 52  
         private RoleService kimRoleService;
 53  
         private GroupService groupService;
 54  
         private KimTypeInfoService kimTypeInfoService;
 55  
 
 56  
         /**
 57  
          * This overridden method ...
 58  
          *
 59  
          * @see org.kuali.rice.kns.service.impl.ModuleServiceBase#getExternalizableBusinessObject(java.lang.Class, java.util.Map)
 60  
          */
 61  
         @SuppressWarnings("unchecked")
 62  
         @Override
 63  
         public <T extends ExternalizableBusinessObject> T getExternalizableBusinessObject(Class<T> businessObjectClass, Map<String, Object> fieldValues) {
 64  0
                 if ( Person.class.isAssignableFrom( businessObjectClass ) ) {
 65  0
                         if ( fieldValues.containsKey( KIMPropertyConstants.Person.PRINCIPAL_ID ) ) {
 66  0
                                 return (T) getPersonService().getPerson( (String)fieldValues.get( KIMPropertyConstants.Person.PRINCIPAL_ID ) );
 67  0
                         } else if ( fieldValues.containsKey( KIMPropertyConstants.Person.PRINCIPAL_NAME ) ) {
 68  0
                                 return (T) getPersonService().getPersonByPrincipalName( (String)fieldValues.get( KIMPropertyConstants.Person.PRINCIPAL_NAME ) );
 69  
                         }
 70  
                         // otherwise, fall through since critieria is not known
 71  0
                 } else if(Role.class.isAssignableFrom(businessObjectClass)){
 72  0
                         if(fieldValues.containsKey(KimConstants.PrimaryKeyConstants.ROLE_ID)){
 73  0
                                 KimRoleInfo roleInfo = getKimRoleService().getRole((String)fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_ID));
 74  
                                 //RoleImpl roleImpl
 75  0
                                 return (T) roleInfo;
 76  
                         }
 77  0
                 } else if(Group.class.isAssignableFrom(businessObjectClass)){
 78  0
                         if(fieldValues.containsKey(KimConstants.PrimaryKeyConstants.GROUP_ID)) {
 79  0
                 Group group = getGroupService().getGroup((String)fieldValues.get(KimConstants.PrimaryKeyConstants.GROUP_ID));
 80  0
                                 return (T) GroupEbo.from(group);
 81  
                         }
 82  
 //                } else if(KimType.class.isAssignableFrom(businessObjectClass)){
 83  
 //                        if(fieldValues.containsKey(KimConstants.PrimaryKeyConstants.KIM_TYPE_ID)) {
 84  
 //                                return (T) getTypeInfoService().getKimType((String)fieldValues.get(KimConstants.PrimaryKeyConstants.KIM_TYPE_ID));
 85  
 //                        }
 86  
                 }
 87  
                 // otherwise, use the default implementation
 88  0
                 return super.getExternalizableBusinessObject( businessObjectClass, fieldValues );
 89  
         }
 90  
 
 91  
         /**
 92  
          * This overridden method ...
 93  
          *
 94  
          * @see org.kuali.rice.kns.service.impl.ModuleServiceBase#getExternalizableBusinessObjectsList(java.lang.Class, java.util.Map)
 95  
          */
 96  
         @SuppressWarnings("unchecked")
 97  
         @Override
 98  
         public <T extends ExternalizableBusinessObject> List<T> getExternalizableBusinessObjectsList(
 99  
                         Class<T> externalizableBusinessObjectClass, Map<String, Object> fieldValues) {
 100  
                 // for Person objects (which are not real PersistableBOs) pull them through the person service
 101  0
                 if ( Person.class.isAssignableFrom( externalizableBusinessObjectClass ) ) {
 102  0
                         return (List)getPersonService().findPeople( (Map)fieldValues );
 103  0
                 } else if ( Role.class.isAssignableFrom( externalizableBusinessObjectClass ) ) {
 104  0
                         return (List)getKimRoleService().getRolesSearchResults((Map)fieldValues );
 105  0
                 } else if ( Group.class.isAssignableFrom(externalizableBusinessObjectClass) ) {
 106  0
                         return (List)getGroupService().lookupGroups( (Map)fieldValues );
 107  
                 }
 108  
                 // otherwise, use the default implementation
 109  0
                 return super.getExternalizableBusinessObjectsList( externalizableBusinessObjectClass, fieldValues );
 110  
         }
 111  
 
 112  
         /***
 113  
          * @see org.kuali.rice.kns.service.ModuleService#getExternalizableBusinessObjectsListForLookup(java.lang.Class, java.util.Map, boolean)
 114  
          */
 115  
         @SuppressWarnings("unchecked")
 116  
         @Override
 117  
         public <T extends ExternalizableBusinessObject> List<T> getExternalizableBusinessObjectsListForLookup(
 118  
                         Class<T> externalizableBusinessObjectClass, Map<String, Object> fieldValues, boolean unbounded) {
 119  
                 // for Person objects (which are not real PersistableBOs) pull them through the person service
 120  0
                 if ( Person.class.isAssignableFrom( externalizableBusinessObjectClass ) ) {
 121  0
                         return (List)getPersonService().findPeople( (Map)fieldValues, unbounded );
 122  0
                 } else if ( Role.class.isAssignableFrom( externalizableBusinessObjectClass ) ) {
 123  
                         // FIXME: needs to send unbounded flag
 124  0
                         return (List)getKimRoleService().getRolesSearchResults((Map)fieldValues );
 125  
                 }
 126  
                 // otherwise, use the default implementation
 127  0
                 return super.getExternalizableBusinessObjectsListForLookup(externalizableBusinessObjectClass, fieldValues, unbounded);
 128  
         }
 129  
 
 130  
         /**
 131  
          * This overridden method ...
 132  
          *
 133  
          * @see org.kuali.rice.kns.service.impl.ModuleServiceBase#listPrimaryKeyFieldNames(java.lang.Class)
 134  
          */
 135  
         @SuppressWarnings("unchecked")
 136  
         @Override
 137  
         public List listPrimaryKeyFieldNames(Class businessObjectInterfaceClass) {
 138  
                 // for Person objects (which are not real PersistableBOs) pull them through the person service
 139  0
                 if ( Person.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
 140  0
                         return Collections.singletonList( KimConstants.PrimaryKeyConstants.PRINCIPAL_ID );
 141  0
                 } else if ( Role.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
 142  0
                         return Collections.singletonList( KimConstants.PrimaryKeyConstants.ROLE_ID );
 143  0
                 } else if ( Group.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
 144  0
                         return Collections.singletonList( KimConstants.PrimaryKeyConstants.GROUP_ID );
 145  0
                 } else if ( KimType.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
 146  0
                         return Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID );
 147  0
                 } else if ( KimCode.class.isAssignableFrom(businessObjectInterfaceClass)) {
 148  0
                         return Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_CODE );
 149  
                 }
 150  
 
 151  
                 // otherwise, use the default implementation
 152  0
                 return super.listPrimaryKeyFieldNames( businessObjectInterfaceClass );
 153  
         }
 154  
 
 155  
         @SuppressWarnings("unchecked")
 156  
         protected PersonService getPersonService() {
 157  0
                 if ( personService == null ) {
 158  0
                         personService = KimApiServiceLocator.getPersonService();
 159  
                 }
 160  0
                 return personService;
 161  
         }
 162  
 
 163  
         protected RoleService getKimRoleService() {
 164  0
                 if ( kimRoleService == null ) {
 165  0
                         kimRoleService = KimApiServiceLocator.getRoleManagementService();
 166  
                 }
 167  0
                 return kimRoleService;
 168  
         }
 169  
 
 170  
         protected GroupService getGroupService() {
 171  0
                 if ( groupService == null ) {
 172  0
                         groupService = KimApiServiceLocator.getGroupService();
 173  
                 }
 174  0
                 return groupService;
 175  
         }
 176  
 
 177  
         protected KimTypeInfoService getTypeInfoService() {
 178  0
                 if(kimTypeInfoService == null){
 179  0
                         kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService();
 180  
                 }
 181  0
                 return kimTypeInfoService;
 182  
         }
 183  
 
 184  
         protected Properties getUrlParameters(String businessObjectClassAttribute, Map<String, String[]> parameters){
 185  0
                 Properties urlParameters = new Properties();
 186  0
                 for (String paramName : parameters.keySet()) {
 187  0
                         String[] parameterValues = parameters.get(paramName);
 188  0
                         if (parameterValues.length > 0) {
 189  0
                                 urlParameters.put(paramName, parameterValues[0]);
 190  
                         }
 191  0
                 }
 192  0
                 urlParameters.put(KNSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, businessObjectClassAttribute);
 193  
                 try{
 194  0
                         Class inquiryBusinessObjectClass = Class.forName(businessObjectClassAttribute);
 195  0
                         if(Role.class.isAssignableFrom(inquiryBusinessObjectClass) || 
 196  
                                         Group.class.isAssignableFrom(inquiryBusinessObjectClass) || 
 197  
                                         Person.class.isAssignableFrom(inquiryBusinessObjectClass)) {
 198  0
                         urlParameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY);                        
 199  
                         } else{
 200  0
                         urlParameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.CONTINUE_WITH_INQUIRY_METHOD_TO_CALL);
 201  
                         }
 202  0
                 } catch(Exception eix){
 203  0
                         urlParameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.CONTINUE_WITH_INQUIRY_METHOD_TO_CALL);
 204  0
                 }
 205  0
         urlParameters.put(KNSConstants.PARAMETER_COMMAND, KEWConstants.INITIATE_COMMAND);
 206  0
                 return urlParameters;
 207  
         }
 208  
 
 209  
         @Override
 210  
         protected String getInquiryUrl(Class inquiryBusinessObjectClass){
 211  0
                 String inquiryUrl = KimCommonUtilsInternal.getKimBasePath();
 212  0
                 if (!inquiryUrl.endsWith("/")) {
 213  0
                         inquiryUrl = inquiryUrl + "/";
 214  
                 }
 215  0
                 if(Role.class.isAssignableFrom(inquiryBusinessObjectClass)) {
 216  0
                         return inquiryUrl + KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_ACTION;
 217  0
                 } else if(Group.class.isAssignableFrom(inquiryBusinessObjectClass)) {
 218  0
                         return inquiryUrl + KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_ACTION;
 219  0
                 } else if(Person.class.isAssignableFrom(inquiryBusinessObjectClass)) {
 220  0
                         return inquiryUrl + KimConstants.KimUIConstants.KIM_PERSON_INQUIRY_ACTION;
 221  
                 }
 222  0
                 return super.getInquiryUrl(inquiryBusinessObjectClass);
 223  
         }
 224  
 
 225  
 }