Browse Source

无JIRA任务 修复一些小问题

pull/1/head
richie 6 years ago
parent
commit
5dba99d1ce
  1. 7
      plugin.xml
  2. 15
      src/main/java/com/fr/plugin/file/submit/oss/fun/OssVariableValue.java
  3. 77
      src/main/java/com/fr/plugin/file/submit/oss/script/OssDownloadHyperlink.java
  4. 10
      src/main/java/com/fr/plugin/file/submit/oss/ui/tools/RewriteAction.java
  5. 270
      src/main/java/com/fr/plugin/file/submit/oss/ui/tools/RewritePane.java

7
plugin.xml

@ -2,15 +2,13 @@
<id>com.fr.plugin.file.submit.oss</id>
<name><![CDATA[文件上传下载(OSS)]]></name>
<active>yes</active>
<version>1.1</version>
<version>1.2</version>
<env-version>10.0</env-version>
<jartime>2018-11-02</jartime>
<vendor>author</vendor>
<description><![CDATA[文件上传至阿里云的OSS中。]]></description>
<dependence>
<item type="plugin" key="com.fr.plugin.customsubmmit.v10"/>
</dependence>
<change-notes><![CDATA[
[2018-11-05]下载无法使用$$$的问题。<br/>
[2018-10-31]初始化插件。<br/>
]]></change-notes>
<extra-core>
@ -27,7 +25,6 @@
<SubmitProvider class="com.fr.plugin.file.submit.oss.OssSubmitUIBridge"/>
<JavaScriptActionProvider class="com.fr.plugin.file.submit.oss.OssJavaScriptActionBridge"/>
<HyperlinkProvider class="com.fr.plugin.file.submit.oss.OssHyperlink4Download"/>
<MenuHandler class="com.fr.plugin.file.submit.oss.OssTemplateReload"/>
</extra-designer>
<function-recorder class="com.fr.plugin.file.submit.oss.job.OssSubmitJob"/>
</plugin>

15
src/main/java/com/fr/plugin/file/submit/oss/fun/OssVariableValue.java

@ -3,7 +3,6 @@ package com.fr.plugin.file.submit.oss.fun;
import com.fr.base.BaseFormula;
import com.fr.general.GeneralUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import com.fr.stable.CommonUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.UtilEvalError;
@ -40,15 +39,27 @@ public class OssVariableValue implements XMLable {
}
}
public Type getType() {
return type;
}
public Object getValue() {
return value;
}
public String getPlainText() {
if (type == Type.FORMULA) {
return ((BaseFormula)value).getPureContent();
} else {
return GeneralUtils.objectToString(value);
}
}
public String getResult(CalculatorProvider cal) {
Object result = value;
if (type == Type.FORMULA) {
try {
result = ((BaseFormula)value).evalValue(cal);
result = ((BaseFormula) value).evalValue(cal);
} catch (UtilEvalError u) {
FineLoggerFactory.getLogger().error(u.getMessage(), u);
}

77
src/main/java/com/fr/plugin/file/submit/oss/script/OssDownloadHyperlink.java

@ -1,16 +1,29 @@
package com.fr.plugin.file.submit.oss.script;
import com.fr.base.BaseFormula;
import com.fr.base.Parameter;
import com.fr.base.ParameterMapNameSpace;
import com.fr.general.GeneralUtils;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.js.Hyperlink;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
import com.fr.script.Calculator;
import com.fr.stable.ArrayUtils;
import com.fr.stable.AssistUtils;
import com.fr.stable.ColumnRow;
import com.fr.stable.FormulaProvider;
import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.script.ExTool;
import com.fr.stable.script.NameSpace;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import com.fr.web.session.SessionIDInfo;
public class OssDownloadHyperlink extends Hyperlink {
@ -32,6 +45,7 @@ public class OssDownloadHyperlink extends Hyperlink {
public void setDirectory(OssVariableValue directory) {
this.directory = directory;
modifyParameters(directory, "directory");
}
public OssVariableValue getFileName() {
@ -40,18 +54,39 @@ public class OssDownloadHyperlink extends Hyperlink {
public void setFileName(OssVariableValue fileName) {
this.fileName = fileName;
modifyParameters(fileName, "fileName");
}
private void modifyParameters(OssVariableValue variableValue, String parameterName) {
if (variableValue == null) {
return;
}
ParameterProvider[] providers = getParameters();
if (ArrayUtils.isEmpty(providers)) {
providers = ArrayUtils.add(providers, new Parameter(parameterName, variableValue.getValue()));
} else {
for (ParameterProvider provider : providers) {
if (AssistUtils.equals(provider.getValue(), parameterName)) {
provider.setValue(variableValue.getValue());
} else {
providers = ArrayUtils.add(providers, new Parameter(parameterName, variableValue.getValue()));
}
}
}
setParameters(providers);
}
@Override
protected String actionJS(Repository repository) {
JSONObject data = JSONObject.create();
try {
data.put("bucket", bucket);
if (directory != null) {
data.put("directory", directory.getResult(repository.getCalculator()));
data.put("directory", getResultValue(repository, "directory", directory));
}
if (fileName != null) {
data.put("fileName", fileName.getResult(repository.getCalculator()));
data.put("fileName", getResultValue(repository, "fileName", fileName));
}
} catch (JSONException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
@ -59,6 +94,40 @@ public class OssDownloadHyperlink extends Hyperlink {
return "FR.doHyperlinkByOssDownload(" + data.toString() + ");";
}
private String getResultValue(Repository repository, String parameterName, OssVariableValue variableValue) {
Object result = null;
ParameterProvider[] providers = getParameters();
for (ParameterProvider provider : providers) {
if (AssistUtils.equals(parameterName, provider.getName())) {
Object value = provider.getValue();
if (value instanceof BaseFormula) {
result = ((BaseFormula) value).getResult();
break;
} else {
result = value;
}
}
}
if (result == null) {
Calculator calculator = newCalculator(repository);
result = variableValue.getResult(calculator);
}
return GeneralUtils.objectToString(result);
}
private Calculator newCalculator(Repository repository) {
Calculator calculator = Calculator.createCalculator();
if (repository != null) {
calculator.pushNameSpace(ParameterMapNameSpace.create(repository.getReportParameterMap()));
calculator.pushNameSpace(SessionIDInfo.asNameSpace(repository.getSessionID()));
}
if (!paraMap.isEmpty()) {
calculator.pushNameSpace(ParameterMapNameSpace.create(this.paraMap));
}
return calculator;
}
public void readXML(final XMLableReader reader) {
super.readXML(reader);
if (reader.isChildNode()) {
@ -66,9 +135,9 @@ public class OssDownloadHyperlink extends Hyperlink {
if ("Bucket".equals(tagName)) {
this.bucket = reader.getElementValue();
} else if ("Directory".equals(tagName)) {
this.directory = (OssVariableValue) GeneralXMLTools.readXMLable(reader);
this.setDirectory((OssVariableValue)GeneralXMLTools.readXMLable(reader));
} else if ("FileName".equals(tagName)) {
this.fileName = (OssVariableValue) GeneralXMLTools.readXMLable(reader);
this.setFileName((OssVariableValue) GeneralXMLTools.readXMLable(reader));
}
}
}

10
src/main/java/com/fr/plugin/file/submit/oss/ui/tools/RewriteAction.java

@ -8,11 +8,15 @@ import java.awt.event.ActionEvent;
public class RewriteAction extends UpdateAction {
public RewriteAction() {
setName("Rewrite");
}
@Override
public void actionPerformed(ActionEvent e) {
RewritePane rewritePane = new RewritePane();
BasicDialog dialog = rewritePane.showWindow(DesignerContext.getDesignerFrame());
dialog.setVisible(true);
// RewritePane rewritePane = new RewritePane();
// BasicDialog dialog = rewritePane.showWindow(DesignerContext.getDesignerFrame());
// dialog.setVisible(true);
}
}

270
src/main/java/com/fr/plugin/file/submit/oss/ui/tools/RewritePane.java

@ -1,124 +1,146 @@
package com.fr.plugin.file.submit.oss.ui.tools;
import com.fr.base.FRContext;
import com.fr.base.extension.FileExtension;
import com.fr.data.SubmitJob;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.file.filetree.FileNode;
import com.fr.io.TemplateWorkBookIO;
import com.fr.main.impl.WorkBook;
import com.fr.plugin.customsubmmit.core.PathConfig;
import com.fr.plugin.customsubmmit.core.ServerPathColumnConfig;
import com.fr.plugin.customsubmmit.report.ServerPathSubmiterJob;
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.OssVariableValue;
import com.fr.plugin.file.submit.oss.job.OssSubmitJob;
import com.fr.report.report.Report;
import com.fr.report.worksheet.WorkSheet;
import com.fr.report.write.ReportWriteAttr;
import com.fr.report.write.SubmitVisitor;
import com.fr.report.write.WClassSubmiter;
import com.fr.stable.project.ProjectConstants;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
public class RewritePane extends BasicPane {
public RewritePane() {
initComponents();
}
private void initComponents() {
setLayout(new BorderLayout());
UIButton button = new UIButton("Start");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
rewrite();
}
});
add(button, BorderLayout.NORTH);
}
private void rewrite() {
new SwingWorker<Void, Integer>() {
@Override
protected Void doInBackground() {
FileNode[] fileNodes = FRContext.getFileNodes().list(ProjectConstants.REPORTLETS_NAME, FileExtension.CPT, true);
int len = fileNodes.length;
for (int i = 0; i < len; i++) {
FileNode fileNode = fileNodes[i];
try {
WorkBook workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(fileNode.getEnvPath().substring(10));
int count = workBook.getReportCount();
for (int n = 0; n < count; n++) {
Report report = workBook.getReport(n);
if (report instanceof WorkSheet) {
ReportWriteAttr reportWriteAttr = ((WorkSheet) report).getAttributeTarget(ReportWriteAttr.XML_TAG);
if (reportWriteAttr != null) {
int submitJobCount = reportWriteAttr.getSubmitVisitorCount();
for (int sn = 0; sn < submitJobCount; sn++) {
SubmitVisitor submitVisitor = reportWriteAttr.getSubmitVisitor(sn);
if (submitVisitor instanceof WClassSubmiter) {
SubmitJob job = ((WClassSubmiter) submitVisitor).getSubmitJob();
if (job instanceof ServerPathSubmiterJob) {
((WClassSubmiter) submitVisitor).setSubmitJob(convert2OssJob((ServerPathSubmiterJob) job));
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
publish(i);
}
return null;
}
@Override
protected void process(List<Integer> chunks) {
System.out.println("已经到第" + chunks.get(chunks.size() - 1) + "个模板");
}
}.execute();
}
private OssSubmitJob convert2OssJob(ServerPathSubmiterJob job) {
OssSubmitJob ossSubmitJob = new OssSubmitJob();
OssSubmitTargetConfig targetConfig = new OssSubmitTargetConfig();
ossSubmitJob.setSubmitTargetConfig(targetConfig);
PathConfig pathConfig = job.getPathConfig();
if (pathConfig != null) {
for (ServerPathColumnConfig config : pathConfig.getColumnConfigList()) {
OssSubmitTarget target = new OssSubmitTarget();
targetConfig.addSubmitTarget(target);
target.setBucket("fanruan-crm");
target.setDirectory(new OssVariableValue(config.getPath()));
target.setFile(new OssVariableValue(config.getCellConfig().toString()));
target.setName(new OssVariableValue(config.getName()));
}
}
return ossSubmitJob;
}
@Override
protected String title4PopupWindow() {
return "Transform";
}
}
//package com.fr.plugin.file.submit.oss.ui.tools;
//
//import com.fr.base.FRContext;
//import com.fr.base.extension.FileExtension;
//import com.fr.data.SubmitJob;
//import com.fr.design.dialog.BasicPane;
//import com.fr.design.gui.ibutton.UIButton;
//import com.fr.design.gui.itextarea.UITextArea;
//import com.fr.file.filetree.FileNode;
//import com.fr.io.TemplateWorkBookIO;
//import com.fr.log.FineLoggerFactory;
//import com.fr.main.TemplateWorkBook;
//import com.fr.main.impl.WorkBook;
//import com.fr.plugin.customsubmmit.core.PathConfig;
//import com.fr.plugin.customsubmmit.core.ServerPathColumnConfig;
//import com.fr.plugin.customsubmmit.report.ServerPathSubmiterJob;
//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.OssVariableValue;
//import com.fr.plugin.file.submit.oss.job.OssSubmitJob;
//import com.fr.report.report.Report;
//import com.fr.report.worksheet.WorkSheet;
//import com.fr.report.write.ReportWriteAttr;
//import com.fr.report.write.SubmitVisitor;
//import com.fr.report.write.WClassSubmiter;
//import com.fr.stable.project.ProjectConstants;
//
//import javax.swing.*;
//import java.awt.*;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.concurrent.ExecutionException;
//
//public class RewritePane extends BasicPane {
//
// private UITextArea textArea;
//
// public RewritePane() {
// initComponents();
// }
//
// private void initComponents() {
// setLayout(new BorderLayout());
// UIButton button = new UIButton("Start");
// button.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// rewrite();
// }
// });
// add(button, BorderLayout.NORTH);
// textArea = new UITextArea();
// add(new JScrollPane(textArea), BorderLayout.CENTER);
// }
//
// private void rewrite() {
// new SwingWorker<List<String>, Integer>() {
// @Override
// protected List<String> doInBackground() {
// FileNode[] fileNodes = FRContext.getFileNodes().list(ProjectConstants.REPORTLETS_NAME, FileExtension.CPT, true);
// int len = fileNodes.length;
// List<String> names = new ArrayList<String>();
// for (int i = 0; i < len; i++) {
// boolean willSave = false;
// FileNode fileNode = fileNodes[i];
// try {
// String path = fileNode.getEnvPath().substring(10);
// WorkBook workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(path);
// int count = workBook.getReportCount();
// for (int n = 0; n < count; n++) {
// Report report = workBook.getReport(n);
// if (report instanceof WorkSheet) {
// ReportWriteAttr reportWriteAttr = ((WorkSheet) report).getAttributeTarget(ReportWriteAttr.XML_TAG);
// if (reportWriteAttr != null) {
// int submitJobCount = reportWriteAttr.getSubmitVisitorCount();
// for (int sn = 0; sn < submitJobCount; sn++) {
// SubmitVisitor submitVisitor = reportWriteAttr.getSubmitVisitor(sn);
// if (submitVisitor instanceof WClassSubmiter) {
// SubmitJob job = ((WClassSubmiter) submitVisitor).getSubmitJob();
// if (job instanceof ServerPathSubmiterJob) {
// ((WClassSubmiter) submitVisitor).setSubmitJob(convert2OssJob((ServerPathSubmiterJob) job));
// willSave = true;
// }
// }
// }
// }
// }
// }
// if (willSave) {
// names.add(path);
// TemplateWorkBookIO.writeTemplateWorkBook(workBook, path);
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// publish(i);
// }
//
// return names;
// }
//
// @Override
// protected void process(List<Integer> chunks) {
// textArea.append("已经到第" + chunks.get(chunks.size() - 1) + "个模板" + "\n");
// }
//
// @Override
// protected void done() {
// try {
// List<String> paths = get();
// for (String text : paths) {
// textArea.append("成功修改了模板:" + text + "\n");
// }
// } catch (Exception e) {
// FineLoggerFactory.getLogger().error(e.getMessage(), e);
// }
// }
// }.execute();
// }
//
// private OssSubmitJob convert2OssJob(ServerPathSubmiterJob job) {
// OssSubmitJob ossSubmitJob = new OssSubmitJob();
// OssSubmitTargetConfig targetConfig = new OssSubmitTargetConfig();
// ossSubmitJob.setSubmitTargetConfig(targetConfig);
//
// PathConfig pathConfig = job.getPathConfig();
// if (pathConfig != null) {
// for (ServerPathColumnConfig config : pathConfig.getColumnConfigList()) {
// OssSubmitTarget target = new OssSubmitTarget();
// targetConfig.addSubmitTarget(target);
// target.setBucket("fanruan-crm");
// target.setDirectory(new OssVariableValue(config.getPath()));
// target.setFile(new OssVariableValue(config.getCellConfig().toString()));
// target.setName(new OssVariableValue(config.getName()));
// }
// }
// return ossSubmitJob;
// }
//
// @Override
// protected String title4PopupWindow() {
// return "Transform";
// }
//}

Loading…
Cancel
Save