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