servername
|-- reports
| |-- ABC
| | |-- COB02May2017
| | | |-- pnlreport.pdf
| | | |-- balancereport.pdf
| | |-- COB03May2017
| |-- CustomerB
| | |-- COB02May2017
| | |-- COB03May2017
| | | |-- balancereport.pdf
| |-- 01CFG
| | |-- COB03Sep2017
I have the above directory tree that holds my customer reports.
I have the following ReportDeliverable
model:
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;
}
I have the following class which is responsible for providing the list of report deliverable objects:
@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;
}
}
Daily a directory is created with name being COB-{prior-day-date} as above directory structure. With Java 8,
- I need some help returning all the file
paths
that concern the criteria held inReportSchedules
. I have tried to explain in the comments ingetFilesToProcess(ReportSchedule reportSchedule)
- From the paths, I need to initialize the
ReportDeliverable
fields, again explained in the commentsgetReportDeliverables(ReportSchedule reportSchedule)