Skip to content

Commit

Permalink
oss合并已存文件body为空错误
Browse files Browse the repository at this point in the history
  • Loading branch information
hongwei.quhw committed Sep 18, 2019
1 parent d5729fb commit 12afc0f
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<url>https://github.com/alipay/rdf-file</url>

<properties>
<rdf.file.core.version>2.2.4</rdf.file.core.version>
<rdf.file.oss.version>2.2.4</rdf.file.oss.version>
<rdf.file.sftp.version>2.2.4</rdf.file.sftp.version>
<rdf.file.core.version>2.2.5</rdf.file.core.version>
<rdf.file.oss.version>2.2.5</rdf.file.oss.version>
<rdf.file.sftp.version>2.2.5</rdf.file.sftp.version>
</properties>

<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ public String readBodyLine() {
}
}

// 返回空
if (!ProcessExecutor.execute(ProcessorTypeEnum.BEFORE_READ_ROW, processors, bodyConfig)) {
return null;
}

ensureOpen(bodyConfig);
try {
return reader.readLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,46 @@ public void testMergeEmpty() throws Exception {

mergedReader.close();
}

@Test
public void testNormlMergeEmpty() throws Exception {
String ossPath = RdfFileUtil.combinePath(ossPathPrefix, "testMergeEmpty");
fileStorage.upload(File.class.getResource("/preheat/de/empty/").getPath(), ossPath, false);

String targetFilePath = RdfFileUtil.combinePath(ossPath, "normalmergeempty.txt");
// 目标文件删除
try {
fileStorage.delete(targetFilePath);
} catch (Exception e) {
}

FileStorage fileStorage = FileFactory.createStorage(storageConfig);
List<String> paths = fileStorage.listAllFiles(ossPath);
Collections.sort(paths);
System.out.println(paths);

FileConfig normalConfig = new FileConfig(targetFilePath,
"/preheat/template_Allocation.json", storageConfig);
normalConfig.setFileEncoding("GBK");
normalConfig.setSummaryEnable(true);

FileMerger fileMerger = FileFactory.createMerger(normalConfig);
MergerConfig mergerConfig = new MergerConfig();
mergerConfig.setExistFilePaths(paths);
fileMerger.merge(mergerConfig);

FileConfig mergedConfig = new FileConfig(targetFilePath,
"/preheat/template_Allocation.json", storageConfig);
mergedConfig.setFileEncoding("GBK");
FileReader mergedReader = FileFactory.createReader(mergedConfig);
Map<String, Object> head = mergedReader.readHead(HashMap.class);
Assert.assertEquals(new Integer(0), head.get("totalCount"));
Assert.assertEquals(new BigDecimal("0.00"), head.get("totalAmount"));

Assert.assertNull(mergedReader.readRow(HashMap.class));

mergedReader.close();
}

@After
public void after() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.alipay.rdf.file.reader;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;

import com.alipay.rdf.file.interfaces.FileFactory;
import com.alipay.rdf.file.interfaces.FileReader;
import com.alipay.rdf.file.interfaces.FileStorage;
import com.alipay.rdf.file.model.FileConfig;
import com.alipay.rdf.file.model.StorageConfig;
import com.alipay.rdf.file.storage.OssConfig;
import com.alipay.rdf.file.util.OssTestUtil;
import com.alipay.rdf.file.util.RdfFileUtil;
import com.alipay.rdf.file.util.TemporaryFolderUtil;

import junit.framework.Assert;

public class BodyEmptyReader {
private TemporaryFolderUtil temporaryFolder = new TemporaryFolderUtil();
private static final StorageConfig storageConfig = OssTestUtil.geStorageConfig();
private static String ossPathPrifx = "rdf/rdf-file/open/BodyEmptyReader";
private static FileStorage fileStorage = FileFactory.createStorage(storageConfig);
private OssConfig ossConfig;

@Before
public void setUp() throws Exception {
temporaryFolder.create();
ossConfig = (OssConfig) storageConfig.getParam(OssConfig.OSS_STORAGE_CONFIG_KEY);
ossConfig.setOssTempRoot(temporaryFolder.getRoot().getAbsolutePath());
System.out.println(temporaryFolder.getRoot().getAbsolutePath());
}

@Test
public void testRead() {
String ossFilePath = RdfFileUtil.combinePath(ossPathPrifx, "test.txt");
fileStorage.upload(File.class.getResource("/reader/test.txt").getPath(), ossFilePath, true);

FileConfig normalConfig = new FileConfig(ossFilePath, "/reader/template_Allocation.json",
storageConfig);
FileReader reader = FileFactory.createReader(normalConfig);

Map<String, Object> row = null;
while (null != (row = reader.readRow(HashMap.class))) {

}

Assert.assertNull(row);
}
}
21 changes: 21 additions & 0 deletions rdf-file-oss/src/test/resources/reader/template_Allocation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"head": [
"totalCount|总笔数|Integer",
"totalAmount|总金额|BigDecimal"
],
"body": [
"orderNo|流水号",
"orderNo|支付宝订单号",
"appSheetNo|基金公司订单号",
"transInAmount|支付金额|BigDecimal",
"tradeType|订单类型",
"paymentStatus|支付状态",
"payTime|创建日期|Date:yyyyMMdd HH:mm:ss",
"memo|备注"
],
"totalCountKey": "totalCount",
"summaryColumnPairs": [
"totalAmount|transInAmount"
],
"protocol":"DE"
}
2 changes: 2 additions & 0 deletions rdf-file-oss/src/test/resources/reader/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
总笔数:0|总金额:0.00
流水号|支付宝订单号|基金公司订单号|支付金额|订单类型|支付状态|创建日期|备注
2 changes: 1 addition & 1 deletion rdf-file-test/src/main/resources/pom/rdf-file-core.pom
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.rdf.file</groupId>
<artifactId>rdf-file-core</artifactId>
<version>2.2.2</version>
<version>2.2.5</version>
<name>RDF FILE CORE</name>
<description>RDF FILE CORE</description>
<url>https://github.com/alipay/rdf-file</url>
Expand Down
2 changes: 1 addition & 1 deletion rdf-file-test/src/main/resources/pom/rdf-file-oss.pom
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.rdf.file</groupId>
<artifactId>rdf-file-oss</artifactId>
<version>2.2.2</version>
<version>2.2.5</version>
<name>RDF FILE OSS</name>
<description>RDF FILE OSS</description>
<url>https://github.com/alipay/rdf-file</url>
Expand Down
2 changes: 1 addition & 1 deletion rdf-file-test/src/main/resources/pom/rdf-file-sftp.pom
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.rdf.file</groupId>
<artifactId>rdf-file-sftp</artifactId>
<version>2.2.2</version>
<version>2.2.5</version>
<name>RDF FILE SFTP</name>
<description>RDF FILE SFTP</description>
<url>https://github.com/alipay/rdf-file</url>
Expand Down

0 comments on commit 12afc0f

Please sign in to comment.