나는 다음과 같은 Domain
모델 파일은 당신이 좋아하는 경우에 제공 할 수있다 감안할 때 :읽기 파일 경로 섹션은 모델링하는
public class Report {
private String reportId;
private String reportName;
private String client;
private String format;
private Date cobDate;
private String filePath;
}
public enum ReportType {
PNL_REPORT("11", "pnlreport"),
BALANCE_SHEET("20", "balance"),
private final String reportId;
private final String name;
private ReportType(String reportId, String name) {
this.reportId = reportId;
this.name = name;
}
}
을 내가 아래 Service
구현이 제공 :
@Service
public class FileService {
@Autowired
private FileRepository fileRepository;
public List<Report> getReport(String filePattern, String format) {
List<Report> reportDeliverables = new ArrayList<>();
List<File> filesToSend = fileRepository.getFilesToSend(sourcePath, filePattern, format);
\\C:\pathToReports\ClientABC\COB28Sep2017\pnlreport.pdf
\\return list of report objects, initialised.
}
}
I을 Java 8을 사용하고 있으며 효율적으로 각 File
개체를 filesToSend
~ Report
개의 필드로 변환하는 방법을 알고 싶습니다.
reportID -> 열거가 아이디보고에서 파생
REPORTNAME (이름이 접미사없이 파일 이름과 일치) -> pnlreport.pdf을
클라이언트 -> clientABC
cobDate-> 28 9 월 2017
형식 -> PDF
적인 filePath -> C : \ pathToReports \ ClientABC \ COB28Sep2017 \ pnlreport.pdf
경로에는 항상 클라이언트, cob 날짜, 보고서 파일 이름 순으로 소스가 있습니다.
reportID를 어떻게 작성합니까? 다른 정보는 regex 그룹을 사용하여 파일 경로에서 추출 할 수 있습니다. https://docs.oracle.com/javase/tutorial/essential/regex/groups.html –
'ReportType' 열거 형'reportID'에 대한 매핑입니다. lookup에서'name'으로 변경되었습니다. – user2781389