org.codeforamerica.open311.internals.caching
Class AbstractCache

java.lang.Object
  extended by org.codeforamerica.open311.internals.caching.AbstractCache
All Implemented Interfaces:
Cache
Direct Known Subclasses:
AndroidCache, RegularJavaCache

public abstract class AbstractCache
extends Object
implements Cache

Implements all the operations of the Cache interface. Classes which extend this will have to implement the abstract methods.

Author:
Santiago MunĂ­n

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.codeforamerica.open311.internals.caching.Cache
Cache.CacheableOperation
 
Field Summary
protected static String FILE
           
 
Constructor Summary
AbstractCache()
           
 
Method Summary
protected abstract  String getProperty(String key)
          Retrieves a property.
 ServiceDefinition retrieveCachedServiceDefinition(String endpointUrl, String serviceCode)
          Looks for a cached service definition.
 ServiceDiscoveryInfo retrieveCachedServiceDiscoveryInfo(City city)
          Looks for the service discovery of a given city in the local cache.
 List<Service> retrieveCachedServiceList(String endpointUrl)
          Looks for a cached list of services.
 ServiceRequest retrieveCachedServiceRequest(String endpointUrl, String serviceRequestId)
          Looks for a cached GET service request response.
 List<ServiceRequest> retrieveCachedServiceRequests(String endpointUrl, GETServiceRequestsFilter filter)
          Looks for a cached GET service requests response.
 String retrieveCitiesInfo()
          Looks for the endpoints-service discovery relationships.
 void saveCitiesInfo(String data)
          Saves the endpoints-service discovery relationships.
 void saveListOfServices(String endpointUrl, List<Service> services)
          Saves a list of Service objects related to an endpoint.
protected abstract  void saveProperty(String key, String value)
          Saves a property.
 void saveServiceDefinition(String endpointUrl, String serviceCode, ServiceDefinition serviceDefinition)
          Saves a service definition.
 void saveServiceDiscovery(City city, ServiceDiscoveryInfo serviceDiscovery)
          Saves a object related to a city.
 void saveServiceRequestList(String endpointUrl, GETServiceRequestsFilter filter, List<ServiceRequest> requests)
          Saves a list of service requests.
 void saveSingleServiceRequest(String endpointUrl, String serviceRequestId, ServiceRequest request)
          Saves a service request.
 void setCustomTimeToLive(Cache.CacheableOperation operation, int timeToLiveInHours)
          Set a custom time to live to a given operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.codeforamerica.open311.internals.caching.Cache
deleteCache
 

Field Detail

FILE

protected static final String FILE
See Also:
Constant Field Values
Constructor Detail

AbstractCache

public AbstractCache()
Method Detail

saveCitiesInfo

public void saveCitiesInfo(String data)
Description copied from interface: Cache
Saves the endpoints-service discovery relationships.

Specified by:
saveCitiesInfo in interface Cache
Parameters:
data - A JSON list.

retrieveCitiesInfo

public String retrieveCitiesInfo()
Description copied from interface: Cache
Looks for the endpoints-service discovery relationships.

Specified by:
retrieveCitiesInfo in interface Cache
Returns:
A JSON list or null if it wasn't found.

saveServiceDiscovery

public void saveServiceDiscovery(City city,
                                 ServiceDiscoveryInfo serviceDiscovery)
Description copied from interface: Cache
Saves a object related to a city.

Specified by:
saveServiceDiscovery in interface Cache
Parameters:
city - City related to the requested service discovery.
serviceDiscovery - The obtained service discovery.

retrieveCachedServiceDiscoveryInfo

public ServiceDiscoveryInfo retrieveCachedServiceDiscoveryInfo(City city)
Description copied from interface: Cache
Looks for the service discovery of a given city in the local cache.

Specified by:
retrieveCachedServiceDiscoveryInfo in interface Cache
Parameters:
city - City of interest.
Returns:
The service discovery of the given city of null if it isn't cached.

saveListOfServices

public void saveListOfServices(String endpointUrl,
                               List<Service> services)
Description copied from interface: Cache
Saves a list of Service objects related to an endpoint.

Specified by:
saveListOfServices in interface Cache
Parameters:
endpointUrl - Url of the endpoint.
services - Obtained services.

retrieveCachedServiceList

public List<Service> retrieveCachedServiceList(String endpointUrl)
Description copied from interface: Cache
Looks for a cached list of services.

Specified by:
retrieveCachedServiceList in interface Cache
Parameters:
endpointUrl - Url of the endpoint.
Returns:
The list of services or null if they aren't cached.

saveServiceDefinition

public void saveServiceDefinition(String endpointUrl,
                                  String serviceCode,
                                  ServiceDefinition serviceDefinition)
Description copied from interface: Cache
Saves a service definition.

Specified by:
saveServiceDefinition in interface Cache
Parameters:
endpointUrl - Url of the endpoint.
serviceCode - Code of the service.
serviceDefinition - Obtained definition from the server.

retrieveCachedServiceDefinition

public ServiceDefinition retrieveCachedServiceDefinition(String endpointUrl,
                                                         String serviceCode)
Description copied from interface: Cache
Looks for a cached service definition.

Specified by:
retrieveCachedServiceDefinition in interface Cache
Parameters:
endpointUrl - Url of the endpoint.
serviceCode - Service code of the desired service.
Returns:
A service definition or null if it isn't cached.

saveServiceRequestList

public void saveServiceRequestList(String endpointUrl,
                                   GETServiceRequestsFilter filter,
                                   List<ServiceRequest> requests)
Description copied from interface: Cache
Saves a list of service requests.

Specified by:
saveServiceRequestList in interface Cache
Parameters:
endpointUrl - Url of the endpoint.
filter - Filter sent to the endpoint.
requests - Obtained list of requests.

retrieveCachedServiceRequests

public List<ServiceRequest> retrieveCachedServiceRequests(String endpointUrl,
                                                          GETServiceRequestsFilter filter)
Description copied from interface: Cache
Looks for a cached GET service requests response.

Specified by:
retrieveCachedServiceRequests in interface Cache
Parameters:
endpointUrl - Url of the endpoint.
filter - The desired filter.
Returns:
A list of ServiceRequest or null if they aren't cached.

saveSingleServiceRequest

public void saveSingleServiceRequest(String endpointUrl,
                                     String serviceRequestId,
                                     ServiceRequest request)
Description copied from interface: Cache
Saves a service request.

Specified by:
saveSingleServiceRequest in interface Cache
Parameters:
endpointUrl - Url of the endpoint.
serviceRequestId - Id of the requested service request.
request - Obtained service request.

retrieveCachedServiceRequest

public ServiceRequest retrieveCachedServiceRequest(String endpointUrl,
                                                   String serviceRequestId)
Description copied from interface: Cache
Looks for a cached GET service request response.

Specified by:
retrieveCachedServiceRequest in interface Cache
Parameters:
endpointUrl - Url of the endpoint.
serviceRequestId - The service request's id.
Returns:
A ServiceRequest or null if it wasn't cached.

setCustomTimeToLive

public void setCustomTimeToLive(Cache.CacheableOperation operation,
                                int timeToLiveInHours)
Description copied from interface: Cache
Set a custom time to live to a given operation.

Specified by:
setCustomTimeToLive in interface Cache
Parameters:
operation - Operation which time to live will be changed.
timeToLiveInHours - New time to live (in hours).

saveProperty

protected abstract void saveProperty(String key,
                                     String value)
Saves a property. The given parameters must be valid strings with content (empty or null strings are not allowed).

Parameters:
key - Key of the property.
value - Value of the property.

getProperty

protected abstract String getProperty(String key)
Retrieves a property.

Parameters:
key - Key of the property (empty or null strings are not allowed).
Returns:
The property value of null if the key doesn't exist.


Copyright © 2013 Code for America. All Rights Reserved.