Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Cache |
|
| 1.0;1 | ||||
Cache$CacheableOperation |
|
| 1.0;1 |
1 | package org.codeforamerica.open311.internals.caching; | |
2 | ||
3 | import java.util.List; | |
4 | ||
5 | import org.codeforamerica.open311.facade.City; | |
6 | import org.codeforamerica.open311.facade.data.Service; | |
7 | import org.codeforamerica.open311.facade.data.ServiceDefinition; | |
8 | import org.codeforamerica.open311.facade.data.ServiceDiscoveryInfo; | |
9 | import org.codeforamerica.open311.facade.data.ServiceRequest; | |
10 | import org.codeforamerica.open311.facade.data.operations.GETServiceRequestsFilter; | |
11 | ||
12 | /** | |
13 | * Specifies all the operations needed to do data caching and avoid useless and | |
14 | * slow network requests. | |
15 | * | |
16 | * @author Santiago Munín <santimunin@gmail.com> | |
17 | * | |
18 | */ | |
19 | public interface Cache { | |
20 | /** | |
21 | * Saves the endpoints-service discovery relationships. | |
22 | * | |
23 | * @param data | |
24 | * A JSON list. | |
25 | */ | |
26 | public void saveCitiesInfo(String data); | |
27 | ||
28 | /** | |
29 | * Looks for the endpoints-service discovery relationships. | |
30 | * | |
31 | * @return A JSON list or <code>null</code> if it wasn't found. | |
32 | */ | |
33 | public String retrieveCitiesInfo(); | |
34 | ||
35 | /** | |
36 | * Saves a {@link ServiceDiscoveryInfo object} related to a city. | |
37 | * | |
38 | * @param city | |
39 | * City related to the requested service discovery. | |
40 | * @param serviceDiscovery | |
41 | * The obtained service discovery. | |
42 | */ | |
43 | public void saveServiceDiscovery(City city, | |
44 | ServiceDiscoveryInfo serviceDiscovery); | |
45 | ||
46 | /** | |
47 | * Looks for the service discovery of a given city in the local cache. | |
48 | * | |
49 | * @param city | |
50 | * City of interest. | |
51 | * @return The service discovery of the given city of <code>null</code> if | |
52 | * it isn't cached. | |
53 | */ | |
54 | public ServiceDiscoveryInfo retrieveCachedServiceDiscoveryInfo(City city); | |
55 | ||
56 | /** | |
57 | * Saves a list of {@link Service} objects related to an endpoint. | |
58 | * | |
59 | * @param endpointUrl | |
60 | * Url of the endpoint. | |
61 | * @param services | |
62 | * Obtained services. | |
63 | */ | |
64 | public void saveListOfServices(String endpointUrl, List<Service> services); | |
65 | ||
66 | /** | |
67 | * Looks for a cached list of services. | |
68 | * | |
69 | * @param endpointUrl | |
70 | * Url of the endpoint. | |
71 | * @return The list of services or <code>null</code> if they aren't cached. | |
72 | */ | |
73 | public List<Service> retrieveCachedServiceList(String endpointUrl); | |
74 | ||
75 | /** | |
76 | * Saves a service definition. | |
77 | * | |
78 | * @param endpointUrl | |
79 | * Url of the endpoint. | |
80 | * @param serviceCode | |
81 | * Code of the service. | |
82 | * @param serviceDefinition | |
83 | * Obtained definition from the server. | |
84 | */ | |
85 | public void saveServiceDefinition(String endpointUrl, String serviceCode, | |
86 | ServiceDefinition serviceDefinition); | |
87 | ||
88 | /** | |
89 | * Looks for a cached service definition. | |
90 | * | |
91 | * @param endpointUrl | |
92 | * Url of the endpoint. | |
93 | * @param serviceCode | |
94 | * Service code of the desired service. | |
95 | * @return A service definition or <code>null</code> if it isn't cached. | |
96 | */ | |
97 | public ServiceDefinition retrieveCachedServiceDefinition( | |
98 | String endpointUrl, String serviceCode); | |
99 | ||
100 | /** | |
101 | * Saves a list of service requests. | |
102 | * | |
103 | * @param endpointUrl | |
104 | * Url of the endpoint. | |
105 | * @param filter | |
106 | * Filter sent to the endpoint. | |
107 | * @param requests | |
108 | * Obtained list of requests. | |
109 | */ | |
110 | public void saveServiceRequestList(String endpointUrl, | |
111 | GETServiceRequestsFilter filter, List<ServiceRequest> requests); | |
112 | ||
113 | /** | |
114 | * Looks for a cached GET service requests response. | |
115 | * | |
116 | * @param endpointUrl | |
117 | * Url of the endpoint. | |
118 | * @param filter | |
119 | * The desired filter. | |
120 | * @return A list of ServiceRequest or <code>null</code> if they aren't | |
121 | * cached. | |
122 | */ | |
123 | public List<ServiceRequest> retrieveCachedServiceRequests( | |
124 | String endpointUrl, GETServiceRequestsFilter filter); | |
125 | ||
126 | /** | |
127 | * Saves a service request. | |
128 | * | |
129 | * @param endpointUrl | |
130 | * Url of the endpoint. | |
131 | * @param serviceRequestId | |
132 | * Id of the requested service request. | |
133 | * @param request | |
134 | * Obtained service request. | |
135 | */ | |
136 | public void saveSingleServiceRequest(String endpointUrl, | |
137 | String serviceRequestId, ServiceRequest request); | |
138 | ||
139 | /** | |
140 | * Looks for a cached GET service request response. | |
141 | * | |
142 | * @param endpointUrl | |
143 | * Url of the endpoint. | |
144 | * @param serviceRequestId | |
145 | * The service request's id. | |
146 | * @return A ServiceRequest or <code>null</code> if it wasn't cached. | |
147 | */ | |
148 | public ServiceRequest retrieveCachedServiceRequest(String endpointUrl, | |
149 | String serviceRequestId); | |
150 | ||
151 | /** | |
152 | * Deletes the cache. | |
153 | */ | |
154 | public void deleteCache(); | |
155 | ||
156 | /** | |
157 | * Set a custom time to live to a given operation. | |
158 | * | |
159 | * @param operation | |
160 | * Operation which time to live will be changed. | |
161 | * @param timeToLiveInHours | |
162 | * New time to live (in hours). | |
163 | */ | |
164 | public void setCustomTimeToLive(CacheableOperation operation, | |
165 | int timeToLiveInHours); | |
166 | ||
167 | /** | |
168 | * Set of operations which will be cached. | |
169 | * | |
170 | * @author Santiago Munín <santimunin@gmail.com> | |
171 | * | |
172 | */ | |
173 | 7 | public static enum CacheableOperation { |
174 | 1 | GET_SERVICE_DISCOVERY, GET_SERVICE_LIST, GET_SERVICE_DEFINITION, GET_SERVICE_REQUEST_LIST, GET_SINGLE_SERVICE_REQUEST, GET_CITIES_SERVICE_DISCOVERY_URLS; |
175 | } | |
176 | } |