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