RequestFileInfoAbstract.cpp
2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "RequestFileInfoAbstract.h"
#include "../Common/Toolbox.h"
using namespace TREPS::Common;
namespace TREPS
{
namespace RequestManager
{
RequestFileInfoAbstractClass::RequestFileInfoAbstractClass(void):RequestAbstractClass() , errorMsg("")
{
//this->useCache = true;
}
RequestFileInfoAbstractClass::~RequestFileInfoAbstractClass(void)
{
this->info.fields.clear();
this->info.frames.clear();
this->info.vectors.clear();
}
bool RequestFileInfoAbstractClass::load(RequestLoaderClass *loader)
{
this->errorMsg = "";
//init the request and lock working dir
if (!this->initOpId(loader,true))
{
this->errorMsg = "Internal error - Cannot get op Id";
LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
return false;
}
return true;
}
bool RequestFileInfoAbstractClass::run(void)
{
this->errorMsg = "";
this->info.fields.clear();
LOG4CXX_INFO(this->app->getLog()->getPtr(),"Run " << this->getRequestId() << " request");
string logFile = this->getRequestId();
logFile += ".log";
this->dirMgr->setActiveForLog(this->opId.c_str(),logFile.c_str());
//get file path
string filePath = this->getFilePath();
if (filePath.compare("") == 0)
{
this->errorMsg = "Internal error - Error to get file path";
LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
return false;
}
//Init file manager
FileLoaderManagerClass *fileLoaderMgr = new FileLoaderManagerClass();
if (!fileLoaderMgr->init(filePath.c_str()))
{
this->errorMsg = fileLoaderMgr->getErrorMsg();
LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
delete fileLoaderMgr;
return false;
}
//get file info
bool res = fileLoaderMgr->getInfo(this->info);
if (!res)
{
this->errorMsg = fileLoaderMgr->getErrorMsg();
LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
}
delete fileLoaderMgr;
return res;
}
void RequestFileInfoAbstractClass::writeResult(ResultWriterClass *writer)
{
if (this->info.fields.empty())
{
if (this->errorMsg.compare("") == 0)
writer->setError("Cannot get file info (unknown error)");
else
writer->setError(this->errorMsg.c_str());
}
else
{
if (this->info.nbRecords > this->app->getConf()->getMaxSourceFileRecords())
{
stringstream msg;
msg << "Too many records in source file (limited to ";
msg << this->app->getConf()->getMaxSourceFileRecords();
msg << ")";
writer->setError(msg.str().c_str());
}
else
{
writer->setSuccess();
writer->addFileInfoArg("info",this->info);
}
}
}
string RequestFileInfoAbstractClass::getResultFileSuffix(void)
{
return "";
}
string RequestFileInfoAbstractClass::getXMLFilePath(void)
{
return "";
}
string RequestFileInfoAbstractClass::getStringResult(void)
{
return "";
}
}
}