1 package net.sourceforge.heracles.service.impl;
2
3
4 import java.util.List;
5
6 import javax.naming.NamingException;
7
8 import net.sourceforge.heracles.dao.LdapQuery;
9 import net.sourceforge.heracles.model.LdapUser;
10 import net.sourceforge.heracles.service.Search;
11 import net.sourceforge.heracles.utilities.HeraclesException;
12
13 import org.apache.log4j.Logger;
14 /**
15 * Title: SearchImpl.java<br>
16 * Description: The implementation of the Serivce Interface<br>
17 * Java Version: JDK 1.5<br>
18 *
19 * @author Philipp Gantert
20 * version 1.0
21 *
22 */
23 public class SearchImpl implements Search {
24 private Logger logger = Logger.getLogger(getClass());
25
26
27 private LdapQuery ldapQuery = null;
28
29 /**
30 * Spring needs this method to inizalize the ldapQuery object.
31 * @param ldapQuery
32 */
33 public void setLdapQuery(LdapQuery ldapQuery) {
34 this.ldapQuery = ldapQuery;
35 }
36
37 /**
38 * This method asks the dao layer for searching something in the ldap. The "where" statement
39 * defines the Attribute which would be to search and the "like" statement defines the String
40 * which is searched.
41 *
42 * @param domainName
43 * String: in which domain
44 * @param where
45 * String: which attribute
46 * @param like
47 * String: which search statement
48 * @return {@link List}
49 * @throws NamingException
50 * @throws HeraclesException
51 */
52 public List<LdapUser> searchInLdap(String domainName,String where, String like) throws NamingException,HeraclesException {
53 validating(domainName, where, like);
54 List<LdapUser> ldapUsers = ldapQuery.searchInLdap(domainName,where, like);
55 if(ldapUsers.size()==0){
56 throw new HeraclesException("There are no results for this search");
57 }
58 return ldapUsers;
59 }
60
61 private void validating(String domainName,String where, String like) throws HeraclesException{
62 if(domainName==null){
63 throw new HeraclesException("The domainName value NULL is not valid");
64 }
65 if (where==null) {
66 throw new HeraclesException("The where value NULL is not valid");
67 }
68 if (like==null) {
69 throw new HeraclesException("The like value NULL is not valid");
70 }
71
72 }
73 }