Skip to content

Commit

Permalink
Flatten json dataset schema with packing job schema
Browse files Browse the repository at this point in the history
  • Loading branch information
paytoncain committed Apr 26, 2024
1 parent 4149de2 commit 35f17c6
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package edu.colorado.cires.pace.data;

import edu.colorado.cires.pace.data.object.PackingJob;
import edu.colorado.cires.pace.data.object.SoundPropagationModelsDataset;
import java.nio.file.Path;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@Jacksonized
public class SoundPropagationModelsPackingJob extends SoundPropagationModelsDataset implements PackingJob {

private final Path temperaturePath;
private final Path biologicalPath;
private final Path otherPath;
private final Path documentsPath;
private final Path calibrationDocumentsPath;
private final Path navigationPath;
private final Path sourcePath;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@Data
@Builder
@SuperBuilder
@Jacksonized
public class AudioDataset implements Dataset, AudioDatasetDetail, AudioCalibrationDetail {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.colorado.cires.pace.data.object;

import java.nio.file.Path;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@Jacksonized
public class AudioPackingJob extends AudioDataset implements PackingJob {

private final Path temperaturePath;
private final Path biologicalPath;
private final Path otherPath;
private final Path documentsPath;
private final Path calibrationDocumentsPath;
private final Path navigationPath;
private final Path sourcePath;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.colorado.cires.pace.data.object;

import java.nio.file.Path;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@Jacksonized
public class CPODPackingJob extends CPodDataset implements PackingJob {

private final Path temperaturePath;
private final Path biologicalPath;
private final Path otherPath;
private final Path documentsPath;
private final Path calibrationDocumentsPath;
private final Path navigationPath;
private final Path sourcePath;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@Data
@Builder
@SuperBuilder
@Jacksonized
public class CPodDataset implements Dataset, AudioDatasetDetail, AudioCalibrationDetail {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@Data
@Builder
@SuperBuilder
@Jacksonized
public class DetectionsDataset implements Dataset, DetectionsDatasetDetail {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.colorado.cires.pace.data.object;

import java.nio.file.Path;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@Jacksonized
public class DetectionsPackingJob extends DetectionsDataset implements PackingJob {

private final Path temperaturePath;
private final Path biologicalPath;
private final Path otherPath;
private final Path documentsPath;
private final Path calibrationDocumentsPath;
private final Path navigationPath;
private final Path sourcePath;

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
package edu.colorado.cires.pace.data.object;

import jakarta.validation.Valid;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import com.fasterxml.jackson.annotation.JsonView;
import edu.colorado.cires.pace.data.SoundPropagationModelsPackingJob;
import jakarta.validation.constraints.NotNull;
import java.nio.file.Path;
import lombok.Builder;
import lombok.Data;
import lombok.extern.jackson.Jacksonized;

@Data
@Builder
@Jacksonized
public class PackingJob {

private final Path temperaturePath;
private final Path biologicalPath;
private final Path otherPath;
private final Path documentsPath;
private final Path calibrationDocumentsPath;
private final Path navigationPath;
@NotNull
private final Path sourcePath;
@NotNull @Valid
private final Dataset dataset;
@JsonTypeInfo(use = Id.NAME, include = As.EXTERNAL_PROPERTY, property = "datasetType")
@JsonSubTypes({
@Type(value = AudioPackingJob.class, name = "audio"),
@Type(value = CPODPackingJob.class, name = "CPOD"),
@Type(value = DetectionsPackingJob.class, name = "detections"),
@Type(value = SoundClipsPackingJob.class, name = "sound clips"),
@Type(value = SoundLevelMetricsPackingJob.class, name = "sound level metrics"),
@Type(value = SoundPropagationModelsPackingJob.class, name = "sound propagation models"),
})
public interface PackingJob {

@JsonView(PackingJob.class)
Path getTemperaturePath();
@JsonView(PackingJob.class)
Path getBiologicalPath();
@JsonView(PackingJob.class)
Path getOtherPath();
@JsonView(PackingJob.class)
Path getDocumentsPath();
@JsonView(PackingJob.class)
Path getCalibrationDocumentsPath();
@JsonView(PackingJob.class)
Path getNavigationPath();
@JsonView(PackingJob.class)
@NotNull
Path getSourcePath();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@Data
@Builder
@SuperBuilder
@Jacksonized
public class SoundClipsDataset implements Dataset, SoundClipsDatasetDetail {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.colorado.cires.pace.data.object;

import java.nio.file.Path;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@Jacksonized
public class SoundClipsPackingJob extends SoundClipsDataset implements PackingJob {

private final Path temperaturePath;
private final Path biologicalPath;
private final Path otherPath;
private final Path documentsPath;
private final Path calibrationDocumentsPath;
private final Path navigationPath;
private final Path sourcePath;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package edu.colorado.cires.pace.data.object;

import java.nio.file.Path;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@Jacksonized
public class SoundLevelMetricsPackingJob extends SoundClipsDataset implements PackingJob {

private final Path temperaturePath;
private final Path biologicalPath;
private final Path otherPath;
private final Path documentsPath;
private final Path calibrationDocumentsPath;
private final Path navigationPath;
private final Path sourcePath;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@Data
@Builder
@SuperBuilder
@Jacksonized
public class SoundPropagationModelsDataset implements Dataset, SoundPropagationModelsDatasetDetail {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.colorado.cires.pace.packaging;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.colorado.cires.pace.data.object.Dataset;
import java.io.FileInputStream;
Expand Down Expand Up @@ -61,7 +60,7 @@ public static boolean filterTimeSize(Path source, Path target) throws IOExceptio
}

public static Path writeMetadata(Dataset dataset, ObjectMapper objectMapper, Path targetDirectory) throws IOException {
String metadata = objectMapper.writeValueAsString(dataset);
String metadata = objectMapper.writerWithView(Dataset.class).writeValueAsString(dataset);

mkdir(targetDirectory);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.colorado.cires.pace.packaging;

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.colorado.cires.pace.data.object.Dataset;
import edu.colorado.cires.pace.data.object.PackingJob;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
Expand Down Expand Up @@ -29,7 +30,7 @@ public void process(PackingJob packingJob, Path outputDir, boolean sourceDataCon
Packager.run(
PackageInstructionFactory.getPackageInstructions(
packingJob,
FileUtils.writeMetadata(packingJob.getDataset(), objectMapper, outputDir.resolve("data")),
FileUtils.writeMetadata((Dataset) packingJob, objectMapper, outputDir.resolve("data")),
outputDir,
sourceDataContainsAudioFiles
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import edu.colorado.cires.pace.data.object.AudioPackingJob;
import edu.colorado.cires.pace.data.object.PackingJob;
import java.io.FileWriter;
import java.io.IOException;
Expand Down Expand Up @@ -66,7 +67,7 @@ void testGetPackageInstructions(
Path dp = documentsPath == null ? null : Path.of(documentsPath).toAbsolutePath();
Path cdp = calibrationDocumentsPath == null ? null : Path.of(calibrationDocumentsPath).toAbsolutePath();
Path bp = biologicalPath == null ? null : Path.of(biologicalPath).toAbsolutePath();
PackingJob packingJob = PackingJob.builder()
PackingJob packingJob = AudioPackingJob.builder()
.temperaturePath(tp)
.biologicalPath(bp)
.otherPath(op)
Expand Down Expand Up @@ -111,7 +112,7 @@ void testGetPackageInstructions(
@Test
void testPathDoesNotExist() throws IOException {
Path sourcePath = Path.of("target/source/source-files").toAbsolutePath();
PackingJob packingJob = PackingJob.builder()
PackingJob packingJob = AudioPackingJob.builder()
.sourcePath(sourcePath)
.build();
writeFiles(sourcePath);
Expand Down
Loading

0 comments on commit 35f17c6

Please sign in to comment.