Ejemplo n.º 1
0
 /**
  *
  * Insert/Update an Policy on the database
  * @param Policy $policy
  * @throws Exception
  */
 private function _setPolicy(Policy &$policy, $insertMode = FALSE)
 {
     $method = "PUT";
     $url = E3_PROV_URL_POLICY . "/" . rawurlencode($policy->getId());
     if ($insertMode) {
         $method = "POST";
         $url = E3_PROV_URL_POLICY;
     }
     /**
      * Send the XML payload the the Provisioning Backend
      */
     LoggerInterface::log(($insertMode ? "Creating" : "Updating") . " Policy: {$policy->toXML()}\nEndpoint: ({$method}) {$url}", LoggerInterface::INFO);
     $reply = $this->restClient->makeCall($url, $method, $policy->toXML());
     $xml = simplexml_load_string($reply->getPayload());
     if ($reply->getHTTPCode() === "200") {
         if ($insertMode) {
             if ($policy->getId() == NULL) {
                 $policy->setId((string) $xml->id);
             }
         }
         return true;
     } else {
         $error = $insertMode ? "Unable to create policy" : "Unable to update policy with id: " . $policy->getId();
         // default error msg
         if ($xml != null) {
             $errorText = $xml->xpath('/response/error/errorText');
             // error msg from response
             if (count($errorText) > 0) {
                 $error = (string) $errorText[0];
             }
         }
         PolicyManager::error($error);
         return false;
     }
 }