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.api.KewApiConstants; |
21 | |
import org.kuali.rice.kim.api.KimConstants; |
22 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
23 | |
import org.kuali.rice.kim.api.type.KimType; |
24 | |
import org.kuali.rice.kim.framework.group.GroupTypeService; |
25 | |
import org.kuali.rice.kim.framework.role.RoleTypeService; |
26 | |
import org.kuali.rice.kim.framework.services.KimFrameworkServiceLocator; |
27 | |
import org.kuali.rice.kim.framework.type.KimTypeService; |
28 | |
import org.kuali.rice.kim.util.KimCommonUtilsInternal; |
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 | |
@SuppressWarnings("unchecked") |
75 | |
@Override |
76 | |
protected String getReturnHref(Properties parameters, LookupForm lookupForm, List returnKeys) { |
77 | 0 | KimType kimType = KimApiServiceLocator.getKimTypeInfoService().getKimType(parameters.getProperty(KimConstants.PrimaryKeyConstants.KIM_TYPE_ID)); |
78 | 0 | String href = ""; |
79 | |
|
80 | 0 | boolean showReturnHref = true; |
81 | 0 | boolean refreshMe = false; |
82 | 0 | String docTypeName = ""; |
83 | 0 | String docTypeAction = ""; |
84 | 0 | if(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY.equals(lookupForm.getFormKey())){ |
85 | 0 | docTypeName = KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_TYPE_NAME; |
86 | 0 | docTypeAction = KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_ACTION; |
87 | |
|
88 | |
|
89 | |
|
90 | 0 | showReturnHref = kimType!=null && |
91 | |
( StringUtils.isBlank( kimType.getServiceName() ) |
92 | |
|| (KimFrameworkServiceLocator.getKimTypeService(kimType) instanceof RoleTypeService |
93 | |
&&!((RoleTypeService) KimFrameworkServiceLocator.getKimTypeService(kimType)).isApplicationRoleType() ) |
94 | |
); |
95 | |
} else{ |
96 | 0 | docTypeName = KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_TYPE_NAME; |
97 | 0 | docTypeAction = KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_ACTION; |
98 | |
|
99 | 0 | refreshMe = true; |
100 | |
} |
101 | 0 | if(showReturnHref){ |
102 | 0 | if (!refreshMe){ |
103 | 0 | parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.DOC_HANDLER_METHOD); |
104 | 0 | parameters.put(KRADConstants.PARAMETER_COMMAND, KewApiConstants.INITIATE_COMMAND); |
105 | 0 | parameters.put(KRADConstants.DOCUMENT_TYPE_NAME, docTypeName); |
106 | 0 | if (StringUtils.isNotBlank(getReturnLocation())) { |
107 | 0 | parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation()); |
108 | |
} |
109 | |
} |
110 | 0 | href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+docTypeAction, parameters); |
111 | |
} |
112 | 0 | return href; |
113 | |
} |
114 | |
|
115 | |
public static boolean hasRoleTypeService(KimType kimType){ |
116 | 0 | return (kimType!=null && kimType.getServiceName()==null) || |
117 | |
(KimFrameworkServiceLocator.getKimTypeService(kimType) instanceof RoleTypeService); |
118 | |
} |
119 | |
|
120 | |
public static boolean hasRoleTypeService(KimType kimType, KimTypeService kimTypeService){ |
121 | 0 | return (kimType!=null && kimType.getServiceName()==null) || |
122 | |
(kimTypeService instanceof RoleTypeService); |
123 | |
} |
124 | |
|
125 | |
public static boolean hasGroupTypeService(KimType kimType){ |
126 | 0 | return (kimType!=null && kimType.getServiceName()==null) || |
127 | |
(KimFrameworkServiceLocator.getKimTypeService(kimType) instanceof GroupTypeService); |
128 | |
} |
129 | |
|
130 | |
public static boolean hasDerivedRoleTypeService(KimType kimType){ |
131 | 0 | boolean hasDerivedRoleTypeService = false; |
132 | 0 | KimTypeService kimTypeService = KimFrameworkServiceLocator.getKimTypeService(kimType); |
133 | |
|
134 | |
|
135 | |
try { |
136 | 0 | if(hasRoleTypeService(kimType, kimTypeService)) |
137 | 0 | hasDerivedRoleTypeService = (kimType.getServiceName()!=null && ((RoleTypeService)kimTypeService).isApplicationRoleType()); |
138 | 0 | } catch (RiceRemoteServiceConnectionException ex) { |
139 | 0 | LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Type: " + kimType.getName(), ex); |
140 | 0 | return hasDerivedRoleTypeService; |
141 | |
} |
142 | |
|
143 | 0 | catch (RemoteAccessException rae) { |
144 | 0 | LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Type: " + kimType.getName(), rae); |
145 | 0 | return hasDerivedRoleTypeService; |
146 | 0 | } |
147 | 0 | return hasDerivedRoleTypeService; |
148 | |
} |
149 | |
|
150 | |
} |