diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionLogCrawler.java b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionLogCrawler.java deleted file mode 100644 index c5b00869..00000000 --- a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionLogCrawler.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.iqser.red.service.redaction.v1.server; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.Test; - -import com.iqser.red.commons.jackson.ObjectMapperFactory; -import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog; -import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry; - -import lombok.SneakyThrows; - -public class RedactionLogCrawler { - - @Test - @SneakyThrows - public void findRedactionLogVersion0() { - - String redactionLogsDir = "/home/kschuettler/Nextcloud/redaction_logs/"; - long version0Count = Files.walk(Path.of(redactionLogsDir)) - .parallel() - .filter(file -> { - try { - return Files.size(file) > 0; - } catch (IOException e) { - throw new RuntimeException(e); - } - }) - .map(Path::toFile) - .filter(File::isFile) - .filter(file -> file.toString().endsWith("redactionlog.json")) - .peek(System.out::println) - .map(this::parseRedactionLog) - .filter(LogAndFile::isValid) - .filter(LogAndFile::hasAnyDuplicates) - .peek(LogAndFile::saveToTmp) - .count(); - System.out.println(version0Count + " version 0 redaction logs found"); - } - - - @SneakyThrows - private LogAndFile parseRedactionLog(File file) { - - var mapper = ObjectMapperFactory.create(); - try (var in = new FileInputStream(file)) { - return new LogAndFile(mapper.readValue(in.readAllBytes(), RedactionLog.class), file); - } - } - - - private record LogAndFile(RedactionLog redactionLog, File file) { - - public boolean hasAnyDuplicates() { - - Set uniqueStrings = new HashSet<>(); - - for (String str : redactionLog.getRedactionLogEntry().stream().map(RedactionLogEntry::getId).toList()) { - if (!uniqueStrings.add(str)) { - return true; - } - } - - return false; - } - - - @SneakyThrows - public void saveToTmp() { - - Path original = file.toPath(); - Path tmpFile = Path.of("/tmp/").resolve(Path.of("/home/kschuettler/Nextcloud").relativize(original)); - tmpFile.toFile().mkdirs(); - Files.copy(original, tmpFile, StandardCopyOption.REPLACE_EXISTING); - } - - - public boolean isValid() { - - return redactionLog.getRedactionLogEntry() != null; - } - - } - -}