private int importCsv(FileItem item) throws IOException, TranslatableException {
CSVReader csvReader = new CSVReader(new InputStreamReader(item.getInputStream()));
DataPointDao dataPointDao = new DataPointDao();
PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss");
// Basic validation
String[] nextLine = csvReader.readNext();
if (nextLine == null)
throw new TranslatableException(new TranslatableMessage("dataImport.import.noData"));
if (nextLine.length < 2)
throw new TranslatableException(new TranslatableMessage("dataImport.import.noPoints"));
// Find the points by XID
DataPointVO[] vos = new DataPointVO[nextLine.length - 1];
for (int i = 1; i < nextLine.length; i++) {
if (StringUtils.isBlank(nextLine[i]))
throw new TranslatableException(new TranslatableMessage("dataImport.import.badXid", i));
DataPointVO vo = dataPointDao.getDataPoint(nextLine[i]);
if (vo == null)
throw new TranslatableException(new TranslatableMessage("dataImport.import.xidNotFound", nextLine[i]));
vos[i - 1] = vo;
}
// Find the RTs for the points if they are enabled
DataPointRT[] rts = new DataPointRT[vos.length];
for (int i = 0; i < vos.length; i++)
rts[i] = Common.runtimeManager.getDataPoint(vos[i].getId());
// Import the data
int count = 0;
while ((nextLine = csvReader.readNext()) != null) {
// The first value is always a date.
long time = dtf.parseDateTime(nextLine[0]).getMillis();
// The rest of the values are point samples.
for (int i = 1; i < nextLine.length; i++) {
DataValue value = DataValue.stringToValue(nextLine[i], vos[i - 1].getPointLocator().getDataTypeId());
PointValueTime pvt = new PointValueTime(value, time);