1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
|
<?php
require_once '../../../env.inc.php';
require_once $gfwww.'include/squal_pre.php';
require_once $gfcommon.'include/gettext.php';
require_once $gfcommon.'include/FusionForge.class.php';
require_once './coreapiobjects.php';
// Log4php initialisation
require_once dirname(__FILE__).'/../log4php/Logger.php';
Logger::configure(dirname(__FILE__).'/../log4php.properties');
/**
* CoreApiService (SOAP Server)
*/
Class CoreApiServer extends SoapServer {
private $logger;
/**
* Default class map for wsdl=>php
* @access private
* @var array
*/
private static $classmap = array(
"getSCMData" => "getSCMData_soap",
"getSCMDataResponse" => "getSCMDataResponse_soap",
"scmData" => "scmData_soap",
"getVersion" => "getVersion_soap",
"getVersionResponse" => "getVersionResponse_soap",
"getGroups" => "getGroups_soap",
"getGroupsResponse" => "getGroupsResponse_soap",
"group" => "group_soap",
"getPublicProjectNames" => "getPublicProjectNames_soap",
"getPublicProjectNamesResponse" => "getPublicProjectNamesResponse_soap",
"userGetGroups" => "userGetGroups_soap",
"userGetGroupsResponse" => "userGetGroupsResponse_soap",
"getUsers" => "getUsers_soap",
"getUsersResponse" => "getUsersResponse_soap",
"user" => "user_soap",
"getGroupsByName" => "getGroupsByName_soap",
"getGroupsByNameResponse" => "getGroupsByNameResponse_soap",
"getUsersByName" => "getUsersByName_soap",
"getUsersByNameResponse" => "getUsersByNameResponse_soap",
);
/**
* Constructor using wsdl location and options array
* @param string $wsdl WSDL location for this service
* @param array $options Options for the SoapClient
*/
public function __construct($wsdl="FusionforgeCoreApi.wsdl", $options=array()) {
$this->logger = Logger::getLogger('api.soap.core.CoreApi');
$this->logger->debug("FusionForgeCoreApi Soap Server created ...");
foreach(self::$classmap as $wsdlClassName => $phpClassName) {
if(!isset($options['classmap'][$wsdlClassName])) {
$options['classmap'][$wsdlClassName] = $phpClassName;
}
}
parent::__construct($wsdl, $options);
}
}
class CoreApiService {
private $logger;
public function __construct() {
// log4php logger initialization for the class
$this->logger = Logger::getLogger('fusionforge.api.soap.CoreApi');
}
/**
* Checks if an argument list matches against a valid argument type list
* @param array $arguments The argument list to check
* @param array $validParameters A list of valid argument types
* @return boolean true if arguments match against validParameters
* @throws Exception invalid function signature message
*/
public function _checkArguments($arguments, $validParameters) {
$variables = "";
foreach ($arguments as $arg) {
$type = gettype($arg);
if ($type == "object") {
$type = get_class($arg);
}
$variables .= "(".$type.")";
}
if (!in_array($variables, $validParameters)) {
throw new Exception("Invalid parameter types: ".str_replace(")(", ", ", $variables));
}
return true;
}
/**
* Service Call: getVersion
*
* @param mixed getVersion_soap (Soap request object)
* @return getVersionResponse_soap (Soap response object) or SoapFault if parameter are invalid
*/
public function getVersion($mixed = null) {
$this->logger->info("CoreApiService Soap call : getVersion");
$validParameters = array(
"(getVersion_soap)",
);
try {
$args = func_get_args();
$this->_checkArguments($args, $validParameters);
}
catch (Exception $e) {
// Invalid parameters => return a soap fault
return new SoapFault($e->getCode(),$e->getMessage());
}
$fusionforge = new FusionForge();
$response = new getVersionResponse_soap();
$response->version = $fusionforge->software_version;
return $response;
}
/**
* Service Call: getGroups
*
* @param mixed getGroups_soap (Soap request object)
* @return getGroupsResponse_soap (Soap response object) or SoapFault if parameters are invalid
*/
public function getGroups($mixed = null) {
$group_ids = $mixed->group_id;
$this->logger->info("CoreApiService Soap call : getGroups for group_id ".var_export($group_ids, true));
$validParameters = array(
"(getGroups_soap)",
);
try {
$args = func_get_args();
$this->_checkArguments($args, $validParameters);
}
catch (Exception $e) {
// Invalid parameters => return a soap fault
return new SoapFault($e->getCode(),$e->getMessage());
}
$grps = group_get_objects($group_ids);
if (!$grps) {
$this->logger->debug("Could Not Get Groups by Id");
return new soap_fault ('2001','group','Could Not Get Groups by Id'.$inputArgs,$feedback);
}
$response = new getGroupsResponse_soap();
$this->logger->debug((count($grps)+1)." Groups objects found");
for ($i=0; $i<count($grps); $i++) {
$group = new group_soap();
$group->group_id = $grps[$i]->data_array['group_id'];
$group->group_name=$grps[$i]->data_array['group_name'];
$group->homepage=$grps[$i]->data_array['homepage'];
$group->is_public=$grps[$i]->data_array['is_public'];
$group->status=$grps[$i]->data_array['status'];
$group->unix_group_name=$grps[$i]->data_array['unix_group_name'];
$group->short_description=$grps[$i]->data_array['short_description'];
$group->scm_box=$grps[$i]->data_array['scm_box'];
$group->register_time=$grps[$i]->data_array['register_time'];
$response->group[$i]=$group;
$this->logger->debug("Adding Group objects : ".var_export($group, true));
}
return $response;
}
/**
* Service Call: getUsers
*
* @param mixed getUsers_soap (Soap request object)
* @return getUsersResponse_soap (Soap response object) or SoapFault if parameters are invalid
*/
public function getUsers($mixed = null) {
$this->logger->debug("CoreApiService Soap call getUsers ".var_export($mixed, true));
// The $mixed->user_id is an array only if several user_id in the SOAP request
if (is_array($mixed->user_id)) {
$user_id = $mixed->user_id;
}
else {
$user_id = array(0=>$mixed->user_id);
}
$validParameters = array(
"(getUsers_soap)",
);
try {
$args = func_get_args();
$this->_checkArguments($args, $validParameters);
}
catch (Exception $e) {
// Invalid parameters => return a soap fault
return new SoapFault($e->getCode(),$e->getMessage());
}
$users = user_get_objects($user_id);
$this->logger->debug("users found : ".var_export($users, true));
if (!$users) {
return new SoapFault('3001','Could Not Get Users By Id');
}
$response = new getUsersResponse_soap();
for ($i=0; $i<count($users); $i++) {
if ($users[$i]->isError()){
//skip it if it had an error
} else {
//build each user_soap response
$user = new user_soap();
$user->user_id=$users[$i]->data_array['user_id'];
$user->user_name=$users[$i]->data_array['user_name'];
$user->title=$users[$i]->data_array['title'];
$user->firstname=$users[$i]->data_array['firstname'];
$user->lastname=$users[$i]->data_array['lastname'];
$user->address=$users[$i]->data_array['address'];
$user->address2=$users[$i]->data_array['address2'];
$user->phone=$users[$i]->data_array['phone'];
$user->fax=$users[$i]->data_array['fax'];
$user->status=$users[$i]->data_array['status'];
$user->timezone=$users[$i]->data_array['timezone'];
$user->country_code=$users[$i]->data_array['country_code'];
$user->add_date=$users[$i]->data_array['add_date'];
$user->language_id=$users[$i]->data_array['language_id'];
$response->user[$i]=$user;
}
}
return $response;
}
/**
* Service Call: getGroupsByName
*
* @param mixed getGroupsByName_soap (Soap request object)
* @return getGroupsByNameResponse_soap (Soap response object) or SoapFault if parameters are invalid
*/
public function getGroupsByName($mixed = null) {
$this->logger->debug("Soap call getGroupsByName ".var_export($mixed, true));
// The $mixed->group_name is an array only if several group_name in the SOAP request
if (is_array($mixed->group_name)) {
$group_names = $mixed->group_name;
}
else {
$group_names = array(0=>$mixed->group_name);
}
$validParameters = array(
"(getGroupsByName_soap)",
);
try {
$args = func_get_args();
$this->_checkArguments($args, $validParameters);
}
catch (Exception $e) {
// Invalid parameters => return a soap fault
return new SoapFault($e->getCode(),$e->getMessage());
}
$grps = group_get_objects_by_name($group_names);
if (!$grps) {
return new SoapFault('2002','Could Not Get Groups by Name');
}
$response = new getGroupsByNameResponse_soap();
// $grps contains an array of Group object
for ($i=0; $i<count($grps); $i++) {
if ($grps[$i]->isError()) {
//skip it if it had an error
} else {
//build each group_soap response
$group = new group_soap();
$group->group_id=$grps[$i]->data_array['group_id'];
$group->group_name=$grps[$i]->data_array['group_name'];
$group->homepage=$grps[$i]->data_array['homepage'];
$group->is_public=$grps[$i]->data_array['is_public'];
$group->status=$grps[$i]->data_array['status'];
$group->unix_group_name=$grps[$i]->data_array['unix_group_name'];
$group->short_description=$grps[$i]->data_array['short_description'];
$group->scm_box=$grps[$i]->data_array['scm_box'];
$group->register_time=$grps[$i]->data_array['register_time'];
$response->group[$i] = $group;
}
}
$this->logger->debug("getGroupsByNameResponse_soap : ".var_export($response, true));
return $response;
}
/**
* Service Call: getPublicProjectNames
*
* @param mixed getPublicProjectNames_soap (Soap request object)
* @return getPublicProjectNamesResponse_soap (Soap response object) or SoapFault if parameters are invalid
*/
public function getPublicProjectNames($mixed = null) {
$this->logger->debug("Soap call getPublicProjectNames");
$validParameters = array(
"(getPublicProjectNames_soap)",
);
try {
$args = func_get_args();
$this->_checkArguments($args, $validParameters);
}
catch (Exception $e) {
// Invalid parameters => return a soap fault
return new SoapFault($e->getCode(),$e->getMessage());
}
// SOAP Response
$response = new getPublicProjectNamesResponse_soap();
$forge = new FusionForge();
$response->project_name = $forge->getPublicProjectNames();
if ($forge->isError()) {
$errMsg = 'Could Not Get Public Group Names: '.$forge->getErrorMessage();
return new SoapFault('2003',$errMsg);
}
$this->logger->debug("Public Projects number found : ".var_export($response->project_name, true));
return $response;
}
/**
* Service Call: getUsersByName
*
* @param mixed getUsersByName_soap (Soap request object)
* @return getUsersByNameResponse_soap (Soap response object) or SoapFault if parameters are invalid
*/
public function getUsersByName($mixed = null) {
$this->logger->debug("CoreApiService Soap call getUsersByName ".var_export($mixed, true));
// The $mixed->group_name is an array only if several group_name in the SOAP request
if (is_array($mixed->user_name)) {
$user_names = $mixed->user_name;
}
else {
$user_names = array(0=>$mixed->user_name);
}
$validParameters = array(
"(getUsersByName_soap)",
);
try {
$args = func_get_args();
$this->_checkArguments($args, $validParameters);
}
catch (Exception $e) {
// Invalid parameters => return a soap fault
return new SoapFault($e->getCode(),$e->getMessage());
}
$users = user_get_objects_by_name($user_names);
if (!$users) {
return new SoapFault('3002','Could Not Get Users By Name');
}
$response = new getUsersByNameResponse_soap();
for ($i=0; $i<count($users); $i++) {
if ($users[$i]->isError()){
//skip it if it had an error
} else {
//build each user_soap response
$user = new user_soap();
$user->user_id=$users[$i]->data_array['user_id'];
$user->user_name=$users[$i]->data_array['user_name'];
$user->title=$users[$i]->data_array['title'];
$user->firstname=$users[$i]->data_array['firstname'];
$user->lastname=$users[$i]->data_array['lastname'];
$user->address=$users[$i]->data_array['address'];
$user->address2=$users[$i]->data_array['address2'];
$user->phone=$users[$i]->data_array['phone'];
$user->fax=$users[$i]->data_array['fax'];
$user->status=$users[$i]->data_array['status'];
$user->timezone=$users[$i]->data_array['timezone'];
$user->country_code=$users[$i]->data_array['country_code'];
$user->add_date=$users[$i]->data_array['add_date'];
$user->language_id=$users[$i]->data_array['language_id'];
$response->user[$i]=$user;
}
}
return $response;
}
/**
* Service Call: userGetGroups
*
* @param mixed userGetGroups_soap (Soap request object)
* @return userGetGroupsResponse_soap (Soap response object) or SoapFault if parameters are invalid
*/
public function userGetGroups($mixed = null) {
$this->logger->debug("CoreApiService Soap call : userGetGroups for user_id ".var_export($mixed, true));
$user_id = $mixed->user_id;
$validParameters = array(
"(userGetGroups_soap)",
);
try {
$args = func_get_args();
$this->_checkArguments($args, $validParameters);
}
catch (Exception $e) {
// Invalid parameters => return a soap fault
return new SoapFault($e->getCode(),$e->getMessage());
}
$user = user_get_object($user_id);
if (!$user) {
return new SoapFault('3003','Could Not Get Users Groups');
}
// $grps contains an array of Group object
$grps = $user->getGroups();
$this->logger->debug(count($grps). " groups found");
$response = new userGetGroupsResponse_soap();
for ($i=0; $i<count($grps); $i++) {
if ($grps[$i]->isError()) {
//skip it if it had an error
} else {
//build each group_soap response
$group = new group_soap();
$group->group_id=$grps[$i]->data_array['group_id'];
$group->group_name=$grps[$i]->data_array['group_name'];
$group->homepage=$grps[$i]->data_array['homepage'];
$group->is_public=$grps[$i]->data_array['is_public'];
$group->status=$grps[$i]->data_array['status'];
$group->unix_group_name=$grps[$i]->data_array['unix_group_name'];
$group->short_description=$grps[$i]->data_array['short_description'];
$group->scm_box=$grps[$i]->data_array['scm_box'];
$group->register_time=$grps[$i]->data_array['register_time'];
$response->group[$i] = $group;
$this->logger->debug("adding group : ".var_export($group, true));
}
}
$this->logger->debug("userGetGroupsResponse_soap : ".var_export($response, true));
return $response;
}
/**
* Service Call: getSCMData
*
* @param mixed getSCMData_soap (Soap request object)
* @return getSCMDataResponse_soap (Soap response object) or SoapFault if parameters are invalid
*/
public function getSCMData($mixed = null) {
$group_id = $mixed->group_id;
$this->logger->debug("Soap call : getSCMData for group_id ".$group_id);
$validParameters = array(
"(getSCMData_soap)",
);
try {
$args = func_get_args();
$this->_checkArguments($args, $validParameters);
}
catch (Exception $e) {
// Invalid parameters => return a soap fault
return new SoapFault($e->getCode(),$e->getMessage());
}
// Search the group object in the database
$grp = group_get_object($group_id);
$this->logger->debug("group_get_object : ".var_export($grp, true));
// Error handle
if (!$grp || !is_object($grp)) {
$this->logger->error("Returning SOAP Fault - Could Not Get Group : ".$group_id);
// TODO : Error code to be determined
return new SoapFault('-1', 'Could Not Get Group');
} elseif ($grp->isError()) {
$this->logger->error($grp->getErrorMessage()." for group_id : ".$group_id);
// TODO : Error code to be determined
return new SoapFault ('-1',$grp->getErrorMessage());
}
if (!$grp->usesSCM()) {
$this->logger->error('SCM is not enabled in this project ; group_id : '.$group_id);
// TODO : Error code to be determined
return new SoapFault ('-1','SCM is not enabled in this project');
}
// Create the SOAP response
$response = new getSCMDataResponse_soap();
$scm_data = new scmData_soap();
if ($grp->usesPlugin("scmcvs")) {
$scm_data->type = "CVS";
$scm_data->allow_anonymous = $grp->enableAnonSCM();
$scm_data->public = $grp->enablePserver();
$scm_data->box = $grp->getSCMBox();
$scm_data->module = $grp->getUnixName();
$scm_data->connection_string = ""; // this doesn't apply to CVS
// Note: This was taken from CVS plugin. Maybe we shouldn't hardcode this?
$scm_data->root = "/cvsroot/".$grp->getUnixName();
} elseif ($grp->usesPlugin("scmsvn")) {
$scm_data->type = "SVN";
$scm_data->allow_anonymous = $grp->enableAnonSCM();
$scm_data->public = $grp->enablePserver();
$scm_data->box = $grp->getSCMBox();
$scm_data->root = $GLOBALS["svn_root"]."/".$grp->getUnixName();
$scm_data->module = ""; // doesn't apply to SVN
// Note: This is an ugly hack. We can't access SVN plugin object for this project
// directly. Currently this is being rewritten, but for now we must make this.
//TODO How to have access to $gfconfig variable ??
include $gfconfig.'plugins/scmsvn/config.php';
$scm_data->connection_string = "http".(($use_ssl) ? "s" : "")."://".$grp->getSCMBox()."/".$svn_root."/".$grp->getUnixName();
}
$response->scm_data= $scm_data;
return $response;
}
}
|