/* * DownloadNode.cc * * Created on: Oct 31, 2012 * Author: f.casimir */ #include // Common module includes #include "OutputFormatTime.hh" // Parameters module includes #include "ServicesServer.hh" #include "Parameter.hh" #include "FileConfigurator.hh" #include "ParameterManager.hh" // XMLConfigurator module includes #include "Constant.hh" // Download module includes #include "DownloadLogger.hh" #include "DownloadOutput.hh" #include "DownloadNode.hh" #include "DownloadParamNode.hh" #include "PostProcessingNode.hh" using namespace AMDA::Parameters; using namespace AMDA::XMLConfigurator; namespace AMDA { namespace ParamOutputImpl { namespace Download { class TimeFormatNode: public AMDA::XMLConfigurator::NodeCfg { public: void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "TimeFormatNode::proceed") DownloadProperties *downloadProperties = pContext.get(); if (strcmp ((const char*)pNode->children->content, "DD") == 0) { downloadProperties->setTimeFormat(FORMAT_OUTPUT_TIME_DD); } else if (strcmp ((const char*)pNode->children->content, "ISO") == 0) { downloadProperties->setTimeFormat(FORMAT_OUTPUT_TIME_ISO); } else if (strcmp ((const char*)pNode->children->content, "DOUBLE") == 0) { downloadProperties->setTimeFormat(FORMAT_OUTPUT_TIME_DOUBLE); } else { ERROR_EXCEPTION("Time Format not supported : " << (const char*)pNode->children->content); } } }; class FileFormatNode: public AMDA::XMLConfigurator::NodeCfg { public: void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "FileFormatNode::proceed") DownloadProperties *downloadProperties = pContext.get(); if (strcmp ((const char*)pNode->children->content, "ASCII") == 0) { downloadProperties->setFileFormat(ASCII_FILE_FORMAT); } else if (strcmp ((const char*)pNode->children->content, "CDF") == 0) { downloadProperties->setFileFormat(CDF_FILE_FORMAT); } else if (strcmp ((const char*)pNode->children->content, "NETCDF") == 0) { downloadProperties->setFileFormat(NETCDF_FILE_FORMAT); } else if (strcmp ((const char*)pNode->children->content, "JSON") == 0) { downloadProperties->setFileFormat(JSON_FILE_FORMAT); if (!downloadProperties->getPrecision()) { LOG4CXX_DEBUG(gLogger, "FileFormatNode::proceed - Precision output is forced for JSON format"); downloadProperties->setPrecision(true); } } else if (strcmp ((const char*)pNode->children->content, "VOT") == 0) { downloadProperties->setFileFormat(VOT_FILE_FORMAT); if (!downloadProperties->getPrecision()) { LOG4CXX_DEBUG(gLogger, "FileFormatNode::proceed - Precision output is forced for VOTable format"); downloadProperties->setPrecision(true); } } else { ERROR_EXCEPTION("File Format not supported : " << (const char*)pNode->children->content); } } }; class FileNameNode: public AMDA::XMLConfigurator::NodeCfg { public: void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "FileNameNode::proceed") DownloadProperties *downloadProperties = pContext.get(); downloadProperties->setFileName((const char*) pNode->children->content); } }; class TimeResolutionNode: public AMDA::XMLConfigurator::NodeCfg { public: void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "TimeResolutionNode::proceed") DownloadProperties *downloadProperties = pContext.get(); downloadProperties->setTimeResolution(atoi((const char*) pNode->children->content)); } }; class OutputStructureNode: public AMDA::XMLConfigurator::NodeCfg { public: void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "OutputStructureNode::proceed") DownloadProperties *downloadProperties = pContext.get(); if (strcmp ((const char*)pNode->children->content, "one-file") == 0) { downloadProperties->setOutputStructure(OutputStructure::ONE_FILE); } else if (strcmp ((const char*)pNode->children->content, "one-file-refparam") == 0) { downloadProperties->setOutputStructure(OutputStructure::ONE_FILE_REFPARAM); } else if (strcmp ((const char*)pNode->children->content, "one-file-per-interval") == 0) { downloadProperties->setOutputStructure(OutputStructure::ONE_FILE_PER_INTERVAL); } else if (strcmp ((const char*)pNode->children->content, "one-file-per-interval-refparam") == 0) { downloadProperties->setOutputStructure(OutputStructure::ONE_FILE_PER_INTERVAL_REFPARAM); } else if (strcmp ((const char*)pNode->children->content, "one-file-per-parameter-per-interval") == 0) { downloadProperties->setOutputStructure(OutputStructure::ONE_FILE_PER_PARAMETER_PER_INTERVAL); } else { ERROR_EXCEPTION("Output structure not supported : " << (const char*)pNode->children->content); } xmlChar* value = NULL; // -- separateInfoFile value = xmlGetProp(pNode, (const xmlChar *) "separateInfoFile"); if (value != NULL) { downloadProperties->setSeparateInfoFile( strcmp((char*)value,"true") == 0); xmlFree(value); } } }; DownloadNode::DownloadNode() : NodeGrpCfg() { /* ISO ASCII result 600 one-file */ getChildList()["timeFormat"] = NodeCfgSPtr(new TimeFormatNode()); getChildList()["fileFormat"] = NodeCfgSPtr(new FileFormatNode()); getChildList()["fileName"]=NodeCfgSPtr(new FileNameNode()); getChildList()["param"]=NodeCfgSPtr(new DownloadParamNode()); getChildList()["timeResolution"]=NodeCfgSPtr(new TimeResolutionNode()); getChildList()["outputStructure"]=NodeCfgSPtr(new OutputStructureNode()); getChildList()["postProcess"]=NodeCfgSPtr(new postprocessing::PostProcessingNode()); } void DownloadNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "DownloadNode::proceed: '" << pNode->name << "' node") ParameterManager* lParameterManager = pContext.get(); ParamOutput *lParamOutputTmp; CfgContext lContext; DownloadOutput* ldownloadOutput = new DownloadOutput(*lParameterManager); xmlChar* lPrecision = xmlGetProp(pNode, (const xmlChar *) "precision"); ldownloadOutput->getDownloadProperties().setPrecision(!(lPrecision == NULL || strcmp((const char *)lPrecision, "false") == 0)); if (lPrecision) xmlFree(lPrecision); lParamOutputTmp = ldownloadOutput; lContext.push(ldownloadOutput); lContext.push(&ldownloadOutput->getDownloadProperties()); ParamOutputSPtr lParamOutput(lParamOutputTmp); NodeGrpCfg::proceed(pNode, lContext); lParameterManager->getParamOutputList().push_back(lParamOutput); } } // namespace Download } // namespace ParamOutputImpl } // namespace AMDA