From b021ed9a2adc136f848ce02ae906f1b984a87dac Mon Sep 17 00:00:00 2001 From: Jean-Michel Glorian Date: Tue, 17 May 2016 10:16:44 +0200 Subject: [PATCH] catch the exception when a value of the granule is not present --- src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java index 5949fc0..0386a89 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java @@ -42,16 +42,38 @@ public class GranuleCtrl { } private String parseString(int rowId, GranuleEnum granuleEnum) { - return (String) data.getCell(rowId, granuleEnum.toString()); + String res = ""; + try { + res = (String) data.getCell(rowId, granuleEnum.toString()); + } catch (Exception e) { + logger.warning(granuleEnum + "not found in the rowId" + rowId + + ": return an empty string"); + } + return res; } private Date parseDate(int rowId, GranuleEnum granuleEnum) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); - return sdf.parse((String) data.getCell(rowId, granuleEnum.toString())); + Date date = new Date(); + try { + date = sdf.parse((String) data.getCell(rowId, granuleEnum.toString())); + } catch (Exception e) { + logger.warning(granuleEnum + "not found in the rowId" + rowId + + ": return an empty Date"); + } + + return date; } private Double parseDouble(int rowId, GranuleEnum granuleEnum) { - Double d = (Double) data.getCell(rowId, granuleEnum.toString()); + Double d = null; + try { + d = (Double) data.getCell(rowId, granuleEnum.toString()); + } catch (Exception e) { + logger.warning(granuleEnum + "not found in the rowId" + rowId + + ": return a Double.NaN"); + } + return d == null ? Double.NaN : d; } @@ -103,7 +125,7 @@ public class GranuleCtrl { g.instrumentHostName = parseString(rowId, GranuleEnum.INSTRUMENT_HOST_NAME); g.instrumentName = parseString(rowId, GranuleEnum.INSTRUMENT_NAME); g.measurementType = parseString(rowId, GranuleEnum.MEASUREMENT_TYPE); - g.processingLevel = (Integer) data.getCell(rowId, GranuleEnum.PROCESSING_LEVEL.toString()); + g.processingLevel = parseInteger(rowId); g.creationDate = parseDate(rowId, GranuleEnum.CREATION_DATE); g.modificationDate = parseDate(rowId, GranuleEnum.MODIFICATION_DATE) ; g.releaseDate = parseDate(rowId, GranuleEnum.RELEASE_DATE) ; @@ -116,6 +138,20 @@ public class GranuleCtrl { return g; } + /** + * @param rowId + * @return + */ + public Integer parseInteger(int rowId) { + Integer val = 0; + try { + val = (Integer) data.getCell(rowId, GranuleEnum.PROCESSING_LEVEL.toString()); + } catch (Exception e) { + // TODO: handle exception + } + return val; + } + public static boolean isV2(VOTableData data) { return !data.isContainingColumnName("index"); } @@ -129,8 +165,10 @@ public class GranuleCtrl { } List granules = new ArrayList<>(); - for (int rowId = 0; rowId < data.getNbRows(); rowId++) { - granules.add(getGranuleFromVOTableRow(rowId)); + if (data != null){ + for (int rowId = 0; rowId < data.getNbRows(); rowId++) { + granules.add(getGranuleFromVOTableRow(rowId)); + } } return granules; } -- libgit2 0.21.2