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 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 if ( Person.class.isAssignableFrom( businessObjectClass ) ) {
64 if ( fieldValues.containsKey( KIMPropertyConstants.Person.PRINCIPAL_ID ) ) {
65 return (T) getPersonService().getPerson( (String)fieldValues.get( KIMPropertyConstants.Person.PRINCIPAL_ID ) );
66 } else if ( fieldValues.containsKey( KIMPropertyConstants.Person.PRINCIPAL_NAME ) ) {
67 return (T) getPersonService().getPersonByPrincipalName( (String)fieldValues.get( KIMPropertyConstants.Person.PRINCIPAL_NAME ) );
68 }
69
70 } else if(Role.class.isAssignableFrom(businessObjectClass)){
71 if(fieldValues.containsKey(KimConstants.PrimaryKeyConstants.ROLE_ID)){
72 KimRoleInfo roleInfo = getKimRoleService().getRole((String)fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_ID));
73
74 return (T) roleInfo;
75 }
76 } else if(Group.class.isAssignableFrom(businessObjectClass)){
77 if(fieldValues.containsKey(KimConstants.PrimaryKeyConstants.GROUP_ID)) {
78 return (T) getGroupService().getGroupInfo((String)fieldValues.get(KimConstants.PrimaryKeyConstants.GROUP_ID));
79 }
80
81
82
83
84 }
85
86 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 if ( Person.class.isAssignableFrom( externalizableBusinessObjectClass ) ) {
100 return (List)getPersonService().findPeople( (Map)fieldValues );
101 } else if ( Role.class.isAssignableFrom( externalizableBusinessObjectClass ) ) {
102 return (List)getKimRoleService().getRolesSearchResults((Map)fieldValues );
103 } else if ( Group.class.isAssignableFrom(externalizableBusinessObjectClass) ) {
104 return (List)getGroupService().lookupGroups( (Map)fieldValues );
105 }
106
107 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 if ( Person.class.isAssignableFrom( externalizableBusinessObjectClass ) ) {
119 return (List)getPersonService().findPeople( (Map)fieldValues, unbounded );
120 } else if ( Role.class.isAssignableFrom( externalizableBusinessObjectClass ) ) {
121
122 return (List)getKimRoleService().getRolesSearchResults((Map)fieldValues );
123 }
124
125 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 if ( Person.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
138 return Collections.singletonList( KimConstants.PrimaryKeyConstants.PRINCIPAL_ID );
139 } else if ( Role.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
140 return Collections.singletonList( KimConstants.PrimaryKeyConstants.ROLE_ID );
141 } else if ( Group.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
142 return Collections.singletonList( KimConstants.PrimaryKeyConstants.GROUP_ID );
143 } else if ( KimType.class.isAssignableFrom( businessObjectInterfaceClass ) ) {
144 return Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID );
145 } else if ( KimCode.class.isAssignableFrom(businessObjectInterfaceClass)) {
146 return Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_CODE );
147 }
148
149
150 return super.listPrimaryKeyFieldNames( businessObjectInterfaceClass );
151 }
152
153 @SuppressWarnings("unchecked")
154 protected PersonService<Person> getPersonService() {
155 if ( personService == null ) {
156 personService = KIMServiceLocator.getPersonService();
157 }
158 return personService;
159 }
160
161 protected RoleService getKimRoleService() {
162 if ( kimRoleService == null ) {
163 kimRoleService = KIMServiceLocator.getRoleManagementService();
164 }
165 return kimRoleService;
166 }
167
168 protected GroupService getGroupService() {
169 if ( groupService == null ) {
170 groupService = KIMServiceLocator.getGroupService();
171 }
172 return groupService;
173 }
174
175 protected KimTypeInfoService getTypeInfoService() {
176 if(kimTypeInfoService == null){
177 kimTypeInfoService = KIMServiceLocator.getTypeInfoService();
178 }
179 return kimTypeInfoService;
180 }
181
182 protected Properties getUrlParameters(String businessObjectClassAttribute, Map<String, String[]> parameters){
183 Properties urlParameters = new Properties();
184 for (String paramName : parameters.keySet()) {
185 String[] parameterValues = parameters.get(paramName);
186 if (parameterValues.length > 0) {
187 urlParameters.put(paramName, parameterValues[0]);
188 }
189 }
190 urlParameters.put(KNSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, businessObjectClassAttribute);
191 try{
192 Class inquiryBusinessObjectClass = Class.forName(businessObjectClassAttribute);
193 if(Role.class.isAssignableFrom(inquiryBusinessObjectClass) ||
194 Group.class.isAssignableFrom(inquiryBusinessObjectClass) ||
195 Person.class.isAssignableFrom(inquiryBusinessObjectClass)) {
196 urlParameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY);
197 } else{
198 urlParameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.CONTINUE_WITH_INQUIRY_METHOD_TO_CALL);
199 }
200 } catch(Exception eix){
201 urlParameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.CONTINUE_WITH_INQUIRY_METHOD_TO_CALL);
202 }
203 urlParameters.put(KNSConstants.PARAMETER_COMMAND, KEWConstants.INITIATE_COMMAND);
204 return urlParameters;
205 }
206
207 @Override
208 protected String getInquiryUrl(Class inquiryBusinessObjectClass){
209 String inquiryUrl = KimCommonUtils.getKimBasePath();
210 if (!inquiryUrl.endsWith("/")) {
211 inquiryUrl = inquiryUrl + "/";
212 }
213 if(Role.class.isAssignableFrom(inquiryBusinessObjectClass)) {
214 return inquiryUrl + KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_ACTION;
215 } else if(Group.class.isAssignableFrom(inquiryBusinessObjectClass)) {
216 return inquiryUrl + KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_ACTION;
217 } else if(Person.class.isAssignableFrom(inquiryBusinessObjectClass)) {
218 return inquiryUrl + KimConstants.KimUIConstants.KIM_PERSON_INQUIRY_ACTION;
219 }
220 return super.getInquiryUrl(inquiryBusinessObjectClass);
221 }
222
223 }