From ffc5cb816f6e1c869e840b47a7a89824e447abc0 Mon Sep 17 00:00:00 2001 From: Elena.Budnik <ebudnik@irap.omp.eu> Date: Tue, 16 May 2017 15:54:32 +0200 Subject: [PATCH] temporary commit --- src/InputOutput/IHMImpl/Config/IHMConfigClass.php | 24 +++++++++++++++++++++++- src/InputOutput/IHMImpl/IHMInputOutputClass.php | 3 ++- src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php | 5 +++-- src/InputOutput/IHMImpl/Tools/CommonClass.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/InputOutput/IHMImpl/Tools/IHMExpressionParserClass.php | 28 ++++++++++++++++++++++------ src/InputOutput/IHMImpl/Tools/IHMImpexParamClass.php | 288 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php | 38 ++++++++++++++++++++------------------ src/Request/ParamInfoRequestClass.php | 33 ++++++++++++++++++++++++++------- src/Request/ParamInfoRequestDataClass.php | 2 ++ src/Request/ParamsRequestImpl/ParamsRequestClass.php | 27 ++++++++++++++++++++++++++- src/Request/ParamsRequestImpl/ParamsRequestDataClass.php | 19 +++++++++++++++++-- src/RequestManager.php | 9 +++++---- 14 files changed, 615 insertions(+), 52 deletions(-) create mode 100644 src/InputOutput/IHMImpl/Tools/IHMImpexParamClass.php diff --git a/src/InputOutput/IHMImpl/Config/IHMConfigClass.php b/src/InputOutput/IHMImpl/Config/IHMConfigClass.php index 6f988fe..441f6ee 100644 --- a/src/InputOutput/IHMImpl/Config/IHMConfigClass.php +++ b/src/InputOutput/IHMImpl/Config/IHMConfigClass.php @@ -50,7 +50,11 @@ class IHMConfigClass private static $userParamMgrFile = "WsParams.xml"; private static $userName; - + + private static $userHost; + + public static $remoteDataDir = "/home/budnik/RemoteDataCenter/MAJ/"; + public static function setUserName($userName) { self::$userName = $userName; @@ -60,7 +64,17 @@ class IHMConfigClass { return self::$userName; } + + public static function setUserHost($userHost) + { + self::$userHost = $userHost; + } + public static function getUserHost() + { + return self::$userHost; + } + public static function getUserPath() { $userPath = IHM_SRC_DIR.self::$dataDir.self::$userName.'/'; @@ -198,6 +212,14 @@ class IHMConfigClass return $localBasePath; } + public static function getRemoteParamsFile() + { + $remoteBasePath = self::getUserPath().self::$wsDir; + + + return $remoteBasePath.'RemoteParams.xml'; + } + public static function getRequestPath() { $requestPath = self::getUserPath().self::$requestDir; diff --git a/src/InputOutput/IHMImpl/IHMInputOutputClass.php b/src/InputOutput/IHMImpl/IHMInputOutputClass.php index b3f3ec7..1ca7d89 100644 --- a/src/InputOutput/IHMImpl/IHMInputOutputClass.php +++ b/src/InputOutput/IHMImpl/IHMInputOutputClass.php @@ -12,9 +12,10 @@ class IHMInputOutputClass implements InputOutputInterface /* * @brief Constructor */ - function __construct($userName) + function __construct($userName, $userHost) { IHMConfigClass::setUserName($userName); + IHMConfigClass::setUserHost($userHost); } /* diff --git a/src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php b/src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php index 180f27e..dfe7d62 100644 --- a/src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php +++ b/src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php @@ -9,6 +9,7 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface { private $paramInfoData = null; private $paramTemplateMgr = null; + private $paramImpexMgr = null; /* * @brief Constructor @@ -27,6 +28,7 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface switch ($input->type) { case 'plot_init' : + $this->paramInfoData->setType(ParamInfoTypeEnumClass::PLOTINIT); if (!isset($input->paramId) || empty($input->paramId)) @@ -37,13 +39,35 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface $paramFilePath = $this->paramTemplateMgr->getTemplatePath($input->paramId); else $paramFilePath = IHMConfigClass::getLocalParamDBPath().$input->paramId.".xml"; + + if (!file_exists("$paramFilePath")) + throw new Exception("Cannot find parameter definition file"); + + $this->paramInfoData->setFilePath($paramFilePath); + break; - if (!file_exists($paramFilePath)) + case 'impex_plot_init' : + + $this->paramInfoData->setType(ParamInfoTypeEnumClass::IMPEXPLOTINIT); + + if (!isset($input->paramId) || empty($input->paramId)) + throw new Exception("Param info request need a param id as argument"); + + if (!$this->paramImpexMgr) + { + $this->paramImpexMgr = new IHMImpexParamClass(); + } + + $paramFilePath = $this->paramImpexMgr->getParamInfoPlotPath($input->paramId); + + if (!$paramFilePath || !file_exists($paramFilePath)) throw new Exception("Cannot find parameter definition file"); $this->paramInfoData->setFilePath($paramFilePath); break; + case 'param_info' : + $this->paramInfoData->setType(ParamInfoTypeEnumClass::PARAMINFO); if (!isset($input->paramId) || empty($input->paramId)) @@ -61,8 +85,31 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface $this->paramInfoData->setFilePath($paramInfoFilePath); break; + + case 'impex_param_info' : + + $this->paramInfoData->setType(ParamInfoTypeEnumClass::IMPEXINFO); + if (!isset($input->paramId) || empty($input->paramId)) + throw new Exception("Param info request need a param id as argument"); + + if (!$this->paramImpexMgr) + { + $this->paramImpexMgr = new IHMImpexParamClass(); + } + $this->paramImpexMgr->setParamTemplateListFilePath($input->paramId); + $templatedParams = $this->paramImpexMgr->getParamTemplates(); + + $simRegion = $this->paramImpexMgr->getSimulationRegion($input->paramId); + + // No SimulationRuns (LESIA) + if ($simRegion == "UNKNOWN") + $simRegion = $this->paramImpexMgr->getResourceID($input->paramId); + + $this->paramInfoData->setTemplateInfo($templatedParams[$simRegion]); + + break; default : - throw new Exception("Para info request type '".$input->type."' not yet implemented"); + throw new Exception("Param info request type '".$input->type."' not yet implemented"); } $this->paramInfoData->setParamId($input->paramId); @@ -80,10 +127,18 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface $result = array("success" => false, "message" => "Cannot get plot init"); $this->getOutputPlotInit($data, $result); break; + case ParamInfoTypeEnumClass::IMPEXPLOTINIT : + $result = array("success" => false, "message" => "Cannot get impex plot init"); + $this->getOutputPlotInit($data, $result); + break; case ParamInfoTypeEnumClass::PARAMINFO : $result = array("success" => false, "message" => "Cannot get param info"); $this->getOutputParamInfo($data, $result); break; + case ParamInfoTypeEnumClass::IMPEXINFO : + $result = array("success" => false, "message" => "Cannot get impex param info"); + $this->getOutputParamInfo($data, $result); + break; default: //Nothing ToDo } diff --git a/src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php b/src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php index 7eeddaa..5d3e810 100644 --- a/src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php +++ b/src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php @@ -52,7 +52,8 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas $downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::ASCII); $formatExtension = ".txt"; break; - case "vot" : + case "vot" : + case "VOT" : $downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::VOTABLE); $formatExtension = ".vot"; break; @@ -65,7 +66,7 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas $formatExtension = ".json"; break; default : - throw new Exception('File format not implemented.'); + throw new Exception('File format '.$input->fileformat.' not implemented.'); } if ($input->fileprefix != "") diff --git a/src/InputOutput/IHMImpl/Tools/CommonClass.php b/src/InputOutput/IHMImpl/Tools/CommonClass.php index 01264af..510d0c3 100644 --- a/src/InputOutput/IHMImpl/Tools/CommonClass.php +++ b/src/InputOutput/IHMImpl/Tools/CommonClass.php @@ -34,6 +34,57 @@ class CommonClass $t = date("His",$timeStamp)."000"; return $y.$d.$t; } + /* + * @brief DDTime to timestamp conversion + */ + public static function DDTimeToTimeStamp($DDTime) + { + date_default_timezone_set('UTC'); + $date = DateTime::createFromFormat('YzHisu', $DDTime); + + return strtotime($date->format("Y-m-d\TH:i:s")); + } + + /* + * @brief DDTime to ISO conversion + */ + public static function DDTimeToIso($DDTime) + { + $date = DateTime::createFromFormat('YzHisu', $DDTime); + + return $date->format("Y-m-d\TH:i:s"); + } + + /* + * @brief DDTime to ISO conversion + */ + public static function DDStartIntervalToStopIso($DDStart, $DDInterval) + { + $startStamp = self::DDTimeToTimeStamp($DDStart); + $intStamp = self::DDTimeToTimeStamp($DDInterval); + + return date("Y-m-d\TH:i:s", $startStamp + $intStamp); + } + + public static function rrmdir($dir) + { + if (is_dir($dir)) + { + $objects = scandir($dir); + foreach ($objects as $object) + { // Recursively delete a directory that is not empty and directorys in directory + if ($object != "." && $object != "..") + { // If object isn't a directory recall recursively this function + if (filetype($dir."/".$object) == "dir") + self::rrmdir($dir."/".$object); + else + unlink($dir."/".$object); + } + } + reset($objects); + rmdir($dir); + } + } } ?> \ No newline at end of file diff --git a/src/InputOutput/IHMImpl/Tools/IHMExpressionParserClass.php b/src/InputOutput/IHMImpl/Tools/IHMExpressionParserClass.php index 8432ed0..e13f4ed 100644 --- a/src/InputOutput/IHMImpl/Tools/IHMExpressionParserClass.php +++ b/src/InputOutput/IHMImpl/Tools/IHMExpressionParserClass.php @@ -45,6 +45,7 @@ class IHMExpressionParserClass private $functionsArray; private $templatedParamMgr = NULL; + private $impexParamMgr = NULL; private $isTest = FALSE; @@ -143,30 +144,45 @@ class IHMExpressionParserClass //group elements in tree $tree = $this->buildTreeElements($elements); - + //translate $params_full = array(); $translated = $this->translate($tree,$params_full); - + //keep only params id $params = array(); - foreach ($params_full as $param_full) { + foreach ($params_full as $param_full) { if (array_key_exists("template_args", $param_full)) { $params[] = array( "paramid" => $param_full['id'], "fullparamid" => $param_full['fullparamid'], "template_args" => $param_full['template_args'] - ); + ); } else if (!$this->isTest && (($templated_param_info = $this->templatedParamMgr->parseTemplatedParam($param_full["id"])) !== FALSE)) { - $params[] = $templated_param_info; + $params[] = $templated_param_info; + } + else if ($this->isImpexParam($param_full["id"])) + { + if (!$this->impexParamMgr) + { + $this->impexParamMgr = new IHMImpexParamClass(); + } + $templated_param_info = $this->impexParamMgr->parseImpexParam($param_full["id"]); + $params[] = $templated_param_info; } else $params[] = array("paramid" => $param_full["id"]); } + return array("expression" => $translated, "params" => $params); } - + + private function isImpexParam($paramID) + { + return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$paramID); + } + /* * @brief clean expression */ diff --git a/src/InputOutput/IHMImpl/Tools/IHMImpexParamClass.php b/src/InputOutput/IHMImpl/Tools/IHMImpexParamClass.php new file mode 100644 index 0000000..18a0569 --- /dev/null +++ b/src/InputOutput/IHMImpl/Tools/IHMImpexParamClass.php @@ -0,0 +1,288 @@ +<?php + +/** + * @class IHMImpexParamClass + * @brief Class used to manage impex parameters + * @details + */ +class IHMImpexParamClass extends IHMParamTemplateClass +{ + private $dataProducer = 'UNKNOWN'; + private $simulationRegion = 'UNKNOWN'; + private $dom; + private $filePath; + + public static $paramPrefix = "spase___IMPEX_NumericalOutput_"; + + /* + * @brief Constructor + */ + function __construct() + { + $this->filePath = IHMConfigClass::getRemoteParamsFile(); + $this->dom = new DomDocument("1.0"); + + if (!file_exists($this->filePath)) + throw new Exception("no RemoteParams File ".$this->filePath); + + $this->dom->load($this->filePath); + + } + + public function param2dd($paramID) + { + $pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_","@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_"); + return strtr($paramID,$pairs); + } + + public function getDataProducer($paramId) + { + $paramNode = $this->dom->getElementById($paramId); + + while ($paramNode->tagName !== 'dataCenter') + { + $paramNode = $paramNode->parentNode; + } + + if ( $paramNode ) + $this->dataProducer = $paramNode->getAttribute('xml:id'); + + return $this->dataProducer; + } + + public function getResourceID($paramId) + { + $paramNode = $this->dom->getElementById($paramId); + + while ($paramNode->tagName !== 'dataset') + { + $paramNode = $paramNode->parentNode; + } + + if ( $paramNode ) + $resourceID = $paramNode->getAttribute('xml:id'); + + return $resourceID; + } + + public function getTranslatedResourceID($paramId) + { + return $this->param2dd($this->getResourceID($paramId)); + } + + public function getSimulationRegion($paramId) + { + $paramNode = $this->dom->getElementById($paramId); + + while ($paramNode->tagName !== 'simulationRegion') + { + $paramNode = $paramNode->parentNode; + if ( $paramNode->tagName == 'simulationModel') break; + + } + + if ( $paramNode && $paramNode->tagName == 'simulationRegion') + $this->simulationRegion = $paramNode->getAttribute('xml:id'); + + return $this->simulationRegion; + } + + public function getParameterKey($paramId) + { + $parameterKey = 'UNKNOWN'; + + $paramNode = $this->dom->getElementById($paramId); + + if ( $paramNode ) + $parameterKey = $paramNode->getAttribute('shortName'); + + return $parameterKey; + } + + + public function getParameterSize($paramId) + { + $parameterSize = 'UNKNOWN'; + + $paramNode = $this->dom->getElementById($paramId); + + if ( $paramNode ) + $parameterSize = $paramNode->getAttribute('size'); + + return $parameterSize; + } + + public function getAccessUrl($paramId) + { + $url = 'UNKNOWN'; + + $paramNode = $this->dom->getElementById($paramId); + + while ($paramNode->tagName !== 'dataset') + { + $paramNode = $paramNode->parentNode; + + } + + if ( $paramNode && $paramNode->hasAttribute('accessUrl')) + $url = $paramNode->getAttribute('accessUrl'); + + return $url; + } + + public function setParamTemplateListFilePath($paramId) + { + $this->paramTemplateListFilePath = IHMConfigClass::$remoteDataDir.$this->getDataProducer($paramId).'_Templates.xml'; + } + + /* + * + */ + public function getImpexFullParamId($param_id, $templateArgs = NULL) { + + if (!$templateArgs) + return $param_id; + + $fullParamId = $param_id; + foreach ($templateArgs as $key => $value) + $fullParamId .= "_".$value; + + return $fullParamId; + } + + public function getImpexParamId($fullParamId) + { + $pos = strrpos($fullParamId,'_'); + $id = $fullParamId; + + $find = false; + + while ($pos && !$find) + { + $id = substr($id,0,$pos); + $param = $this->dom->getElementById($id); + if ($param) $find = true; + $pos = strrpos($id,'_'); + } + if (!$find) + throw new Exception("Can not find IMPEX parameter ".$fullParamId); + + return $id; + } + + public function parseImpexParam($param_expression) + { + $paramId = $this->getImpexParamId($param_expression); + $this->getDataProducer($paramId); + $this->getSimulationRegion($paramId); + $this->setParamTemplateListFilePath($paramId); + + $templateArgsString = substr($param_expression,strlen($paramId."_")); + + $allTemplatedParams = $this->getParamTemplates(); + $templatedParams = $allTemplatedParams[$this->simulationRegion]; + $args = $templatedParams['arguments']; + + $templateArgs = array(); + foreach ($args as $key => $value) + { + /*$r = print_r($templatedParams,true); */ + switch($value["type"]) + { + case 'float' : + case 'double' : + case 'int': + $pos = strpos($templateArgsString,'_'); + $arg_value = substr($templateArgsString,0,$pos); + $templateArgsString = substr($templateArgsString,$pos+1); + break; + case 'list' : + $arg_items = $value['items']; + foreach ($arg_items as $arg_key => $arg_val) + { + if ( strncmp($arg_key, $templateArgsString, strlen($arg_key)) === 0) + { + $arg_value = $arg_key; + $templateArgsString = substr($templateArgsString,strlen($arg_key)+1); + break; + } + } + break; + default: + } + + $templateArgs[$key] = $arg_value; + } + + $params = array( + "paramid" => $paramId, + "fullparamid" => $param_expression, + "template_args" => $templateArgs + ); + + return $params; + } + + /* + * List of Vector params in this data set + */ + public function getVectorList($resourceId) + { + $vectorList = array(); + + $datasetNode = $this->dom->getElementById($resourceId); + if ($datasetNode) + { + $params = $datasetNode->getElementsByTagName('parameter'); + foreach ($params as $param) + { + if ($param->hasAttribute('size')) + if ($param->getAttribute('size') == '3') + $vectorList[] = $param->getAttribute('shortName'); + } + } + + return $vectorList; + } + + //IMPEXPLOTINIT - predefined plot output + public function getParamInfoPlotPath($paramId) + { + + if ($this->getDataProducer($paramId) != "IPIM" && !$this->isSpectra($paramId)) + return null; + + $templateXml = IHMConfigClass::$remoteDataDir.$this->getDataProducer($paramId).'_PlotSettings.xml'; + + if (!file_exists($templateXml)) + throw new Exception("No $templateXml"); + + $dom = new DomDocument("1.0"); + if (!$dom->load($templateXml)) + throw new Exception("Cannot load $templateXml"); + + $paramNode = $dom->documentElement; + $paramNode->setAttribute("xml:id", $paramId); + + $plotParamNode = $paramNode->getElementsByTagName('param'); + if ($plotParamNode->length == 0) + throw new Exception("No Plot Param Node in $templateXml"); + + $plotParamNode->item(0)->setAttribute("id", $paramId); + + $filePath = IHMConfigClass::getUserWSPath().$paramId."_plot.xml"; + + $dom->save($filePath); + + return $filePath; + + } + + public function isSpectra($paramId) + { + $paramNode = $this->dom->getElementById($paramId); + + return $paramNode->hasAttribute('isSpectra'); + + } +} \ No newline at end of file diff --git a/src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php b/src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php index 915fb55..8e54aa3 100644 --- a/src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php +++ b/src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php @@ -10,6 +10,7 @@ class IHMParamManagerClass protected $userParameterLoader = null; protected $expressionParser = null; protected $templateParamsManager = null; + protected $paramImpexMgr = null; /* * @brief Constructor @@ -23,13 +24,15 @@ class IHMParamManagerClass * @brief Add an existing parameter */ public function addExistingParam($param, $paramsData, $templateArgs = NULL) - { + { if ($this->isDerivedParam($param)) return $this->addDerivedParam($param,$paramsData); else if ($this->isUploadedParam($param)) return $this->addUploadedParam($param,$paramsData); + else if ($this->isImpexParam($param)) + return $this->addImpexParam($param,$paramsData,$templateArgs); else - return $this->addLocalParam($param,$paramsData, $templateArgs); + return $this->addLocalParam($param,$paramsData,$templateArgs); return ""; } @@ -37,13 +40,15 @@ class IHMParamManagerClass * @brief Add a process parameter */ public function addProcessParam($paramId,$expression,$params,$sampling,$gap,$dateModif,$paramsData) - { - $paramsData->addProcessParamToCreate($paramId, $expression, $params, $sampling, $gap,$dateModif); - + { + $paramsData->addProcessParamToCreate($paramId, $expression, $params, $sampling, $gap,$dateModif); + foreach ($params as $param) { - $template_args = NULL; + $template_args = NULL; + if (array_key_exists("template_args", $param)) $template_args = $param["template_args"]; + $this->addExistingParam($param["paramid"],$paramsData,$template_args); } @@ -65,6 +70,14 @@ class IHMParamManagerClass { return preg_match("#^wsd_#",$param); } + + /* + * @brief Detect if it's IMPEX parameter + */ + private function isImpexParam($param) + { + return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$param); + } /* * @brief Add a local parameter @@ -84,12 +97,13 @@ class IHMParamManagerClass } else $paramId = $param; - + //check templated parameter $real_param_id = $paramId; if ($this->templateParamsManager->isTemplatedParam($paramId)) { $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs); $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); + if (empty($paramPath) || !file_exists($paramPath)) throw new Exception('Cannot generate parameter template file '.$paramId); } @@ -184,7 +198,58 @@ class IHMParamManagerClass return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); } - + + /* + * @brief Add IMPEX parameter : create dynamically xml parameter descriptor in user WS + */ + private function addImpexParam($param,$paramsData,$templateArgs = NULL) + { + if (!isset($this->paramImpexMgr)) + $this->paramImpexMgr = new ImpexParamManager(); + + $parameterID = $this->paramImpexMgr->getImpexFullParamId($param, $templateArgs); + + $requestNodes = $paramsData->getRequestNodes(); + + // it is PARAMSGEN + if (!$requestNodes) { + return array("id" => $parameterID); + } + + $timesNode = $requestNodes[0]->getTimesNode(); + $intervals = $timesNode->getIntervals(); + $originFile = IHMConfigClass::getUserWSPath().$parameterID.".xml"; + + if (!file_exists($originFile)) { + // create IMPEX parameter info and data + $res = $this->paramImpexMgr->createImpexParameter($param, $intervals, $templateArgs); + + if (!$res["success"]) + throw new Exception('Error to create IMPEX parameter : '.$res["message"]); + + $newParamNode = $paramsData->addLocalParamToCreate($res["param"]["id"], + $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], + $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], + $res["param"]["info"]["type"],$res["param"]["info"]["size"], + $res["param"]["dateModif"],true); + + $tableDef = $res["param"]["info"]["tableDef"]; + if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) + { + + } + + return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]); + } + else { + // add IMPEX parameter data + $this->paramImpexMgr->addImpexData($param, $intervals, $templateArgs); + $paramsData->addParamToCopy($parameterID, $originFile); + + return array("id" => $parameterID); + } + } + /* * @brief Add uploaded parameter */ diff --git a/src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php b/src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php index 48e0e13..f20eb90 100644 --- a/src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php +++ b/src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php @@ -8,25 +8,27 @@ class IHMParamTemplateClass { protected $paramTemplateList = null; + protected $paramTemplateListFilePath; - private static $paramTemplateNode = 'paramTemplate'; - private static $paramTemplateIdAtt = 'paramId'; - private static $paramTemplateFileNameAtt = 'fileName'; - private static $paramTemplateArgumentsNode = 'arguments'; - private static $paramTemplateArgumentNode = 'argument'; - private static $paramTemplateArgumentKeyAtt = 'key'; - private static $paramTemplateArgumentNameAtt = 'name'; - private static $paramTemplateArgumentTypeAtt = 'type'; - private static $paramTemplateArgumentDefaultAtt = 'default'; - private static $paramTemplateArgumentListItemNode = 'item'; - private static $paramTemplateArgumentListItemKeyAtt = 'key'; - private static $paramTemplateArgumentListItemNameAtt = 'name'; + protected static $paramTemplateNode = 'paramTemplate'; + protected static $paramTemplateIdAtt = 'paramId'; + protected static $paramTemplateFileNameAtt = 'fileName'; + protected static $paramTemplateArgumentsNode = 'arguments'; + protected static $paramTemplateArgumentNode = 'argument'; + protected static $paramTemplateArgumentKeyAtt = 'key'; + protected static $paramTemplateArgumentNameAtt = 'name'; + protected static $paramTemplateArgumentTypeAtt = 'type'; + protected static $paramTemplateArgumentDefaultAtt = 'default'; + protected static $paramTemplateArgumentListItemNode = 'item'; + protected static $paramTemplateArgumentListItemKeyAtt = 'key'; + protected static $paramTemplateArgumentListItemNameAtt = 'name'; /* * @brief Constructor */ function __construct() { + $this->paramTemplateListFilePath = IHMConfigClass::getParamTemplateListFilePath(); } /* @@ -227,27 +229,27 @@ class IHMParamTemplateClass /* * @brief Load list of templated parameters */ - private function loadUserParamManagerFile() + protected function loadUserParamManagerFile() { if (isset($this->paramTemplateList)) return; $this->paramTemplateList = array(); - + //load xml file $dom = new DomDocument("1.0"); - if (!$dom->load(IHMConfigClass::getParamTemplateListFilePath())) + if (!$dom->load($this->paramTemplateListFilePath)) return; - + $paramTemplateNodes = $dom->getElementsByTagName(self::$paramTemplateNode); - + foreach ($paramTemplateNodes as $paramTemplateNode) { $paramId = $paramTemplateNode->getAttribute(self::$paramTemplateIdAtt); $paramFileName = $paramTemplateNode->getAttribute(self::$paramTemplateFileNameAtt); if (empty($paramId) || empty($paramFileName)) continue; - + $arguments = array(); $argumentsNode = $paramTemplateNode->getElementsByTagName(self::$paramTemplateArgumentsNode); diff --git a/src/Request/ParamInfoRequestClass.php b/src/Request/ParamInfoRequestClass.php index df5d9c2..92da765 100644 --- a/src/Request/ParamInfoRequestClass.php +++ b/src/Request/ParamInfoRequestClass.php @@ -14,7 +14,8 @@ class ParamInfoRequestClass extends RequestAbstractClass if (!isset($this->requestData)) return false; - if ($this->requestData->getType() == ParamInfoTypeEnumClass::PLOTINIT) { + if ($this->requestData->getType() == ParamInfoTypeEnumClass::PLOTINIT + || $this->requestData->getType() == ParamInfoTypeEnumClass::IMPEXPLOTINIT) { //Force load of node files to init the NodeFactory foreach (glob(dirname(__FILE__)."/ParamsRequestImpl/Nodes/Requests/*NodeClass.php") as $filename) { require_once $filename; @@ -29,6 +30,21 @@ class ParamInfoRequestClass extends RequestAbstractClass */ public function run() { + + if ($this->requestData->getType() == ParamInfoTypeEnumClass::IMPEXINFO) + { + $this->requestData->setSuccess(true); + + $result = array(); + $result['dimensions'] = array( + 'dim1' => 1, + 'dim2' => 1 + ); + + $this->requestData->setResult($result); + return $this->requestData->getSuccess(); + } + $dom = new DOMDocument("1.0","UTF-8"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; @@ -41,20 +57,22 @@ class ParamInfoRequestClass extends RequestAbstractClass $this->requestData->setLastErrorMessage("Cannot load file"); return false; } - + switch ($this->requestData->getType()) { - case ParamInfoTypeEnumClass::PLOTINIT : + case ParamInfoTypeEnumClass::IMPEXPLOTINIT : + case ParamInfoTypeEnumClass::PLOTINIT : $this->runFromParamFile($dom); - break; + break; case ParamInfoTypeEnumClass::PARAMINFO : $this->runFromParamInfoFile($dom); break; default : - $this->requestData->setLastErrorMessage("Unknown ParamInfo type"); + $this->requestData->setLastErrorMessage("Unknown ParamInfo type "); } return $this->requestData->getSuccess(); } + private function runFromParamFile($dom) { $paramNode = new ParamNodeClass(); @@ -67,17 +85,18 @@ class ParamInfoRequestClass extends RequestAbstractClass } switch ($this->requestData->getType()) { + case ParamInfoTypeEnumClass::IMPEXPLOTINIT : case ParamInfoTypeEnumClass::PLOTINIT : $outputNode = $paramNode->getOutput(); if (!isset($outputNode)) { $this->requestData->setLastErrorMessage("Cannot parse output node"); return false; - } + } $plotNode = $outputNode->getChildInstanceByName("plot"); if (!isset($plotNode)) { $this->requestData->setLastErrorMessage("Cannot parse plot node"); return false; - } + } $this->requestData->setResult($plotNode); $this->requestData->setSuccess(true); return true; diff --git a/src/Request/ParamInfoRequestDataClass.php b/src/Request/ParamInfoRequestDataClass.php index 9e851ea..ad9daaf 100644 --- a/src/Request/ParamInfoRequestDataClass.php +++ b/src/Request/ParamInfoRequestDataClass.php @@ -9,7 +9,9 @@ abstract class ParamInfoTypeEnumClass { const UNKNOWN = ""; const PLOTINIT = "plot_init"; + const IMPEXPLOTINIT = "impex_plot_init"; const PARAMINFO = "param_info"; + const IMPEXINFO = "impex_param_info"; } /** diff --git a/src/Request/ParamsRequestImpl/ParamsRequestClass.php b/src/Request/ParamsRequestImpl/ParamsRequestClass.php index d582a65..b24fbfd 100644 --- a/src/Request/ParamsRequestImpl/ParamsRequestClass.php +++ b/src/Request/ParamsRequestImpl/ParamsRequestClass.php @@ -177,10 +177,35 @@ class ParamsRequestClass extends ProcessRequestClass touch($destinationFile, $value["dateModif"]); } + //create and copy local params files + foreach ($this->requestData->getLocalParamsToCreateAndCopy() as $key => $value) + { + $doc = new DOMDocument("1.0", "UTF-8"); + $doc->preserveWhiteSpace = false; + $doc->formatOutput = true; + if (!$xmlNode = $value["param"]->toXMLNode($doc)) + { + $this->requestData->setLastErrorMessage('Cannot create params XML file for '.$key); + return false; + } + + $doc->appendChild($xmlNode); + + $originFile = IHMConfigClass::getUserWSPath().$key.".xml"; + $destinationFile = KernelConfigClass::getRequestParamsPath($this->requestData->getWorkingPath()).$key.".xml"; + + if (!$doc->save($destinationFile) || !$doc->save($originFile)) + { + $this->requestData->setLastErrorMessage('Cannot save params XML file for '.$key); + return false; + } + + touch($originFile, $value["dateModif"]); + touch($destinationFile, $value["dateModif"]); + } return true; } - /* * @brief Run a params request */ diff --git a/src/Request/ParamsRequestImpl/ParamsRequestDataClass.php b/src/Request/ParamsRequestImpl/ParamsRequestDataClass.php index e26d4b7..11dd960 100644 --- a/src/Request/ParamsRequestImpl/ParamsRequestDataClass.php +++ b/src/Request/ParamsRequestImpl/ParamsRequestDataClass.php @@ -26,6 +26,7 @@ class ParamsRequestDataClass extends ProcessRequestDataClass private $waitingResults = array(); private $processParamsToCreate = array(); private $localParamsToCreate = array(); + private $localParamsToCreateAndCopy = array(); private $paramsToCopy = array(); private $paramId = ""; @@ -133,6 +134,7 @@ class ParamsRequestDataClass extends ProcessRequestDataClass } $newParam->setProcess($expression); $newParam->setOutput(); + $this->processParamsToCreate[$paramId] = array('param' => $newParam, 'dateModif' => $dateModif); } @@ -141,7 +143,12 @@ class ParamsRequestDataClass extends ProcessRequestDataClass return $this->localParamsToCreate; } - public function addLocalParamToCreate($paramId, $viId, $realVarId, $minSampling, $maxSampling, $type, $size, $dateModif) + public function getLocalParamsToCreateAndCopy() + { + return $this->localParamsToCreateAndCopy; + } + + public function addLocalParamToCreate($paramId, $viId, $realVarId, $minSampling, $maxSampling, $type, $size, $dateModif, $isImpex = false) { $newParam = new ParamNodeClass(); $newParam->setId($paramId); @@ -155,7 +162,15 @@ class ParamsRequestDataClass extends ProcessRequestDataClass $newParam->setProcess(""); $newParam->setOutput(); - $this->localParamsToCreate[$paramId] = array('param' => $newParam, 'dateModif' => $dateModif); + + if ($isImpex) + { + $this->localParamsToCreateAndCopy[$paramId] = array('param' => $newParam, 'dateModif' => $dateModif); + } + else + { + $this->localParamsToCreate[$paramId] = array('param' => $newParam, 'dateModif' => $dateModif); + } return $newParam; } diff --git a/src/RequestManager.php b/src/RequestManager.php index a5ab10e..e0c7ec8 100644 --- a/src/RequestManager.php +++ b/src/RequestManager.php @@ -27,7 +27,8 @@ function amdaintegration_autoload($class_name) 'Request/ParamsRequestImpl/Nodes/Requests', 'Request/ProcessRequestImpl', 'Request/ProcessRequestImpl/Process', - 'Request/TTRequestImpl' + 'Request/TTRequestImpl', + 'RemoteDataCenter' ); foreach($dirs as $dir) @@ -137,12 +138,12 @@ Class RequestManagerClass /* * @brief Create an instance of the InputOutput interface in relation with the client */ - private function createInputOutput($user,$client) + private function createInputOutput($user,$userHost = null,$client) { switch ($client) { case ClientTypeEnumClass::IHM : - return new IHMInputOutputClass($user); + return new IHMInputOutputClass($user, $userHost); case ClientTypeEnumClass::TEST : return new TestInputOutputClass($user); default : @@ -156,7 +157,7 @@ Class RequestManagerClass private function runGenericRequest($client,$user,$userHost,$function,$input) { //create an instance of the InputOutput interface - $inputOutput = $this->createInputOutput($user, $client); + $inputOutput = $this->createInputOutput($user, $userHost, $client); //get the input data from the request input data by using the InputOutput interface $inputdata = $inputOutput->getInputData($input,$function); -- libgit2 0.21.2