Browse Source

REPORT-18400 报表API变更导致插件乱码问题

pull/1/head
richie 6 years ago
parent
commit
d1dac8bc6d
  1. 6
      build.xml
  2. 13
      plugin.xml
  3. 7
      pom.xml
  4. 8
      src/main/java/com/fr/plugin/file/download/oss/OssFile2Image.java
  5. 23
      src/main/java/com/fr/plugin/file/submit/oss/OssLifeCycleMonitor.java
  6. 8
      src/main/java/com/fr/plugin/file/submit/oss/fun/OssDownloadHttpHandler.java
  7. 16
      src/main/java/com/fr/plugin/file/submit/oss/fun/OssUpload.java
  8. 8
      src/main/java/com/fr/plugin/file/submit/oss/fun/OssUploadHttpHandler.java
  9. 8
      src/main/java/com/fr/plugin/file/submit/oss/job/OssSubmitJob.java
  10. 7
      src/main/java/com/fr/plugin/file/submit/oss/script/OssSubmitJavaScript.java
  11. 4
      src/main/java/com/fr/plugin/file/submit/oss/ui/OssHyperlink4DownloadPane.java
  12. 4
      src/main/java/com/fr/plugin/file/submit/oss/ui/OssSubmitPathTableModel.java
  13. 1
      src/main/resources/com/fr/plugin/file/submit/oss/submit.properties
  14. 1
      src/main/resources/com/fr/plugin/file/submit/oss/submit_zh_CN.properties
  15. 4
      src/main/resources/com/fr/plugin/file/submit/oss/web/oss.js

6
build.xml

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="plugin">
<!-- JDK路径,根据自己机器上实际位置修改-->
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home"/>
<property name="jdk.home" value="/Library/Java/OtherVirtualMachines/amazon-corretto-8/Contents/Home"/>
<property name="libs" value="${basedir}/lib"/>
<property name="dependenceLibs" value="${basedir}/lib/dependence"/>
<property name="publicLibs" value=""/>
<property name="reportLibs" value="${basedir}/../webroot/WEB-INF/lib"/>
<property name="destLoc" value="."/>
@ -33,6 +34,9 @@
<fileset dir="${reportLibs}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${dependenceLibs}">
<include name="**/*.jar"/>
</fileset>
</path>
<patternset id="resources4Jar">
<exclude name="**/.settings/**"/>

13
plugin.xml

@ -1,13 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.file.submit.oss</id>
<name><![CDATA[文件上传下载(OSS)]]></name>
<name><![CDATA[OSS文件上传下载]]></name>
<active>yes</active>
<version>2.5</version>
<version>4.2</version>
<env-version>10.0</env-version>
<jartime>2018-11-30</jartime>
<jartime>2019-06-13</jartime>
<vendor>author</vendor>
<description><![CDATA[文件上传至阿里云的OSS中。]]></description>
<dependence>
<item type="plugin" key="com.fr.plugin.oss.universal"/>
</dependence>
<change-notes><![CDATA[
[2019-06-21]适配最新的版本,修改下载乱码问题。<br/>
[2019-03-11]适配最新的10.0。<br/>
[2018-12-29]移除内置的OSS配置,依赖公共的OSS配置。<br/>
[2018-12-04]提供Oss的可视化配置界面。<br/>
[2018-11-26]修复文件名中包含特殊字符时无法下载的问题。<br/>
[2018-11-21]修复扩展单元格无法正确上传文件的问题。<br/>
@ -33,5 +39,4 @@
<HyperlinkProvider class="com.fr.plugin.file.submit.oss.OssHyperlink4Download"/>
</extra-designer>
<function-recorder class="com.fr.plugin.file.submit.oss.job.OssSubmitJob"/>
<lifecycle-monitor class="com.fr.plugin.file.submit.oss.OssLifeCycleMonitor"/>
</plugin>

7
pom.xml

@ -17,6 +17,13 @@
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.fr.plugin.oss</groupId>
<artifactId>oss-universal-config</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/dependence/fr-plugin-oss-universal-config-4.0.jar</systemPath>
</dependency>
</dependencies>
<build>
<!---如果要更改调试插件,改这里的配置就可以了-->

8
src/main/java/com/fr/plugin/file/download/oss/OssFile2Image.java

@ -5,7 +5,7 @@ import com.aliyun.oss.model.OSSObject;
import com.fr.general.GeneralUtils;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.oss.universal.config.OssUniversalConfig;
import com.fr.script.AbstractFunction;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Primitive;
@ -28,9 +28,9 @@ public class OssFile2Image extends AbstractFunction {
String key = GeneralUtils.objectToString(args[0]);
String bucket = GeneralUtils.objectToString(args[1]);
OSSClient ossClient = new OSSClient(
FileSubmitOssServerConfig.getInstance().getEndPoint(),
FileSubmitOssServerConfig.getInstance().getAccessKeyId(),
FileSubmitOssServerConfig.getInstance().getAccessKeySecret());
OssUniversalConfig.getInstance().getEndPoint(),
OssUniversalConfig.getInstance().getAccessKeyId(),
OssUniversalConfig.getInstance().getRealAccessKeySecret());
OSSObject object = ossClient.getObject(bucket, key);
byte[] bytes = IOUtils.inputStream2Bytes(object.getObjectContent());
try {

23
src/main/java/com/fr/plugin/file/submit/oss/OssLifeCycleMonitor.java

@ -1,23 +0,0 @@
package com.fr.plugin.file.submit.oss;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
/**
* @author richie
* @version 10.0
* Created by richie on 2018-12-04
*/
public class OssLifeCycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
// 只是为了初始化一下配置类
FileSubmitOssServerConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

8
src/main/java/com/fr/plugin/file/submit/oss/fun/OssDownloadHttpHandler.java

@ -5,7 +5,7 @@ import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
import com.fr.data.NetworkHelper;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.oss.universal.config.OssUniversalConfig;
import com.fr.stable.StableUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
@ -47,9 +47,9 @@ public class OssDownloadHttpHandler extends BaseHttpHandler {
private String createDownloadUrl(String bucket, String directory, String fileName) throws Exception {
// 创建OSSClient实例。
OSSClient ossClient = new OSSClient(
FileSubmitOssServerConfig.getInstance().getEndPoint(),
FileSubmitOssServerConfig.getInstance().getAccessKeyId(),
FileSubmitOssServerConfig.getInstance().getAccessKeySecret());
OssUniversalConfig.getInstance().getEndPoint(),
OssUniversalConfig.getInstance().getAccessKeyId(),
OssUniversalConfig.getInstance().getRealAccessKeySecret());
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, 1);

16
src/main/java/com/fr/plugin/file/submit/oss/fun/OssUpload.java

@ -4,7 +4,9 @@ import com.aliyun.oss.OSSClient;
import com.fr.cache.Attachment;
import com.fr.general.FArray;
import com.fr.general.GeneralUtils;
import com.fr.locale.InterProviderFactory;
import com.fr.script.Calculator;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.FRFile;
@ -16,7 +18,8 @@ public class OssUpload {
OssSubmitTarget[] submitTargets = submitTargetConfig.getSubmitTargets();
for (OssSubmitTarget target : submitTargets) {
OssVariableValue fileObject = target.getFile();
Object file = calculator.evalValue(GeneralUtils.objectToString(fileObject));
String filePath = GeneralUtils.objectToString(fileObject);
Object file = calculator.evalValue(filePath);
uploadFile(ossClient, target.getBucket(), file,
@ -27,7 +30,7 @@ public class OssUpload {
private static void uploadFile( OSSClient ossClient, String bucket, Object file, String directory, String newFileName) {
if (file instanceof FRFile) {
ossClient.putObject(bucket, directory + "/" + combineName(((FRFile) file).getFileName(), newFileName), new ByteArrayInputStream(((FRFile) file).getBytes()));
uploadSingleFile(ossClient, bucket, directory, combineName(((FRFile) file).getFileName(), newFileName), ((FRFile) file).getBytes());
} else if (file instanceof FArray && ((FArray) file).length() != 0) {
FArray array = (FArray)file;
for (int i = 0; i < array.length(); i++) {
@ -37,12 +40,19 @@ public class OssUpload {
uploadFile(ossClient, bucket, element, directory, newFileName);
}
} else {
ossClient.putObject(bucket, directory + "/" + combineName(((Attachment) element).getFilename(), newFileName), new ByteArrayInputStream(((Attachment) element).getBytes()));
uploadSingleFile(ossClient, bucket, directory, combineName(((Attachment) element).getFilename(), newFileName), ((Attachment) element).getBytes());
}
}
}
}
private static void uploadSingleFile(OSSClient ossClient, String bucket, String directory, String newFileName, byte[] bytes) {
if (ArrayUtils.isEmpty(bytes)) {
throw new RuntimeException(InterProviderFactory.getProvider().getLocText("Plugin-File_Submit_Oss_Failed", newFileName));
}
ossClient.putObject(bucket, directory + "/" + newFileName, new ByteArrayInputStream(bytes));
}
/*
* 这里的逻辑是
* 1如果没有设置文件名就用上传的文件的名字

8
src/main/java/com/fr/plugin/file/submit/oss/fun/OssUploadHttpHandler.java

@ -10,8 +10,8 @@ import com.fr.json.JSONArray;
import com.fr.json.JSONFactory;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.file.submit.oss.script.OssSubmitJavaScript;
import com.fr.plugin.oss.universal.config.OssUniversalConfig;
import com.fr.script.Calculator;
import com.fr.stable.ColumnRow;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
@ -60,9 +60,9 @@ public class OssUploadHttpHandler extends BaseHttpHandler {
boolean b = true;
final JSONObject jsonObject = JSONObject.create();
OSSClient ossClient = new OSSClient(
FileSubmitOssServerConfig.getInstance().getEndPoint(),
FileSubmitOssServerConfig.getInstance().getAccessKeyId(),
FileSubmitOssServerConfig.getInstance().getAccessKeySecret());
OssUniversalConfig.getInstance().getEndPoint(),
OssUniversalConfig.getInstance().getAccessKeyId(),
OssUniversalConfig.getInstance().getRealAccessKeySecret());
try {
this.process(ossClient, javaScript, calculator);
} catch (Exception ex) {

8
src/main/java/com/fr/plugin/file/submit/oss/job/OssSubmitJob.java

@ -5,12 +5,12 @@ import com.fr.data.AbstractSubmitTask;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.file.submit.oss.fun.OssConstants;
import com.fr.plugin.file.submit.oss.fun.OssSubmitTarget;
import com.fr.plugin.file.submit.oss.fun.OssSubmitTargetConfig;
import com.fr.plugin.file.submit.oss.fun.OssUpload;
import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
import com.fr.plugin.oss.universal.config.OssUniversalConfig;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.report.worksheet.CalculatableResWorkSheet;
import com.fr.script.Calculator;
@ -53,9 +53,9 @@ public class OssSubmitJob extends AbstractSubmitTask {
@Focus(id = "com.fr.plugin.file.submit.oss", text = "Plugin-File_Submit_OSS", source = Original.PLUGIN)
public void doJob(Calculator ca) throws Exception {
ossClient = new OSSClient(
FileSubmitOssServerConfig.getInstance().getEndPoint(),
FileSubmitOssServerConfig.getInstance().getAccessKeyId(),
FileSubmitOssServerConfig.getInstance().getAccessKeySecret());
OssUniversalConfig.getInstance().getEndPoint(),
OssUniversalConfig.getInstance().getAccessKeyId(),
OssUniversalConfig.getInstance().getRealAccessKeySecret());
CalculatableResWorkSheet currentReport = ca.getAttribute(DMLReport.KEY);
if (submitTargetConfig != null && currentReport != null) {
ColumnRow[] crs = calculateRelatedColumnRows(submitTargetConfig);

7
src/main/java/com/fr/plugin/file/submit/oss/script/OssSubmitJavaScript.java

@ -5,6 +5,7 @@ import com.fr.js.AbstractJavaScript;
import com.fr.json.JSONObject;
import com.fr.plugin.file.submit.oss.fun.OssSubmitTargetConfig;
import com.fr.stable.AssistUtils;
import com.fr.stable.CommonCodeUtils;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
@ -23,7 +24,11 @@ public class OssSubmitJavaScript extends AbstractJavaScript {
@Override
protected String actionJS(Repository repository) {
return "var fm = new FR.OssForm();fm.ossCommit({xmlconf:" + JSONObject.quote(GeneralXMLTools.writeXMLableAsString(this)) + "},this)";
return "var fm = new FR.OssForm();fm.ossCommit({xmlconf:" + quote(GeneralXMLTools.writeXMLableAsString(this)) + "},this)";
}
private String quote(String string) {
return "\"" + CommonCodeUtils.javascriptEncode(string) + "\"" ;
}
@Override

4
src/main/java/com/fr/plugin/file/submit/oss/ui/OssHyperlink4DownloadPane.java

@ -8,9 +8,9 @@ import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.general.GeneralUtils;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
import com.fr.plugin.file.submit.oss.script.OssDownloadHyperlink;
import com.fr.plugin.oss.universal.config.OssUniversalConfig;
import javax.swing.*;
import java.awt.*;
@ -27,7 +27,7 @@ public class OssHyperlink4DownloadPane extends BasicBeanPane<OssDownloadHyperlin
private void initComponents() {
this.setLayout(new BorderLayout());
this.bucketComboBox = new UIComboBox(FileSubmitOssServerConfig.getInstance().getBuckets());
this.bucketComboBox = new UIComboBox(OssUniversalConfig.getInstance().getArrayBuckets());
this.directoryValuePane = Editors.createValueEditorPane();
this.fileNameValuePane = Editors.createValueEditorPane();
double p = TableLayout.PREFERRED;

4
src/main/java/com/fr/plugin/file/submit/oss/ui/OssSubmitPathTableModel.java

@ -7,9 +7,9 @@ import com.fr.design.gui.itableeditorpane.UITableEditAction;
import com.fr.design.gui.itableeditorpane.UITableModelAdapter;
import com.fr.design.i18n.Toolkit;
import com.fr.general.GeneralUtils;
import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig;
import com.fr.plugin.file.submit.oss.fun.OssSubmitTarget;
import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
import com.fr.plugin.oss.universal.config.OssUniversalConfig;
import com.fr.stable.StringUtils;
import javax.swing.*;
@ -88,7 +88,7 @@ public class OssSubmitPathTableModel extends UITableModelAdapter<OssSubmitTarget
private UIComboBox bucketComboBox;
public BucketEditor() {
bucketComboBox = new UIComboBox(FileSubmitOssServerConfig.getInstance().getBuckets());
bucketComboBox = new UIComboBox(OssUniversalConfig.getInstance().getArrayBuckets());
this.addCellEditorListener(new CellEditorListener() {
@Override
public void editingCanceled(final ChangeEvent changeEvent) {

1
src/main/resources/com/fr/plugin/file/submit/oss/submit.properties

@ -12,3 +12,4 @@ Plugin-Oss_End_Point=EndPoint
Plugin-Oss_Buckets=Buckets
Plugin-Oss_AccessKeyId=AccessKeyId
Plugin-Oss_AccessKeySecret=AccessKeySecret
Plugin-File_Submit_Oss_Failed=Submit file failed, because the file {} is 0kb.

1
src/main/resources/com/fr/plugin/file/submit/oss/submit_zh_CN.properties

@ -12,3 +12,4 @@ Plugin-Oss_End_Point=\u5730\u57DF\u8282\u70B9\u4FE1\u606F
Plugin-Oss_Buckets=Buckets
Plugin-Oss_AccessKeyId=AccessKeyId
Plugin-Oss_AccessKeySecret=AccessKeySecret
Plugin-File_Submit_Oss_Failed=文件上传失败,因为文件{}大小为0kb。

4
src/main/resources/com/fr/plugin/file/submit/oss/web/oss.js

@ -69,8 +69,8 @@ $.extend(FR, {
data : {
sessionID: FR.SessionMgr.getSessionID(),
bucket : data.bucket,
directory : encodeURIComponent(data.directory),
fileName : encodeURIComponent(data.fileName)
directory : data.directory,
fileName : data.fileName
},
complete: function (res, status) {
window.open(res.responseText);

Loading…
Cancel
Save