Commit 8d5016bccf5d2d0becae81ef45185d50e5fafb13

Authored by Nathanael Jourdane
1 parent 3a42858d

bugFix: do not use as 'select' array and convert query results as string

js/app/controllers/EpnTapModule.js
... ... @@ -26,7 +26,6 @@ Ext.define('amdaDesktop.EpnTapModule', {
26 26 Module initialisation.
27 27 */
28 28 init: function() {
29   - this.select = Array();
30 29 this.filter = Array();
31 30 this.selectedServiceId = null;
32 31  
... ... @@ -261,12 +260,12 @@ Ext.define('amdaDesktop.EpnTapModule', {
261 260 var newPageNumber = 1;
262 261 var limit = Number(this.rowsPerPageNf.value);
263 262 var offset = 0;
264   - var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
  263 + var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data;
265 264  
266 265 this.wait();
267 266 this.disableNavBtns(true, true, false, false);
268 267 this.currentPageLb.setText('' + newPageNumber);
269   - AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
  268 + AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, limit, offset, this.fillGranules);
270 269 },
271 270  
272 271 /**
... ... @@ -277,13 +276,13 @@ Ext.define('amdaDesktop.EpnTapModule', {
277 276 var newPageNumber = Number(this.currentPageLb.text) - 1;
278 277 var limit = Number(this.rowsPerPageNf.value);
279 278 var offset = (newPageNumber-1) * limit;
280   - var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
  279 + var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data;
281 280  
282 281 this.wait();
283 282 this.currentPageLb.setText('' + newPageNumber);
284 283 var isFirstPage = this.currentPageLb.text === '1';
285 284 this.disableNavBtns(isFirstPage, isFirstPage, false, false);
286   - AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
  285 + AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, limit, offset, this.fillGranules);
287 286 },
288 287  
289 288 /**
... ... @@ -294,13 +293,13 @@ Ext.define('amdaDesktop.EpnTapModule', {
294 293 var newPageNumber = Number(this.currentPageLb.text) + 1;
295 294 var limit = Number(this.rowsPerPageNf.value);
296 295 var offset = (newPageNumber-1) * limit;
297   - var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
  296 + var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data;
298 297  
299 298 this.wait();
300 299 this.currentPageLb.setText('' + newPageNumber);
301 300 var isLastPage = this.currentPageLb.text == this.totalPagesLb.text;
302 301 this.disableNavBtns(false, false, isLastPage, isLastPage);
303   - AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
  302 + AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, limit, offset, this.fillGranules);
304 303 },
305 304  
306 305 /**
... ... @@ -311,12 +310,12 @@ Ext.define('amdaDesktop.EpnTapModule', {
311 310 var newPageNumber = Number(this.totalPagesLb.text);
312 311 var limit = Number(this.rowsPerPageNf.value);
313 312 var offset = (newPageNumber-1) * limit;
314   - var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl'];
  313 + var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data;
315 314  
316 315 this.wait();
317 316 this.currentPageLb.setText('' + newPageNumber);
318 317 this.disableNavBtns(false, false, true, true);
319   - AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules);
  318 + AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, limit, offset, this.fillGranules);
320 319 },
321 320  
322 321 /*******************
... ... @@ -331,21 +330,13 @@ Ext.define('amdaDesktop.EpnTapModule', {
331 330 // console.log("Selected service " + selectedServiceId);
332 331 this.wait();
333 332 this.selectedServiceId = selectedServiceId;
334   - this.select = Array();
335   -
336 333 var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data;
337   - console.log(selectedService);
  334 +
338 335 if (selectedService == null) {
339 336 throw this.selectedServiceId + ' not found in the list of services.';
340 337 return;
341 338 }
342 339  
343   - var columns = selectedService['columns'].split(',');
344   - for (var ic=0 ; ic<this.granulesGrid.columns.length ; ic++) {
345   - if (columns.indexOf(this.granulesGrid.columns[ic].dataIndex) != -1) {
346   - this.select.push(this.granulesGrid.columns[ic].dataIndex);
347   - }
348   - }
349 340 this.filter = Array(
350 341 this.productTypeCB.value === 'all' ? null : this.productTypeCB.value, // product type
351 342 this.targetNameCB.value === 'all' ? null : this.targetNameCB.value, // target name
... ... @@ -353,9 +344,8 @@ Ext.define(&#39;amdaDesktop.EpnTapModule&#39;, {
353 344 Ext.Date.format(this.timeSelector.getStopTime(), 'd/m/Y H:i:s') // stop time
354 345 );
355 346  
356   - // console.log(selectedServiceId, selectedService['access_url'], this.filter);
357   - AmdaAction.epnTapGetNbRows(selectedServiceId, selectedService['access_url'], this.filter, this.updateNbRows);
358   - AmdaAction.epnTapGetGranules(selectedServiceId, selectedService['access_url'], this.filter, this.select, this.rowsPerPageNf.value, 0, this.fillGranules);
  347 + AmdaAction.epnTapGetNbRows(selectedService['table_name'], selectedService['access_url'], this.filter, this.updateNbRows);
  348 + AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, this.rowsPerPageNf.value, 0, this.fillGranules);
359 349 },
360 350  
361 351 /**
... ...
php/classes/AmdaAction.php
... ... @@ -1341,8 +1341,8 @@ class AmdaAction {
1341 1341 return array('success' => true, 'alreadyUsed' => $alreadyUsed);
1342 1342 }
1343 1343  
1344   - public function epnTapGetGranules($table_name, $access_url, $filter, $select, $limit, $offset) {
1345   - return (new EpnTapMgr)->getGranules($table_name, $access_url, $filter, $select, $limit, $offset);
  1344 + public function epnTapGetGranules($table_name, $access_url, $filter, $limit, $offset) {
  1345 + return (new EpnTapMgr)->getGranules($table_name, $access_url, $filter, $limit, $offset);
1346 1346 }
1347 1347  
1348 1348 public function epnTapGetNbRows($table_name, $access_url, $filter) {
... ...
php/classes/EpnTapMgr.php
... ... @@ -38,18 +38,20 @@ class EpnTapMgr {
38 38 $params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery';
39 39 $url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode(preg_replace('/\s+/', ' ', $query)); // remove also multiple whitespaces
40 40  
41   - $res = $votMgr->load($url);
42   - error_log("Query URL: " . $url);
  41 + $votMgr->load($url);
  42 +
43 43 $result = $votMgr->parseStream();
44 44 return $votMgr->getVotableError() ? array('error' => $votMgr->getVotableError()) : $result;
45 45 }
46 46  
47 47 /* filter order: product type, target name, time min, time max */
48   - public function getGranules($table_name, $access_url, $filter, $select, $limit, $offset) {
49   - $query = "SELECT TOP {$limit} " . join(', ', $select) . " FROM {$table_name}.epn_core " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]) . " OFFSET {$offset}";
  48 + public function getGranules($table_name, $access_url, $filter, $limit, $offset) {
  49 +
  50 + $query = "SELECT TOP {$limit} * FROM {$table_name} " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]) . " OFFSET {$offset}";
50 51 $result = $this->request($access_url, $query);
51 52 if(! array_key_exists("error", $result)) {
52   - for ($i = 0 ; $i < sizeof($result) ; $i++) {
  53 +
  54 + for ($i = 0 ; $i < count($result) ; $i++) {
53 55 $result[$i]['num'] = $i + $offset + 1;
54 56 $result[$i]['time_min'] = $this->JDTodate($result[$i]['time_min']);
55 57 $result[$i]['time_max'] = $this->JDTodate($result[$i]['time_max']);
... ... @@ -89,8 +91,9 @@ class EpnTapMgr {
89 91  
90 92 /* filter order: product type, target name, time min, time max */
91 93 public function getNbRows($table_name, $access_url, $filter) {
92   - $query = "SELECT COUNT(*) AS nb_rows FROM {$table_name}.epn_core " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]);
93   - return $this->request($access_url, $query)[0]['nb_rows'];
  94 + $query = "SELECT COUNT(*) AS nb_rows FROM {$table_name} " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]);
  95 + $result = $this->request($access_url, $query)[0]['nb_rows'];
  96 + return $result;
94 97 }
95 98  
96 99 }
... ...
php/classes/VOTableMgr.php
... ... @@ -34,7 +34,7 @@ class VOTableMgr {
34 34 $this->xml = new DomDocument();
35 35  
36 36 try {
37   - $res = $this->xml->load($fileName);
  37 + $load_res = $this->xml->load($fileName);
38 38 } catch (Exception $e) {
39 39 $this->votable_error = $e->message;
40 40 return false;
... ... @@ -55,13 +55,11 @@ class VOTableMgr {
55 55  
56 56 function isValidSchema() {
57 57 if ($this->votable_error != false) {
58   - error_log("There is an error on the VOTable: " . $this->votable_error);
59 58 return false;
60 59 }
61 60  
62 61 if (!$this->xml) {
63 62 $this->votable_error = "The returned file is not XML.";
64   - error_log("There is an error on the VOTable: " . $this->votable_error);
65 63 return false;
66 64 }
67 65  
... ... @@ -69,7 +67,6 @@ class VOTableMgr {
69 67 foreach($infos as $info) {
70 68 if($info->getAttribute('value') == 'ERROR') {
71 69 $this->votable_error = $info->textContent;
72   - error_log("There is an error on the VOTable: " . $this->votable_error);
73 70 return false;
74 71 }
75 72 }
... ... @@ -254,11 +251,12 @@ class VOTableMgr {
254 251 /** Get the VOTable stream content.*/
255 252 public function parseStream() {
256 253 if (! $this->isValidSchema()) {
  254 + error_log('There is an error on the VOTable: ' . $this->votable_error);
257 255 return null;
258   - // TODO: check this
259 256 }
260 257 $data = Array();
261 258 $fields = $this->xp->query($this->queryFields());
  259 + $resource = $this->xp->query($this->queryResource());
262 260 $nb_columns = $fields->length;
263 261 $row = Array();
264 262 $n_value = 0; // index of current value
... ... @@ -266,13 +264,13 @@ class VOTableMgr {
266 264 $query_stream = $this->xp->query($this->queryStream())->item(0);
267 265 if($query_stream == NULL) {
268 266 $this->votable_error = "There is no STREAM node in the VOTable file.";
269   - return NULL;
  267 + return null;
270 268 }
271 269 $this->stream = base64_decode($query_stream->textContent);
272 270 $stream_len = strlen($this->stream);
273 271 if($stream_len == 0) {
274 272 $this->votable_error = "There is no result for this query.";
275   - return NULL;
  273 + return null;
276 274 }
277 275 while($this->c < strlen($this->stream)) {
278 276 $col_id = $n_value % $nb_columns;
... ... @@ -342,7 +340,7 @@ class VOTableMgr {
342 340 break;
343 341 }
344 342 $this->c+=$row_size;
345   - return $res;
  343 + return (string)$res;
346 344 }
347 345  
348 346  
... ...
php/config.php
... ... @@ -384,7 +384,7 @@ $API = array(
384 384 'isSharedObjectNameAlreadyUsed' => array(
385 385 'len'=>1
386 386 ),
387   - 'epnTapGetGranules' => array('len'=>6),
  387 + 'epnTapGetGranules' => array('len'=>5),
388 388 'epnTapGetNbRows' => array('len'=>3),
389 389 'epnTapGetServices' => array('len'=>0)
390 390 )
... ...