RequestFileGetAbstract.cpp
3.18 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
128
129
130
131
132
#include "RequestFileGetAbstract.h"
#include "../Common/Toolbox.h"
using namespace TREPS::Common;
namespace TREPS
{
namespace RequestManager
{
RequestFileGetAbstractClass::RequestFileGetAbstractClass(void):RequestAbstractClass(), start(0), limit(0), total(0), errorMsg("")
{
//this->useCache = true;
this->data.clear();
}
RequestFileGetAbstractClass::~RequestFileGetAbstractClass(void)
{
this->data.clear();
}
bool RequestFileGetAbstractClass::load(RequestLoaderClass *loader)
{
this->errorMsg = "";
this->start = 0;
this->limit = 0;
//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;
}
//get the page start and the page limite
string pageStartStr = loader->getArgStrByName("start");
if (pageStartStr.compare("") != 0)
stringstream ( pageStartStr ) >> this->start;
string pageLimitStr = loader->getArgStrByName("limit");
if (pageLimitStr.compare("") != 0)
stringstream ( pageLimitStr ) >> this->limit;
return true;
}
bool RequestFileGetAbstractClass::run(void)
{
this->data.clear();
this->total = 0;
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 - Cannot get source file path";
LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
return false;
}
//init the file loader manager
FileLoaderManagerClass *fileLoaderMgr = new FileLoaderManagerClass();
if (!fileLoaderMgr->init(filePath.c_str()))
{
this->errorMsg = this->errorMsg;
LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
delete fileLoaderMgr;
return false;
}
//get file data
bool res = fileLoaderMgr->getData(this->start,this->limit,&this->data,this->total);
if (!res)
{
this->errorMsg = fileLoaderMgr->getErrorMsg();
LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
}
delete fileLoaderMgr;
return res;
}
void RequestFileGetAbstractClass::writeResult(ResultWriterClass *writer)
{
if (this->data.isEmpty())
{
if (this->errorMsg.compare("") == 0)
writer->setError("Error to get file data (unknown error)");
else
writer->setError(this->errorMsg.c_str());
}
else
{
writer->setSuccess();
writer->addIntArg("start",this->start);
writer->addIntArg("limit",this->limit);
writer->addIntArg("total",this->total);
writer->addDataRecordListArg("data",&this->data);
}
}
string RequestFileGetAbstractClass::getResultFileSuffix(void)
{
stringstream res;
res << "_" << this->start << "_" << this->limit;
return res.str();
}
string RequestFileGetAbstractClass::getXMLFilePath(void)
{
return "";
}
string RequestFileGetAbstractClass::getStringResult(void)
{
return "";
}
}
}