Blame view

src/REMOTEDATA/RemoteDataCenterClass.php 3.59 KB
41792000   Elena.Budnik   new REMOTEDATA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
/**
 * @class RemoteDataCenterClass  
 * @brief   Server
 * @details
 */
abstract class RemoteDataCenterClass
{
	protected $url = null, $WSDL = null, $treeXML = null;	
		
	protected $needsArgs = false;
	protected $hasAccessUrl = false;

	public $domAmda = null, $dataCenter = null;  
	public $domAmdaName = "base.xml";
	public $additionalArgs = null;
41792000   Elena.Budnik   new REMOTEDATA
17
	public $baseID = null;
8c0d5a9f   Elena.Budnik   correct location ...
18
	public $location;
0ec21281   Elena.Budnik   reorganization + ...
19
	
41792000   Elena.Budnik   new REMOTEDATA
20
	public $tree = null;
d4071e27   Elena.Budnik   makeProxy with en...
21
	protected $DDserverDir;
41792000   Elena.Budnik   new REMOTEDATA
22
23
24
25
26
27
28
29
30
	
   public static $MAX_NAME_LENGTH = 31;
   public static $MAX_VI_NAME_LENGTH = 16;
   
	/*
	 * @brief Constructor
	*/
	function __construct()
	{		
8c0d5a9f   Elena.Budnik   correct location ...
31
32
		$this->baseID = get_class($this);
		$this->location = RemoteData."/bases/".$this->baseID;
36b01ac2   Elena.Budnik   set utc time zone...
33
		date_default_timezone_set('UTC');
155b6b3c   Elena.Budnik   other approach to...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
	}
	
	/*    Function to change  External Bases stuff in case of existing AMDA aliases.
		Uses file  DICTIONARY_DIR.mapBaseID.xml */

	protected function alias($Dictionary, $name) {

		$xmldoc =  new DomDocument("1.0");
		$xmldoc->load($DictionaryFile);
		$item = $xmldoc->getElementById(strtoupper($name));
		
		if (!$item) return $name;      
		$alias =  $item->nodeValue;

	return $alias;
	}
	
41792000   Elena.Budnik   new REMOTEDATA
51
52
53
	
	public function param2dd($paramID) 
	{
d4071e27   Elena.Budnik   makeProxy with en...
54
55
56
		$pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_",
							"@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_"); 

41792000   Elena.Budnik   new REMOTEDATA
57
58
59
60
61
		return strtr($paramID,$pairs); 
	}
	
	public function saveProxy()
	{		
8c0d5a9f   Elena.Budnik   correct location ...
62
		$this->domAmda->save($this->location."/".$this->domAmdaName);		 		
41792000   Elena.Budnik   new REMOTEDATA
63
64
65
66
67
	}
	
	abstract public function init(); 
	abstract protected function getRemoteTree();
	abstract protected function setDataCenterAttributes();
41792000   Elena.Budnik   new REMOTEDATA
68
	abstract protected function makeArgumentsList();
0ec21281   Elena.Budnik   reorganization + ...
69
//	abstract public function getDatasetInfo($ds);	
41792000   Elena.Budnik   new REMOTEDATA
70
71
//	abstract public function getData($ds, $start, $stop);
//	abstract protected function convert2nc();
d4071e27   Elena.Budnik   makeProxy with en...
72
73
74
// abstract protected function createDatasetNodes();
// abstract protected function createParameterNodes();
// abstract protected function createDatasetGroupNodes($data);
41792000   Elena.Budnik   new REMOTEDATA
75
76
77
	
	public function initProxy() 
	{	 
8c0d5a9f   Elena.Budnik   correct location ...
78
		if (!is_dir($this->location))
69754a74   Elena.Budnik   access permission...
79
				mkdir($this->location, 0775, true);
d4071e27   Elena.Budnik   makeProxy with en...
80
81
82
83

		$this->DDserverDir = RemoteData."/DDServer/".$this->baseID;
		
		if (!is_dir($this->DDserverDir)) 
69754a74   Elena.Budnik   access permission...
84
				mkdir($this->DDserverDir, 0775, true);		
d4071e27   Elena.Budnik   makeProxy with en...
85
86
		
		$this->init();
41792000   Elena.Budnik   new REMOTEDATA
87
		
d4071e27   Elena.Budnik   makeProxy with en...
88
		$this->getRemoteTree();	
41792000   Elena.Budnik   new REMOTEDATA
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	} 
	
	public function makeProxy()
	{	
		$this->domAmda = new DOMDocument('1.0', 'utf-8');
		$this->domAmda->formatOutput = TRUE;
		$this->domAmda->preserveWhiteSpace = FALSE;
		
		$dataRoot = $this->domAmda->createElement('dataRoot');
		$dataRoot->setAttribute('xml:id', 'myRemoteData-treeRootNode');
		$this->domAmda->appendChild($dataRoot);	
		
		$this->dataCenter=$this->domAmda->createElement('dataCenter');

		$this->dataCenter->setAttribute('xml:id', $this->baseID);
		$this->dataCenter->setAttribute('name', $this->baseID);		 
		
		$dataRoot->appendChild($this->dataCenter);
		
		$this->setDataCenterAttributes();	
		
		$missionNodes = $this->createMissionNodes();
		
		foreach ($missionNodes as $missionNode)
			$this->dataCenter->appendChild($missionNode);
	}
05fbcab0   Elena.Budnik   DDServices reorga...
115

155b6b3c   Elena.Budnik   other approach to...
116
117
	protected function getIdFromSpase($spaseId) 
	{
05fbcab0   Elena.Budnik   DDServices reorga...
118
119
			$temp = explode('/',$spaseId);
			return $temp[count($temp)-1]; 
155b6b3c   Elena.Budnik   other approach to...
120
121
	}
	
41792000   Elena.Budnik   new REMOTEDATA
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
	public function monitor()
	{		 		
		$ch = curl_init($this->url."/".$this->WSDL);  
		curl_setopt($ch, CURLOPT_TIMEOUT, 3);  
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);  
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
		$data = curl_exec($ch);  
		$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);		
		curl_close($ch); 
		
		if($httpcode >= 200 && $httpcode < 300)
		{  
			return true;  
		} else 
		{  
			return false;  
		}  
	}
}
?>