protected function doDispatch(KalturaBatchJob $job, KalturaIntegrationJobData &$data, KalturaCielo24JobProviderData $providerData)
 {
     $entryId = $providerData->entryId;
     $flavorAssetId = $providerData->flavorAssetId;
     $spokenLanguage = $providerData->spokenLanguage;
     $priority = $providerData->priority;
     $fidelity = $providerData->fidelity;
     $formatsString = $providerData->captionAssetFormats;
     $formatsArray = explode(',', $formatsString);
     $shouldReplaceRemoteMedia = $providerData->replaceMediaContent;
     $callBackUrl = $data->callbackNotificationUrl;
     KalturaLog::debug('callback is - ' . $callBackUrl);
     $this->clientHelper = Cielo24Plugin::getClientHelper($providerData->username, $providerData->password);
     //setting a pre-defined name to prevent the flavor-url to contain chars that will break the curl url syntax
     $nameOptions = new KalturaFlavorAssetUrlOptions();
     $nameOptions->fileName = self::GET_URL_FILE_NAME;
     $flavorUrl = KBatchBase::$kClient->flavorAsset->getUrl($flavorAssetId, null, null, $nameOptions);
     $remoteJobId = $this->clientHelper->getRemoteFinishedJobId($entryId);
     if (!$remoteJobId) {
         $uploadSuccess = $this->clientHelper->uploadMedia($flavorUrl, $entryId, $callBackUrl, $spokenLanguage, $priority, $fidelity);
         if (!$uploadSuccess) {
             throw new Exception("upload failed");
         }
     } elseif ($shouldReplaceRemoteMedia == true) {
         $this->clientHelper->deleteRemoteFile($remoteJobId);
         $uploadSuccess = $this->clientHelper->uploadMedia($flavorUrl, $entryId, $callBackUrl, $spokenLanguage, $priority, $fidelity);
         if (!$uploadSuccess) {
             throw new Exception("upload failed");
         }
     } else {
         return true;
     }
     return false;
 }
 public function updatedJob(BatchJob $dbBatchJob)
 {
     $data = $dbBatchJob->getData();
     $providerData = $data->getProviderData();
     $entryId = $providerData->getEntryId();
     $partnerId = $dbBatchJob->getPartnerId();
     $spokenLanguage = $providerData->getSpokenLanguage();
     $transcript = $this->getAssetsByLanguage($entryId, array(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT)), $spokenLanguage, true);
     if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED) {
         if ($transcript) {
             $transcript->setStatus(AttachmentAsset::FLAVOR_ASSET_STATUS_ERROR);
             $transcript->save();
         }
     }
     if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_DONT_PROCESS) {
         if (!$transcript) {
             $transcript = new TranscriptAsset();
             $transcript->setType(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT));
             $transcript->setEntryId($entryId);
             $transcript->setPartnerId($partnerId);
             $transcript->setLanguage($spokenLanguage);
             $transcript->setContainerFormat(AttachmentType::TEXT);
         }
         $transcript->setStatus(AttachmentAsset::ASSET_STATUS_QUEUED);
         $transcript->save();
         return true;
     }
     $formatsString = $providerData->getCaptionAssetFormats();
     if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED) {
         $clientHelper = Cielo24Plugin::getClientHelper($providerData->getUsername(), $providerData->getPassword());
         $remoteJobId = $clientHelper->getRemoteFinishedJobId($entryId);
         if (!$remoteJobId) {
             KalturaLog::err('remote content does not exist');
             return true;
         }
         $formatsArray = explode(',', $formatsString);
         $transcriptContent = $clientHelper->getRemoteTranscript($remoteJobId);
         KalturaLog::debug("transcript content - {$transcriptContent}");
         $captionsContentArray = $clientHelper->getRemoteCaptions($remoteJobId, $formatsArray);
         KalturaLog::debug("captions content - " . print_r($captionsContentArray, true));
         $captions = $this->getAssetsByLanguage($entryId, array(CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION)), $spokenLanguage);
         switch ($providerData->getFidelity()) {
             case KalturaCielo24Fidelity::MECHANICAL:
                 $accuracyRate = self::MECHNICAL_TRANSCRIPTION_ACCURACY_VALUE;
                 break;
             case KalturaCielo24Fidelity::PREMIUM:
                 $accuracyRate = self::PREMIUM_TRANSCRIPTION_ACCURACY_VALUE;
                 break;
             case KalturaCielo24Fidelity::PROFESSIONAL:
                 $accuracyRate = self::PROFESSIONAL_TRANSCRIPTION_ACCURACY_VALUE;
                 break;
         }
         $this->setObjectContent($transcript, $transcriptContent, $accuracyRate, null, true);
         foreach ($captionsContentArray as $format => $content) {
             $captionFormatConst = constant("KalturaCaptionType::" . $format);
             if (isset($captions[$captionFormatConst])) {
                 $caption = $captions[$captionFormatConst];
             } else {
                 $caption = new CaptionAsset();
                 $caption->setEntryId($entryId);
                 $caption->setPartnerId($partnerId);
                 $caption->setLanguage($spokenLanguage);
                 $caption->setContainerFormat($captionFormatConst);
                 $caption->setStatus(CaptionAsset::ASSET_STATUS_QUEUED);
                 $caption->save();
             }
             $this->setObjectContent($caption, $content, $accuracyRate, $format);
         }
     }
     return true;
 }