Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ default void validateCaseName(String caseName) {
}

default CaseMetadataEntity getCaseMetaDataEntity(UUID caseUuid) {
return getCaseMetadataRepository().findById(caseUuid).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "case " + caseUuid + NOT_FOUND));
return getCaseMetadataRepository().findById(caseUuid).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Metadata of case " + caseUuid + NOT_FOUND));
}

default Boolean isUploadedAsPlainFile(UUID caseUuid) {
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/powsybl/caseserver/service/FsCaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,25 @@ String getFormat(Path caseFile) {
public List<CaseInfos> getCases() {
try (Stream<Path> walk = Files.walk(getStorageRootDir())) {
return walk.filter(Files::isRegularFile)
.map(this::getCaseInfos)
.map(this::getCaseInfosOrNull)
.filter(Objects::nonNull)
.map(this::removeGzipExtensionFromPlainFile)
.toList();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private CaseInfos getCaseInfos(Path file) {
return createInfos(file, UUID.fromString(file.getParent().getFileName().toString()));
}

private CaseInfos getCaseInfosOrNull(Path file) {
Objects.requireNonNull(file);
try {
return createInfos(file, UUID.fromString(file.getParent().getFileName().toString()));
CaseInfos caseInfos = getCaseInfos(file);
return Objects.nonNull(caseInfos) ? removeGzipExtensionFromPlainFile(caseInfos) : null;
} catch (Exception e) {
// This method is called by getCases() that is a method for supervision and administration. We do not want the request to stop and fail on error cases.
LOGGER.error("Error processing file {}: {}", file.getFileName(), e.getMessage(), e);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,16 @@ private static String getDateSearchTerm(String entsoeFormatDate) {
@Test
void invalidFileInCaseDirectoryShouldBeIgnored() throws Exception {
createStorageDir();

// add a random file in the storage, not stored in a UUID named directory
Path filePath = fileSystem.getPath(caseService.getRootDirectory()).resolve("randomFile.txt");
Files.createFile(filePath);

// add a case file in a UUID named directory but no metadata in the database
Path casePath = fileSystem.getPath(caseService.getRootDirectory()).resolve(UUID.randomUUID().toString());
Files.createDirectory(casePath);
Files.createFile(casePath.resolve(TEST_CASE));

importCase(TEST_CASE, false);

MvcResult mvcResult = mvc.perform(get("/v1/cases"))
Expand Down