1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.service.impl; |
17 | |
|
18 | |
import org.kuali.rice.core.api.criteria.Predicate; |
19 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
20 | |
import org.kuali.rice.kew.api.KewApiConstants; |
21 | |
import org.kuali.rice.kim.api.KimConstants; |
22 | |
import org.kuali.rice.kim.api.group.Group; |
23 | |
import org.kuali.rice.kim.api.group.GroupContract; |
24 | |
import org.kuali.rice.kim.api.group.GroupService; |
25 | |
import org.kuali.rice.kim.api.identity.CodedAttribute; |
26 | |
import org.kuali.rice.kim.api.identity.IdentityService; |
27 | |
import org.kuali.rice.kim.api.identity.Person; |
28 | |
import org.kuali.rice.kim.api.identity.PersonService; |
29 | |
import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationType; |
30 | |
import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierType; |
31 | |
import org.kuali.rice.kim.api.role.Role; |
32 | |
import org.kuali.rice.kim.api.role.RoleContract; |
33 | |
import org.kuali.rice.kim.api.role.RoleService; |
34 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
35 | |
import org.kuali.rice.kim.api.type.KimType; |
36 | |
import org.kuali.rice.kim.api.type.KimTypeContract; |
37 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService; |
38 | |
import org.kuali.rice.kim.framework.group.GroupEbo; |
39 | |
import org.kuali.rice.kim.framework.identity.EntityTypeEbo; |
40 | |
import org.kuali.rice.kim.framework.identity.address.EntityAddressTypeEbo; |
41 | |
import org.kuali.rice.kim.framework.identity.affiliation.EntityAffiliationTypeEbo; |
42 | |
import org.kuali.rice.kim.framework.identity.citizenship.EntityCitizenshipStatusEbo; |
43 | |
import org.kuali.rice.kim.framework.identity.email.EntityEmailTypeContractEbo; |
44 | |
import org.kuali.rice.kim.framework.identity.email.EntityEmailTypeEbo; |
45 | |
import org.kuali.rice.kim.framework.identity.employment.EntityEmploymentStatusEbo; |
46 | |
import org.kuali.rice.kim.framework.identity.employment.EntityEmploymentTypeEbo; |
47 | |
import org.kuali.rice.kim.framework.identity.external.EntityExternalIdentifierTypeEbo; |
48 | |
import org.kuali.rice.kim.framework.identity.name.EntityNameTypeEbo; |
49 | |
import org.kuali.rice.kim.framework.identity.phone.EntityPhoneTypeEbo; |
50 | |
import org.kuali.rice.kim.framework.role.RoleEbo; |
51 | |
import org.kuali.rice.kim.impl.KIMPropertyConstants; |
52 | |
import org.kuali.rice.kim.impl.group.GroupBo; |
53 | |
import org.kuali.rice.kim.impl.role.RoleBo; |
54 | |
import org.kuali.rice.kim.util.KimCommonUtilsInternal; |
55 | |
import org.kuali.rice.krad.bo.ExternalizableBusinessObject; |
56 | |
import org.kuali.rice.krad.service.impl.ModuleServiceBase; |
57 | |
import org.kuali.rice.krad.util.KRADConstants; |
58 | |
|
59 | |
import java.util.ArrayList; |
60 | |
import java.util.Collections; |
61 | |
import java.util.HashSet; |
62 | |
import java.util.List; |
63 | |
import java.util.Map; |
64 | |
import java.util.Properties; |
65 | |
import java.util.Set; |
66 | |
|
67 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.equal; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 0 | public class KimModuleService extends ModuleServiceBase { |
76 | |
|
77 | |
private PersonService personService; |
78 | |
private RoleService kimRoleService; |
79 | |
private GroupService groupService; |
80 | |
private IdentityService identityService; |
81 | |
private KimTypeInfoService kimTypeInfoService; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
@SuppressWarnings("unchecked") |
89 | |
@Override |
90 | |
public <T extends ExternalizableBusinessObject> T getExternalizableBusinessObject(Class<T> businessObjectClass, Map<String, Object> fieldValues) { |
91 | 0 | if ( Person.class.isAssignableFrom( businessObjectClass ) ) { |
92 | 0 | if ( fieldValues.containsKey( KIMPropertyConstants.Person.PRINCIPAL_ID ) ) { |
93 | 0 | return (T) getPersonService().getPerson( (String)fieldValues.get( KIMPropertyConstants.Person.PRINCIPAL_ID ) ); |
94 | 0 | } else if ( fieldValues.containsKey( KIMPropertyConstants.Person.PRINCIPAL_NAME ) ) { |
95 | 0 | return (T) getPersonService().getPersonByPrincipalName( (String)fieldValues.get( KIMPropertyConstants.Person.PRINCIPAL_NAME ) ); |
96 | |
} |
97 | |
|
98 | 0 | } else if(RoleContract.class.isAssignableFrom(businessObjectClass)){ |
99 | 0 | if(fieldValues.containsKey(KimConstants.PrimaryKeyConstants.ROLE_ID)){ |
100 | 0 | Role role = getKimRoleService().getRole((String)fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_ID)); |
101 | 0 | return (T) RoleEbo.from(role); |
102 | |
} |
103 | 0 | } else if(GroupContract.class.isAssignableFrom(businessObjectClass)){ |
104 | 0 | if(fieldValues.containsKey(KimConstants.PrimaryKeyConstants.GROUP_ID)) { |
105 | 0 | Group group = getGroupService().getGroup((String)fieldValues.get(KimConstants.PrimaryKeyConstants.GROUP_ID)); |
106 | 0 | return (T) GroupEbo.from(group); |
107 | |
} |
108 | 0 | } else if (EntityEmailTypeEbo.class.isAssignableFrom(businessObjectClass)) { |
109 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
110 | 0 | CodedAttribute codedAttribute = getIdentityService() |
111 | |
.getEmailType((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
112 | 0 | return (T)EntityEmailTypeEbo.from(codedAttribute); |
113 | |
} |
114 | 0 | } else if (EntityAddressTypeEbo.class.isAssignableFrom(businessObjectClass)) { |
115 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
116 | 0 | CodedAttribute codedAttribute = getIdentityService() |
117 | |
.getAddressType((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
118 | 0 | return (T)EntityAddressTypeEbo.from(codedAttribute); |
119 | |
} |
120 | 0 | } else if (EntityAffiliationTypeEbo.class.isAssignableFrom(businessObjectClass)) { |
121 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
122 | 0 | EntityAffiliationType codedAttribute = getIdentityService() |
123 | |
.getAffiliationType((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
124 | 0 | return (T)EntityAffiliationTypeEbo.from(codedAttribute); |
125 | |
} |
126 | 0 | } else if (EntityCitizenshipStatusEbo.class.isAssignableFrom(businessObjectClass)) { |
127 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
128 | 0 | CodedAttribute codedAttribute = getIdentityService() |
129 | |
.getCitizenshipStatus((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
130 | 0 | return (T)EntityCitizenshipStatusEbo.from(codedAttribute); |
131 | |
} |
132 | 0 | } else if (EntityEmploymentStatusEbo.class.isAssignableFrom(businessObjectClass)) { |
133 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
134 | 0 | CodedAttribute codedAttribute = getIdentityService() |
135 | |
.getEmploymentStatus((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
136 | 0 | return (T)EntityEmploymentStatusEbo.from(codedAttribute); |
137 | |
} |
138 | 0 | } else if (EntityEmploymentTypeEbo.class.isAssignableFrom(businessObjectClass)) { |
139 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
140 | 0 | CodedAttribute codedAttribute = getIdentityService() |
141 | |
.getEmploymentType((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
142 | 0 | return (T)EntityEmploymentTypeEbo.from(codedAttribute); |
143 | |
} |
144 | 0 | } else if (EntityNameTypeEbo.class.isAssignableFrom(businessObjectClass)) { |
145 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
146 | 0 | CodedAttribute codedAttribute = getIdentityService() |
147 | |
.getNameType((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
148 | 0 | return (T)EntityNameTypeEbo.from(codedAttribute); |
149 | |
} |
150 | 0 | } else if (EntityTypeEbo.class.isAssignableFrom(businessObjectClass)) { |
151 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
152 | 0 | CodedAttribute codedAttribute = getIdentityService() |
153 | |
.getEntityType((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
154 | 0 | return (T)EntityTypeEbo.from(codedAttribute); |
155 | |
} |
156 | 0 | } else if (EntityExternalIdentifierTypeEbo.class.isAssignableFrom(businessObjectClass)) { |
157 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
158 | 0 | EntityExternalIdentifierType codedAttribute = getIdentityService() |
159 | |
.getExternalIdentifierType((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
160 | 0 | return (T)EntityExternalIdentifierTypeEbo.from(codedAttribute); |
161 | |
} |
162 | 0 | } else if (EntityPhoneTypeEbo.class.isAssignableFrom(businessObjectClass)) { |
163 | 0 | if (fieldValues.containsKey(KimConstants.PrimaryKeyConstants.CODE)) { |
164 | 0 | CodedAttribute codedAttribute = getIdentityService() |
165 | |
.getPhoneType((String) fieldValues.get(KimConstants.PrimaryKeyConstants.CODE)); |
166 | 0 | return (T)EntityPhoneTypeEbo.from(codedAttribute); |
167 | |
} |
168 | |
} |
169 | |
|
170 | 0 | return super.getExternalizableBusinessObject( businessObjectClass, fieldValues ); |
171 | |
} |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
@SuppressWarnings("unchecked") |
179 | |
@Override |
180 | |
public <T extends ExternalizableBusinessObject> List<T> getExternalizableBusinessObjectsList( |
181 | |
Class<T> externalizableBusinessObjectClass, Map<String, Object> fieldValues) { |
182 | |
|
183 | |
|
184 | 0 | if ( Person.class.isAssignableFrom( externalizableBusinessObjectClass ) ) { |
185 | 0 | return (List)getPersonService().findPeople( (Map)fieldValues ); |
186 | |
} |
187 | 0 | else if ( RoleContract.class.isAssignableFrom( externalizableBusinessObjectClass ) ) { |
188 | 0 | List<Role> roles = getKimRoleService().findRoles(toQuery(fieldValues)).getResults(); |
189 | 0 | List<RoleEbo> roleEbos = new ArrayList<RoleEbo>(roles.size()); |
190 | 0 | for (Role role : roles) { |
191 | 0 | roleEbos.add(RoleEbo.from(role)); |
192 | |
} |
193 | 0 | return (List<T>)roleEbos; |
194 | 0 | } else if ( GroupContract.class.isAssignableFrom(externalizableBusinessObjectClass) ) { |
195 | 0 | List<Group> groups = getGroupService().findGroups(toQuery(fieldValues)).getResults(); |
196 | 0 | List<GroupEbo> groupEbos = new ArrayList<GroupEbo>(groups.size()); |
197 | 0 | for (Group group : groups) { |
198 | 0 | groupEbos.add(GroupEbo.from(group)); |
199 | |
} |
200 | 0 | return (List<T>)groupEbos; |
201 | |
} |
202 | |
|
203 | 0 | return super.getExternalizableBusinessObjectsList( externalizableBusinessObjectClass, fieldValues ); |
204 | |
} |
205 | |
|
206 | |
private QueryByCriteria toQuery(Map<String,?> fieldValues) { |
207 | 0 | Set<Predicate> preds = new HashSet<Predicate>(); |
208 | 0 | for (String key : fieldValues.keySet()) { |
209 | 0 | preds.add(equal(key, fieldValues.get(key))); |
210 | |
} |
211 | 0 | Predicate[] predicates = new Predicate[0]; |
212 | 0 | predicates = preds.toArray(predicates); |
213 | 0 | return QueryByCriteria.Builder.fromPredicates(predicates); |
214 | |
} |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
@SuppressWarnings("unchecked") |
220 | |
@Override |
221 | |
public <T extends ExternalizableBusinessObject> List<T> getExternalizableBusinessObjectsListForLookup( |
222 | |
Class<T> externalizableBusinessObjectClass, Map<String, Object> fieldValues, boolean unbounded) { |
223 | |
|
224 | 0 | if ( Person.class.isAssignableFrom( externalizableBusinessObjectClass ) ) { |
225 | 0 | return (List)getPersonService().findPeople( (Map)fieldValues, unbounded ); |
226 | 0 | } else if ( RoleContract.class.isAssignableFrom( externalizableBusinessObjectClass ) ) { |
227 | 0 | List<Role> roles = getKimRoleService().findRoles(toQuery(fieldValues)).getResults(); |
228 | 0 | List<RoleEbo> roleEbos = new ArrayList<RoleEbo>(roles.size()); |
229 | 0 | for (Role role : roles) { |
230 | 0 | roleEbos.add(RoleEbo.from(role)); |
231 | |
} |
232 | 0 | return (List<T>)roleEbos; |
233 | 0 | } else if (GroupContract.class.isAssignableFrom( externalizableBusinessObjectClass)) { |
234 | 0 | List<Group> groups = getGroupService().findGroups(toQuery(fieldValues)).getResults(); |
235 | 0 | List<GroupEbo> groupEbos = new ArrayList<GroupEbo>(groups.size()); |
236 | 0 | for (Group group : groups) { |
237 | 0 | groupEbos.add(GroupEbo.from(group)); |
238 | |
} |
239 | 0 | return (List<T>)groupEbos; |
240 | |
} |
241 | |
|
242 | 0 | return super.getExternalizableBusinessObjectsListForLookup(externalizableBusinessObjectClass, fieldValues, unbounded); |
243 | |
} |
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
@SuppressWarnings("unchecked") |
251 | |
@Override |
252 | |
public List listPrimaryKeyFieldNames(Class businessObjectInterfaceClass) { |
253 | |
|
254 | 0 | if ( Person.class.isAssignableFrom( businessObjectInterfaceClass ) ) { |
255 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.PRINCIPAL_ID ); |
256 | 0 | } else if ( RoleEbo.class.isAssignableFrom( businessObjectInterfaceClass ) ) { |
257 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.ROLE_ID ); |
258 | 0 | } else if ( GroupEbo.class.isAssignableFrom( businessObjectInterfaceClass ) ) { |
259 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.GROUP_ID ); |
260 | 0 | } else if ( KimType.class.isAssignableFrom( businessObjectInterfaceClass ) ) { |
261 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ); |
262 | 0 | } else if ( KimTypeContract.class.isAssignableFrom(businessObjectInterfaceClass)) { |
263 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_CODE ); |
264 | |
} |
265 | |
|
266 | |
|
267 | 0 | return super.listPrimaryKeyFieldNames( businessObjectInterfaceClass ); |
268 | |
} |
269 | |
|
270 | |
@SuppressWarnings("unchecked") |
271 | |
protected PersonService getPersonService() { |
272 | 0 | if ( personService == null ) { |
273 | 0 | personService = KimApiServiceLocator.getPersonService(); |
274 | |
} |
275 | 0 | return personService; |
276 | |
} |
277 | |
|
278 | |
protected RoleService getKimRoleService() { |
279 | 0 | if ( kimRoleService == null ) { |
280 | 0 | kimRoleService = KimApiServiceLocator.getRoleService(); |
281 | |
} |
282 | 0 | return kimRoleService; |
283 | |
} |
284 | |
|
285 | |
protected GroupService getGroupService() { |
286 | 0 | if ( groupService == null ) { |
287 | 0 | groupService = KimApiServiceLocator.getGroupService(); |
288 | |
} |
289 | 0 | return groupService; |
290 | |
} |
291 | |
|
292 | |
protected IdentityService getIdentityService() { |
293 | 0 | if ( identityService == null ) { |
294 | 0 | identityService = KimApiServiceLocator.getIdentityService(); |
295 | |
} |
296 | 0 | return identityService; |
297 | |
} |
298 | |
|
299 | |
protected KimTypeInfoService getTypeInfoService() { |
300 | 0 | if(kimTypeInfoService == null){ |
301 | 0 | kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService(); |
302 | |
} |
303 | 0 | return kimTypeInfoService; |
304 | |
} |
305 | |
|
306 | |
protected Properties getUrlParameters(String businessObjectClassAttribute, Map<String, String[]> parameters){ |
307 | 0 | Properties urlParameters = new Properties(); |
308 | 0 | for (String paramName : parameters.keySet()) { |
309 | 0 | String[] parameterValues = parameters.get(paramName); |
310 | 0 | if (parameterValues.length > 0) { |
311 | 0 | urlParameters.put(paramName, parameterValues[0]); |
312 | |
} |
313 | 0 | } |
314 | 0 | urlParameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, businessObjectClassAttribute); |
315 | |
try{ |
316 | 0 | Class inquiryBusinessObjectClass = Class.forName(businessObjectClassAttribute); |
317 | 0 | if(Role.class.isAssignableFrom(inquiryBusinessObjectClass) || |
318 | |
Group.class.isAssignableFrom(inquiryBusinessObjectClass) || |
319 | |
Person.class.isAssignableFrom(inquiryBusinessObjectClass)) { |
320 | 0 | urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY); |
321 | |
} else{ |
322 | 0 | urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.CONTINUE_WITH_INQUIRY_METHOD_TO_CALL); |
323 | |
} |
324 | 0 | } catch(Exception eix){ |
325 | 0 | urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.CONTINUE_WITH_INQUIRY_METHOD_TO_CALL); |
326 | 0 | } |
327 | 0 | urlParameters.put(KRADConstants.PARAMETER_COMMAND, KewApiConstants.INITIATE_COMMAND); |
328 | 0 | return urlParameters; |
329 | |
} |
330 | |
|
331 | |
@Override |
332 | |
protected String getInquiryUrl(Class inquiryBusinessObjectClass){ |
333 | 0 | String inquiryUrl = KimCommonUtilsInternal.getKimBasePath(); |
334 | 0 | if (!inquiryUrl.endsWith("/")) { |
335 | 0 | inquiryUrl = inquiryUrl + "/"; |
336 | |
} |
337 | 0 | if(Role.class.isAssignableFrom(inquiryBusinessObjectClass)) { |
338 | 0 | return inquiryUrl + KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_ACTION; |
339 | 0 | } else if(Group.class.isAssignableFrom(inquiryBusinessObjectClass)) { |
340 | 0 | return inquiryUrl + KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_ACTION; |
341 | 0 | } else if(Person.class.isAssignableFrom(inquiryBusinessObjectClass)) { |
342 | 0 | return inquiryUrl + KimConstants.KimUIConstants.KIM_PERSON_INQUIRY_ACTION; |
343 | |
} |
344 | 0 | return super.getInquiryUrl(inquiryBusinessObjectClass); |
345 | |
} |
346 | |
|
347 | |
} |