|
|
|
package com.fr.plugin.file.submit.oss.job;
|
|
|
|
|
|
|
|
import com.aliyun.oss.OSSClient;
|
|
|
|
import com.fanruan.api.xml.XmlKit;
|
|
|
|
import com.fr.data.AbstractSubmitTask;
|
|
|
|
import com.fr.intelli.record.Focus;
|
|
|
|
import com.fr.intelli.record.Original;
|
|
|
|
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;
|
|
|
|
import com.fr.stable.ColumnRow;
|
|
|
|
import com.fr.stable.ColumnRowRelated;
|
|
|
|
import com.fr.stable.xml.XMLPrintWriter;
|
|
|
|
import com.fr.stable.xml.XMLableReader;
|
|
|
|
import com.fr.write.DBWriteAction;
|
|
|
|
import com.fr.write.DMLReport;
|
|
|
|
import com.fr.write.cal.WB;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 提交到OSS的任务
|
|
|
|
*/
|
|
|
|
@EnableMetrics
|
|
|
|
public class OssSubmitJob extends AbstractSubmitTask {
|
|
|
|
|
|
|
|
private OSSClient ossClient = null;
|
|
|
|
|
|
|
|
private OssSubmitTargetConfig submitTargetConfig;
|
|
|
|
|
|
|
|
public OssSubmitTargetConfig getSubmitTargetConfig() {
|
|
|
|
return submitTargetConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSubmitTargetConfig(OssSubmitTargetConfig submitTargetConfig) {
|
|
|
|
this.submitTargetConfig = submitTargetConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getJobType() {
|
|
|
|
return OssConstants.KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@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(
|
|
|
|
OssUniversalConfig.getInstance().getEndPoint(),
|
|
|
|
OssUniversalConfig.getInstance().getAccessKeyId(),
|
|
|
|
OssUniversalConfig.getInstance().getRealAccessKeySecret());
|
|
|
|
CalculatableResWorkSheet currentReport = ca.getAttribute(DMLReport.KEY);
|
|
|
|
if (submitTargetConfig != null && currentReport != null) {
|
|
|
|
ColumnRow[] crs = calculateRelatedColumnRows(submitTargetConfig);
|
|
|
|
if (currentReport instanceof WB) {
|
|
|
|
WB wb = (WB) (currentReport);
|
|
|
|
ColumnRow cr = ca.getAttribute(ColumnRow.class);
|
|
|
|
wb.setCurrentColumnRow(crs, cr, ca, new DBWriteAction() {
|
|
|
|
@Override
|
|
|
|
public void run(int index, Calculator ca, int groupIdx) throws Exception {
|
|
|
|
OssUpload.upload(ca, ossClient, submitTargetConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isDynamic() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private ColumnRow[] calculateRelatedColumnRows(OssSubmitTargetConfig config) {
|
|
|
|
Set<ColumnRow> set = new HashSet<ColumnRow>();
|
|
|
|
OssSubmitTarget[] targets = config.getSubmitTargets();
|
|
|
|
for (OssSubmitTarget target : targets) {
|
|
|
|
set.addAll(Arrays.asList(getColumnRowsFromValue(target.getDirectory())));
|
|
|
|
set.addAll(Arrays.asList(getColumnRowsFromValue(target.getName())));
|
|
|
|
set.addAll(Arrays.asList(getColumnRowsFromValue(target.getFile())));
|
|
|
|
}
|
|
|
|
return set.toArray(new ColumnRow[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ColumnRow[] getColumnRowsFromValue(OssVariableValue value) {
|
|
|
|
if (value != null && value.getValue() instanceof ColumnRowRelated) {
|
|
|
|
return ((ColumnRowRelated) value.getValue()).getRelatedColumnRows();
|
|
|
|
}
|
|
|
|
return new ColumnRow[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void doFinish(Calculator calculator) throws Exception {
|
|
|
|
ossClient.shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readXML(final XMLableReader reader) {
|
|
|
|
if (reader.isChildNode()) {
|
|
|
|
String tagName = reader.getTagName();
|
|
|
|
if (OssSubmitTargetConfig.XML_TAG.equals(tagName)) {
|
|
|
|
OssSubmitTargetConfig config = new OssSubmitTargetConfig();
|
|
|
|
config.readXML(reader);
|
|
|
|
submitTargetConfig = config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeXML(XMLPrintWriter writer) {
|
|
|
|
if (submitTargetConfig != null) {
|
|
|
|
XmlKit.writeXMLable(writer, submitTargetConfig, OssSubmitTargetConfig.XML_TAG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|