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 | 42 | } |
43 | 43 | |
44 | 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 | 55 | private Date parseDate(int rowId, GranuleEnum granuleEnum) throws ParseException { |
49 | 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 | 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 | 77 | return d == null ? Double.NaN : d; |
56 | 78 | } |
57 | 79 | |
... | ... | @@ -103,7 +125,7 @@ public class GranuleCtrl { |
103 | 125 | g.instrumentHostName = parseString(rowId, GranuleEnum.INSTRUMENT_HOST_NAME); |
104 | 126 | g.instrumentName = parseString(rowId, GranuleEnum.INSTRUMENT_NAME); |
105 | 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 | 129 | g.creationDate = parseDate(rowId, GranuleEnum.CREATION_DATE); |
108 | 130 | g.modificationDate = parseDate(rowId, GranuleEnum.MODIFICATION_DATE) ; |
109 | 131 | g.releaseDate = parseDate(rowId, GranuleEnum.RELEASE_DATE) ; |
... | ... | @@ -116,6 +138,20 @@ public class GranuleCtrl { |
116 | 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 | 155 | public static boolean isV2(VOTableData data) { |
120 | 156 | return !data.isContainingColumnName("index"); |
121 | 157 | } |
... | ... | @@ -129,8 +165,10 @@ public class GranuleCtrl { |
129 | 165 | } |
130 | 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 | 173 | return granules; |
136 | 174 | } | ... | ... |