| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 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 | |
|
| 76 | |
|
| 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 | |
|
| 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 | |
|
| 92 | |
|
| 93 | |
|
| 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 | |
|
| 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 | |
|
| 138 | |
|
| 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 | |
|
| 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 | |
} |