From e48a45d78c9e9e9e3b81748c150cee8adcb043f7 Mon Sep 17 00:00:00 2001 From: Elena.Budnik <ebudnik@irap.omp.eu> Date: Fri, 23 Mar 2018 17:23:02 +0100 Subject: [PATCH] WebServices folder --- php/WebServices/Client/WSClientInterface.php | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ php/WebServices/Client/WSClientREST.php | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ php/WebServices/Client/WSClientSOAP.php | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ php/WebServices/WSUserMgr.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ php/WebServices/WebServer.php | 736 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ php/WebServices/xml/AmdaPlots.xml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ php/WebServices/xml/xml2vot.xsl | 39 +++++++++++++++++++++++++++++++++++++++ php/XML/xml2vot.xsl | 39 --------------------------------------- php/classes/WSClientInterface.php | 138 ------------------------------------------------------------------------------------------------------------------------------------------ php/classes/WSClientREST.php | 182 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- php/classes/WSClientSOAP.php | 197 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- php/classes/WSUserMgr.php | 64 ---------------------------------------------------------------- php/classes/WebServer.php | 735 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- php/testWebServer.php | 6 +++--- public/WebServices/XML/AmdaPlots.xml | 48 ------------------------------------------------ 15 files changed, 1407 insertions(+), 1406 deletions(-) create mode 100644 php/WebServices/Client/WSClientInterface.php create mode 100644 php/WebServices/Client/WSClientREST.php create mode 100644 php/WebServices/Client/WSClientSOAP.php create mode 100644 php/WebServices/WSUserMgr.php create mode 100644 php/WebServices/WebServer.php create mode 100755 php/WebServices/xml/AmdaPlots.xml create mode 100644 php/WebServices/xml/xml2vot.xsl delete mode 100644 php/XML/xml2vot.xsl delete mode 100644 php/classes/WSClientInterface.php delete mode 100644 php/classes/WSClientREST.php delete mode 100644 php/classes/WSClientSOAP.php delete mode 100644 php/classes/WSUserMgr.php delete mode 100644 php/classes/WebServer.php delete mode 100755 public/WebServices/XML/AmdaPlots.xml diff --git a/php/WebServices/Client/WSClientInterface.php b/php/WebServices/Client/WSClientInterface.php new file mode 100644 index 0000000..ba01852 --- /dev/null +++ b/php/WebServices/Client/WSClientInterface.php @@ -0,0 +1,138 @@ +<?php +abstract class WSOutputFileFormat +{ + const NETCDF = "netCDF"; + const VOTABLE = "VOTable"; + const ASCII = "ASCII"; +} + +abstract class WSOutputTimeFormat +{ + const ISO = "ISO8601"; + const TIMESTAMP = "unixtime"; +} + +abstract class WSOrbitUnit +{ + const KM = "km"; + const RS = "Rs"; + const RJ = "Rj"; + const RCA = "Rca"; + const RGA = "Rga"; + const RIO = "Rio"; + const REU = "Reu"; + const RV = "Rv"; + const RM = "Rm"; + const RE = "Re"; + const AU = "AU"; +} + +abstract class WSSpacecraft +{ + const CASSINI = "Cassini"; + const GALILEO = "Galileo"; + const VOYAGER1 = "Voyager_1"; + const VOYAGER2 = "Voyager_2"; + const PIONEER10 = "Pioneer_10"; + const PIONEER11 = "Pioneer_11"; + const PVO = "PVO"; + const ACE = "ACE"; + const VEX = "VEX"; + const MEX = "MEX"; + const MGS = "MGS"; + const MAVEN = "MAVEN"; + const MESSENGER = "MESSENGER"; + const ULYSSES = "ULYSSES"; + const STEREOA = "Stereo-A"; + const STEREOB = "Stereo-B"; + const WIND = "WIND"; + const THEMISA = "THEMIS-A"; + const THEMISB = "THEMIS-B"; + const THEMISC = "THEMIS-C"; + const THEMISD = "THEMIS-D"; + const THEMISE = "THEMIS-E"; + const CLUSTER1 = "CLUSTER1"; + const CLUSTER2 = "CLUSTER2"; + const CLUSTER3 = "CLUSTER3"; + const CLUSTER4 = "CLUSTER4"; + const DOUBLESTAR1 = "DoubleStar1"; + const IMP8 = "IMP-8"; + const GEOTAIL = "GEOTAIL"; + const POLAR = "POLAR"; + const INTERBALLTAIL = "INTERBALL-Tail"; + const ISEE1 = "ISEE-1"; + const ISEE2 = "ISEE-2"; +} + +abstract class WSCoordinatesSytem +{ + const CPHIO = "CPHIO"; + const GPHIO = "GPHIO"; + const IPHIO = "IPHIO"; + const EPHIO = "EPHIO"; + const EQUATORIAL = "Equatorial"; + const CGM = "CGM"; + const CARRINGTON = "Carrington"; + const DM = "DM"; + const GEI = "GEI"; + const GEO = "GEO"; + const GSE = "GSE"; + const GSEQ = "GSEQ"; + const GSM = "GSM"; + const HAE = "HAE"; + const HCC = "HCC"; + const HCI = "HCI"; + const HCR = "HCR"; + const HEE = "HEE"; + const HEEQ = "HEEQ"; + const HG = "HG"; + const HGI = "HGI"; + const HPC = "HPC"; + const HPR = "HPR"; + const J2000 = "J2000"; + const LGM = "LGM"; + const MAG = "MAG"; + const MFA = "MFA"; + const RTN = "RTN"; + const SC = "SC"; + const SE = "SE"; + const SM = "SM"; + const SR = "SR"; + const SR2 = "SR2"; + const SSE = "SSE"; + const SSE_L = "SSE_L"; + const SPACECRAFTORBPLANE = "SpacecraftOrbitPlane"; + const WGS84 = "WGS84"; + const MSO = "MSO"; + const VSO = "VSO"; +} + +Interface WSClientInterface +{ + public function getTimeTablesList($userID = "", $password = ""); + + public function getTimeTable($ttID, $userID = "", $password = ""); + + public function getParameterList($userID, $password = ""); + + public function getParameter($startTime, $stopTime, $parameterID, $sampling = 0, $userID = "", $password = "", + $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0); + + public function getStatus($processID); + + public function getDataset($startTime, $stopTime, $datasetID, $sampling = 0, $userID = "", $password = "", + $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0); + + public function getPlot($startTime, $stopTime, $missionID, $userID = "", $password = ""); + + public function getResultPlot($plotDirectoryURL); + + public function getOrbites($startTime, $stopTime, $spacecraft, $coordinateSystem, $units = WSOrbitUnit::KM, + $sampling = 0, $userID = "", $password = "", $outputFormat = WSOutputFileFormat::NETCDF, + $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0); + + public function isAlive(); + + public function getObsDataTree(); +} +?> \ No newline at end of file diff --git a/php/WebServices/Client/WSClientREST.php b/php/WebServices/Client/WSClientREST.php new file mode 100644 index 0000000..057095a --- /dev/null +++ b/php/WebServices/Client/WSClientREST.php @@ -0,0 +1,182 @@ +<?php + +require_once("WSClientInterface.php"); + +class WSClientREST implements WSClientInterface +{ + private $baseURL = ""; + + function __construct($baseURL) + { + $this->baseURL = $baseURL; + } + + public function isAlive() + { + return $this->call(__FUNCTION__, array()); + } + + public function getObsDataTree() + { + return $this->call(__FUNCTION__, array()); + } + + public function getTimeTablesList($userID = "", $password = "") + { + $params = array('parameters' => array()); + if ($userID != "" && $password != "") + { + $params['parameters'] = array( + "userID" => $userID, + "password"=> $password + ); + } + return $this->call(__FUNCTION__, $params); + } + + public function getTimeTable($ttID, $userID = "", $password = "") + { + $params = array('parameters' => array()); + if ($userID != "" && $password != "") + { + $params['parameters'] = array( + "userID" => $userID, + "password"=> $password + ); + } + $params['parameters']['ttID'] = $ttID; + return $this->call(__FUNCTION__, $params); + } + + public function getParameterList($userID, $password = "") + { + $params = array('parameters' => array( + "userID" => $userID + )); + if ($password != "") + $params['parameters']["password"] = $password; + return $this->call(__FUNCTION__, $params); + } + + public function getParameter($startTime, $stopTime, $parameterID, $sampling = 0, $userID = "", $password = "", + $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) + { + $params = array('parameters' => array( + "startTime" => $startTime, + "stopTime" => $stopTime, + "parameterID" => $parameterID, + "outputFormat" => $outputFormat, + "timeFormat" => $timeFormat, + "gzip" => $gzip + )); + + if ($sampling > 0) + $params["parameters"]["sampling"] = $sampling; + + if ($userID != "" && $password != "") + { + $params["parameters"]["userID"] = $userID; + $params["parameters"]["password"] = $password; + } + + return $this->call(__FUNCTION__, $params); + } + + public function getDataset($startTime, $stopTime, $datasetID, $sampling = 0, $userID = "", $password = "", + $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) + { + $params = array('parameters' => array( + "startTime" => $startTime, + "stopTime" => $stopTime, + "datasetID" => $datasetID, + "outputFormat" => $outputFormat, + "timeFormat" => $timeFormat, + "gzip" => $gzip + )); + + if ($sampling > 0) + $params["parameters"]["sampling"] = $sampling; + + if ($userID != "" && $password != "") + { + $params["parameters"]["userID"] = $userID; + $params["parameters"]["password"] = $password; + } + + return $this->call(__FUNCTION__, $params); + } + + public function getOrbites($startTime, $stopTime, $spacecraft, $coordinateSystem, $units = WSOrbitUnit::KM, + $sampling = 0, $userID = "", $password = "", $outputFormat = WSOutputFileFormat::NETCDF, + $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) + { + $params = array('parameters' => array( + "startTime" => $startTime, + "stopTime" => $stopTime, + "spacecraft" => $spacecraft, + "coordinateSystem" => $coordinateSystem, + "units" => $units, + "outputFormat" => $outputFormat, + "timeFormat" => $timeFormat, + "gzip" => $gzip + )); + + if ($sampling > 0) + $params["parameters"]["sampling"] = $sampling; + + if ($userID != "" && $password != "") + { + $params["parameters"]["userID"] = $userID; + $params["parameters"]["password"] = $password; + } + + return $this->call(__FUNCTION__, $params); + } + + public function getPlot($startTime, $stopTime, $missionID, $userID = "", $password = "") + { + $params = array('parameters' => array( + "startTime" => $startTime, + "stopTime" => $stopTime, + "missionID" => $missionID + )); + + if ($userID != "" && $password != "") + { + $params["parameters"]["userID"] = $userID; + $params["parameters"]["password"] = $password; + } + + return $this->call(__FUNCTION__, $params); + } + + public function getResultPlot($plotDirectoryURL) + { + $params = array('parameters' => array( + "plotDirectoryURL" => $plotDirectoryURL + )); + + return $this->call(__FUNCTION__, $params); + } + + private function call($function, $params) + { + $functionURL = $this->baseURL."/".$function.".php"; + + if (isset($params['parameters'])) + { + $isFirstParam = true; + foreach ($params['parameters'] as $paramName => $paramValue) + { + if ($isFirstParam) + $functionURL .= "?"; + else + $functionURL .= "&"; + $functionURL .= $paramName."=".$paramValue; + } + } + + return file_get_contents($functionURL); + } +} +?> \ No newline at end of file diff --git a/php/WebServices/Client/WSClientSOAP.php b/php/WebServices/Client/WSClientSOAP.php new file mode 100644 index 0000000..b0e8fcc --- /dev/null +++ b/php/WebServices/Client/WSClientSOAP.php @@ -0,0 +1,197 @@ +<?php + +require_once("WSClientInterface.php"); + +class WSClientSOAP implements WSClientInterface +{ + private $wsdl = ""; + private $client = null; + + function __construct($wsdl) + { + $this->wsdl = $wsdl; + ini_set('soap.wsdl_cache_enabled', 0); + } + + public function isAlive() + { + return $this->call(__FUNCTION__, array()); + } + + public function getObsDataTree() + { + return $this->call(__FUNCTION__, array()); + } + + public function getTimeTablesList($userID = "", $password = "") + { + $params = array('parameters' => array()); + if ($userID != "" && $password != "") + { + $params['parameters'] = array( + "userID" => $userID, + "password"=> $password + ); + } + return $this->call(__FUNCTION__, $params); + } + + public function getTimeTable($ttID, $userID = "", $password = "") + { + $params = array('parameters' => array()); + if ($userID != "" && $password != "") + { + $params['parameters'] = array( + "userID" => $userID, + "password"=> $password + ); + } + $params['parameters']['ttID'] = $ttID; + return $this->call(__FUNCTION__, $params); + } + + public function getParameterList($userID, $password = "") + { + $params = array('parameters' => array( + "userID" => $userID + )); + if ($password != "") + $params['parameters']["password"] = $password; + return $this->call(__FUNCTION__, $params); + } + + public function getParameter($startTime, $stopTime, $parameterID, $sampling = 0, $userID = "", $password = "", + $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) + { + $params = array('parameters' => array( + "startTime" => $startTime, + "stopTime" => $stopTime, + "parameterID" => $parameterID, + "outputFormat" => $outputFormat, + "timeFormat" => $timeFormat, + "gzip" => $gzip + )); + + if ($sampling > 0) + $params["parameters"]["sampling"] = $sampling; + + if ($userID != "" && $password != "") + { + $params["parameters"]["userID"] = $userID; + $params["parameters"]["password"] = $password; + } + + return $this->call(__FUNCTION__, $params); + } + + public function getStatus($processID) + { + $params = array('parameters' => array( + "id" => $processID + )); + + return $this->call(__FUNCTION__, $params); + } + + public function getDataset($startTime, $stopTime, $datasetID, $sampling = 0, $userID = "", $password = "", + $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) + { + $params = array('parameters' => array( + "startTime" => $startTime, + "stopTime" => $stopTime, + "datasetID" => $datasetID, + "outputFormat" => $outputFormat, + "timeFormat" => $timeFormat, + "gzip" => $gzip + )); + + if ($sampling > 0) + $params["parameters"]["sampling"] = $sampling; + + if ($userID != "" && $password != "") + { + $params["parameters"]["userID"] = $userID; + $params["parameters"]["password"] = $password; + } + + return $this->call(__FUNCTION__, $params); + } + + public function getOrbites($startTime, $stopTime, $spacecraft, $coordinateSystem, $units = WSOrbitUnit::KM, + $sampling = 0, $userID = "", $password = "", $outputFormat = WSOutputFileFormat::NETCDF, + $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) + { + $params = array('parameters' => array( + "startTime" => $startTime, + "stopTime" => $stopTime, + "spacecraft" => $spacecraft, + "coordinateSystem" => $coordinateSystem, + "units" => $units, + "outputFormat" => $outputFormat, + "timeFormat" => $timeFormat, + "gzip" => $gzip + )); + + if ($sampling > 0) + $params["parameters"]["sampling"] = $sampling; + + if ($userID != "" && $password != "") + { + $params["parameters"]["userID"] = $userID; + $params["parameters"]["password"] = $password; + } + + return $this->call(__FUNCTION__, $params); + } + + public function getPlot($startTime, $stopTime, $missionID, $userID = "", $password = "") + { + $params = array('parameters' => array( + "startTime" => $startTime, + "stopTime" => $stopTime, + "missionID" => $missionID + )); + + if ($userID != "" && $password != "") + { + $params["parameters"]["userID"] = $userID; + $params["parameters"]["password"] = $password; + } + + return $this->call(__FUNCTION__, $params); + } + + public function getResultPlot($plotDirectoryURL) + { + $params = array('parameters' => array( + "plotDirectoryURL" => $plotDirectoryURL + )); + + return $this->call(__FUNCTION__, $params); + } + + private function call($function, $params) + { + if ($this->client == null) + $this->createSOAPClient(); + try { + return $this->client ->__call($function, $params); + } + catch (Exception $e) { + print_r($this->client->__getLastResponse()); + var_dump($e); + return null; + } + } + + private function createSOAPClient() + { + $this->client = new SoapClient( + $this->wsdl, + array( + "trace"=> 1, + "soap_version"=> SOAP_1_1 + )); + } +} +?> \ No newline at end of file diff --git a/php/WebServices/WSUserMgr.php b/php/WebServices/WSUserMgr.php new file mode 100644 index 0000000..9d687d7 --- /dev/null +++ b/php/WebServices/WSUserMgr.php @@ -0,0 +1,64 @@ +<?php +/** + * @class WSUserMgr + * @version $Id: WSUserMgr.php 2806 2015-03-02 15:31:05Z natacha $ + * @brief WebServices User Manager + */ + +class WSUserMgr extends UserMgr +{ + protected $isSoap; + + private function throwError($errorType, $msg) + { + if ($this->isSoap) + throw new SoapFault($errorType, $msg); + else + return array("error" => $msg); + } + + public function init($username, $password, $sessionID, $setPathOnly, $isSoap) + { + $this->user = trim($username); + if (isset($sessionID)) + $this->sessionID = trim($sessionID); + if (isset($password)) + $this->passwd = trim($password); + + $this->isSoap = isset($isSoap); + + if (isset($password) && ! $setPathOnly) + { + // Check if user has DD session already open, otherwise - login + if ($this->ddCheckUser() != 0) + { + if ($this->ddLogin() != 0) { // DD Login if user is not registered + $this->throwError("loginError", "Login procedure failed"); + } + + if ($this->ddCheckUser() != 0) { + $this->throwError("loginError", "CheckUser procedure failed"); + } + } + } + + $this->userdir = USERPATH."/".$this->user."/"; + + if (!is_dir($this->userdir)) + { + if (!$this->createDir()) { + $this->throwError("loginError", "Cannot create UserDir"); + } + } + + $this->setPath(); + if ( $setPathOnly ) + return array('success' => true); + + $this->makeLocalTree(); + $this->makeRemoteTree(); + + return array('success' => true); + } +} +?> \ No newline at end of file diff --git a/php/WebServices/WebServer.php b/php/WebServices/WebServer.php new file mode 100644 index 0000000..9d4cb00 --- /dev/null +++ b/php/WebServices/WebServer.php @@ -0,0 +1,736 @@ +<?php +/** +* @file WebServer.php +* @brief Web services AMDA +*/ + +class WebServer +{ + private $isSoap = false; + private $userID, $userPWD = null, $sessionID = null, $IPclient; + private $dataFileName; + private $requestManager = null; + private $paramLoader = null; + private $service; + private $requestTime; + + function __construct() + { + if (!is_dir(WSConfigClass::getWsResultDir())) mkdir(WSConfigClass::getWsResultDir(), 0775); + } + + protected function init($data) + { + $this->requestTime = date('Ymd',time()); + + if (!isset($data)) { + $this->userID = 'impex'; + return array('success' => true); + } + + if(is_object($data)){ + $vars = get_object_vars($data); + $this->isSoap = true; + } + else { + $vars = $data; + } + + if (isset($vars['userID'])){ + $this->userID = $vars['userID']; + } + else { + $this->userID = 'impex'; + } + + $this->sessionID = $this->userID; + + if (isset($vars['password'])) + $this->userPWD = $vars['password']; + else + $this->userPWD = 'impexfp7'; + + return array('success' => true, 'vars' => $vars); + } + + private function initUserMgr($setPatOnly = false) + { + $wsUserMgr = new WSUserMgr(); + $wsUserMgr->init($this->userID, $this->userPWD, $this->sessionID, $setPatOnly, $this->isSoap); + + $this->IPclient = $wsUserMgr->getIPClient(); + + return array('success' => true); + } + + private function throwError($errorType, $msg) + { + if ($this->isSoap) + throw new SoapFault($errorType, $msg); + else + return array("error" => $msg); + } + + private function isGetPlotRequest($name){ + + return (substr($name,0,7) == 'getplot'); + } + + private function xsl2vot($inputName, $outputName) + { + // Load Time table + $xml = new DomDocument("1.0"); + if (!@$xml->load($inputName)) + $this->throwError("wokrspaceError", "Cannot load time table $inputName for ".$this->userID); + + // Load XSL file + $xsl = new DomDocument("1.0"); + if (!@$xsl->load(WSConfigClass::getXslDir()."xml2vot.xsl")) + $this->throwError("systemError", "Cannot load xsl file"); + + // Import XSL and write output file in vot format + $xslt = new XSLTProcessor(); + $xslt->importStylesheet($xsl); + $vot = new DomDocument("1.0"); + if (!@$vot->loadXML($xslt->transformToXML($xml))) + $this->throwError("systemError", "Cannot convert time table to VOtable"); + + if (!$vot->save(WSConfigClass::getWsResultDir().$outputName)) + $this->throwError("systemError", "Cannot save time table to result dir"); + } + + private function getDatasetInfo($id) + { + $dataSetXml = WSConfigClass::getDataSetInfoDir().$id.".xml"; + + if (!file_exists($dataSetXml)) + $this->throwError("systemError", "Cannot find info file for dataset ".$id); + + $dataSetDom = new DomDocument("1.0"); + + if (!@$dataSetDom->load($dataSetXml)) + $this->throwError("systemError", "Cannot load info file for dataset ".$id); + + return $dataSetXml; + } + +/* +* get user TimeTables list; Shared for impex +*/ + private function getTimeTablesCatalogsList($object) + { + $this->initUserMgr(true); + $dom = new DOMDocument("1.0"); + + if ($this->userID == 'impex') { + $sharedObjMgr = new SharedObjectsMgr(); + if (!@$dom->load($sharedObjMgr->getTreeFilePath())) + $this->throwError("workspaceError", "Workspace Error : Cannot load Shared TimeTable list"); + } + else { + if (!@$dom->load(USERWSDIR.'Tt.xml')) + $this->throwError("workspaceError", "Workspace Error : Cannot load TimeTable list for ".$this->userID); + } + + $tagName = $object == "timetables" ? "timetabList" : "catalogList"; + $timetabNode = $dom->getElementsByTagName($tagName); + + if ($timetabNode->length < 1){ + $this->throwError("workspaceWarning", "Workspace Warning : No $object"); + } + + $outDOM = new DOMDocument("1.0"); + $outDOM->formatOutput = TRUE; + $outDOM->preserveWhiteSpace = FALSE; + + $newNode = $outDOM->importNode($timetabNode->item(0),TRUE); + $outDOM->appendChild($newNode); + + $ttListResult = $object.'_'.$this->userID.'_'.$this->requestTime.'.xml'; + + if (!$outDOM->save(WSConfigClass::getWsResultDir().$ttListResult)) + $this->throwError("workspaceError", "Workspace Error : problem while saving $object list file"); + + return WSConfigClass::getUrl().$ttListResult; + } + +/* +* Get corresponding orbit parameter ID +*/ + private function getOrbitParameter($orbitRequest) + { + if (!file_exists(WSConfigClass::getOrbitsXml())) + $this->throwError('systemError', "No AMDA system orbits file"); + + $orbitsXml = new DomDocument(); + + if (!@$orbitsXml->load(WSConfigClass::getOrbitsXml())) + $this->throwError('systemError', "Cannot load AMDA system orbits file"); + + $spacecraft = strtolower($orbitRequest['spacecraft']); + $spacecraft = str_replace('-', '', $spacecraft); + + $xpath = new DOMXpath($orbitsXml); + $path = '//orbites[@mission="'.$spacecraft.'" and @coordinate_system="'.$orbitRequest['coordinateSystem'].'" and @units="'.$orbitRequest['units'].'" ] '; + + $orbits = $xpath->query($path); + + foreach ($orbits as $orbit) + { + $datasetID = strtr($orbit->getAttribute('dataset'),"_","-"); + $dataSetDom = $this->getDatasetInfo($datasetID); + + $paramStart = strtotime($dataSetDom->getElementsByTagName('global_start')->item(0)->nodeValue); + $paramStop = strtotime($dataSetDom->getElementsByTagName('global_stop')->item(0)->nodeValue); + + if(($paramStart <= strtotime($orbitRequest['startTime']) && (strtotime($orbitRequest['stopTime'])) <= $paramStop)) { + + return array('success' => true, + 'parameterID' => $orbit->getAttribute('xml:id') + ); + } + } + + $this->throwError('systemError', + "Cannot find orbit data for ".$orbitRequest['spacecraft']." for ".$orbitRequest['startTime']."-".$orbitRequest['stopTime']." in ".$orbitRequest['units']." ".$orbitRequest['coordinateSystem']."($paramStart - $paramStop)"); + } + + private function doDownloadRequest($interval, $paramList, $formatInfo) + { + if (!isset($this->paramLoader)) + $this->paramLoader = new IHMUserParamLoaderClass(); + + //Build parameter list + $params = array(); + + //TODO template arguments to implement ? + foreach ($paramList['params'] as $paramId) + { + $param = new stdClass; + + if (preg_match("#^ws_#",$paramId)) + { + $res = $this->paramLoader->getDerivedParameterNameFromId($paramId); + + if (!$res["success"]) { + $this->throwError("serverError", "Not available derived parameter $paramId"); + } + $param->paramid = "ws_".$res['name']; + } + else if (preg_match("#^wsd_#",$paramId)) + { + $res = $this->paramLoader->getUploadedParameterNameFromId($paramId); + + if (!$res["success"]){ + $this->throwError("serverError", "Not available parameter $paramId"); + } + $param->paramid = "wsd_".$res['name']; + } + else { + $param->paramid = $paramId; + } + $params[] = $param; + } + + $obj = (object)array( + "sampling" => $interval['sampling'], + "startDate" => $interval['startTime'], + "stopDate" => $interval['stopTime'], + "list" => $params, + "fileformat" => $formatInfo['format'], + "timeformat" => $formatInfo['timeFormat'], + "compression" => $formatInfo['gzip'] + ); + + if (!isset($this->requestManager)) + $this->requestManager = new RequestManagerClass(); + + try { + $downloadResult = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::PARAMS, $this->service, $obj); + } catch (Exception $e) { + $this->throwError("executionError", "Exception detected : ".$e->getMessage()); + } + + if (!$downloadResult['success']) { + $this->throwError("serverError", $downloadResult['message']); + } + + if($downloadResult['status'] == 'in_progress') { + return ['success' => true, 'status' => 'in progress', 'id' => $downloadResult['id']]; + } elseif ($downloadResult['status'] == 'done') + { + $this->deleteProcess($downloadResult['id']); + return array('success' => true, 'status' => 'done', 'dataFileURLs' => WSConfigClass::getUrl().$downloadResult['result']); + } else { + return ['success' => false, 'message' => 'Unknown status ' . $downloadResult['status']]; + } + } + +/* +* delete process after execution : +* delete temporary files/folders ( JOBS/process_xxxx, RES/DDxxx ); +* delete job node in processManager.xml +*/ + private function deleteProcess($id) + { + $obj = (object)array('id' => $id); + + if (!isset($this->requestManager)) + $this->requestManager = new RequestManagerClass(); + + try { + $downloadResult = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::PROCESSDELETE, null, $obj); + } catch (Exception $e) { + $this->throwError("deleteProcessError", $e->getMessage()); + } + } + +/* +* generate AUTH token for access to REST services +*/ + public function getNewToken() + { + // generate token from timeStamp and some salt + $newToken = md5(1321 * (int)( time() / WSConfigClass::$timeLimitQuery)); + + return array('success' => true, 'token' => $newToken); + } + +/************************** WEB SERVICES **************************************/ + +/* +* public data only : user impex +*/ + public function getObsDataTree() + { + $res = $this->init(); + $this->initUserMgr(); + + $locParamSrc = USERWSDIR.'LocalParams.xml'; + $locParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml'; + + if (!copy($locParamSrc,WSConfigClass::getWsResultDir().$locParamDst)) + $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file'); + + return array('success' => true,'WorkSpace' => array("LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst)); + } + +/* +* get Parameter List for given user +*/ + public function getParameterList($data) + { + $res = $this->init($data); + $this->initUserMgr(); + + $vars = $res['vars']; + + $locParamSrc = USERWSDIR.'LocalParams.xml'; + $wsParamSrc = USERWSDIR.'WsParams.xml'; + + $locParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml'; + $wsParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_UserDefinedParameters.xml'; + + if (!copy($locParamSrc, WSConfigClass::getWsResultDir().$locParamDst)) + $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file for '.$this->userID); + + if (!copy($wsParamSrc, WSConfigClass::getWsResultDir().$wsParamDst)) + $this->throwError('workspaceError', 'No User Defined Parameters description file for '.$this->userID); + + return array('success' => true,'ParameterList' => + array("UserDefinedParameters" => WSConfigClass::getUrl().$wsParamDst, + "LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst, + "RemoteDataBaseParameters" => "not implemented")); + } + +/* +* getParameter +*/ + public function getParameter($data) + { + $res = $this->init($data); + + if (!$res['success']){ + $this->throwError("requestError", "Cannot parse request"); + } + + $this->initUserMgr(); + + $vars = $res['vars']; + + if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ + $this->throwError("requestError", "Requested time interval should be greater than 0"); + } + + $paramId = array(); + array_push($paramId, $vars["parameterID"]); + + if (!$vars["timeFormat"]) + $timeFormat = "ISO8601"; + else + $timeFormat = $vars["timeFormat"]; + + if (!$vars["gzip"]) + $gzip = 0; + else + $gzip = $vars["gzip"]; + + if (!$vars["stream"]) + $stream = 0; + else + $stream = $vars["stream"]; + + $this->service = strtolower(__FUNCTION__); + + $res = $this->doDownloadRequest( + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]), + array("params" => $paramId), + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream)); + + if ($res['success']) + return $res; + + $this->throwError("serverError", $res['message']); + } + +/* +* get user Catalogs list; Shared for impex +*/ + public function getCatalogsList($data) + { + $this->init($data); + $this->init($data); + return array('success' => true, 'CatalogsList' => $this->getTimeTablesCatalogsList('catalogs')); + } + +/* +* get user TimeTables list; Shared for impex +*/ + public function getTimeTablesList($data) + { + $this->init($data); + + return array('success' => true, 'TimeTablesList' => $this->getTimeTablesCatalogsList('timetables')); + } + + public function isAlive() + { + return true; + } + +/* +* get Dataset +*/ + public function getDataset($data) + { + $res = $this->init($data); + + if (!$res['success']){ + $this->throwError("requestError", "Cannot parse request"); + } + + $this->initUserMgr(); + + $vars = $res['vars']; + + if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ + $this->throwError("requestError", "Requested time interval should be greater than 0"); + } + + $dataSetDom = $this->getDatasetInfo($vars['datasetID']); + + $params = $dataSetDom->getElementsByTagName("parameter"); + + if ($params->length == 0) + $this->throwError("systemError", "Cannot find parameter list for dataset ".$vars['datasetID']); + + $paramId = array(); + + foreach ($params as $p) + $paramId[] = $p->nodeValue; + + if (!$vars["sampling"]) + { + $sampling = $dataSetDom->getElementsByTagName('min_sampling')->item(0)->nodeValue; + + $units = substr($sampling,-1); + $sampling = substr($sampling,0,strlen($sampling)-1); + + switch ($units) { +// case 'S': +// $sampling = floatval($sampling); +// break; + case 'M': + $sampling = floatval($sampling)*60; + break; + case 'H': + $sampling = floatval($sampling)*60*60; + break; + default: + } + } + else { + $sampling = $vars["sampling"]; + } + + if (!$vars["timeFormat"]) + $timeFormat = "ISO8601"; + else + $timeFormat = $vars["timeFormat"]; + + if (!$vars["gzip"]) + $gzip = 0; + else + $gzip = $vars["gzip"]; + + if (!$vars["stream"]) + $stream = 0; + else + $stream = $vars["stream"]; + + $this->service = strtolower(__FUNCTION__); + + $res = $this->doDownloadRequest( + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $sampling), + array("params" => $paramId), + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream)); + + if ($res['success']) return $res; + + $this->throwError("serverError", $res['message']); + } + +/* +* get status for jobs in batch +*/ + public function getStatus($data) + { + $result = $this->init($data); + + $id = $result['vars']['id']; + + if (!isset($this->requestManager)) + $this->requestManager = new RequestManagerClass(); + + try + { + $res = $this->requestManager->runWSRequest('nobody', 'nobody', FunctionTypeEnumClass::PROCESSGETINFO, null, $id); + } + catch (Exception $e) + { + // after first getStatus() call process is deleted + $jobsManager = new WSJobsManagerClass(); + + try + { + $res = $jobsManager->getResultFromProcessId($id); + if (!$res['success']) { + $this->throwError("processError","Cannot retrieve process $id info"); + } + + $resultTag = $this->isGetPlotRequest($res['result']) ? 'plotURL' : 'dataFileURLs'; + + return array('success' => true, 'status' => 'done', $resultTag => WSConfigClass::getUrl().$res['result']); + } + catch (Exception $e) + { + $this->throwError("getResultFromProcessIdError", "Exception detected : ".$e->getMessage()); + } + } + + if (!$res['success']) { + $this->throwError("processError","Cannot retrieve process $id info"); + } + + if ($res['status'] == 'in_progress') { + return array('success' => true, 'status' => 'in progress'); + } + + if ($res['error']) { + $this->throwError("processError","Process $id error code"); + } + + $this->deleteProcess($res['id']); + + $resultTag = $this->isGetPlotRequest($res['result']) ? 'plotURL' : 'dataFileURLs'; + + return array('success' => true, 'status' => $res['status'], $resultTag => WSConfigClass::getUrl().$res['result']); + } + +/* +* TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!! +* TODO Think about this if merge/union will be also done by AMDA_Kernel +* +* get Time Table : shared for impex ; user' for user +*/ + public function getTimeTable($data) + { + $res = $this->init($data); + + if (!$res['success']){ + $this->throwError("requestError", "Cannot parse request"); + } + + $this->initUserMgr(true); + + $ttID = $res['vars']['ttID']; + + if ($this->userID == 'impex') { + $sharedObjMgr = new SharedObjectsMgr(); + $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID); + } + else + $ttSrc = USERTTDIR.$ttID.'.xml'; + + if (!file_exists($ttSrc)) { + $this->throwError("workspaceError", "No such table ".$ttID." for user ".$this->userID); + } + + $ttDst = substr(strtolower(__FUNCTION__), 3)."_".$this->userID."_".$this->requestTime."_$ttID.xml"; + + //TODO can be done by + // $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient,FunctionTypeEnumClass::TTCONVERT, null, $ttID); + $this->xsl2vot($ttSrc,$ttDst); + + return array('success' => true, 'ttFileURL' => WSConfigClass::getUrl().$ttDst); + } + +/* +* get Orbits +*/ + public function getOrbites($data) + { + $res = $this->init($data); + + if (!$res['success']){ + $this->throwError("requestError", "Cannot parse request"); + } + + $this->initUserMgr(); + + $vars = $res['vars']; + + if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ + $this->throwError("requestError", "Requested time interval should be greater than 0"); + } + + $spacecraft = $vars["spacecraft"]; + $coordinateSystem = $vars["coordinateSystem"]; + + if (!$vars["units"]) + $units = "km"; + else + $units = $vars["units"]; + + $orbitRequest = array("startTime" => $vars["startTime"], + "stopTime" => $vars["stopTime"], + "spacecraft" => $spacecraft, + "coordinateSystem" => $coordinateSystem, + "units" => $units + ); + + $orbitParam = $this->getOrbitParameter($orbitRequest); + + $paramId = array(); + array_push($paramId, $orbitParam['parameterID']); + + if (!$vars["timeFormat"]) + $timeFormat = "ISO8601"; + else + $timeFormat = $vars["timeFormat"]; + + if (!$vars["gzip"]) + $gzip = 0; + else + $gzip = $vars["gzip"]; + + $this->service = strtolower(__FUNCTION__); + + $res = $this->doDownloadRequest( + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]), + array("params" => $paramId), + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream)); + + if ($res['success']) return $res; + + $this->throwError("serverError",$res['message']); + } + +/* +* getPlot : predefined; by mission +*/ + public function getPlot($data) + { + $res = $this->init($data); + + if (!$res['success']){ + $this->throwError("requestError", "Cannot parse request"); + } + + $this->initUserMgr(); + + $vars = $res['vars']; + $mission = $vars["missionID"]; + + $resultFilePrefix = strtolower(__FUNCTION__)."_".$mission."_".date("YmdHms",strtotime($vars["startTime"]))."_".date("YmdHms",strtotime($vars["stopTime"])); + + if ($this->userID != "impex") + $resultFilePrefix .= "_".$this->userID; + + $dom = new DomDocument("1.0"); + if (!@$dom->load(WSConfigClass::getXslDir()."AmdaPlots.xml")) + $this->throwError("systemError", "Cannot load predefined plot definition"); ; + + $missionTag = $dom->getElementById($mission); + $params = $missionTag->getElementsByTagName('param'); + + $paramsList = array(); + foreach ($params as $param) + $paramsList[] = $param->getAttribute('name'); + + $requestObject = (Object) array( + "nodeType" => "request", + "file-format" => "PNG", + "result-file" => $resultFilePrefix, + "timesrc" => "Interval", + "startDate" => $vars["startTime"], + "stopDate" => $vars["stopTime"], + "parameters" => array() + ); + + foreach ($paramsList as $paramToPlot) + { + $paramObject = (Object) array( + "paramid" => $paramToPlot + ); + + $requestObject->{"parameters"}[] = $paramObject; + } + + $this->service = strtolower(__FUNCTION__); + + if (!isset($this->requestManager)) + $this->requestManager = new RequestManagerClass(); + + try { + $plotResult = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::PARAMS, $this->service, $requestObject); + } catch (Exception $e) { + $this->throwError("plotError", "Exeption detected : ".$e->getMessage()); + } + + if (!$plotResult['success']) { + $this->throwError("serverError", $plotResult['message']); + } + + if($plotResult['status'] == 'in_progress') { + return ['success' => true, 'status' => 'in progress', 'id' => $plotResult['id']]; + } elseif ($plotResult['status'] == 'done') + { + $this->deleteProcess($plotResult['id']); + return array('success' => true, 'status' => 'done', 'plotFileURL' => WSConfigClass::getUrl().$plotResult['result']); + } else { + return ['success' => false, 'message' => 'Unknown status ' . $plotResult['status']]; + } + } +} +?> diff --git a/php/WebServices/xml/AmdaPlots.xml b/php/WebServices/xml/AmdaPlots.xml new file mode 100755 index 0000000..79127e4 --- /dev/null +++ b/php/WebServices/xml/AmdaPlots.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<missions> + <mission xml:id='ACE'> + <param name='sw_vb'/> + <param name='sw_t'/> + <param name='sw_n'/> + <param name='imf'/> + <param name='imf_mag'/> + </mission> + <mission xml:id='WIND'> + <param name='wnd_swe_vmag'/> + <param name='wnd_swe_vth'/> + <param name='wnd_swe_n'/> + <param name='wnd_b' class="mag"/> + <param name='wnd_bmag'/> + </mission> + <mission xml:id='STEREO-A'> + <param name='vpbulk_sta'/> + <param name='vth_sta'/> + <param name='np_sta'/> + <param name='sta_b'/> + <param name='sta_btot'/> + </mission> + <mission xml:id='STEREO-B'> + <param name='vpbulk_stb'/> + <param name='vth_stb'/> + <param name='np_stb'/> + <param name='stb_b'/> + <param name='stb_btot'/> + </mission> + <mission xml:id='VEX'> + <param name='vex_mag_4s'/> + <param name='vex_mag_4s_tot'/> + </mission> + <mission xml:id='OMNI'> + <param name='omni_sw_v'/> + <param name='omni_sw_t'/> + <param name='omni_sw_n'/> + <param name='omni_imf' /> + <param name='omni_imf_mag'/> + </mission> + <mission xml:id='GEOMAG'> + <param name='omni_kp'/> + <param name='omni_dst'/> + <param name='omni_ae'/> + </mission> +</missions> + diff --git a/php/WebServices/xml/xml2vot.xsl b/php/WebServices/xml/xml2vot.xsl new file mode 100644 index 0000000..b6d7df9 --- /dev/null +++ b/php/WebServices/xml/xml2vot.xsl @@ -0,0 +1,39 @@ +<xsl:stylesheet version="1.0" +xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + +<xsl:output method="xml"/> + +<xsl:template match="/timetable"> + <VOTABLE version='1.1'> + <DESCRIPTION> + Name: <xsl:value-of select="name"/>; + Description: <xsl:value-of select="description"/>; + Historic: <xsl:value-of select="history"/>; + Creation Date : <xsl:value-of select="created"/>; + </DESCRIPTION> +<RESOURCE> +<DESCRIPTION> + AMDA @ CDPP +</DESCRIPTION> +<TABLE> +<FIELD datatype='char' name='Start Time' ID='TimeIntervalStart' ucd='time.start'> + <DESCRIPTION>time tag for beginning of interval</DESCRIPTION> +</FIELD> +<FIELD datatype='char' name='Stop Time' ID='TimeIntervalStop' ucd='time.stop'> + <DESCRIPTION>time tag for end of interval</DESCRIPTION> +</FIELD> +<DATA> + <TABLEDATA> + <xsl:for-each select="intervals"> + <TR> + <TD><xsl:value-of select="start"/></TD> + <TD><xsl:value-of select="stop"/></TD> + </TR> + </xsl:for-each> + </TABLEDATA> + </DATA> + </TABLE> + </RESOURCE> + </VOTABLE> +</xsl:template> +</xsl:stylesheet> diff --git a/php/XML/xml2vot.xsl b/php/XML/xml2vot.xsl deleted file mode 100644 index b6d7df9..0000000 --- a/php/XML/xml2vot.xsl +++ /dev/null @@ -1,39 +0,0 @@ -<xsl:stylesheet version="1.0" -xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> - -<xsl:output method="xml"/> - -<xsl:template match="/timetable"> - <VOTABLE version='1.1'> - <DESCRIPTION> - Name: <xsl:value-of select="name"/>; - Description: <xsl:value-of select="description"/>; - Historic: <xsl:value-of select="history"/>; - Creation Date : <xsl:value-of select="created"/>; - </DESCRIPTION> -<RESOURCE> -<DESCRIPTION> - AMDA @ CDPP -</DESCRIPTION> -<TABLE> -<FIELD datatype='char' name='Start Time' ID='TimeIntervalStart' ucd='time.start'> - <DESCRIPTION>time tag for beginning of interval</DESCRIPTION> -</FIELD> -<FIELD datatype='char' name='Stop Time' ID='TimeIntervalStop' ucd='time.stop'> - <DESCRIPTION>time tag for end of interval</DESCRIPTION> -</FIELD> -<DATA> - <TABLEDATA> - <xsl:for-each select="intervals"> - <TR> - <TD><xsl:value-of select="start"/></TD> - <TD><xsl:value-of select="stop"/></TD> - </TR> - </xsl:for-each> - </TABLEDATA> - </DATA> - </TABLE> - </RESOURCE> - </VOTABLE> -</xsl:template> -</xsl:stylesheet> diff --git a/php/classes/WSClientInterface.php b/php/classes/WSClientInterface.php deleted file mode 100644 index ba01852..0000000 --- a/php/classes/WSClientInterface.php +++ /dev/null @@ -1,138 +0,0 @@ -<?php -abstract class WSOutputFileFormat -{ - const NETCDF = "netCDF"; - const VOTABLE = "VOTable"; - const ASCII = "ASCII"; -} - -abstract class WSOutputTimeFormat -{ - const ISO = "ISO8601"; - const TIMESTAMP = "unixtime"; -} - -abstract class WSOrbitUnit -{ - const KM = "km"; - const RS = "Rs"; - const RJ = "Rj"; - const RCA = "Rca"; - const RGA = "Rga"; - const RIO = "Rio"; - const REU = "Reu"; - const RV = "Rv"; - const RM = "Rm"; - const RE = "Re"; - const AU = "AU"; -} - -abstract class WSSpacecraft -{ - const CASSINI = "Cassini"; - const GALILEO = "Galileo"; - const VOYAGER1 = "Voyager_1"; - const VOYAGER2 = "Voyager_2"; - const PIONEER10 = "Pioneer_10"; - const PIONEER11 = "Pioneer_11"; - const PVO = "PVO"; - const ACE = "ACE"; - const VEX = "VEX"; - const MEX = "MEX"; - const MGS = "MGS"; - const MAVEN = "MAVEN"; - const MESSENGER = "MESSENGER"; - const ULYSSES = "ULYSSES"; - const STEREOA = "Stereo-A"; - const STEREOB = "Stereo-B"; - const WIND = "WIND"; - const THEMISA = "THEMIS-A"; - const THEMISB = "THEMIS-B"; - const THEMISC = "THEMIS-C"; - const THEMISD = "THEMIS-D"; - const THEMISE = "THEMIS-E"; - const CLUSTER1 = "CLUSTER1"; - const CLUSTER2 = "CLUSTER2"; - const CLUSTER3 = "CLUSTER3"; - const CLUSTER4 = "CLUSTER4"; - const DOUBLESTAR1 = "DoubleStar1"; - const IMP8 = "IMP-8"; - const GEOTAIL = "GEOTAIL"; - const POLAR = "POLAR"; - const INTERBALLTAIL = "INTERBALL-Tail"; - const ISEE1 = "ISEE-1"; - const ISEE2 = "ISEE-2"; -} - -abstract class WSCoordinatesSytem -{ - const CPHIO = "CPHIO"; - const GPHIO = "GPHIO"; - const IPHIO = "IPHIO"; - const EPHIO = "EPHIO"; - const EQUATORIAL = "Equatorial"; - const CGM = "CGM"; - const CARRINGTON = "Carrington"; - const DM = "DM"; - const GEI = "GEI"; - const GEO = "GEO"; - const GSE = "GSE"; - const GSEQ = "GSEQ"; - const GSM = "GSM"; - const HAE = "HAE"; - const HCC = "HCC"; - const HCI = "HCI"; - const HCR = "HCR"; - const HEE = "HEE"; - const HEEQ = "HEEQ"; - const HG = "HG"; - const HGI = "HGI"; - const HPC = "HPC"; - const HPR = "HPR"; - const J2000 = "J2000"; - const LGM = "LGM"; - const MAG = "MAG"; - const MFA = "MFA"; - const RTN = "RTN"; - const SC = "SC"; - const SE = "SE"; - const SM = "SM"; - const SR = "SR"; - const SR2 = "SR2"; - const SSE = "SSE"; - const SSE_L = "SSE_L"; - const SPACECRAFTORBPLANE = "SpacecraftOrbitPlane"; - const WGS84 = "WGS84"; - const MSO = "MSO"; - const VSO = "VSO"; -} - -Interface WSClientInterface -{ - public function getTimeTablesList($userID = "", $password = ""); - - public function getTimeTable($ttID, $userID = "", $password = ""); - - public function getParameterList($userID, $password = ""); - - public function getParameter($startTime, $stopTime, $parameterID, $sampling = 0, $userID = "", $password = "", - $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0); - - public function getStatus($processID); - - public function getDataset($startTime, $stopTime, $datasetID, $sampling = 0, $userID = "", $password = "", - $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0); - - public function getPlot($startTime, $stopTime, $missionID, $userID = "", $password = ""); - - public function getResultPlot($plotDirectoryURL); - - public function getOrbites($startTime, $stopTime, $spacecraft, $coordinateSystem, $units = WSOrbitUnit::KM, - $sampling = 0, $userID = "", $password = "", $outputFormat = WSOutputFileFormat::NETCDF, - $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0); - - public function isAlive(); - - public function getObsDataTree(); -} -?> \ No newline at end of file diff --git a/php/classes/WSClientREST.php b/php/classes/WSClientREST.php deleted file mode 100644 index 057095a..0000000 --- a/php/classes/WSClientREST.php +++ /dev/null @@ -1,182 +0,0 @@ -<?php - -require_once("WSClientInterface.php"); - -class WSClientREST implements WSClientInterface -{ - private $baseURL = ""; - - function __construct($baseURL) - { - $this->baseURL = $baseURL; - } - - public function isAlive() - { - return $this->call(__FUNCTION__, array()); - } - - public function getObsDataTree() - { - return $this->call(__FUNCTION__, array()); - } - - public function getTimeTablesList($userID = "", $password = "") - { - $params = array('parameters' => array()); - if ($userID != "" && $password != "") - { - $params['parameters'] = array( - "userID" => $userID, - "password"=> $password - ); - } - return $this->call(__FUNCTION__, $params); - } - - public function getTimeTable($ttID, $userID = "", $password = "") - { - $params = array('parameters' => array()); - if ($userID != "" && $password != "") - { - $params['parameters'] = array( - "userID" => $userID, - "password"=> $password - ); - } - $params['parameters']['ttID'] = $ttID; - return $this->call(__FUNCTION__, $params); - } - - public function getParameterList($userID, $password = "") - { - $params = array('parameters' => array( - "userID" => $userID - )); - if ($password != "") - $params['parameters']["password"] = $password; - return $this->call(__FUNCTION__, $params); - } - - public function getParameter($startTime, $stopTime, $parameterID, $sampling = 0, $userID = "", $password = "", - $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) - { - $params = array('parameters' => array( - "startTime" => $startTime, - "stopTime" => $stopTime, - "parameterID" => $parameterID, - "outputFormat" => $outputFormat, - "timeFormat" => $timeFormat, - "gzip" => $gzip - )); - - if ($sampling > 0) - $params["parameters"]["sampling"] = $sampling; - - if ($userID != "" && $password != "") - { - $params["parameters"]["userID"] = $userID; - $params["parameters"]["password"] = $password; - } - - return $this->call(__FUNCTION__, $params); - } - - public function getDataset($startTime, $stopTime, $datasetID, $sampling = 0, $userID = "", $password = "", - $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) - { - $params = array('parameters' => array( - "startTime" => $startTime, - "stopTime" => $stopTime, - "datasetID" => $datasetID, - "outputFormat" => $outputFormat, - "timeFormat" => $timeFormat, - "gzip" => $gzip - )); - - if ($sampling > 0) - $params["parameters"]["sampling"] = $sampling; - - if ($userID != "" && $password != "") - { - $params["parameters"]["userID"] = $userID; - $params["parameters"]["password"] = $password; - } - - return $this->call(__FUNCTION__, $params); - } - - public function getOrbites($startTime, $stopTime, $spacecraft, $coordinateSystem, $units = WSOrbitUnit::KM, - $sampling = 0, $userID = "", $password = "", $outputFormat = WSOutputFileFormat::NETCDF, - $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) - { - $params = array('parameters' => array( - "startTime" => $startTime, - "stopTime" => $stopTime, - "spacecraft" => $spacecraft, - "coordinateSystem" => $coordinateSystem, - "units" => $units, - "outputFormat" => $outputFormat, - "timeFormat" => $timeFormat, - "gzip" => $gzip - )); - - if ($sampling > 0) - $params["parameters"]["sampling"] = $sampling; - - if ($userID != "" && $password != "") - { - $params["parameters"]["userID"] = $userID; - $params["parameters"]["password"] = $password; - } - - return $this->call(__FUNCTION__, $params); - } - - public function getPlot($startTime, $stopTime, $missionID, $userID = "", $password = "") - { - $params = array('parameters' => array( - "startTime" => $startTime, - "stopTime" => $stopTime, - "missionID" => $missionID - )); - - if ($userID != "" && $password != "") - { - $params["parameters"]["userID"] = $userID; - $params["parameters"]["password"] = $password; - } - - return $this->call(__FUNCTION__, $params); - } - - public function getResultPlot($plotDirectoryURL) - { - $params = array('parameters' => array( - "plotDirectoryURL" => $plotDirectoryURL - )); - - return $this->call(__FUNCTION__, $params); - } - - private function call($function, $params) - { - $functionURL = $this->baseURL."/".$function.".php"; - - if (isset($params['parameters'])) - { - $isFirstParam = true; - foreach ($params['parameters'] as $paramName => $paramValue) - { - if ($isFirstParam) - $functionURL .= "?"; - else - $functionURL .= "&"; - $functionURL .= $paramName."=".$paramValue; - } - } - - return file_get_contents($functionURL); - } -} -?> \ No newline at end of file diff --git a/php/classes/WSClientSOAP.php b/php/classes/WSClientSOAP.php deleted file mode 100644 index b0e8fcc..0000000 --- a/php/classes/WSClientSOAP.php +++ /dev/null @@ -1,197 +0,0 @@ -<?php - -require_once("WSClientInterface.php"); - -class WSClientSOAP implements WSClientInterface -{ - private $wsdl = ""; - private $client = null; - - function __construct($wsdl) - { - $this->wsdl = $wsdl; - ini_set('soap.wsdl_cache_enabled', 0); - } - - public function isAlive() - { - return $this->call(__FUNCTION__, array()); - } - - public function getObsDataTree() - { - return $this->call(__FUNCTION__, array()); - } - - public function getTimeTablesList($userID = "", $password = "") - { - $params = array('parameters' => array()); - if ($userID != "" && $password != "") - { - $params['parameters'] = array( - "userID" => $userID, - "password"=> $password - ); - } - return $this->call(__FUNCTION__, $params); - } - - public function getTimeTable($ttID, $userID = "", $password = "") - { - $params = array('parameters' => array()); - if ($userID != "" && $password != "") - { - $params['parameters'] = array( - "userID" => $userID, - "password"=> $password - ); - } - $params['parameters']['ttID'] = $ttID; - return $this->call(__FUNCTION__, $params); - } - - public function getParameterList($userID, $password = "") - { - $params = array('parameters' => array( - "userID" => $userID - )); - if ($password != "") - $params['parameters']["password"] = $password; - return $this->call(__FUNCTION__, $params); - } - - public function getParameter($startTime, $stopTime, $parameterID, $sampling = 0, $userID = "", $password = "", - $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) - { - $params = array('parameters' => array( - "startTime" => $startTime, - "stopTime" => $stopTime, - "parameterID" => $parameterID, - "outputFormat" => $outputFormat, - "timeFormat" => $timeFormat, - "gzip" => $gzip - )); - - if ($sampling > 0) - $params["parameters"]["sampling"] = $sampling; - - if ($userID != "" && $password != "") - { - $params["parameters"]["userID"] = $userID; - $params["parameters"]["password"] = $password; - } - - return $this->call(__FUNCTION__, $params); - } - - public function getStatus($processID) - { - $params = array('parameters' => array( - "id" => $processID - )); - - return $this->call(__FUNCTION__, $params); - } - - public function getDataset($startTime, $stopTime, $datasetID, $sampling = 0, $userID = "", $password = "", - $outputFormat = WSOutputFileFormat::NETCDF, $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) - { - $params = array('parameters' => array( - "startTime" => $startTime, - "stopTime" => $stopTime, - "datasetID" => $datasetID, - "outputFormat" => $outputFormat, - "timeFormat" => $timeFormat, - "gzip" => $gzip - )); - - if ($sampling > 0) - $params["parameters"]["sampling"] = $sampling; - - if ($userID != "" && $password != "") - { - $params["parameters"]["userID"] = $userID; - $params["parameters"]["password"] = $password; - } - - return $this->call(__FUNCTION__, $params); - } - - public function getOrbites($startTime, $stopTime, $spacecraft, $coordinateSystem, $units = WSOrbitUnit::KM, - $sampling = 0, $userID = "", $password = "", $outputFormat = WSOutputFileFormat::NETCDF, - $timeFormat = WSOutputTimeFormat::ISO, $gzip = 0) - { - $params = array('parameters' => array( - "startTime" => $startTime, - "stopTime" => $stopTime, - "spacecraft" => $spacecraft, - "coordinateSystem" => $coordinateSystem, - "units" => $units, - "outputFormat" => $outputFormat, - "timeFormat" => $timeFormat, - "gzip" => $gzip - )); - - if ($sampling > 0) - $params["parameters"]["sampling"] = $sampling; - - if ($userID != "" && $password != "") - { - $params["parameters"]["userID"] = $userID; - $params["parameters"]["password"] = $password; - } - - return $this->call(__FUNCTION__, $params); - } - - public function getPlot($startTime, $stopTime, $missionID, $userID = "", $password = "") - { - $params = array('parameters' => array( - "startTime" => $startTime, - "stopTime" => $stopTime, - "missionID" => $missionID - )); - - if ($userID != "" && $password != "") - { - $params["parameters"]["userID"] = $userID; - $params["parameters"]["password"] = $password; - } - - return $this->call(__FUNCTION__, $params); - } - - public function getResultPlot($plotDirectoryURL) - { - $params = array('parameters' => array( - "plotDirectoryURL" => $plotDirectoryURL - )); - - return $this->call(__FUNCTION__, $params); - } - - private function call($function, $params) - { - if ($this->client == null) - $this->createSOAPClient(); - try { - return $this->client ->__call($function, $params); - } - catch (Exception $e) { - print_r($this->client->__getLastResponse()); - var_dump($e); - return null; - } - } - - private function createSOAPClient() - { - $this->client = new SoapClient( - $this->wsdl, - array( - "trace"=> 1, - "soap_version"=> SOAP_1_1 - )); - } -} -?> \ No newline at end of file diff --git a/php/classes/WSUserMgr.php b/php/classes/WSUserMgr.php deleted file mode 100644 index 9d687d7..0000000 --- a/php/classes/WSUserMgr.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php -/** - * @class WSUserMgr - * @version $Id: WSUserMgr.php 2806 2015-03-02 15:31:05Z natacha $ - * @brief WebServices User Manager - */ - -class WSUserMgr extends UserMgr -{ - protected $isSoap; - - private function throwError($errorType, $msg) - { - if ($this->isSoap) - throw new SoapFault($errorType, $msg); - else - return array("error" => $msg); - } - - public function init($username, $password, $sessionID, $setPathOnly, $isSoap) - { - $this->user = trim($username); - if (isset($sessionID)) - $this->sessionID = trim($sessionID); - if (isset($password)) - $this->passwd = trim($password); - - $this->isSoap = isset($isSoap); - - if (isset($password) && ! $setPathOnly) - { - // Check if user has DD session already open, otherwise - login - if ($this->ddCheckUser() != 0) - { - if ($this->ddLogin() != 0) { // DD Login if user is not registered - $this->throwError("loginError", "Login procedure failed"); - } - - if ($this->ddCheckUser() != 0) { - $this->throwError("loginError", "CheckUser procedure failed"); - } - } - } - - $this->userdir = USERPATH."/".$this->user."/"; - - if (!is_dir($this->userdir)) - { - if (!$this->createDir()) { - $this->throwError("loginError", "Cannot create UserDir"); - } - } - - $this->setPath(); - if ( $setPathOnly ) - return array('success' => true); - - $this->makeLocalTree(); - $this->makeRemoteTree(); - - return array('success' => true); - } -} -?> \ No newline at end of file diff --git a/php/classes/WebServer.php b/php/classes/WebServer.php deleted file mode 100644 index 8be2454..0000000 --- a/php/classes/WebServer.php +++ /dev/null @@ -1,735 +0,0 @@ -<?php -/** -* @file WebServer.php -* @brief Web services AMDA -*/ - -class WebServer -{ - private $isSoap = false; - private $userID, $userPWD = null, $sessionID = null, $IPclient; - private $dataFileName; - private $requestManager = null; - private $paramLoader = null; - private $service; - private $requestTime; - - function __construct() - { - if (!is_dir(WSConfigClass::getWsResultDir())) mkdir(WSConfigClass::getWsResultDir(), 0775); - } - - protected function init($data) - { - $this->requestTime = date('Ymd',time()); - - if (!isset($data)) { - $this->userID = 'impex'; - return array('success' => true); - } - - if(is_object($data)){ - $vars = get_object_vars($data); - $this->isSoap = true; - } - else { - $vars = $data; - } - - if (isset($vars['userID'])){ - $this->userID = $vars['userID']; - } - else { - $this->userID = 'impex'; - } - - $this->sessionID = $this->userID; - - if (isset($vars['password'])) - $this->userPWD = $vars['password']; - else - $this->userPWD = 'impexfp7'; - - return array('success' => true, 'vars' => $vars); - } - - private function initUserMgr($setPatOnly = false) - { - $wsUserMgr = new WSUserMgr(); - $wsUserMgr->init($this->userID, $this->userPWD, $this->sessionID, $setPatOnly, $this->isSoap); - - $this->IPclient = $wsUserMgr->getIPClient(); - - return array('success' => true); - } - - private function throwError($errorType, $msg) - { - if ($this->isSoap) - throw new SoapFault($errorType, $msg); - else - return array("error" => $msg); - } - - private function isGetPlotRequest($name){ - - return (substr($name,0,7) == 'getplot'); - } - - private function xsl2vot($inputName, $outputName) - { - // Load Time table - $xml = new DomDocument("1.0"); - if (!@$xml->load($inputName)) - $this->throwError("wokrspaceError", "Cannot load time table $inputName for ".$this->userID); - - // Load XSL file - $xsl = new DomDocument("1.0"); - if (!@$xsl->load(WSConfigClass::getXslDir()."xml2vot.xsl")) - $this->throwError("systemError", "Cannot load xsl file"); - - // Import XSL and write output file in vot format - $xslt = new XSLTProcessor(); - $xslt->importStylesheet($xsl); - $vot = new DomDocument("1.0"); - if (!@$vot->loadXML($xslt->transformToXML($xml))) - $this->throwError("systemError", "Cannot convert time table to VOtable"); - - if (!$vot->save(WSConfigClass::getWsResultDir().$outputName)) - $this->throwError("systemError", "Cannot save time table to result dir"); - } - - private function getDatasetInfo($id) - { - $dataSetXml = WSConfigClass::getDataSetInfoDir().$id.".xml"; - - if (!file_exists($dataSetXml)) - $this->throwError("systemError", "Cannot find info file for dataset ".$id); - - $dataSetDom = new DomDocument("1.0"); - - if (!@$dataSetDom->load($dataSetXml)) - $this->throwError("systemError", "Cannot load info file for dataset ".$id); - - return $dataSetXml; - } - -/* -* get user TimeTables list; Shared for impex -*/ - private function getTimeTablesCatalogsList($object) - { - $this->initUserMgr(true); - $dom = new DOMDocument("1.0"); - - if ($this->userID == 'impex') { - $sharedObjMgr = new SharedObjectsMgr(); - if (!@$dom->load($sharedObjMgr->getTreeFilePath())) - $this->throwError("workspaceError", "Workspace Error : Cannot load Shared TimeTable list"); - } - else { - if (!@$dom->load(USERWSDIR.'Tt.xml')) - $this->throwError("workspaceError", "Workspace Error : Cannot load TimeTable list for ".$this->userID); - } - - $tagName = $object == "timetables" ? "timetabList" : "catalogList"; - $timetabNode = $dom->getElementsByTagName($tagName); - - if ($timetabNode->length < 1){ - $this->throwError("workspaceWarning", "Workspace Warning : No $object"); - } - - $outDOM = new DOMDocument("1.0"); - $outDOM->formatOutput = TRUE; - $outDOM->preserveWhiteSpace = FALSE; - - $newNode = $outDOM->importNode($timetabNode->item(0),TRUE); - $outDOM->appendChild($newNode); - - $ttListResult = $object.'_'.$this->userID.'_'.$this->requestTime.'.xml'; - - if (!$outDOM->save(WSConfigClass::getWsResultDir().$ttListResult)) - $this->throwError("workspaceError", "Workspace Error : problem while saving $object list file"); - - return WSConfigClass::getUrl().$ttListResult; - } - -/* -* Get corresponding orbit parameter ID -*/ - private function getOrbitParameter($orbitRequest) - { - if (!file_exists(WSConfigClass::getOrbitsXml())) - $this->throwError('systemError', "No AMDA system orbits file"); - - $orbitsXml = new DomDocument(); - - if (!@$orbitsXml->load(WSConfigClass::getOrbitsXml())) - $this->throwError('systemError', "Cannot load AMDA system orbits file"); - - $spacecraft = strtolower($orbitRequest['spacecraft']); - $spacecraft = str_replace('-', '', $spacecraft); - - $xpath = new DOMXpath($orbitsXml); - $path = '//orbites[@mission="'.$spacecraft.'" and @coordinate_system="'.$orbitRequest['coordinateSystem'].'" and @units="'.$orbitRequest['units'].'" ] '; - - $orbits = $xpath->query($path); - - foreach ($orbits as $orbit) - { - $datasetID = strtr($orbit->getAttribute('dataset'),"_","-"); - $dataSetDom = $this->getDatasetInfo($datasetID); - - $paramStart = strtotime($dataSetDom->getElementsByTagName('global_start')->item(0)->nodeValue); - $paramStop = strtotime($dataSetDom->getElementsByTagName('global_stop')->item(0)->nodeValue); - - if(($paramStart <= strtotime($orbitRequest['startTime']) && (strtotime($orbitRequest['stopTime'])) <= $paramStop)) { - - return array('success' => true, - 'parameterID' => $orbit->getAttribute('xml:id') - ); - } - } - - $this->throwError('systemError', - "Cannot find orbit data for ".$orbitRequest['spacecraft']." for ".$orbitRequest['startTime']."-".$orbitRequest['stopTime']." in ".$orbitRequest['units']." ".$orbitRequest['coordinateSystem']."($paramStart - $paramStop)"); - } - - private function doDownloadRequest($interval, $paramList, $formatInfo) - { - if (!isset($this->paramLoader)) - $this->paramLoader = new IHMUserParamLoaderClass(); - - //Build parameter list - $params = array(); - - //TODO template arguments to implement ? - foreach ($paramList['params'] as $paramId) - { - $param = new stdClass; - - if (preg_match("#^ws_#",$paramId)) - { - $res = $this->paramLoader->getDerivedParameterNameFromId($paramId); - - if (!$res["success"]) { - $this->throwError("serverError", "Not available derived parameter $paramId"); - } - $param->paramid = "ws_".$res['name']; - } - else if (preg_match("#^wsd_#",$paramId)) - { - $res = $this->paramLoader->getUploadedParameterNameFromId($paramId); - - if (!$res["success"]){ - $this->throwError("serverError", "Not available parameter $paramId"); - } - $param->paramid = "wsd_".$res['name']; - } - else { - $param->paramid = $paramId; - } - $params[] = $param; - } - - $obj = (object)array( - "sampling" => $interval['sampling'], - "startDate" => $interval['startTime'], - "stopDate" => $interval['stopTime'], - "list" => $params, - "fileformat" => $formatInfo['format'], - "timeformat" => $formatInfo['timeFormat'], - "compression" => $formatInfo['gzip'] - ); - - if (!isset($this->requestManager)) - $this->requestManager = new RequestManagerClass(); - - try { - $downloadResult = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::PARAMS, $this->service, $obj); - } catch (Exception $e) { - $this->throwError("executionError", "Exception detected : ".$e->getMessage()); - } - - if (!$downloadResult['success']) { - $this->throwError("serverError", $downloadResult['message']); - } - - if($downloadResult['status'] == 'in_progress') { - return ['success' => true, 'status' => 'in progress', 'id' => $downloadResult['id']]; - } elseif ($downloadResult['status'] == 'done') - { - $this->deleteProcess($downloadResult['id']); - return array('success' => true, 'status' => 'done', 'dataFileURLs' => WSConfigClass::getUrl().$downloadResult['result']); - } else { - return ['success' => false, 'message' => 'Unknown status ' . $downloadResult['status']]; - } - } - -/* -* delete process after execution : -* delete temporary files/folders ( JOBS/process_xxxx, RES/DDxxx ); -* delete job node in processManager.xml -*/ - private function deleteProcess($id) - { - $obj = (object)array('id' => $id); - - if (!isset($this->requestManager)) - $this->requestManager = new RequestManagerClass(); - - try { - $downloadResult = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::PROCESSDELETE, null, $obj); - } catch (Exception $e) { - $this->throwError("deleteProcessError", $e->getMessage()); - } - } - -/* -* generate AUTH token for access to REST services -*/ - public function getNewToken() - { - // generate token from timeStamp and some salt - $newToken = md5(1321 * (int)( time() / WSConfigClass::$timeLimitQuery)); - - return array('success' => true, 'token' => $newToken); - } - -/************************** WEB SERVICES **************************************/ - -/* -* public data only : user impex -*/ - public function getObsDataTree() - { - $res = $this->init(); - $this->initUserMgr(); - - $locParamSrc = USERWSDIR.'LocalParams.xml'; - $locParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml'; - - if (!copy($locParamSrc,WSConfigClass::getWsResultDir().$locParamDst)) - $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file'); - - return array('success' => true,'WorkSpace' => array("LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst)); - } - -/* -* get Parameter List for given user -*/ - public function getParameterList($data) - { - $res = $this->init($data); - $this->initUserMgr(); - - $vars = $res['vars']; - - $locParamSrc = USERWSDIR.'LocalParams.xml'; - $wsParamSrc = USERWSDIR.'WsParams.xml'; - - $locParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml'; - $wsParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_UserDefinedParameters.xml'; - - if (!copy($locParamSrc, WSConfigClass::getWsResultDir().$locParamDst)) - $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file for '.$this->userID); - - if (!copy($wsParamSrc, WSConfigClass::getWsResultDir().$wsParamDst)) - $this->throwError('workspaceError', 'No User Defined Parameters description file for '.$this->userID); - - return array('success' => true,'ParameterList' => - array("UserDefinedParameters" => WSConfigClass::getUrl().$wsParamDst, - "LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst, - "RemoteDataBaseParameters" => "not implemented")); - } - -/* -* getParameter -*/ - public function getParameter($data) - { - $res = $this->init($data); - - if (!$res['success']){ - $this->throwError("requestError", "Cannot parse request"); - } - - $this->initUserMgr(); - - $vars = $res['vars']; - - if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ - $this->throwError("requestError", "Requested time interval should be greater than 0"); - } - - $paramId = array(); - array_push($paramId, $vars["parameterID"]); - - if (!$vars["timeFormat"]) - $timeFormat = "ISO8601"; - else - $timeFormat = $vars["timeFormat"]; - - if (!$vars["gzip"]) - $gzip = 0; - else - $gzip = $vars["gzip"]; - - if (!$vars["stream"]) - $stream = 0; - else - $stream = $vars["stream"]; - - $this->service = strtolower(__FUNCTION__); - - $res = $this->doDownloadRequest( - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]), - array("params" => $paramId), - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream)); - - if ($res['success']) - return $res; - - $this->throwError("serverError", $res['message']); - } - -/* -* get user Catalogs list; Shared for impex -*/ - public function getCatalogsList($data) - { - $this->init($data); - $this->init($data); - return array('success' => true, 'CatalogsList' => $this->getTimeTablesCatalogsList('catalogs')); - } - -/* -* get user TimeTables list; Shared for impex -*/ - public function getTimeTablesList($data) - { - $this->init($data); - - return array('success' => true, 'TimeTablesList' => $this->getTimeTablesCatalogsList('timetables')); - } - - public function isAlive() - { - return true; - } - -/* -* get Dataset -*/ - public function getDataset($data) - { - $res = $this->init($data); - - if (!$res['success']){ - $this->throwError("requestError", "Cannot parse request"); - } - - $this->initUserMgr(); - - $vars = $res['vars']; - - if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ - $this->throwError("requestError", "Requested time interval should be greater than 0"); - } - - $dataSetDom = $this->getDatasetInfo($vars['datasetID']); - - $params = $dataSetDom->getElementsByTagName("parameter"); - - if ($params->length == 0) - $this->throwError("systemError", "Cannot find parameter list for dataset ".$vars['datasetID']); - - $paramId = array(); - - foreach ($params as $p) - $paramId[] = $p->nodeValue; - - if (!$vars["sampling"]) - { - $sampling = $dataSetDom->getElementsByTagName('min_sampling')->item(0)->nodeValue; - - $units = substr($sampling,-1); - $sampling = substr($sampling,0,strlen($sampling)-1); - - switch ($units) { -// case 'S': -// $sampling = floatval($sampling); -// break; - case 'M': - $sampling = floatval($sampling)*60; - break; - case 'H': - $sampling = floatval($sampling)*60*60; - break; - default: - } - } - else { - $sampling = $vars["sampling"]; - } - - if (!$vars["timeFormat"]) - $timeFormat = "ISO8601"; - else - $timeFormat = $vars["timeFormat"]; - - if (!$vars["gzip"]) - $gzip = 0; - else - $gzip = $vars["gzip"]; - - if (!$vars["stream"]) - $stream = 0; - else - $stream = $vars["stream"]; - - $this->service = strtolower(__FUNCTION__); - - $res = $this->doDownloadRequest( - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $sampling), - array("params" => $paramId), - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream)); - - if ($res['success']) return $res; - - $this->throwError("serverError", $res['message']); - } - -/* -* get status for jobs in batch -*/ - public function getStatus($data) - { - $result = $this->init($data); - - $id = $result['vars']['id']; - - if (!isset($this->requestManager)) - $this->requestManager = new RequestManagerClass(); - - try - { - $res = $this->requestManager->runWSRequest('nobody', 'nobody', FunctionTypeEnumClass::PROCESSGETINFO, null, $id); - } - catch (Exception $e) - { - // after first getStatus() call process is deleted - $jobsManager = new WSJobsManagerClass(); - - try - { - $res = $jobsManager->getResultFromProcessId($id); - if (!$res['success']) { - $this->throwError("processError","Cannot retrieve process $id info"); - } - - $resultTag = $this->isGetPlotRequest($res['result']) ? 'plotURL' : 'dataFileURLs'; - - return array('success' => true, 'status' => 'done', $resultTag => WSConfigClass::getUrl().$res['result']); - } - catch (Exception $e) - { - $this->throwError("getResultFromProcessIdError", "Exception detected : ".$e->getMessage()); - } - } - - if (!$res['success']) { - $this->throwError("processError","Cannot retrieve process $id info"); - } - - if ($res['status'] == 'in_progress') { - return array('success' => true, 'status' => 'in progress'); - } - - if ($res['error']) { - $this->throwError("processError","Process $id error code"); - } - - $this->deleteProcess($res['id']); - - $resultTag = $this->isGetPlotRequest($res['result']) ? 'plotURL' : 'dataFileURLs'; - - return array('success' => true, 'status' => $res['status'], $resultTag => WSConfigClass::getUrl().$res['result']); - } - -/* -* TODO Can be done by TTCONVERT function of AMDA_Kernel - more hard !!! -* TODO Think about this if merge/union will be also done by AMDA_Kernel -* -* get Time Table : shared for impex ; user' for user -*/ - public function getTimeTable($data) - { - $res = $this->init($data); - - if (!$res['success']){ - $this->throwError("requestError", "Cannot parse request"); - } - - $this->initUserMgr(true); - - $ttID = $res['vars']['ttID']; - - if ($this->userID == 'impex') { - $sharedObjMgr = new SharedObjectsMgr(); - $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID); - } - else - $ttSrc = USERTTDIR.$ttID.'.xml'; - - if (!file_exists($ttSrc)) { - $this->throwError("workspaceError", "No such table ".$ttID." for user ".$this->userID); - } - - $ttDst = substr(strtolower(__FUNCTION__), 3)."_".$this->userID."_".$this->requestTime."_$ttID.xml"; - - //TODO can be done by - // $res = $this->requestManager->runWSRequest($this->userID, $this->IPclient,FunctionTypeEnumClass::TTCONVERT, null, $ttID); - $this->xsl2vot($ttSrc,$ttDst); - - return array('success' => true, 'ttFileURL' => WSConfigClass::getUrl().$ttDst); - } - -/* -* get Orbits -*/ - public function getOrbites($data) - { - $res = $this->init($data); - - if (!$res['success']){ - $this->throwError("requestError", "Cannot parse request"); - } - - $this->initUserMgr(); - - $vars = $res['vars']; - - if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ - $this->throwError("requestError", "Requested time interval should be greater than 0"); - } - - $spacecraft = $vars["spacecraft"]; - $coordinateSystem = $vars["coordinateSystem"]; - - if (!$vars["units"]) - $units = "km"; - else - $units = $vars["units"]; - - $orbitRequest = array("startTime" => $vars["startTime"], - "stopTime" => $vars["stopTime"], - "spacecraft" => $spacecraft, - "coordinateSystem" => $coordinateSystem, - "units" => $units - ); - - $orbitParam = $this->getOrbitParameter($orbitRequest); - - $paramId = array(); - array_push($paramId, $orbitParam['parameterID']); - - if (!$vars["timeFormat"]) - $timeFormat = "ISO8601"; - else - $timeFormat = $vars["timeFormat"]; - - if (!$vars["gzip"]) - $gzip = 0; - else - $gzip = $vars["gzip"]; - - $this->service = strtolower(__FUNCTION__); - - $res = $this->doDownloadRequest( - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]), - array("params" => $paramId), - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream)); - - if ($res['success']) return $res; - - $this->throwError("serverError",$res['message']); - } - -/* -* getPlot : predefined; by mission -*/ - public function getPlot($data) - { - $res = $this->init($data); - - if (!$res['success']){ - $this->throwError("requestError", "Cannot parse request"); - } - - $this->initUserMgr(); - - $vars = $res['vars']; - $mission = $vars["missionID"]; - - $resultFilePrefix = strtolower(__FUNCTION__)."_".$mission."_".date("YmdHms",strtotime($vars["startTime"]))."_".date("YmdHms",strtotime($vars["stopTime"])); - - if ($this->userID != "impex") - $resultFilePrefix .= "_".$this->userID; - - $dom = new DomDocument("1.0"); - $dom->load(plotsXml); - - $missionTag = $dom->getElementById($mission); - $params = $missionTag->getElementsByTagName('param'); - - $paramsList = array(); - foreach ($params as $param) - $paramsList[] = $param->getAttribute('name'); - - $requestObject = (Object) array( - "nodeType" => "request", - "file-format" => "PNG", - "result-file" => $resultFilePrefix, - "timesrc" => "Interval", - "startDate" => $vars["startTime"], - "stopDate" => $vars["stopTime"], - "parameters" => array() - ); - - foreach ($paramsList as $paramToPlot) - { - $paramObject = (Object) array( - "paramid" => $paramToPlot - ); - - $requestObject->{"parameters"}[] = $paramObject; - } - - $this->service = strtolower(__FUNCTION__); - - if (!isset($this->requestManager)) - $this->requestManager = new RequestManagerClass(); - - try { - $plotResult = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::PARAMS, $this->service, $requestObject); - } catch (Exception $e) { - $this->throwError("plotError", "Exeption detected : ".$e->getMessage()); - } - - if (!$plotResult['success']) { - $this->throwError("serverError", $plotResult['message']); - } - - if($plotResult['status'] == 'in_progress') { - return ['success' => true, 'status' => 'in progress', 'id' => $plotResult['id']]; - } elseif ($plotResult['status'] == 'done') - { - $this->deleteProcess($plotResult['id']); - return array('success' => true, 'status' => 'done', 'plotFileURL' => WSConfigClass::getUrl().$plotResult['result']); - } else { - return ['success' => false, 'message' => 'Unknown status ' . $plotResult['status']]; - } - } -} -?> diff --git a/php/testWebServer.php b/php/testWebServer.php index b5bbaa6..cec0f9e 100644 --- a/php/testWebServer.php +++ b/php/testWebServer.php @@ -1,7 +1,7 @@ <?php -require_once("classes/WSClientSOAP.php"); -require_once("classes/WSClientREST.php"); +require_once("WebServices/WSClientSOAP.php"); +require_once("WebServices/WSClientREST.php"); function runSuiteTests($client) { @@ -150,7 +150,7 @@ function runSuiteTests($client) } } -$clientSOAP = new WSClientSOAP("http://localhost/NEWAMDA-BENJAMIN/public/wsdl/Methods_AMDA.wsdl"); +$clientSOAP = new WSClientSOAP("http://apus.irap.omp.eu/NEWAMDA/public/wsdl/Methods_AMDA.wsdl"); echo "==> Suite tests for SOAP client".PHP_EOL; runSuiteTests($clientSOAP); diff --git a/public/WebServices/XML/AmdaPlots.xml b/public/WebServices/XML/AmdaPlots.xml deleted file mode 100755 index 79127e4..0000000 --- a/public/WebServices/XML/AmdaPlots.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<missions> - <mission xml:id='ACE'> - <param name='sw_vb'/> - <param name='sw_t'/> - <param name='sw_n'/> - <param name='imf'/> - <param name='imf_mag'/> - </mission> - <mission xml:id='WIND'> - <param name='wnd_swe_vmag'/> - <param name='wnd_swe_vth'/> - <param name='wnd_swe_n'/> - <param name='wnd_b' class="mag"/> - <param name='wnd_bmag'/> - </mission> - <mission xml:id='STEREO-A'> - <param name='vpbulk_sta'/> - <param name='vth_sta'/> - <param name='np_sta'/> - <param name='sta_b'/> - <param name='sta_btot'/> - </mission> - <mission xml:id='STEREO-B'> - <param name='vpbulk_stb'/> - <param name='vth_stb'/> - <param name='np_stb'/> - <param name='stb_b'/> - <param name='stb_btot'/> - </mission> - <mission xml:id='VEX'> - <param name='vex_mag_4s'/> - <param name='vex_mag_4s_tot'/> - </mission> - <mission xml:id='OMNI'> - <param name='omni_sw_v'/> - <param name='omni_sw_t'/> - <param name='omni_sw_n'/> - <param name='omni_imf' /> - <param name='omni_imf_mag'/> - </mission> - <mission xml:id='GEOMAG'> - <param name='omni_kp'/> - <param name='omni_dst'/> - <param name='omni_ae'/> - </mission> -</missions> - -- libgit2 0.21.2