RequestRunInfo.cpp 2.82 KB
#include "RequestRunInfo.h"

#include "../TimeManager/TimeManager.h"
#include "../Transformation/TransformationRequest.h"

using namespace TREPS::TimeManager;
using namespace TREPS::Transformation;

namespace TREPS
{
	namespace RequestManager
	{
		RequestRunInfoClass::RequestRunInfoClass(void) : success(false), info()
		{
			this->info.srcVectors.clear();
		}

		RequestRunInfoClass::~RequestRunInfoClass(void)
		{
			this->info.srcVectors.clear();
		}

		string RequestRunInfoClass::getRequestId(void)
		{
			return "run_info";
		}

		bool RequestRunInfoClass::load(RequestLoaderClass *loader)
		{
			this->success = false;

			this->info.srcVectors.clear();

			//init request and lock working dir
			if (!this->initOpId(loader,true))
			{
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get op Id");
				return false;
			}

			//get transformation request file path (to load information about the transformation request)
			string requestPath = this->dirMgr->getTransformationRequestFromId(this->opId.c_str());

			if (requestPath.compare("") == 0)
			{
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to get transformation request path");
				return false;
			}

			//get time manager instance
			TimeManagerClass *timeMgr = TimeManagerClass::getInstance();

			//load information about transformation request
			TransformationRequestClass *transRequest = new TransformationRequestClass();

			this->success = transRequest->loadFromFile(requestPath.c_str());

			if (this->success)
			{
				this->info.srcFrame     = transRequest->getSrcFrame();
				this->info.dstFrame     = transRequest->getDstFrame();
				for (t_VectorList::iterator it=transRequest->getSrcVectors()->begin(); it != transRequest->getSrcVectors()->end(); ++it)
					this->info.srcVectors.push_back(*it);
				this->info.timeFieldId  = transRequest->getTimeFieldId();
				this->info.timeFormatId = timeMgr->getTimeIdFromFormatAndPattern(transRequest->getTimeFormat(),
										transRequest->getTimePattern().c_str());
				this->info.timePattern  = transRequest->getTimePattern();
			}
			else
			{
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot load information about transformation request");
			}
			
			delete transRequest;

			return this->success;
		}

		bool RequestRunInfoClass::run(void)
		{
			//nothing to do
			return this->success;
		}

		void RequestRunInfoClass::writeResult(ResultWriterClass *writer)
		{
			if (!this->success)
				writer->setError("Cannot get transformation info");
			else
			{
				writer->setSuccess();
				writer->addTransformationInfoArg("info",this->info);
			}
		}

		string RequestRunInfoClass::getResultFileSuffix(void)
		{
			//nothing to do
			return "";
		}

		string RequestRunInfoClass::getXMLFilePath(void)
		{
			//nothing to do
			return "";
		}

		string RequestRunInfoClass::getStringResult(void)
		{
			//nothing to do
			return "";
		}
	}
}