Skip to content

Commit

Permalink
Simplify JsonDatastore module
Browse files Browse the repository at this point in the history
  • Loading branch information
paytoncain committed Apr 9, 2024
1 parent ec18371 commit d4715d1
Show file tree
Hide file tree
Showing 35 changed files with 96 additions and 740 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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;

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
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileType> createDatastore(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException {
return new JsonDatastore<>(
datastoreDirectory, objectMapper, FileType.class
) {};
}

public static FileTypeController createController(Path datastoreDirectory, ObjectMapper objectMapper) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

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;

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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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;

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
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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;

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
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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;

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
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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;

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
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

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;

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
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

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;

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
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

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;

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
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

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;

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
)
);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import java.util.function.Function;
import java.util.stream.Stream;

public abstract class JsonDatastore<O extends ObjectWithUniqueField> implements Datastore<O> {
public class JsonDatastore<O extends ObjectWithUniqueField> implements Datastore<O> {

private final Path storageDirectory;
private final ObjectMapper objectMapper;
private final Class<O> clazz;

protected JsonDatastore(Path storageDirectory, ObjectMapper objectMapper, Class<O> clazz) throws IOException {
public JsonDatastore(Path storageDirectory, ObjectMapper objectMapper, Class<O> clazz) throws IOException {
this.storageDirectory = storageDirectory;
this.objectMapper = objectMapper;
this.clazz = clazz;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d4715d1

Please sign in to comment.