diff --git a/src/InputOutput/IHMImpl/TimeTables/IHMInputOutputConvertTTClass.php b/src/InputOutput/IHMImpl/TimeTables/IHMInputOutputConvertTTClass.php index b0dd742..34624be 100644 --- a/src/InputOutput/IHMImpl/TimeTables/IHMInputOutputConvertTTClass.php +++ b/src/InputOutput/IHMImpl/TimeTables/IHMInputOutputConvertTTClass.php @@ -1,68 +1,69 @@ -<?php - -/** - * @class IHMInputOutputConvertTTClass - * @brief - * @details -*/ -class IHMInputOutputConvertTTClass implements InputOutputInterface -{ - private $processData = NULL; - - - /* - * @brief Constructor - */ - function __construct() - { - - } - - /* - * @brief translate input data from AMDA IHM to AMDA_Integration module for a tt process request - */ - public function getInputData($input, $function, $requestId="") - { - if (isset($this->processData)) - unset($this->processData); - - $processData = new TTRequestDataClass(); - $processData->setInputFileName($input['inputFile']); - switch ($input['inputFormat']) { - case 'ASCII': - $processData->setInputFileFormat(TTRequestFileFormatEnum::ASCII); - break; - case 'VOTABLE': - $processData->setInputFileFormat(TTRequestFileFormatEnum::VOTABLE); - break; - case 'INTERNAL': - $processData->setInputFileFormat(TTRequestFileFormatEnum::INTERNAL); - break; - default: - throw new Exception('Unknown input format'); - } - $processData->setOutputDir($input['outputDir']); - $processData->setOutputFileFormat(TTRequestFileFormatEnum::INTERNAL); - $processData->setOutputFileName($input['outputFileName']); - $processData->setType($function); - $processData->setCmd("ttConversion"); - - $this->processData = $processData; - - return $this->processData; - } - - /* - * @brief translate output data from AMDA_Integration module to AMDA IHM request - */ - public function getOutput($data) - { - $result = array('success' => $data->getSuccess()); - if ($result['success']) { - $result['file'] = $data->getOutputDir()."/".$data->getOutputFileName(); - } - return $result; - } -} - -?> +<?php + +/** + * @class IHMInputOutputConvertTTClass + * @brief + * @details +*/ +class IHMInputOutputConvertTTClass implements InputOutputInterface +{ + private $processData = NULL; + + + /* + * @brief Constructor + */ + function __construct() + { + + } + + /* + * @brief translate input data from AMDA IHM to AMDA_Integration module for a tt process request + */ + public function getInputData($input, $function, $requestId="") + { + if (isset($this->processData)) + unset($this->processData); + + $processData = new TTRequestDataClass(); + $processData->setInputFileName($input['inputFile']); + switch ($input['inputFormat']) { + case 'ASCII': + $processData->setInputFileFormat(TTRequestFileFormatEnum::ASCII); + break; + case 'VOTABLE': + $processData->setInputFileFormat(TTRequestFileFormatEnum::VOTABLE); + break; + case 'INTERNAL': + $processData->setInputFileFormat(TTRequestFileFormatEnum::INTERNAL); + break; + default: + throw new Exception('Unknown input format'); + } + $processData->setOutputDir($input['outputDir']); + $processData->setOutputFileFormat(TTRequestFileFormatEnum::INTERNAL); + $processData->setOutputFileName($input['outputFileName']); + $processData->setOutputTimeFormat($input['outputTimeFormat']); + $processData->setType($function); + $processData->setCmd("ttConversion"); + + $this->processData = $processData; + + return $this->processData; + } + + /* + * @brief translate output data from AMDA_Integration module to AMDA IHM request + */ + public function getOutput($data) + { + $result = array('success' => $data->getSuccess()); + if ($result['success']) { + $result['file'] = $data->getOutputDir()."/".$data->getOutputFileName(); + } + return $result; + } +} + +?> diff --git a/src/InputOutput/IHMImpl/TimeTables/IHMInputOutputTTClass.php b/src/InputOutput/IHMImpl/TimeTables/IHMInputOutputTTClass.php index 2f6007a..234a7f8 100644 --- a/src/InputOutput/IHMImpl/TimeTables/IHMInputOutputTTClass.php +++ b/src/InputOutput/IHMImpl/TimeTables/IHMInputOutputTTClass.php @@ -1,179 +1,201 @@ -<?php - -/** - * @class IHMInputOutputTTClass - * @brief - * @details -*/ -class IHMInputOutputTTClass implements InputOutputInterface -{ - -/* - * @brief Constructor -*/ - function __construct() - { - - } - -/* - * @brief translate input data from IHM client to AMDA_Integration module for a tt process request -*/ - public function getInputData($input, $function, $requestId="") - { - if (isset($this->processDatas)) - unset($this->processDatas); - - $sendToSamp = isset($input->sendToSamp) && $input->sendToSamp; - $compression = !$sendToSamp && ($input->compression !== 'none'); - $formatstr = $sendToSamp ? 'vot' : $input->fileformat; - $tmp = new TTRequestDataClass(); // just to be sure that TTRequestDataClass is loaded with the 'autoload' => TTRequestDataClass is defined - $outputformat = $this->getFormatFromString(!empty($formatstr) ? $formatstr : 'vot'); - - $final = ""; - - if (is_dir(IHMConfigClass::getDownloadTmpPath())) { - foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.zip') as $filename) unlink($filename); - foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.tar.gz') as $filename) unlink($filename); - } - - foreach($input->list as $tt) - { - //create a list of data to treat - $processData = new TTRequestDataClass(); - - if (!isset($tt->id) && !empty($tt->path)) { - $ttName = $tt->path; - $inputformat = $this->getFormatFromString(!empty($tt->format) ? $tt->format : 'internal'); - } - else if (strpos($tt->id,"sharedtimeTable_") === 0 || strpos($tt->id,"sharedcatalog_") === 0) { - //Shared TimeTable /Catalog - $objectType = strpos($tt->id,"timeTable") != 0 ? "timeTable" : "catalog"; - $result = IHMSharedObjectsClass::getPath($objectType, $tt->id); - if (!$result['success']) - throw new Exception('Shared '.$objectType.' '.$tt->name.' not found'); - $ttName = $result['path']; - $inputformat = TTRequestFileFormatEnum::INTERNAL; - } - else { - //User TimeTable / Catalog - $ttName = IHMConfigClass::getUserTTPath().$tt->id.'.xml'; - $inputformat = TTRequestFileFormatEnum::INTERNAL; - } - if (!file_exists($ttName)) - throw new Exception('TimeTable or Catalog '.$tt->name.' not found'); - $processData->setInputFileName($ttName); - $processData->setInputFileFormat($inputformat); - $processData->setOutputDir(IHMConfigClass::getDownloadTmpPath()); - $processData->setOutputFileFormat($outputformat); - - switch ($outputformat) { - case TTRequestFileFormatEnum::VOTABLE : - $outputName = $tt->name.'.xml'; - break; - case TTRequestFileFormatEnum::ASCII : - $outputName = $tt->name.'.txt'; - break; - default : - $outputName = $tt->name.'.xml'; - } - - // $processData->setOutputTimeFormat($input->timeformat); - $processData->setOutputFileName($outputName); - $final .= " ".$outputName; - $processData->setType($function); - $processData->setCmd("ttConversion"); - $processData->setSendToSamp($sendToSamp); - - $this->processDatas[] = $processData; - } - - $this->postProcessTT = new PostProcessTTClass(); - $this->postProcessTT->setOutputDirAlias($this->processDatas[0]->getOutputDir()); - - if ($compression) { - $this->postProcessTT->compression = true; - $archive = "Timetable_archive_".date('Ymd_Hi'); - switch ($input->compression) { - case 'zip' : - $postCmd = "zip -Dj ".$archive.".zip ".$final." 1> /dev/null 2> /dev/null"; - $outputFileName = $archive.".zip"; - break; - case 'tar+gzip': - default : - $postCmd="tar cfz ".$archive.".tar.gz --directory=".$this->processDatas[0]->getOutputDir()." ".$final; - $outputFileName = $archive.".tar.gz"; - break; - } - $this->postProcessTT->setPostCmd($postCmd); - $this->postProcessTT->setOutputFileName($outputFileName); - $this->postProcessTT->setOutputDir($this->processDatas[0]->getOutputDir()); - } - - return $this->processDatas; - } - - /* - * @brief Get format from input string - */ - private function getFormatFromString($str) { - switch (strtolower($str)) { - case 'vot': - case 'votable': - return TTRequestFileFormatEnum::VOTABLE; - case 'ascii': - case 'text': - case 'txt': - case 'asc': - return TTRequestFileFormatEnum::ASCII; - } - return TTRequestFileFormatEnum::INTERNAL; - } - -/* - * @brief translate output data from AMDA_Integration module to IHM client request -*/ - public function getOutput($data) - { - if ( $this->postProcessTT->compression ) { - - $timeStart = time(); - - $cmd = $this->postProcessTT->getPostCmd(); - system($cmd); - - while (!file_exists($this->postProcessTT->getOutputFileName()) && ( time() - $timeStart ) < KernelConfigClass::getTimeToBatchMode()) - sleep(1); - - - foreach ($data as $d) - { - $rawFileName = $d->getOutputDir().$d->getOutputFileName(); - if (file_exists($rawFileName)) - unlink($rawFileName); - } - - $result = array('success'=>true, - 'download'=>$this->postProcessTT->getOutputDirAlias().$this->postProcessTT->getOutputFileName(), - 'compression' => $this->postProcessTT->compression); - - - } - else if ($data[0]->getSendToSamp()) { - $donwload = array(); - foreach ($data as $d) { - $donwload[] = $this->postProcessTT->getOutputDirAlias().$d->getOutputFileName(); - } - $result = array('success'=>$data[0]->getSuccess(), 'sendToSamp' => TRUE, - 'download' => $donwload); - } - else { - $result = array('success'=>$data[0]->getSuccess(), - 'download' => $this->postProcessTT->getOutputDirAlias().$data[0]->getOutputFileName()); - } - - return $result; - } -} - -?> +<?php + +/** + * @class IHMInputOutputTTClass + * @brief + * @details +*/ +class IHMInputOutputTTClass implements InputOutputInterface +{ + +/* + * @brief Constructor +*/ + function __construct() + { + + } + +/* + * @brief translate input data from IHM client to AMDA_Integration module for a tt process request +*/ + public function getInputData($input, $function, $requestId="") + { + if (isset($this->processDatas)) + unset($this->processDatas); + + $sendToSamp = isset($input->sendToSamp) && $input->sendToSamp; + $compression = !$sendToSamp && ($input->compression !== 'none'); + $formatstr = $sendToSamp ? 'vot' : $input->fileformat; + $tmp = new TTRequestDataClass(); // just to be sure that TTRequestDataClass is loaded with the 'autoload' => TTRequestDataClass is defined + $outputformat = $this->getFormatFromString(!empty($formatstr) ? $formatstr : 'vot'); + + $final = ""; + + if (is_dir(IHMConfigClass::getDownloadTmpPath())) { + foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.zip') as $filename) unlink($filename); + foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.tar.gz') as $filename) unlink($filename); + } + + foreach($input->list as $tt) + { + //create a list of data to treat + $processData = new TTRequestDataClass(); + + if (!isset($tt->id) && !empty($tt->path)) { + $ttName = $tt->path; + $inputFileFormat = $this->getFormatFromString(!empty($tt->format) ? $tt->format : TTRequestFileFormatEnum::INTERNAL); + } + else if (strpos($tt->id,"sharedtimeTable_") === 0 || strpos($tt->id,"sharedcatalog_") === 0) { + //Shared TimeTable /Catalog + $objectType = strpos($tt->id,"timeTable") != 0 ? "timeTable" : "catalog"; + $result = IHMSharedObjectsClass::getPath($objectType, $tt->id); + if (!$result['success']) + throw new Exception('Shared '.$objectType.' '.$tt->name.' not found'); + $ttName = $result['path']; + $inputFileFormat = TTRequestFileFormatEnum::INTERNAL; + } + else { + //User TimeTable / Catalog + $ttName = IHMConfigClass::getUserTTPath().$tt->id.'.xml'; + $inputFileFormat = TTRequestFileFormatEnum::INTERNAL; + } + if (!file_exists($ttName)) + throw new Exception('TimeTable or Catalog '.$tt->name.' not found'); + $processData->setInputFileName($ttName); + $processData->setInputFileFormat($inputFileFormat); + $processData->setOutputDir(IHMConfigClass::getDownloadTmpPath()); + $processData->setOutputFileFormat($outputformat); + + switch ($outputformat) { + case TTRequestFileFormatEnum::VOTABLE : + $outputName = $tt->name.'.xml'; + break; + case TTRequestFileFormatEnum::ASCII : + $outputName = $tt->name.'.txt'; + break; + default : + $outputName = $tt->name.'.xml'; + } + + //timeformatData : [['Y-m-dTH:i:s', 'YYYY-MM-DDThh:mm:ss'], ['DD Time', 'DD Time'], ['Timestamp', 'Timestamp']], + switch ($input->timeformat) + { + case 'YYYY-MM-DDThh:mm:ss' : + $processData->setOutputTimeFormat(TTRequestTimeFormatEnum::ISO); + break; + case 'DD Time' : + $processData->setOutputTimeFormat(TTRequestTimeFormatEnum::DDTIME); + break; + case 'Timestamp' : + $processData->setOutputTimeFormat(TTRequestTimeFormatEnum::TIMESTAMP); + break; + case 'Timestamp-with-milliseconds' : + $processData->setOutputTimeFormat(TTRequestTimeFormatEnum::MS); + break; + case 'YYYY MM DD hh mm ss' : + $processData->setOutputTimeFormat(TTRequestTimeFormatEnum::SPACES); + break; + + default : + throw new Exception('Time format not implemented.'); + } + + $processData->setOutputFileName($outputName); + $final .= " ".$outputName; + $processData->setType($function); + $processData->setCmd("ttConversion"); + $processData->setSendToSamp($sendToSamp); + + $this->processDatas[] = $processData; + } + + $this->postProcessTT = new PostProcessTTClass(); + $this->postProcessTT->setOutputDirAlias($this->processDatas[0]->getOutputDir()); + + if ($compression) { + $this->postProcessTT->compression = true; + $archive = "Timetable_archive_".date('Ymd_Hi'); + switch ($input->compression) { + case 'zip' : + $postCmd = "zip -Dj ".$archive.".zip ".$final." 1> /dev/null 2> /dev/null"; + $outputFileName = $archive.".zip"; + break; + case 'tar+gzip': + default : + $postCmd="tar cfz ".$archive.".tar.gz --directory=".$this->processDatas[0]->getOutputDir()." ".$final; + $outputFileName = $archive.".tar.gz"; + break; + } + $this->postProcessTT->setPostCmd($postCmd); + $this->postProcessTT->setOutputFileName($outputFileName); + $this->postProcessTT->setOutputDir($this->processDatas[0]->getOutputDir()); + } + + return $this->processDatas; + } + + /* + * @brief Get format from input string + */ + private function getFormatFromString($str) { + switch (strtolower($str)) { + case 'vot': + case 'votable': + return TTRequestFileFormatEnum::VOTABLE; + case 'ascii': + case 'text': + case 'txt': + case 'asc': + return TTRequestFileFormatEnum::ASCII; + } + return TTRequestFileFormatEnum::INTERNAL; + } + +/* + * @brief translate output data from AMDA_Integration module to IHM client request +*/ + public function getOutput($data) + { + if ( $this->postProcessTT->compression ) { + + $timeStart = time(); + + $cmd = $this->postProcessTT->getPostCmd(); + system($cmd); + + while (!file_exists($this->postProcessTT->getOutputFileName()) && ( time() - $timeStart ) < KernelConfigClass::getTimeToBatchMode()) + sleep(1); + + + foreach ($data as $d) + { + $rawFileName = $d->getOutputDir().$d->getOutputFileName(); + if (file_exists($rawFileName)) + unlink($rawFileName); + } + + $result = array('success'=>true, + 'download'=>$this->postProcessTT->getOutputDirAlias().$this->postProcessTT->getOutputFileName(), + 'compression' => $this->postProcessTT->compression); + + + } + else if ($data[0]->getSendToSamp()) { + $donwload = array(); + foreach ($data as $d) { + $donwload[] = $this->postProcessTT->getOutputDirAlias().$d->getOutputFileName(); + } + $result = array('success'=>$data[0]->getSuccess(), 'sendToSamp' => TRUE, + 'download' => $donwload); + } + else { + $result = array('success'=>$data[0]->getSuccess(), + 'download' => $this->postProcessTT->getOutputDirAlias().$data[0]->getOutputFileName()); + } + + return $result; + } +} + +?> diff --git a/src/Request/TTRequestImpl/TTRequestClass.php b/src/Request/TTRequestImpl/TTRequestClass.php index 9abd2bb..791c928 100644 --- a/src/Request/TTRequestImpl/TTRequestClass.php +++ b/src/Request/TTRequestImpl/TTRequestClass.php @@ -61,8 +61,8 @@ class TTRequestClass extends RequestAbstractClass //run process $args = "\"".$this->requestData->getInputFileName()."\" ".$this->requestData->getInputFileFormat() - ." \"".$this->requestData->getOutputDir()."\" \"".$this->requestData->getOutputFileName() - ."\" ".$this->requestData->getOutputFileFormat(); + ." \"".$this->requestData->getOutputDir()."\" \"".$this->requestData->getOutputFileName()."\" " + .$this->requestData->getOutputFileFormat()." ".$this->requestData->getOutputTimeFormat(); $cmd = $this->requestData->getCmd()." ".$args; diff --git a/src/Request/TTRequestImpl/TTRequestDataClass.php b/src/Request/TTRequestImpl/TTRequestDataClass.php index bb20ba7..8e4e3bb 100644 --- a/src/Request/TTRequestImpl/TTRequestDataClass.php +++ b/src/Request/TTRequestImpl/TTRequestDataClass.php @@ -1,140 +1,162 @@ -<?php - -abstract class TTRequestTimeFormatEnum -{ - const UNKNOWN = ""; - const ISO = "ISO"; - const DDTIME = "DD"; - const TIMESTAMP = "DOUBLE"; -} - -abstract class TTRequestFileFormatEnum -{ - const UNKNOWN = ""; - const ASCII = "ASCII"; - const VOTABLE = "VO"; - const INTERNAL = "Internal"; -} - -/** - * @class TTRequestDataClass - * @brief Data for a TT process request - * @details - */ -class TTRequestDataClass extends RequestDataClass -{ - private $inputTimeTable = ""; - private $outputTimeTable = ""; - private $inputFileFormat = ""; - private $outputFileFormat = ""; - private $inputTimeFormat = ""; - private $outputTimeFormat = ""; - private $outputDir = ""; - private $cmd = ""; - private $envVars = array(); - private $exitCode = 0; - private $sendToSamp = FALSE; - - public function getInputFileName() - { - return $this->inputTimeTable; - } - - public function setInputFileName($inputTimeTable) - { - $this->inputTimeTable = $inputTimeTable; - } - - public function getOutputFileName() - { - return $this->outputTimeTable; - } - - public function setOutputFileName($outputTimeTable) - { - $this->outputTimeTable = $outputTimeTable; - } - - public function getOutputFileFormat() - { - return $this->outputFileFormat; - } - - public function setOutputFileFormat($outputFileFormat) - { - $this->outputFileFormat = $outputFileFormat; - } - - public function getInputFileFormat() - { - return $this->inputFileFormat; - } - - public function setInputFileFormat($inputFileFormat) - { - $this->inputFileFormat = $inputFileFormat; - } - - public function getOutputDir() - { - return $this->outputDir."/"; - } - - public function setOutputDir($outputDir) - { - $this->outputDir = $outputDir; - } - - public function setSendToSamp($sendToSamp) - { - $this->sendToSamp = $sendToSamp; - } - - public function getSendToSamp() - { - return $this->sendToSamp; - } - - public function getCmd() - { - return $this->cmd; - } - - public function setCmd($cmd) - { - $this->cmd = $cmd; - } - - public function getEnvVars() - { - return $this->envVars; - } - - public function setEnvVars($envVars) - { - $this->envVars = $envVars; - } - - public function getType() - { - return $this->type; - } - - public function setType($type) - { - $this->type = $type; - } - - - public function getErrorCode() - { - return $this->exitCode; - } - - public function setErrorCode($errorCode) - { - $this->exitCode = $errorCode; - } -} - -?> +<?php + +abstract class TTRequestTimeFormatEnum +{ + const UNKNOWN = ""; + const ISO = "ISO"; + const DDTIME = "DD"; + const TIMESTAMP = "DOUBLE"; + const SPACES = "SPACES"; + const MS = "MS"; +} + +abstract class TTRequestFileFormatEnum +{ + const UNKNOWN = ""; + const ASCII = "ASCII"; + const VOTABLE = "VO"; + const INTERNAL = "Internal"; +} + +/** + * @class TTRequestDataClass + * @brief Data for a TT process request + * @details + */ +class TTRequestDataClass extends RequestDataClass +{ + private $inputTimeTable = ""; + private $outputTimeTable = ""; + private $inputFileFormat = ""; + private $outputFileFormat = ""; + private $inputTimeFormat = ""; + private $outputTimeFormat = ""; + private $outputDir = ""; + private $cmd = ""; + private $envVars = array(); + private $exitCode = 0; + private $sendToSamp = FALSE; + + public function getInputFileName() + { + return $this->inputTimeTable; + } + + public function setInputFileName($inputTimeTable) + { + $this->inputTimeTable = $inputTimeTable; + } + + public function getOutputFileName() + { + return $this->outputTimeTable; + } + + public function setOutputFileName($outputTimeTable) + { + $this->outputTimeTable = $outputTimeTable; + } + + public function getOutputFileFormat() + { + return $this->outputFileFormat; + } + + public function setOutputFileFormat($outputFileFormat) + { + $this->outputFileFormat = $outputFileFormat; + } + + public function getInputFileFormat() + { + return $this->inputFileFormat; + } + + public function setInputFileFormat($inputFileFormat) + { + $this->inputFileFormat = $inputFileFormat; + } + + public function setInputTimeFormat($inputTimeFormat) + { + $this->inputTimeFormat = $inputTimeFormat; + } + + public function getInputTimeFormat() + { + return $this->inputTimeFormat; + } + + public function setOutputTimeFormat($outputTimeFormat) + { + $this->outputTimeFormat = $outputTimeFormat; + } + + public function getOutputTimeFormat() + { + return $this->outputTimeFormat; + } + + public function getOutputDir() + { + return $this->outputDir."/"; + } + + public function setOutputDir($outputDir) + { + $this->outputDir = $outputDir; + } + + public function setSendToSamp($sendToSamp) + { + $this->sendToSamp = $sendToSamp; + } + + public function getSendToSamp() + { + return $this->sendToSamp; + } + + public function getCmd() + { + return $this->cmd; + } + + public function setCmd($cmd) + { + $this->cmd = $cmd; + } + + public function getEnvVars() + { + return $this->envVars; + } + + public function setEnvVars($envVars) + { + $this->envVars = $envVars; + } + + public function getType() + { + return $this->type; + } + + public function setType($type) + { + $this->type = $type; + } + + + public function getErrorCode() + { + return $this->exitCode; + } + + public function setErrorCode($errorCode) + { + $this->exitCode = $errorCode; + } +} + +?> -- libgit2 0.21.2