Commit 52e364426a2fdb01417eabbcf5af1913f9b24725

Authored by Laurent BEIGBEDER
1 parent 5e3d9598
Exists in master

9763: HAPI access fixed

ihm/app/controller/Steps/SourceSelectionStep.js
1   -Ext.define('treps.controller.Steps.SourceSelectionStep', {
2   - extend: 'treps.controller.Steps.BaseStep',
3   -
4   - views: [
5   - 'Steps.SourceSelection.SourceSelectionPanel'
6   - ],
7   -
8   - requires: [
9   - 'treps.controller.SAMP.SAMPManager'
10   - ],
11   -
12   - sampButtonSelector : 'sourceselection_panel > panel > sampdata_panel > sampconnect_button',
13   -
14   - sampClientsDataViewSelector : 'sourceselection_panel > panel > sampdata_panel > sampclients_dataview',
15   -
16   - localFileSelector : 'sourceselection_panel > panel > localfile_panel > filefield',
17   -
18   - refs: [
19   - {
20   - ref: 'sourceSelectionPanel',
21   - selector: 'sourceselection_panel'
22   - },
23   - {
24   - ref: 'filefield',
25   - selector: 'filedropzone'
26   - }
27   - ],
28   -
29   - init: function() {
30   - var me = this;
31   -
32   - this.ref(
33   - [
34   - {
35   - ref: 'sampConnectButton',
36   - selector: this.sampButtonSelector
37   - },
38   - {
39   - ref: 'sampClientsDataView',
40   - selector: this.sampClientsDataViewSelector
41   - }
42   - ]
43   - );
44   -
45   - var c = {};
46   - c[this.sampButtonSelector] = {
47   - click : me.onChangeSampConnection,
48   - scope : me
49   - };
50   -
51   -
52   - c[this.localFileSelector] = {
53   - change : me.onSelectLocalFile,
54   - scope : me
55   - };
56   -
57   - this.control(c);
58   -
59   -
60   - this.application.on(
61   - {
62   - samp_connect: me.updateSAMPConnection,
63   - scope: me
64   - }
65   - );
66   -
67   - this.application.on(
68   - {
69   - samp_disconnect: me.updateSAMPConnection,
70   - scope: me
71   - }
72   - );
73   -
74   - this.application.on(
75   - {
76   - samp_clients: me.updateSAMPClients,
77   - scope: me
78   - }
79   - );
80   - },
81   -
82   - getCrtPanel: function() {
83   - var mainPanel = this.getSourceSelectionPanel();
84   - return mainPanel.child("[collapsed=false]").child("panel");
85   - },
86   -
87   - onChangeSampConnection: function()
88   - {
89   - var sampManager = treps.controller.SAMP.SAMPManager;
90   -
91   - if (!sampManager.isConnected())
92   - sampManager.connect();
93   - else
94   - sampManager.disconnect();
95   - },
96   -
97   - onSelectLocalFile : function()
98   - {
99   - treps.getApplication().fireEvent('receivesource',null,null);
100   - },
101   -
102   - updateSAMPConnection: function()
103   - {
104   - var sampManager = treps.controller.SAMP.SAMPManager;
105   - var sampButton = this.getSampConnectButton();
106   -
107   - if (sampButton == null)
108   - return;
109   -
110   - var connected = sampManager.isConnected();
111   -
112   - if (connected)
113   - {
114   - sampButton.setText('Disconnect to hub');
115   - sampButton.setIconCls('icons-24x24-disconnect');
116   - }
117   - else
118   - {
119   - sampButton.setText('Connect to hub');
120   - sampButton.setIconCls('icons-24x24-connect');
121   - }
122   -
123   - },
124   -
125   - updateSAMPClients: function()
126   - {
127   - var sampManager = treps.controller.SAMP.SAMPManager;
128   - var clientsStore = sampManager.getClientsStore();
129   - var clientsDataView = this.getSampClientsDataView();
130   -
131   - if (clientsDataView == null)
132   - return;
133   -
134   - if (clientsDataView.getStore().storeId != clientsStore.storeId)
135   - clientsDataView.bindStore(clientsStore);
136   - },
137   -
138   - doInitStep: function() {
139   - var editController = treps.app.getController('Data.Edit.EditDataGrid');
140   - editController.clearStore();
141   - var dropController = treps.app.getController('Drop.FileDrop');
142   - this.updateSAMPConnection();
143   - this.updateSAMPClients();
144   - },
145   -
146   - isValidStep: function() {
147   - var me = this;
148   - var crtPanel = this.getCrtPanel();
149   -
150   - var editController = treps.app.getController('Data.Edit.EditDataGrid');
151   -
152   - if (crtPanel == null)
153   - return false;
154   -
155   - switch (crtPanel.xtype)
156   - {
157   - case 'localfile_panel':
158   - if (!crtPanel.isValid())
159   - {
160   - treps.Messages.showError("Validation error. Cannot submit the request.");
161   - return false;
162   - }
163   - break;
164   - case 'sampdata_panel':
165   - treps.Messages.showInfo("Please send data with a SAMP notification.");
166   - return false;
167   - case 'webfile_panel':
168   - if (!crtPanel.isValid())
169   - {
170   - treps.Messages.showError("Validation error. Cannot submit the request.");
171   - return false;
172   - }
173   - break;
174   - case 'manualdata_panel':
175   - if (!editController.isValid())
176   - {
177   - treps.Messages.showInfo("Validation error. Cannot submit the request.");
178   - return false;
179   - }
180   - break;
181   - }
182   -
183   - return true;
184   - },
185   -
186   - doRequest: function(afterrequest,type,data) {
187   - var me = this;
188   - var crtPanel = this.getCrtPanel();
189   - if (crtPanel == null)
190   - return false;
191   -
192   - var editController = treps.app.getController('Data.Edit.EditDataGrid');
193   -
194   - //reinit source selection
195   - var session = treps.model.Session;
196   - //session.set('in_filenameBase',null);
197   -
198   - //on SAMP notification or drag & drop selection
199   - if ((type != null) && (data != null))
200   - {
201   - me.callRequest(type,data,afterrequest);
202   - return;
203   - }
204   -
205   - switch (crtPanel.xtype)
206   - {
207   - case 'localfile_panel':
208   - crtPanel.getForm().submit(
209   - {
210   - url: treps.Constants.PHP_DIR+'UploadFile.php',
211   - waitMsg: 'Uploading your file...',
212   - timeout: 120000,
213   - success: function(form, action) {
214   - //save input file name, removing first random generated chars
215   - //redmine 6610
216   - var filenameBase = action.result.fileName.substring(
217   - action.result.fileName.indexOf("_",11)+1,
218   - action.result.fileName.lastIndexOf('.'));
219   - //console.log('localfile_panel filename2: '+filenameBase);
220   - treps.model.Session.set('in_filenameBase',filenameBase);
221   - me.callRequest('local',action.result.fileName,afterrequest);
222   - },
223   - failure: function(form, action)
224   - {
225   - treps.LoadMask.hide();
226   -
227   - switch (action.failureType)
228   - {
229   - case Ext.form.action.Action.CLIENT_INVALID:
230   - treps.Messages.showError('Form fields may not be submitted with invalid values');
231   - break;
232   - case Ext.form.action.Action.CONNECT_FAILURE:
233   - treps.Messages.showError('Ajax communication failed');
234   - break;
235   - case Ext.form.action.Action.SERVER_INVALID:
236   - if (!action.result)
237   - treps.Messages.showError("Internal error during UploadFile request");
238   - else
239   - treps.Messages.showError(action.result.error);
240   - break;
241   - default:
242   - treps.Messages.showError('Unknown error');
243   - }
244   - afterrequest.call(me,false);
245   -
246   - }
247   - }
248   - );
249   - break;
250   - case 'sampdata_panel':
251   - //nothing to do
252   - break;
253   - case 'webfile_panel':
254   - var url = crtPanel.child("textfield").getRawValue();
255   - var filenameBase = url.substring(
256   - action.result.fileName.lastIndexOf("_",11)+1,
257   - action.result.fileName.lastIndexOf('.'));
258   - me.callRequest('url',url,afterrequest);
259   - break;
260   - case 'manualdata_panel':
261   - var data = editController.getData();
262   - me.callRequest('data',data,afterrequest);
263   - break;
264   - }
265   - },
266   -
267   - callRequest : function(type, location, afterrequest)
268   - {
269   - var me = this;
270   - treps.LoadMask.show("Get source data. Please Wait ...");
271   - TREPSAction.startNewOperation({'type' : type, 'data' : location}, function(result, event)
272   - {
273   - treps.LoadMask.hide();
274   - // console.log('callRequestlocation: '+location);
275   -
276   - if (!result)
277   - {
278   - treps.Messages.showError("Internal error during startNewOperation request");
279   - afterrequest.call(me,false);
280   - return;
281   - }
282   - else if (!result.success)
283   - {
284   - treps.Messages.showError(result.error);
285   - afterrequest.call(me,false);
286   - return;
287   - }
288   -
289   - var session_id = result.id;
290   -
291   -
292   - treps.model.Session.set('id',session_id);
293   -
294   -
295   - afterrequest.call(me,true);
296   - }
297   - );
298   - }
299   -});
  1 +Ext.define('treps.controller.Steps.SourceSelectionStep', {
  2 + extend: 'treps.controller.Steps.BaseStep',
  3 +
  4 + views: [
  5 + 'Steps.SourceSelection.SourceSelectionPanel'
  6 + ],
  7 +
  8 + requires: [
  9 + 'treps.controller.SAMP.SAMPManager'
  10 + ],
  11 +
  12 + sampButtonSelector : 'sourceselection_panel > panel > sampdata_panel > sampconnect_button',
  13 +
  14 + sampClientsDataViewSelector : 'sourceselection_panel > panel > sampdata_panel > sampclients_dataview',
  15 +
  16 + localFileSelector : 'sourceselection_panel > panel > localfile_panel > filefield',
  17 +
  18 + refs: [
  19 + {
  20 + ref: 'sourceSelectionPanel',
  21 + selector: 'sourceselection_panel'
  22 + },
  23 + {
  24 + ref: 'filefield',
  25 + selector: 'filedropzone'
  26 + }
  27 + ],
  28 +
  29 + init: function() {
  30 + var me = this;
  31 +
  32 + this.ref(
  33 + [
  34 + {
  35 + ref: 'sampConnectButton',
  36 + selector: this.sampButtonSelector
  37 + },
  38 + {
  39 + ref: 'sampClientsDataView',
  40 + selector: this.sampClientsDataViewSelector
  41 + }
  42 + ]
  43 + );
  44 +
  45 + var c = {};
  46 + c[this.sampButtonSelector] = {
  47 + click : me.onChangeSampConnection,
  48 + scope : me
  49 + };
  50 +
  51 +
  52 + c[this.localFileSelector] = {
  53 + change : me.onSelectLocalFile,
  54 + scope : me
  55 + };
  56 +
  57 + this.control(c);
  58 +
  59 +
  60 + this.application.on(
  61 + {
  62 + samp_connect: me.updateSAMPConnection,
  63 + scope: me
  64 + }
  65 + );
  66 +
  67 + this.application.on(
  68 + {
  69 + samp_disconnect: me.updateSAMPConnection,
  70 + scope: me
  71 + }
  72 + );
  73 +
  74 + this.application.on(
  75 + {
  76 + samp_clients: me.updateSAMPClients,
  77 + scope: me
  78 + }
  79 + );
  80 + },
  81 +
  82 + getCrtPanel: function() {
  83 + var mainPanel = this.getSourceSelectionPanel();
  84 + return mainPanel.child("[collapsed=false]").child("panel");
  85 + },
  86 +
  87 + onChangeSampConnection: function()
  88 + {
  89 + var sampManager = treps.controller.SAMP.SAMPManager;
  90 +
  91 + if (!sampManager.isConnected())
  92 + sampManager.connect();
  93 + else
  94 + sampManager.disconnect();
  95 + },
  96 +
  97 + onSelectLocalFile : function()
  98 + {
  99 + treps.getApplication().fireEvent('receivesource',null,null);
  100 + },
  101 +
  102 + updateSAMPConnection: function()
  103 + {
  104 + var sampManager = treps.controller.SAMP.SAMPManager;
  105 + var sampButton = this.getSampConnectButton();
  106 +
  107 + if (sampButton == null)
  108 + return;
  109 +
  110 + var connected = sampManager.isConnected();
  111 +
  112 + if (connected)
  113 + {
  114 + sampButton.setText('Disconnect to hub');
  115 + sampButton.setIconCls('icons-24x24-disconnect');
  116 + }
  117 + else
  118 + {
  119 + sampButton.setText('Connect to hub');
  120 + sampButton.setIconCls('icons-24x24-connect');
  121 + }
  122 +
  123 + },
  124 +
  125 + updateSAMPClients: function()
  126 + {
  127 + var sampManager = treps.controller.SAMP.SAMPManager;
  128 + var clientsStore = sampManager.getClientsStore();
  129 + var clientsDataView = this.getSampClientsDataView();
  130 +
  131 + if (clientsDataView == null)
  132 + return;
  133 +
  134 + if (clientsDataView.getStore().storeId != clientsStore.storeId)
  135 + clientsDataView.bindStore(clientsStore);
  136 + },
  137 +
  138 + doInitStep: function() {
  139 + var editController = treps.app.getController('Data.Edit.EditDataGrid');
  140 + editController.clearStore();
  141 + var dropController = treps.app.getController('Drop.FileDrop');
  142 + this.updateSAMPConnection();
  143 + this.updateSAMPClients();
  144 + },
  145 +
  146 + isValidStep: function() {
  147 + var me = this;
  148 + var crtPanel = this.getCrtPanel();
  149 +
  150 + var editController = treps.app.getController('Data.Edit.EditDataGrid');
  151 +
  152 + if (crtPanel == null)
  153 + return false;
  154 +
  155 + switch (crtPanel.xtype)
  156 + {
  157 + case 'localfile_panel':
  158 + if (!crtPanel.isValid())
  159 + {
  160 + treps.Messages.showError("Validation error. Cannot submit the request.");
  161 + return false;
  162 + }
  163 + break;
  164 + case 'sampdata_panel':
  165 + treps.Messages.showInfo("Please send data with a SAMP notification.");
  166 + return false;
  167 + case 'webfile_panel':
  168 + if (!crtPanel.isValid())
  169 + {
  170 + treps.Messages.showError("Validation error. Cannot submit the request.");
  171 + return false;
  172 + }
  173 + break;
  174 + case 'manualdata_panel':
  175 + if (!editController.isValid())
  176 + {
  177 + treps.Messages.showInfo("Validation error. Cannot submit the request.");
  178 + return false;
  179 + }
  180 + break;
  181 + }
  182 +
  183 + return true;
  184 + },
  185 +
  186 + doRequest: function(afterrequest,type,data) {
  187 + var me = this;
  188 + var crtPanel = this.getCrtPanel();
  189 + if (crtPanel == null)
  190 + return false;
  191 +
  192 + var editController = treps.app.getController('Data.Edit.EditDataGrid');
  193 +
  194 + //reinit source selection
  195 + var session = treps.model.Session;
  196 + //session.set('in_filenameBase',null);
  197 +
  198 + //on SAMP notification or drag & drop selection
  199 + if ((type != null) && (data != null))
  200 + {
  201 + me.callRequest(type,data,afterrequest);
  202 + return;
  203 + }
  204 +
  205 + switch (crtPanel.xtype)
  206 + {
  207 + case 'localfile_panel':
  208 + crtPanel.getForm().submit(
  209 + {
  210 + url: treps.Constants.PHP_DIR+'UploadFile.php',
  211 + waitMsg: 'Uploading your file...',
  212 + timeout: 120000,
  213 + success: function(form, action) {
  214 + //save input file name, removing first random generated chars
  215 + //redmine 6610
  216 + var filenameBase = action.result.fileName.substring(
  217 + action.result.fileName.indexOf("_",11)+1,
  218 + action.result.fileName.lastIndexOf('.'));
  219 + //console.log('localfile_panel filename2: '+filenameBase);
  220 + treps.model.Session.set('in_filenameBase',filenameBase);
  221 + me.callRequest('local',action.result.fileName,afterrequest);
  222 + },
  223 + failure: function(form, action)
  224 + {
  225 + treps.LoadMask.hide();
  226 +
  227 + switch (action.failureType)
  228 + {
  229 + case Ext.form.action.Action.CLIENT_INVALID:
  230 + treps.Messages.showError('Form fields may not be submitted with invalid values');
  231 + break;
  232 + case Ext.form.action.Action.CONNECT_FAILURE:
  233 + treps.Messages.showError('Ajax communication failed');
  234 + break;
  235 + case Ext.form.action.Action.SERVER_INVALID:
  236 + if (!action.result)
  237 + treps.Messages.showError("Internal error during UploadFile request");
  238 + else
  239 + treps.Messages.showError(action.result.error);
  240 + break;
  241 + default:
  242 + treps.Messages.showError('Unknown error');
  243 + }
  244 + afterrequest.call(me,false);
  245 +
  246 + }
  247 + }
  248 + );
  249 + break;
  250 + case 'sampdata_panel':
  251 + //nothing to do
  252 + break;
  253 + case 'webfile_panel':
  254 + var url = crtPanel.child("textfield").getRawValue();
  255 +
  256 +
  257 + // 9763 11621 : Uncaught ReferenceError: action is not defined
  258 + //var filenameBase = url.substring(
  259 + // action.result.fileName.lastIndexOf("_",11)+1,
  260 + // action.result.fileName.lastIndexOf('.'));
  261 +
  262 + const urlObject = new URL(url);
  263 + const hostname = urlObject.hostname;
  264 + const siteName = hostname.replace(/\./g, '-');
  265 + //const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
  266 + //const filenameBase = `${siteName}_${timestamp}.txt`;
  267 + const filenameBase = `${siteName}`;
  268 + //console.log('- url:' + url);
  269 + //console.log('- filenameBase:' + filenameBase);
  270 + url = me.encodeHtml(url);
  271 + // 9763 11621
  272 +
  273 + treps.model.Session.set('in_filenameBase',filenameBase);
  274 + me.callRequest('url',url,afterrequest);
  275 + break;
  276 + case 'manualdata_panel':
  277 + var data = editController.getData();
  278 + me.callRequest('data',data,afterrequest);
  279 + break;
  280 + }
  281 + },
  282 +
  283 + callRequest : function(type, location, afterrequest)
  284 + {
  285 + var me = this;
  286 + treps.LoadMask.show("Get source data. Please Wait ...");
  287 +
  288 + TREPSAction.startNewOperation({'type' : type, 'data' : location}, function(result, event)
  289 + {
  290 + treps.LoadMask.hide();
  291 + // console.log('callRequestlocation: '+location);
  292 +
  293 + if (!result)
  294 + {
  295 + treps.Messages.showError("Internal error during startNewOperation request");
  296 + afterrequest.call(me,false);
  297 + return;
  298 + }
  299 + else if (!result.success)
  300 + {
  301 + treps.Messages.showError(result.error);
  302 + afterrequest.call(me,false);
  303 + return;
  304 + }
  305 +
  306 + var session_id = result.id;
  307 +
  308 +
  309 + treps.model.Session.set('id',session_id);
  310 +
  311 +
  312 + afterrequest.call(me,true);
  313 + }
  314 + );
  315 + },
  316 +
  317 +
  318 + // 9763 11621
  319 + encodeHtml: function(text) {
  320 + return text
  321 + .replace(/&/g, "&")
  322 + .replace(/</g, "&lt;")
  323 + .replace(/>/g, "&gt;")
  324 + .replace(/"/g, "&quot;")
  325 + .replace(/'/g, "&#039;");
  326 +}
  327 +
  328 +
  329 +
  330 +});
... ...
server/kernel/src/File/FileLoaderASCII.cpp
... ... @@ -64,14 +64,34 @@ namespace TREPS
64 64 if (!this->getNextDataLine())
65 65 return fields;
66 66  
  67 +
  68 + //9763 check if delimiter is ','
  69 + this->resetLine();
  70 + this->getNextDataLine();
  71 + string lTmp = *this->crtLine;
  72 + bool isCommaDelimiter = false;
  73 +
  74 + if(lTmp.find(",") != std::string::npos){
  75 + isCommaDelimiter = true;
  76 + this->errorMsg = "Unknown delimiter, only space or tab characters are recognized.";
  77 + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
  78 + return fields;
  79 + }
  80 + this->resetLine();
  81 + //9763 check if delimiter is ','
  82 +
  83 +
  84 +
67 85 stringstream ss(*(this->crtLine));
68 86 string entry;
69 87  
70 88 t_Field crtField;
71 89  
72 90 int index = 0;
73   - while (ss >> entry)
74   - {
  91 +
  92 +
  93 + while (ss >> entry)
  94 + {
75 95 //create new fields
76 96 crtField.id = intToStr(index);
77 97 crtField.name = "Field_";
... ... @@ -87,8 +107,10 @@ namespace TREPS
87 107 fields.push_back(crtField);
88 108  
89 109 ++index;
90   - }
91   -
  110 + }
  111 +
  112 +
  113 +
92 114 return fields;
93 115 }
94 116  
... ... @@ -241,8 +263,24 @@ namespace TREPS
241 263  
242 264 total = 0;
243 265  
  266 +
  267 + //9763 check if delimiter is ','
  268 + this->getNextDataLine();
  269 + string lTmp = *this->crtLine;
  270 + bool isCommaDelimiter = false;
  271 +
  272 + if(lTmp.find(",") != std::string::npos){
  273 + isCommaDelimiter = true;
  274 + this->errorMsg = "Unknown delimiter, only space or tab characters are recognized.";
  275 + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
  276 + return false;
  277 + }
  278 + this->resetLine();
  279 + //9763 check if delimiter is ','
  280 +
244 281 while (this->getNextDataLine())
245 282 {
  283 +
246 284 if (!getall && (total < start))
247 285 {
248 286 total++;
... ... @@ -251,17 +289,18 @@ namespace TREPS
251 289  
252 290 if (getall || (total < start + limit))
253 291 {
  292 +
254 293 stringstream ss(*this->crtLine);
255 294 string entry;
256 295  
257 296 DataRecordClass *newRec = data->addNew();
258 297  
259   - int crtId = 0;
  298 + int crtId = 0;
260 299 while (ss >> entry)
261 300 {
262 301 newRec->setValue(intToStr(crtId).c_str(), entry.c_str());
263 302 ++crtId;
264   - }
  303 + }
265 304 }
266 305  
267 306 total++;
... ...
server/kernel/src/File/FileLoaderAbstract.cpp
1   -#include "FileLoaderAbstract.h"
2   -
3   -#include "../Common/Toolbox.h"
4   -
5   -using namespace TREPS::Common;
6   -
7   -namespace TREPS
8   -{
9   - namespace File
10   - {
11   - FileLoaderAbstractClass::FileLoaderAbstractClass(void) : app(NULL), frameMgr(NULL)
12   - {
13   - this->app = ApplicationClass::getInstance();
14   -
15   - this->frameMgr = new FrameManagerClass();
16   - }
17   -
18   - FileLoaderAbstractClass::~FileLoaderAbstractClass(void)
19   - {
20   - if (this->frameMgr != NULL)
21   - {
22   - delete this->frameMgr;
23   - this->frameMgr = NULL;
24   - }
25   - }
26   -
27   - bool FileLoaderAbstractClass::getInfo(t_FileInfo &info)
28   - {
29   - info.format = this->getFormat();
30   -
31   - //get frames list file path
32   - string framesPath = this->app->getConf()->getFramesFilePath();
33   -
34   - if (framesPath.compare("") != 0)
35   - //init frame manager
36   - frameMgr->init(framesPath.c_str());
37   -
38   - //get nb of records
39   - info.nbRecords = this->getNbRecords();
40   -
41   - //get fields
42   - info.fields = this->getFields(info.nbRecords);
43   -
44   - //detect frames
45   - info.frames = this->getFrames(&info.fields);
46   -
47   - //detect vectors
48   - info.vectors = this->getVectors(&info.fields);
49   -
50   - //get file attributes
51   - info.attributes = this->getAttributes();
52   -
53   - return (!info.fields.empty());
54   - }
55   -
56   - t_VectorList FileLoaderAbstractClass::getVectors(const t_FieldList *fields)
57   - {
58   - //get common vectors
59   - t_VectorList vectors;
60   - vectors.clear();
61   -
62   - int vecIndex = 0;
63   - for (t_FieldList::const_iterator field = fields->begin(); field != fields->end(); ++field)
64   - {
65   - //a string field or a time field cannot be considerate as a vector
66   - if (((*field).type == FT_UNKNOWN) || ((*field).type == FT_TIME))
67   - continue;
68   - //no dimension => it's a scalar
69   - if ((*field).dims.empty())
70   - continue;
71   - //more than one dimension => it's not a vector
72   - if ((*field).dims.size() > 1)
73   - continue;
74   - //if the dimension size is 3 => it's a vector
75   - if ((*field).dims.begin()->size == 3)
76   - {
77   - //use the field id for the vector id
78   - t_Vector vec;
79   - vec.id = "v_";
80   - vec.id += intToStr(vecIndex);
81   -
82   - //define the 3 components
83   - vec.fieldId[0] = (*field).id;
84   - vec.fieldId[0] += "_TREPSID0";
85   -
86   - vec.fieldId[1] = (*field).id;
87   - vec.fieldId[1] += "_TREPSID1";
88   -
89   - vec.fieldId[2] = (*field).id;
90   - vec.fieldId[2] += "_TREPSID2";
91   -
92   - vec.nbRecords = (*field).nbRecords;
93   -
94   - vectors.push_back(vec);
95   - ++vecIndex;
96   - }
97   - }
98   -
99   - //add specific possibility to define a vector for a format file
100   - this->addSpecificFormatVectors(fields, vectors);
101   -
102   - return vectors;
103   - }
104   - }
105   -}
  1 +#include "FileLoaderAbstract.h"
  2 +
  3 +#include "../Common/Toolbox.h"
  4 +
  5 +using namespace TREPS::Common;
  6 +
  7 +namespace TREPS
  8 +{
  9 + namespace File
  10 + {
  11 + FileLoaderAbstractClass::FileLoaderAbstractClass(void) : app(NULL), frameMgr(NULL)
  12 + {
  13 + this->app = ApplicationClass::getInstance();
  14 +
  15 + this->frameMgr = new FrameManagerClass();
  16 + }
  17 +
  18 + FileLoaderAbstractClass::~FileLoaderAbstractClass(void)
  19 + {
  20 + if (this->frameMgr != NULL)
  21 + {
  22 + delete this->frameMgr;
  23 + this->frameMgr = NULL;
  24 + }
  25 + }
  26 +
  27 + bool FileLoaderAbstractClass::getInfo(t_FileInfo &info)
  28 + {
  29 + info.format = this->getFormat();
  30 +
  31 + //get frames list file path
  32 + string framesPath = this->app->getConf()->getFramesFilePath();
  33 +
  34 + if (framesPath.compare("") != 0)
  35 + //init frame manager
  36 + frameMgr->init(framesPath.c_str());
  37 +
  38 + //get nb of records
  39 + info.nbRecords = this->getNbRecords();
  40 +
  41 + //get fields
  42 + info.fields = this->getFields(info.nbRecords);
  43 +
  44 + //detect frames
  45 + info.frames = this->getFrames(&info.fields);
  46 +
  47 + //detect vectors
  48 + info.vectors = this->getVectors(&info.fields);
  49 +
  50 + //get file attributes
  51 + info.attributes = this->getAttributes();
  52 +
  53 + return (!info.fields.empty());
  54 + }
  55 +
  56 + t_VectorList FileLoaderAbstractClass::getVectors(const t_FieldList *fields)
  57 + {
  58 + //get common vectors
  59 + t_VectorList vectors;
  60 + vectors.clear();
  61 +
  62 + int vecIndex = 0;
  63 + for (t_FieldList::const_iterator field = fields->begin(); field != fields->end(); ++field)
  64 + {
  65 + //a string field or a time field cannot be considerate as a vector
  66 + if (((*field).type == FT_UNKNOWN) || ((*field).type == FT_TIME))
  67 + continue;
  68 + //no dimension => it's a scalar
  69 + if ((*field).dims.empty())
  70 + continue;
  71 + //more than one dimension => it's not a vector
  72 + if ((*field).dims.size() > 1)
  73 + continue;
  74 + //if the dimension size is 3 => it's a vector
  75 + if ((*field).dims.begin()->size == 3)
  76 + {
  77 + //use the field id for the vector id
  78 + t_Vector vec;
  79 + vec.id = "v_";
  80 + vec.id += intToStr(vecIndex);
  81 +
  82 + //define the 3 components
  83 + vec.fieldId[0] = (*field).id;
  84 + vec.fieldId[0] += "_TREPSID0";
  85 +
  86 + vec.fieldId[1] = (*field).id;
  87 + vec.fieldId[1] += "_TREPSID1";
  88 +
  89 + vec.fieldId[2] = (*field).id;
  90 + vec.fieldId[2] += "_TREPSID2";
  91 +
  92 + vec.nbRecords = (*field).nbRecords;
  93 +
  94 + vectors.push_back(vec);
  95 + ++vecIndex;
  96 + }
  97 + }
  98 +
  99 + //add specific possibility to define a vector for a format file
  100 + this->addSpecificFormatVectors(fields, vectors);
  101 +
  102 + return vectors;
  103 + }
  104 +
  105 +
  106 + // 9763 - add message error to rise it to user
  107 + string FileLoaderAbstractClass::getErrorMsg(void)
  108 + {
  109 + return this->errorMsg;
  110 + }
  111 +
  112 + }
  113 +}
... ...
server/kernel/src/File/FileLoaderAbstract.h
1   -#ifndef FILELOADERABSTRACT_H
2   -#define FILELOADERABSTRACT_H
3   -
4   -#include "../Common/TREPSTypes.h"
5   -#include "../Application/Application.h"
6   -#include "../DataRecord/DataRecordList.h"
7   -#include "../FrameManager/FrameManager.h"
8   -
9   -using namespace TREPS::Common;
10   -using namespace TREPS::Application;
11   -using namespace TREPS::DataRecord;
12   -using namespace TREPS::FrameManager;
13   -
14   -namespace TREPS
15   -{
16   - namespace File
17   - {
18   - class FileLoaderAbstractClass
19   - {
20   - public :
21   - FileLoaderAbstractClass(void);
22   -
23   - virtual ~FileLoaderAbstractClass(void) = 0;
24   -
25   - //open a file
26   - virtual bool open(const char *file_path) = 0;
27   -
28   - //close a file
29   - virtual bool close(void) = 0;
30   -
31   - //test if a file is opened
32   - virtual bool isOpened(void) = 0;
33   -
34   - //return file format
35   - virtual t_FileFormat getFormat(void) = 0;
36   -
37   - //return detected frames list
38   - virtual t_StringList getFrames(const t_FieldList *fields) = 0;
39   -
40   - //return number of records
41   - virtual long int getNbRecords(void) = 0;
42   -
43   - //return file fields list
44   - virtual t_FieldList getFields(long int nbRecords) = 0;
45   -
46   - //add some format specific vectors
47   - virtual void addSpecificFormatVectors(const t_FieldList *fields, t_VectorList &vectors) = 0;
48   -
49   - //return file attributes
50   - virtual map<string,string> getAttributes(void) = 0;
51   -
52   - //return file data
53   - virtual bool getData(int start, int limit, DataRecordListClass *data, int &total) = 0;
54   -
55   - //get file information
56   - bool getInfo(t_FileInfo &fileInfo);
57   -
58   - protected :
59   - ApplicationClass *app;
60   -
61   - //Frame manager used to check detected frames in files
62   - FrameManagerClass *frameMgr;
63   -
64   - //return vectors list
65   - t_VectorList getVectors(const t_FieldList *fields);
66   - };
67   - }
68   -}
69   -
70   -#endif
  1 +#ifndef FILELOADERABSTRACT_H
  2 +#define FILELOADERABSTRACT_H
  3 +
  4 +#include "../Common/TREPSTypes.h"
  5 +#include "../Application/Application.h"
  6 +#include "../DataRecord/DataRecordList.h"
  7 +#include "../FrameManager/FrameManager.h"
  8 +
  9 +using namespace TREPS::Common;
  10 +using namespace TREPS::Application;
  11 +using namespace TREPS::DataRecord;
  12 +using namespace TREPS::FrameManager;
  13 +
  14 +namespace TREPS
  15 +{
  16 + namespace File
  17 + {
  18 + class FileLoaderAbstractClass
  19 + {
  20 + public :
  21 + FileLoaderAbstractClass(void);
  22 +
  23 + virtual ~FileLoaderAbstractClass(void) = 0;
  24 +
  25 + //open a file
  26 + virtual bool open(const char *file_path) = 0;
  27 +
  28 + //close a file
  29 + virtual bool close(void) = 0;
  30 +
  31 + //test if a file is opened
  32 + virtual bool isOpened(void) = 0;
  33 +
  34 + //return file format
  35 + virtual t_FileFormat getFormat(void) = 0;
  36 +
  37 + //return detected frames list
  38 + virtual t_StringList getFrames(const t_FieldList *fields) = 0;
  39 +
  40 + //return number of records
  41 + virtual long int getNbRecords(void) = 0;
  42 +
  43 + //return file fields list
  44 + virtual t_FieldList getFields(long int nbRecords) = 0;
  45 +
  46 + //add some format specific vectors
  47 + virtual void addSpecificFormatVectors(const t_FieldList *fields, t_VectorList &vectors) = 0;
  48 +
  49 + //return file attributes
  50 + virtual map<string,string> getAttributes(void) = 0;
  51 +
  52 + //return file data
  53 + virtual bool getData(int start, int limit, DataRecordListClass *data, int &total) = 0;
  54 +
  55 + //get file information
  56 + bool getInfo(t_FileInfo &fileInfo);
  57 +
  58 + // 9763 - add message error to rise it to user
  59 + string getErrorMsg(void);
  60 +
  61 + protected :
  62 + ApplicationClass *app;
  63 +
  64 + //Frame manager used to check detected frames in files
  65 + FrameManagerClass *frameMgr;
  66 +
  67 + //return vectors list
  68 + t_VectorList getVectors(const t_FieldList *fields);
  69 +
  70 +
  71 + // 9763 - add message error to rise it to user
  72 + string errorMsg;
  73 +
  74 +
  75 + };
  76 + }
  77 +}
  78 +
  79 +#endif
... ...
server/kernel/src/File/FileLoaderManager.cpp
... ... @@ -58,26 +58,33 @@ namespace TREPS
58 58 return false;
59 59 }
60 60  
  61 +
61 62 //init the file loader in relation with the file format
62 63 t_FileFormat format = formatMgr->detectFileFormat(file_path);
63 64  
  65 +
64 66 delete formatMgr;
65 67  
66 68 switch (format)
67 69 {
68 70 case FF_ASCII :
  71 +
69 72 this->loader = new FileLoaderASCIIClass();
70 73 break;
71 74 case FF_VOTABLE :
  75 +
72 76 this->loader = new FileLoaderVOTableClass();
73 77 break;
74 78 case FF_NETCDF :
  79 +
75 80 this->loader = new FileLoaderNetCDFClass();
76 81 break;
77 82 case FF_CDF :
  83 +
78 84 this->loader = new FileLoaderCDFClass();
79 85 break;
80 86 default :
  87 +
81 88 this->errorMsg = "Unknown file format";
82 89 LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
83 90 return false;
... ... @@ -119,7 +126,9 @@ namespace TREPS
119 126 if (!res)
120 127 {
121 128 this->errorMsg = "Cannot get file info. Unable to load the file structure.";
122   - LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg);
  129 + // 9763 - add message error to rise it to user
  130 + this->errorMsg = this->errorMsg + "\n<br>" + this->loader->getErrorMsg();
  131 + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg );
123 132 }
124 133  
125 134 return res;
... ...