Skip to content

Commit 5104f43

Browse files
committed
continuer les modifs
1 parent a5009d0 commit 5104f43

5 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/main/java/fr/insee/genesis/controller/rest/UtilsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ResponseEntity<Object> saveResponsesFromXmlFile(@RequestParam("inputFolde
4747
XMLSplitter.split(inputFolder, filename, outputFolder, "SurveyUnit", nbSU);
4848
return ResponseEntity.ok("File split");
4949
}
50-
50+
//TODO
5151
@Operation(summary = "Record volumetrics of each campaign in a folder")
5252
@PutMapping(path = "/volumetrics/save-all-campaigns")
5353
@PreAuthorize("hasRole('SCHEDULER')")

src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ private void processOneXmlFileForCampaign(String campaignName,
578578
fileUtils.moveDataFile(campaignName, mode.getFolder(),filepath);
579579
return;
580580
}
581-
log.error("Error {} on file {} : {}", response.getStatusCode(), fileName, response.getBody());
582-
581+
log.error("Failed to process file {} for campaign {} mode {} (HTTP: {})",
582+
fileName, campaignName, mode.getModeName(), response.getStatusCode());
583583
}
584584

585585
private static long getFileSizeInMB(Path filepath) {
@@ -676,6 +676,7 @@ private VariablesMap getVariablesMap(Mode modeSpecified,
676676
return variablesMap;
677677
}
678678

679+
//
679680
private static VariablesMap getVariablesMapWithPath(String metadataFilePath) throws GenesisException {
680681
if(metadataFilePath.endsWith(".xml")) {
681682
//Parse DDI

src/main/java/fr/insee/genesis/domain/service/metadata/QuestionnaireMetadataService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.FileInputStream;
2424
import java.io.IOException;
2525
import java.io.InputStream;
26+
import java.nio.file.NoSuchFileException;
2627
import java.nio.file.Path;
2728
import java.util.List;
2829

@@ -82,7 +83,7 @@ private void saveMetadata(String collectionInstrumentId, Mode mode, MetadataMode
8283
* @return VariablesMap or null if parsing fails
8384
*/
8485
private MetadataModel readMetadatas(String campaignName, String modeName, FileUtils fileUtils,
85-
List<GenesisError> errors) throws GenesisException{
86+
List<GenesisError> errors) throws GenesisException{
8687

8788
Path ddiFilePath;
8889
Path lunaticFilePath;
@@ -91,7 +92,8 @@ private MetadataModel readMetadatas(String campaignName, String modeName, FileUt
9192
ddiFilePath = fileUtils.findFile(String.format("%s/%s", fileUtils.getSpecFolder(campaignName), modeName), DDI_FILE_PATTERN);
9293
lunaticFilePath = fileUtils.findFile(String.format("%s/%s", fileUtils.getSpecFolder(campaignName), modeName), LUNATIC_FILE_PATTERN);
9394
metadataModel = parseMetadata(lunaticFilePath, ddiFilePath);
94-
} catch (RuntimeException e) {
95+
} catch (NoSuchFileException e) {
96+
log.warn("Specification file missing for campaign={}, mode={}", campaignName, modeName);
9597
//DDI file not found and already log - Go to next step
9698
} catch (IOException e) {
9799
log.warn("No DDI File found for {}, {} mode. Will try to use Lunatic...", campaignName, modeName);

src/main/java/fr/insee/genesis/exceptions/GenesisExceptionHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public ResponseEntity<String> handleSpec(SpecificationNotFoundException exceptio
5555
}
5656

5757
@ExceptionHandler(ReviewDisabledException.class)
58-
public ResponseEntity<String> handleReviewDisabled(ReviewDisabledException ex) {
59-
log.error("[{}] {}", ex.getClass().getSimpleName(), ex.getMessage());
58+
public ResponseEntity<String> handleReviewDisabled(ReviewDisabledException exception) {
59+
log.error("[{}] {}", exception.getClass().getSimpleName(), exception.getMessage());
6060
return ResponseEntity.status(HttpStatus.FORBIDDEN)
61-
.body(ex.getMessage());
61+
.body(exception.getMessage());
6262
}
6363

6464
@ExceptionHandler(Exception.class)
65-
public ResponseEntity<String> handleAny(Exception ex) {
66-
log.error("Unexpected error (Type: {}) : {}", ex.getClass().getSimpleName(), ex.getMessage());
65+
public ResponseEntity<String> handleAny(Exception exception) {
66+
log.error("Unexpected error (Type: {}) : {}", exception.getClass().getSimpleName(), exception.getMessage(), exception);
6767
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
6868
.body("Internal server error");
6969
}

src/main/java/fr/insee/genesis/infrastructure/utils/FileUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import java.io.*;
1515
import java.nio.file.Files;
16+
import java.nio.file.NoSuchFileException;
1617
import java.nio.file.Path;
1718
import java.nio.file.StandardCopyOption;
1819
import java.util.ArrayList;
@@ -130,7 +131,7 @@ public List<String> listFolders(String dir) {
130131
public Path findFile(String directory, String regex) throws IOException {
131132
try (Stream<Path> files = Files.find(Path.of(directory), 1, (path, basicFileAttributes) -> path.toFile().getName().toLowerCase().matches(regex))) {
132133
return files.findFirst()
133-
.orElseThrow(() -> new RuntimeException("No file (%s) found in ".formatted(regex) + directory));
134+
.orElseThrow(() -> new NoSuchFileException("No file (%s) found in %s".formatted(regex, directory)));
134135
}
135136
}
136137

0 commit comments

Comments
 (0)