final List<String> l = FileUtils.readLines(f, "UTF-8");
log.debug("tot line:" + l.size());
final Datastore ds = MongoConnectionHelper.ds;
log.debug("hasHeader: " + hasHeader);
int lineCount = 0;
int lineDouble = 0;
for (String s : l) {
if (hasHeader) {
hasHeader = false;
continue;
}
final String[] columns = s.split(";");
List<Meteolog> check = ds.createQuery(Meteolog.class).field("time").equal(getDate("dd-MM-yyyy HH:mm", columns[1], log)).asList();
if (check != null && !check.isEmpty()) {
log.debug("data exist, continue");
lineDouble++;
continue;
}
final Meteolog meteoLog = new Meteolog();
try {
meteoLog.setN(Integer.valueOf(columns[0]));
} catch (Exception e) {
log.error("line skipped " + lineCount, e);
continue;
}
try {
meteoLog.setTime(getDate("dd-MM-yyyy HH:mm", columns[1], log));
} catch (Exception e) {
log.error("line skipped" + lineCount, e);
continue;
}
try {
meteoLog.setInterval(Integer.valueOf(columns[2]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setIndoorHumidity(Double.valueOf(columns[3]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setIndoorTemperature(Double.valueOf(columns[4]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setOutdoorHumidity(Double.valueOf(columns[5]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setOutdoorTemperature(Double.valueOf(columns[6]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setAbsolutePressure(Double.valueOf(columns[7]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setWind(Double.valueOf(columns[8]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setGust(Double.valueOf(columns[9]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setDirection(columns[10]);
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setRelativePressure(Double.valueOf(columns[11]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setDewpoint(Double.valueOf(columns[12]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setWindChill(Double.valueOf(columns[13]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setHourRainfall(Double.valueOf(columns[14]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setDayRainfall(Double.valueOf(columns[15]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setWeekRainfall(Double.valueOf(columns[16]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setMonthRainfall(Double.valueOf(columns[17]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setTotalRainfall(Double.valueOf(columns[18]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setWindLevel(Double.valueOf(columns[19]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
try {
meteoLog.setGustLevel(Double.valueOf(columns[20]));
} catch (Exception e) {
log.error("line " + lineCount, e);
}
ds.save(meteoLog, WriteConcern.NORMAL);
lineCount++;
}
log.debug("Tot line insert:" + lineCount);