Blame view

src/RequestManagerClass.php 5.12 KB
cc3bdb0e   Elena.Budnik   RequestManager sp...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
/**
 * @class RequestManagerClass
 * @brief Main class to manage a request that's come from an AMDA client
 * @details
 */
Class RequestManagerClass
{
	public static $version = "1.6.0";

/*
	* @brief Constructor
*/
	function __construct()
	{
	
	}
d5a86709   Elena.Budnik   interim commit
18
19
20
21
	
/*
	* @brief Treat a request that's come from the WebServices
*/
8b8f98e3   Elena.Budnik   getStatus fixed
22
	public function runWSRequest($user, $userHost, $function, $service = "", $input)
d5a86709   Elena.Budnik   interim commit
23
	{
8b8f98e3   Elena.Budnik   getStatus fixed
24
25
		if (isset($service))
				WSInputOutputClass::setService($service);
738745d3   Elena.Budnik   draft for Web Ser...
26
27
		//TODO time table conversions can be made by AMDA_Kernel
		if ($function == FunctionTypeEnumClass::PARAMS ) // || $function == FunctionTypeEnumClass::TTCONVERT)
8b8f98e3   Elena.Budnik   getStatus fixed
28
				KernelConfigClass::setTimeToBatchMode(WSConfigClass::$timeToBatchMode);
d5a86709   Elena.Budnik   interim commit
29
		
8b8f98e3   Elena.Budnik   getStatus fixed
30
		return $this->runGenericRequest(ClientTypeEnumClass::WS, $user, $userHost, $function, $input);
d5a86709   Elena.Budnik   interim commit
31
	}
cc3bdb0e   Elena.Budnik   RequestManager sp...
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

/*
	* @brief Treat a request that's come from the IHM
*/
	public function runIHMRequest($user, $userHost, $function, $input)
	{
		return $this->runGenericRequest(ClientTypeEnumClass::IHM,$user,$userHost,$function,$input);
	}

/*
	* @brief Treat a request that's come from a test script
*/
	public function runTestRequest($user, $function, $input)
	{
		$userHost = "";
		return $this->runGenericRequest(ClientTypeEnumClass::TEST,$user,$userHost,$function,$input);
	}

/*
0cea8a4b   Benjamin Renard   Add new client fo...
51
52
53
54
55
56
57
58
59
60
	* @brief Treat a request that's come from AMDA shared objects updater
*/
        public function runSharedObjectsUpdaterRequest($function, $input)
        {
		$user = "";
                $userHost = "";
                return $this->runGenericRequest(ClientTypeEnumClass::SHAREDOBJECTSUPDATER,$user,$userHost,$function,$input);
        }

/*
cc3bdb0e   Elena.Budnik   RequestManager sp...
61
62
63
64
65
66
67
68
	* @brief Create the request instance in relation with the function type
*/
	private function createRequest($user, $userHost, $function)
	{
		switch ($function)
		{
			case FunctionTypeEnumClass::PARAMS :
			case FunctionTypeEnumClass::PARAMSGEN :
cd28a380   Benjamin Renard   Generate param in...
69
70
                        case FunctionTypeEnumClass::PARAMSINFOGEN :
				return new ParamsRequestClass($user, $userHost);
cc3bdb0e   Elena.Budnik   RequestManager sp...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
			case FunctionTypeEnumClass::ACTION :
				return new ParamsRequestClass($user, $userHost);
			case FunctionTypeEnumClass::PROCESSDELETE :
			case FunctionTypeEnumClass::PROCESSRUNNINGINFO :
			case FunctionTypeEnumClass::PROCESSGETINFO :
			case FunctionTypeEnumClass::PROCESSCLEAN :
			case FunctionTypeEnumClass::PROCESSGETREQUEST :
				return new ProcessRequestClass($user, $userHost);
			case FunctionTypeEnumClass::TTMERGE :
			case FunctionTypeEnumClass::TTUNION :
			case FunctionTypeEnumClass::TTCONVERT :
				return new TTRequestClass($user, $userHost);
			case FunctionTypeEnumClass::PARAMINFO :
				return new ParamInfoRequestClass($user, $userHost);
574d7ed3   Benjamin Renard   First step to aut...
85
86
			case FunctionTypeEnumClass::USERWSINIT :
				return new UserRequestClass($user, $userHost);
554f1fae   Erdogan Furkan   #6265 - Zip todo
87
88
			case FunctionTypeEnumClass::DLOBJECT :
				return new DownloadObjectRequestClass($user, $userHost);
cc3bdb0e   Elena.Budnik   RequestManager sp...
89
90
91
92
93
94
95
96
97
98
99
100
101
102
			default :
				throw new Exception('Request '.$function.' not implemented.');
		}
	}

/*
	*  @brief Create an instance of the InputOutput interface in relation with the client
*/
	private function createInputOutput($user,$userHost = null,$client)
	{
		switch ($client)
		{
			case ClientTypeEnumClass::IHM :
				return new IHMInputOutputClass($user, $userHost);
d5a86709   Elena.Budnik   interim commit
103
104
			case ClientTypeEnumClass::WS :
				return new WSInputOutputClass($user, $userHost);	
cc3bdb0e   Elena.Budnik   RequestManager sp...
105
			case ClientTypeEnumClass::TEST :
0cea8a4b   Benjamin Renard   Add new client fo...
106
107
108
				return new TestInputOutputClass($user);
			case ClientTypeEnumClass::SHAREDOBJECTSUPDATER :
				return new SharedObjectsUpdaterInputOutputClass();
cc3bdb0e   Elena.Budnik   RequestManager sp...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
			default :
				throw new Exception('Client '.$client.' not implemented.');
		}
	}

/*
	* @brief Sequence used to run a request
*/
	private function runGenericRequest($client,$user,$userHost,$function,$input)
	{
		//create an instance of the InputOutput interface
		$inputOutput = $this->createInputOutput($user, $userHost, $client);

		//get the input data from the request input data by using the InputOutput interface
		$inputdata = $inputOutput->getInputData($input,$function);
0cea8a4b   Benjamin Renard   Add new client fo...
124
	
cc3bdb0e   Elena.Budnik   RequestManager sp...
125
126
		//create an instance of the RequestClass to run the request
		$request = $this->createRequest($user, $userHost, $function);
8b8f98e3   Elena.Budnik   getStatus fixed
127

cc3bdb0e   Elena.Budnik   RequestManager sp...
128
129
130
131
132
133
134
135
136
		if (is_array($inputdata))
		{
			$outputdata = array();
			foreach ($inputdata as $data)
				//execute the request
				$outputdata[] = $this->runSingleRequest($request,$data);
		}
		else
			$outputdata = $this->runSingleRequest($request,$inputdata);
8b8f98e3   Elena.Budnik   getStatus fixed
137

cc3bdb0e   Elena.Budnik   RequestManager sp...
138
139
140
141
142
143
144
145
146
147
148
		//get the request output data from the output data by using the InputOutput interface
		return $inputOutput->getOutput($outputdata);
	}

/*
	*  @brief Run a single request
*/
	private function runSingleRequest($request,$data)
	{
		//link the request to the input data
		$request->setData($data);
8b8f98e3   Elena.Budnik   getStatus fixed
149
		
cc3bdb0e   Elena.Budnik   RequestManager sp...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
		//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();
	}
}
0cea8a4b   Benjamin Renard   Add new client fo...
173
?>