RequestOutputDownloadNodeClass.php 5.86 KB
<?php

require_once("RequestOutputPostProcessingNodeClass.php");

define ("REQUESTOUTPUTDOWNLOAD_NAME", "download");
define ("REQUESTOUTPUTDOWNLOAD_TIMEFORMAT", "timeFormat");
define ("REQUESTOUTPUTDOWNLOAD_FILEFORMAT", "fileFormat");
define ("REQUESTOUTPUTDOWNLOAD_FILENAME", "fileName");
define ("REQUESTOUTPUTDOWNLOAD_SAMPLING", "timeResolution");
define ("REQUESTOUTPUTDOWNLOAD_STRUCTURE", "outputStructure");
define ("REQUESTOUTPUTDOWNLOAD_PRECISION", "precision");

define ("REQUESTOUTPUTDOWNLOADPARAM_NAME", "param");
define ("REQUESTOUTPUTDOWNLOADPARAM_ID", "id");
define ("REQUESTOUTPUTDOWNLOADPARAM_INDEX", "index");
define ("REQUESTOUTPUTDOWNLOADPARAM_CALIB", "calibration_info");

abstract class RequestOutputDownloadTimeFormatEnum
{
	const UNKNOWN   = "";
	const ISO       = "ISO";
	const DDTIME    = "DD";
	const TIMESTAMP = "DOUBLE";
}

abstract class RequestOutputDownloadFileFormatEnum
{
	const UNKNOWN = "";
	const ASCII   = "ASCII";
	const VOTABLE = "VOT";
	const CDF     = "CDF";
	const JSON    = "JSON";
}

abstract class RequestOutputDownloadStructureEnum
{
	const UNKNOWN                             = "";
	const ONE_FILE                            = "one-file";
	const ONE_FILE_REFPARAM                   = "one-file-refparam";
	const ONE_FILE_PER_INTERVAL               = "one-file-per-interval";
	const ONE_FILE_PER_INTERVAL_REFPARAM      = "one-file-per-interval-refparam";
	const ONE_FILE_PER_PARAMETER_PER_INTERVAL = "one-file-per-parameter-per-interval";
}

class RequestOutputDownloadParamNodeClass extends NodeClass
{
	public function __construct()
	{
		parent::__construct(REQUESTOUTPUTDOWNLOADPARAM_NAME);
	}

	public function setId($id)
	{
		$this->setAttribute(REQUESTOUTPUTDOWNLOADPARAM_ID, $id);
	}

	public function getId()
	{
		return $this->getAttribute(REQUESTOUTPUTDOWNLOADPARAM_ID);
	}

	public function addIndex($index)
	{
		if ($this->indexExist($index))
			return;

		$node = new NodeClass(REQUESTOUTPUTDOWNLOADPARAM_INDEX);
		$node->setValue($index);
		$this->addChild($node);
	}

	public function indexExist($index)
	{
		$indexNodes = $this->getChildrenByName(REQUESTOUTPUTDOWNLOADPARAM_INDEX);

		foreach ($indexNodes as $indexNode)
		if ($indexNode->getValue() == $index)
			return true;

		return false;
	}

	public function addCalibInfo($calibInfo)
	{
		if ($this->calibInfoExist($calibInfo))
			return;

		$node = new NodeClass(REQUESTOUTPUTDOWNLOADPARAM_CALIB);
		$node->setValue($calibInfo);
		$this->addChild($node);
	}

	public function calibInfoExist($calibInfo)
	{
		$calibNodes = $this->getChildrenByName(REQUESTOUTPUTDOWNLOADPARAM_CALIB);

		foreach ($calibNodes as $calibNode)
		if ($calibNode->getValue() == $calibInfo)
			return true;

		return false;
	}
}

/**
 * @class RequestOutputDownloadNodeClass
 * @brief Definition of a request download output node for AMDA_Kernel
 * @details
 */
class RequestOutputDownloadNodeClass extends NodeClass
{
	public function __construct()
	{
		parent::__construct(REQUESTOUTPUTDOWNLOAD_NAME);
	}

	public function setTimeFormat($type)
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_TIMEFORMAT, true);
		$node->setValue($type);
	}

	public function getTimeFormat()
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_TIMEFORMAT);
		return (($node == NULL) ? RequestOutputDownloadTimeFormatEnum::UNKNOWN : $node->getValue());
	}

	public function setFileFormat($type)
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_FILEFORMAT, true);
		$node->setValue($type);
	}

	public function getFileFormat()
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_FILEFORMAT);
		return (($node == NULL) ? RequestOutputDownloadFileFormatEnum::UNKNOWN : $node->getValue());
	}

	public function setFileName($name)
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_FILENAME, true);
		$node->setValue($name);
	}

	public function getFileName()
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_FILENAME);
		return (($node == NULL) ? "" : $node->getValue());
	}

	public function setSamplingTime($sampling)
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_SAMPLING, true);
		$node->setValue($sampling);
	}

	public function getSamplingTime()
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_SAMPLING);
		return (($node == NULL) ? "" : $node->getValue());
	}

	public function setStructure($type)
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_STRUCTURE, true);
		$node->setValue($type);
	}

	public function getStructure()
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTDOWNLOAD_STRUCTURE);
		return (($node == NULL) ? RequestOutputDownloadStructureEnum::UNKNOWN : $node->getValue());
	}

	public function setPrecision($precision)
	{
		$this->setAttribute(REQUESTOUTPUTDOWNLOAD_PRECISION, $precision);
	}

	public function getPrecision()
	{
		return $this->getAttribute(REQUESTOUTPUTDOWNLOAD_PRECISION);
	}

	public function addParam($id, $indexes, $calib_infos)
	{
		$node = new RequestOutputDownloadParamNodeClass();
		$node->setId($id);
		if (isset($indexes))
		{
			foreach ($indexes as $index)
				$node->addIndex($index);
		}
		if (isset($calib_infos))
		{
			foreach ($calib_infos as $calib_info)
				$node->addCalibInfo($calib_infos);
		}
		$this->addChild($node);
	}

	public function getParam($id)
	{
		$nodes = $this->getChildrenByName(REQUESTOUTPUTDOWNLOADPARAM_NAME);

		foreach ($nodes as $node)
		if ($node->getId() == $id)
			return $node;
		return NULL;
	}

	public function addPostProcessing($process)
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTPOSTPROCESSING_NAME);
		if ($node == NULL)
		{
			$node = new RequestOutputPostProcessingNodeClass();
			$this->addChild($node);
		}

		$node->addPostProcessing($process);
	}

	public function isPostProcessing($process)
	{
		$node = $this->getChildInstanceByName(REQUESTOUTPUTPOSTPROCESSING_NAME);

		if ($node == NULL)
			return false;
			
		return $node->isPostProcessing($process);
	}
}

?>