Blame view

src/RequestManager.php 5.92 KB
22521f1c   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
<?php

//autoload configuration
function amdaintegration_autoload($class_name)
{
	$dirs = array(
			'InputOutput',
			'InputOutput/IHMImpl',
			'InputOutput/IHMImpl/Config',
			'InputOutput/IHMImpl/Params',
			'InputOutput/IHMImpl/Params/DataMiningImpl',
01ff2cc6   elena   catalog draft
12
			'InputOutput/IHMImpl/Params/StatisticsImpl',
22521f1c   Benjamin Renard   First commit
13
14
			'InputOutput/IHMImpl/Params/DownloadImpl',
			'InputOutput/IHMImpl/Params/PlotImpl',
3493f196   Benjamin Renard   Add request to ge...
15
			'InputOutput/IHMImpl/Params/GeneratorImpl',
22521f1c   Benjamin Renard   First commit
16
			'InputOutput/IHMImpl/Process',
966bd5f8   Benjamin Renard   Add request to ge...
17
			'InputOutput/IHMImpl/ParamInfo',
22521f1c   Benjamin Renard   First commit
18
			'InputOutput/IHMImpl/Tools',
0b6b2080   Elena.Budnik   TT download
19
			'InputOutput/IHMImpl/TimeTables',
22521f1c   Benjamin Renard   First commit
20
21
22
23
24
			'InputOutput/TestImpl',
			'Request',
			'Request/Config',
			'Request/ParamsRequestImpl',
			'Request/ParamsRequestImpl/Nodes',
944199fe   Benjamin Renard   Use table definit...
25
			'Request/ParamsRequestImpl/Nodes/Infos',
22521f1c   Benjamin Renard   First commit
26
27
28
			'Request/ParamsRequestImpl/Nodes/Params',
			'Request/ParamsRequestImpl/Nodes/Requests',
			'Request/ProcessRequestImpl',
0b6b2080   Elena.Budnik   TT download
29
			'Request/ProcessRequestImpl/Process',
577d5c04   Elena.Budnik   IMPEX integration
30
			'Request/TTRequestImpl' 
22521f1c   Benjamin Renard   First commit
31
	);
577d5c04   Elena.Budnik   IMPEX integration
32
33
34
35
36
37
38
39
	
	$ihm_dirs = array(
			IHM_SRC_DIR.'php/classes',
			IHM_SRC_DIR.'php/RemoteDataCenter'
	);
   
   $find = false;
	
22521f1c   Benjamin Renard   First commit
40
41
42
43
44
45
	foreach($dirs as $dir)
	{
		$file = __DIR__.'/'.$dir.'/'.$class_name.'.php';
		if (file_exists($file))
		{
			require $file;
577d5c04   Elena.Budnik   IMPEX integration
46
			$find = true;
22521f1c   Benjamin Renard   First commit
47
48
49
			break;
		}
	}
577d5c04   Elena.Budnik   IMPEX integration
50
51
52
53
54
55
56
57
58
59
60
	
	if (!$find)
		foreach($ihm_dirs as $dir)
		{
			$file = $dir.'/'.$class_name.'.php';
			if (file_exists($file))
			{
				require $file;			 
				break;
			}
		}		
22521f1c   Benjamin Renard   First commit
61
62
63
64
65
66
67
68
69
70
71
72
}

spl_autoload_register('amdaintegration_autoload');

/**
 * @class FunctionTypeEnumClass
 * @brief Abstract class used as an enumerate for function type.
 * @details
*/
abstract class FunctionTypeEnumClass
{
	const PARAMS             = "params";
3493f196   Benjamin Renard   Add request to ge...
73
	const PARAMSGEN          = "params_gen";
22521f1c   Benjamin Renard   First commit
74
75
76
77
78
79
	const ACTION             = "action";
	const PROCESSDELETE      = "process_delete";
	const PROCESSRUNNINGINFO = "process_running_info";
	const PROCESSGETINFO     = "process_get_info";
	const PROCESSCLEAN       = "process_clean";
	const TTMERGE            = "tt_merge";
966bd5f8   Benjamin Renard   Add request to ge...
80
	const TTUNION            = "tt_union";
0b6b2080   Elena.Budnik   TT download
81
	const TTCONVERT          = "tt_convert";
966bd5f8   Benjamin Renard   Add request to ge...
82
	const PARAMINFO          = "param_info";
22521f1c   Benjamin Renard   First commit
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
}

/**
 * @class ClientTypeEnumClass
 * @brief Abstract class used as an enumerate for AMDA_Integration client.
 * @details
 */
abstract class ClientTypeEnumClass
{
	const IHM  = "ihm";
	const TEST = "test";
}

/**
 * @class RequestManagerClass
 * @brief Main class to manage a request that's come from an AMDA client
 * @details
 */
Class RequestManagerClass
{
443f9d6b   Benjamin Renard   Set to version 1.5
103
	public static $version = "1.5.0";
22521f1c   Benjamin Renard   First commit
104

0b6b2080   Elena.Budnik   TT download
105
106
107
/*
	* @brief Constructor
*/
22521f1c   Benjamin Renard   First commit
108
109
110
111
	function __construct()
	{
	}

0b6b2080   Elena.Budnik   TT download
112
113
114
/*
	* @brief Treat a request that's come from the IHM
*/
22521f1c   Benjamin Renard   First commit
115
116
117
118
119
	public function runIHMRequest($user, $userHost, $function, $input)
	{
		return $this->runGenericRequest(ClientTypeEnumClass::IHM,$user,$userHost,$function,$input);
	}

0b6b2080   Elena.Budnik   TT download
120
121
122
/*
	* @brief Treat a request that's come from a test script
*/
22521f1c   Benjamin Renard   First commit
123
124
125
126
127
128
	public function runTestRequest($user, $function, $input)
	{
		$userHost = "";
		return $this->runGenericRequest(ClientTypeEnumClass::TEST,$user,$userHost,$function,$input);
	}

0b6b2080   Elena.Budnik   TT download
129
130
131
/*
	* @brief Create the request instance in relation with the function type
*/
87a28122   Elena.Budnik   create app.user.n...
132
	private function createRequest($user, $userHost, $function)
22521f1c   Benjamin Renard   First commit
133
134
135
136
	{
		switch ($function)
		{
			case FunctionTypeEnumClass::PARAMS :
3493f196   Benjamin Renard   Add request to ge...
137
			case FunctionTypeEnumClass::PARAMSGEN :
22521f1c   Benjamin Renard   First commit
138
			case FunctionTypeEnumClass::ACTION :
87a28122   Elena.Budnik   create app.user.n...
139
				return new ParamsRequestClass($user, $userHost);
22521f1c   Benjamin Renard   First commit
140
141
142
143
			case FunctionTypeEnumClass::PROCESSDELETE :
			case FunctionTypeEnumClass::PROCESSRUNNINGINFO :
			case FunctionTypeEnumClass::PROCESSGETINFO :
			case FunctionTypeEnumClass::PROCESSCLEAN :
87a28122   Elena.Budnik   create app.user.n...
144
				return new ProcessRequestClass($user, $userHost);
22521f1c   Benjamin Renard   First commit
145
146
			case FunctionTypeEnumClass::TTMERGE :
			case FunctionTypeEnumClass::TTUNION :
0b6b2080   Elena.Budnik   TT download
147
			case FunctionTypeEnumClass::TTCONVERT :
87a28122   Elena.Budnik   create app.user.n...
148
				return new TTRequestClass($user, $userHost);
966bd5f8   Benjamin Renard   Add request to ge...
149
			case FunctionTypeEnumClass::PARAMINFO :
87a28122   Elena.Budnik   create app.user.n...
150
				return new ParamInfoRequestClass($user, $userHost);
22521f1c   Benjamin Renard   First commit
151
152
153
154
155
			default :
				throw new Exception('Request '.$function.' not implemented.');
		}
	}

0b6b2080   Elena.Budnik   TT download
156
157
158
/*
	*  @brief Create an instance of the InputOutput interface in relation with the client
*/
ffc5cb81   Elena.Budnik   temporary commit
159
	private function createInputOutput($user,$userHost = null,$client)
22521f1c   Benjamin Renard   First commit
160
161
162
163
	{
		switch ($client)
		{
			case ClientTypeEnumClass::IHM :
ffc5cb81   Elena.Budnik   temporary commit
164
				return new IHMInputOutputClass($user, $userHost);
22521f1c   Benjamin Renard   First commit
165
166
167
168
169
170
171
			case ClientTypeEnumClass::TEST :
				return new TestInputOutputClass($user);
			default :
				throw new Exception('Client '.$client.' not implemented.');
		}
	}

0b6b2080   Elena.Budnik   TT download
172
173
174
/*
	* @brief Sequence used to run a request
*/
22521f1c   Benjamin Renard   First commit
175
176
177
	private function runGenericRequest($client,$user,$userHost,$function,$input)
	{
		//create an instance of the InputOutput interface
ffc5cb81   Elena.Budnik   temporary commit
178
		$inputOutput = $this->createInputOutput($user, $userHost, $client);
22521f1c   Benjamin Renard   First commit
179
180
181

		//get the input data from the request input data by using the InputOutput interface
		$inputdata = $inputOutput->getInputData($input,$function);
952dd7c7   elena   catalog integration
182
		
22521f1c   Benjamin Renard   First commit
183
		//create an instance of the RequestClass to run the request
87a28122   Elena.Budnik   create app.user.n...
184
		$request = $this->createRequest($user, $userHost, $function);
952dd7c7   elena   catalog integration
185
		
22521f1c   Benjamin Renard   First commit
186
187
188
189
190
191
192
193
194
		if (is_array($inputdata))
		{
			$outputdata = array();
			foreach ($inputdata as $data)
				//execute the request
				$outputdata[] = $this->runSingleRequest($request,$data);
		}
		else
			$outputdata = $this->runSingleRequest($request,$inputdata);
0b6b2080   Elena.Budnik   TT download
195
				
22521f1c   Benjamin Renard   First commit
196
197
198
199
		//get the request output data from the output data by using the InputOutput interface
		return $inputOutput->getOutput($outputdata);
	}

0b6b2080   Elena.Budnik   TT download
200
201
202
/*
	*  @brief Run a single request
*/
22521f1c   Benjamin Renard   First commit
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
	private function runSingleRequest($request,$data)
	{
		//link the request to the input data
		$request->setData($data);

		//init the request
		if (!$request->init())
		{
			$crtData = $request->getData();
			if (isset($crtData))
				throw new Exception('Request initialization error  : '.$crtData->getLastErrorMessage());
			else
				throw new Exception('Cannot init request. Unknown error.');
		}

		//run the request
		if (!$request->run())
		{
			$crtData = $request->getData();
			if ($crtData)
				throw new Exception('Request execution error  : '.$crtData->getLastErrorMessage());
			else
				throw new Exception('Cannot run request. Unknown error.');
		}

		return $request->getData();
	}
}

?>