'LocalParams.xml', 'remoteParam' => 'RemoteParams.xml', 'remoteSimuParam' => 'RemoteParams.xml', 'derivedParam' => 'WsParams.xml', 'myDataParam' => 'WsParams.xml', 'timeTable' => 'Tt.xml', 'catalog' => 'Tt.xml', 'alias' => 'Alias.xml', 'myData' => 'Files.xml', 'request' => 'Request.xml', 'condition' => 'Request.xml', 'download' => 'Request.xml', 'statistic' => 'Request.xml', 'bkgWorks' => 'jobs.xml'); private $user, $amdaStat; public function __construct() { $dd = new UserMgr(); $this->user = $dd->user; if (!defined('NEWKERNEL_DEBUG') || !NEWKERNEL_DEBUG) $this->amdaStat = new AmdaStats($dd->user); } private function getUrlDirs($url) { //TODO replace by ftp php class methods: ftp_nlist() etc require_once "simple_html_dom.php"; $url = html_entity_decode($url); $trimmed_url = trim($url); if (strrpos($trimmed_url, "/") == strlen($trimmed_url) - 1) { if (file_exists("temp.html")) unlink("temp.html"); exec("wget -O temp.html ".$url); $html = file_get_html('temp.html'); $dirs = $html->find('a[href]'); foreach ($dirs as $dir) { $name = $dir->innertext; //$dir->href; $isLeaf = strrpos($name, "/") !== strlen($name) - 1; $childrenToReturn[] = array('text' => $name, 'id' => $trimmed_url.$name, 'nodeType' => 'url', 'leaf' => $isLeaf); } } return $childrenToReturn; } /***************************************************************** * PUBLIC FUNCTIONS *****************************************************************/ /* * $obj = { id: node.id, nodeType: node.nodeType } */ public function getTree($obj) { $node = $obj->node; $nodeType = $obj->nodeType; $remoteBase = false; $isRemoteDataSet = false; if ($nodeType == 'url') { $url = $node == 'root' ? $obj->baseId : $node; return $this->getUrlDirs($url); } if (isset($obj->baseId)) $remoteBase = true; if ($node == 'root' && $remoteBase) $node = $obj->baseId; if ($node == 'root' && !$remoteBase) { if (file_exists(DATAPATH.$nodeType.'.json')) { $json_o = json_decode(file_get_contents(DATAPATH.$nodeType.'.json')); if (empty($json_o)) { $childrenToReturn = array(); } else { $childrenToReturn = $json_o->nodes; } } else { $childrenToReturn = array(); } } else { $Dom = new DomDocument("1.0"); switch ($nodeType) { case 'sharedtimeTable': case 'sharedcatalog': $xmlName = SHAREDPATH.'/SharedObjectTree.xml'; break; case 'bkgWorks': // data//JOBS/jobs.xml $xmlName = USERJOBDIR.$this->xmlFiles[$nodeType]; break; case 'source': $xmlName = DATAPATH.'RemoteData/'.$obj->baseId.'/base.xml'; break; case 'destination': $xmlName = USERWSDIR.'RemoteParams.xml'; break; default: $xmlName = USERWSDIR.$this->xmlFiles[$nodeType]; } if ($remoteBase){ $nodeType = 'remoteParam'; } @$Dom->load($xmlName); if ($node == "myRemoteSimuData-treeRootNode") $node = "myRemoteData-treeRootNode"; $nodeToOpen = $Dom->getElementById($node); $children = empty($nodeToOpen->childNodes) ? array() : $nodeToOpen->childNodes; foreach ($children as $child) if ($child->nodeType == XML_ELEMENT_NODE) { $isLeaf = true; if ($child->hasChildNodes()) foreach ($child->childNodes as $grandChild) if ($grandChild -> nodeType == XML_ELEMENT_NODE) { $isLeaf = false; break; } if ($child->tagName == 'folder') $isLeaf = false; //TODO MAKE PROPERLY as function of nodetype !!!! $info = ''; $dim_1 = 1; $dim_2 = 1; $id = $child->getAttribute('xml:id'); $name = $child->getAttribute('name'); $help = $child->getAttribute('att'); $specialNode = false; $isParameter = false; $isAddable = false; $isSimulation = false; $rank = null; $skip = FALSE; $last_update = 0; switch ($nodeType) { case 'bkgWorks': $specialNode = true; $childrenToReturn[] = [ 'text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'leaf' => $isLeaf, 'pid' => $child->getAttribute('pid'), 'status' => $child->getAttribute('status'), 'jobType' => $child->getAttribute('jobType'), 'info' => $child->getAttribute('info') ]; break; case 'download': case 'condition': case 'request': case 'statistic': $objectMgr = new RequestMgr($nodeType); $info = $objectMgr->getObjectInfo($id); $obj_info = $objectMgr->getObject($id); if (!empty($obj_info) && !empty($obj_info->last_update)) { $last_update = $obj_info->last_update; } break; case 'timeTable': case 'catalog': if ($isLeaf) $info = $child->getAttribute('intervals').' intervals'; break; case 'sharedtimeTable': case 'sharedcatalog': if ($isLeaf) { $info = 'Nb intervals: '.$child->getAttribute('nbIntervals').'
'; $info .= 'Shared by: '.$child->getAttribute('sharedBy').' ('.$child->getAttribute('sharedDate').')
'; $info .= 'Description: '.$child->getAttribute('description'); } break; case 'derivedParam': error_log("child"); $info = $child->getAttribute('buildchain').'
'; if($child->hasAttribute('units') && $child->getAttribute('units') != 'undefined') $info .= 'Units: '.$child->getAttribute('units').'
'; $samplingMode = $child->getAttribute('sampling_mode'); if($samplingMode == 'timestep'){ $info .= 'Sampling Time: '.$child->getAttribute('timestep'); }else if($samplingMode == 'refparam'){ $info .= 'Reference Parameter: '.$child->getAttribute('reference_param'); } if ($child->hasAttribute('dim_1')) { $dim_1 = $child->getAttribute('dim_1'); } if ($child->hasAttribute('dim_2')) { $dim_2 = $child->getAttribute('dim_2'); } if ($isLeaf) $isParameter = true; break; case 'localParam': $globalStart = null; $globalStop = null; $timeRestriction = false; $specialNode = true; $isParameter = false; $needsArgs = false; $isSpectra = false; $is2dSpectra = false; $isStack = false; $not_yet = false; if ($child->hasAttribute('desc')) { $info = $child->getAttribute('desc'); if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop')) { $dataStart = $child->getAttribute('dataStart'); // check UTC format if ( !preg_match('/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/', $dataStart ) ) { if ( $dataStart == "MissionDependent" ) $info .= "
Time Range : depending on mission selection"; else $info .= "
Time Range : undefined"; $child->setAttribute('dataStart', date("Y-m-d\TH:i:s\Z", strtotime(' -1 day'))); $child->setAttribute('dataStop', date("Y-m-d\TH:i:s\Z", time())); } else { $info .= "
Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop'); } if ($child->hasAttribute('lastUpdate')) { $info .= "
Last Updated: : ".$child->getAttribute('lastUpdate'); } } } if ($child->hasAttribute('units')) { $units = $child->getAttribute('units'); if ($child->hasAttribute('description')) $info = $child->getAttribute('description')."
".$units; else $info = $units; } else { if ($child->hasAttribute('description')) $info = $child->getAttribute('description'); } if ($child->tagName == 'parameter') { $isParameter = true; if ($child->hasAttribute('TemplatedParameter')) $needsArgs = true; if ($child->hasAttribute('PredefinedTemplatedParameter')) $predefinedArgs = true; if ($child->parentNode->hasAttribute('dataStart')) { $globalStart = $child->parentNode->getAttribute('dataStart'); $globalStop = $child->parentNode->getAttribute('dataStop'); } if ($child->parentNode->hasAttribute('restriction')) { if ($child->parentNode->getAttribute('restriction') == "plotOnly") { $not_yet = true; } } if ($child->parentNode->hasAttribute('timeRestriction')) { $timeRestriction = $child->parentNode->getAttribute('timeRestriction'); } } $component_info = array(); if ($child->tagName == 'component') { $isParameter = true; if ($child->parentNode->parentNode->hasAttribute('dataStart')) { $globalStart = $child->parentNode->parentNode->getAttribute('dataStart'); $globalStop = $child->parentNode->parentNode->getAttribute('dataStop'); } if ($child->parentNode->parentNode->hasAttribute('restriction')) { if ($child->parentNode->parentNode->getAttribute('restriction') == "plotOnly") { $not_yet = true; } } if ($child->parentNode->parentNode->hasAttribute('timeRestriction')) { $timeRestriction = $child->parentNode->parentNode->getAttribute('timeRestriction'); } if ($child->hasAttribute("index1")) $component_info["index1"] = $child->getAttribute('index1'); if ($child->hasAttribute("index2")) $component_info["index2"] = $child->getAttribute('index2'); $component_info["parentId"] = $child->parentNode->getAttribute('xml:id'); } if ($child->tagName == 'parameter' && $child->hasAttribute('display_type')){ if ($child->getAttribute('display_type') == 'spectrogram') { $needsArgs = true; $isSpectra = true; if (strpos($child->getAttribute('name'),'2D') !== false) $is2dSpectra = true; } elseif ($child->getAttribute('display_type') == 'stackplot') { $isStack = true; } } if ($isParameter) { $objectMgr = new AliasMgr(); $alias = $objectMgr->getAlias($id); if (! ($child->parentNode->hasAttribute('group') || $child->parentNode->parentNode->hasAttribute('group'))) $info .= '
ID : '.$id.''; $childrenToReturn[] = array('text' => $name,'alias' => $alias, 'id' => $id,'nodeType' => $nodeType, 'info' => $info, "component_info" => $component_info, 'globalStart' => $globalStart, 'globalStop' => $globalStop, 'timeRestriction' => $timeRestriction, 'leaf' => $isLeaf, 'isParameter' => $isParameter,'isSpectra' => $isSpectra, 'is2dSpectra' => $is2dSpectra,'isStack' => $isStack, 'needsArgs' => $needsArgs, 'predefinedArgs' => $predefinedArgs, 'help' => $help, 'notyet' => $not_yet); } else { if ($child->hasAttribute('rank')) { $rank = $child->getAttribute('rank'); } if ($child->hasAttribute("timeRestriction")) { $timeRestriction = $child->getAttribute("timeRestriction"); } $disable = TRUE; if ($child->hasAttribute('group')) { if ($child->getAttribute("group") === "TBD") { $info .= "
Under Testing"; } else { if (!empty($timeRestriction)) { $disable = FALSE; $formattedTimeRestriction = date("Y-m-d\TH:i:s\Z",strtotime($timeRestriction)+1); $info .= "
After $formattedTimeRestriction data are restricted to group ".$child->getAttribute('group').""; } else { $info .= "
Restricted Access : Group ".$child->getAttribute('group').""; } } } else { $disable = FALSE; if ($child->hasAttribute('restriction') && $child->getAttribute('restriction') == 'plotOnly') $info .= "
Plot Only!!!"; } $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'info' => $info, 'last_update' => $last_update, 'leaf' => false, 'help' => $help, 'disable' => $disable, 'rank' => $rank, 'timeRestriction' => $timeRestriction); } break; case 'remoteSimuParam' : $globalStart = null; $service_down = false; $isSimulation = true; if ($child->getAttribute('isAddable')) // 'spase://IMPEX/SimulationModel/FMI/GUMICS' { $isLeaf = false; $isAddable = true; } if ($child->tagName == 'dataCenter') { if ($child->getAttribute('isSimulation')) { $service_down = !($child->getAttribute('available')); break; } else { $skip = true; break; } } if ($child->hasAttribute('rank')) { $rank = $child->getAttribute('rank'); } if ( $child->tagName == 'parameter') { if ($child->parentNode->hasAttribute('globalStart')) { $globalStart = $child->parentNode->getAttribute('globalStart'); $globalStop = $child->parentNode->getAttribute('globalStop'); } } if ( $child->tagName == 'component') { if ($child->parentNode->parentNode->hasAttribute('globalStart')) { $globalStart = $child->parentNode->parentNode->getAttribute('globalStart'); $globalStop = $child->parentNode->parentNode->getAttribute('globalStop'); } } case 'remoteParam' : if ($child->getAttribute('isSimulation') && $child->tagName == 'dataCenter') { $skip = true; break; } $isDeletable = $child->hasAttribute('isDeletable'); $specialNode = true; $isParameter = false; $isSpectra = false; switch ($id) { case 'CDAWEB' : case 'THEMIS' : $rank = 5; break; default: } $info = $child->getAttribute('desc'); if ($info && !$isSimulation) { $info = str_replace(';', "
Time Range: ", $info); } if (($child->tagName == 'parameter') || ($child->tagName == 'component')) { $isParameter = true; } $needsArgs = $child->getAttribute('needsArgs'); if ($remoteBase) { if ($child->tagName == 'dataset') $isRemoteDataSet = true; } if ($child->tagName == 'parameter'){ if ($child->parentNode->hasAttribute('dataStart')){ $globalStart = date('Y-m-d\TH:i:s\Z', strtotime($child->parentNode->getAttribute('dataStart'))); $globalStop = date('Y-m-d\TH:i:s\Z', strtotime($child->parentNode->getAttribute('dataStop'))); } } if ( $child->tagName == 'component'){ if ($child->parentNode->parentNode->hasAttribute('dataStart')){ $globalStart = date('Y-m-d\TH:i:s\Z', strtotime($child->parentNode->getAttribute('dataStart'))); $globalStop = date('Y-m-d\TH:i:s\Z', strtotime($child->parentNode->getAttribute('dataStop'))); } } if ($isParameter) { $disable = $child->parentNode->getAttribute('disabled'); $objectMgr = new AliasMgr(); $alias = $objectMgr->getAlias($id); if ($child->hasAttribute('display_type') && $child->getAttribute('display_type') == 'spectrogram') { $needsArgs = true; $isSpectra = true; } if ($globalStart) $childrenToReturn[] = array('text' => $name,'alias' => $alias, 'id' => $id,'nodeType' => $nodeType, 'info' => $info, 'help' => $help, 'globalStart' => $globalStart, 'globalStop' => $globalStop, 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => isset($component_info) ? $component_info : NULL); else $childrenToReturn[] = array('text' => $name,'alias' => $alias, 'id' => $id,'nodeType' => $nodeType, 'info' => $info, 'help' => $help, 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info); } else { $restricted = FALSE; if ($child->tagName == 'dataset') { $nonavailable = ($child->getAttribute('disabled')); } else { $nonavailable = false; } if ($nonavailable) $info .= "
Not available yet"; if ($child->getAttribute('url')) $info .= "
".$child->getAttribute('url'); if ($child->hasAttribute('obsolete')) { $info = $child->getAttribute('desc'); $obsolete = true; } else $obsolete = false; $disable = $restricted || $nonavailable || $obsolete; $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'isAddable' => $isAddable, 'info' => $info, 'leaf' => false, 'isRemoteDataSet' => $isRemoteDataSet, 'disable' => $disable, 'isSimulation' => $isSimulation, 'rank' => $rank, 'isDeletable' => $isDeletable, 'help' => $help); } break; case 'myData' : $info = $child->hasAttribute('info') ? $child->getAttribute('info') : $child->nodeValue; break; case 'myDataParam' : $globalStart = null; $globalStop = null; $specialNode = true; $size = $child->getAttribute('size'); $mask = $child->getAttribute('mask'); $sampling = null; if ($child->hasAttribute('minsampling')) $sampling = $child->getAttribute('minsampling'); $isSpectra = false; if ($isLeaf) { $isParameter = true; $info = "Size: ".$size."
".$child->getAttribute('desc')."
Mask: ".$mask; if ($sampling) $info .= "
Sampling : ".$sampling; $isSpectra = $child->getAttribute('plottype') === 'Spectra'; } if ($child->hasAttribute('desc')) { $globalStart = substr($child->getAttribute('desc'), 0, 19); $globalStop = substr($child->getAttribute('desc'), 20); } $childrenToReturn[] = array('text' => $name, 'size' => $size, 'id' => $id, 'globalStart' => $globalStart, 'globalStop' => $globalStop, 'nodeType' => $nodeType, 'info' => $info, 'leaf' => $isLeaf, 'isParameter' => $isParameter, 'linkedMask' => $mask, 'isSpectra' => $isSpectra); break; default: } if (!$specialNode && !$skip) { if ($child->hasAttribute('desc')) $info = $child->getAttribute('desc'); if ($isSimulation && $service_down) { $info = "Service is currently down"; } $childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info, 'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter, 'dim_1' => $dim_1, 'dim_2' => $dim_2, 'component_info' => isset($component_info) ? $component_info : NULL, 'iconCls' => isset($iconCls) ? $iconCls : NULL, 'last_update' => $last_update ); } } // if $childrenToReturn we have to return [] if (empty($childrenToReturn)) { $childrenToReturn = array('nodeType' => $nodeType, 'text' => null); } } return $childrenToReturn; } /* * add Remote Parameter to user RemoteParams.xml * send request to DDServer to AddVi if Vi doesn't exist * create Remote Parameter Description */ public function saveTree($obj) { $paramMgr = new RemoteParamManager(); $res = $paramMgr->init(); if ($res['success']) return $paramMgr->saveTree($obj); else return $res; } /* * delete Remote Parameter from user RemoteParams.xml */ public function deleteFromTree($obj) { $paramMgr = new RemoteParamManager(); $res = $paramMgr->init(); if ($res['success']) return $paramMgr->deleteFromTree($obj); else return $res; } public function doNothing($obj) { return array("res" => 'ok'); } /* * get temporary object from Upload */ public function getUploadedObject($name, $format, $nodeType) { $fileContent = preg_replace(['~\R~u', "/\t/"], ["\n", ' '], trim(file_get_contents(USERTEMPDIR . $name))); file_put_contents(USERTEMPDIR . $name, $fileContent); $isTTCat = FALSE; switch ($nodeType) { case 'timeTable' : $objectMgr = new TimeTableMgr(); $isTTCat = TRUE; break; case 'myDataParam' : $objectMgr = new FilesMgr(); break; case 'catalog' : $objectMgr = new CatalogMgr(); $isTTCat = TRUE; break; default: return array("error" => $nodeType." NOT_IMPLEMENTED_YET"); } if ($isTTCat) { //Pre-process: convert to INTERNAL format if needed if (($format == 'ASCII') || ($format == 'VOT')) { $result = $this->executeRequest((Object) array( 'compression' => 'none', 'fileformat' => 'internal', 'timeformat' => 'YYYY-MM-DDThh:mm:ss', 'sendToSamp' => FALSE, 'list' => array( (Object) array( 'path' => USERTEMPDIR . $name, 'format' => $format, 'name' => pathinfo($name, PATHINFO_FILENAME), ) ), ), FunctionTypeEnumClass::TTCONVERT); if (!$result['success']) { return array("error" => "Error during file conversion"); } $name = basename($result['download']); $convertedFile = USERDIR.'/DOWNLOAD.TEMP/'.$name; if (!file_exists($convertedFile)) { return array("error" => "Error during file conversion"); } $format = 'internal'; rename($convertedFile, USERTEMPDIR . '/' . $name); } } return $objectMgr->getUploadedObject($name, $format, true); } /* * fill ascii file into grid */ public function getAsciiFile($obj) { $objectMgr = new FilesMgr(); return $objectMgr->getAsciiFile($obj->fileName); } public function getMyParamInfo($object) { $objectMgr = new FilesMgr(); return $objectMgr->getParamInfo($object); } /* * get temporary object from Search */ public function getTmpObject($folderId, $name, $nodeType) { switch ($nodeType) { case 'timeTable' : $objectMgr = new TimeTableMgr(); break; case 'catalog' : $objectMgr = new CatalogMgr(); break; default: return array("error" => $nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr->getTmpObject($folderId, $name, true); } public function getObject($id, $nodeType) { switch ($nodeType) { case 'myDataParam': case 'derivedParam' : $objectMgr = new DerivedParamMgr($nodeType); break; case 'timeTable' : case 'sharedtimeTable' : $objectMgr = new TimeTableMgr(); break; case 'catalog' : case 'sharedcatalog' : $objectMgr = new CatalogMgr(); break; case 'condition' : case 'request' : case 'download' : case 'statistic': $objectMgr = new RequestMgr($nodeType); break; case 'bkgWorks' : return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO); break; case 'myData' : $objectMgr = new FilesMgr(); break; default: return array("error" => $nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr->getObject($id, $nodeType); } /* * $obj = { id: node.id, leaf: node.leaf, nodeType: node.nodeType } */ public function deleteObject($obj) { switch ($obj->nodeType) { case 'myDataParam' : case 'derivedParam' : $objectMgr = new DerivedParamMgr($obj->nodeType); break; case 'timeTable' : $objectMgr = new TimeTableMgr(); break; case 'catalog' : $objectMgr = new CatalogMgr(); break; case 'condition' : case 'request' : case 'download' : case 'statistic' : $objectMgr = new RequestMgr($obj->nodeType); break; case 'alias' : $objectMgr = new AliasMgr(); $obj->id = substr($obj->id,strlen('alias_')); break; case 'bkgWorks' : return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSDELETE); case 'myData' : $objectMgr = new FilesMgr(); break; default: return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr -> deleteObject($obj); } /* * $obj = { id: node.id, old_name: node.text, name: value, parent : node.parentNode.id, leaf: node.leaf, nodeType: node.nodeType } */ public function renameObject($obj) { switch ($obj->nodeType) { case 'myDataParam' : case 'derivedParam' : $objectMgr = new DerivedParamMgr($obj->nodeType); break; case 'timeTable' : $objectMgr = new TimeTableMgr(); break; case 'catalog' : $objectMgr = new CatalogMgr(); break; case 'condition' : case 'request' : case 'download' : case 'statistic' : $objectMgr = new RequestMgr($obj->nodeType); break; case 'alias' : $objectMgr = new AliasMgr(); break; default: return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr -> renameObject($obj); } /* * $obj = { name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES } */ public function createObject($obj, $folder) { switch ($obj->nodeType) { case 'myDataParam' : case 'derivedParam' : if ($obj->nodeType == 'derivedParam' && $this->amdaStat->success) $this->amdaStat->addTask($this->user, 'create', null); $objectMgr = new DerivedParamMgr($obj->nodeType); break; case 'timeTable' : $objectMgr = new TimeTableMgr(); break; case 'catalog' : $objectMgr = new CatalogMgr(); break; case 'condition' : case 'request' : case 'download' : case 'statistic' : $objectMgr = new RequestMgr($obj->nodeType); break; case 'alias' : $objectMgr = new AliasMgr(); break; default: return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr -> createObject($obj, $folder); } /* * $obj = { id:obj.id, name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES } */ public function modifyObject($obj) { switch ($obj->nodeType) { case 'myDataParam' : case 'derivedParam' : $objectMgr = new DerivedParamMgr($obj->nodeType); break; case 'timeTable' : $objectMgr = new TimeTableMgr(); break; case 'catalog' : $objectMgr = new CatalogMgr(); break; case 'condition' : case 'request' : case 'download' : case 'statistic' : $objectMgr = new RequestMgr($obj->nodeType); break; default: return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr -> modifyObject($obj); } /* * {obj.name, obj.nodeType, obj.leaf} */ public function validNameObject($obj) { switch ($obj->nodeType) { case 'myDataParam' : case 'derivedParam' : $objectMgr = new DerivedParamMgr($obj->nodeType); break; case 'timeTable' : case 'sharedtimeTable' : $objectMgr = new TimeTableMgr(); break; case 'catalog' : case 'sharedcatalog' : $objectMgr = new CatalogMgr(); break; case 'condition' : case 'request' : case 'download' : case 'statistic' : $objectMgr = new RequestMgr($obj->nodeType); break; default: return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr -> validNameObject($obj); } /* * Get running jobs */ public function getJobs($obj = null) { $obj = (object) array(); return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO); } /* AKKA-KERNEL-INT Move user check from RequestMgr.php to AmdaAction.php */ private function checkUser($obj) { if (defined('NEWKERNEL_DEBUG') && NEWKERNEL_DEBUG){ $this->user = NEWKERNEL_DEBUG_USER; return array('success' => true); } if (isset($obj->username) && isset($obj->password) && isset($obj->sessionID)) { $dd = new WSUserMgr(); $dd->initWS($obj->username,$obj->password,$obj->sessionID, false, false); } else { $dd = new UserMgr(); $dd->setSpecialSettings(); } //TODO error handling if (($res = $dd->ddCheckUser()) != 0) { if ($res == 156) return array('success' => false, 'message' => 'Your AMDA session is expired.
Login please!'); return array('success' => false, 'message' => 'ddLogin error: '.$res); } if ($dd->user == WSConfigClass::getAnonymousUserName()) { //if ($dd->getWsSize() > DISK_QUOTA * 100) // error_log('Natacha! It is time to CLEAN UP IMPEX WS!',1,'nbourrel@irap.omp.eu'); // return array('success' => false, "message" => "AKKA-KERNEL-INT - WS support for IMPEx not implemented"); } else { // check disk space if ($dd->getWsSize() > DISK_QUOTA) { //Try to delete log files - cf. #6245 if ($dd->getWsSize(TRUE) > DISK_QUOTA) { return array('success' => false, 'message' => 'Please clean up your workspace.
No more space is available'); } } } $this->user = $dd->user; return array('success' => true, 'userHost' => $dd->getIPclient()); } private function executeRequest($obj, $function) { // Check user if access to DD Server and / or possible 'space consuming' action if ( $function == FunctionTypeEnumClass::PARAMS || $function == FunctionTypeEnumClass::ACTION || $function == FunctionTypeEnumClass::PARAMSGEN || $function == FunctionTypeEnumClass::PARAMSINFOGEN ) { $res = $this->checkUser($obj); if (!$res['success']) return $res; } $requestManager = new RequestManagerClass(); try { $res = $requestManager->runIHMRequest($this->user, !empty($res['userHost']) ? $res['userHost'] : NULL, $function, $obj); } catch (Exception $e) { return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage()); } return $res; } /* * Main EXECUTE PROCEDURE */ public function execute($node, $obj) { // just convert TT / Catalog if ($obj->nodeType == "download" && $obj->downloadSrc == "1") return $this->executeRequest($obj, FunctionTypeEnumClass::TTCONVERT); else if (isset($obj->action)) return $this->executeRequest($obj, FunctionTypeEnumClass::ACTION); else { $res = RequestMgr::checkRequest($obj); if (!$res['success']) return $res; return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMS); } } /* * Generate derived parameter compilation */ public function compilParam($obj) { return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMSGEN); } /* * Generate parameter info for display (e.g size) */ public function generateParamInfo($obj) { return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMSINFOGEN); } /* * Delete derived parameter compilation */ public function compilParamDelete($obj) { $res = $this->checkUser($obj); if (!$res['success']) return $res; IHMConfigClass::setUserName($this->user); $libParamPath = IHMConfigClass::getCompilationPath()."lib/".$obj->paramId.".so"; if (file_exists($libParamPath)) unlink($libParamPath); return array("success" => true); } /* * kill plot process */ public function killPlotRequest() { return $this->executeRequest((object) array('nodeType' => 'killplot'), FunctionTypeEnumClass::PARAMS); } /* * merge time tables */ public function merge($obj) { if ($this->amdaStat->success) $this->amdaStat->addTask( $this->user, 'ttoper', null); $objectMgr = new TimeTableMgr(); return $objectMgr -> merge($obj); } /* * intersect time tables */ public function intersect($obj) { if ($this->amdaStat->success) $this->amdaStat->addTask($this->user, 'ttoper', null); $objectMgr = new TimeTableMgr(); $result = $objectMgr -> intersect($obj); return $result; } public function initObjectCache($isCatalog = false, $nparams = 1) { if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr(); else $cacheMgr = new CatalogCacheMgr(); return $cacheMgr->initObjectCache(array('nparams' => $nparams)); } public function initObjectCacheFromObject($id, $type) { if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->initFromObject($id, $type); } public function initObjectCacheFromCatalog($id, $type) { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->initFromCatalog($id, $type); } public function initObjectCacheFromTimeTable($id, $type, $nparams) { $cacheMgr = new CatalogCacheMgr(); return $cacheMgr->initFromTimeTable($id, $nparams, $type); } public function initObjectCacheFromTmpObject($folderId, $name, $isCatalog = false) { if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr(); else $cacheMgr = new CatalogCacheMgr(); return $cacheMgr->initFromTmpObject($folderId, $name); } public function initObjectCacheFromUploadedFile($name, $format, $isCatalog = false) { if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr(); else $cacheMgr = new CatalogCacheMgr(); return $cacheMgr->initFromUploadedFile($name, $format); } public function readCacheIntervals($o) { if (isset($o->typeTT) && ($o->typeTT == 'catalog' || $o->typeTT == 'sharedcatalog')) $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->getIntervals($o->start,$o->limit,isset($o->sort) ? $o->sort : NULL, isset($o->filter) ? $o->filter : NULL); } public function readIntervalsForChart($o) { $objMgr = new CatalogCacheMgr(TRUE); $objMgr->initFromObject($o->id, $o->type); return $objMgr->getIntervalsForChart(); } public function saveTTCacheIntervalsInTT($o) { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->saveInObject($o->ttId,$o->action,$o->cacheToken); } public function addCacheInterval($o) { if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->addInterval($o->index, $o->start, $o->stop); } public function removeTTCacheIntervalFromId($id, $isCatalog = false) { if ($isCatalog) $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->removeIntervalFromId($id); } public function modifyCacheInterval($o) { if ($o->isCatalog) { $cacheMgr = new CatalogCacheMgr(); } else $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->data); } public function operationTTCacheIntervals($extendTime, $shiftTime) { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->operationIntervals($extendTime, $shiftTime); } public function mergeTTCacheIntervals() { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->mergeIntervals(); } public function getTTCacheStatistics($obj) { if($obj->name == "timeTableUi"){ $cacheMgr = new TimeTableCacheMgr(); }elseif($obj->name == "catalogUI"){ $cacheMgr = new CatalogCacheMgr(); }else{ return array('success' => false, 'message' => 'unkown type: '.$obj->name); } return $cacheMgr->getStatistics(); } public function getTTCacheStatus() { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->getStatus(); } /* * Send a feedback * */ public function sendFeedback($feed) { $feedMgr = new FeedbackMgr(); return $feedMgr->addFeedback($feed->user, $feed->interface, $feed->subject, $feed->userText, $feed->userAgent, $feed->attach); } /* * Save state * */ public function saveState($datas) { $myStateMgr = new StateMgr(); return $myStateMgr->saveState($datas); } /* * Load state * */ public function loadState($o) { $myStateMgr = new StateMgr(); return $myStateMgr->loadState(); } /* * HST Images */ public function getHstImagesUrl($o) { if ($this->amdaStat->success) $this->amdaStat->addTask($this->user, 'images', null); $myHstMgr = new HstMgr(); $res = $myHstMgr->getImagesUrl($o->startTime, $o->stopTime, $o->planet); //if ($domRes->length <= 0) // return array('success' => false, 'message' => 'Cannot find HST Images for this request.'); return array('success' => true, 'result' => $res); } public function getAPISImagesUrl($o) { if ($this->amdaStat->success) $this->amdaStat->addTask($this->user, 'images', null); $apisMgr = new APISMgr(); $res = $apisMgr->get($o->target, $o->startTime, $o->stopTime, $o->datasets); return $res; } /* * Filters */ public function loadFilterList() { $filtersMgr = new FiltersMgr(); $res = $filtersMgr->loadList(); return $res; } public function loadFilters($o) { $filtersMgr = new FiltersMgr(); if (isset($o->id)) $res = $filtersMgr->loadFilter($o->id); else $res = $filtersMgr->loadAll(); return $res; } public function saveFilter($o) { $filtersMgr = new FiltersMgr(); return $filtersMgr->save($o); } public function createFilter($o) { $filtersMgr = new FiltersMgr(); return $filtersMgr->create($o); } public function destroyFilter($o) { $filtersMgr = new FiltersMgr(); $res = $filtersMgr->delete($o); return; } public function getCrtFilterId() { $filtersMgr = new FiltersMgr(); $res = $filtersMgr->getCrtId(); return $res; } public function getCrtFilterResult() { $filtersMgr = new FiltersMgr(); return $filtersMgr->getCrtResult(); } public function setCrtFilterId($o) { $filtersMgr = new FiltersMgr(); return $filtersMgr->setCrtId($o->id); } public function resetFilter() { $filtersMgr = new FiltersMgr(); $res = $filtersMgr->reset(); return $res; } public function logout($isGuest) { if ($isGuest) { $guestMgr = new Guest($this->user); $guestMgr->deleteGuest(); } else { $this->cleanUserWS(); } return; } public function getInfo($obj) { if (file_exists(HELPPATH.$obj->name)) { $content = file_get_contents(HELPPATH.$obj->name); return array('success' => true, 'result' => $content); } return array('success' => false); } public function getUserInfo() { $dd = new UserMgr(); return $dd->getUserInfo(); } // $obj ={"Object":"Earth","RunCount":"2", // "SW_Density_value":"10","SW_Density_weight":"1","SW_Density_scale":"7","SW_Temperature_value":"100", ....} public function getRun($obj) { $myBestRunsMgr = new BestRunsMgr(); $res = $myBestRunsMgr->getRun($obj); return $res; } //$obj = array of IDs public function addRun($obj) { $myBestRunsMgr = new BestRunsMgr(); $ok = $myBestRunsMgr->init(); if (!$ok) return array('success'=>false,'message'=>'cannot init addRun'); $myBestRunsMgr->addRuns($obj); return array('success'=>true,'addedRuns'=>$obj); } //AKKA - New action to clean user WS public function cleanUserWS() { $this->rrmdir(USERDIR.'DOWNLOAD.TEMP'); $this->rrmdir(USERDIR.'TEMP'); IHMConfigClass::setUserName($this->user); // delete impex params and data $impexParamMgr = new ImpexParamManager(); $impexParamMgr->deleteImpexStaff(); $obj = (object) array(); return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSCLEAN); } public 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") $this->rrmdir($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } public function deleteSpecialInfo($name) { if (file_exists(USERDIR.$name)) unlink(USERDIR.$name); return array('success' => true); } public function interactivePlot($obj) { $inputobj = (Object)array( 'action' => $obj, ); return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION); } public function getParamPlotInit($obj) { // IMPEX param if (preg_match("#^spase___IMPEX_#",$obj->paramId)) $type = 'impex_plot_init'; else $type = 'plot_init'; $inputobj = (Object)array( 'paramId' => $obj->paramId, 'type' => $type ); return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO); } public function getParamInfo($obj) { // IMPEX param if (preg_match("#^spase___IMPEX_#",$obj->paramId)) $type = 'impex_param_info'; else $type = 'param_info'; $inputobj = (Object)array( 'paramId' => $obj->paramId, 'predefinedArgs' => !empty($obj->predefinedArgs), 'type' => $type ); return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO); } public function getDerivedParamInfo($obj) { $dom = new DomDocument("1.0"); $xmlName=USERWSDIR.$this->xmlFiles['derivedParam']; @$dom->load($xmlName); $params=$dom->getElementsByTagName("param"); foreach($params as $param) { if($param->hasAttribute("name") && ("ws_" . ($param->getAttribute("name")))==$obj->paramId) { $dim_1=$param->getAttribute("dim_1"); $dim_2=$param->getAttribute("dim_2"); return $this->createDerivedParamInfo($dim_1,$dim_2,$obj->paramId); } } return array('success'=>false, 'message'=>'unkown parameter (derived parameter arguments are not handled)'); } public function getMyDataParamInfo($obj) { $dom = new DomDocument("1.0"); $xmlName=USERWSDIR.$this->xmlFiles['derivedParam']; @$dom->load($xmlName); $params=$dom->getElementsByTagName("mydata"); foreach($params as $param) { if($param->hasAttribute("name") && ("wsd_" . ($param->getAttribute("name")))==$obj->paramId) { $dim_1=$param->getAttribute("size"); $dim_2=1; return $this->createDerivedParamInfo($dim_1,$dim_2,$obj->paramId); } } return array('success'=>false, 'message'=>'unkown parameter (derived parameter arguments are not handled)'); } public function createDerivedParamInfo($dim_1,$dim_2,$paramId) { /* case of constant */ if($dim_1*$dim_2==1) { return array('success'=>false,'msg'=>"dim1=1 dim2=1 no arguments for this parameter"); }elseif(($dim_1==1 && $dim_2>1 && $dim_2<=3)||($dim_2==1 && $dim_1>1 && $dim_1<=3) ) /* case of vector */ { $dims=array( 'dim1'=>$dim_1, 'dim2'=>$dim_2 ); $compts=array(); for($i=0;$i<($dim_1*$dim_2);++$i) { $c=array( 'index_1'=>($dim_1>$dim_2)?(string)$i:"", 'index_2'=>($dim_1<$dim_2)?$i:"", 'name'=>$paramId.'('.$i.')' ); array_push($compts,$c); } $data=array( 'dimensions'=>$dims, 'components'=>$compts ); return array('success'=>true,'data'=>$data); }else /* case of spectro*/ { $sizes=array($dim_1,$dim_2); $dims=array( 'dim1'=>$dim_1, 'dim2'=>$dim_2 ); $channels=array(); $tables=array(); for($j=0;$j'L' . $i,'max'=>'L' . ($i+1)); array_push($compts,$c); } $tab=array( 'relatedDim'=>'dim' . ($j+1), 'name'=>'component' . ($j+1), 'units'=>"", 'variable'=>"", 'channels'=>$compts, 'minmax'=>"" ); array_push($tables,$tab); } $data=array( 'dimensions'=>$dims, 'tables'=>$tables ); return array('success'=>true,'data'=>$data); } } public function getSharedObjectFolders($obj) { $mgr = new SharedObjectsMgr(); $folders = $mgr->getFolders($obj->type); return array('success' => true, 'folders' => $folders); } public function shareObjects($obj) { $mgr = new SharedObjectsMgr(); switch ($obj->type) { case 'timeTable' : case 'catalog' : $src_object_path = USERTTDIR.$obj->object->id.".xml"; break; default: return array('success' => false, 'message' => 'Unknown object type'); } $result = $mgr->add($obj->type, $obj->name, $obj->folder, $src_object_path, $obj->description, $this->user); if (!$result['success']) return $result; $mgr->updateTree(); return $result; } public function isSharedObjectNameAlreadyUsed($obj) { $mgr = new SharedObjectsMgr(); $alreadyUsed = $mgr->isNameAlreadyUsed($obj->type, $obj->name); return array('success' => true, 'alreadyUsed' => $alreadyUsed); } public function getRequestByProcessId($obj) { return $this->executeRequest($obj->processId, FunctionTypeEnumClass::PROCESSGETREQUEST); } public function parseTemplatedParam($paramTemplateId) { $args = (Object)array( 'paramId' => $paramTemplateId, 'type' => 'param_parse_template' ); return $this->executeRequest($args, FunctionTypeEnumClass::PARAMINFO); } } ?>