Skip to content

Commit

Permalink
Add data collection name as additional unique value for packages
Browse files Browse the repository at this point in the history
  • Loading branch information
paytoncain committed Aug 2, 2024
1 parent 8d3e32d commit a3defc5
Show file tree
Hide file tree
Showing 18 changed files with 381 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,9 @@ public AudioPackage createObject(String uniqueField, boolean withUUID) {
.calibrationDocumentsPath(testPath.resolve("calibrationDocumentsPath").toAbsolutePath())
.navigationPath(testPath.resolve("navigationPath").toAbsolutePath())
.sourcePath(testPath.resolve("sourcePath").toAbsolutePath())
.siteOrCruiseName("siteOrCruiseName")
.siteOrCruiseName(uniqueField)
.deploymentId(uniqueField)
.dataCollectionName(uniqueField)
.datasetPackager(datasetPackager.getName())
.projects(List.of(project.getName()))
.publicReleaseDate(LocalDate.of(2020, 1,1))
Expand Down Expand Up @@ -606,6 +607,8 @@ public AudioPackage createObject(String uniqueField, boolean withUUID) {
protected AudioPackage updateObject(AudioPackage original, String uniqueField) {
return original.toBuilder()
.deploymentId(uniqueField)
.siteOrCruiseName(uniqueField)
.dataCollectionName(uniqueField)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
Expand Down Expand Up @@ -66,6 +67,7 @@ protected String getUniqueFieldCommandSuffix() {
protected String[] getTranslatorFields() {
List<String> fields = new ArrayList<>(List.of(
"UUID",
"dataCollectionName",
"timeZone",
"temperaturePath",
"biologicalPath",
Expand Down Expand Up @@ -105,6 +107,7 @@ protected T createTranslator(String name) {
PackageTranslator packageTranslator = PackageTranslator.builder()
.name(name)
.packageUUID("UUID")
.dataCollectionName("dataCollectionName")
.temperaturePath("temperaturePath")
.biologicalPath("biologicalPath")
.otherPath("otherPath")
Expand Down Expand Up @@ -156,6 +159,7 @@ protected T createTranslator(String name) {
protected String[] objectToRow(P object) {
List<String> fields = new ArrayList<>(List.of(
object.getUuid() == null ? "" : object.getUuid().toString(),
object.getDataCollectionName(),
"UTC",
object.getTemperaturePath().toString(),
object.getBiologicalPath().toString(),
Expand Down Expand Up @@ -237,6 +241,7 @@ protected void assertObjectsEqual(P expected, P actual, boolean checkUUID) throw
assertEquals(expected.getSiteOrCruiseName(), actual.getSiteOrCruiseName());
assertEquals(expected.getDeploymentId(), actual.getDeploymentId());
assertEquals(expected.getDatasetPackager(), actual.getDatasetPackager());
assertEquals(expected.getDataCollectionName(), actual.getDataCollectionName());

for (int i = 0; i < expected.getProjects().size(); i++) {
assertEquals(
Expand Down Expand Up @@ -326,22 +331,22 @@ void testPackage(boolean useSavedObject) throws IOException {
execute("package", "process", packageFile.toString(), outputDirectory.toString());

Set<String> expectedPaths = Set.of(
"target/test-dir/output/project 1_siteOrCruiseName_test/bagit.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/bag-info.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/process.log",
"target/test-dir/output/project 1_siteOrCruiseName_test/tagmanifest-sha256.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/nav_files/navigationPath.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/calibration/calibrationDocumentsPath.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/project 1_siteOrCruiseName_test.json",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/other/otherPath.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/organizations.json",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/docs/documentsPath.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/projects.json",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/acoustic_files/sourcePath.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/biological/biologicalPath.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/people.json",
"target/test-dir/output/project 1_siteOrCruiseName_test/data/temperature/temperaturePath.txt",
"target/test-dir/output/project 1_siteOrCruiseName_test/manifest-sha256.txt"
"target/test-dir/output/test/bagit.txt",
"target/test-dir/output/test/bag-info.txt",
"target/test-dir/output/test/process.log",
"target/test-dir/output/test/tagmanifest-sha256.txt",
"target/test-dir/output/test/data/nav_files/navigationPath.txt",
"target/test-dir/output/test/data/calibration/calibrationDocumentsPath.txt",
"target/test-dir/output/test/data/test.json",
"target/test-dir/output/test/data/other/otherPath.txt",
"target/test-dir/output/test/data/organizations.json",
"target/test-dir/output/test/data/docs/documentsPath.txt",
"target/test-dir/output/test/data/projects.json",
"target/test-dir/output/test/data/acoustic_files/sourcePath.txt",
"target/test-dir/output/test/data/biological/biologicalPath.txt",
"target/test-dir/output/test/data/people.json",
"target/test-dir/output/test/data/temperature/temperaturePath.txt",
"target/test-dir/output/test/manifest-sha256.txt"
);

Set<String> actualPaths = Files.walk(outputDirectory.toPath())
Expand Down Expand Up @@ -411,9 +416,26 @@ void testCreateValidationException() throws IOException {
), exception.message());

ArrayList<?> detail = (ArrayList<?>) exception.detail();
assertEquals(1, detail.size());
Map<String, Object> map = (Map<String, Object>) detail.get(0);
assertEquals("deploymentId", map.get("field"));
assertEquals("must not be blank", map.get("message"));
assertEquals(3, detail.size());

Map<String, String> map = detail.stream()
.map(o -> (Map<String, Object>) o)
.collect(Collectors.toMap(
d -> (String) d.get("field"),
d -> (String) d.get("message")
));

assertEquals(3, map.keySet().size());

assertEquals(
Set.of("deploymentId","siteOrCruiseName","dataCollectionName"),
map.keySet()
);

assertTrue(
map.values().stream().allMatch(
v -> v.equals("at least dataCollectionName, siteOrCruiseName, or deploymentId required")
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class AudioPackageTranslator extends AudioDataPackageTranslator {
return AudioPackageTranslator
.builder()
.uuid(packageTranslator.getUuid())
.dataCollectionName(packageTranslator.getDataCollectionName())
.name(packageTranslator.getName())
.packageUUID(packageTranslator.getPackageUUID())
.temperaturePath(packageTranslator.getTemperaturePath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class CPODPackageTranslator extends AudioDataPackageTranslator {
public static CPODPackageTranslatorBuilder<?, ?> toBuilder(PackageTranslator packageTranslator) {
return CPODPackageTranslator.builder()
.uuid(packageTranslator.getUuid())
.dataCollectionName(packageTranslator.getDataCollectionName())
.name(packageTranslator.getName())
.packageUUID(packageTranslator.getPackageUUID())
.temperaturePath(packageTranslator.getTemperaturePath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.StringUtils;

@Data
@EqualsAndHashCode
Expand All @@ -38,10 +39,12 @@ public abstract class BasePackage<T> implements AbstractObject, TimeRange, Calib
@NotNull
private final Path sourcePath;

@NotBlank
private final String dataCollectionName;
private final String siteOrCruiseName;
@NotBlank
private final String deploymentId;
@NotNull
protected abstract List<@NotNull @Valid T> getProjects();

@NotNull
private final LocalDate publicReleaseDate;
@NotNull @Valid
Expand All @@ -67,9 +70,6 @@ public abstract class BasePackage<T> implements AbstractObject, TimeRange, Calib
@NotNull
@NotEmpty
protected abstract List<@NotNull @Valid T> getScientists();
@NotNull
@NotEmpty
protected abstract List<@NotNull @Valid T> getProjects();
@NotNull @NotEmpty
protected abstract List<@NotNull @Valid T> getSponsors();
@NotNull @NotEmpty
Expand All @@ -89,6 +89,10 @@ public String getUniqueField() {

@JsonIgnore
public String getPackageId() {
if (StringUtils.isNotBlank(dataCollectionName)) {
return dataCollectionName;
}

String packageId = null;

List<String> projects = getProjects() == null ? Collections.emptyList() : getProjectNames();
Expand Down Expand Up @@ -117,7 +121,7 @@ public String getPackageId() {
);
}
}

return packageId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import edu.colorado.cires.pace.data.object.dataset.soundClips.SoundClipsPackage;
import edu.colorado.cires.pace.data.object.dataset.soundLevelMetrics.SoundLevelMetricsPackage;
import edu.colorado.cires.pace.data.object.dataset.soundPropagationModels.SoundPropagationModelsPackage;
import edu.colorado.cires.pace.data.validation.ValidPackageIdentifiers;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
Expand All @@ -33,12 +34,13 @@
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
@ValidPackageIdentifiers
public abstract class Package extends BasePackage<String> {
@NotBlank
private final String datasetPackager;
@NotEmpty @NotNull
private final List<@NotBlank String> scientists;
@NotNull @NotEmpty
@NotNull
private final List<@NotBlank String> projects;
@NotNull @NotEmpty
private final List<@NotBlank String> sponsors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@SuperBuilder(toBuilder = true)
public class PackageTranslator extends Translator {
private final String packageUUID;
private final String dataCollectionName;
private final String temperaturePath;
private final String biologicalPath;
private final String otherPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class DetectionsPackageTranslator extends SoundAnalysisPackageTranslator
public static DetectionsPackageTranslatorBuilder<?, ?> toBuilder(PackageTranslator packageTranslator) {
return DetectionsPackageTranslator.builder()
.uuid(packageTranslator.getUuid())
.dataCollectionName(packageTranslator.getDataCollectionName())
.name(packageTranslator.getName())
.packageUUID(packageTranslator.getPackageUUID())
.temperaturePath(packageTranslator.getTemperaturePath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SoundClipsPackageTranslator extends SoftwareDependentPackageTransla
public static SoundClipsPackageTranslatorBuilder<?, ?> toBuilder(PackageTranslator packageTranslator) {
return SoundClipsPackageTranslator.builder()
.uuid(packageTranslator.getUuid())
.dataCollectionName(packageTranslator.getDataCollectionName())
.name(packageTranslator.getName())
.packageUUID(packageTranslator.getPackageUUID())
.temperaturePath(packageTranslator.getTemperaturePath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class SoundLevelMetricsPackageTranslator extends SoundAnalysisPackageTran
public static SoundLevelMetricsPackageTranslatorBuilder<?, ?> toBuilder(PackageTranslator packageTranslator) {
return SoundLevelMetricsPackageTranslator.builder()
.uuid(packageTranslator.getUuid())
.dataCollectionName(packageTranslator.getDataCollectionName())
.name(packageTranslator.getName())
.packageUUID(packageTranslator.getPackageUUID())
.temperaturePath(packageTranslator.getTemperaturePath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class SoundPropagationModelsPackageTranslator extends SoftwareDependentPa
public static SoundPropagationModelsPackageTranslatorBuilder<?, ?> toBuilder(PackageTranslator packageTranslator) {
return SoundPropagationModelsPackageTranslator.builder()
.uuid(packageTranslator.getUuid())
.dataCollectionName(packageTranslator.getDataCollectionName())
.name(packageTranslator.getName())
.packageUUID(packageTranslator.getPackageUUID())
.temperaturePath(packageTranslator.getTemperaturePath())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package edu.colorado.cires.pace.data.validation;

import edu.colorado.cires.pace.data.object.dataset.base.Package;
import edu.colorado.cires.pace.data.validation.ValidPackageIdentifiers.ValidPackageIdentifiersValidator;
import jakarta.validation.Constraint;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import jakarta.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.commons.lang3.StringUtils;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = ValidPackageIdentifiersValidator.class)
@Documented
public @interface ValidPackageIdentifiers {

String message() default "at least dataCollectionName, siteOrCruiseName, or deploymentId required";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};

class ValidPackageIdentifiersValidator implements ConstraintValidator<ValidPackageIdentifiers, Package> {

@Override
public boolean isValid(Package aPackage, ConstraintValidatorContext context) {
String dataCollectionName = aPackage.getDataCollectionName();
String siteOrCruiseName = aPackage.getSiteOrCruiseName();
String deploymentId = aPackage.getDeploymentId();

if (
StringUtils.isBlank(dataCollectionName) &&
StringUtils.isBlank(siteOrCruiseName) &&
StringUtils.isBlank(deploymentId)
) {
context.disableDefaultConstraintViolation();
String message = "at least dataCollectionName, siteOrCruiseName, or deploymentId required";
context.buildConstraintViolationWithTemplate(message)
.addPropertyNode("dataCollectionName")
.addConstraintViolation();
context.buildConstraintViolationWithTemplate(message)
.addPropertyNode("siteOrCruiseName")
.addConstraintViolation();
context.buildConstraintViolationWithTemplate(message)
.addPropertyNode("deploymentId")
.addConstraintViolation();

return false;
}

return true;
}
}

}
Loading

0 comments on commit a3defc5

Please sign in to comment.