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