1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.kuali.mobility.people.service;
15
16 import org.apache.commons.collections.CollectionUtils;
17 import org.kuali.mobility.people.dao.DirectoryDao;
18 import org.kuali.mobility.people.entity.GroupImpl;
19 import org.kuali.mobility.people.entity.PersonImpl;
20 import org.kuali.mobility.people.entity.SearchCriteria;
21 import org.kuali.mobility.people.entity.SearchResultImpl;
22 import org.kuali.mobility.people.service.util.GroupTransform;
23 import org.kuali.mobility.people.service.util.PersonTransform;
24 import org.springframework.context.ApplicationContext;
25 import org.springframework.context.ApplicationContextAware;
26
27 import javax.jws.WebService;
28 import javax.ws.rs.*;
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35
36
37 @WebService(endpointInterface = "org.kuali.mobility.people.service.DirectoryService")
38 public class DirectoryServiceImpl implements DirectoryService, ApplicationContextAware {
39
40
41
42
43 private ApplicationContext applicationContext;
44
45
46
47
48 private DirectoryDao directoryDao;
49
50
51
52
53 private PersonTransform personTransform;
54
55
56
57
58 private GroupTransform groupTransform;
59
60
61
62
63
64 @POST
65 @Path("/search")
66 public SearchResultImpl search(
67 @FormParam("searchText") final String searchText,
68 @FormParam("firstName") final String firstName,
69 @FormParam("lastName") final String lastName,
70 @FormParam("username") final String username,
71 @FormParam("exactness") final String exactness,
72 @FormParam("status") final String status,
73 @FormParam("location") final String location) {
74 SearchCriteria searchCriteria = new SearchCriteria();
75
76 searchCriteria.setExactness(exactness);
77 searchCriteria.setFirstName(firstName);
78 searchCriteria.setLastName(lastName);
79 searchCriteria.setLocation(location);
80 searchCriteria.setSearchText(searchText);
81 searchCriteria.setStatus(status);
82 searchCriteria.setUserName(username);
83 SearchResultImpl result = findEntries(searchCriteria);
84 if (result != null) {
85 result.setSearchCriteria(searchCriteria);
86 }
87 return result;
88 }
89
90
91
92
93 @Override
94 public SearchResultImpl findEntries(SearchCriteria searchCriteria) {
95 return (SearchResultImpl) directoryDao.findEntries(searchCriteria);
96 }
97
98
99
100
101
102 @POST
103 @Path("/person/search")
104 public List<PersonImpl> personSearch(
105 @FormParam("searchText") final String searchText,
106 @FormParam("firstName") final String firstName,
107 @FormParam("lastName") final String lastName,
108 @FormParam("username") final String username,
109 @FormParam("exactness") final String exactness,
110 @FormParam("status") final String status,
111 @FormParam("location") final String location) {
112 List<PersonImpl> people = new ArrayList<PersonImpl>();
113
114 SearchCriteria searchCriteria = new SearchCriteria();
115 searchCriteria = new SearchCriteria();
116 searchCriteria.setExactness(exactness);
117 searchCriteria.setFirstName(firstName);
118 searchCriteria.setLastName(lastName);
119 searchCriteria.setLocation(location);
120 searchCriteria.setSearchText(searchText);
121 searchCriteria.setStatus(status);
122 searchCriteria.setUserName(username);
123
124 CollectionUtils.collect(
125 (getDirectoryDao().findEntries(searchCriteria)).getPeople(),
126 getPersonTransform(),
127 people);
128
129 return people;
130 }
131
132
133
134
135 @GET
136 @Path("/person/lookup")
137 @Override
138 public PersonImpl personLookup(@QueryParam("username") final String personId) {
139 return getPersonTransform().transform(directoryDao.lookupPerson(personId));
140 }
141
142
143
144
145 @GET
146 @Path("/group/search")
147 @Override
148 public List<GroupImpl> findSimpleGroup(@QueryParam("searchTerms") final String groupId) {
149 List<GroupImpl> groups = new ArrayList<GroupImpl>();
150 CollectionUtils.collect(directoryDao.findSimpleGroup(groupId), getGroupTransform(), groups);
151 return groups;
152 }
153
154
155
156
157 @GET
158 @Path("/group/lookup")
159 @Override
160 public GroupImpl groupLookup(@QueryParam("dn") final String groupId) {
161 return getGroupTransform().transform(directoryDao.lookupGroup(groupId));
162 }
163
164
165
166
167
168 public DirectoryDao getDirectoryDao() {
169 return directoryDao;
170 }
171
172
173
174
175
176 public void setDirectoryDao(DirectoryDao directoryDao) {
177 this.directoryDao = directoryDao;
178 }
179
180
181
182
183
184 public PersonTransform getPersonTransform() {
185 return personTransform;
186 }
187
188
189
190
191
192 public void setPersonTransform(PersonTransform personTransform) {
193 this.personTransform = personTransform;
194 }
195
196
197
198
199
200 public GroupTransform getGroupTransform() {
201 return groupTransform;
202 }
203
204
205
206
207
208 public void setGroupTransform(GroupTransform groupTransform) {
209 this.groupTransform = groupTransform;
210 }
211
212
213
214
215
216 public ApplicationContext getApplicationContext() {
217 return applicationContext;
218 }
219
220
221
222
223
224 public void setApplicationContext(ApplicationContext applicationContext) {
225 this.applicationContext = applicationContext;
226 }
227 }