RequestExportOp.cpp
5.6 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include "RequestExportOp.h"
#include "../TimeManager/TimeManager.h"
#include "../Export/ExportManager.h"
#include "../File/FileFormatManager.h"
using namespace TREPS::TimeManager;
using namespace TREPS::Export;
using namespace TREPS::File;
namespace TREPS
{
namespace RequestManager
{
RequestExportOpClass::RequestExportOpClass(void):format(""), structure(""), timeFormat(TF_NONE), timePattern(""), success(false)
{
}
RequestExportOpClass::~RequestExportOpClass(void)
{
}
string RequestExportOpClass::getRequestId(void)
{
return "export_op";
}
bool RequestExportOpClass::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;
}
//get export format
this->format = loader->getArgStrByName("format");
if (this->format.compare("") == 0)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get export file format");
return false;
}
//get export structure
this->structure = loader->getArgStrByName("structure");
if (this->format.compare("") == 0)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get export file structure");
return false;
}
//get time manager instance
TimeManagerClass *timeMgr = TimeManagerClass::getInstance();
//get time format
string format = loader->getArgStrByName("timeformat");
this->timeFormat = timeMgr->getFormatFromTimeId(format.c_str());
//get timepattern
this->timePattern = "";
if (this->timeFormat == TF_PATTERN)
{
this->timePattern = loader->getArgStrByName("timepattern");
if (this->timePattern.compare("") == 0)
//try to get pre defined pattern
this->timePattern = timeMgr->getPatternFromTimeId(format.c_str());
if (this->timePattern.compare("") == 0)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get time pattern");
return false;
}
}
return true;
}
bool RequestExportOpClass::run(void)
{
this->success = false;
//set log to working dir
this->dirMgr->setActiveForLog(this->opId.c_str(),"export_op.log");
//get source, result and export path
string srcPath = this->dirMgr->getSourcePathFromId(this->opId.c_str());
if (srcPath.compare("") == 0)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get source file path");
return false;
}
string resPath = this->dirMgr->getResultPathFromId(this->opId.c_str());
if (resPath.compare("") == 0)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get result file path");
return false;
}
string expPath = this->dirMgr->getExportedPathFromId(this->opId.c_str());
if (expPath.compare("") == 0)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get exported file path");
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 export format
string formatsFile = this->app->getConf()->getFormatsFilePath();
if (formatsFile.compare("") == 0)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get files formats file path");
return false;
}
FileFormatManagerClass *formatMgr = new FileFormatManagerClass();
if (!formatMgr->init(formatsFile.c_str()))
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot init file format manager");
delete formatMgr;
return false;
}
t_FileFormat exportFormat = formatMgr->getFileFormatFromId(this->format.c_str());
if (exportFormat == FF_NONE)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Unknown export format id " << this->format);
delete formatMgr;
return false;
}
delete formatMgr;
//get export structure
string exportsFile = this->app->getConf()->getExportsFilePath();
if (exportsFile.compare("") == 0)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get exports file path");
return false;
}
ExportManagerClass *exportMgr = new ExportManagerClass();
if (!exportMgr->init(exportsFile.c_str()))
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot init export manager");
delete exportMgr;
return false;
}
t_ExportStructure exportStruct = exportMgr->getExportStructureFromId(this->structure.c_str());
if (exportStruct == ES_NONE)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Unknown export structure id " << this->structure);
delete exportMgr;
return false;
}
//run exportation
this->success = exportMgr->runExportOp(exportStruct, exportFormat, this->timeFormat,
this->timePattern.c_str(), requestPath.c_str(),
srcPath.c_str(), resPath.c_str(), expPath.c_str());
if (!this->success)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Error to run exportation");
}
delete exportMgr;
return this->success;
}
void RequestExportOpClass::writeResult(ResultWriterClass *writer)
{
if (!this->success)
writer->setError("Internal error during exportation request");
else
writer->setSuccess();
}
string RequestExportOpClass::getResultFileSuffix(void)
{
//nothing to do
return "";
}
string RequestExportOpClass::getXMLFilePath(void)
{
//nothing to do
return "";
}
string RequestExportOpClass::getStringResult(void)
{
//nothing to do
return "";
}
}
}