From d4715d1791b8995c98c6b81f3811c3446cfec721 Mon Sep 17 00:00:00 2001 From: paytoncain Date: Tue, 9 Apr 2024 16:02:49 -0600 Subject: [PATCH] Simplify JsonDatastore module --- .../DetectionTypeControllerFactory.java | 8 +-- .../fileType/FileTypeControllerFactory.java | 12 ++-- .../InstrumentControllerFactory.java | 9 +-- .../OrganizationControllerFactory.java | 8 +-- .../person/PersonControllerFactory.java | 8 +-- .../platform/PlatformControllerFactory.java | 8 +-- .../project/ProjectControllerFactory.java | 8 +-- .../cli/command/sea/SeaControllerFactory.java | 8 +-- .../command/ship/ShipControllerFactory.java | 10 +-- .../csv/CSVTranslatorControllerFactory.java | 7 +- .../ExcelTranslatorControllerFactory.java | 7 +- .../json/CSVTranslatorJsonDatastore.java | 13 ---- .../json/DetectionTypeJsonDatastore.java | 13 ---- .../json/ExcelTranslatorJsonDatastore.java | 13 ---- .../datastore/json/FileTypeJsonDatastore.java | 13 ---- .../json/InstrumentJsonDatastore.java | 13 ---- .../pace/datastore/json/JsonDatastore.java | 4 +- .../json/OrganizationJsonDatastore.java | 13 ---- .../datastore/json/PersonJsonDatastore.java | 13 ---- .../datastore/json/PlatformJsonDatastore.java | 13 ---- .../datastore/json/ProjectJsonDatastore.java | 13 ---- .../pace/datastore/json/SeaJsonDatastore.java | 13 ---- .../datastore/json/ShipJsonDatastore.java | 13 ---- .../json/CSVTranslatorJsonDatastoreTest.java | 63 ----------------- .../json/DetectionTypeJsonDatastoreTest.java | 38 ---------- .../ExcelTranslatorJsonDatastoreTest.java | 67 ------------------ .../json/FileTypeJsonDatastoreTest.java | 38 ---------- .../json/InstrumentJsonDatastoreTest.java | 70 ------------------- .../datastore/json/JsonDatastoreTest.java | 70 ++++++++++++------- .../json/OrganizationJsonDatastoreTest.java | 50 ------------- .../json/PersonJsonDatastoreTest.java | 56 --------------- .../json/PlatformJsonDatastoreTest.java | 36 ---------- .../json/ProjectJsonDatastoreTest.java | 36 ---------- .../datastore/json/SeaJsonDatastoreTest.java | 36 ---------- .../datastore/json/ShipJsonDatastoreTest.java | 36 ---------- 35 files changed, 96 insertions(+), 740 deletions(-) delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/CSVTranslatorJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/DetectionTypeJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ExcelTranslatorJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/FileTypeJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/InstrumentJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/OrganizationJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/PersonJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/PlatformJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ProjectJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/SeaJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ShipJsonDatastore.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/CSVTranslatorJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/DetectionTypeJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ExcelTranslatorJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/FileTypeJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/InstrumentJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/OrganizationJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/PersonJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/PlatformJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ProjectJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/SeaJsonDatastoreTest.java delete mode 100644 pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ShipJsonDatastoreTest.java diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/detectionType/DetectionTypeControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/detectionType/DetectionTypeControllerFactory.java index 88686251..84765b80 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/detectionType/DetectionTypeControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/detectionType/DetectionTypeControllerFactory.java @@ -2,7 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.DetectionTypeController; -import edu.colorado.cires.pace.datastore.json.DetectionTypeJsonDatastore; +import edu.colorado.cires.pace.data.DetectionType; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -10,9 +11,8 @@ final class DetectionTypeControllerFactory { public static DetectionTypeController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { return new DetectionTypeController( - new DetectionTypeJsonDatastore( - datastoreDirectory, - objectMapper + new JsonDatastore<>( + datastoreDirectory, objectMapper, DetectionType.class ) ); } diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/fileType/FileTypeControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/fileType/FileTypeControllerFactory.java index 1b737360..6bbc895e 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/fileType/FileTypeControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/fileType/FileTypeControllerFactory.java @@ -2,16 +2,18 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.FileTypeController; -import edu.colorado.cires.pace.datastore.json.FileTypeJsonDatastore; +import edu.colorado.cires.pace.core.state.datastore.Datastore; +import edu.colorado.cires.pace.data.FileType; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; public final class FileTypeControllerFactory { - public static FileTypeJsonDatastore createDatastore(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { - return new FileTypeJsonDatastore( - datastoreDirectory, objectMapper - ); + public static Datastore createDatastore(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { + return new JsonDatastore<>( + datastoreDirectory, objectMapper, FileType.class + ) {}; } public static FileTypeController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/instrument/InstrumentControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/instrument/InstrumentControllerFactory.java index 471ea70e..ce74e074 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/instrument/InstrumentControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/instrument/InstrumentControllerFactory.java @@ -2,8 +2,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.InstrumentController; -import edu.colorado.cires.pace.datastore.json.FileTypeJsonDatastore; -import edu.colorado.cires.pace.datastore.json.InstrumentJsonDatastore; +import edu.colorado.cires.pace.data.FileType; +import edu.colorado.cires.pace.data.Instrument; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -11,8 +12,8 @@ final class InstrumentControllerFactory { public static InstrumentController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { return new InstrumentController( - new InstrumentJsonDatastore(datastoreDirectory, objectMapper), - new FileTypeJsonDatastore(datastoreDirectory, objectMapper) + new JsonDatastore<>(datastoreDirectory, objectMapper, Instrument.class), + new JsonDatastore<>(datastoreDirectory, objectMapper, FileType.class) ); } diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/organization/OrganizationControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/organization/OrganizationControllerFactory.java index a722ff00..d2461a69 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/organization/OrganizationControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/organization/OrganizationControllerFactory.java @@ -2,7 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.OrganizationController; -import edu.colorado.cires.pace.datastore.json.OrganizationJsonDatastore; +import edu.colorado.cires.pace.data.Organization; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -10,9 +11,8 @@ final class OrganizationControllerFactory { public static OrganizationController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { return new OrganizationController( - new OrganizationJsonDatastore( - datastoreDirectory, - objectMapper + new JsonDatastore<>( + datastoreDirectory, objectMapper, Organization.class ) ); } diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/person/PersonControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/person/PersonControllerFactory.java index 7e3416d7..05058e31 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/person/PersonControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/person/PersonControllerFactory.java @@ -2,7 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.PersonController; -import edu.colorado.cires.pace.datastore.json.PersonJsonDatastore; +import edu.colorado.cires.pace.data.Person; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -10,9 +11,8 @@ final class PersonControllerFactory { public static PersonController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { return new PersonController( - new PersonJsonDatastore( - datastoreDirectory, - objectMapper + new JsonDatastore<>( + datastoreDirectory, objectMapper, Person.class ) ); } diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/platform/PlatformControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/platform/PlatformControllerFactory.java index 3001cead..a41bd661 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/platform/PlatformControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/platform/PlatformControllerFactory.java @@ -2,7 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.PlatformController; -import edu.colorado.cires.pace.datastore.json.PlatformJsonDatastore; +import edu.colorado.cires.pace.data.Platform; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -10,9 +11,8 @@ final class PlatformControllerFactory { public static PlatformController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { return new PlatformController( - new PlatformJsonDatastore( - datastoreDirectory, - objectMapper + new JsonDatastore<>( + datastoreDirectory, objectMapper, Platform.class ) ); } diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/project/ProjectControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/project/ProjectControllerFactory.java index c9e069a5..2cda95b6 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/project/ProjectControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/project/ProjectControllerFactory.java @@ -2,7 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.ProjectController; -import edu.colorado.cires.pace.datastore.json.ProjectJsonDatastore; +import edu.colorado.cires.pace.data.Project; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -10,9 +11,8 @@ final class ProjectControllerFactory { public static ProjectController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { return new ProjectController( - new ProjectJsonDatastore( - datastoreDirectory, - objectMapper + new JsonDatastore<>( + datastoreDirectory, objectMapper, Project.class ) ); } diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/sea/SeaControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/sea/SeaControllerFactory.java index f84058ed..e0e2e952 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/sea/SeaControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/sea/SeaControllerFactory.java @@ -2,7 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.SeaController; -import edu.colorado.cires.pace.datastore.json.SeaJsonDatastore; +import edu.colorado.cires.pace.data.Sea; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -10,9 +11,8 @@ final class SeaControllerFactory { public static SeaController createController(Path datastorePath, ObjectMapper objectMapper) throws IOException { return new SeaController( - new SeaJsonDatastore( - datastorePath, - objectMapper + new JsonDatastore<>( + datastorePath, objectMapper, Sea.class ) ); } diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/ship/ShipControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/ship/ShipControllerFactory.java index 10f424e6..e5b81493 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/ship/ShipControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/ship/ShipControllerFactory.java @@ -2,7 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.ShipController; -import edu.colorado.cires.pace.datastore.json.ShipJsonDatastore; +import edu.colorado.cires.pace.data.Ship; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -10,10 +11,9 @@ final class ShipControllerFactory { public static ShipController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { return new ShipController( - new ShipJsonDatastore( - datastoreDirectory, - objectMapper - ) + new JsonDatastore<>( + datastoreDirectory, objectMapper, Ship.class + ) ); } diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/translation/csv/CSVTranslatorControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/translation/csv/CSVTranslatorControllerFactory.java index 044e4360..816cd7b8 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/translation/csv/CSVTranslatorControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/translation/csv/CSVTranslatorControllerFactory.java @@ -2,7 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.CSVTranslatorController; -import edu.colorado.cires.pace.datastore.json.CSVTranslatorJsonDatastore; +import edu.colorado.cires.pace.data.CSVTranslator; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -10,8 +11,8 @@ final class CSVTranslatorControllerFactory { public static CSVTranslatorController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { return new CSVTranslatorController( - new CSVTranslatorJsonDatastore( - datastoreDirectory, objectMapper + new JsonDatastore<>( + datastoreDirectory, objectMapper, CSVTranslator.class ) ); } diff --git a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/translation/excel/ExcelTranslatorControllerFactory.java b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/translation/excel/ExcelTranslatorControllerFactory.java index 1f901ecc..1cf6864f 100644 --- a/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/translation/excel/ExcelTranslatorControllerFactory.java +++ b/pace-cli/src/main/java/edu/colorado/cires/pace/cli/command/translation/excel/ExcelTranslatorControllerFactory.java @@ -2,7 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import edu.colorado.cires.pace.core.state.controller.ExcelTranslatorController; -import edu.colorado.cires.pace.datastore.json.ExcelTranslatorJsonDatastore; +import edu.colorado.cires.pace.data.ExcelTranslator; +import edu.colorado.cires.pace.datastore.json.JsonDatastore; import java.io.IOException; import java.nio.file.Path; @@ -10,8 +11,8 @@ final class ExcelTranslatorControllerFactory { public static ExcelTranslatorController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException { return new ExcelTranslatorController( - new ExcelTranslatorJsonDatastore( - datastoreDirectory, objectMapper + new JsonDatastore<>( + datastoreDirectory, objectMapper, ExcelTranslator.class ) ); } diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/CSVTranslatorJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/CSVTranslatorJsonDatastore.java deleted file mode 100644 index c04879f7..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/CSVTranslatorJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.CSVTranslator; -import java.io.IOException; -import java.nio.file.Path; - -public class CSVTranslatorJsonDatastore extends JsonDatastore { - - public CSVTranslatorJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory.resolve("csv-translations"), objectMapper, CSVTranslator.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/DetectionTypeJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/DetectionTypeJsonDatastore.java deleted file mode 100644 index 0efd8cf6..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/DetectionTypeJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.DetectionType; -import java.io.IOException; -import java.nio.file.Path; - -public class DetectionTypeJsonDatastore extends JsonDatastore { - - public DetectionTypeJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory.resolve("data-types"), objectMapper, DetectionType.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ExcelTranslatorJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ExcelTranslatorJsonDatastore.java deleted file mode 100644 index ac84c529..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ExcelTranslatorJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.ExcelTranslator; -import java.io.IOException; -import java.nio.file.Path; - -public class ExcelTranslatorJsonDatastore extends JsonDatastore { - - public ExcelTranslatorJsonDatastore(Path storageDirectory, ObjectMapper objectMapper) throws IOException { - super(storageDirectory, objectMapper, ExcelTranslator.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/FileTypeJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/FileTypeJsonDatastore.java deleted file mode 100644 index b27bac50..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/FileTypeJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.FileType; -import java.io.IOException; -import java.nio.file.Path; - -public class FileTypeJsonDatastore extends JsonDatastore { - - public FileTypeJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory.resolve("file-types"), objectMapper, FileType.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/InstrumentJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/InstrumentJsonDatastore.java deleted file mode 100644 index d1b8101b..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/InstrumentJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Instrument; -import java.io.IOException; -import java.nio.file.Path; - -public class InstrumentJsonDatastore extends JsonDatastore { - - public InstrumentJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory.resolve("instruments"), objectMapper, Instrument.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/JsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/JsonDatastore.java index 3f5342e6..9c632246 100644 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/JsonDatastore.java +++ b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/JsonDatastore.java @@ -16,13 +16,13 @@ import java.util.function.Function; import java.util.stream.Stream; -public abstract class JsonDatastore implements Datastore { +public class JsonDatastore implements Datastore { private final Path storageDirectory; private final ObjectMapper objectMapper; private final Class clazz; - protected JsonDatastore(Path storageDirectory, ObjectMapper objectMapper, Class clazz) throws IOException { + public JsonDatastore(Path storageDirectory, ObjectMapper objectMapper, Class clazz) throws IOException { this.storageDirectory = storageDirectory; this.objectMapper = objectMapper; this.clazz = clazz; diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/OrganizationJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/OrganizationJsonDatastore.java deleted file mode 100644 index d96c5a1a..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/OrganizationJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Organization; -import java.io.IOException; -import java.nio.file.Path; - -public class OrganizationJsonDatastore extends JsonDatastore { - - public OrganizationJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory.resolve("organizations"), objectMapper, Organization.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/PersonJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/PersonJsonDatastore.java deleted file mode 100644 index ad30b1ee..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/PersonJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Person; -import java.io.IOException; -import java.nio.file.Path; - -public class PersonJsonDatastore extends JsonDatastore { - - public PersonJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory.resolve("people"), objectMapper, Person.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/PlatformJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/PlatformJsonDatastore.java deleted file mode 100644 index ed5ed0b6..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/PlatformJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Platform; -import java.io.IOException; -import java.nio.file.Path; - -public class PlatformJsonDatastore extends JsonDatastore { - - public PlatformJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory.resolve("platforms"), objectMapper, Platform.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ProjectJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ProjectJsonDatastore.java deleted file mode 100644 index 17e4e491..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ProjectJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Project; -import java.io.IOException; -import java.nio.file.Path; - -public class ProjectJsonDatastore extends JsonDatastore { - - public ProjectJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory.resolve("projects"), objectMapper, Project.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/SeaJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/SeaJsonDatastore.java deleted file mode 100644 index 5e2073ac..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/SeaJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Sea; -import java.io.IOException; -import java.nio.file.Path; - -public class SeaJsonDatastore extends JsonDatastore { - - public SeaJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory.resolve("seas"), objectMapper, Sea.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ShipJsonDatastore.java b/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ShipJsonDatastore.java deleted file mode 100644 index db1af5a8..00000000 --- a/pace-datastore/pace-json-datastore/src/main/java/edu/colorado/cires/pace/datastore/json/ShipJsonDatastore.java +++ /dev/null @@ -1,13 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Ship; -import java.io.IOException; -import java.nio.file.Path; - -public class ShipJsonDatastore extends JsonDatastore { - - public ShipJsonDatastore(Path workDirectory, ObjectMapper objectMapper) throws IOException { - super(workDirectory, objectMapper, Ship.class); - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/CSVTranslatorJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/CSVTranslatorJsonDatastoreTest.java deleted file mode 100644 index dde5bcbf..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/CSVTranslatorJsonDatastoreTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.CSVTranslator; -import edu.colorado.cires.pace.data.CSVTranslatorField; -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; -import java.util.UUID; - -class CSVTranslatorJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return CSVTranslator.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new CSVTranslatorJsonDatastore(storagePath, objectMapper); - } - - @Override - protected CSVTranslator createNewObject() { - CSVTranslatorField field1 = new CSVTranslatorField( - "property1", - 1 - ); - CSVTranslatorField field2 = new CSVTranslatorField( - "property2", - 2 - ); - - return new CSVTranslator( - UUID.randomUUID(), - UUID.randomUUID().toString(), - List.of( - field1, field2 - ) - ); - } - - @Override - protected void assertObjectsEqual(CSVTranslator expected, CSVTranslator actual) { - assertEquals(expected.name(), actual.name()); - assertEquals(expected.uuid(), actual.uuid()); - - List expectedFields = expected.fields().stream() - .sorted((f1, f2) -> f1.propertyName().compareToIgnoreCase(f2.propertyName())) - .toList(); - List actualFields = actual.fields().stream() - .sorted((f1, f2) -> f1.propertyName().compareToIgnoreCase(f2.propertyName())) - .toList(); - assertEquals(expectedFields.size(), actualFields.size()); - - for (int i = 0; i < expected.fields().size(); i++) { - assertEquals(expectedFields.get(i).columnNumber(), actualFields.get(i).columnNumber()); - assertEquals(expectedFields.get(i).propertyName(), actualFields.get(i).propertyName()); - } - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/DetectionTypeJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/DetectionTypeJsonDatastoreTest.java deleted file mode 100644 index 7f9e9e32..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/DetectionTypeJsonDatastoreTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.DetectionType; -import java.io.IOException; -import java.nio.file.Path; -import java.util.UUID; - -class DetectionTypeJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return DetectionType.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new DetectionTypeJsonDatastore(storagePath, objectMapper); - } - - @Override - protected DetectionType createNewObject() { - return new DetectionType( - UUID.randomUUID(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString() - ); - } - - @Override - protected void assertObjectsEqual(DetectionType expected, DetectionType actual) { - assertEquals(expected.uuid(), actual.uuid()); - assertEquals(expected.scienceName(), actual.scienceName()); - assertEquals(expected.source(), actual.source()); - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ExcelTranslatorJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ExcelTranslatorJsonDatastoreTest.java deleted file mode 100644 index cdf9ddb2..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ExcelTranslatorJsonDatastoreTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.ExcelTranslator; -import edu.colorado.cires.pace.data.ExcelTranslatorField; -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; -import java.util.UUID; - -class ExcelTranslatorJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return ExcelTranslator.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new ExcelTranslatorJsonDatastore(storagePath, objectMapper); - } - - @Override - protected ExcelTranslator createNewObject() { - ExcelTranslatorField field1 = new ExcelTranslatorField( - "property1", - 1, - 1 - ); - - ExcelTranslatorField field2 = new ExcelTranslatorField( - "property2", - 2, - 2 - ); - - return new ExcelTranslator( - UUID.randomUUID(), - UUID.randomUUID().toString(), - List.of( - field1, field2 - ) - ); - } - - @Override - protected void assertObjectsEqual(ExcelTranslator expected, ExcelTranslator actual) { - assertEquals(expected.name(), actual.name()); - assertEquals(expected.uuid(), actual.uuid()); - - List expectedFields = expected.fields().stream() - .sorted((f1, f2) -> f1.propertyName().compareToIgnoreCase(f2.propertyName())) - .toList(); - List actualFields = actual.fields().stream() - .sorted((f1, f2) -> f1.propertyName().compareToIgnoreCase(f2.propertyName())) - .toList(); - assertEquals(expectedFields.size(), actualFields.size()); - - for (int i = 0; i < expected.fields().size(); i++) { - assertEquals(expectedFields.get(i).columnNumber(), actualFields.get(i).columnNumber()); - assertEquals(expectedFields.get(i).propertyName(), actualFields.get(i).propertyName()); - assertEquals(expectedFields.get(i).sheetNumber(), actualFields.get(i).sheetNumber()); - } - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/FileTypeJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/FileTypeJsonDatastoreTest.java deleted file mode 100644 index 94ad8c54..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/FileTypeJsonDatastoreTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.FileType; -import java.io.IOException; -import java.nio.file.Path; -import java.util.UUID; - -public class FileTypeJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return FileType.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new FileTypeJsonDatastore(storagePath, objectMapper); - } - - @Override - protected FileType createNewObject() { - return new FileType( - UUID.randomUUID(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString() - ); - } - - @Override - protected void assertObjectsEqual(FileType expected, FileType actual) { - assertEquals(expected.uuid(), actual.uuid()); - assertEquals(expected.type(), actual.type()); - assertEquals(expected.comment(), actual.comment()); - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/InstrumentJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/InstrumentJsonDatastoreTest.java deleted file mode 100644 index 67601dcb..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/InstrumentJsonDatastoreTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.FileType; -import edu.colorado.cires.pace.data.Instrument; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Comparator; -import java.util.List; -import java.util.UUID; - -class InstrumentJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return Instrument.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new InstrumentJsonDatastore(storagePath, objectMapper); - } - - @Override - protected Instrument createNewObject() { - FileType fileType1 = new FileType( - UUID.randomUUID(), - UUID.randomUUID().toString(), - "comment" - ); - - FileType fileType2 = new FileType( - UUID.randomUUID(), - UUID.randomUUID().toString(), - "comment" - ); - - return new Instrument( - UUID.randomUUID(), - UUID.randomUUID().toString(), - List.of( - fileType1, fileType2 - ) - ); - } - - @Override - protected void assertObjectsEqual(Instrument expected, Instrument actual) { - assertEquals(expected.uuid(), actual.uuid()); - assertEquals(expected.name(), actual.name()); - - List expectedFileTypes = expected.fileTypes().stream() - .sorted(Comparator.comparing(FileType::uuid)) - .toList(); - - List actualFileTypes = actual.fileTypes().stream() - .sorted(Comparator.comparing(FileType::uuid)) - .toList(); - - assertEquals(expectedFileTypes.size(), actualFileTypes.size()); - - for (int i = 0; i < expectedFileTypes.size(); i++) { - assertEquals(expectedFileTypes.get(i).uuid(), actualFileTypes.get(i).uuid()); - assertEquals(expectedFileTypes.get(i).type(), actualFileTypes.get(i).type()); - assertEquals(expectedFileTypes.get(i).comment(), actualFileTypes.get(i).comment()); - } - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/JsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/JsonDatastoreTest.java index 2339c9c3..1ffe3331 100644 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/JsonDatastoreTest.java +++ b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/JsonDatastoreTest.java @@ -4,8 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import com.fasterxml.jackson.databind.ObjectMapper; +import edu.colorado.cires.pace.data.ObjectWithName; import edu.colorado.cires.pace.data.ObjectWithUUID; -import edu.colorado.cires.pace.data.ObjectWithUniqueField; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -14,21 +14,32 @@ import java.util.Comparator; import java.util.List; import java.util.Optional; +import java.util.UUID; import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -abstract class JsonDatastoreTest { + +class JsonDatastoreTest { + + record TestObject(UUID uuid, String name) implements ObjectWithName { + + @Override + public ObjectWithUUID copyWithNewUUID(UUID uuid) { + return new TestObject( + uuid, + name + ); + } + } private static final Path TEST_PATH = Paths.get("target").resolve("test-dir"); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - protected abstract Class getClazz(); - protected abstract JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException; - private final JsonDatastore datastore; + private final JsonDatastore datastore; { try { - datastore = createDatastore(TEST_PATH, OBJECT_MAPPER); + datastore = new JsonDatastore<>(TEST_PATH, OBJECT_MAPPER, TestObject.class); } catch (IOException e) { throw new RuntimeException(e); } @@ -64,9 +75,9 @@ private static void cleanTestDir() { @Test void testSave() throws IOException { - O object = createNewObject(); + TestObject object = createNewObject(); - O result = datastore.save(object); + TestObject result = datastore.save(object); assertObjectsEqual(object, result); assertSavedObjectEqualsObject(object, result); assertTrue(getFileForObject(result).isPresent()); @@ -74,7 +85,7 @@ void testSave() throws IOException { @Test void testDelete() throws IOException { - O object = createNewObject(); + TestObject object = createNewObject(); datastore.save(object); datastore.delete(object); @@ -83,10 +94,10 @@ void testDelete() throws IOException { @Test void testFindByUUID() throws IOException { - O object = createNewObject(); - O result = datastore.save(object); + TestObject object = createNewObject(); + TestObject result = datastore.save(object); - Optional maybeResult = datastore.findByUUID(result.uuid()); + Optional maybeResult = datastore.findByUUID(result.uuid()); assertTrue(maybeResult.isPresent()); assertObjectsEqual(maybeResult.get(), result); @@ -97,10 +108,10 @@ void testFindByUUID() throws IOException { @Test void testFindByUniqueField() throws IOException { - O object = createNewObject(); - O result = datastore.save(object); + TestObject object = createNewObject(); + TestObject result = datastore.save(object); - Optional maybeResult = datastore.findByUniqueField(result.uniqueField()); + Optional maybeResult = datastore.findByUniqueField(result.uniqueField()); assertTrue(maybeResult.isPresent()); assertObjectsEqual(maybeResult.get(), result); @@ -111,15 +122,15 @@ void testFindByUniqueField() throws IOException { @Test void testFindAll() throws IOException { - O object1 = createNewObject(); + TestObject object1 = createNewObject(); object1 = datastore.save(object1); - O object2 = createNewObject(); + TestObject object2 = createNewObject(); object2 = datastore.save(object2); - List results = datastore.findAll() + List results = datastore.findAll() .sorted((Comparator.comparing(ObjectWithUUID::uuid))) .toList(); - List expected = Stream.of(object1, object2).sorted(Comparator.comparing(ObjectWithUUID::uuid)) + List expected = Stream.of(object1, object2).sorted(Comparator.comparing(ObjectWithUUID::uuid)) .toList(); assertEquals(expected.size(), results.size()); @@ -128,11 +139,20 @@ void testFindAll() throws IOException { assertObjectsEqual(expected.get(i), results.get(i)); } } + + private TestObject createNewObject() { + return new TestObject( + UUID.randomUUID(), + UUID.randomUUID().toString() + ); + } + + private void assertObjectsEqual(TestObject expected, TestObject actual) { + assertEquals(expected.uuid(), actual.uuid()); + assertEquals(expected.name(), actual.name()); + } - protected abstract O createNewObject(); - protected abstract void assertObjectsEqual(O expected, O actual); - - private void assertSavedObjectEqualsObject(O expected, O actual) throws IOException { + private void assertSavedObjectEqualsObject(TestObject expected, TestObject actual) throws IOException { try (Stream paths = Files.walk(TEST_PATH)) { paths.map(Path::toFile) .filter(File::isFile) @@ -142,7 +162,7 @@ private void assertSavedObjectEqualsObject(O expected, O actual) throws IOExcept try { assertObjectsEqual( expected, - OBJECT_MAPPER.readValue(f, getClazz()) + OBJECT_MAPPER.readValue(f, TestObject.class) ); } catch (IOException e) { throw new IllegalStateException(String.format( @@ -157,7 +177,7 @@ private void assertSavedObjectEqualsObject(O expected, O actual) throws IOExcept } } - private Optional getFileForObject(O object) throws IOException { + private Optional getFileForObject(TestObject object) throws IOException { try (Stream paths = Files.walk(TEST_PATH)) { return paths.map(Path::toFile) .filter(File::isFile) diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/OrganizationJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/OrganizationJsonDatastoreTest.java deleted file mode 100644 index b53d2632..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/OrganizationJsonDatastoreTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Organization; -import java.io.IOException; -import java.nio.file.Path; -import java.util.UUID; - -class OrganizationJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return Organization.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new OrganizationJsonDatastore(storagePath, objectMapper); - } - - @Override - protected Organization createNewObject() { - return new Organization( - UUID.randomUUID(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString() - ); - } - - @Override - protected void assertObjectsEqual(Organization expected, Organization actual) { - assertEquals(expected.uuid(), actual.uuid()); - assertEquals(expected.city(), actual.city()); - assertEquals(expected.country(), actual.country()); - assertEquals(expected.email(), actual.email()); - assertEquals(expected.name(), actual.name()); - assertEquals(expected.phone(), actual.phone()); - assertEquals(expected.state(), actual.state()); - assertEquals(expected.street(), actual.street()); - assertEquals(expected.zip(), actual.zip()); - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/PersonJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/PersonJsonDatastoreTest.java deleted file mode 100644 index 7380bbf8..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/PersonJsonDatastoreTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Person; -import java.io.IOException; -import java.nio.file.Path; -import java.util.UUID; - -class PersonJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return Person.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new PersonJsonDatastore(storagePath, objectMapper); - } - - @Override - protected Person createNewObject() { - return new Person( - UUID.randomUUID(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString(), - UUID.randomUUID().toString() - ); - } - - @Override - protected void assertObjectsEqual(Person expected, Person actual) { - assertEquals(expected.uuid(), actual.uuid()); - assertEquals(expected.city(), actual.city()); - assertEquals(expected.country(), actual.country()); - assertEquals(expected.email(), actual.email()); - assertEquals(expected.name(), actual.name()); - assertEquals(expected.orcid(), actual.orcid()); - assertEquals(expected.organization(), actual.organization()); - assertEquals(expected.phone(), actual.phone()); - assertEquals(expected.position(), actual.position()); - assertEquals(expected.state(), actual.state()); - assertEquals(expected.street(), actual.street()); - assertEquals(expected.zip(), actual.zip()); - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/PlatformJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/PlatformJsonDatastoreTest.java deleted file mode 100644 index 634056a8..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/PlatformJsonDatastoreTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Platform; -import java.io.IOException; -import java.nio.file.Path; -import java.util.UUID; - -class PlatformJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return Platform.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new PlatformJsonDatastore(storagePath, objectMapper); - } - - @Override - protected Platform createNewObject() { - return new Platform( - UUID.randomUUID(), - UUID.randomUUID().toString() - ); - } - - @Override - protected void assertObjectsEqual(Platform expected, Platform actual) { - assertEquals(expected.uuid(), actual.uuid()); - assertEquals(expected.name(), actual.name()); - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ProjectJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ProjectJsonDatastoreTest.java deleted file mode 100644 index fb37d3f3..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ProjectJsonDatastoreTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Project; -import java.io.IOException; -import java.nio.file.Path; -import java.util.UUID; - -class ProjectJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return Project.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new ProjectJsonDatastore(storagePath, objectMapper); - } - - @Override - protected Project createNewObject() { - return new Project( - UUID.randomUUID(), - UUID.randomUUID().toString() - ); - } - - @Override - protected void assertObjectsEqual(Project expected, Project actual) { - assertEquals(expected.uuid(), actual.uuid()); - assertEquals(expected.name(), actual.name()); - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/SeaJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/SeaJsonDatastoreTest.java deleted file mode 100644 index f27f4797..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/SeaJsonDatastoreTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Sea; -import java.io.IOException; -import java.nio.file.Path; -import java.util.UUID; - -class SeaJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return Sea.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new SeaJsonDatastore(storagePath, objectMapper); - } - - @Override - protected Sea createNewObject() { - return new Sea( - UUID.randomUUID(), - UUID.randomUUID().toString() - ); - } - - @Override - protected void assertObjectsEqual(Sea expected, Sea actual) { - assertEquals(expected.uuid(), actual.uuid()); - assertEquals(expected.name(), actual.name()); - } -} diff --git a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ShipJsonDatastoreTest.java b/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ShipJsonDatastoreTest.java deleted file mode 100644 index 53e93260..00000000 --- a/pace-datastore/pace-json-datastore/src/test/java/edu/colorado/cires/pace/datastore/json/ShipJsonDatastoreTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package edu.colorado.cires.pace.datastore.json; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.colorado.cires.pace.data.Ship; -import java.io.IOException; -import java.nio.file.Path; -import java.util.UUID; - -class ShipJsonDatastoreTest extends JsonDatastoreTest { - - @Override - protected Class getClazz() { - return Ship.class; - } - - @Override - protected JsonDatastore createDatastore(Path storagePath, ObjectMapper objectMapper) throws IOException { - return new ShipJsonDatastore(storagePath, objectMapper); - } - - @Override - protected Ship createNewObject() { - return new Ship( - UUID.randomUUID(), - UUID.randomUUID().toString() - ); - } - - @Override - protected void assertObjectsEqual(Ship expected, Ship actual) { - assertEquals(expected.uuid(), actual.uuid()); - assertEquals(expected. name(), actual. name()); - } -}