Commit 641a1a7223f81948c97e7c6937affa524c3849ec
1 parent
91eef29d
Exists in
master
and in
9 other branches
Add the possibility to have template parameters definition in getObsDataTree API
Showing
3 changed files
with
63 additions
and
6 deletions
Show diff stats
php/WebServices/WebServer.php
... | ... | @@ -50,7 +50,11 @@ class WebServer |
50 | 50 | $this->userPWD = $vars['password']; |
51 | 51 | else |
52 | 52 | $this->userPWD = WSConfigClass::getAnonymousUserPwd(); |
53 | - | |
53 | + | |
54 | + if (isset($vars['referenceTime'])) | |
55 | + $this->referenceTime = $vars['referenceTime']; | |
56 | + else | |
57 | + $this->referenceTime = NULL; | |
54 | 58 | return array('success' => true, 'vars' => $vars); |
55 | 59 | } |
56 | 60 | |
... | ... | @@ -114,6 +118,12 @@ class WebServer |
114 | 118 | |
115 | 119 | return $dataSetDom; |
116 | 120 | } |
121 | + | |
122 | + private function getUserInfo($data) | |
123 | + { | |
124 | + $res = $this->init($data); | |
125 | + $this->initUserMgr(); | |
126 | + } | |
117 | 127 | |
118 | 128 | /* |
119 | 129 | * get user TimeTables list; Shared for anonymous user ('impex') |
... | ... | @@ -327,6 +337,42 @@ class WebServer |
327 | 337 | if (!$locParamSrcDom->save(WSConfigClass::getWsResultDir().$locParamDst)) |
328 | 338 | $this->throwError('workspaceError', 'Cannot save Amda Local DataBase Parameters description file'.$this->userID); |
329 | 339 | } |
340 | + | |
341 | + private function injectTemplateInfo($locParamFile) { | |
342 | + $paramTemplateListFile = WSConfigClass::getParamTemplateListFilePath(); | |
343 | + | |
344 | + $paramTemplateListFileDom = new DomDocument("1.0"); | |
345 | + if (!@$paramTemplateListFileDom->load($paramTemplateListFile)) | |
346 | + $this->throwError("getObsDataTree", "Cannot load Amda Templated Parameters description file".$this->userID); | |
347 | + | |
348 | + $paramTemplateNodes = $paramTemplateListFileDom->getElementsByTagName('paramTemplate'); | |
349 | + | |
350 | + $locParamFileDom = new DomDocument("1.0"); | |
351 | + $locParamFileDom->preserveWhiteSpace = FALSE; /// Important !!! otherwise removeChild() leaves empty text nodes | |
352 | + | |
353 | + if (!@$locParamFileDom->load(WSConfigClass::getWsResultDir().$locParamFile)) | |
354 | + $this->throwError("getObsDataTree", "Cannot load Amda Local DataBase Parameters description file ".$this->userID); | |
355 | + | |
356 | + $xp = new domxpath($locParamFileDom); | |
357 | + | |
358 | + foreach ($paramTemplateNodes as $paramTemplateNode) { | |
359 | + $paramTemplateId = $paramTemplateNode->getAttribute('paramId'); | |
360 | + $paramFileName = $paramTemplateNode->getAttribute('fileName'); | |
361 | + $parameterNodes = $xp->query("//parameter[@template='$paramFileName']"); | |
362 | + $argumentsNodes = $paramTemplateNode->getElementsByTagName("arguments"); | |
363 | + if ($argumentsNodes->length < 1) | |
364 | + continue; | |
365 | + $argumentsNode = $argumentsNodes->item(0); | |
366 | + foreach ($parameterNodes as $parameterNode) { | |
367 | + $node = $locParamFileDom->importNode($argumentsNode, TRUE); | |
368 | + $parameterNode->appendChild($node); | |
369 | + } | |
370 | + } | |
371 | + | |
372 | + | |
373 | + if (!$locParamFileDom->save(WSConfigClass::getWsResultDir().$locParamFile)) | |
374 | + $this->throwError('workspaceError', 'Cannot save Amda Local DataBase Parameters description file'.$this->userID); | |
375 | + } | |
330 | 376 | |
331 | 377 | private function checkInputTime($startTime, $stopTime) |
332 | 378 | { |
... | ... | @@ -349,19 +395,26 @@ class WebServer |
349 | 395 | /* |
350 | 396 | * public data only : anonymous user (impex) |
351 | 397 | */ |
352 | - public function getObsDataTree() | |
398 | + public function getObsDataTree($data) | |
353 | 399 | { |
354 | - $res = $this->init(); | |
400 | + $res = $this->init($data); | |
355 | 401 | $this->initUserMgr(); |
402 | + | |
403 | + $injectTemplateInfo = array_key_exists('templateInfo', $data) && (!empty($data["templateInfo"])); | |
356 | 404 | |
357 | 405 | $locParamSrc = USERWSDIR.'LocalParams.xml'; |
358 | 406 | |
359 | - $locParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.$this->requestTime.'_AmdaLocalDataBaseParameters.xml'; | |
407 | + $locParamDst = substr(strtolower(__FUNCTION__),3).'_'.$this->userID.'_'.($injectTemplateInfo ? 'withtemplate_' : '').$this->requestTime.'_AmdaLocalDataBaseParameters.xml'; | |
360 | 408 | |
361 | 409 | // if (!copy($locParamSrc,WSConfigClass::getWsResultDir().$locParamDst)) |
362 | 410 | // $this->throwError('workspaceError', 'No Amda Local DataBase Parameters description file'); |
363 | 411 | |
364 | 412 | $this->excludePrivateNodes($locParamSrc,$locParamDst); |
413 | + | |
414 | + if ($injectTemplateInfo) { | |
415 | + $this->injectTemplateInfo($locParamDst); | |
416 | + } | |
417 | + | |
365 | 418 | return array('success' => true,'WorkSpace' => array("LocalDataBaseParameters" => WSConfigClass::getUrl().$locParamDst)); |
366 | 419 | } |
367 | 420 | ... | ... |
php/classes/AmdaAction.php
... | ... | @@ -299,10 +299,10 @@ class AmdaAction |
299 | 299 | |
300 | 300 | if ($child->tagName == 'parameter') { |
301 | 301 | $isParameter = true; |
302 | - if ($child->hasAttribute('TemplatedParameter')) | |
302 | + if ($child->hasAttribute('template')) | |
303 | 303 | $needsArgs = true; |
304 | 304 | |
305 | - if ($child->hasAttribute('PredefinedTemplatedParameter')) | |
305 | + if ($child->hasAttribute('predefined')) | |
306 | 306 | $predefinedArgs = true; |
307 | 307 | |
308 | 308 | if ($child->parentNode->hasAttribute('dataStart')) { | ... | ... |
php/rest/getObsDataTree.php
... | ... | @@ -5,6 +5,10 @@ |
5 | 5 | * @apiDescription Provides the hierarchy of public access data in AMDA. |
6 | 6 | * @apiName getObsDataTree |
7 | 7 | * @apiGroup webservices |
8 | + * | |
9 | + * @apiParam {String} [userID] Identifier of the user in AMDA (*mandatory for user owned data*) | |
10 | + * @apiParam {String} [password] Password of the user in AMDA (*mandatory for user owned data*) | |
11 | + * @apiParam {Boolean} [templateInfo] `1` to include info about templated parameters - Default `0`. | |
8 | 12 | * |
9 | 13 | * @apiSuccess {String} success true. |
10 | 14 | * @apiSuccess {String} workspace URL of the XML file containing the list of "public" parameters in AMDA. | ... | ... |