1 | |
package org.codeforamerica.open311.facade.data; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
import java.util.Date; |
5 | |
import java.util.LinkedList; |
6 | |
import java.util.List; |
7 | |
|
8 | |
import org.codeforamerica.open311.facade.EndpointType; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
public class ServiceDiscoveryInfo implements Serializable { |
17 | |
|
18 | |
private static final long serialVersionUID = 5804902138488110319L; |
19 | |
private final static String GEO_REPORT_V2_SPECIFICATION_URL = "http://wiki.open311.org/GeoReport_v2"; |
20 | |
private Date changeset; |
21 | |
private String contact; |
22 | |
private String keyService; |
23 | |
List<Endpoint> endpoints; |
24 | |
|
25 | |
public ServiceDiscoveryInfo(Date changeset, String contact, |
26 | |
String keyService, List<Endpoint> endpoints) { |
27 | 6 | super(); |
28 | 6 | this.changeset = changeset; |
29 | 6 | this.contact = contact; |
30 | 6 | this.keyService = keyService; |
31 | 6 | this.endpoints = endpoints; |
32 | 6 | } |
33 | |
|
34 | |
public Date getChangeset() { |
35 | 1 | return changeset; |
36 | |
} |
37 | |
|
38 | |
public String getContact() { |
39 | 1 | return contact; |
40 | |
} |
41 | |
|
42 | |
public String getKeyService() { |
43 | 1 | return keyService; |
44 | |
} |
45 | |
|
46 | |
public List<Endpoint> getEndpoints() { |
47 | 1 | return endpoints; |
48 | |
} |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public Endpoint getMoreSuitableEndpoint(EndpointType endpointType) { |
60 | 6 | List<Endpoint> typeFilteredEndpoints = new LinkedList<Endpoint>(); |
61 | 6 | for (Endpoint endpoint : endpoints) { |
62 | 24 | if (endpoint.getType() == endpointType) { |
63 | 12 | typeFilteredEndpoints.add(endpoint); |
64 | |
} |
65 | |
} |
66 | 6 | Endpoint candidate = null; |
67 | 6 | for (Endpoint endpoint : typeFilteredEndpoints) { |
68 | |
|
69 | |
|
70 | 6 | if (endpoint.getSpecificationUrl().equals(GEO_REPORT_V2_SPECIFICATION_URL)) { |
71 | 6 | if (endpoint.getUrl().contains("v2")) { |
72 | 6 | return endpoint; |
73 | |
} |
74 | 0 | candidate = endpoint; |
75 | |
} |
76 | |
} |
77 | 0 | return candidate; |
78 | |
} |
79 | |
} |