* @package taoDelivery * */ class KVDeliveryExecution implements DeliveryExecutionInterface, \JsonSerializable { /** * @var KeyValueService */ private $service; private $id; private $data; public function __construct(KeyValueService $service, $identifier, $data = null) { $this->service = $service; $this->id = $identifier; $this->data = $data; } /** * (non-PHPdoc) * * @see DeliveryExecutionInterface::getIdentifier() */ public function getIdentifier() { return $this->id; } /** * (non-PHPdoc) * * @see DeliveryExecutionInterface::getStartTime() */ public function getStartTime() { return $this->getData(OntologyDeliveryExecution::PROPERTY_TIME_START); } /** * (non-PHPdoc) * * @see DeliveryExecutionInterface::getFinishTime() */ public function getFinishTime() { if ($this->hasData(OntologyDeliveryExecution::PROPERTY_TIME_END)) { return $this->getData(OntologyDeliveryExecution::PROPERTY_TIME_END); } return null; } /** * (non-PHPdoc) * * @see DeliveryExecutionInterface::getLabel() */ public function getLabel() { return $this->getData(OntologyRdfs::RDFS_LABEL); } /** * (non-PHPdoc) * * @see DeliveryExecutionInterface::getState() */ public function getState() { return new core_kernel_classes_Resource($this->getData(OntologyDeliveryExecution::PROPERTY_STATUS)); } /** * (non-PHPdoc) * * @see DeliveryExecutionInterface::getDelivery() */ public function getDelivery() { return new core_kernel_classes_Resource($this->getData(OntologyDeliveryExecution::PROPERTY_DELIVERY)); } /** * (non-PHPdoc) * * @see DeliveryExecutionInterface::getUserIdentifier() */ public function getUserIdentifier() { return $this->getData(OntologyDeliveryExecution::PROPERTY_SUBJECT); } /** * (non-PHPdoc) * @see DeliveryExecutionInterface::setState() */ public function setState($state) { $oldState = $this->getState()->getUri(); if ($oldState == $state) { common_Logger::w('Delivery execution ' . $this->getIdentifier() . ' already in state ' . $state); return false; } $this->setData(OntologyDeliveryExecution::PROPERTY_STATUS, $state); if ($state == DeliveryExecutionInterface::STATE_FINISHED) { $this->setData(OntologyDeliveryExecution::PROPERTY_TIME_END, microtime()); } return $this->service->updateDeliveryExecutionStatus($this, $oldState, $state); } private function getData($dataKey) { if (is_null($this->data)) { $this->data = $this->service->getData($this->id); } if (! isset($this->data[$dataKey])) { throw new common_exception_NotFound('Information ' . $dataKey . ' not found for entry ' . $this->id); } return $this->data[$dataKey]; } private function hasData($dataKey) { if (is_null($this->data)) { $this->data = $this->service->getData($this->id); } return isset($this->data[$dataKey]); } private function setData($dataKey, $value) { if (is_null($this->data)) { $this->data = $this->service->getData($this->id); } $this->data[$dataKey] = $value; } /** * (non-PHPdoc) * @see JsonSerializable::jsonSerialize() * @throws \common_exception_Error */ public function jsonSerialize() { if (is_null($this->data)) { throw new common_exception_Error('Unloaded delivery execution serialized'); } return $this->data; } /** * @return bool */ public function exists() { return $this->service->exists($this->id); } /** * Stored the current data * * @deprecated since version 13.1.0 - not used anywhere */ private function save() { $this->service->update($this); } }