Commit e480d2ae68f8247fdca0ed51e8fd939d679f97d3

Authored by Nathanael Jourdane
1 parent dda6052c
Exists in master and in 1 other branch b6.0.X

Make readTable() private and use newVOTable() and appendVOTable() instead, to avoid confusions.

src/main/java/eu/omp/irap/vespa/votable/VOTableApp.java
... ... @@ -56,17 +56,16 @@ public class VOTableApp {
56 56 .info("Lauching VOTable app with arguments: " + StringJoiner.join(args));
57 57 VOTableController ctrl;
58 58  
59   - if (args.length == 1) {
60   - ctrl = new VOTableController(args[0]);
61   - } else if (args.length == 2) {
62   - ctrl = new VOTableController(args[0], args[1]);
63   - } else {
64   - System.console().writer().println(VOTableApp.WRONG_COMMAND);
65   - return;
66   - }
67   -
  59 + ctrl = new VOTableController();
68 60 try {
69   - ctrl.readTable();
  61 + if (args.length == 1) {
  62 + ctrl.newVOTable(args[0]);
  63 + } else if (args.length == 2) {
  64 + ctrl.newVOTable(args[0], args[1]);
  65 + } else {
  66 + System.console().writer().println(VOTableApp.WRONG_COMMAND);
  67 + return;
  68 + }
70 69 } catch (VOTableException e) {
71 70 VOTableApp.LOGGER.log(Level.WARNING, e.getMessage(), e);
72 71 return;
... ...
src/main/java/eu/omp/irap/vespa/votable/controller/VOTableController.java
... ... @@ -63,27 +63,6 @@ public class VOTableController {
63 63 }
64 64  
65 65 /**
66   - * Constructor of VOTableController
67   - *
68   - * @param voTablePath The path of a local VOTable to parse.
69   - */
70   - public VOTableController(String voTablePath) {
71   - this.voTablePath = voTablePath;
72   - }
73   -
74   - /**
75   - * Method constructor
76   - *
77   - * @param targetURL The target URL of the registry or service used to get the VOTable.
78   - * @param query The query to ask to the registry or service.
79   - */
80   - public VOTableController(String targetURL, String query) {
81   - voTablePath = null;
82   - this.targetURL = targetURL;
83   - this.query = query;
84   - }
85   -
86   - /**
87 66 * Check the VOTable body.
88 67 *
89 68 * @param voTable The VOTable
... ... @@ -116,6 +95,33 @@ public class VOTableController {
116 95 }
117 96  
118 97 /**
  98 + * Parse a VOTable and append the result to the old one.
  99 + *
  100 + * @param newVOTablePath The path of the new VOTable.
  101 + * @throws VOTableException The VOTable can not be downloaded or parsed.
  102 + */
  103 + public void appendVOTable(String newVOTablePath) throws VOTableException {
  104 + voTablePath = newVOTablePath;
  105 + targetURL = null;
  106 + query = null;
  107 + readTable();
  108 + }
  109 +
  110 + /**
  111 + * Download and parse a VOTable, then append the result to the old one.
  112 + *
  113 + * @param newTargetURL The new target URL of the registry or service used to get the VOTable.
  114 + * @param newQuery The new query to ask to the registry or service.
  115 + * @throws VOTableException The VOTable can not be downloaded or parsed.
  116 + */
  117 + public void appendVOTable(String newTargetURL, String newQuery) throws VOTableException {
  118 + voTablePath = null;
  119 + targetURL = newTargetURL;
  120 + query = newQuery;
  121 + readTable();
  122 + }
  123 +
  124 + /**
119 125 * Display an informative message to the user.
120 126 *
121 127 * @param shortMessage A short version of the message.
... ... @@ -127,6 +133,50 @@ public class VOTableController {
127 133 }
128 134  
129 135 /**
  136 + * @return The VOTable as a VOTABLE object (corresponding to the XSD).
  137 + */
  138 + public VOTABLE getVOTable() {
  139 + return voTable;
  140 + }
  141 +
  142 + /**
  143 + * @return The VOTableData object representing the data stored in the VOTable.
  144 + */
  145 + public VOTableData getVOTableData() {
  146 + return voTableData;
  147 + }
  148 +
  149 + /**
  150 + * @return The path of the local VOTable.
  151 + */
  152 + public String getVOTablePath() {
  153 + return voTablePath;
  154 + }
  155 +
  156 + /**
  157 + * Parse a VOTable and override the result to the old one.
  158 + *
  159 + * @param newVOTablePath The path of the new VOTable.
  160 + * @throws VOTableException The VOTable can not be downloaded or parsed.
  161 + */
  162 + public void newVOTable(String newVOTablePath) throws VOTableException {
  163 + voTableData = null;
  164 + appendVOTable(newVOTablePath);
  165 + }
  166 +
  167 + /**
  168 + * Parse a VOTable and override the result to the old one.
  169 + *
  170 + * @param newTargetURL The new target URL of the registry or service used to get the VOTable.
  171 + * @param newQuery The new query to ask to the registry or service.
  172 + * @throws VOTableException The VOTable can not be downloaded or parsed.
  173 + */
  174 + public void newVOTable(String newTargetURL, String newQuery) throws VOTableException {
  175 + voTableData = null;
  176 + appendVOTable(newTargetURL, newQuery);
  177 + }
  178 +
  179 + /**
130 180 * Send the specified query to a service or registry and get the resulting VOTable.
131 181 *
132 182 * @param targetUrl The target URL of the registry or service used to get the VOTable.
... ... @@ -134,7 +184,7 @@ public class VOTableController {
134 184 * @return The path of the downloaded VOTable.
135 185 * @throws CantGetVOTableException The VOTable can not be donwloaded.
136 186 */
137   - public String downloadVOTable(String targetUrl, String newQuery)
  187 + private String downloadVOTable(String targetUrl, String newQuery)
138 188 throws CantGetVOTableException {
139 189 String url = targetUrl + "/sync";
140 190 // TODO: why do not use query and voTablePath instead of newQuery and newVoTablePath?
... ... @@ -159,32 +209,11 @@ public class VOTableController {
159 209 }
160 210  
161 211 /**
162   - * @return The VOTable as a VOTABLE object (corresponding to the XSD).
163   - */
164   - public VOTABLE getVOTable() {
165   - return voTable;
166   - }
167   -
168   - /**
169   - * @return The VOTableData object representing the data stored in the VOTable.
170   - */
171   - public VOTableData getVOTableData() {
172   - return voTableData;
173   - }
174   -
175   - /**
176   - * @return The path of the local VOTable.
177   - */
178   - public String getVOTablePath() {
179   - return voTablePath;
180   - }
181   -
182   - /**
183 212 * Download the VOTable, parse it, and save the content in voTableData.
184 213 *
185 214 * @throws VOTableException If the VOTable can not be downloaded or parsed.
186 215 */
187   - public void readTable() throws VOTableException {
  216 + private void readTable() throws VOTableException {
188 217 if (voTablePath == null) {
189 218 voTablePath = downloadVOTable(targetURL, query);
190 219 }
... ... @@ -204,33 +233,4 @@ public class VOTableController {
204 233 }
205 234  
206 235 }
207   -
208   - /**
209   - * Parse a new VOTable and update the old one.
210   - *
211   - * @param newVOTablePath The path of the new VOTable.
212   - * @throws VOTableException The VOTable can not be downloaded or parsed.
213   - */
214   - public void updateVOTable(String newVOTablePath) throws VOTableException {
215   - voTablePath = newVOTablePath;
216   - voTableData = null;
217   - targetURL = null;
218   - query = null;
219   - readTable();
220   - }
221   -
222   - /**
223   - * Download and parse a new VOTable and update the old one.
224   - *
225   - * @param newTargetURL The new target URL of the registry or service used to get the VOTable.
226   - * @param newQuery The new query to ask to the registry or service.
227   - * @throws VOTableException The VOTable can not be downloaded or parsed.
228   - */
229   - public void updateVOTable(String newTargetURL, String newQuery) throws VOTableException {
230   - voTablePath = null;
231   - voTableData = null;
232   - targetURL = newTargetURL;
233   - query = newQuery;
234   - readTable();
235   - }
236 236 }
... ...