You are here

private function GLExchange::_setConnectionConfig in GlobalLink Connect for Drupal 7.7

* * Set/update Project Director connection configuration * *

Parameters

* $connectionConfig: * PDConfig - Project Director Connection Configuration * @throws Exception

1 call to GLExchange::_setConnectionConfig()
GLExchange::__construct in gl_ws/glc/GLExchange.php
* * Initialize Project Director connector * *

File

gl_ws/glc/GLExchange.php, line 50

Class

GLExchange

Code

private function _setConnectionConfig(\PDConfig $connectionConfig) {
  $this->pdConfig = $connectionConfig;
  if (!isset($this->pdConfig->url)) {
    throw new Exception("Invalid URL");
  }
  if (!isset($this->pdConfig->username)) {
    throw new Exception("Invalid username");
  }
  if (!isset($this->pdConfig->password)) {
    throw new Exception("Invalid Password");
  }
  if (!isset($this->pdConfig->userAgent)) {
    throw new Exception("Invalid User Agent");
  }
  $proxyConfig = array();
  if (isset($connectionConfig->proxyConfig)) {
    $proxyConfig = array(
      'proxy_host' => $connectionConfig->proxyConfig->proxyHost,
      'proxy_port' => $connectionConfig->proxyConfig->proxyPort,
      'proxy_login' => $connectionConfig->proxyConfig->proxyUser,
      'proxy_password' => $connectionConfig->proxyConfig->proxyPassword,
    );
  }
  $security = '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">' . '<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">' . '<wsse:Username>' . $this->pdConfig->username . '</wsse:Username>' . '<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' . $this->pdConfig->password . '</wsse:Password>' . '</wsse:UsernameToken></wsse:Security>';
  $userAgent = '<commons:userAgent xmlns:commons="http://commons.ws.projectdirector.gs4tr.org">' . $this->pdConfig->userAgent . '</commons:userAgent>';
  $header = array();
  $header[] = new SoapHeader("Security", 'Security', new SoapVar($security, XSD_ANYXML), true);
  $header[] = new SoapHeader("userAgent", 'userAgent', new SoapVar($userAgent, XSD_ANYXML), true);
  $this->projectService = new ProjectService_4180(PROJECT_SERVICE_WSDL, array_merge(array(
    'location' => $this->pdConfig->url . '/services/ProjectService_4180',
  ), $proxyConfig), $header);
  $this->submissionService = new SubmissionService_4180(SUBMISSION_SERVICE_WSDL, array_merge(array(
    'location' => $this->pdConfig->url . '/services/SubmissionService_4180',
  ), $proxyConfig), $header);
  $this->workflowService = new WorkflowService_4180(WORKFLOW_SERVICE_WSDL, array_merge(array(
    'location' => $this->pdConfig->url . '/services/WorkflowService_4180',
  ), $proxyConfig), $header);
  $this->targetService = new TargetService_4180(TARGET_SERVICE_WSDL, array_merge(array(
    'location' => $this->pdConfig->url . '/services/TargetService_4180',
  ), $proxyConfig), $header);
  $this->documentService = new DocumentService_4180(DOCUMENT_SERVICE_WSDL, array_merge(array(
    'location' => $this->pdConfig->url . '/services/DocumentService_4180',
  ), $proxyConfig), $header);
  $this->userProfileService = new UserProfileService_4180(USER_PROFILE_SERVICE_WSDL, array_merge(array(
    'location' => $this->pdConfig->url . '/services/UserProfileService_4180',
  ), $proxyConfig), $header);
  try {
    $getUserProjectsRequest = new getUserProjects();
    $getUserProjectsRequest->isSubProjectIncluded = TRUE;
    $projects = $this->projectService
      ->getUserProjects($getUserProjectsRequest)->return;
  } catch (Exception $ex) {
    throw new Exception("Invalid config");
  }
}