Commit b021ed9a2adc136f848ce02ae906f1b984a87dac
1 parent
76c297d8
Exists in
master
catch the exception when a value of the granule is not present
Showing
1 changed file
with
44 additions
and
6 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java
@@ -42,16 +42,38 @@ public class GranuleCtrl { | @@ -42,16 +42,38 @@ public class GranuleCtrl { | ||
42 | } | 42 | } |
43 | 43 | ||
44 | private String parseString(int rowId, GranuleEnum granuleEnum) { | 44 | private String parseString(int rowId, GranuleEnum granuleEnum) { |
45 | - return (String) data.getCell(rowId, granuleEnum.toString()); | 45 | + String res = ""; |
46 | + try { | ||
47 | + res = (String) data.getCell(rowId, granuleEnum.toString()); | ||
48 | + } catch (Exception e) { | ||
49 | + logger.warning(granuleEnum + "not found in the rowId" + rowId + | ||
50 | + ": return an empty string"); | ||
51 | + } | ||
52 | + return res; | ||
46 | } | 53 | } |
47 | 54 | ||
48 | private Date parseDate(int rowId, GranuleEnum granuleEnum) throws ParseException { | 55 | private Date parseDate(int rowId, GranuleEnum granuleEnum) throws ParseException { |
49 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); | 56 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); |
50 | - return sdf.parse((String) data.getCell(rowId, granuleEnum.toString())); | 57 | + Date date = new Date(); |
58 | + try { | ||
59 | + date = sdf.parse((String) data.getCell(rowId, granuleEnum.toString())); | ||
60 | + } catch (Exception e) { | ||
61 | + logger.warning(granuleEnum + "not found in the rowId" + rowId + | ||
62 | + ": return an empty Date"); | ||
63 | + } | ||
64 | + | ||
65 | + return date; | ||
51 | } | 66 | } |
52 | 67 | ||
53 | private Double parseDouble(int rowId, GranuleEnum granuleEnum) { | 68 | private Double parseDouble(int rowId, GranuleEnum granuleEnum) { |
54 | - Double d = (Double) data.getCell(rowId, granuleEnum.toString()); | 69 | + Double d = null; |
70 | + try { | ||
71 | + d = (Double) data.getCell(rowId, granuleEnum.toString()); | ||
72 | + } catch (Exception e) { | ||
73 | + logger.warning(granuleEnum + "not found in the rowId" + rowId + | ||
74 | + ": return a Double.NaN"); | ||
75 | + } | ||
76 | + | ||
55 | return d == null ? Double.NaN : d; | 77 | return d == null ? Double.NaN : d; |
56 | } | 78 | } |
57 | 79 | ||
@@ -103,7 +125,7 @@ public class GranuleCtrl { | @@ -103,7 +125,7 @@ public class GranuleCtrl { | ||
103 | g.instrumentHostName = parseString(rowId, GranuleEnum.INSTRUMENT_HOST_NAME); | 125 | g.instrumentHostName = parseString(rowId, GranuleEnum.INSTRUMENT_HOST_NAME); |
104 | g.instrumentName = parseString(rowId, GranuleEnum.INSTRUMENT_NAME); | 126 | g.instrumentName = parseString(rowId, GranuleEnum.INSTRUMENT_NAME); |
105 | g.measurementType = parseString(rowId, GranuleEnum.MEASUREMENT_TYPE); | 127 | g.measurementType = parseString(rowId, GranuleEnum.MEASUREMENT_TYPE); |
106 | - g.processingLevel = (Integer) data.getCell(rowId, GranuleEnum.PROCESSING_LEVEL.toString()); | 128 | + g.processingLevel = parseInteger(rowId); |
107 | g.creationDate = parseDate(rowId, GranuleEnum.CREATION_DATE); | 129 | g.creationDate = parseDate(rowId, GranuleEnum.CREATION_DATE); |
108 | g.modificationDate = parseDate(rowId, GranuleEnum.MODIFICATION_DATE) ; | 130 | g.modificationDate = parseDate(rowId, GranuleEnum.MODIFICATION_DATE) ; |
109 | g.releaseDate = parseDate(rowId, GranuleEnum.RELEASE_DATE) ; | 131 | g.releaseDate = parseDate(rowId, GranuleEnum.RELEASE_DATE) ; |
@@ -116,6 +138,20 @@ public class GranuleCtrl { | @@ -116,6 +138,20 @@ public class GranuleCtrl { | ||
116 | return g; | 138 | return g; |
117 | } | 139 | } |
118 | 140 | ||
141 | + /** | ||
142 | + * @param rowId | ||
143 | + * @return | ||
144 | + */ | ||
145 | + public Integer parseInteger(int rowId) { | ||
146 | + Integer val = 0; | ||
147 | + try { | ||
148 | + val = (Integer) data.getCell(rowId, GranuleEnum.PROCESSING_LEVEL.toString()); | ||
149 | + } catch (Exception e) { | ||
150 | + // TODO: handle exception | ||
151 | + } | ||
152 | + return val; | ||
153 | + } | ||
154 | + | ||
119 | public static boolean isV2(VOTableData data) { | 155 | public static boolean isV2(VOTableData data) { |
120 | return !data.isContainingColumnName("index"); | 156 | return !data.isContainingColumnName("index"); |
121 | } | 157 | } |
@@ -129,8 +165,10 @@ public class GranuleCtrl { | @@ -129,8 +165,10 @@ public class GranuleCtrl { | ||
129 | } | 165 | } |
130 | List<Granule> granules = new ArrayList<>(); | 166 | List<Granule> granules = new ArrayList<>(); |
131 | 167 | ||
132 | - for (int rowId = 0; rowId < data.getNbRows(); rowId++) { | ||
133 | - granules.add(getGranuleFromVOTableRow(rowId)); | 168 | + if (data != null){ |
169 | + for (int rowId = 0; rowId < data.getNbRows(); rowId++) { | ||
170 | + granules.add(getGranuleFromVOTableRow(rowId)); | ||
171 | + } | ||
134 | } | 172 | } |
135 | return granules; | 173 | return granules; |
136 | } | 174 | } |