Blame view

src/RequestManager.php 6.02 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
	const ACTION             = "action";
	const PROCESSDELETE      = "process_delete";
	const PROCESSRUNNINGINFO = "process_running_info";
	const PROCESSGETINFO     = "process_get_info";
	const PROCESSCLEAN       = "process_clean";
84cb4dbb   Benjamin Renard   Give the possibil...
79
	const PROCESSGETREQUEST  = "process_get_request";
22521f1c   Benjamin Renard   First commit
80
	const TTMERGE            = "tt_merge";
966bd5f8   Benjamin Renard   Add request to ge...
81
	const TTUNION            = "tt_union";
0b6b2080   Elena.Budnik   TT download
82
	const TTCONVERT          = "tt_convert";
966bd5f8   Benjamin Renard   Add request to ge...
83
	const PARAMINFO          = "param_info";
22521f1c   Benjamin Renard   First commit
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
}

/**
 * @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
{
34f96c08   Benjamin Renard   Set to version 1.6.0
104
	public static $version = "1.6.0";
22521f1c   Benjamin Renard   First commit
105

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

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

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

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

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

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

		//get the input data from the request input data by using the InputOutput interface
		$inputdata = $inputOutput->getInputData($input,$function);
952dd7c7   elena   catalog integration
184
		
22521f1c   Benjamin Renard   First commit
185
		//create an instance of the RequestClass to run the request
87a28122   Elena.Budnik   create app.user.n...
186
		$request = $this->createRequest($user, $userHost, $function);
952dd7c7   elena   catalog integration
187
		
22521f1c   Benjamin Renard   First commit
188
189
190
191
192
193
194
195
196
		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
197
				
22521f1c   Benjamin Renard   First commit
198
199
200
201
		//get the request output data from the output data by using the InputOutput interface
		return $inputOutput->getOutput($outputdata);
	}

0b6b2080   Elena.Budnik   TT download
202
203
204
/*
	*  @brief Run a single request
*/
22521f1c   Benjamin Renard   First commit
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
233
234
	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();
	}
}

?>