Skip to content

Commit 275fb46

Browse files
authored
Merge pull request #792 from ie3-institute/vb/#791_delete_initFiles
Deleted initFiles. Deleted all initFiles Tests. Set parameter append to false by default
2 parents 2ac8733 + f86dba0 commit 275fb46

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

2223

2324
## [3.0.0] - 2023-02-16

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,11 @@ private BufferedCsvWriter initWriter(String baseDirectory, CsvFileDefinition fil
117117
if (!directories.exists() && !directories.mkdirs())
118118
throw new IOException("Unable to create directory tree '" + directories + "'");
119119

120-
File pathFile = new File(fullPath);
121-
boolean append = pathFile.exists();
122120
BufferedCsvWriter writer =
123121
new BufferedCsvWriter(
124-
fullPath, fileDefinition.headLineElements(), fileDefinition.csvSep(), append);
125-
if (!append) {
126-
writer.writeFileHeader();
127-
} else {
128-
log.warn(
129-
"File '{}' already exist. Will append new content WITHOUT new header! Full path: {}",
130-
fileDefinition.fileName(),
131-
pathFile.getAbsolutePath());
132-
}
122+
fullPath, fileDefinition.headLineElements(), fileDefinition.csvSep(), false);
123+
writer.writeFileHeader();
124+
133125
return writer;
134126
}
135127

@@ -220,15 +212,15 @@ public BufferedReader initReader(String filePath) throws FileNotFoundException {
220212
* possible readers will be initialized.
221213
* @return A mapping from column scheme to the individual time series meta information
222214
*/
223-
public Map<UUID, edu.ie3.datamodel.io.csv.CsvIndividualTimeSeriesMetaInformation>
215+
public Map<UUID, CsvIndividualTimeSeriesMetaInformation>
224216
getCsvIndividualTimeSeriesMetaInformation(final ColumnScheme... columnSchemes) {
225217
return getIndividualTimeSeriesFilePaths().parallelStream()
226218
.map(
227219
filePath -> {
228220
/* Extract meta information from file path and enhance it with the file path itself */
229221
IndividualTimeSeriesMetaInformation metaInformation =
230222
fileNamingStrategy.individualTimeSeriesMetaInformation(filePath);
231-
return new edu.ie3.datamodel.io.csv.CsvIndividualTimeSeriesMetaInformation(
223+
return new CsvIndividualTimeSeriesMetaInformation(
232224
metaInformation, FileNamingStrategy.removeFileNameEnding(filePath));
233225
})
234226
.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
@@ -59,7 +59,7 @@ public class CsvFileSink implements InputDataSink, OutputDataSink {
5959
private final String csvSep;
6060

6161
public CsvFileSink(String baseFolderPath) {
62-
this(baseFolderPath, new FileNamingStrategy(), false, ",");
62+
this(baseFolderPath, new FileNamingStrategy(), ",");
6363
}
6464

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

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

115102
@Override
@@ -352,40 +339,6 @@ private <C extends UniqueEntity> void write(C entity) {
352339
}
353340
}
354341

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class GridIoIT extends Specification implements CsvTestDataMeta {
4040
new DefaultDirectoryHierarchy("output", "vn_simona"))
4141
tempDirectory = Files.createTempDirectory("GridIoIT")
4242
sinkFlat = new CsvFileSink(tempDirectory.toAbsolutePath().toString())
43-
sinkHierarchic = new CsvFileSink(tempDirectory.toAbsolutePath().toString(), hierarchicNamingStrategy, false, ",")
43+
sinkHierarchic = new CsvFileSink(tempDirectory.toAbsolutePath().toString(), hierarchicNamingStrategy, ",")
4444
}
4545

4646
def cleanupSpec() {

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

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

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

10376
def "A valid CsvFileSink is able to convert an entity data map correctly to RFC 4180 compliant strings"() {
10477
given:
@@ -140,7 +113,7 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
140113
csvFileSink.shutdown()
141114
}
142115

143-
def "A valid CsvFileSink without 'initFiles' should only persist provided elements correctly but not init all files"() {
116+
def "A valid CsvFileSink should persist provided elements correctly"() {
144117
given:
145118
CsvFileSink csvFileSink = new CsvFileSink(testBaseFolderPath,
146119
new ProcessorProvider([
@@ -166,7 +139,6 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
166139
new InputEntityProcessor(EmInput)
167140
], [] as Map),
168141
new FileNamingStrategy(),
169-
false,
170142
",")
171143

172144
UUID uuid = UUID.fromString("22bea5fc-2cb2-4c61-beb9-b476e0107f52")
@@ -237,7 +209,6 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
237209
CsvFileSink csvFileSink = new CsvFileSink(testBaseFolderPath,
238210
new ProcessorProvider([], timeSeriesProcessorMap),
239211
new FileNamingStrategy(),
240-
false,
241212
",")
242213

243214
when:
@@ -311,7 +282,6 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
311282
ProcessorProvider.allEntityProcessors(),
312283
new HashMap<TimeSeriesProcessorKey, TimeSeriesProcessor<TimeSeries<TimeSeriesEntry<Value>, Value>, TimeSeriesEntry<Value>, Value>>()),
313284
new FileNamingStrategy(),
314-
false,
315285
",")
316286

317287
when:
@@ -331,7 +301,6 @@ class CsvFileSinkTest extends Specification implements TimeSeriesTestData {
331301
testBaseFolderPath,
332302
new ProcessorProvider(),
333303
new FileNamingStrategy(),
334-
false,
335304
",")
336305

337306
when:

0 commit comments

Comments
 (0)