Esempio n. 1
0
 /**
  * Returns List of entities changed after certain time.
  * @param array entityList List of entity.
  * @param long changedSince DateTime of timespan after which entities were changed.
  * @return IntuitCDCResponse Returns an IntuitCDCResponse.
  */
 public function CDC($entityList, $changedSince)
 {
     $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Called Method CDC.");
     // Validate parameter
     if (count($entityList) <= 0) {
         $exception = new IdsException('ParameterNotNullMessage');
         $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Error, "ParameterNotNullMessage");
         IdsExceptionManager::HandleException($exception);
     }
     $entityString = implode(",", $entityList);
     $query = NULL;
     $uri = NULL;
     $formattedChangedSince = date("Y-m-d\\TH:m:sP", $this->verifyChangedSince($changedSince));
     $query = "entities=" . $entityString . "&changedSince=" . $formattedChangedSince;
     $uri = "company/{1}/cdc?{2}";
     //$uri = str_replace("{0}", CoreConstants::VERSION, $uri);
     $uri = str_replace("{1}", $this->serviceContext->realmId, $uri);
     $uri = str_replace("{2}", $query, $uri);
     // Creates request parameters
     $requestParameters = $this->getGetRequestParameters($uri, CoreConstants::CONTENTTYPE_APPLICATIONXML);
     $restRequestHandler = new SyncRestHandler($this->serviceContext);
     try {
         // gets response
         list($responseCode, $responseBody) = $restRequestHandler->GetResponse($requestParameters, NULL, NULL);
     } catch (Exception $e) {
     }
     CoreHelper::CheckNullResponseAndThrowException($responseBody);
     $returnValue = new IntuitCDCResponse();
     try {
         $xmlObj = simplexml_load_string($responseBody);
         foreach ($xmlObj->CDCResponse->QueryResponse as $oneObj) {
             $entities = $this->responseSerializer->Deserialize($oneObj->asXML(), FALSE);
             $entityName = NULL;
             foreach ($oneObj->children() as $oneObjChild) {
                 $entityName = (string) $oneObjChild->getName();
                 break;
             }
             $returnValue->entities[$entityName] = $entities;
         }
     } catch (Exception $e) {
         IdsExceptionManager::HandleException($e);
     }
     $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Finished Executing Method CDC.");
     return $returnValue;
 }
 /**
  * This method executes the batch request.
  */
 public function Execute()
 {
     $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Started Executing Method Execute for Batch");
     // Create Intuit Batch Request
     $intuitBatchRequest = new IPPIntuitBatchRequest();
     $intuitBatchRequest->BatchItemRequest = $this->batchRequests;
     $uri = "company/{1}/batch?requestid=" . rand() . rand();
     $uri = str_replace('{1}', $this->serviceContext->realmId, $uri);
     // Creates request parameters
     $requestParameters = NULL;
     if (0) {
         // No JSON support here yet
         //$requestParameters = new RequestParameters($uri, 'POST', CoreConstants::CONTENTTYPE_APPLICATIONJSON, NULL);
     } else {
         $requestParameters = new RequestParameters($uri, 'POST', CoreConstants::CONTENTTYPE_APPLICATIONXML, NULL);
     }
     $restRequestHandler = new SyncRestHandler($this->serviceContext);
     try {
         // Get literal XML representation of IntuitBatchRequest into a DOMDocument
         $httpsPostBodyPreProcessed = XmlObjectSerializer::getPostXmlFromArbitraryEntity($intuitBatchRequest, $urlResource);
         $doc = new DOMDocument();
         $domObj = $doc->loadXML($httpsPostBodyPreProcessed);
         $xpath = new DOMXpath($doc);
         // Replace generically-named IntuitObject nodes with tags that describe contained objects
         $objectIndex = 0;
         while (1) {
             $matchingElementArray = $xpath->query("//IntuitObject");
             if (is_null($matchingElementArray)) {
                 break;
             }
             if ($objectIndex >= count($intuitBatchRequest->BatchItemRequest)) {
                 break;
             }
             foreach ($matchingElementArray as $oneNode) {
                 // Found a DOMNode currently named "IntuitObject".  Need to rename to
                 // entity that describes it's contents, like "ns0:Customer" (determine correct
                 // name by inspecting IntuitObject's class).
                 if ($intuitBatchRequest->BatchItemRequest[$objectIndex]->IntuitObject) {
                     // Determine entity name to use
                     $entityClassName = get_class($intuitBatchRequest->BatchItemRequest[$objectIndex]->IntuitObject);
                     $entityTransferName = XmlObjectSerializer::cleanPhpClassNameToIntuitEntityName($entityClassName);
                     $entityTransferName = 'ns0:' . $entityTransferName;
                     // Replace old-named DOMNode with new-named DOMNode
                     $newNode = $oneNode->ownerDocument->createElement($entityTransferName);
                     if ($oneNode->attributes->length) {
                         foreach ($oneNode->attributes as $attribute) {
                             $newNode->setAttribute($attribute->nodeName, $attribute->nodeValue);
                         }
                     }
                     while ($oneNode->firstChild) {
                         $newNode->appendChild($oneNode->firstChild);
                     }
                     $oneNode->parentNode->replaceChild($newNode, $oneNode);
                 }
                 break;
             }
             $objectIndex++;
         }
         $httpsPostBody = $doc->saveXML();
         list($responseCode, $responseBody, $responseError) = $restRequestHandler->GetResponse($requestParameters, $httpsPostBody, NULL);
     } catch (Exception $e) {
         IdsExceptionManager::HandleException($e);
     }
     CoreHelper::CheckResponseErrorAndThrowException($this->serviceContext, $responseError);
     CoreHelper::CheckNullResponseAndThrowException($responseBody);
     try {
         $this->batchResponses = array();
         $this->intuitBatchItemResponses = array();
         // No JSON support here yet
         // de serialize object
         $responseXmlObj = simplexml_load_string($responseBody);
         foreach ($responseXmlObj as $oneXmlObj) {
             // process batch item
             $intuitBatchResponse = $this->ProcessBatchItemResponse($oneXmlObj);
             $this->intuitBatchItemResponses[] = $intuitBatchResponse;
             if ($intuitBatchResponse && $intuitBatchResponse->entities && count($intuitBatchResponse->entities)) {
                 $this->batchResponses[] = $intuitBatchResponse->entities;
             }
         }
     } catch (Exception $e) {
         return NULL;
     }
     $this->serviceContext->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Finished Execute method for batch.");
 }