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