diff --git a/src/main/java/edu/harvard/iq/dataverse/Dataset.java b/src/main/java/edu/harvard/iq/dataverse/Dataset.java index 96fa3a0bef3..ef2f39620e9 100644 --- a/src/main/java/edu/harvard/iq/dataverse/Dataset.java +++ b/src/main/java/edu/harvard/iq/dataverse/Dataset.java @@ -1,6 +1,7 @@ package edu.harvard.iq.dataverse; import edu.harvard.iq.dataverse.dataset.DatasetThumbnail; +import edu.harvard.iq.dataverse.dataset.DatasetType; import edu.harvard.iq.dataverse.dataset.DatasetUtil; import edu.harvard.iq.dataverse.harvest.client.HarvestingClient; import edu.harvard.iq.dataverse.license.License; @@ -38,7 +39,6 @@ import edu.harvard.iq.dataverse.storageuse.StorageUse; import edu.harvard.iq.dataverse.util.StringUtil; import edu.harvard.iq.dataverse.util.SystemConfig; -import jakarta.persistence.Transient; /** * @@ -129,8 +129,9 @@ public class Dataset extends DvObjectContainer { */ private boolean useGenericThumbnail; - @Transient - private String datasetType; + @OneToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST}) + @JoinColumn(name = "datasettype_id", nullable = true) + private DatasetType datasetType; @OneToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST}) @JoinColumn(name = "guestbook_id", unique = false, nullable = true, insertable = true, updatable = true) @@ -741,11 +742,11 @@ public void setUseGenericThumbnail(boolean useGenericThumbnail) { this.useGenericThumbnail = useGenericThumbnail; } - public String getDatasetType() { + public DatasetType getDatasetType() { return datasetType; } - public void setDatasetType(String datasetType) { + public void setDatasetType(DatasetType datasetType) { this.datasetType = datasetType; } diff --git a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetType.java b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetType.java new file mode 100644 index 00000000000..0d47d6a5885 --- /dev/null +++ b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetType.java @@ -0,0 +1,79 @@ +package edu.harvard.iq.dataverse.dataset; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import java.io.Serializable; +import java.util.Arrays; + +@Entity +public class DatasetType implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private Type baseType; + + /** + * This default constructor is only here to prevent this error at + * deployment: + * + * Exception Description: The instance creation method + * [...DatasetType.], with no parameters, does not + * exist, or is not accessible + * + * Don't use it. + */ + @Deprecated + public DatasetType() { + } + + public DatasetType(Type baseType) { + this.baseType = baseType; + } + + public enum Type { + + DATASET("dataset"), + SOFTWARE("software"), + WORKFLOW("workflow"); + + private final String text; + + private Type(final String text) { + this.text = text; + } + + public static Type fromString(String text) { + if (text != null) { + for (Type type : Type.values()) { + if (text.equals(type.text)) { + return type; + } + } + } + throw new IllegalArgumentException("Type must be one of these values: " + Arrays.asList(Type.values()) + "."); + } + + @Override + public String toString() { + return text; + } + } + + public Type getBaseType() { + return baseType; + } + + public void setBaseType(Type baseType) { + this.baseType = baseType; + } + +} diff --git a/src/main/java/edu/harvard/iq/dataverse/dataverse/DataverseUtil.java b/src/main/java/edu/harvard/iq/dataverse/dataverse/DataverseUtil.java index 0fac22ef480..f13f73f2dc8 100644 --- a/src/main/java/edu/harvard/iq/dataverse/dataverse/DataverseUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/dataverse/DataverseUtil.java @@ -125,13 +125,12 @@ public static void checkMetadataLangauge(Dataset ds, Dataverse owner, Map