3 require_once '../../../env.inc.php';
4 require_once $gfwww.'include/squal_pre.php';
5 require_once $gfcommon.'include/gettext.php';
6 require_once $gfcommon.'include/FusionForge.class.php';
7 require_once './coreapiobjects.php';
9 // Log4php initialisation
10 require_once dirname(__FILE__).'/../log4php/Logger.php';
11 Logger::configure(dirname(__FILE__).'/../log4php.properties');
15 * CoreApiService (SOAP Server)
17 Class CoreApiServer extends SoapServer {
22 * Default class map for wsdl=>php
26 private static $classmap = array(
27 "getSCMData" => "getSCMData_soap",
28 "getSCMDataResponse" => "getSCMDataResponse_soap",
29 "scmData" => "scmData_soap",
30 "getVersion" => "getVersion_soap",
31 "getVersionResponse" => "getVersionResponse_soap",
32 "getGroups" => "getGroups_soap",
33 "getGroupsResponse" => "getGroupsResponse_soap",
34 "group" => "group_soap",
35 "getPublicProjectNames" => "getPublicProjectNames_soap",
36 "getPublicProjectNamesResponse" => "getPublicProjectNamesResponse_soap",
37 "userGetGroups" => "userGetGroups_soap",
38 "userGetGroupsResponse" => "userGetGroupsResponse_soap",
39 "getUsers" => "getUsers_soap",
40 "getUsersResponse" => "getUsersResponse_soap",
41 "user" => "user_soap",
42 "getGroupsByName" => "getGroupsByName_soap",
43 "getGroupsByNameResponse" => "getGroupsByNameResponse_soap",
44 "getUsersByName" => "getUsersByName_soap",
45 "getUsersByNameResponse" => "getUsersByNameResponse_soap",
49 * Constructor using wsdl location and options array
50 * @param string $wsdl WSDL location for this service
51 * @param array $options Options for the SoapClient
53 public function __construct($wsdl="FusionforgeCoreApi.wsdl", $options=array()) {
55 $this->logger = Logger::getLogger('api.soap.core.CoreApi');
56 $this->logger->debug("FusionForgeCoreApi Soap Server created ...");
57 foreach(self::$classmap as $wsdlClassName => $phpClassName) {
58 if(!isset($options['classmap'][$wsdlClassName])) {
59 $options['classmap'][$wsdlClassName] = $phpClassName;
62 parent::__construct($wsdl, $options);
67 class CoreApiService {
71 public function __construct() {
72 // log4php logger initialization for the class
73 $this->logger = Logger::getLogger('fusionforge.api.soap.CoreApi');
77 * Checks if an argument list matches against a valid argument type list
78 * @param array $arguments The argument list to check
79 * @param array $validParameters A list of valid argument types
80 * @return boolean true if arguments match against validParameters
81 * @throws Exception invalid function signature message
83 public function _checkArguments($arguments, $validParameters) {
85 foreach ($arguments as $arg) {
86 $type = gettype($arg);
87 if ($type == "object") {
88 $type = get_class($arg);
90 $variables .= "(".$type.")";
92 if (!in_array($variables, $validParameters)) {
93 throw new Exception("Invalid parameter types: ".str_replace(")(", ", ", $variables));
99 * Service Call: getVersion
101 * @param mixed getVersion_soap (Soap request object)
102 * @return getVersionResponse_soap (Soap response object) or SoapFault if parameter are invalid
104 public function getVersion($mixed = null) {
105 $this->logger->info("CoreApiService Soap call : getVersion");
106 $validParameters = array(
111 $args = func_get_args();
112 $this->_checkArguments($args, $validParameters);
114 catch (Exception $e) {
115 // Invalid parameters => return a soap fault
116 return new SoapFault($e->getCode(),$e->getMessage());
119 $fusionforge = new FusionForge();
120 $response = new getVersionResponse_soap();
121 $response->version = $fusionforge->software_version;
127 * Service Call: getGroups
129 * @param mixed getGroups_soap (Soap request object)
130 * @return getGroupsResponse_soap (Soap response object) or SoapFault if parameters are invalid
132 public function getGroups($mixed = null) {
133 $group_ids = $mixed->group_id;
134 $this->logger->info("CoreApiService Soap call : getGroups for group_id ".var_export($group_ids, true));
135 $validParameters = array(
140 $args = func_get_args();
141 $this->_checkArguments($args, $validParameters);
143 catch (Exception $e) {
144 // Invalid parameters => return a soap fault
145 return new SoapFault($e->getCode(),$e->getMessage());
148 $grps =& group_get_objects($group_ids);
150 $this->logger->debug("Could Not Get Groups by Id");
151 return new soap_fault ('2001','group','Could Not Get Groups by Id'.$inputArgs,$feedback);
154 $response = new getGroupsResponse_soap();
155 $this->logger->debug((count($grps)+1)." Groups objects found");
157 for ($i=0; $i<count($grps); $i++) {
158 $group = new group_soap();
159 $group->group_id = $grps[$i]->data_array['group_id'];
160 $group->group_name=$grps[$i]->data_array['group_name'];
161 $group->homepage=$grps[$i]->data_array['homepage'];
162 $group->is_public=$grps[$i]->data_array['is_public'];
163 $group->status=$grps[$i]->data_array['status'];
164 $group->unix_group_name=$grps[$i]->data_array['unix_group_name'];
165 $group->short_description=$grps[$i]->data_array['short_description'];
166 $group->scm_box=$grps[$i]->data_array['scm_box'];
167 $group->register_time=$grps[$i]->data_array['register_time'];
168 $response->group[$i]=$group;
169 $this->logger->debug("Adding Group objects : ".var_export($group, true));
177 * Service Call: getUsers
179 * @param mixed getUsers_soap (Soap request object)
180 * @return getUsersResponse_soap (Soap response object) or SoapFault if parameters are invalid
182 public function getUsers($mixed = null) {
183 $this->logger->debug("CoreApiService Soap call getUsers ".var_export($mixed, true));
185 // The $mixed->user_id is an array only if several user_id in the SOAP request
186 if (is_array($mixed->user_id)) {
187 $user_id = $mixed->user_id;
190 $user_id = array(0=>$mixed->user_id);
193 $validParameters = array(
198 $args = func_get_args();
199 $this->_checkArguments($args, $validParameters);
201 catch (Exception $e) {
202 // Invalid parameters => return a soap fault
203 return new SoapFault($e->getCode(),$e->getMessage());
206 $users =& user_get_objects($user_id);
207 $this->logger->debug("users found : ".var_export($users, true));
209 return new SoapFault('3001','Could Not Get Users By Id');
212 $response = new getUsersResponse_soap();
213 for ($i=0; $i<count($users); $i++) {
214 if ($users[$i]->isError()){
215 //skip it if it had an error
217 //build each user_soap response
218 $user = new user_soap();
219 $user->user_id=$users[$i]->data_array['user_id'];
220 $user->user_name=$users[$i]->data_array['user_name'];
221 $user->title=$users[$i]->data_array['title'];
222 $user->firstname=$users[$i]->data_array['firstname'];
223 $user->lastname=$users[$i]->data_array['lastname'];
224 $user->address=$users[$i]->data_array['address'];
225 $user->address2=$users[$i]->data_array['address2'];
226 $user->phone=$users[$i]->data_array['phone'];
227 $user->fax=$users[$i]->data_array['fax'];
228 $user->status=$users[$i]->data_array['status'];
229 $user->timezone=$users[$i]->data_array['timezone'];
230 $user->country_code=$users[$i]->data_array['country_code'];
231 $user->add_date=$users[$i]->data_array['add_date'];
232 $user->language_id=$users[$i]->data_array['language_id'];
233 $response->user[$i]=$user;
241 * Service Call: getGroupsByName
243 * @param mixed getGroupsByName_soap (Soap request object)
244 * @return getGroupsByNameResponse_soap (Soap response object) or SoapFault if parameters are invalid
246 public function getGroupsByName($mixed = null) {
247 $this->logger->debug("Soap call getGroupsByName ".var_export($mixed, true));
248 // The $mixed->group_name is an array only if several group_name in the SOAP request
249 if (is_array($mixed->group_name)) {
250 $group_names = $mixed->group_name;
253 $group_names = array(0=>$mixed->group_name);
256 $validParameters = array(
257 "(getGroupsByName_soap)",
261 $args = func_get_args();
262 $this->_checkArguments($args, $validParameters);
264 catch (Exception $e) {
265 // Invalid parameters => return a soap fault
266 return new SoapFault($e->getCode(),$e->getMessage());
268 $grps =& group_get_objects_by_name($group_names);
270 return new SoapFault('2002','Could Not Get Groups by Name');
273 $response = new getGroupsByNameResponse_soap();
274 // $grps contains an array of Group object
275 for ($i=0; $i<count($grps); $i++) {
276 if ($grps[$i]->isError()) {
277 //skip it if it had an error
279 //build each group_soap response
280 $group = new group_soap();
281 $group->group_id=$grps[$i]->data_array['group_id'];
282 $group->group_name=$grps[$i]->data_array['group_name'];
283 $group->homepage=$grps[$i]->data_array['homepage'];
284 $group->is_public=$grps[$i]->data_array['is_public'];
285 $group->status=$grps[$i]->data_array['status'];
286 $group->unix_group_name=$grps[$i]->data_array['unix_group_name'];
287 $group->short_description=$grps[$i]->data_array['short_description'];
288 $group->scm_box=$grps[$i]->data_array['scm_box'];
289 $group->register_time=$grps[$i]->data_array['register_time'];
290 $response->group[$i] = $group;
294 $this->logger->debug("getGroupsByNameResponse_soap : ".var_export($response, true));
300 * Service Call: getPublicProjectNames
302 * @param mixed getPublicProjectNames_soap (Soap request object)
303 * @return getPublicProjectNamesResponse_soap (Soap response object) or SoapFault if parameters are invalid
305 public function getPublicProjectNames($mixed = null) {
306 $this->logger->debug("Soap call getPublicProjectNames");
307 $validParameters = array(
308 "(getPublicProjectNames_soap)",
312 $args = func_get_args();
313 $this->_checkArguments($args, $validParameters);
315 catch (Exception $e) {
316 // Invalid parameters => return a soap fault
317 return new SoapFault($e->getCode(),$e->getMessage());
320 $response = new getPublicProjectNamesResponse_soap();
321 $forge = new FusionForge();
322 $response->project_name = $forge->getPublicProjectNames();
324 if ($forge->isError()) {
325 $errMsg = 'Could Not Get Public Group Names: '.$forge->getErrorMessage();
326 return new SoapFault('2003',$errMsg);
328 $this->logger->debug("Public Projects number found : ".var_export($response->project_name, true));
334 * Service Call: getUsersByName
336 * @param mixed getUsersByName_soap (Soap request object)
337 * @return getUsersByNameResponse_soap (Soap response object) or SoapFault if parameters are invalid
339 public function getUsersByName($mixed = null) {
340 $this->logger->debug("CoreApiService Soap call getUsersByName ".var_export($mixed, true));
341 // The $mixed->group_name is an array only if several group_name in the SOAP request
342 if (is_array($mixed->user_name)) {
343 $user_names = $mixed->user_name;
346 $user_names = array(0=>$mixed->user_name);
349 $validParameters = array(
350 "(getUsersByName_soap)",
353 $args = func_get_args();
354 $this->_checkArguments($args, $validParameters);
356 catch (Exception $e) {
357 // Invalid parameters => return a soap fault
358 return new SoapFault($e->getCode(),$e->getMessage());
361 $users =& user_get_objects_by_name($user_names);
363 return new SoapFault('3002','Could Not Get Users By Name');
366 $response = new getUsersByNameResponse_soap();
367 for ($i=0; $i<count($users); $i++) {
368 if ($users[$i]->isError()){
369 //skip it if it had an error
371 //build each user_soap response
372 $user = new user_soap();
373 $user->user_id=$users[$i]->data_array['user_id'];
374 $user->user_name=$users[$i]->data_array['user_name'];
375 $user->title=$users[$i]->data_array['title'];
376 $user->firstname=$users[$i]->data_array['firstname'];
377 $user->lastname=$users[$i]->data_array['lastname'];
378 $user->address=$users[$i]->data_array['address'];
379 $user->address2=$users[$i]->data_array['address2'];
380 $user->phone=$users[$i]->data_array['phone'];
381 $user->fax=$users[$i]->data_array['fax'];
382 $user->status=$users[$i]->data_array['status'];
383 $user->timezone=$users[$i]->data_array['timezone'];
384 $user->country_code=$users[$i]->data_array['country_code'];
385 $user->add_date=$users[$i]->data_array['add_date'];
386 $user->language_id=$users[$i]->data_array['language_id'];
387 $response->user[$i]=$user;
395 * Service Call: userGetGroups
397 * @param mixed userGetGroups_soap (Soap request object)
398 * @return userGetGroupsResponse_soap (Soap response object) or SoapFault if parameters are invalid
400 public function userGetGroups($mixed = null) {
402 $this->logger->debug("CoreApiService Soap call : userGetGroups for user_id ".var_export($mixed, true));
403 $user_id = $mixed->user_id;
405 $validParameters = array(
406 "(userGetGroups_soap)",
409 $args = func_get_args();
410 $this->_checkArguments($args, $validParameters);
412 catch (Exception $e) {
413 // Invalid parameters => return a soap fault
414 return new SoapFault($e->getCode(),$e->getMessage());
417 $user =& user_get_object($user_id);
419 return new SoapFault('3003','Could Not Get Users Groups');
422 // $grps contains an array of Group object
423 $grps = $user->getGroups();
424 $this->logger->debug(count($grps). " groups found");
425 $response = new userGetGroupsResponse_soap();
427 for ($i=0; $i<count($grps); $i++) {
428 if ($grps[$i]->isError()) {
429 //skip it if it had an error
431 //build each group_soap response
432 $group = new group_soap();
433 $group->group_id=$grps[$i]->data_array['group_id'];
434 $group->group_name=$grps[$i]->data_array['group_name'];
435 $group->homepage=$grps[$i]->data_array['homepage'];
436 $group->is_public=$grps[$i]->data_array['is_public'];
437 $group->status=$grps[$i]->data_array['status'];
438 $group->unix_group_name=$grps[$i]->data_array['unix_group_name'];
439 $group->short_description=$grps[$i]->data_array['short_description'];
440 $group->scm_box=$grps[$i]->data_array['scm_box'];
441 $group->register_time=$grps[$i]->data_array['register_time'];
442 $response->group[$i] = $group;
443 $this->logger->debug("adding group : ".var_export($group, true));
447 $this->logger->debug("userGetGroupsResponse_soap : ".var_export($response, true));
455 * Service Call: getSCMData
457 * @param mixed getSCMData_soap (Soap request object)
458 * @return getSCMDataResponse_soap (Soap response object) or SoapFault if parameters are invalid
460 public function getSCMData($mixed = null) {
461 $group_id = $mixed->group_id;
462 $this->logger->debug("Soap call : getSCMData for group_id ".$group_id);
463 $validParameters = array(
467 $args = func_get_args();
468 $this->_checkArguments($args, $validParameters);
470 catch (Exception $e) {
471 // Invalid parameters => return a soap fault
472 return new SoapFault($e->getCode(),$e->getMessage());
474 // Search the group object in the database
475 $grp =& group_get_object($group_id);
476 $this->logger->debug("group_get_object : ".var_export($grp, true));
479 if (!$grp || !is_object($grp)) {
480 $this->logger->error("Returning SOAP Fault - Could Not Get Group : ".$group_id);
481 // TODO : Error code to be determined
482 return new SoapFault('-1', 'Could Not Get Group');
483 } elseif ($grp->isError()) {
484 $this->logger->error($grp->getErrorMessage()." for group_id : ".$group_id);
485 // TODO : Error code to be determined
486 return new SoapFault ('-1',$grp->getErrorMessage());
488 if (!$grp->usesSCM()) {
489 $this->logger->error('SCM is not enabled in this project ; group_id : '.$group_id);
490 // TODO : Error code to be determined
491 return new SoapFault ('-1','SCM is not enabled in this project');
494 // Create the SOAP response
495 $response = new getSCMDataResponse_soap();
496 $scm_data = new scmData_soap();
498 if ($grp->usesPlugin("scmcvs")) {
499 $scm_data->type = "CVS";
500 $scm_data->allow_anonymous = $grp->enableAnonSCM();
501 $scm_data->public = $grp->enablePserver();
502 $scm_data->box = $grp->getSCMBox();
503 $scm_data->module = $grp->getUnixName();
504 $scm_data->connection_string = ""; // this doesn't apply to CVS
505 // Note: This was taken from CVS plugin. Maybe we shouldn't hardcode this?
506 $scm_data->root = "/cvsroot/".$grp->getUnixName();
507 } else if ($grp->usesPlugin("scmsvn")) {
508 $scm_data->type = "SVN";
509 $scm_data->allow_anonymous = $grp->enableAnonSCM();
510 $scm_data->public = $grp->enablePserver();
511 $scm_data->box = $grp->getSCMBox();
512 $scm_data->root = $GLOBALS["svn_root"]."/".$grp->getUnixName();
513 $scm_data->module = ""; // doesn't apply to SVN
515 // Note: This is an ugly hack. We can't access SVN plugin object for this project
516 // directly. Currently this is being rewritten, but for now we must make this.
518 //TODO How to have access to $gfconfig variable ??
520 include $gfconfig.'plugins/scmsvn/config.php';
521 $scm_data->connection_string = "http".(($use_ssl) ? "s" : "")."://".$grp->getSCMBox()."/".$svn_root."/".$grp->getUnixName();
524 $response->scm_data= $scm_data;