From 8d5016bccf5d2d0becae81ef45185d50e5fafb13 Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Mon, 12 Jun 2017 11:55:03 +0200 Subject: [PATCH] bugFix: do not use as 'select' array and convert query results as string --- js/app/controllers/EpnTapModule.js | 32 +++++++++++--------------------- php/classes/AmdaAction.php | 4 ++-- php/classes/EpnTapMgr.php | 17 ++++++++++------- php/classes/VOTableMgr.php | 14 ++++++-------- php/config.php | 2 +- 5 files changed, 30 insertions(+), 39 deletions(-) diff --git a/js/app/controllers/EpnTapModule.js b/js/app/controllers/EpnTapModule.js index 7762fbb..73303ae 100644 --- a/js/app/controllers/EpnTapModule.js +++ b/js/app/controllers/EpnTapModule.js @@ -26,7 +26,6 @@ Ext.define('amdaDesktop.EpnTapModule', { Module initialisation. */ init: function() { - this.select = Array(); this.filter = Array(); this.selectedServiceId = null; @@ -261,12 +260,12 @@ Ext.define('amdaDesktop.EpnTapModule', { var newPageNumber = 1; var limit = Number(this.rowsPerPageNf.value); var offset = 0; - var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl']; + var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data; this.wait(); this.disableNavBtns(true, true, false, false); this.currentPageLb.setText('' + newPageNumber); - AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules); + AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, limit, offset, this.fillGranules); }, /** @@ -277,13 +276,13 @@ Ext.define('amdaDesktop.EpnTapModule', { var newPageNumber = Number(this.currentPageLb.text) - 1; var limit = Number(this.rowsPerPageNf.value); var offset = (newPageNumber-1) * limit; - var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl']; + var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data; this.wait(); this.currentPageLb.setText('' + newPageNumber); var isFirstPage = this.currentPageLb.text === '1'; this.disableNavBtns(isFirstPage, isFirstPage, false, false); - AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules); + AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, limit, offset, this.fillGranules); }, /** @@ -294,13 +293,13 @@ Ext.define('amdaDesktop.EpnTapModule', { var newPageNumber = Number(this.currentPageLb.text) + 1; var limit = Number(this.rowsPerPageNf.value); var offset = (newPageNumber-1) * limit; - var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl']; + var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data; this.wait(); this.currentPageLb.setText('' + newPageNumber); var isLastPage = this.currentPageLb.text == this.totalPagesLb.text; this.disableNavBtns(false, false, isLastPage, isLastPage); - AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules); + AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, limit, offset, this.fillGranules); }, /** @@ -311,12 +310,12 @@ Ext.define('amdaDesktop.EpnTapModule', { var newPageNumber = Number(this.totalPagesLb.text); var limit = Number(this.rowsPerPageNf.value); var offset = (newPageNumber-1) * limit; - var selectedServiceURL = Ext.data.StoreManager.lookup('servicesStore').getById(this.selectedServiceId)['accessurl']; + var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data; this.wait(); this.currentPageLb.setText('' + newPageNumber); this.disableNavBtns(false, false, true, true); - AmdaAction.epnTapGetGranules(this.selectedServiceId, selectedServiceURL, this.filter, this.select, limit, offset, this.fillGranules); + AmdaAction.epnTapGetGranules(selectedService['table_name'], selectedService['access_url'], this.filter, limit, offset, this.fillGranules); }, /******************* @@ -331,21 +330,13 @@ Ext.define('amdaDesktop.EpnTapModule', { // console.log("Selected service " + selectedServiceId); this.wait(); this.selectedServiceId = selectedServiceId; - this.select = Array(); - var selectedService = Ext.data.StoreManager.lookup('servicesStore').findRecord('id', selectedServiceId).data; - console.log(selectedService); + if (selectedService == null) { throw this.selectedServiceId + ' not found in the list of services.'; return; } - var columns = selectedService['columns'].split(','); - for (var ic=0 ; ic true, 'alreadyUsed' => $alreadyUsed); } - public function epnTapGetGranules($table_name, $access_url, $filter, $select, $limit, $offset) { - return (new EpnTapMgr)->getGranules($table_name, $access_url, $filter, $select, $limit, $offset); + public function epnTapGetGranules($table_name, $access_url, $filter, $limit, $offset) { + return (new EpnTapMgr)->getGranules($table_name, $access_url, $filter, $limit, $offset); } public function epnTapGetNbRows($table_name, $access_url, $filter) { diff --git a/php/classes/EpnTapMgr.php b/php/classes/EpnTapMgr.php index c296685..7d4e8ae 100644 --- a/php/classes/EpnTapMgr.php +++ b/php/classes/EpnTapMgr.php @@ -38,18 +38,20 @@ class EpnTapMgr { $params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery'; $url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode(preg_replace('/\s+/', ' ', $query)); // remove also multiple whitespaces - $res = $votMgr->load($url); - error_log("Query URL: " . $url); + $votMgr->load($url); + $result = $votMgr->parseStream(); return $votMgr->getVotableError() ? array('error' => $votMgr->getVotableError()) : $result; } /* filter order: product type, target name, time min, time max */ - public function getGranules($table_name, $access_url, $filter, $select, $limit, $offset) { - $query = "SELECT TOP {$limit} " . join(', ', $select) . " FROM {$table_name}.epn_core " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]) . " OFFSET {$offset}"; + public function getGranules($table_name, $access_url, $filter, $limit, $offset) { + + $query = "SELECT TOP {$limit} * FROM {$table_name} " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]) . " OFFSET {$offset}"; $result = $this->request($access_url, $query); if(! array_key_exists("error", $result)) { - for ($i = 0 ; $i < sizeof($result) ; $i++) { + + for ($i = 0 ; $i < count($result) ; $i++) { $result[$i]['num'] = $i + $offset + 1; $result[$i]['time_min'] = $this->JDTodate($result[$i]['time_min']); $result[$i]['time_max'] = $this->JDTodate($result[$i]['time_max']); @@ -89,8 +91,9 @@ class EpnTapMgr { /* filter order: product type, target name, time min, time max */ public function getNbRows($table_name, $access_url, $filter) { - $query = "SELECT COUNT(*) AS nb_rows FROM {$table_name}.epn_core " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]); - return $this->request($access_url, $query)[0]['nb_rows']; + $query = "SELECT COUNT(*) AS nb_rows FROM {$table_name} " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]); + $result = $this->request($access_url, $query)[0]['nb_rows']; + return $result; } } diff --git a/php/classes/VOTableMgr.php b/php/classes/VOTableMgr.php index aa4982a..509723e 100644 --- a/php/classes/VOTableMgr.php +++ b/php/classes/VOTableMgr.php @@ -34,7 +34,7 @@ class VOTableMgr { $this->xml = new DomDocument(); try { - $res = $this->xml->load($fileName); + $load_res = $this->xml->load($fileName); } catch (Exception $e) { $this->votable_error = $e->message; return false; @@ -55,13 +55,11 @@ class VOTableMgr { function isValidSchema() { if ($this->votable_error != false) { - error_log("There is an error on the VOTable: " . $this->votable_error); return false; } if (!$this->xml) { $this->votable_error = "The returned file is not XML."; - error_log("There is an error on the VOTable: " . $this->votable_error); return false; } @@ -69,7 +67,6 @@ class VOTableMgr { foreach($infos as $info) { if($info->getAttribute('value') == 'ERROR') { $this->votable_error = $info->textContent; - error_log("There is an error on the VOTable: " . $this->votable_error); return false; } } @@ -254,11 +251,12 @@ class VOTableMgr { /** Get the VOTable stream content.*/ public function parseStream() { if (! $this->isValidSchema()) { + error_log('There is an error on the VOTable: ' . $this->votable_error); return null; - // TODO: check this } $data = Array(); $fields = $this->xp->query($this->queryFields()); + $resource = $this->xp->query($this->queryResource()); $nb_columns = $fields->length; $row = Array(); $n_value = 0; // index of current value @@ -266,13 +264,13 @@ class VOTableMgr { $query_stream = $this->xp->query($this->queryStream())->item(0); if($query_stream == NULL) { $this->votable_error = "There is no STREAM node in the VOTable file."; - return NULL; + return null; } $this->stream = base64_decode($query_stream->textContent); $stream_len = strlen($this->stream); if($stream_len == 0) { $this->votable_error = "There is no result for this query."; - return NULL; + return null; } while($this->c < strlen($this->stream)) { $col_id = $n_value % $nb_columns; @@ -342,7 +340,7 @@ class VOTableMgr { break; } $this->c+=$row_size; - return $res; + return (string)$res; } diff --git a/php/config.php b/php/config.php index aac5725..c9a70a6 100644 --- a/php/config.php +++ b/php/config.php @@ -384,7 +384,7 @@ $API = array( 'isSharedObjectNameAlreadyUsed' => array( 'len'=>1 ), - 'epnTapGetGranules' => array('len'=>6), + 'epnTapGetGranules' => array('len'=>5), 'epnTapGetNbRows' => array('len'=>3), 'epnTapGetServices' => array('len'=>0) ) -- libgit2 0.21.2