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 java.util.Collections; |
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
import java.util.Properties; |
22 | |
|
23 | |
import org.kuali.rice.kew.util.KEWConstants; |
24 | |
import org.kuali.rice.kim.bo.Group; |
25 | |
import org.kuali.rice.kim.bo.KimType; |
26 | |
import org.kuali.rice.kim.bo.Person; |
27 | |
import org.kuali.rice.kim.bo.Role; |
28 | |
import org.kuali.rice.kim.bo.reference.KimCode; |
29 | |
import org.kuali.rice.kim.bo.role.dto.KimRoleInfo; |
30 | |
import org.kuali.rice.kim.service.GroupService; |
31 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
32 | |
import org.kuali.rice.kim.service.KimTypeInfoService; |
33 | |
import org.kuali.rice.kim.service.PersonService; |
34 | |
import org.kuali.rice.kim.service.RoleService; |
35 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
36 | |
import org.kuali.rice.kim.util.KimCommonUtils; |
37 | |
import org.kuali.rice.kim.util.KimConstants; |
38 | |
import org.kuali.rice.kns.bo.ExternalizableBusinessObject; |
39 | |
import org.kuali.rice.kns.service.impl.ModuleServiceBase; |
40 | |
import org.kuali.rice.kns.util.KNSConstants; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | 0 | public class KimModuleService extends ModuleServiceBase { |
49 | |
|
50 | |
private PersonService<Person> personService; |
51 | |
private RoleService kimRoleService; |
52 | |
private GroupService groupService; |
53 | |
private KimTypeInfoService kimTypeInfoService; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
@SuppressWarnings("unchecked") |
61 | |
@Override |
62 | |
public <T extends ExternalizableBusinessObject> T getExternalizableBusinessObject(Class<T> businessObjectClass, Map<String, Object> fieldValues) { |
63 | 0 | if ( Person.class.isAssignableFrom( businessObjectClass ) ) { |
64 | 0 | if ( fieldValues.containsKey( KIMPropertyConstants.Person.PRINCIPAL_ID ) ) { |
65 | 0 | return (T) getPersonService().getPerson( (String)fieldValues.get( KIMPropertyConstants.Person.PRINCIPAL_ID ) ); |
66 | 0 | } else if ( fieldValues.containsKey( KIMPropertyConstants.Person.PRINCIPAL_NAME ) ) { |
67 | 0 | return (T) getPersonService().getPersonByPrincipalName( (String)fieldValues.get( KIMPropertyConstants.Person.PRINCIPAL_NAME ) ); |
68 | |
} |
69 | |
|
70 | 0 | } else if(Role.class.isAssignableFrom(businessObjectClass)){ |
71 | 0 | if(fieldValues.containsKey(KimConstants.PrimaryKeyConstants.ROLE_ID)){ |
72 | 0 | KimRoleInfo roleInfo = getKimRoleService().getRole((String)fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_ID)); |
73 | |
|
74 | 0 | return (T) roleInfo; |
75 | |
} |
76 | 0 | } else if(Group.class.isAssignableFrom(businessObjectClass)){ |
77 | 0 | if(fieldValues.containsKey(KimConstants.PrimaryKeyConstants.GROUP_ID)) { |
78 | 0 | return (T) getGroupService().getGroupInfo((String)fieldValues.get(KimConstants.PrimaryKeyConstants.GROUP_ID)); |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
} |
85 | |
|
86 | 0 | return super.getExternalizableBusinessObject( businessObjectClass, fieldValues ); |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
@SuppressWarnings("unchecked") |
95 | |
@Override |
96 | |
public <T extends ExternalizableBusinessObject> List<T> getExternalizableBusinessObjectsList( |
97 | |
Class<T> externalizableBusinessObjectClass, Map<String, Object> fieldValues) { |
98 | |
|
99 | 0 | if ( Person.class.isAssignableFrom( externalizableBusinessObjectClass ) ) { |
100 | 0 | return (List)getPersonService().findPeople( (Map)fieldValues ); |
101 | 0 | } else if ( Role.class.isAssignableFrom( externalizableBusinessObjectClass ) ) { |
102 | 0 | return (List)getKimRoleService().getRolesSearchResults((Map)fieldValues ); |
103 | 0 | } else if ( Group.class.isAssignableFrom(externalizableBusinessObjectClass) ) { |
104 | 0 | return (List)getGroupService().lookupGroups( (Map)fieldValues ); |
105 | |
} |
106 | |
|
107 | 0 | return super.getExternalizableBusinessObjectsList( externalizableBusinessObjectClass, fieldValues ); |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
@SuppressWarnings("unchecked") |
114 | |
@Override |
115 | |
public <T extends ExternalizableBusinessObject> List<T> getExternalizableBusinessObjectsListForLookup( |
116 | |
Class<T> externalizableBusinessObjectClass, Map<String, Object> fieldValues, boolean unbounded) { |
117 | |
|
118 | 0 | if ( Person.class.isAssignableFrom( externalizableBusinessObjectClass ) ) { |
119 | 0 | return (List)getPersonService().findPeople( (Map)fieldValues, unbounded ); |
120 | 0 | } else if ( Role.class.isAssignableFrom( externalizableBusinessObjectClass ) ) { |
121 | |
|
122 | 0 | return (List)getKimRoleService().getRolesSearchResults((Map)fieldValues ); |
123 | |
} |
124 | |
|
125 | 0 | return super.getExternalizableBusinessObjectsListForLookup(externalizableBusinessObjectClass, fieldValues, unbounded); |
126 | |
} |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
@SuppressWarnings("unchecked") |
134 | |
@Override |
135 | |
public List listPrimaryKeyFieldNames(Class businessObjectInterfaceClass) { |
136 | |
|
137 | 0 | if ( Person.class.isAssignableFrom( businessObjectInterfaceClass ) ) { |
138 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.PRINCIPAL_ID ); |
139 | 0 | } else if ( Role.class.isAssignableFrom( businessObjectInterfaceClass ) ) { |
140 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.ROLE_ID ); |
141 | 0 | } else if ( Group.class.isAssignableFrom( businessObjectInterfaceClass ) ) { |
142 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.GROUP_ID ); |
143 | 0 | } else if ( KimType.class.isAssignableFrom( businessObjectInterfaceClass ) ) { |
144 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ); |
145 | 0 | } else if ( KimCode.class.isAssignableFrom(businessObjectInterfaceClass)) { |
146 | 0 | return Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_CODE ); |
147 | |
} |
148 | |
|
149 | |
|
150 | 0 | return super.listPrimaryKeyFieldNames( businessObjectInterfaceClass ); |
151 | |
} |
152 | |
|
153 | |
@SuppressWarnings("unchecked") |
154 | |
protected PersonService<Person> getPersonService() { |
155 | 0 | if ( personService == null ) { |
156 | 0 | personService = KIMServiceLocator.getPersonService(); |
157 | |
} |
158 | 0 | return personService; |
159 | |
} |
160 | |
|
161 | |
protected RoleService getKimRoleService() { |
162 | 0 | if ( kimRoleService == null ) { |
163 | 0 | kimRoleService = KIMServiceLocator.getRoleManagementService(); |
164 | |
} |
165 | 0 | return kimRoleService; |
166 | |
} |
167 | |
|
168 | |
protected GroupService getGroupService() { |
169 | 0 | if ( groupService == null ) { |
170 | 0 | groupService = KIMServiceLocator.getGroupService(); |
171 | |
} |
172 | 0 | return groupService; |
173 | |
} |
174 | |
|
175 | |
protected KimTypeInfoService getTypeInfoService() { |
176 | 0 | if(kimTypeInfoService == null){ |
177 | 0 | kimTypeInfoService = KIMServiceLocator.getTypeInfoService(); |
178 | |
} |
179 | 0 | return kimTypeInfoService; |
180 | |
} |
181 | |
|
182 | |
protected Properties getUrlParameters(String businessObjectClassAttribute, Map<String, String[]> parameters){ |
183 | 0 | Properties urlParameters = new Properties(); |
184 | 0 | for (String paramName : parameters.keySet()) { |
185 | 0 | String[] parameterValues = parameters.get(paramName); |
186 | 0 | if (parameterValues.length > 0) { |
187 | 0 | urlParameters.put(paramName, parameterValues[0]); |
188 | |
} |
189 | 0 | } |
190 | 0 | urlParameters.put(KNSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, businessObjectClassAttribute); |
191 | |
try{ |
192 | 0 | Class inquiryBusinessObjectClass = Class.forName(businessObjectClassAttribute); |
193 | 0 | if(Role.class.isAssignableFrom(inquiryBusinessObjectClass) || |
194 | |
Group.class.isAssignableFrom(inquiryBusinessObjectClass) || |
195 | |
Person.class.isAssignableFrom(inquiryBusinessObjectClass)) { |
196 | 0 | urlParameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY); |
197 | |
} else{ |
198 | 0 | urlParameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.CONTINUE_WITH_INQUIRY_METHOD_TO_CALL); |
199 | |
} |
200 | 0 | } catch(Exception eix){ |
201 | 0 | urlParameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.CONTINUE_WITH_INQUIRY_METHOD_TO_CALL); |
202 | 0 | } |
203 | 0 | urlParameters.put(KNSConstants.PARAMETER_COMMAND, KEWConstants.INITIATE_COMMAND); |
204 | 0 | return urlParameters; |
205 | |
} |
206 | |
|
207 | |
@Override |
208 | |
protected String getInquiryUrl(Class inquiryBusinessObjectClass){ |
209 | 0 | String inquiryUrl = KimCommonUtils.getKimBasePath(); |
210 | 0 | if (!inquiryUrl.endsWith("/")) { |
211 | 0 | inquiryUrl = inquiryUrl + "/"; |
212 | |
} |
213 | 0 | if(Role.class.isAssignableFrom(inquiryBusinessObjectClass)) { |
214 | 0 | return inquiryUrl + KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_ACTION; |
215 | 0 | } else if(Group.class.isAssignableFrom(inquiryBusinessObjectClass)) { |
216 | 0 | return inquiryUrl + KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_ACTION; |
217 | 0 | } else if(Person.class.isAssignableFrom(inquiryBusinessObjectClass)) { |
218 | 0 | return inquiryUrl + KimConstants.KimUIConstants.KIM_PERSON_INQUIRY_ACTION; |
219 | |
} |
220 | 0 | return super.getInquiryUrl(inquiryBusinessObjectClass); |
221 | |
} |
222 | |
|
223 | |
} |