(cherry picked from commit 13fcd30)
This commit is contained in:
Chumva 2018-08-01 18:31:38 +03:00
parent f4b02deb68
commit 5be05c6848

View file

@ -14,10 +14,14 @@ import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@ -77,7 +81,7 @@ public class IncrementalChangesManager {
List<String> list = new ArrayList<String>(regionUpdateFiles.monthUpdates.keySet());
for (String month : list) {
RegionUpdate ru = regionUpdateFiles.monthUpdates.get(month);
if (ru.obfCreated < dateCreated) {
if (ru.obfCreated < dateCreated || checkIfItemOutdated(ru, dateCreated)) {
log.info("Delete overlapping month update " + ru.file.getName());
resourceManager.closeFile(ru.file.getName());
regionUpdateFiles.monthUpdates.remove(month);
@ -97,7 +101,7 @@ public class IncrementalChangesManager {
if(ru == null) {
continue;
}
if (ru.obfCreated < dateCreated ||
if (ru.obfCreated < dateCreated || (checkIfItemOutdated(ru, dateCreated)) ||
(monthRu != null && ru.obfCreated < monthRu.obfCreated)) {
log.info("Delete overlapping day update " + ru.file.getName());
resourceManager.closeFile(ru.file.getName());
@ -411,4 +415,25 @@ public class IncrementalChangesManager {
}
return timestamp;
}
private boolean checkIfItemOutdated(RegionUpdate ru, long dateMainMapCreated) {
boolean outdated = false;
Date strDate = null;
String date = ru.date;
if (!Algorithms.isEmpty(date) && ru.obfCreated == dateMainMapCreated) {
try {
if (date.endsWith("00")) {
strDate = new SimpleDateFormat("yy_MM", Locale.getDefault()).parse(date);
} else {
strDate = new SimpleDateFormat("yy_MM_dd", Locale.getDefault()).parse(date);
}
} catch (ParseException e) {
e.printStackTrace();
}
if (new Date(dateMainMapCreated).after(strDate)) {
outdated = true;
}
}
return outdated;
}
}