RequestExportResult.cpp 2.16 KB
#include "RequestExportResult.h"

#include "../TimeManager/TimeManager.h"
#include "../File/FileFormatManager.h"

using namespace TREPS::TimeManager;
using namespace TREPS::File;

namespace TREPS
{
	namespace RequestManager
	{
		RequestExportResultClass::RequestExportResultClass(void): filePath(""), fileFormat(""), success(false)
		{

		}

		RequestExportResultClass::~RequestExportResultClass(void)
		{

		}

		string RequestExportResultClass::getRequestId(void)
		{
			return "export_result";
		}

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

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

			return true;
		}

		bool RequestExportResultClass::run(void)
		{
			this->success = false;

			//get export path
			this->filePath = this->dirMgr->getExportedPathFromId(this->opId.c_str());

			if (this->filePath.compare("") == 0)
			{
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get exported file path");
				return false;
			}


			//
			FileFormatManagerClass *formatMgr = new FileFormatManagerClass();

			t_FileFormat format = formatMgr->detectFileFormat(this->filePath.c_str());

			if (format == FF_NONE)
			{
				LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Unknown file format");
				delete formatMgr;
				return false;
			}

			this->fileFormat = formatMgr->getFileFormatIdFromFileFormat(format);

			delete formatMgr;

			this->success = true;

			return this->success;
		}

		void RequestExportResultClass::writeResult(ResultWriterClass *writer)
		{
			if (!this->success)
				writer->setError("Internal error during export result request");
			else
			{
				writer->setSuccess();
				writer->addStrArg("path",this->filePath.c_str());
				writer->addStrArg("format",this->fileFormat.c_str());
			}
		}

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

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

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