Skip to content

Commit c97279a

Browse files
committed
#13771 - Add Epipulse export functionality for Measles disease
1 parent 1b70f5f commit c97279a

2 files changed

Lines changed: 17 additions & 42 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/epipulse/EpipulseLaboratoryMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public static String mapSampleMaterialToEpipulseCode(SampleMaterial sampleMateri
8484
*
8585
* @param testResult
8686
* SORMAS test result enum
87-
* @return EpiPulse result code (POS/NEG/EQUI/NOTEST)
87+
* @return EpiPulse result code (POS/NEG/EQUI/NOTEST), or null if input is null
8888
*/
8989
public static String mapTestResultToEpipulseCode(PathogenTestResultType testResult) {
9090
if (testResult == null) {
91-
return "NOTEST";
91+
return null;
9292
}
9393

9494
switch (testResult) {
@@ -102,7 +102,7 @@ public static String mapTestResultToEpipulseCode(PathogenTestResultType testResu
102102
case NOT_DONE:
103103
return "NOTEST";
104104
default:
105-
return "NOTEST";
105+
return null;
106106
}
107107
}
108108

sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/EpipulseCsvExportOrchestrator.java

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ public class EpipulseCsvExportOrchestrator {
7575
*/
7676
public void orchestrateExport(String uuid, ExportFunction exportFunction, CsvExportStrategy csvStrategy) {
7777

78-
CSVWriter writer = null;
79-
FileOutputStream fos = null;
80-
OutputStreamWriter osw = null;
8178
EpipulseExport epipulseExport = null;
8279
EpipulseExportStatus exportStatus = EpipulseExportStatus.FAILED;
8380
boolean shouldUpdateStatus = false;
@@ -119,52 +116,30 @@ public void orchestrateExport(String uuid, ExportFunction exportFunction, CsvExp
119116
EpipulseDiseaseExportResult exportResult = exportFunction.execute(exportDto, serverCountryCode, serverCountryName);
120117
totalRecords = exportResult.getExportEntryList().size();
121118

122-
// Setup CSV writer with explicit stream management
123-
fos = new FileOutputStream(exportFilePath);
124-
osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
125-
writer = CSVUtils.createCSVWriter(osw, configFacadeEjb.getCsvSeparator());
119+
// Setup CSV writer with try-with-resources for automatic resource management
120+
try (FileOutputStream fos = new FileOutputStream(exportFilePath);
121+
OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
122+
CSVWriter writer = CSVUtils.createCSVWriter(osw, configFacadeEjb.getCsvSeparator())) {
126123

127-
// Build column names using strategy
128-
List<String> columnNames = csvStrategy.buildColumnNames(exportResult);
124+
// Build column names using strategy
125+
List<String> columnNames = csvStrategy.buildColumnNames(exportResult);
129126

130-
// Write headers
131-
writer.writeNext(columnNames.toArray(new String[columnNames.size()]));
127+
// Write headers
128+
writer.writeNext(columnNames.toArray(new String[columnNames.size()]));
132129

133-
// Write entries using strategy
134-
for (EpipulseDiseaseExportEntryDto dto : exportResult.getExportEntryList()) {
135-
String[] exportLine = new String[columnNames.size()];
136-
csvStrategy.writeEntryRow(dto, exportLine, exportResult);
137-
writer.writeNext(exportLine);
130+
// Write entries using strategy
131+
for (EpipulseDiseaseExportEntryDto dto : exportResult.getExportEntryList()) {
132+
String[] exportLine = new String[columnNames.size()];
133+
csvStrategy.writeEntryRow(dto, exportLine, exportResult);
134+
writer.writeNext(exportLine);
135+
}
138136
}
139137

140138
exportStatus = EpipulseExportStatus.COMPLETED;
141139
} catch (Exception e) {
142140
exportStatus = EpipulseExportStatus.FAILED;
143141
logger.error("Error during export with uuid " + uuid + ": " + e.getMessage(), e);
144142
} finally {
145-
// Close resources in reverse order
146-
if (writer != null) {
147-
try {
148-
writer.close();
149-
} catch (Exception e) {
150-
logger.error("CRITICAL: Failed to close CSVWriter for uuid " + uuid + ": " + e.getMessage(), e);
151-
}
152-
}
153-
if (osw != null) {
154-
try {
155-
osw.close();
156-
} catch (Exception e) {
157-
logger.error("CRITICAL: Failed to close OutputStreamWriter for uuid " + uuid + ": " + e.getMessage(), e);
158-
}
159-
}
160-
if (fos != null) {
161-
try {
162-
fos.close();
163-
} catch (Exception e) {
164-
logger.error("CRITICAL: Failed to close FileOutputStream for uuid " + uuid + ": " + e.getMessage(), e);
165-
}
166-
}
167-
168143
// Calculate file size after writer is closed
169144
if (exportFilePath != null && exportStatus == EpipulseExportStatus.COMPLETED) {
170145
try {

0 commit comments

Comments
 (0)