Created
June 21, 2013 20:34
-
-
Save lmeadors/5834121 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private BorrowedListMessage getResponse(boolean forceRefresh) { | |
final BorrowedListMessage response; | |
if (forceRefresh) { | |
// force is true - try the service | |
final BorrowedListMessage serviceResponse = borrowedService.getBorrowed(patron); | |
if (serviceResponse.getResponseStatus().equals(ResponseStatus.OK)) { | |
// service response is good - use it | |
response = serviceResponse; | |
} else { | |
// service response is bad - try the cached data | |
final BorrowedListMessage cachedResponse = state.getBorrowed(context); | |
if (null == cachedResponse) { | |
// cached data is bunk - use the failing service response | |
response = serviceResponse; | |
} else { | |
// cache is good - use it | |
response = cachedResponse; | |
} | |
} | |
} else { | |
// force is false - try the cached data | |
final BorrowedListMessage cachedResponse = state.getBorrowed(context); | |
if (null != cachedResponse) { | |
// cached data is good - use it | |
response = cachedResponse; | |
} else { | |
// cached data is bunk - use the service response, regardless of it's outcome | |
response = borrowedService.getBorrowed(patron); | |
} | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment