1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
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 | |
|
77 | |
|
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 | |
|
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 | |
|
93 | |
|
94 | |
|
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 | |
|
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 | |
|
139 | |
|
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 | |
|
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 | |
} |