// Update the start date for next time. The parameter the updateProgressDate is the date
// of that retrieveHistory had gotten to when it completed or gave up.
// If lastSync is set and is < updateProgressDate we will use that, and otherwise use updateProgressDate.
void updateStartDate(UpdateInfo updateInfo, ObjectType ot, DateTime updateProgressTime)
{
DateTimeComparator comparator = DateTimeComparator.getDateOnlyInstance();
// Calculate the name of the key in the ApiAttributes table
// where the next start of update for this object type is
// stored and retrieve the stored value. This stored value
// may potentially be null if something happened to the attributes table
String updateKeyName = "BodyMedia." + ot.getName() + ".updateStartDate";
String storedUpdateStartDate = guestService.getApiKeyAttribute(updateInfo.apiKey, updateKeyName);
// Retrieve the lastSync date if it has been added to the
// updateInfo context by an extractor
DateTime lastSync = (DateTime)updateInfo.getContext("lastSync");
// Check which is earlier: the lastSync time returned from Bodymedia or the
// point we were in the update that just ended. Store the lesser of the two
// in nextUpdateStartDate
String nextUpdateStartDate = storedUpdateStartDate;
if (lastSync != null) {
if (comparator.compare(updateProgressTime, lastSync) > 0) {
// lastSync from Bodymedia is less than the update progress
nextUpdateStartDate = lastSync.toString(formatter);
}
else {
// the update progress is less than lastSync from Bodymedia