Skip to content

Commit 3e56b97

Browse files
committed
Merge branch 'dev' into ms/#723-use-nio-paths-instead-of-strings
# Conflicts: # CHANGELOG.md # src/main/java/edu/ie3/datamodel/io/connectors/CsvFileConnector.java # src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java # src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy # src/test/groovy/edu/ie3/datamodel/io/source/csv/GridIoIT.groovy
2 parents 38e0377 + 275fb46 commit 3e56b97

File tree

5 files changed

+11
-96
lines changed

5 files changed

+11
-96
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
### Changed
1919
- Removing deprecated classes and methods [#540](https://github.com/ie3-institute/PowerSystemDataModel/issues/540)
2020
- Refactor CSV data sources [#716](https://github.com/ie3-institute/PowerSystemDataModel/issues/716)
21+
- Deleted parameter initFiles, set parameter append to false by default [#791](https://github.com/ie3-institute/PowerSystemDataModel/issues/791)
2122
- Use nio paths instead of strings for file path [#723](https://github.com/ie3-institute/PowerSystemDataModel/issues/723)
2223

2324

src/main/java/edu/ie3/datamodel/io/connectors/CsvFileConnector.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,11 @@ private BufferedCsvWriter initWriter(Path baseDirectory, CsvFileDefinition fileD
114114
if (!directories.exists() && !directories.mkdirs())
115115
throw new IOException("Unable to create directory tree '" + directories + "'");
116116

117-
File pathFile = fullPath.toFile();
118-
boolean append = pathFile.exists();
119117
BufferedCsvWriter writer =
120118
new BufferedCsvWriter(
121-
fullPath, fileDefinition.headLineElements(), fileDefinition.csvSep(), append);
122-
if (!append) {
123-
writer.writeFileHeader();
124-
} else {
125-
log.warn(
126-
"File '{}' already exist. Will append new content WITHOUT new header! Full path: {}",
127-
fileDefinition.getFilePath().getFileName(),
128-
pathFile.getAbsolutePath());
129-
}
119+
fullPath, fileDefinition.headLineElements(), fileDefinition.csvSep(), false);
120+
writer.writeFileHeader();
121+
130122
return writer;
131123
}
132124

@@ -218,15 +210,15 @@ public BufferedReader initReader(Path filePath) throws FileNotFoundException {
218210
* possible readers will be initialized.
219211
* @return A mapping from column scheme to the individual time series meta information
220212
*/
221-
public Map<UUID, edu.ie3.datamodel.io.csv.CsvIndividualTimeSeriesMetaInformation>
213+
public Map<UUID, CsvIndividualTimeSeriesMetaInformation>
222214
getCsvIndividualTimeSeriesMetaInformation(final ColumnScheme... columnSchemes) {
223215
return getIndividualTimeSeriesFilePaths().parallelStream()
224216
.map(
225217
filePath -> {
226218
/* Extract meta information from file path and enhance it with the file path itself */
227219
IndividualTimeSeriesMetaInformation metaInformation =
228220
fileNamingStrategy.individualTimeSeriesMetaInformation(filePath.toString());
229-
return new edu.ie3.datamodel.io.csv.CsvIndividualTimeSeriesMetaInformation(
221+
return new CsvIndividualTimeSeriesMetaInformation(
230222
metaInformation, FileNamingStrategy.removeFileNameEnding(filePath.getFileName()));
231223
})
232224
.filter(

src/main/java/edu/ie3/datamodel/io/sink/CsvFileSink.java

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class CsvFileSink implements InputDataSink, OutputDataSink {
6060
private final String csvSep;
6161

6262
public CsvFileSink(Path baseFolderPath) {
63-
this(baseFolderPath, new FileNamingStrategy(), false, ",");
63+
this(baseFolderPath, new FileNamingStrategy(), ",");
6464
}
6565

6666
/**
@@ -70,17 +70,10 @@ public CsvFileSink(Path baseFolderPath) {
7070
*
7171
* @param baseFolderPath the base folder path where the files should be put into
7272
* @param fileNamingStrategy the data sink file naming strategy that should be used
73-
* @param initFiles true if the files should be created during initialization (might create files,
74-
* that only consist of a headline, because no data will be written into them), false
75-
* otherwise
7673
* @param csvSep the csv file separator that should be use
7774
*/
78-
public CsvFileSink(
79-
Path baseFolderPath,
80-
FileNamingStrategy fileNamingStrategy,
81-
boolean initFiles,
82-
String csvSep) {
83-
this(baseFolderPath, new ProcessorProvider(), fileNamingStrategy, initFiles, csvSep);
75+
public CsvFileSink(Path baseFolderPath, FileNamingStrategy fileNamingStrategy, String csvSep) {
76+
this(baseFolderPath, new ProcessorProvider(), fileNamingStrategy, csvSep);
8477
}
8578

8679
/**
@@ -95,22 +88,16 @@ public CsvFileSink(
9588
* @param baseFolderPath the base folder path where the files should be put into
9689
* @param processorProvider the processor provided that should be used for entity serialization
9790
* @param fileNamingStrategy the data sink file naming strategy that should be used
98-
* @param initFiles true if the files should be created during initialization (might create files,
99-
* that only consist of a headline, because no data will be written into them), false
100-
* otherwise
10191
* @param csvSep the csv file separator that should be use
10292
*/
10393
public CsvFileSink(
10494
Path baseFolderPath,
10595
ProcessorProvider processorProvider,
10696
FileNamingStrategy fileNamingStrategy,
107-
boolean initFiles,
10897
String csvSep) {
10998
this.csvSep = csvSep;
11099
this.processorProvider = processorProvider;
111100
this.connector = new CsvFileConnector(baseFolderPath, fileNamingStrategy);
112-
113-
if (initFiles) initFiles(processorProvider, connector);
114101
}
115102

116103
@Override
@@ -353,40 +340,6 @@ private <C extends UniqueEntity> void write(C entity) {
353340
}
354341
}
355342

356-
/**
357-
* Initialize files, hence create a file for each expected class that will be processed in the
358-
* future. Please note, that files for time series can only be create on presence of a concrete
359-
* time series, as their file name depends on the individual uuid of the time series.
360-
*
361-
* @param processorProvider the processor provider all files that will be processed is derived
362-
* from
363-
* @param connector the connector to the files
364-
*/
365-
private void initFiles(
366-
final ProcessorProvider processorProvider, final CsvFileConnector connector) {
367-
processorProvider
368-
.getRegisteredClasses()
369-
.forEach(
370-
clz -> {
371-
try {
372-
String[] headerElements =
373-
csvHeaderElements(processorProvider.getHeaderElements(clz));
374-
375-
connector.getOrInitWriter(clz, headerElements, csvSep);
376-
} catch (ProcessorProviderException e) {
377-
log.error(
378-
"Error during receiving of head line elements. Cannot prepare writer for class {}.",
379-
clz,
380-
e);
381-
} catch (ConnectorException e) {
382-
log.error(
383-
"Error during instantiation files. Cannot get or init writer for class {}.",
384-
clz,
385-
e);
386-
}
387-
});
388-
}
389-
390343
/**
391344
* Transforms a provided array of strings to valid csv formatted strings (according to csv
392345
* specification RFC 4180)

src/test/groovy/edu/ie3/datamodel/io/sink/CsvFileSinkTest.groovy

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,6 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
7474
}
7575
}
7676

77-
def "A valid CsvFileSink called by simple constructor should not initialize files by default and consist of several default values"() {
78-
given:
79-
CsvFileSink csvFileSink = new CsvFileSink(testBaseFolderPath)
80-
csvFileSink.shutdown()
81-
82-
expect:
83-
!testBaseFolderPath.toFile().exists()
84-
csvFileSink.csvSep == ","
85-
}
86-
87-
def "A valid CsvFileSink with 'initFiles' enabled should create files as expected"() {
88-
given:
89-
CsvFileSink csvFileSink = new CsvFileSink(testBaseFolderPath,
90-
new ProcessorProvider([
91-
new ResultEntityProcessor(PvResult),
92-
new ResultEntityProcessor(EvResult)
93-
], [] as Map),
94-
new FileNamingStrategy(),
95-
true,
96-
",")
97-
csvFileSink.shutdown()
98-
99-
expect:
100-
testBaseFolderPath.toFile().exists()
101-
testBaseFolderPath.resolve("ev_res.csv").toFile().exists()
102-
testBaseFolderPath.resolve("pv_res.csv").toFile().exists()
103-
}
10477

10578
def "A valid CsvFileSink is able to convert an entity data map correctly to RFC 4180 compliant strings"() {
10679
given:
@@ -142,7 +115,7 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
142115
csvFileSink.shutdown()
143116
}
144117

145-
def "A valid CsvFileSink without 'initFiles' should only persist provided elements correctly but not init all files"() {
118+
def "A valid CsvFileSink should persist provided elements correctly"() {
146119
given:
147120
CsvFileSink csvFileSink = new CsvFileSink(testBaseFolderPath,
148121
new ProcessorProvider([
@@ -168,7 +141,6 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
168141
new InputEntityProcessor(EmInput)
169142
], [] as Map),
170143
new FileNamingStrategy(),
171-
false,
172144
",")
173145

174146
UUID uuid = UUID.fromString("22bea5fc-2cb2-4c61-beb9-b476e0107f52")
@@ -239,7 +211,6 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
239211
CsvFileSink csvFileSink = new CsvFileSink(testBaseFolderPath,
240212
new ProcessorProvider([], timeSeriesProcessorMap),
241213
new FileNamingStrategy(),
242-
false,
243214
",")
244215

245216
when:
@@ -313,7 +284,6 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
313284
ProcessorProvider.allEntityProcessors(),
314285
new HashMap<TimeSeriesProcessorKey, TimeSeriesProcessor<TimeSeries<TimeSeriesEntry<Value>, Value>, TimeSeriesEntry<Value>, Value>>()),
315286
new FileNamingStrategy(),
316-
false,
317287
",")
318288

319289
when:
@@ -333,7 +303,6 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
333303
testBaseFolderPath,
334304
new ProcessorProvider(),
335305
new FileNamingStrategy(),
336-
false,
337306
",")
338307

339308
when:

src/test/groovy/edu/ie3/datamodel/io/source/csv/GridIoIT.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class GridIoIT extends Specification implements CsvTestDataMeta {
3838
new DefaultDirectoryHierarchy(Path.of("output"), "vn_simona"))
3939
tempDirectory = Files.createTempDirectory("GridIoIT")
4040
sinkFlat = new CsvFileSink(tempDirectory.toAbsolutePath())
41-
sinkHierarchic = new CsvFileSink(tempDirectory.toAbsolutePath(), hierarchicNamingStrategy, false, ",")
41+
sinkHierarchic = new CsvFileSink(tempDirectory.toAbsolutePath(), hierarchicNamingStrategy, ",")
4242
}
4343

4444
def cleanupSpec() {

0 commit comments

Comments
 (0)