View Javadoc
1   /**
2    * Copyright 2011-2014 The Kuali Foundation Licensed under the Educational Community
3    * License, Version 2.0 (the "License"); you may not use this file except in
4    * compliance with the License. You may obtain a copy of the License at
5    *
6    * http://www.osedu.org/licenses/ECL-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11   * License for the specific language governing permissions and limitations under
12   * the License.
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   * Implementation of the <code>DirectoryService</code>
34   * @author Kuali Mobility Team (mobility.collab@kuali.org)
35   * @since
36   */
37  @WebService(endpointInterface = "org.kuali.mobility.people.service.DirectoryService")
38  public class DirectoryServiceImpl implements DirectoryService, ApplicationContextAware {
39  
40  	/**
41  	 * A reference to the <code>ApplicationContext</code>.
42  	 */
43  	private ApplicationContext applicationContext;
44  
45  	/**
46  	 * A reference to the <code>DirectoryDao</code>.
47  	 */
48  	private DirectoryDao directoryDao;
49  
50  	/**
51  	 * A reference to the <code>PersonTransform</code>.
52  	 */
53  	private PersonTransform personTransform;
54  	
55  	/**
56  	 * A reference to the <code>GroupTransform</code>.
57  	 */
58  	private GroupTransform groupTransform;
59  
60  	/**
61  	 * Performs a search
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  //		searchCriteria = new SearchCriteria();
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  	 * Finds entries for a search criteria
92  	 */
93  	@Override
94  	public SearchResultImpl findEntries(SearchCriteria searchCriteria) {
95  		return (SearchResultImpl) directoryDao.findEntries(searchCriteria);
96  	}
97  
98  	/**
99  	 * Searches for a person
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 	 * Looks up a person
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 	 * Searches for groups
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 	 * Looks up a group
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 	 * Gets the reference to the <code>DirectoryDao</code>.
166 	 * @return Reference to the <code>DirectoryDao</code>.
167 	 */
168 	public DirectoryDao getDirectoryDao() {
169 		return directoryDao;
170 	}
171 
172 	/**
173 	 * Sets the reference to the <code>DirectoryDao</code>.
174 	 * @param directoryDao Reference to the <code>DirectoryDao</code>.
175 	 */
176 	public void setDirectoryDao(DirectoryDao directoryDao) {
177 		this.directoryDao = directoryDao;
178 	}
179 
180 	/**
181 	 * Gets the reference to the <code>PersonTransform</code>.
182 	 * @return Reference to the <code>PersonTransform</code>.
183 	 */
184 	public PersonTransform getPersonTransform() {
185 		return personTransform;
186 	}
187 
188 	/**
189 	 * Sets the reference to the <code>PersonTransform</code>.
190 	 * @param personTransform Reference to the <code>PersonTransform</code>.
191 	 */
192 	public void setPersonTransform(PersonTransform personTransform) {
193 		this.personTransform = personTransform;
194 	}
195 
196 	/**
197 	 * Gets the reference to the <code>GroupTransform</code>.
198 	 * @return Reference to the <code>GroupTransform</code>.
199 	 */
200 	public GroupTransform getGroupTransform() {
201 		return groupTransform;
202 	}
203 
204 	/**
205 	 * Sets the reference to the <code>GroupTransform</code>.
206 	 * @param groupTransform Reference to the <code>GroupTransform</code>.
207 	 */
208 	public void setGroupTransform(GroupTransform groupTransform) {
209 		this.groupTransform = groupTransform;
210 	}
211 
212 	/**
213 	 * Gets the reference to the <code>ApplicationContext</code>.
214 	 * @return Reference to the <code>ApplicationContext</code>.
215 	 */
216 	public ApplicationContext getApplicationContext() {
217 		return applicationContext;
218 	}
219 
220 	/**
221 	 * Sets the reference to the <code>ApplicationContext</code>.
222 	 * @param applicationContext Reference to the <code>ApplicationContext</code>.
223 	 */
224 	public void setApplicationContext(ApplicationContext applicationContext) {
225 		this.applicationContext = applicationContext;
226 	}
227 }