RequestBodiesGet.cpp 4.26 KB
#include "RequestBodiesGet.h"

#include "../Bodies/BodiesCDPP3DView.h"
#include "../Common/Toolbox.h"
#include "../TimeManager/TimeManager.h"

using namespace TREPS::Common;
using namespace TREPS::Bodies;
using namespace TREPS::TimeManager;

namespace TREPS
{
	namespace RequestManager
	{
		RequestBodiesGetClass::RequestBodiesGetClass(void):RequestAbstractClass(), startTime(), stopTime()
		{
			this->outputType = OUTPUT_XMLFILE;
		}

		RequestBodiesGetClass::~RequestBodiesGetClass(void)
		{
		}

		string RequestBodiesGetClass::getRequestId(void)
                {
                        return "bodies_get";
                }

		bool RequestBodiesGetClass::load(RequestLoaderClass *loader)
		{
			//init request and lock workind dir where we will generate result file
			if (!this->initOpId(loader,true))
			{
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get op Id");
				return false;
			}
			
			//get isSc
			string isSc = loader->getArgStrByName("issc");
			if(isSc.compare("true")==0) {
				this->isSc = true;
			} else {
				this->isSc = false;
			}
			LOG4CXX_INFO(this->app->getLog()->getPtr(),"RequestBodiesGetClass found isSc "<<isSc.c_str()<<" / "<<this->isSc);
			//get start time
			string startTime = loader->getArgStrByName("starttime");
			//get end time
			string stopTime = loader->getArgStrByName("stoptime");
			
			
			//get time manager instance
			TimeManagerClass *timeMgr = TimeManagerClass::getInstance();

			string pattern = timeMgr->detectPattern(startTime.c_str());
			timeMgr->setCurrentPattern(pattern.c_str());
			timeMgr->from_PATTERN(startTime.c_str(),this->startTime,false);
			timeMgr->from_PATTERN(stopTime.c_str(),this->stopTime,false);
			
			
			LOG4CXX_INFO(this->app->getLog()->getPtr(),"RequestBodiesGetClass converted start and stop "<<startTime.c_str()<<" / "<<stopTime.c_str());
			
			/*
			t_FieldType type;
			t_TimeFormat timeformat;
			string timepattern;

			if (pattern.compare("") != 0)
			{
				//a time pattern has been detected
				timeformat  = TF_PATTERN;
				timepattern = pattern;
				type        = FT_TIME;
			}
			*/
			
			
			
			
			return true;
		}

		bool RequestBodiesGetClass::run(void)
		{



			//init getBodies manager
			BodiesCDPP3DViewClass *getBodies = new BodiesCDPP3DViewClass(this);
			TimeManagerClass *timeMgr = TimeManagerClass::getInstance();
			string isoPattern = timeMgr->getPatternFromTimeId("iso-mls-z");
			timeMgr->setCurrentPattern(isoPattern.c_str());

			//LOG4CXX_INFO(this->app->getLog()->getPtr(),"RequestBodiesGet init getBodies");
			if (!getBodies->init(this->isSc, &(this->startTime),&(this->stopTime)))
			{
				this->lastMsg = getBodies->getLastError();
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to init transformation request");
				return false;
			}

			//get bodies
			bool res = getBodies->run();

			if (!res)
			{
				this->lastMsg = getBodies->getLastError();
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error during get Bodies between "<<timeMgr->to_PATTERN(this->startTime).c_str()<<" and "<<timeMgr->to_PATTERN(this->stopTime).c_str());
			} else {
				
			
			//get working dir
			string dirPath = this->dirMgr->createNewDir(false);
			if (dirPath.compare("") == 0)
			{
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error create dir path");
				return false;
			}
			//LOG4CXX_INFO(this->app->getLog()->getPtr(),"Got dirPath: "<<dirPath.c_str());

			this->filePath += getPathCorrection(this->app->getConf()->getWorkingDirPath().c_str());
			this->filePath += getPathCorrection(dirPath.c_str());
			this->filePath += "bodiesList.xml";

			//LOG4CXX_INFO(this->app->getLog()->getPtr(),"*** RequestBodiesGet writer to file "<<this->filePath.c_str());

			if (this->filePath.compare("") == 0)
			{
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to get bodies result file path");
				return false;
			}
			
				getBodies->writeResult(this->filePath.c_str());
			}

			//this->success = res;
			delete getBodies;

			return res;

		}
		
		void RequestBodiesGetClass::writeResult(ResultWriterClass *writer)
		{
			//No result file for this request
		}

		string RequestBodiesGetClass::getResultFileSuffix(void)
		{
			return "";
		}

		string RequestBodiesGetClass::getXMLFilePath(void)
		{
			return this->filePath;
		}

		string RequestBodiesGetClass::getStringResult(void)
		{
			return "";
		}
	}
}