Commit e4545ed54a20a1dc679c1e25e2e868070a73060e

Authored by Benjamin Renard
1 parent bf27ba04

Implement templated parameters for download, data mining and derived parameters

src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php
... ... @@ -74,7 +74,7 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas
74 74 //add params to output
75 75 foreach ($input->list as $param)
76 76 {
77   - $paramInfo = $this->paramManager->addExistingParam($param->name, $this->paramsData);
  77 + $paramInfo = $this->paramManager->addExistingParam($param->paramid, $this->paramsData, $param->template_args);
78 78 switch ($param->type) {
79 79 case 0:
80 80 //scalar - nothing to do
... ...
src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php
... ... @@ -646,7 +646,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
646 646 foreach ($paramsData as $paramData)
647 647 {
648 648 //Param
649   - $paramInfo = $this->paramManager->addExistingParam($paramData->{'param-id'}, $this->paramsData, $paramData->{'param-template-args'});
  649 + $paramInfo = $this->paramManager->addExistingParam($paramData->{'paramid'}, $this->paramsData, $paramData->{'template_args'});
650 650  
651 651 $paramInfo['indexes'] = array();
652 652 $dim1 = $paramData->{'param-dim-1'};
... ... @@ -2081,7 +2081,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
2081 2081  
2082 2082 $instantParam = (Object)array(
2083 2083 "id" => 1,
2084   - "param-id" => $crtParam->{'param-id'},
  2084 + "paramid" => $crtParam->{'paramid'},
2085 2085 "param-drawing-type" => "iserie",
2086 2086 "param-drawing-object" => (Object)array(
2087 2087 "iserie-tableonx" => true,
... ...
src/InputOutput/IHMImpl/Params/StatisticsImpl/IHMInputOutputParamsStatisticsClass.php
... ... @@ -38,7 +38,7 @@ class IHMInputOutputParamsStatisticsClass extends IHMInputOutputParamsAbstractCl
38 38 foreach ($paramFunctionAssociation as $param => $functions) {
39 39  
40 40 $paramInfo = $this->paramManager->addExistingParam($param, $this->paramsData);
41   - $paramsNode->addParam($paramInfo['id']);
  41 + $paramsNode->addParam($paramInfo['id']);
42 42 $outputParamNode = $catalogNode->addParam($paramInfo['id'],$paramInfo['indexes']);
43 43 foreach ($functions as $function) $outputParamNode->addFunction($function);
44 44 }
... ...
src/InputOutput/IHMImpl/Tools/IHMExpressionParserClass.php
... ... @@ -43,12 +43,15 @@ class IHMExpressionParserClass
43 43 private $aliasesArray;
44 44  
45 45 private $functionsArray;
  46 +
  47 + private $templatedParamMgr = NULL;
46 48  
47 49 /*
48 50 * @brief Constructor
49 51 */
50 52 function __construct()
51 53 {
  54 + $this->templatedParamMgr = new IHMParamTemplateClass();
52 55 }
53 56  
54 57 /*
... ... @@ -142,8 +145,13 @@ class IHMExpressionParserClass
142 145  
143 146 //keep only params id
144 147 $params = array();
145   - foreach ($params_full as $param_full)
146   - $params[] = $param_full["id"];
  148 + foreach ($params_full as $param_full) {
  149 + if (($templated_param_info = $this->templatedParamMgr->parseTemplatedParam($param_full["id"])) !== FALSE) {
  150 + $params[] = $templated_param_info;
  151 + }
  152 + else
  153 + $params[] = array("paramid" => $param_full["id"]);
  154 + }
147 155  
148 156 return array("expression" => $translated, "params" => $params);
149 157 }
... ...
src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php
... ... @@ -40,8 +40,12 @@ class IHMParamManagerClass
40 40 {
41 41 $paramsData->addProcessParamToCreate($paramId, $expression, $params, $sampling, $gap,$dateModif);
42 42  
43   - foreach ($params as $param)
44   - $this->addExistingParam($param,$paramsData);
  43 + foreach ($params as $param) {
  44 + $template_args = NULL;
  45 + if (array_key_exists("template_args", $param))
  46 + $template_args = $param["template_args"];
  47 + $this->addExistingParam($param["paramid"],$paramsData,$template_args);
  48 + }
45 49  
46 50 return true;
47 51 }
... ...
src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php
... ... @@ -46,6 +46,72 @@ class IHMParamTemplateClass
46 46 }
47 47  
48 48 /*
  49 + *
  50 + */
  51 + public function parseTemplatedParam($param_expression) {
  52 + $exploded_param_expression = explode('_',$param_expression);
  53 +
  54 + $tmp_paramid = "";
  55 + $real_param_id = "";
  56 +
  57 + foreach ($exploded_param_expression as $expression_part) {
  58 + //add one by one each part of the expression to check if it's a templated parameter
  59 + if ($tmp_paramid != "")
  60 + $tmp_paramid .= "_";
  61 + $tmp_paramid .= $expression_part;
  62 + if ($this->isTemplatedParam($tmp_paramid)) {
  63 + $real_param_id = $tmp_paramid;
  64 + break;
  65 + }
  66 + }
  67 +
  68 + if (empty($real_param_id))
  69 + return FALSE;
  70 +
  71 + $template_args_str = str_replace($real_param_id, "", $param_expression);
  72 +
  73 + if ($template_args_str == "")
  74 + //A templated param need at least one argument
  75 + return FALSE;
  76 +
  77 + $template_args_info = $this->paramTemplateList[$real_param_id];
  78 +
  79 + $args_format = "";
  80 + foreach ($template_args_info["arguments"] as $arg) {
  81 + $args_format .= "_";
  82 + switch($arg["type"]) {
  83 + case 'float' :
  84 + case 'double' :
  85 + $args_format .= "%f";
  86 + break;
  87 + case 'int' :
  88 + $args_format .= "%d";
  89 + break;
  90 + default:
  91 + $args_format .= "%s";
  92 + }
  93 + }
  94 +
  95 + $exploded_args = sscanf($template_args_str , $args_format);
  96 +
  97 + if ($exploded_args === -1)
  98 + return FALSE;
  99 +
  100 + $template_args = array();
  101 + $i = 0;
  102 + foreach ($template_args_info["arguments"] as $arg_key => $arg) {
  103 + $template_args[$arg_key] = $exploded_args[$i];
  104 + ++$i;
  105 + }
  106 +
  107 + return array(
  108 + "paramid" => $real_param_id,
  109 + "fullparamid" => $param_expression,
  110 + "template_args" => $template_args
  111 + );
  112 + }
  113 +
  114 + /*
49 115 * @brief Get templated parameter id
50 116 */
51 117 public function getTemplatedParamId($param_id, $template_args) {
... ...
src/Request/ParamsRequestImpl/ParamsRequestClass.php
... ... @@ -81,11 +81,22 @@ class ParamsRequestClass extends ProcessRequestClass
81 81 return false;
82 82 }
83 83  
  84 + libxml_use_internal_errors(true);
84 85 if (!$doc->schemaValidate(KernelConfigClass::getXSDRequestFilePath()))
85 86 {
86   - $this->requestData->setLastErrorMessage('Params request XML file not valid for request '.$requestNode->getRealIndex());
  87 + $error_msg = "";
  88 + $errors = libxml_get_errors();
  89 + foreach ($errors as $error) {
  90 + if ($error_msg != "")
  91 + $error_msg .= PHP_EOL;
  92 + $error_msg .= 'XML error "'.$error->message.'" ['.$error->level.'] (Code '.$error->code.') in '.$error->file.' on line '.$error->line.' column '.$error->column;
  93 + }
  94 + libxml_clear_errors();
  95 +
  96 + $this->requestData->setLastErrorMessage('Params request XML file not valid for request '.$requestNode->getRealIndex().' ('.$error_msg.')');
87 97 return false;
88 98 }
  99 + libxml_use_internal_errors(false);
89 100 }
90 101 }
91 102  
... ...
src/Request/ParamsRequestImpl/ParamsRequestDataClass.php
... ... @@ -126,7 +126,10 @@ class ParamsRequestDataClass extends ProcessRequestDataClass
126 126 foreach ($getParams as $getParam)
127 127 {
128 128 $amdaParamNode = $newParam->addParamGet(ParamGetTypeEnum::AMDAPARAM);
129   - $amdaParamNode->setParamName($getParam);
  129 + if (array_key_exists('template_args', $getParam))
  130 + $amdaParamNode->setParamName($getParam['fullparamid']);
  131 + else
  132 + $amdaParamNode->setParamName($getParam['paramid']);
130 133 }
131 134 $newParam->setProcess($expression);
132 135 $newParam->setOutput();
... ...