public function run()
 {
     $offset = 0;
     $queue = new Datasource_Insurance_Document_InsuranceRequest();
     $history = new Datasource_Insurance_Document_InsuranceRequestHistory();
     $templates = new Datasource_Insurance_Document_InsuranceTemplates();
     // Authenticate with document production server
     $this->_remoteServerAuthentication();
     while ($request = $queue->retrieveNextRequest($offset)) {
         //error_log('request id: ' . $request['request_id']);
         $this->httpclient->resetParameters();
         $this->httpclient->setParameterPost(array('PHPSESSID' => $this->sessionid, 'action' => 'ComposeDoc', 'CustomerCode' => $this->customercode, 'DocTypeName' => $templates->getTemplateName($request['template_id']), 'VarDocData' => base64_encode($request['request_xml'])));
         try {
             $response = $this->httpclient->request('POST');
         } catch (Zend_Http_Client_Exception $ex) {
             error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage());
             $offset++;
             continue;
         }
         $this->_debugRequest($this->httpclient);
         if (is_string($response)) {
             $response = Zend_Http_Response::fromString($response);
         } else {
             if (!$response instanceof Zend_Http_Response) {
                 // Some other response returned, don't know how to process.
                 // The request is queued, so return a fault.
                 error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage());
                 $offset++;
                 continue;
             }
         }
         try {
             $response = $response->getBody();
             $createresponse = Zend_Json::decode($response);
         } catch (Exception $ex) {
             // Problem requesting service, report the problem back but keep the queue record
             error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage());
             $offset++;
             continue;
         }
         // Check login response
         if ($createresponse == null) {
             // Problem requesting document generation with DMS server
             error_log(__FILE__ . ':' . __LINE__ . ':Failed to request document generation from DMS server for request');
             $offset++;
             continue;
         }
         // Check create response
         if ($createresponse['Status'] != 'DocComp_OK' && $createresponse['Status'] != 'DocComp_WRN') {
             // Problem creating document. Report failure but keep the queue record
             error_log(__FILE__ . ':' . __LINE__ . ':Failed to request document generation from DMS server for request: ' . $createresponse['MsgID'] . ':' . $createresponse['MsgText']);
             // Failed to generate document, skip to next docment
             $offset++;
             continue;
         }
         // Move the queue record from the queue table into the history table
         try {
             // Insert into history
             $history->storeQueueRecord($request);
             // Delete previous request
             $queue->deleteRequest($request['request_hash']);
         } catch (Zend_Db_Exception $ex) {
             error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage());
             throw new Exception('Failed to move document request to history');
         }
     }
 }
示例#2
0
 /**
  * Build the XML structure to be sent to DMS solution
  *
  * @param string $policynumber Document policy number
  * @param $documentname
  * @param $csuid
  * @param string $deliverymethod Delivery method required, print, email, fax or none
  * @param string $deliverytarget Target for delivery on email and fax based delivery methods
  * @param string $bucketname Bucket for determining the print bucket override
  * @param string $emailCatTarget Email category target
  * @param string $emailCat Email category
  * @param $documentDelivery
  * @param array $referencefields List of reference fields
  * @param array $properties List of properties
  * @param array $variables List of variables
  * @param null $policycovers
  * @param null $endorsements
  * @param null $pedalcycles
  * @param null $specpossessions
  * @param null $underwritingquestions
  * @param null $propertydetails
  * @param null $inserts
  * @throws Application_Soap_Fault
  * @internal param string $documenttype Document type name, or template name
  * @return array XML string, generated unique reference number
  */
 private function _createAndStoreRequest($policynumber, $documentname, $csuid, $deliverymethod, $deliverytarget, $bucketname, $emailCatTarget, $emailCat, $documentDelivery, $referencefields, $properties = null, $variables = null, $policycovers = null, $endorsements = null, $pedalcycles = null, $specpossessions = null, $underwritingquestions = null, $propertydetails = null, $inserts = null)
 {
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->preserveWhiteSpace = true;
     $doc->formatOutput = true;
     // Create root element
     $root = $doc->createElementNS('urn:HomeLetDMSTypes', 'hl:documentRequest');
     $doc->appendChild($root);
     // Create basic data
     $uniquerequestnode = $doc->createElement('hl:uniqueRequestID');
     $root->appendChild($doc->createElement('hl:documentType', $this->_encodechars($documentname)));
     $root->appendChild($uniquerequestnode);
     $root->appendChild($doc->createElement('hl:deliveryMethod', $this->_encodechars($deliverymethod)));
     $root->appendChild($doc->createElement('hl:deliveryTarget', $this->_encodechars($deliverytarget)));
     $root->appendChild($doc->createElement('hl:BucketOverride', $this->_encodechars($bucketname)));
     $root->appendChild($doc->createElement('hl:policyNumber', $this->_encodechars($policynumber)));
     $root->appendChild($doc->createElement('hl:requestTimestamp', gmdate("l dS \\of F Y h:i:s.u A")));
     // Adds some entropy to the message
     // Add reference field agentSchemeNumber
     if ($referencefields !== null && is_a($referencefields, 'stdClass') && isset($referencefields->agentSchemeNumber) && $referencefields->agentSchemeNumber !== null) {
         # Add properties if found
         $root->appendChild($doc->createElement('hl:agentSchemeNumber', $this->_encodechars($referencefields->agentSchemeNumber)));
     } else {
         # Missing reference fields, fail with fault
         error_log(__FILE__ . ':' . __LINE__ . ':Missing reference field agentSchemeNumber in SOAP request; cannot proceed');
         throw new Application_Soap_Fault('Missing reference field agentSchemeNumber', 'Server');
     }
     // Add reference field targetPostcode
     if ($referencefields !== null && is_a($referencefields, 'stdClass') && isset($referencefields->targetPostcode) && $referencefields->targetPostcode !== null) {
         # Add properties if found
         $root->appendChild($doc->createElement('hl:targetPostcode', $this->_encodechars(strtoupper($referencefields->targetPostcode))));
     } else {
         # Missing reference fields, fail with fault
         error_log(__FILE__ . ':' . __LINE__ . ':Missing reference field targetPostcode in SOAP request; cannot proceed');
         throw new Application_Soap_Fault('Missing reference field targetPostcode', 'Server');
     }
     // Add cat target & cat name
     $root->appendChild($doc->createElement('hl:emailCategoryTarget', $this->_encodechars($emailCatTarget)));
     $root->appendChild($doc->createElement('hl:emailCategory', $this->_encodechars($emailCat)));
     $root->appendChild($doc->createElement('hl:documentDelivery', $this->_encodechars($documentDelivery)));
     // Add list of properties
     $proplistnode = $root->appendChild($doc->createElement('hl:properties'));
     if ($properties !== null && is_a($properties, 'stdClass') && isset($properties->property) && $properties->property !== null) {
         foreach ($properties->property as $property) {
             $propnode = $proplistnode->appendChild($doc->createElement('hl:property'));
             $propnode->appendChild($doc->createElement('hl:name', $this->_encodechars($property->name)));
             $propnode->appendChild($doc->createElement('hl:value', $this->_encodechars($property->value)));
         }
     }
     // Add list of variables
     $varlistnode = $root->appendChild($doc->createElement('hl:variables'));
     if ($variables !== null && is_a($variables, 'stdClass') && isset($variables->variable) && $variables->variable !== null) {
         foreach ($variables->variable as $variable) {
             $varnode = $varlistnode->appendChild($doc->createElement('hl:variable'));
             $varnode->appendChild($doc->createElement('hl:name', $this->_encodechars($variable->name)));
             $varnode->appendChild($doc->createElement('hl:value', $this->_encodechars($variable->value)));
         }
         // Add specific document retrieval url
         if ($emailCatTarget == 'AGENT') {
             $config = Zend_Registry::get('params');
             $connectUrl = $config->connectUrl->connectRootUrl . '/insurance/show-policy?policyno=' . $policynumber;
             $varnode = $varlistnode->appendChild($doc->createElement('hl:variable'));
             $varnode->appendChild($doc->createElement('hl:name', $this->_encodechars('customer-portal-url')));
             $varnode->appendChild($doc->createElement('hl:value', $this->_encodechars($connectUrl)));
         } elseif ($emailCatTarget == 'LANDLORD' || $emailCatTarget == 'TENANT') {
             $config = Zend_Registry::get('params');
             if (preg_match('/^Q/', $policynumber)) {
                 $portalUrl = $config->homelet->domain . '/my-homelet/quotes?id=' . $policynumber;
             } else {
                 $portalUrl = $config->homelet->domain . '/my-homelet/policies?id=' . $policynumber;
             }
             $varnode = $varlistnode->appendChild($doc->createElement('hl:variable'));
             $varnode->appendChild($doc->createElement('hl:name', $this->_encodechars('customer-portal-url')));
             $varnode->appendChild($doc->createElement('hl:value', $this->_encodechars($portalUrl)));
         }
     }
     // policy covers
     $coverlistnode = $root->appendChild($doc->createElement('hl:policycovers'));
     if ($policycovers !== null && is_a($policycovers, 'stdClass') && isset($policycovers->policycover) && $policycovers->policycover !== null) {
         foreach ($policycovers->policycover as $policycover) {
             $covernode = $coverlistnode->appendChild($doc->createElement('hl:policycover'));
             $covernode->appendChild($doc->createElement('hl:cover', $this->_encodechars($policycover->cover)));
             $covernode->appendChild($doc->createElement('hl:suminsured', $this->_encodechars($policycover->suminsured)));
             $covernode->appendChild($doc->createElement('hl:excess', $this->_encodechars($policycover->excess)));
             $covernode->appendChild($doc->createElement('hl:monthlypremium', $this->_encodechars($policycover->monthlypremium)));
             $covernode->appendChild($doc->createElement('hl:annualpremium', $this->_encodechars($policycover->annualpremium)));
             $covernode->appendChild($doc->createElement('hl:presentation', $this->_encodechars($policycover->presentation)));
             $covernode->appendChild($doc->createElement('hl:bulleted', $this->_encodechars($policycover->bulleted)));
         }
     }
     // endorsements
     $endorsementlistnode = $root->appendChild($doc->createElement('hl:endorsements'));
     if ($endorsements !== null && is_a($endorsements, 'stdClass') && isset($endorsements->endorsement) && $endorsements->endorsement !== null) {
         foreach ($endorsements->endorsement as $endorsement) {
             $endorsementnode = $endorsementlistnode->appendChild($doc->createElement('hl:endorsement'));
             $endorsementnode->appendChild($doc->createElement('hl:name', 'Endorsement ' . $this->_encodechars($endorsement->endorsement)));
             if ($endorsement->effectivedate !== '0000-00-00') {
                 // dont send if no effective date
                 $endorsementnode->appendChild($doc->createElement('hl:effective-date', $this->_encodechars($endorsement->effectivedate)));
             }
             $endorsementnode->appendChild($doc->createElement('hl:excess', $this->_encodechars($endorsement->excess)));
         }
     }
     // pedal cycles
     $pedalcyclelistnode = $root->appendChild($doc->createElement('hl:pedalcycles'));
     if ($pedalcycles !== null && is_a($pedalcycles, 'stdClass') && isset($pedalcycles->pedalcycle) && $pedalcycles->pedalcycle !== null) {
         foreach ($pedalcycles->pedalcycle as $pedalcycle) {
             $pedalcyclenode = $pedalcyclelistnode->appendChild($doc->createElement('hl:pedalcycle'));
             $pedalcyclenode->appendChild($doc->createElement('hl:make', $this->_encodechars($pedalcycle->make)));
             $pedalcyclenode->appendChild($doc->createElement('hl:model', $this->_encodechars($pedalcycle->model)));
             $pedalcyclenode->appendChild($doc->createElement('hl:serialno', $this->_encodechars($pedalcycle->serialno)));
             $pedalcyclenode->appendChild($doc->createElement('hl:value', $this->_encodechars($pedalcycle->value)));
         }
     }
     // specified possessions
     $specpossessionslistnode = $root->appendChild($doc->createElement('hl:specpossessions'));
     if ($specpossessions !== null && is_a($specpossessions, 'stdClass') && isset($specpossessions->specpossession) && $specpossessions->specpossession !== null) {
         foreach ($specpossessions->specpossession as $specpossession) {
             $specpossessionsnode = $specpossessionslistnode->appendChild($doc->createElement('hl:specpossession'));
             $specpossessionsnode->appendChild($doc->createElement('hl:description', $this->_encodechars($specpossession->description)));
             $specpossessionsnode->appendChild($doc->createElement('hl:value', $this->_encodechars($specpossession->value)));
             $specpossessionsnode->appendChild($doc->createElement('hl:confirmed', $this->_encodechars($specpossession->confirmed)));
         }
     }
     // underwriting questions
     $underwritingquestionlistnode = $root->appendChild($doc->createElement('hl:underwritingquestions'));
     if ($underwritingquestions !== null && is_a($underwritingquestions, 'stdClass') && isset($underwritingquestions->underwritingquestion) && $underwritingquestions->underwritingquestion !== null) {
         foreach ($underwritingquestions->underwritingquestion as $underwritingquestion) {
             $underwritingquestionnode = $underwritingquestionlistnode->appendChild($doc->createElement('hl:underwritingquestion'));
             $underwritingquestionnode->appendChild($doc->createElement('hl:question', $this->_encodechars($underwritingquestion->question)));
             $underwritingquestionnode->appendChild($doc->createElement('hl:answer', $this->_encodechars($underwritingquestion->answer)));
         }
     }
     // property details
     $propertydetailslistnode = $root->appendChild($doc->createElement('hl:propertydetails'));
     if ($propertydetails !== null && is_a($propertydetails, 'stdClass') && isset($propertydetails->propertydetail) && $propertydetails->propertydetail !== null) {
         foreach ($propertydetails->propertydetail as $propertydetail) {
             $propertydetailnode = $propertydetailslistnode->appendChild($doc->createElement('hl:propertydetail'));
             $propertydetailnode->appendChild($doc->createElement('hl:detail', $this->_encodechars($propertydetail->detail)));
             $propertydetailnode->appendChild($doc->createElement('hl:value', $this->_encodechars($propertydetail->value)));
         }
     }
     // Add list of inserts
     $insertlistnode = $root->appendChild($doc->createElement('hl:inserts'));
     if ($inserts !== null && is_a($inserts, 'stdClass') && isset($inserts->insert) && $inserts->insert !== null) {
         foreach ($inserts->insert as $insert) {
             $insertnode = $insertlistnode->appendChild($doc->createElement('hl:insert'));
             $insertnode->setAttribute('name', $this->_encodechars($insert->name));
             $insertnode->setAttribute('burst', $insert->burst === 1 ? 1 : 0);
         }
     }
     // Generate unique request hash and insert into XML
     $uniquerequestid = strtoupper(hash('sha256', $doc->saveXML()));
     // force upper case for Fastant's benefit
     $uniquerequestnode->appendChild(new DOMText($uniquerequestid));
     $xml = $doc->saveXML();
     // Get request method id
     $reqmethod = new Datasource_Insurance_Document_InsuranceRequestMethods();
     try {
         $deliverymethodid = $reqmethod->getRequestMethodId($deliverymethod);
     } catch (Zend_Db_Exception $ex) {
         error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage());
         throw new Application_Soap_Fault('Failed to get request method id', 'Server');
     }
     // Get Print Bucket override id
     $bucket = new Datasource_Insurance_Document_InsurancePrintBuckets();
     try {
         if ($bucketname) {
             $bucketid = $bucket->getBucketId($bucketname);
         } else {
             $bucketid = 0;
         }
     } catch (Zend_Db_Exception $ex) {
         error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage());
         throw new Application_Soap_Fault('Failed to get print bucket id', 'Server');
     }
     // Fetch the document template id
     $templates = new Datasource_Insurance_Document_InsuranceTemplates();
     try {
         $templateid = $templates->getTemplateId($documentname);
         if (!isset($templateid)) {
             // Failed to fetch template id
             throw new Application_Soap_Fault('Failed to fetch template Id', 'Server');
         }
     } catch (Zend_Db_Exception $ex) {
         error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage());
         throw new Application_Soap_Fault('Failed to fetch template Id', 'Server');
     }
     // Store the request record
     $xmlstore = new Datasource_Insurance_Document_InsuranceRequest();
     try {
         if ($xmlstore->storeRequest($policynumber, $templateid, $csuid, $deliverymethodid, $deliverytarget, $uniquerequestid, $xml) === false) {
             // Failed to store request, return failure to client
             throw new Application_Soap_Fault('Failed to start document request record', 'Server');
         }
     } catch (Zend_Db_Exception $ex) {
         error_log(__FILE__ . ':' . __LINE__ . ':' . $ex->getMessage());
         throw new Application_Soap_Fault('Failed to start document request record', 'Server');
     }
     return array($xml, $uniquerequestid);
 }