【发布时间】:2018-03-09 09:43:10
【问题描述】:
servername
|-- reports
| |-- ABC
| | |-- COB02May2017
| | | |-- pnlreport.pdf
| | | |-- balancereport.pdf
| | |-- COB03May2017
| |-- CustomerB
| | |-- COB02May2017
| | |-- COB03May2017
| | | |-- balancereport.pdf
| |-- 01CFG
| | |-- COB03Sep2017
我有上面的目录树来保存我的客户报告。
我有以下ReportDeliverable 模型:
public class ReportDeliverable {
private String reportId;
private String reportName;
private String customer;
private String format;
private Date cobDate;
}
ReportSchedule:
public class ReportSchedule {
private final String schedule;
private final String reportId;
private final String filePattern;
private final String format;
private final String filePath;
}
我有以下类负责提供报告可交付对象的列表:
@Service
public class FileServiceImpl implements FileService {
@Value("${reports.source-path}")
private String sourcePath;
@Override
public List<ReportDeliverable> getReportDeliverables(ReportSchedule reportSchedule) {
List<ReportDeliverable> reportDeliverables = new ArrayList<>();
List<Path> filesToProcess = getFilesToProcess(reportSchedule);
filesToProcess.forEach(path -> {
//for each path returned, extract and initialise ReportDeliverable object
ReportDeliverable reportDeliverable = new ReportDeliverable();
//reportDeliverable.setReportName(); > pnlreport.xls
//reportDeliverable.setFormat(); > > PDF
//reportDeliverable.setCobDate(); > 26-SEP-2017
//reportDeliverable.setClient(); > CustomerA
//reportDeliverable.setFilePath(); > \servername\reports\CustomerA\COB26Sep2017\pnlreport.pdf
reportDeliverables.add(reportDeliverable);
});
return reportDeliverables;
}
public List<Path> getFilesToProcess(ReportSchedule reportSchedule) {
String pattern = reportSchedule.getFilePattern(); //e.g. pnlreport
String format = reportSchedule.getFormat(); // PDF
//return full paths from here based on report criteria for COB that is T-1 (day before today). ignore the rest
// e.g. if today is 27/09/2017
//return -> \servername\reports\CustomerA\COB26Sep2017\pnlreport.pdf, \servername\reports\CustomerB\COB26Sep2017\pnlreport.PDF
return path;
}
}
每天都会创建一个目录,名称为COB-{prior-day-date},如上述目录结构。在 Java 8 中,
- 我需要一些帮助来返回与
ReportSchedules中保存的标准有关的所有文件paths。我试图在getFilesToProcess(ReportSchedule reportSchedule)的 cmets 中解释 - 从路径中,我需要初始化
ReportDeliverable字段,在 cmetsgetReportDeliverables(ReportSchedule reportSchedule)中再次说明
【问题讨论】:
标签: java nio java-io file-processing