1 |
package dk.thoerup.webservice; |
package dk.thoerup.webservice; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
import java.util.Collection; |
import java.util.Collection; |
5 |
import java.util.GregorianCalendar; |
import java.util.GregorianCalendar; |
6 |
import java.util.HashMap; |
import java.util.HashMap; |
63 |
@Path("/search") |
@Path("/search") |
64 |
@GET |
@GET |
65 |
@Produces(MediaType.APPLICATION_JSON) |
@Produces(MediaType.APPLICATION_JSON) |
66 |
public Person search( |
public Collection<Person> search( |
67 |
@Size(min=1) @QueryParam("q") String q |
@QueryParam("q") String q |
68 |
) { |
) { |
69 |
q = q.toLowerCase(); |
q = q.toLowerCase(); |
70 |
|
|
71 |
|
ArrayList<Person> result = new ArrayList<Person>(); |
72 |
|
|
73 |
for(Person p : persons.values()) { |
for(Person p : persons.values()) { |
74 |
if (p.getName().toLowerCase().contains(q)) |
if (p.getName().toLowerCase().contains(q)) { |
75 |
return p; |
result.add(p); |
76 |
|
} |
77 |
|
|
78 |
|
} |
79 |
|
if (result.isEmpty()) { |
80 |
|
throw new PersonNotFoundException(); |
81 |
} |
} |
82 |
|
|
83 |
throw new PersonNotFoundException(); |
return result; |
84 |
} |
} |
85 |
|
|
86 |
|
|