导出资源到简道云的需求,需要支持文件在【文件导出到服务器】系统选项中新增自定义的文件服务器类型。
位置 | smartbi.module.export.store.IFileManagerStore |
父类 | smartbi.module.export.offline.storer.IOfflineFileStorer smartbi.module.export.offline.downloader.IOfflineDownloader |
功能 | 定义一个文件服务器 |
InputStream download(String filename)
功能 | 处理电子表格单元格格式为“文件”时,点击后触发的下载文件功能 |
参数说明 | filename:文件名称 |
返回值 | 输出流 |
void initServer(JSONObject serverConfig) throws Exception
功能 | 初始化服务器相关成员变量 |
参数说明 | serverConfig:服务器配置 |
返回值 | 无 |
PS. serverConfig调用者会获取系统选项【SPREAD_SHEET_REPORT_WRITEBACK_FILE】中的单个json对象,然后往这个json对象中添加一个“offlineDirectory”键用于记录当前导出的目录,需要注意两个场景:
场景一:在执行产品内置的在线导出、离线导出情况下,这个offlineDirectory为系统选项【OFFLINE_FILE_DIRECTORY】中的值;
场景二:因电子表格单元格回写和单元格格式设置为“文件”格式触发的下载时,这个offlineDirectory为配置“填报属性”时设置的“相对路径”:
以产品内置的“服务器”类型为例,则这个serverConfig的内容示例如下:
{ "name": "111", "addressType": "fileSystem", "address": "E:/temp_csv_xml_files", "account": "server-account", "id": "dialogCB2CE5E473D00001C6CD1E80E7B01FBD", "password": "server-password", "offlineDirectory": "/test", } |
boolean testConnection(String address, String account, String password) throws Exception
功能 | “文件存储位置设置”中点击“测试连接”时,最终执行的方法 |
参数说明 | address 服务器地址 account 用户名 password 密码(前端输入的明文) |
返回值 | 连接成功:true;连接失败:false |
boolean existFile(String subDirectory, String fileName) throws Exception
功能 | 使用于电子表格回写上传文件的场景,用于判断文件是否存在 |
参数说明 | subDirectory:“填报属性”中设置的“相对路径”; fileName:文件名 |
返回值 | 文件存在:true;文件不存在:false |
void download(HttpServletRequest request, HttpServletResponse response, String filename) throws Exception;
功能 | 在线导出和离线导出时调用,从当前服务器中下载filename文件到HttpServletResponse的输出流 |
参数说明 | request:请求; response:响应; filename:文件名(含后缀) |
返回值 | 文件存在:true;文件不存在:false |
备注 | 继承自 smartbi.module.export.offline.downloader.IOfflineDownloader |
void download(HttpServletRequest request, HttpServletResponse response, String filename, String downloadName) throws Exception;
功能 | 在线导出和离线导出时调用,从当前服务器中下载filename文件到HttpServletResonse的输出流并指定文件名为downloadName |
参数说明 | request:请求; response:响应; filename:文件名(含后缀); downloadName:下载后的文件名(含后缀) |
返回值 | 无 |
备注 | 继承自 smartbi.module.export.offline.downloader.IOfflineDownloader |
double getProcess()
功能 | 获取下载进度,一般在实现时直接返回0.001即可 |
参数说明 | 无 |
返回值 | 无 |
备注 | 继承自 smartbi.module.export.offline.downloader.IOfflineDownloader |
String getId()
功能 | 获取文件存储位置id,也就是serverConfig中“id”字段对应的值 |
参数说明 | 无 |
返回值 | 无 |
备注 | 继承自 smartbi.module.export.offline.downloader.IOfflineFileStorer |
String getDirectory()
功能 | 获取文件存储目录 |
参数说明 | 无 |
返回值 | 文件存储目录 |
备注 | 继承自 smartbi.module.export.offline.downloader.IOfflineFileStorer |
boolean store(File tempFile)
功能 | 电子表格回写、离线导出时,上传(保存)文件到服务器中 |
参数说明 | tempFile:临时文件 |
返回值 | 上传成功:true;上传失败:false |
备注 | 继承自 smartbi.module.export.offline.downloader.IOfflineFileStorer |
boolean unstore(String name)
功能 | 删除服务器中的文件 |
参数说明 | name:文件名(含后缀) |
返回值 | 删除成功:true;删除失败:false |
备注 | 继承自 smartbi.module.export.offline.downloader.IOfflineFileStorer |
void init()
功能 | 上传文件前调用者会执行的服务器初始化动作,一般用于创建目录 |
参数说明 | 无 |
返回值 | 无 |
备注 | 继承自 smartbi.module.export.offline.downloader.IOfflineFileStorer |
在线导出、离线导出后的下载
iFileManagerStore.initServer(config); iFileManagerStore.download(request, response, fileName, downloadName); |
离线导出导致的上传
iFileManagerStore.initServer(config); // 存储前,会调用init方法 iFileManagerStore.init(); iFileManagerStore.store(request, response, fileName, downloadName); |
电子表格单元格格式设置为“文件”时导致的下载
iFileManagerStore.initServer(config); iFileManagerStore.download(filename); |
电子表格单元格回写导致的上传
iFileManagerStore.initServer(config); //existFile返回结果仅用于处理最终上传的文件名,不影响后续的下载动作 iFileManagerStore.existFile(subdirectory, fileName); // 存储前,会调用init方法 iFileManagerStore.init(); iFileManagerStore.store(tempFile) |
文件删除
iFileManagerStore.initServer(config); // 删除前,需要调用init方法 iFileManagerStore.unstore(filename); |
位置:smartbi.module.export.store.IFileManagerStore
功能描述:用于注册IFileManagerStore的实现类
成员变量:Map<String, IFileManagerStore> handlers ,IFileManagerStore实际存储的容器
成员方法说明:
方法名 | 功能 | 输入 | 输出 |
getInstance() | 返回IFileManagerFactory单例. | 无 | IFileManagerFactory |
registerFileManagerStoreHandlerIfNotExist(String handlerName, IFileManagerStore handler) | 注册一个文件系统,handlerName为这IFileManagerStore 对应服务器类型的键名。如果注册时已经存在同名对象,则不进行注册。 | handlerName:服务器类型名 handler:自定义的服务器实现类 | 无 |
registerEncryptHandlerForce(String handlerName, IFileManagerStore handler) | 注册一个文件系统,handlerName为这IFileManagerStore 对应服务器类型的键名。如果注册时已经存在同名对象,会覆盖式注册。 | handlerName:服务器类型名 handler:自定义的服务器实现类 | 无 |
etEncryptHandler(String handlerName) | 根据handlerName从handlers 中获取一个对应的文件服务器对象。不存在时返回空。 | handlerName:服务器类型名 | IFileManagerStore |
getRegistedServerKeys() | 获取所有注册的键名。 | 无 | Set<String> |
SpreadsheetReportWriteBackFileSettingDialog.js 新增两个方法
handleBeforeShowUp(obj,tline)
说明 | 在“文件存储位置设置”中,在每一条服务器记录被渲染到前端之前,执行此方法可以进行一些前置操作。 |
入参 | obj:最终渲染到前端的某一行数据(数组形式); tline:当前这一行的原始数据(数组形式) |
输出 | 无 |
handleBeforeWriteBack(obj,ctl)
说明 | 在点击保存之后,数据传入后端进行保存之前,执行此方法可以进行一些前置操作。 |
入参 | obj:最终写入知识库的某一行数据(对象形式);ctl:当前这一行的原始数据(数组形式) |
输出 | 无 |
FTPRemovableGrid.js 新增一个方法
说明 | 测试连接前执行的操作,用于复制服务器配置信息。 |
入参 | configObj:服务器配置信息(对象形式) currentTableLine:当前行的原始数据(数组形式) |
输出 | 无 |
public class CustomManagerStore implements IFileManagerStore{ //实现接口相关方法处理服务器逻辑 } |
IFileManagerFactory.getInstance().registerFileManagerStoreHandlerIfNotExist("MyFileSystem",new JDYFileManagerStore()); |
SpreadsheetReportWriteBackFileSettingDialog.prototype.getType_SMS_61642 = SpreadsheetReportWriteBackFileSettingDialog.prototype.getType; SpreadsheetReportWriteBackFileSettingDialog.prototype.getType = function(options){ this.getType_SMS_61642(options); //遍历options,将指定键名国际化处理 for(var i=0;i<options.length;i++){ if(options[i].value === "MyFileSystem"){ options[i].text = "自定义文件系统"; options[i].value = "自定义文件系统"; break; } } } SpreadsheetReportWriteBackFileSettingDialog.prototype.handleBeforeWriteBack_SMS_61642 = SpreadsheetReportWriteBackFileSettingDialog.prototype.handleBeforeWriteBack SpreadsheetReportWriteBackFileSettingDialog.prototype.handleBeforeWriteBack = function (obj,ctl) { this.handleBeforeWriteBack_SMS_61642(obj,ctl) if(obj.addressType ==="自定义文件系统"){ obj.addressType ="MyFileSystem"; } } SpreadsheetReportWriteBackFileSettingDialog.prototype.handleBeforeShowUp_SMS_61642 = SpreadsheetReportWriteBackFileSettingDialog.prototype.handleBeforeShowUp SpreadsheetReportWriteBackFileSettingDialog.prototype.handleBeforeShowUp = function (array,tline){ this.handleBeforeShowUp_SMS_61642(array,tline); if(array[1]==="MyFileSystem"){ array[1]="自定义文件系统"; } } |
FTPRemovableGrid.prototype.handleBeforeTestConnection_SMS_61642 = FTPRemovableGrid.prototype.handleBeforeTestConnection FTPRemovableGrid.prototype.handleBeforeTestConnection = function(configObj,currentTableLine){ this.handleBeforeTestConnection_SMS_61642(configObj,currentTableLine); if("自定义文件系统" === configObj.serverType){ configObj.serverType = "MyFileSystem"; } } |
扩展包示例: