Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/main/java/fun/wilddev/geo/importer/LocationFileImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,36 @@ public int startImport() throws FileReaderException {
String[] line;
List<LocationD> buff = new ArrayList<>(BUFF_SIZE);

for (int i = 0; (line = csv.readNext()) != null; i++) {
while ((line = csv.readNext()) != null) {

if (i % BUFF_SIZE == 0) {
if (line.length < 3) {

locationRepository.saveAll(buff);
buff.clear();

log.debug("Flushed");
log.debug("Bad entry, skipping ...");
continue;
}

} else {
LocationD location = new LocationD(new Country(line[1], line[0]), line[2]);

if (line.length < 3) {
buff.add(location);
counter++;

log.debug("Bad entry, skipping ...");
continue;
}
log.info("Location read: {}", location);

LocationD location = new LocationD(new Country(line[1], line[0]), line[2]);
if (buff.size() >= BUFF_SIZE) {

buff.add(location);
counter++;
locationRepository.saveAll(buff);
buff.clear();

log.info("Location read: {}", location);
log.debug("Flushed");
}
}

if (!buff.isEmpty()) {

locationRepository.saveAll(buff);
log.debug("Flushed remaining");
}

} catch (Exception ex) {
throw new FileReaderException("Failed to read location file", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public Location find(@NonNull String ip) throws HttpRequestFailedException {

val source = response.bodyTo(IpStackLocationResponse.class);

if (source == null)
throw new HttpRequestFailedException("null response");

if (source.getSuccess() == Boolean.FALSE)
throw new HttpRequestFailedException("Request rejected: " + source);

Expand Down
Loading