@@ -72,23 +72,15 @@ public Stream<FileIndividualTimeSeriesMetaInformation> getIndividualTimeSeriesMe
7272 final ColumnScheme ... columnSchemes ) {
7373 FileNamingStrategy namingStrategy = getNamingStrategy ();
7474 return getTimeSeriesFilePaths (namingStrategy .getIndividualTimeSeriesPattern ()).parallelStream ()
75+ .map (filePath -> resolveFileInformation (filePath , "individual time series" ))
76+ .flatMap (Optional ::stream )
7577 .map (
76- filePath -> {
77- String fileName = filePath .getFileName ().toString ();
78- FileType fileType ;
79- try {
80- fileType = FileType .getFileType (fileName );
81- } catch (ParsingException e ) {
82- log .warn ("Unable to load load profile meta data for {}" , fileName , e );
83- fileType = null ; // will be filtered out
84- }
85- /* Extract meta information from file path and enhance it with the file path itself */
78+ fileMeta -> {
8679 IndividualTimeSeriesMetaInformation metaInformation =
87- namingStrategy .individualTimeSeriesMetaInformation (filePath .toString ());
80+ namingStrategy .individualTimeSeriesMetaInformation (
81+ fileMeta .filePath ().toString ());
8882 return new FileIndividualTimeSeriesMetaInformation (
89- metaInformation ,
90- Path .of (FileNamingStrategy .removeFileNameEnding (fileName )),
91- fileType );
83+ metaInformation , fileMeta .pathWithoutEnding (), fileMeta .fileType ());
9284 })
9385 .filter (meta -> meta .getFileType () != null )
9486 .filter (
@@ -110,24 +102,15 @@ public Stream<FileLoadProfileMetaInformation> getLoadProfileMetaInformation(
110102 FileNamingStrategy namingStrategy = getNamingStrategy ();
111103
112104 return getTimeSeriesFilePaths (namingStrategy .getLoadProfileTimeSeriesPattern ()).parallelStream ()
105+ .map (filePath -> resolveFileInformation (filePath , "load profile" ))
106+ .flatMap (Optional ::stream )
113107 .map (
114- filePath -> {
115- String fileName = filePath .getFileName ().toString ();
116- FileType fileType ;
117- try {
118- fileType = FileType .getFileType (fileName );
119- } catch (ParsingException e ) {
120- log .warn ("Unable to load load profile meta data for {}" , fileName , e );
121- fileType = null ; // will be filtered out
122- }
123-
124- /* Extract meta information from file path and enhance it with the file path itself */
108+ fileMeta -> {
125109 LoadProfileMetaInformation metaInformation =
126- namingStrategy .loadProfileTimeSeriesMetaInformation (filePath .toString ());
110+ namingStrategy .loadProfileTimeSeriesMetaInformation (
111+ fileMeta .filePath ().toString ());
127112 return new FileLoadProfileMetaInformation (
128- metaInformation .getProfile (),
129- Path .of (FileNamingStrategy .removeFileNameEnding (fileName )),
130- fileType );
113+ metaInformation .getProfile (), fileMeta .pathWithoutEnding (), fileMeta .fileType ());
131114 })
132115 .filter (meta -> meta .getFileType () != null )
133116 .filter (
@@ -138,4 +121,18 @@ public Stream<FileLoadProfileMetaInformation> getLoadProfileMetaInformation(
138121 .anyMatch (
139122 profile -> profile .getKey ().equals (metaInformation .getProfile ())));
140123 }
124+
125+ private Optional <FileMetaDetails > resolveFileInformation (Path filePath , String metaType ) {
126+ String fileName = filePath .getFileName ().toString ();
127+ try {
128+ FileType fileType = FileType .getFileType (fileName );
129+ Path pathWithoutEnding = Path .of (FileNamingStrategy .removeFileNameEnding (fileName ));
130+ return Optional .of (new FileMetaDetails (filePath , pathWithoutEnding , fileType ));
131+ } catch (ParsingException e ) {
132+ log .warn ("Unable to load {} meta data for {}" , metaType , fileName , e );
133+ return Optional .empty ();
134+ }
135+ }
136+
137+ private record FileMetaDetails (Path filePath , Path pathWithoutEnding , FileType fileType ) {}
141138}
0 commit comments