Skip to content

Commit

Permalink
list datadir dir at metadata level
Browse files Browse the repository at this point in the history
  • Loading branch information
cmangeat committed Jan 11, 2024
1 parent 6ffd7fb commit 3ac2013
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.fao.geonet.api.maintenance;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.fao.geonet.kernel.GeonetworkDataDirectory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
Expand All @@ -10,11 +12,19 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

@RequestMapping(value = {"/{portal}/api/maintenance"})
@Tag(name = "maintenance")
@Controller("maintenance")
public class DatadirCleaner {

@Autowired
GeonetworkDataDirectory geonetworkDataDirectory;

@io.swagger.v3.oas.annotations.Operation(summary = "Clean data dir")
@RequestMapping(
path = "/cleanDatadir",
Expand All @@ -24,6 +34,25 @@ public class DatadirCleaner {
@PreAuthorize("hasAuthority('UserAdmin')")
@ResponseBody
public Object cleanDataDir() {
cleanFile();
return "cleaned";
}

public void cleanFile() {
Path rootPath = geonetworkDataDirectory.getMetadataDataDir();

listFilesEatingException(rootPath) //
.flatMap(this::listFilesEatingException)
.map(Path::toString)
.forEach(System.err::println);
}

private Stream<Path> listFilesEatingException(Path path) {
try {
return Files.list(path);
} catch (IOException e) {
e.printStackTrace();
return Stream.of();
}
}
}

0 comments on commit 3ac2013

Please sign in to comment.