Exemple #1
0
 /**
  * To handle the HttpResponse object of a HttpRequest POST request in
  * non-batching mode. This function will invoke ObjectContext::AttachLocation
  * which uses the value of HttpHeader with key 'Location' to set the Identity
  * and EditLink of current entry (ResourceBox) under process. Also populate the
  * entity instance with OData service returned values.
  *
  * @param HttpResponse $httpResponse
  */
 protected function HandleOperationResponse($httpResponse)
 {
     $resourceBox = $this->_changedEntries[$this->_entryIndex];
     if ($resourceBox->IsResource()) {
         $headers = $httpResponse->getHeaders();
         //Handle the POST Operation Response.
         //SDK will fire POST operation in three cases
         //1. AddLink [we will skip this case]
         //2. AddObject [$resourceBox->State == EntityStates::Added]
         //3. SetSaveStream on an entity which is just added using AddObject
         //   In this case the CheckAndProcessMediaEntryPost will set the state
         //   of the object to Modified.
         //   [($resourceBox->State == EntityStates::Modified) &&
         //      $this->_processingMediaLinkEntry) &&
         //     !$this->_processingMediaLinkEntryPut)]
         if ($resourceBox->State == EntityStates::Added || $resourceBox->State == EntityStates::Modified && $this->_processingMediaLinkEntry && !$this->_processingMediaLinkEntryPut) {
             $resourceBox->EntityETag = AtomParser::GetEntityEtag($httpResponse->getBody());
             $location = isset($headers[HttpRequestHeader::Location]) ? $headers[HttpRequestHeader::Location] : null;
             if ($httpResponse->isSuccessful()) {
                 if ($location == null) {
                     throw new ODataServiceException(Resource::NoLocationHeader, '', array(), null);
                 }
                 $this->_context->AttachLocation($resourceBox->getResource(), $location);
                 if ($resourceBox->State == EntityStates::Added) {
                     $atomEntry = null;
                     AtomParser::PopulateObject($httpResponse->getBody(), $resourceBox->getResource(), $uri, $atomEntry);
                 } else {
                     //After the POST operation for a media, state of corrosponding entity will be
                     //updated to Modified [earlier it will be Added] in CheckAndProcessMediaEntryPost
                     //function. So next will be a MERGE request, while generating body for this
                     //MERGE operation, the function CreateChangeSetBodyForResource will throw error
                     //if any of the Key field is null. So update the Key fields.
                     AtomParser::PopulateMediaEntryKeyFields($httpResponse->getBody(), $resourceBox->getResource());
                 }
             }
         }
         if ($this->_processingMediaLinkEntry && !$httpResponse->isSuccessful()) {
             $this->_processingMediaLinkEntry = false;
             if ($this->_processingMediaLinkEntryPut) {
                 $resourceBox->State = EntityStates::Added;
                 $this->_processingMediaLinkEntryPut = false;
             }
         }
     }
 }
Exemple #2
0
 /**
  * To update the $resourceBox::Source object by parsing the atom XML in $str.
  * [Note: Do not call this function from your application, it is used internally]
  *
  * @param string $str
  * @param ResourceBox $resourceBox
  * @param string $content_type
  */
 public function LoadResourceBox($str, $resourceBox, $content_type)
 {
     $resource = $resourceBox->GetResource();
     $uri = null;
     $atomEntry = null;
     AtomParser::PopulateObject($str, $resource, $uri, $atomEntry);
     if (isset($uri)) {
         $index = Utility::reverseFind($uri, '/');
         $editLink = substr($uri, $index + 1, strlen($uri) - $index);
         $resourceBox->Identity = $uri;
         $resourceBox->EditLink = $editLink;
     }
     //If $str represents content of entry of type Media then
     //popluate values specific to media entry
     $resourceBox->EditMediaLink = $atomEntry->EditMediaLink;
     $resourceBox->MediaLinkEntry = $atomEntry->MediaLinkEntry;
     $resourceBox->StreamETag = $atomEntry->StreamETag;
     $resourceBox->EntityETag = $atomEntry->EntityETag;
     $resourceBox->StreamLink = $atomEntry->MediaContentUri;
 }