Commit 1f971475f1df7acff93cb0419e4239b051593a12
1 parent
f2e9bb55
Exists in
master
Granule parsing: replace IllegalArgumentException by a custom one.
Showing
5 changed files
with
32 additions
and
24 deletions
Show diff stats
.classpath
... | ... | @@ -38,5 +38,7 @@ |
38 | 38 | <attribute name="maven.pomderived" value="true"/> |
39 | 39 | </attributes> |
40 | 40 | </classpathentry> |
41 | + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | |
42 | + <classpathentry combineaccessrules="false" kind="src" path="/VOTableLib"/> | |
41 | 43 | <classpathentry kind="output" path="target/classes"/> |
42 | 44 | </classpath> | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java
... | ... | @@ -32,6 +32,7 @@ import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; |
32 | 32 | import eu.omp.irap.vespa.votable.controller.VOTableController; |
33 | 33 | import eu.omp.irap.vespa.votable.controller.VOTableException; |
34 | 34 | import eu.omp.irap.vespa.votable.controller.VOTableException.CantParseVOTableException; |
35 | +import eu.omp.irap.vespa.votable.utils.Debug; | |
35 | 36 | import eu.omp.irap.vespa.votable.utils.StringJoiner; |
36 | 37 | import eu.omp.irap.vespa.votable.votabledata.VOTableData; |
37 | 38 | |
... | ... | @@ -146,6 +147,7 @@ public class EpnTapConnection implements EpnTapInterface { |
146 | 147 | VOTableController voTableCtrl = new VOTableController(tapURL, query); |
147 | 148 | voTableCtrl.readTable(); |
148 | 149 | VOTableData data = voTableCtrl.getVOTableData(); |
150 | + Debug.writeObject("data", data); | |
149 | 151 | |
150 | 152 | List<Granule> granules; |
151 | 153 | try { | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java
... | ... | @@ -24,6 +24,7 @@ import java.util.List; |
24 | 24 | import java.util.logging.Level; |
25 | 25 | import java.util.logging.Logger; |
26 | 26 | |
27 | +import eu.omp.irap.vespa.votable.controller.VOTableException.CanNotParseDataException; | |
27 | 28 | import eu.omp.irap.vespa.votable.votabledata.VOTableData; |
28 | 29 | |
29 | 30 | /** |
... | ... | @@ -56,8 +57,9 @@ public class GranuleCtrl { |
56 | 57 | * @param rowId The row identifier |
57 | 58 | * @param granule The Granule enumeration, representing the column name. |
58 | 59 | * @return The value as String. |
60 | + * @throws CanNotParseDataException The column name was not found in the list. | |
59 | 61 | */ |
60 | - private String parseString(int rowId, GranuleEnum granule) { | |
62 | + private String parseString(int rowId, GranuleEnum granule) throws CanNotParseDataException { | |
61 | 63 | String res = ""; |
62 | 64 | try { |
63 | 65 | res = (String) data.getCell(rowId, granule.toString()); |
... | ... | @@ -74,8 +76,10 @@ public class GranuleCtrl { |
74 | 76 | * @param granule The Granule enumeration, representing the column name. |
75 | 77 | * @return The value as Date. |
76 | 78 | * @throws ParseException The date format is not correct. |
79 | + * @throws CanNotParseDataException The column name was not found in the list. | |
77 | 80 | */ |
78 | - private Date parseDate(int rowId, GranuleEnum granule) throws ParseException { | |
81 | + private Date parseDate(int rowId, GranuleEnum granule) | |
82 | + throws ParseException, CanNotParseDataException { | |
79 | 83 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); |
80 | 84 | Date date = new Date(); |
81 | 85 | try { |
... | ... | @@ -93,19 +97,16 @@ public class GranuleCtrl { |
93 | 97 | * @param rowId The row identifier |
94 | 98 | * @param granule The Granule enumeration, representing the column name. |
95 | 99 | * @return The value as Double. |
100 | + * @throws CanNotParseDataException The column name was not found in the list. | |
96 | 101 | */ |
97 | - private Double parseDouble(int rowId, GranuleEnum granule) { | |
102 | + private Double parseDouble(int rowId, GranuleEnum granule) throws CanNotParseDataException { | |
98 | 103 | Double d = null; |
99 | - try { | |
100 | - Object lObj = data.getCell(rowId, granule.toString()); | |
101 | - if (lObj instanceof Double) { | |
102 | - d = (Double) lObj; | |
103 | - } | |
104 | - if (lObj instanceof Float) { | |
105 | - d = new Double((Float) lObj); | |
106 | - } | |
107 | - } catch (IllegalArgumentException e) { | |
108 | - LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "double.NaN"), e); | |
104 | + Object lObj = data.getCell(rowId, granule.toString()); | |
105 | + if (lObj instanceof Double) { | |
106 | + d = (Double) lObj; | |
107 | + } | |
108 | + if (lObj instanceof Float) { | |
109 | + d = new Double((Float) lObj); | |
109 | 110 | } |
110 | 111 | |
111 | 112 | return d == null ? Double.NaN : d; |
... | ... | @@ -117,15 +118,10 @@ public class GranuleCtrl { |
117 | 118 | * @param rowId The row identifier |
118 | 119 | * @param granule The Granule enumeration, representing the column name. |
119 | 120 | * @return The value as Double. |
121 | + * @throws CanNotParseDataException The column name was not found in the list. | |
120 | 122 | */ |
121 | - public Integer parseInteger(int rowId, GranuleEnum granule) { | |
122 | - Integer val = 0; | |
123 | - try { | |
124 | - val = (Integer) data.getCell(rowId, granule.toString()); | |
125 | - } catch (IllegalArgumentException e) { | |
126 | - LOGGER.log(Level.WARNING, String.format(ERROR_MSG, granule, rowId, "0"), e); | |
127 | - } | |
128 | - return val; | |
123 | + private Integer parseInteger(int rowId, GranuleEnum granule) throws CanNotParseDataException { | |
124 | + return (Integer) data.getCell(rowId, granule.toString()); | |
129 | 125 | } |
130 | 126 | |
131 | 127 | /** |
... | ... | @@ -134,8 +130,10 @@ public class GranuleCtrl { |
134 | 130 | * @param rowId the row identified |
135 | 131 | * @return the granule at the position rowId in the VOTable data. |
136 | 132 | * @throws ParseException If an element can not be parsed (ie., a date). |
133 | + * @throws CanNotParseDataException The column name was not found in the list. | |
137 | 134 | */ |
138 | - public Granule getGranuleFromVOTableRow(int rowId) throws ParseException { | |
135 | + public Granule getGranuleFromVOTableRow(int rowId) | |
136 | + throws ParseException, CanNotParseDataException { | |
139 | 137 | //@noformat |
140 | 138 | Granule g = new Granule(parseString(rowId, GranuleEnum.GRANULE_UID)); |
141 | 139 | g.setGranuleGid(parseString(rowId, GranuleEnum.GRANULE_GID)); |
... | ... | @@ -201,8 +199,9 @@ public class GranuleCtrl { |
201 | 199 | /** |
202 | 200 | * @return A list of Granules from a VOTable, where each Granule is a row of the VOTable data. |
203 | 201 | * @throws ParseException If the granule can not be parsed. |
202 | + * @throws CanNotParseDataException The column name was not found in the list. | |
204 | 203 | */ |
205 | - public List<Granule> getGranules() throws ParseException { | |
204 | + public List<Granule> getGranules() throws ParseException, CanNotParseDataException { | |
206 | 205 | if (!isV2()) { |
207 | 206 | throw new IllegalArgumentException( |
208 | 207 | "The EPN-CORE is not v2, which is the only suported version"); | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java
... | ... | @@ -32,6 +32,7 @@ import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; |
32 | 32 | import eu.omp.irap.vespa.votable.Consts; |
33 | 33 | import eu.omp.irap.vespa.votable.controller.VOTableController; |
34 | 34 | import eu.omp.irap.vespa.votable.controller.VOTableException; |
35 | +import eu.omp.irap.vespa.votable.controller.VOTableException.CanNotParseDataException; | |
35 | 36 | import eu.omp.irap.vespa.votable.utils.StringJoiner; |
36 | 37 | import eu.omp.irap.vespa.votable.votabledata.VOTableData; |
37 | 38 | import eu.omp.irap.vespa.votable.votabledata.VOTableDataParser; |
... | ... | @@ -88,8 +89,10 @@ public class ServiceCtrl { |
88 | 89 | * @param data The VOTableData of the service, created by the VOTable parser. Each row of the |
89 | 90 | * data set is a service. |
90 | 91 | * @return The corresponding list of service. |
92 | + * @throws CanNotParseDataException The column name was not found in the list. | |
91 | 93 | */ |
92 | - public static final List<Service> getServices(VOTableData data) { | |
94 | + public static final List<Service> getServices(VOTableData data) | |
95 | + throws CanNotParseDataException { | |
93 | 96 | List<Service> services = new ArrayList<>(); |
94 | 97 | for (int i = 0; i < data.getNbRows(); i++) { |
95 | 98 | Service service = new Service((String) data.getCell(i, "ivoid")); | ... | ... |
src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java
... | ... | @@ -34,6 +34,7 @@ import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException; |
34 | 34 | import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; |
35 | 35 | import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; |
36 | 36 | import eu.omp.irap.vespa.votable.controller.VOTableException; |
37 | +import eu.omp.irap.vespa.votable.utils.Debug; | |
37 | 38 | import eu.omp.irap.vespa.votable.votabledata.VOTableData; |
38 | 39 | |
39 | 40 | /** |
... | ... | @@ -347,6 +348,7 @@ public class EpnTapConnectionTest { |
347 | 348 | assertEquals(8, granules.size()); |
348 | 349 | Granule mars = null; |
349 | 350 | for (Granule granule : granules) { |
351 | + System.out.println(Debug.toJson(granule)); | |
350 | 352 | if ("Mars".equals(granule.getGranuleUid())) { |
351 | 353 | mars = granule; |
352 | 354 | } | ... | ... |