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 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 | |
|
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 | |
|
76 | |
|
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 | |
|
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.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 | |
|
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 | |
|
135 | |
|
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 | |
|
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 | |
} |