public function getData(kHttpNotificationDispatchJobData $jobData = null)
 {
     $coreObject = unserialize($this->coreObject);
     $apiObject = new $this->apiObjectType();
     /* @var $apiObject KalturaObject */
     $apiObject->fromObject($coreObject);
     $httpNotificationTemplate = EventNotificationTemplatePeer::retrieveByPK($jobData->getTemplateId());
     $notification = new KalturaHttpNotification();
     $notification->object = $apiObject;
     $notification->eventObjectType = kPluginableEnumsManager::coreToApi('EventNotificationEventObjectType', $httpNotificationTemplate->getObjectType());
     $notification->eventNotificationJobId = $jobData->getJobId();
     $notification->templateId = $httpNotificationTemplate->getId();
     $notification->templateName = $httpNotificationTemplate->getName();
     $notification->templateSystemName = $httpNotificationTemplate->getSystemName();
     $notification->eventType = $httpNotificationTemplate->getEventType();
     $data = '';
     switch ($this->format) {
         case KalturaResponseType::RESPONSE_TYPE_XML:
             $serializer = new KalturaXmlSerializer($this->ignoreNull);
             $data = '<notification>' . $serializer->serialize($notification) . '</notification>';
             break;
         case KalturaResponseType::RESPONSE_TYPE_PHP:
             $serializer = new KalturaPhpSerializer($this->ignoreNull);
             $data = $serializer->serialize($notification);
             break;
         case KalturaResponseType::RESPONSE_TYPE_JSON:
             $serializer = new KalturaJsonSerializer($this->ignoreNull);
             $data = $serializer->serialize($notification);
             break;
     }
     return "data={$data}";
 }
 public function validateForUsage($sourceObject, $propertiesToSkip = array())
 {
     parent::validateForUsage($sourceObject, $propertiesToSkip);
     $this->validatePropertyNotNull('eventNotificationTemplateId');
     myPartnerUtils::addPartnerToCriteria('EventNotificationTemplate', kCurrentContext::getCurrentPartnerId(), true);
     $eventNotificationTemplate = EventNotificationTemplatePeer::retrieveByPK($this->eventNotificationTemplateId);
     if (is_null($eventNotificationTemplate)) {
         throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND, $this->eventNotificationTemplateId);
     }
 }
 /**
  * @return the $caseId
  */
 public function getCaseId()
 {
     if ($this->caseId) {
         return $this->caseId;
     }
     $template = EventNotificationTemplatePeer::retrieveByPK($this->getTemplateId());
     /* @var $template BusinessProcessNotificationTemplate */
     $object = $this->getObject();
     if ($template && $object) {
         $cases = $template->getCaseIds($object);
         return end($cases);
     }
 }
 public function updatedJob(BatchJob $dbBatchJob)
 {
     $data = $dbBatchJob->getData();
     /* @var $data kIntegrationJobData */
     $triggerData = $data->getTriggerData();
     /* @var $triggerData kBpmEventNotificationIntegrationJobTriggerData */
     $template = EventNotificationTemplatePeer::retrieveByPK($triggerData->getTemplateId());
     /* @var $template BusinessProcessNotificationTemplate */
     $object = $dbBatchJob->getObject();
     if ($object) {
         $template->addCaseId($object, $triggerData->getCaseId(), $triggerData->getBusinessProcessId());
     }
     return true;
 }
 public function objectDeleted(BaseObject $object, BatchJob $raisedJob = null)
 {
     $scope = new kEventNotificationScope();
     $scope->setObject($object);
     if ($raisedJob) {
         $scope->setParentRaisedJob($raisedJob);
     }
     $templateIds = BusinessProcessNotificationTemplate::getCaseTemplatesIds($object);
     foreach ($templateIds as $templateId) {
         $notificationTemplate = EventNotificationTemplatePeer::retrieveByPK($templateId);
         /* @var $notificationTemplate BusinessProcessStartNotificationTemplate */
         if ($notificationTemplate->getStatus() != EventNotificationTemplateStatus::ACTIVE || !$notificationTemplate->getAbortOnDeletion()) {
             continue;
         }
         if ($notificationTemplate->getPartnerId()) {
             $scope->setPartnerId($notificationTemplate->getPartnerId());
         }
         $notificationTemplate->abort($scope);
     }
     return true;
 }
 /**
  * Dispatch event notification object by id
  * 
  * @action dispatch
  * @param int $id 
  * @param KalturaEventNotificationScope $scope
  * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND
  * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_DISABLED
  * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_FAILED
  * @return int
  */
 public function dispatchAction($id, KalturaEventNotificationScope $scope)
 {
     // get the object
     $dbEventNotificationTemplate = EventNotificationTemplatePeer::retrieveByPK($id);
     if (!$dbEventNotificationTemplate) {
         throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND, $id);
     }
     if (!$dbEventNotificationTemplate->getManualDispatchEnabled()) {
         throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_DISABLED, $id);
     }
     $jobId = $dbEventNotificationTemplate->dispatch($scope->toObject());
     if (!$jobId) {
         throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_FAILED, $id);
     }
     return $jobId;
 }
 /**
  * Dispatch event notification object by id
  * 
  * @action dispatch
  * @param int $id 
  * @param KalturaEventNotificationDispatchJobData $jobData 
  * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND
  * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_DISABLED
  * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_FAILED
  * @return int
  */
 public function dispatchAction($id, KalturaEventNotificationDispatchJobData $data)
 {
     // get the object
     $dbEventNotificationTemplate = EventNotificationTemplatePeer::retrieveByPK($id);
     if (!$dbEventNotificationTemplate) {
         throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND, $id);
     }
     if (!$dbEventNotificationTemplate->getManualDispatchEnabled()) {
         throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_DISABLED, $id);
     }
     $jobData = $data->toObject($dbEventNotificationTemplate->getJobData());
     $job = kEventNotificationFlowManager::addEventNotificationDispatchJob($dbEventNotificationTemplate->getType(), $jobData);
     if (!$job) {
         throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_FAILED, $id);
     }
     return $job->getId();
 }
 /**
  * list business-process cases
  * 
  * @action list
  * @param KalturaEventNotificationEventObjectType $objectType
  * @param string $objectId
  * @return KalturaBusinessProcessCaseArray
  * 
  * @throws KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_CASE_NOT_FOUND
  * @throws KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_SERVER_NOT_FOUND
  */
 public function listAction($objectType, $objectId)
 {
     $dbObject = kEventNotificationFlowManager::getObject($objectType, $objectId);
     if (!$dbObject) {
         throw new KalturaAPIException(KalturaErrors::OBJECT_NOT_FOUND);
     }
     $templatesIds = BusinessProcessNotificationTemplate::getCaseTemplatesIds($dbObject);
     if (!count($templatesIds)) {
         throw new KalturaAPIException(KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_CASE_NOT_FOUND);
     }
     $array = new KalturaBusinessProcessCaseArray();
     foreach ($templatesIds as $templateId) {
         $dbTemplate = EventNotificationTemplatePeer::retrieveByPK($templateId);
         if (!$dbTemplate || !$dbTemplate instanceof BusinessProcessStartNotificationTemplate) {
             KalturaLog::info("Template [{$templateId}] not found");
             continue;
         }
         $caseIds = $dbTemplate->getCaseIds($dbObject, false);
         if (!count($caseIds)) {
             KalturaLog::info("No cases found");
             continue;
         }
         $dbBusinessProcessServer = BusinessProcessServerPeer::retrieveByPK($dbTemplate->getServerId());
         if (!$dbBusinessProcessServer) {
             KalturaLog::info("Business-Process server [" . $dbTemplate->getServerId() . "] not found");
             continue;
         }
         $businessProcessServer = KalturaBusinessProcessServer::getInstanceByType($dbBusinessProcessServer->getType());
         $businessProcessServer->fromObject($dbBusinessProcessServer);
         $provider = kBusinessProcessProvider::get($businessProcessServer);
         if (!$provider) {
             KalturaLog::info("Provider [" . $businessProcessServer->type . "] not found");
             continue;
         }
         foreach ($caseIds as $caseId) {
             try {
                 $case = $provider->getCase($caseId);
                 $businessProcessCase = new KalturaBusinessProcessCase();
                 $businessProcessCase->businessProcessStartNotificationTemplateId = $templateId;
                 $businessProcessCase->fromObject($case);
                 $array[] = $businessProcessCase;
             } catch (ActivitiClientException $e) {
                 KalturaLog::err("Case [{$caseId}] not found: " . $e->getMessage());
             }
         }
     }
     return $array;
 }