Commit 62372d94bcc104cf6d934d13f8da4b6c70f98a47

Authored by Elena.Budnik
1 parent 155b6b3c

RemoveVi

src/CALLEXT/createVI.php
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 32
33 $verbose = true; 33 $verbose = true;
34 34
35 - $LOGDIR = getenv("DDBASE")."../LOG/"); 35 + $LOGDIR = getenv("DDBASE")."/../LOG/";
36 if (!is_dir($LOGDIR)) 36 if (!is_dir($LOGDIR))
37 mkdir($LOGDIR, 0755, true); 37 mkdir($LOGDIR, 0755, true);
38 38
src/CALLEXT/getData.php
@@ -33,15 +33,23 @@ @@ -33,15 +33,23 @@
33 putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH")); 33 putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH"));
34 putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin"); 34 putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin");
35 set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT")); 35 set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT"));
  36 + $verbose = true;
  37 +
  38 + $LOGDIR = getenv("DDBASE")."/../LOG/";
  39 + if (!is_dir($LOGDIR))
  40 + mkdir($LOGDIR, 0755, true);
  41 +
  42 + define("log",$LOGDIR."/getData.log");
  43 + define("err",$LOGDIR."/getData.err");
36 44
37 date_default_timezone_set('UTC'); 45 date_default_timezone_set('UTC');
38 $startStamp = strtotime($Start); 46 $startStamp = strtotime($Start);
39 $stopStamp = strtotime($Stop); 47 $stopStamp = strtotime($Stop);
40 - $start = date( "Ymd\THis\Z", $startStamp);  
41 - $stop = date( "Ymd\THis\Z", $stopStamp); 48 + $start = date("Ymd\THis\Z", $startStamp);
  49 + $stop = date("Ymd\THis\Z", $stopStamp);
42 50
43 - $startIso = date( "Y-m-d\TH:i:s\.000\Z", $startStamp);  
44 - $stopIso = date( "Y-m-d\TH:i:s\.000\Z", $stopStamp); 51 + $startIso = date("Y-m-d\TH:i:s\.000\Z", $startStamp);
  52 + $stopIso = date("Y-m-d\TH:i:s\.000\Z", $stopStamp);
45 // Get data and convert to nc 53 // Get data and convert to nc
46 $center = new $base(); 54 $center = new $base();
47 55
src/DATA/MANAGER/DDBaseMgr.php
@@ -115,6 +115,27 @@ class DDBaseMgr @@ -115,6 +115,27 @@ class DDBaseMgr
115 $this->makeAllInLocation(); 115 $this->makeAllInLocation();
116 } 116 }
117 117
  118 + public function deleteVi($ViId, $baseId)
  119 + {
  120 + $XPath = new DOMXpath($this->DDsysDoc);
  121 +
  122 + $dataSet = $XPath->query("//NAME[.='$ViId']");
  123 +
  124 + if ($dataSet->item(0)->getAttribute("base") != $baseId)
  125 + return;
  126 +
  127 + $ViToDelete = $dataSet->item(0)->parentNode;
  128 + $location = $ViToDelete->getElementsByTagName('LOCATION')->item(0)->nodeValue;
  129 +
  130 + $ViToDelete->parentNode->removeChild($ViToDelete);
  131 +
  132 + $this->DDsysDoc->save($this->DDsys);
  133 + system("makeDDsys");
  134 +
  135 + foreach (glob($location."/*") as $file) unlink($file);
  136 + rmdir($location);
  137 + }
  138 +
118 private function makeAllInLocation() 139 private function makeAllInLocation()
119 { 140 {
120 if (!is_dir($this->location)) 141 if (!is_dir($this->location))
@@ -179,12 +200,7 @@ class DDBaseMgr @@ -179,12 +200,7 @@ class DDBaseMgr
179 $this->DDsysDoc->save($this->DDsys); 200 $this->DDsysDoc->save($this->DDsys);
180 system("makeDDsys"); 201 system("makeDDsys");
181 } 202 }
182 -  
183 - public function deleteVi($ViId, $baseId)  
184 - {  
185 -  
186 - }  
187 - 203 +
188 // public function getRemoteLocation($base, $remoteVi) 204 // public function getRemoteLocation($base, $remoteVi)
189 // { 205 // {
190 // $XPath = new DOMXpath($this->DDsysDoc); 206 // $XPath = new DOMXpath($this->DDsysDoc);
src/DATA/MANAGER/RemoveVI.php 0 โ†’ 100644
@@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
  1 +<?php
  2 +
  3 +/**
  4 +* @file RemoveVI.php
  5 +* @version $Id: RemoveVI.php 14 2013-09-23 11:23:28Z elena $
  6 +* @brief DD Server Tools:
  7 +* @arg ViID , [BaseID]
  8 +*/
  9 + if (!function_exists('__autoload'))
  10 + {
  11 + function __autoload($class_name) {
  12 + require_once $class_name . '.php';
  13 + }
  14 + }
  15 +
  16 + putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH"));
  17 + putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin");
  18 + set_include_path("./:".getenv("DATAMANAGER"));
  19 +
  20 + $ViID = strtolower($argv[1]);
  21 + if ($argc == 3)
  22 + $BaseID = strtoupper($argv[2]);
  23 + else
  24 + $BaseID = "LOCAL";
  25 +
  26 + $baseMgr = new DDBaseMgr();
  27 +
  28 + if ($baseMgr->viExists($ViID, $BaseID))
  29 + $baseMgr->deleteVi($ViID, $BaseID);
  30 + else
  31 + echo "NO $ViID in DDsys.xml".PHP_EOL;
  32 +
  33 +?>
src/REMOTEDATA/CDAWEB.php
@@ -8,16 +8,16 @@ class CDAWEB extends RemoteDataCenterClass @@ -8,16 +8,16 @@ class CDAWEB extends RemoteDataCenterClass
8 { 8 {
9 private $ch, $res, $dataViewUR; 9 private $ch, $res, $dataViewUR;
10 private $obsGroupsIds; 10 private $obsGroupsIds;
11 - private $spase_res; 11 + private $spase_res, $insXML;
12 12
13 private $observatoryGroups, $instrumentTypes; 13 private $observatoryGroups, $instrumentTypes;
14 private $CDAWEB = array(), $masterCDF = array(); 14 private $CDAWEB = array(), $masterCDF = array();
15 15
16 // https://cdaweb.gsfc.nasa.gov/WS/cdasr/1/dataviews/sp_phys/instrumentTypes 16 // https://cdaweb.gsfc.nasa.gov/WS/cdasr/1/dataviews/sp_phys/instrumentTypes
17 -/* private $validInstrumentTypes = [ "Activity%20Indices", "Electric%20Fields%20(space)","Gamma%20and%20X-Rays", 17 + private $validInstrumentTypes = [ "Activity%20Indices", "Electric%20Fields%20(space)","Gamma%20and%20X-Rays",
18 "Magnetic%20Fields%20(space)", "Particles%20(space)", "Plasma%20and%20Solar%20Wind", 18 "Magnetic%20Fields%20(space)", "Particles%20(space)", "Plasma%20and%20Solar%20Wind",
19 - "Radio%20and%20Plasma%20Waves%20(space)" ]; */  
20 - private $validInstrumentTypes = [ "Magnetic%20Fields%20(space)" ]; 19 + "Radio%20and%20Plasma%20Waves%20(space)" ];
  20 + // private $validInstrumentTypes = [ "Magnetic%20Fields%20(space)" ];
21 21
22 // not used : $validInstrumentTypes = ["Ephemeris"]; 22 // not used : $validInstrumentTypes = ["Ephemeris"];
23 23
@@ -619,8 +619,6 @@ class CDAWEB extends RemoteDataCenterClass @@ -619,8 +619,6 @@ class CDAWEB extends RemoteDataCenterClass
619 // Create datasets nodes 619 // Create datasets nodes
620 foreach ($dss as $ds){ 620 foreach ($dss as $ds){
621 $dsId = $this->baseID.":".$ds; 621 $dsId = $this->baseID.":".$ds;
622 -// $this->domAmda->save('temp.xml');  
623 -// $this->domAmda->load('temp.xml');  
624 if (!$this->domAmda->getElementById($dsId)){ 622 if (!$this->domAmda->getElementById($dsId)){
625 $this->initDDServerXml($ds,$ins,$obs); 623 $this->initDDServerXml($ds,$ins,$obs);
626 $dsNode = $this->createDatasetNode($ds); 624 $dsNode = $this->createDatasetNode($ds);
@@ -636,10 +634,14 @@ class CDAWEB extends RemoteDataCenterClass @@ -636,10 +634,14 @@ class CDAWEB extends RemoteDataCenterClass
636 if (!$insSpaseId ) 634 if (!$insSpaseId )
637 $insSpaseId = $ins; 635 $insSpaseId = $ins;
638 636
639 - $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs).":".$this->param2dd($insSpaseId); 637 + $obsSpaseId = $this->getObservatorySpase();
  638 + if (!$obsSpaseId )
  639 + $obsSpaseId = $obs;
  640 +
  641 + $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsSpaseId).":".$this->param2dd($insSpaseId);
640 642
641 if (!($insNode = $this->domAmda->getElementById($insId))){ 643 if (!($insNode = $this->domAmda->getElementById($insId))){
642 - $insNode = $this->createInstrumentNode($insSpaseId, $obs, $groupId); 644 + $insNode = $this->createInstrumentNode($insSpaseId, $obsSpaseId, $groupId);
643 $insNodes[] = $insNode; 645 $insNodes[] = $insNode;
644 } 646 }
645 foreach ($dsNodes as $dsNode){ 647 foreach ($dsNodes as $dsNode){
@@ -648,10 +650,11 @@ class CDAWEB extends RemoteDataCenterClass @@ -648,10 +650,11 @@ class CDAWEB extends RemoteDataCenterClass
648 } 650 }
649 } // foreach ($inss as $ins => $dss) 651 } // foreach ($inss as $ins => $dss)
650 if ($insNodes){ 652 if ($insNodes){
651 - $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs); 653 +
  654 + $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsSpaseId);
652 655
653 if (!($obsNode = $this->domAmda->getElementById($obsId))){ 656 if (!($obsNode = $this->domAmda->getElementById($obsId))){
654 - $obsNode = $this->createObservatoryNode($obs, $groupId); 657 + $obsNode = $this->createObservatoryNode($obsSpaseId, $groupId);
655 $obsNodes[] = $obsNode; 658 $obsNodes[] = $obsNode;
656 } 659 }
657 660
@@ -670,9 +673,21 @@ class CDAWEB extends RemoteDataCenterClass @@ -670,9 +673,21 @@ class CDAWEB extends RemoteDataCenterClass
670 } 673 }
671 674
672 foreach ($obsNodes as $obsNode){ 675 foreach ($obsNodes as $obsNode){
673 - $missionNode->appendChild($obsNode); 676 + // observatory == mission
  677 + if ($obsNode->getAttribute('name') == $missionNode->getAttribute('name')) {
  678 + $insNodes = $obsNode->getElementsByTagName("instrument");
  679 + foreach ($insNodes as $insNode)
  680 + $missionNode->appendChild($insNode);
  681 + }
  682 + else
  683 + $missionNode->appendChild($obsNode);
674 } 684 }
675 - } 685 + }
  686 + // getElemetByID doesn't work on newly created Document
  687 + $this->domAmda->save('temp.xml');
  688 + $this->domAmda->load('temp.xml');
  689 +
  690 + $this->dataCenter = $this->domAmda->getElementById($this->baseID);
676 } 691 }
677 } 692 }
678 693
@@ -686,18 +701,19 @@ class CDAWEB extends RemoteDataCenterClass @@ -686,18 +701,19 @@ class CDAWEB extends RemoteDataCenterClass
686 } 701 }
687 702
688 protected function getInstrumentSpase(){ 703 protected function getInstrumentSpase(){
689 - $insXML = new DomDocument("1.0"); 704 +
  705 + $this->insXML = new DomDocument("1.0");
690 706
691 if ($this->spase_res){ 707 if ($this->spase_res){
692 $instrument = $this->spase_res->getElementsByTagName('InstrumentID'); 708 $instrument = $this->spase_res->getElementsByTagName('InstrumentID');
693 709
694 if ($instrument->length > 0) { 710 if ($instrument->length > 0) {
  711 +
  712 + curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$instrument->item(0)->nodeValue);
  713 +
  714 + $this->insXML->loadXML(curl_exec($this->ch));
  715 +
695 return $this->getIdFromSpase($instrument->item(0)->nodeValue); 716 return $this->getIdFromSpase($instrument->item(0)->nodeValue);
696 -// curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$instrument->item(0)->nodeValue);  
697 -//  
698 -// if (!$insXML->loadXML(curl_exec($this->ch))){  
699 -// return null;  
700 -// }  
701 //InstrumentType 717 //InstrumentType
702 //spase://SMWG/Observatory/ACE 718 //spase://SMWG/Observatory/ACE
703 } 719 }
@@ -706,6 +722,19 @@ class CDAWEB extends RemoteDataCenterClass @@ -706,6 +722,19 @@ class CDAWEB extends RemoteDataCenterClass
706 return null; 722 return null;
707 } 723 }
708 724
  725 + protected function getObservatorySpase(){
  726 +
  727 + if ($this->insXML){
  728 + $observatory = $this->insXML->getElementsByTagName('ObservatoryID');
  729 +
  730 + if ($observatory->length > 0) {
  731 + return $this->getIdFromSpase($observatory->item(0)->nodeValue);
  732 + }
  733 + }
  734 +
  735 + return null;
  736 + }
  737 +
709 protected function setDataCenterAttributes(){} 738 protected function setDataCenterAttributes(){}
710 protected function makeArgumentsList(){} 739 protected function makeArgumentsList(){}
711 } 740 }