From 52e364426a2fdb01417eabbcf5af1913f9b24725 Mon Sep 17 00:00:00 2001 From: Laurent BEIGBEDER Date: Wed, 18 Dec 2024 15:52:43 +0100 Subject: [PATCH] 9763: HAPI access fixed --- ihm/app/controller/Steps/SourceSelectionStep.js | 629 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- server/kernel/src/File/FileLoaderASCII.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++------ server/kernel/src/File/FileLoaderAbstract.cpp | 218 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------- server/kernel/src/File/FileLoaderAbstract.h | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------- server/kernel/src/File/FileLoaderManager.cpp | 11 ++++++++++- 5 files changed, 577 insertions(+), 481 deletions(-) diff --git a/ihm/app/controller/Steps/SourceSelectionStep.js b/ihm/app/controller/Steps/SourceSelectionStep.js index 8158aee..9878081 100644 --- a/ihm/app/controller/Steps/SourceSelectionStep.js +++ b/ihm/app/controller/Steps/SourceSelectionStep.js @@ -1,299 +1,330 @@ -Ext.define('treps.controller.Steps.SourceSelectionStep', { - extend: 'treps.controller.Steps.BaseStep', - - views: [ - 'Steps.SourceSelection.SourceSelectionPanel' - ], - - requires: [ - 'treps.controller.SAMP.SAMPManager' - ], - - sampButtonSelector : 'sourceselection_panel > panel > sampdata_panel > sampconnect_button', - - sampClientsDataViewSelector : 'sourceselection_panel > panel > sampdata_panel > sampclients_dataview', - - localFileSelector : 'sourceselection_panel > panel > localfile_panel > filefield', - - refs: [ - { - ref: 'sourceSelectionPanel', - selector: 'sourceselection_panel' - }, - { - ref: 'filefield', - selector: 'filedropzone' - } - ], - - init: function() { - var me = this; - - this.ref( - [ - { - ref: 'sampConnectButton', - selector: this.sampButtonSelector - }, - { - ref: 'sampClientsDataView', - selector: this.sampClientsDataViewSelector - } - ] - ); - - var c = {}; - c[this.sampButtonSelector] = { - click : me.onChangeSampConnection, - scope : me - }; - - - c[this.localFileSelector] = { - change : me.onSelectLocalFile, - scope : me - }; - - this.control(c); - - - this.application.on( - { - samp_connect: me.updateSAMPConnection, - scope: me - } - ); - - this.application.on( - { - samp_disconnect: me.updateSAMPConnection, - scope: me - } - ); - - this.application.on( - { - samp_clients: me.updateSAMPClients, - scope: me - } - ); - }, - - getCrtPanel: function() { - var mainPanel = this.getSourceSelectionPanel(); - return mainPanel.child("[collapsed=false]").child("panel"); - }, - - onChangeSampConnection: function() - { - var sampManager = treps.controller.SAMP.SAMPManager; - - if (!sampManager.isConnected()) - sampManager.connect(); - else - sampManager.disconnect(); - }, - - onSelectLocalFile : function() - { - treps.getApplication().fireEvent('receivesource',null,null); - }, - - updateSAMPConnection: function() - { - var sampManager = treps.controller.SAMP.SAMPManager; - var sampButton = this.getSampConnectButton(); - - if (sampButton == null) - return; - - var connected = sampManager.isConnected(); - - if (connected) - { - sampButton.setText('Disconnect to hub'); - sampButton.setIconCls('icons-24x24-disconnect'); - } - else - { - sampButton.setText('Connect to hub'); - sampButton.setIconCls('icons-24x24-connect'); - } - - }, - - updateSAMPClients: function() - { - var sampManager = treps.controller.SAMP.SAMPManager; - var clientsStore = sampManager.getClientsStore(); - var clientsDataView = this.getSampClientsDataView(); - - if (clientsDataView == null) - return; - - if (clientsDataView.getStore().storeId != clientsStore.storeId) - clientsDataView.bindStore(clientsStore); - }, - - doInitStep: function() { - var editController = treps.app.getController('Data.Edit.EditDataGrid'); - editController.clearStore(); - var dropController = treps.app.getController('Drop.FileDrop'); - this.updateSAMPConnection(); - this.updateSAMPClients(); - }, - - isValidStep: function() { - var me = this; - var crtPanel = this.getCrtPanel(); - - var editController = treps.app.getController('Data.Edit.EditDataGrid'); - - if (crtPanel == null) - return false; - - switch (crtPanel.xtype) - { - case 'localfile_panel': - if (!crtPanel.isValid()) - { - treps.Messages.showError("Validation error. Cannot submit the request."); - return false; - } - break; - case 'sampdata_panel': - treps.Messages.showInfo("Please send data with a SAMP notification."); - return false; - case 'webfile_panel': - if (!crtPanel.isValid()) - { - treps.Messages.showError("Validation error. Cannot submit the request."); - return false; - } - break; - case 'manualdata_panel': - if (!editController.isValid()) - { - treps.Messages.showInfo("Validation error. Cannot submit the request."); - return false; - } - break; - } - - return true; - }, - - doRequest: function(afterrequest,type,data) { - var me = this; - var crtPanel = this.getCrtPanel(); - if (crtPanel == null) - return false; - - var editController = treps.app.getController('Data.Edit.EditDataGrid'); - - //reinit source selection - var session = treps.model.Session; - //session.set('in_filenameBase',null); - - //on SAMP notification or drag & drop selection - if ((type != null) && (data != null)) - { - me.callRequest(type,data,afterrequest); - return; - } - - switch (crtPanel.xtype) - { - case 'localfile_panel': - crtPanel.getForm().submit( - { - url: treps.Constants.PHP_DIR+'UploadFile.php', - waitMsg: 'Uploading your file...', - timeout: 120000, - success: function(form, action) { - //save input file name, removing first random generated chars - //redmine 6610 - var filenameBase = action.result.fileName.substring( - action.result.fileName.indexOf("_",11)+1, - action.result.fileName.lastIndexOf('.')); - //console.log('localfile_panel filename2: '+filenameBase); - treps.model.Session.set('in_filenameBase',filenameBase); - me.callRequest('local',action.result.fileName,afterrequest); - }, - failure: function(form, action) - { - treps.LoadMask.hide(); - - switch (action.failureType) - { - case Ext.form.action.Action.CLIENT_INVALID: - treps.Messages.showError('Form fields may not be submitted with invalid values'); - break; - case Ext.form.action.Action.CONNECT_FAILURE: - treps.Messages.showError('Ajax communication failed'); - break; - case Ext.form.action.Action.SERVER_INVALID: - if (!action.result) - treps.Messages.showError("Internal error during UploadFile request"); - else - treps.Messages.showError(action.result.error); - break; - default: - treps.Messages.showError('Unknown error'); - } - afterrequest.call(me,false); - - } - } - ); - break; - case 'sampdata_panel': - //nothing to do - break; - case 'webfile_panel': - var url = crtPanel.child("textfield").getRawValue(); - var filenameBase = url.substring( - action.result.fileName.lastIndexOf("_",11)+1, - action.result.fileName.lastIndexOf('.')); - me.callRequest('url',url,afterrequest); - break; - case 'manualdata_panel': - var data = editController.getData(); - me.callRequest('data',data,afterrequest); - break; - } - }, - - callRequest : function(type, location, afterrequest) - { - var me = this; - treps.LoadMask.show("Get source data. Please Wait ..."); - TREPSAction.startNewOperation({'type' : type, 'data' : location}, function(result, event) - { - treps.LoadMask.hide(); - // console.log('callRequestlocation: '+location); - - if (!result) - { - treps.Messages.showError("Internal error during startNewOperation request"); - afterrequest.call(me,false); - return; - } - else if (!result.success) - { - treps.Messages.showError(result.error); - afterrequest.call(me,false); - return; - } - - var session_id = result.id; - - - treps.model.Session.set('id',session_id); - - - afterrequest.call(me,true); - } - ); - } -}); +Ext.define('treps.controller.Steps.SourceSelectionStep', { + extend: 'treps.controller.Steps.BaseStep', + + views: [ + 'Steps.SourceSelection.SourceSelectionPanel' + ], + + requires: [ + 'treps.controller.SAMP.SAMPManager' + ], + + sampButtonSelector : 'sourceselection_panel > panel > sampdata_panel > sampconnect_button', + + sampClientsDataViewSelector : 'sourceselection_panel > panel > sampdata_panel > sampclients_dataview', + + localFileSelector : 'sourceselection_panel > panel > localfile_panel > filefield', + + refs: [ + { + ref: 'sourceSelectionPanel', + selector: 'sourceselection_panel' + }, + { + ref: 'filefield', + selector: 'filedropzone' + } + ], + + init: function() { + var me = this; + + this.ref( + [ + { + ref: 'sampConnectButton', + selector: this.sampButtonSelector + }, + { + ref: 'sampClientsDataView', + selector: this.sampClientsDataViewSelector + } + ] + ); + + var c = {}; + c[this.sampButtonSelector] = { + click : me.onChangeSampConnection, + scope : me + }; + + + c[this.localFileSelector] = { + change : me.onSelectLocalFile, + scope : me + }; + + this.control(c); + + + this.application.on( + { + samp_connect: me.updateSAMPConnection, + scope: me + } + ); + + this.application.on( + { + samp_disconnect: me.updateSAMPConnection, + scope: me + } + ); + + this.application.on( + { + samp_clients: me.updateSAMPClients, + scope: me + } + ); + }, + + getCrtPanel: function() { + var mainPanel = this.getSourceSelectionPanel(); + return mainPanel.child("[collapsed=false]").child("panel"); + }, + + onChangeSampConnection: function() + { + var sampManager = treps.controller.SAMP.SAMPManager; + + if (!sampManager.isConnected()) + sampManager.connect(); + else + sampManager.disconnect(); + }, + + onSelectLocalFile : function() + { + treps.getApplication().fireEvent('receivesource',null,null); + }, + + updateSAMPConnection: function() + { + var sampManager = treps.controller.SAMP.SAMPManager; + var sampButton = this.getSampConnectButton(); + + if (sampButton == null) + return; + + var connected = sampManager.isConnected(); + + if (connected) + { + sampButton.setText('Disconnect to hub'); + sampButton.setIconCls('icons-24x24-disconnect'); + } + else + { + sampButton.setText('Connect to hub'); + sampButton.setIconCls('icons-24x24-connect'); + } + + }, + + updateSAMPClients: function() + { + var sampManager = treps.controller.SAMP.SAMPManager; + var clientsStore = sampManager.getClientsStore(); + var clientsDataView = this.getSampClientsDataView(); + + if (clientsDataView == null) + return; + + if (clientsDataView.getStore().storeId != clientsStore.storeId) + clientsDataView.bindStore(clientsStore); + }, + + doInitStep: function() { + var editController = treps.app.getController('Data.Edit.EditDataGrid'); + editController.clearStore(); + var dropController = treps.app.getController('Drop.FileDrop'); + this.updateSAMPConnection(); + this.updateSAMPClients(); + }, + + isValidStep: function() { + var me = this; + var crtPanel = this.getCrtPanel(); + + var editController = treps.app.getController('Data.Edit.EditDataGrid'); + + if (crtPanel == null) + return false; + + switch (crtPanel.xtype) + { + case 'localfile_panel': + if (!crtPanel.isValid()) + { + treps.Messages.showError("Validation error. Cannot submit the request."); + return false; + } + break; + case 'sampdata_panel': + treps.Messages.showInfo("Please send data with a SAMP notification."); + return false; + case 'webfile_panel': + if (!crtPanel.isValid()) + { + treps.Messages.showError("Validation error. Cannot submit the request."); + return false; + } + break; + case 'manualdata_panel': + if (!editController.isValid()) + { + treps.Messages.showInfo("Validation error. Cannot submit the request."); + return false; + } + break; + } + + return true; + }, + + doRequest: function(afterrequest,type,data) { + var me = this; + var crtPanel = this.getCrtPanel(); + if (crtPanel == null) + return false; + + var editController = treps.app.getController('Data.Edit.EditDataGrid'); + + //reinit source selection + var session = treps.model.Session; + //session.set('in_filenameBase',null); + + //on SAMP notification or drag & drop selection + if ((type != null) && (data != null)) + { + me.callRequest(type,data,afterrequest); + return; + } + + switch (crtPanel.xtype) + { + case 'localfile_panel': + crtPanel.getForm().submit( + { + url: treps.Constants.PHP_DIR+'UploadFile.php', + waitMsg: 'Uploading your file...', + timeout: 120000, + success: function(form, action) { + //save input file name, removing first random generated chars + //redmine 6610 + var filenameBase = action.result.fileName.substring( + action.result.fileName.indexOf("_",11)+1, + action.result.fileName.lastIndexOf('.')); + //console.log('localfile_panel filename2: '+filenameBase); + treps.model.Session.set('in_filenameBase',filenameBase); + me.callRequest('local',action.result.fileName,afterrequest); + }, + failure: function(form, action) + { + treps.LoadMask.hide(); + + switch (action.failureType) + { + case Ext.form.action.Action.CLIENT_INVALID: + treps.Messages.showError('Form fields may not be submitted with invalid values'); + break; + case Ext.form.action.Action.CONNECT_FAILURE: + treps.Messages.showError('Ajax communication failed'); + break; + case Ext.form.action.Action.SERVER_INVALID: + if (!action.result) + treps.Messages.showError("Internal error during UploadFile request"); + else + treps.Messages.showError(action.result.error); + break; + default: + treps.Messages.showError('Unknown error'); + } + afterrequest.call(me,false); + + } + } + ); + break; + case 'sampdata_panel': + //nothing to do + break; + case 'webfile_panel': + var url = crtPanel.child("textfield").getRawValue(); + + + // 9763 11621 : Uncaught ReferenceError: action is not defined + //var filenameBase = url.substring( + // action.result.fileName.lastIndexOf("_",11)+1, + // action.result.fileName.lastIndexOf('.')); + + const urlObject = new URL(url); + const hostname = urlObject.hostname; + const siteName = hostname.replace(/\./g, '-'); + //const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); + //const filenameBase = `${siteName}_${timestamp}.txt`; + const filenameBase = `${siteName}`; + //console.log('- url:' + url); + //console.log('- filenameBase:' + filenameBase); + url = me.encodeHtml(url); + // 9763 11621 + + treps.model.Session.set('in_filenameBase',filenameBase); + me.callRequest('url',url,afterrequest); + break; + case 'manualdata_panel': + var data = editController.getData(); + me.callRequest('data',data,afterrequest); + break; + } + }, + + callRequest : function(type, location, afterrequest) + { + var me = this; + treps.LoadMask.show("Get source data. Please Wait ..."); + + TREPSAction.startNewOperation({'type' : type, 'data' : location}, function(result, event) + { + treps.LoadMask.hide(); + // console.log('callRequestlocation: '+location); + + if (!result) + { + treps.Messages.showError("Internal error during startNewOperation request"); + afterrequest.call(me,false); + return; + } + else if (!result.success) + { + treps.Messages.showError(result.error); + afterrequest.call(me,false); + return; + } + + var session_id = result.id; + + + treps.model.Session.set('id',session_id); + + + afterrequest.call(me,true); + } + ); + }, + + + // 9763 11621 + encodeHtml: function(text) { + return text + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} + + + +}); diff --git a/server/kernel/src/File/FileLoaderASCII.cpp b/server/kernel/src/File/FileLoaderASCII.cpp index 6483a88..1be3e99 100644 --- a/server/kernel/src/File/FileLoaderASCII.cpp +++ b/server/kernel/src/File/FileLoaderASCII.cpp @@ -64,14 +64,34 @@ namespace TREPS if (!this->getNextDataLine()) return fields; + + //9763 check if delimiter is ',' + this->resetLine(); + this->getNextDataLine(); + string lTmp = *this->crtLine; + bool isCommaDelimiter = false; + + if(lTmp.find(",") != std::string::npos){ + isCommaDelimiter = true; + this->errorMsg = "Unknown delimiter, only space or tab characters are recognized."; + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg); + return fields; + } + this->resetLine(); + //9763 check if delimiter is ',' + + + stringstream ss(*(this->crtLine)); string entry; t_Field crtField; int index = 0; - while (ss >> entry) - { + + + while (ss >> entry) + { //create new fields crtField.id = intToStr(index); crtField.name = "Field_"; @@ -87,8 +107,10 @@ namespace TREPS fields.push_back(crtField); ++index; - } - + } + + + return fields; } @@ -241,8 +263,24 @@ namespace TREPS total = 0; + + //9763 check if delimiter is ',' + this->getNextDataLine(); + string lTmp = *this->crtLine; + bool isCommaDelimiter = false; + + if(lTmp.find(",") != std::string::npos){ + isCommaDelimiter = true; + this->errorMsg = "Unknown delimiter, only space or tab characters are recognized."; + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg); + return false; + } + this->resetLine(); + //9763 check if delimiter is ',' + while (this->getNextDataLine()) { + if (!getall && (total < start)) { total++; @@ -251,17 +289,18 @@ namespace TREPS if (getall || (total < start + limit)) { + stringstream ss(*this->crtLine); string entry; DataRecordClass *newRec = data->addNew(); - int crtId = 0; + int crtId = 0; while (ss >> entry) { newRec->setValue(intToStr(crtId).c_str(), entry.c_str()); ++crtId; - } + } } total++; diff --git a/server/kernel/src/File/FileLoaderAbstract.cpp b/server/kernel/src/File/FileLoaderAbstract.cpp index c8e9fd7..8421f24 100644 --- a/server/kernel/src/File/FileLoaderAbstract.cpp +++ b/server/kernel/src/File/FileLoaderAbstract.cpp @@ -1,105 +1,113 @@ -#include "FileLoaderAbstract.h" - -#include "../Common/Toolbox.h" - -using namespace TREPS::Common; - -namespace TREPS -{ - namespace File - { - FileLoaderAbstractClass::FileLoaderAbstractClass(void) : app(NULL), frameMgr(NULL) - { - this->app = ApplicationClass::getInstance(); - - this->frameMgr = new FrameManagerClass(); - } - - FileLoaderAbstractClass::~FileLoaderAbstractClass(void) - { - if (this->frameMgr != NULL) - { - delete this->frameMgr; - this->frameMgr = NULL; - } - } - - bool FileLoaderAbstractClass::getInfo(t_FileInfo &info) - { - info.format = this->getFormat(); - - //get frames list file path - string framesPath = this->app->getConf()->getFramesFilePath(); - - if (framesPath.compare("") != 0) - //init frame manager - frameMgr->init(framesPath.c_str()); - - //get nb of records - info.nbRecords = this->getNbRecords(); - - //get fields - info.fields = this->getFields(info.nbRecords); - - //detect frames - info.frames = this->getFrames(&info.fields); - - //detect vectors - info.vectors = this->getVectors(&info.fields); - - //get file attributes - info.attributes = this->getAttributes(); - - return (!info.fields.empty()); - } - - t_VectorList FileLoaderAbstractClass::getVectors(const t_FieldList *fields) - { - //get common vectors - t_VectorList vectors; - vectors.clear(); - - int vecIndex = 0; - for (t_FieldList::const_iterator field = fields->begin(); field != fields->end(); ++field) - { - //a string field or a time field cannot be considerate as a vector - if (((*field).type == FT_UNKNOWN) || ((*field).type == FT_TIME)) - continue; - //no dimension => it's a scalar - if ((*field).dims.empty()) - continue; - //more than one dimension => it's not a vector - if ((*field).dims.size() > 1) - continue; - //if the dimension size is 3 => it's a vector - if ((*field).dims.begin()->size == 3) - { - //use the field id for the vector id - t_Vector vec; - vec.id = "v_"; - vec.id += intToStr(vecIndex); - - //define the 3 components - vec.fieldId[0] = (*field).id; - vec.fieldId[0] += "_TREPSID0"; - - vec.fieldId[1] = (*field).id; - vec.fieldId[1] += "_TREPSID1"; - - vec.fieldId[2] = (*field).id; - vec.fieldId[2] += "_TREPSID2"; - - vec.nbRecords = (*field).nbRecords; - - vectors.push_back(vec); - ++vecIndex; - } - } - - //add specific possibility to define a vector for a format file - this->addSpecificFormatVectors(fields, vectors); - - return vectors; - } - } -} +#include "FileLoaderAbstract.h" + +#include "../Common/Toolbox.h" + +using namespace TREPS::Common; + +namespace TREPS +{ + namespace File + { + FileLoaderAbstractClass::FileLoaderAbstractClass(void) : app(NULL), frameMgr(NULL) + { + this->app = ApplicationClass::getInstance(); + + this->frameMgr = new FrameManagerClass(); + } + + FileLoaderAbstractClass::~FileLoaderAbstractClass(void) + { + if (this->frameMgr != NULL) + { + delete this->frameMgr; + this->frameMgr = NULL; + } + } + + bool FileLoaderAbstractClass::getInfo(t_FileInfo &info) + { + info.format = this->getFormat(); + + //get frames list file path + string framesPath = this->app->getConf()->getFramesFilePath(); + + if (framesPath.compare("") != 0) + //init frame manager + frameMgr->init(framesPath.c_str()); + + //get nb of records + info.nbRecords = this->getNbRecords(); + + //get fields + info.fields = this->getFields(info.nbRecords); + + //detect frames + info.frames = this->getFrames(&info.fields); + + //detect vectors + info.vectors = this->getVectors(&info.fields); + + //get file attributes + info.attributes = this->getAttributes(); + + return (!info.fields.empty()); + } + + t_VectorList FileLoaderAbstractClass::getVectors(const t_FieldList *fields) + { + //get common vectors + t_VectorList vectors; + vectors.clear(); + + int vecIndex = 0; + for (t_FieldList::const_iterator field = fields->begin(); field != fields->end(); ++field) + { + //a string field or a time field cannot be considerate as a vector + if (((*field).type == FT_UNKNOWN) || ((*field).type == FT_TIME)) + continue; + //no dimension => it's a scalar + if ((*field).dims.empty()) + continue; + //more than one dimension => it's not a vector + if ((*field).dims.size() > 1) + continue; + //if the dimension size is 3 => it's a vector + if ((*field).dims.begin()->size == 3) + { + //use the field id for the vector id + t_Vector vec; + vec.id = "v_"; + vec.id += intToStr(vecIndex); + + //define the 3 components + vec.fieldId[0] = (*field).id; + vec.fieldId[0] += "_TREPSID0"; + + vec.fieldId[1] = (*field).id; + vec.fieldId[1] += "_TREPSID1"; + + vec.fieldId[2] = (*field).id; + vec.fieldId[2] += "_TREPSID2"; + + vec.nbRecords = (*field).nbRecords; + + vectors.push_back(vec); + ++vecIndex; + } + } + + //add specific possibility to define a vector for a format file + this->addSpecificFormatVectors(fields, vectors); + + return vectors; + } + + + // 9763 - add message error to rise it to user + string FileLoaderAbstractClass::getErrorMsg(void) + { + return this->errorMsg; + } + + } +} diff --git a/server/kernel/src/File/FileLoaderAbstract.h b/server/kernel/src/File/FileLoaderAbstract.h index 6f2bd3b..a607c84 100644 --- a/server/kernel/src/File/FileLoaderAbstract.h +++ b/server/kernel/src/File/FileLoaderAbstract.h @@ -1,70 +1,79 @@ -#ifndef FILELOADERABSTRACT_H -#define FILELOADERABSTRACT_H - -#include "../Common/TREPSTypes.h" -#include "../Application/Application.h" -#include "../DataRecord/DataRecordList.h" -#include "../FrameManager/FrameManager.h" - -using namespace TREPS::Common; -using namespace TREPS::Application; -using namespace TREPS::DataRecord; -using namespace TREPS::FrameManager; - -namespace TREPS -{ - namespace File - { - class FileLoaderAbstractClass - { - public : - FileLoaderAbstractClass(void); - - virtual ~FileLoaderAbstractClass(void) = 0; - - //open a file - virtual bool open(const char *file_path) = 0; - - //close a file - virtual bool close(void) = 0; - - //test if a file is opened - virtual bool isOpened(void) = 0; - - //return file format - virtual t_FileFormat getFormat(void) = 0; - - //return detected frames list - virtual t_StringList getFrames(const t_FieldList *fields) = 0; - - //return number of records - virtual long int getNbRecords(void) = 0; - - //return file fields list - virtual t_FieldList getFields(long int nbRecords) = 0; - - //add some format specific vectors - virtual void addSpecificFormatVectors(const t_FieldList *fields, t_VectorList &vectors) = 0; - - //return file attributes - virtual map getAttributes(void) = 0; - - //return file data - virtual bool getData(int start, int limit, DataRecordListClass *data, int &total) = 0; - - //get file information - bool getInfo(t_FileInfo &fileInfo); - - protected : - ApplicationClass *app; - - //Frame manager used to check detected frames in files - FrameManagerClass *frameMgr; - - //return vectors list - t_VectorList getVectors(const t_FieldList *fields); - }; - } -} - -#endif +#ifndef FILELOADERABSTRACT_H +#define FILELOADERABSTRACT_H + +#include "../Common/TREPSTypes.h" +#include "../Application/Application.h" +#include "../DataRecord/DataRecordList.h" +#include "../FrameManager/FrameManager.h" + +using namespace TREPS::Common; +using namespace TREPS::Application; +using namespace TREPS::DataRecord; +using namespace TREPS::FrameManager; + +namespace TREPS +{ + namespace File + { + class FileLoaderAbstractClass + { + public : + FileLoaderAbstractClass(void); + + virtual ~FileLoaderAbstractClass(void) = 0; + + //open a file + virtual bool open(const char *file_path) = 0; + + //close a file + virtual bool close(void) = 0; + + //test if a file is opened + virtual bool isOpened(void) = 0; + + //return file format + virtual t_FileFormat getFormat(void) = 0; + + //return detected frames list + virtual t_StringList getFrames(const t_FieldList *fields) = 0; + + //return number of records + virtual long int getNbRecords(void) = 0; + + //return file fields list + virtual t_FieldList getFields(long int nbRecords) = 0; + + //add some format specific vectors + virtual void addSpecificFormatVectors(const t_FieldList *fields, t_VectorList &vectors) = 0; + + //return file attributes + virtual map getAttributes(void) = 0; + + //return file data + virtual bool getData(int start, int limit, DataRecordListClass *data, int &total) = 0; + + //get file information + bool getInfo(t_FileInfo &fileInfo); + + // 9763 - add message error to rise it to user + string getErrorMsg(void); + + protected : + ApplicationClass *app; + + //Frame manager used to check detected frames in files + FrameManagerClass *frameMgr; + + //return vectors list + t_VectorList getVectors(const t_FieldList *fields); + + + // 9763 - add message error to rise it to user + string errorMsg; + + + }; + } +} + +#endif diff --git a/server/kernel/src/File/FileLoaderManager.cpp b/server/kernel/src/File/FileLoaderManager.cpp index 875adc8..9249f32 100644 --- a/server/kernel/src/File/FileLoaderManager.cpp +++ b/server/kernel/src/File/FileLoaderManager.cpp @@ -58,26 +58,33 @@ namespace TREPS return false; } + //init the file loader in relation with the file format t_FileFormat format = formatMgr->detectFileFormat(file_path); + delete formatMgr; switch (format) { case FF_ASCII : + this->loader = new FileLoaderASCIIClass(); break; case FF_VOTABLE : + this->loader = new FileLoaderVOTableClass(); break; case FF_NETCDF : + this->loader = new FileLoaderNetCDFClass(); break; case FF_CDF : + this->loader = new FileLoaderCDFClass(); break; default : + this->errorMsg = "Unknown file format"; LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg); return false; @@ -119,7 +126,9 @@ namespace TREPS if (!res) { this->errorMsg = "Cannot get file info. Unable to load the file structure."; - LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg); + // 9763 - add message error to rise it to user + this->errorMsg = this->errorMsg + "\n
" + this->loader->getErrorMsg(); + LOG4CXX_ERROR(this->app->getLog()->getPtr(),this->errorMsg ); } return res; -- libgit2 0.21.2