|
|
|
@ -1,35 +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.stable.ParameterProvider; |
|
|
|
|
import com.fanruan.api.cal.ParameterKit; |
|
|
|
|
import com.fr.base.ResultFormula; |
|
|
|
|
import com.fr.general.GeneralUtils; |
|
|
|
|
import com.fr.general.xml.GeneralXMLTools; |
|
|
|
|
import com.fanruan.api.util.GeneralKit; |
|
|
|
|
import com.fanruan.api.xml.XmlKit; |
|
|
|
|
import com.fr.js.Hyperlink; |
|
|
|
|
import com.fr.json.JSONException; |
|
|
|
|
import com.fanruan.api.err.JSONException; |
|
|
|
|
import com.fr.json.JSONObject; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import com.fanruan.api.json.JSONKit; |
|
|
|
|
import com.fanruan.api.log.LogKit; |
|
|
|
|
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.fanruan.api.util.ArrayKit; |
|
|
|
|
import com.fanruan.api.util.AssistKit; |
|
|
|
|
import com.fanruan.api.util.StringKit; |
|
|
|
|
import com.fr.stable.web.Repository; |
|
|
|
|
import com.fr.stable.xml.XMLPrintWriter; |
|
|
|
|
import com.fr.stable.xml.XMLableReader; |
|
|
|
|
import com.fr.web.session.SessionIDInfo; |
|
|
|
|
import com.fanruan.api.session.SessionKit; |
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
public class OssDownloadHyperlink extends Hyperlink { |
|
|
|
|
|
|
|
|
@ -68,8 +62,8 @@ public class OssDownloadHyperlink extends Hyperlink {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
ParameterProvider[] providers = getParameters(); |
|
|
|
|
if (ArrayUtils.isEmpty(providers)) { |
|
|
|
|
providers = ArrayUtils.add(providers, new Parameter(parameterName, variableValue.getValue())); |
|
|
|
|
if (ArrayKit.isEmpty(providers)) { |
|
|
|
|
providers = ArrayKit.add(providers, ParameterKit.newParameter(parameterName, variableValue.getValue())); |
|
|
|
|
} else { |
|
|
|
|
Map<String, ParameterProvider> map = new HashMap<String, ParameterProvider>(); |
|
|
|
|
for (ParameterProvider provider : providers) { |
|
|
|
@ -78,7 +72,7 @@ public class OssDownloadHyperlink extends Hyperlink {
|
|
|
|
|
if (map.containsKey(parameterName)) { |
|
|
|
|
map.get(parameterName).setValue(variableValue.getValue()); |
|
|
|
|
} else { |
|
|
|
|
providers = ArrayUtils.add(providers, new Parameter(parameterName, variableValue.getValue())); |
|
|
|
|
providers = ArrayKit.add(providers, ParameterKit.newParameter(parameterName, variableValue.getValue())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
setParameters(providers); |
|
|
|
@ -86,8 +80,8 @@ public class OssDownloadHyperlink extends Hyperlink {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected String actionJS(Repository repository) { |
|
|
|
|
JSONObject data = JSONObject.create(); |
|
|
|
|
protected String actionJS(Repository repository) throws JSONException{ |
|
|
|
|
JSONObject data = JSONKit.create(); |
|
|
|
|
try { |
|
|
|
|
data.put("bucket", bucket); |
|
|
|
|
if (directory != null) { |
|
|
|
@ -97,16 +91,17 @@ public class OssDownloadHyperlink extends Hyperlink {
|
|
|
|
|
data.put("fileName", getResultValue(repository, "fileName", fileName)); |
|
|
|
|
} |
|
|
|
|
} catch (JSONException e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
LogKit.error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
return "FR.doHyperlinkByOssDownload(" + data.toString() + ");"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@NotNull |
|
|
|
|
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())) { |
|
|
|
|
if (AssistKit.equals(parameterName, provider.getName())) { |
|
|
|
|
Object value = provider.getValue(); |
|
|
|
|
if (value instanceof BaseFormula) { |
|
|
|
|
result = ((BaseFormula) value).getResult(); |
|
|
|
@ -123,22 +118,22 @@ public class OssDownloadHyperlink extends Hyperlink {
|
|
|
|
|
Calculator calculator = newCalculator(repository); |
|
|
|
|
result = variableValue.getResult(calculator); |
|
|
|
|
} |
|
|
|
|
return GeneralUtils.objectToString(result); |
|
|
|
|
return GeneralKit.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())); |
|
|
|
|
calculator.pushNameSpace(ParameterKit.createParameterMapNameSpace(repository.getReportParameterMap())); |
|
|
|
|
calculator.pushNameSpace(SessionKit.asNameSpace(repository.getSessionID())); |
|
|
|
|
} |
|
|
|
|
if (!paraMap.isEmpty()) { |
|
|
|
|
calculator.pushNameSpace(ParameterMapNameSpace.create(this.paraMap)); |
|
|
|
|
calculator.pushNameSpace(ParameterKit.createParameterMapNameSpace(new HashMap(this.paraMap))); |
|
|
|
|
} |
|
|
|
|
return calculator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void readXML(final XMLableReader reader) { |
|
|
|
|
super.readXML(reader); |
|
|
|
|
if (reader.isChildNode()) { |
|
|
|
@ -146,24 +141,24 @@ public class OssDownloadHyperlink extends Hyperlink {
|
|
|
|
|
if ("Bucket".equals(tagName)) { |
|
|
|
|
this.bucket = reader.getElementValue(); |
|
|
|
|
} else if ("Directory".equals(tagName)) { |
|
|
|
|
this.setDirectory((OssVariableValue)GeneralXMLTools.readXMLable(reader)); |
|
|
|
|
this.setDirectory((OssVariableValue)XmlKit.readXMLable(reader)); |
|
|
|
|
} else if ("FileName".equals(tagName)) { |
|
|
|
|
this.setFileName((OssVariableValue) GeneralXMLTools.readXMLable(reader)); |
|
|
|
|
this.setFileName((OssVariableValue) XmlKit.readXMLable(reader)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void writeXML(final XMLPrintWriter writer) { |
|
|
|
|
writer.startTAG("JavaScript").attr("class", this.getClass().getName()); |
|
|
|
|
super.writeXML(writer); |
|
|
|
|
if (StringUtils.isNotEmpty(bucket)) { |
|
|
|
|
if (StringKit.isNotEmpty(bucket)) { |
|
|
|
|
writer.startTAG("Bucket").textNode(bucket).end(); |
|
|
|
|
} |
|
|
|
|
if (directory != null) { |
|
|
|
|
GeneralXMLTools.writeXMLable(writer, directory, "Directory"); |
|
|
|
|
XmlKit.writeXMLable(writer, directory, "Directory"); |
|
|
|
|
} |
|
|
|
|
if (fileName != null) { |
|
|
|
|
GeneralXMLTools.writeXMLable(writer, fileName, "FileName"); |
|
|
|
|
XmlKit.writeXMLable(writer, fileName, "FileName"); |
|
|
|
|
} |
|
|
|
|
writer.end(); |
|
|
|
|
} |
|
|
|
@ -171,9 +166,9 @@ public class OssDownloadHyperlink extends Hyperlink {
|
|
|
|
|
@Override |
|
|
|
|
public boolean equals(Object o) { |
|
|
|
|
return o instanceof OssDownloadHyperlink |
|
|
|
|
&& AssistUtils.equals(((OssDownloadHyperlink) o).bucket, bucket) |
|
|
|
|
&& AssistUtils.equals(((OssDownloadHyperlink) o).directory, directory) |
|
|
|
|
&& AssistUtils.equals(((OssDownloadHyperlink) o).fileName, fileName); |
|
|
|
|
&& AssistKit.equals(((OssDownloadHyperlink) o).bucket, bucket) |
|
|
|
|
&& AssistKit.equals(((OssDownloadHyperlink) o).directory, directory) |
|
|
|
|
&& AssistKit.equals(((OssDownloadHyperlink) o).fileName, fileName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|