diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java new file mode 100644 index 0000000..3a4759e --- /dev/null +++ b/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java @@ -0,0 +1,104 @@ +package net.onelitefeather.vulpes.api.model; + +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MappedSuperclass; +import jakarta.validation.constraints.NotNull; +import net.onelitefeather.vulpes.api.model.project.ProjectEntity; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +/** + * Base class for every entity that belongs to a {@link ProjectEntity}. Adds the project + * reference and the entity's local key, which combine into a namespaced key + * (e.g. {@code cygnus:whatever}) via {@link #getNamespacedKey()}. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 2.2.0 + */ +@MappedSuperclass +public abstract class AbstractEntity extends IdentifiableEntity { + + @ManyToOne + @JoinColumn(name = "project_id", nullable = false) + @OnDelete(action = OnDeleteAction.CASCADE) + private ProjectEntity project; + + @NotNull + private String key; + + /** + * Default constructor for JPA and Micronaut Data. + */ + protected AbstractEntity() { + // No-argument constructor for JPA + } + + /** + * Constructs a new {@link AbstractEntity} with the specified local key and project. + * + * @param key the local key of the entity within the project's namespace + * @param project the project this entity belongs to + */ + protected AbstractEntity(String key, ProjectEntity project) { + this.key = key; + this.project = project; + } + + /** + * Returns the project this entity belongs to. + * + * @return the project of the entity + */ + public ProjectEntity getProject() { + return project; + } + + /** + * Sets the project this entity belongs to. + * + * @param project the project to set + */ + public void setProject(ProjectEntity project) { + this.project = project; + } + + /** + * Returns the local key of the entity within its project's namespace (e.g. {@code whatever}). + * + * @return the local key of the entity + */ + public String getKey() { + return key; + } + + /** + * Sets the local key of the entity within its project's namespace (e.g. {@code whatever}). + * + * @param key the local key to set + */ + public void setKey(String key) { + this.key = key; + } + + /** + * Returns the full namespaced key, combining the project's key with this entity's local key + * (e.g. project key {@code cygnus} and local key {@code whatever} become {@code cygnus:whatever}). + * + * @return the namespaced key of the entity + */ + public String getNamespacedKey() { + return project.getKey() + ":" + key; + } + + /** + * Derives the variable name of the entity from its local key, e.g. local key {@code whatever} + * becomes {@code WHATEVER}. + * + * @return the derived variable name of the entity + */ + public String getVariableName() { + return key.toUpperCase(); + } +} diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java index 4b4da40..b8ad4f4 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java @@ -1,17 +1,10 @@ package net.onelitefeather.vulpes.api.model; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import jakarta.persistence.UniqueConstraint; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.UUID; @@ -27,21 +20,14 @@ @Entity(name = "attributes") @Table(name = "attributes", indexes = { @Index(name = "idx_attributes_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_attributes_project_key", columnNames = {"project_id", "key"}) }) -public class AttributeEntity implements VulpesModel { +public class AttributeEntity extends AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String uiName; - private String variableName; private double defaultValue; private double maximumValue; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; /** * Default constructor for JPA and Micronaut Data. @@ -58,40 +44,23 @@ public AttributeEntity() { * * @param id the unique identifier of the attribute * @param uiName the model name associated with the attribute - * @param variableName the name of the attribute + * @param key the local key of the attribute within the project's namespace + * (e.g. {@code generic.max_health}, becomes {@code :generic.max_health} + * via {@link #getNamespacedKey()}) * @param defaultValue the default value of the attribute * @param maximumValue the maximum value of the attribute * @param project the project this attribute belongs to */ - public AttributeEntity(UUID id, String uiName, String variableName, double defaultValue, double maximumValue, ProjectEntity project) { - this.id = id; + public AttributeEntity(UUID id, String uiName, String key, double defaultValue, double maximumValue, ProjectEntity project) { + super(key, project); + this.setId(id); this.uiName = uiName; - this.variableName = variableName; this.defaultValue = defaultValue; this.maximumValue = maximumValue; - this.project = project; } // Getters and setters for each field - /** - * Returns the unique identifier of the attribute - * - * @return the unique identifier of the attribute - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the attribute - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Returns the model name associated with the attribute * @@ -110,24 +79,6 @@ public void setUiName(String modelName) { this.uiName = modelName; } - /** - * Returns the name of the attribute - * - * @return the name of the attribute - */ - public String getVariableName() { - return variableName; - } - - /** - * Sets the name of the attribute - * - * @param name the name to set - */ - public void setVariableName(String name) { - this.variableName = name; - } - /** * Returns the default value of the attribute * @@ -164,24 +115,6 @@ public void setMaximumValue(double maximumValue) { this.maximumValue = maximumValue; } - /** - * Returns the project this attribute belongs to. - * - * @return the project of the attribute - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this attribute belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - /** * Provides a string representation of the AttributeModel * @@ -190,12 +123,12 @@ public void setProject(ProjectEntity project) { @Override public String toString() { return "AttributeModel{" + - "id='" + id + '\'' + + "id='" + getId() + '\'' + ", modelName='" + uiName + '\'' + - ", name='" + variableName + '\'' + + ", key='" + getKey() + '\'' + ", defaultValue=" + defaultValue + ", maximumValue=" + maximumValue + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java index b51aa30..f423f4d 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java @@ -2,19 +2,12 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import jakarta.persistence.UniqueConstraint; import net.onelitefeather.vulpes.api.model.font.FontStringEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.List; import java.util.UUID; @@ -31,15 +24,12 @@ @Entity(name = "fonts") @Table(name = "fonts", indexes = { @Index(name = "idx_fonts_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_fonts_project_key", columnNames = {"project_id", "key"}) }) -public class FontEntity implements VulpesModel { +public class FontEntity extends AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String uiName; - private String variableName; private String provider; private String mapper = "font"; private String texturePath; @@ -49,11 +39,6 @@ public class FontEntity implements VulpesModel { @OneToMany(mappedBy = "font", cascade = CascadeType.ALL) private List chars; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; - /** * Default constructor for JPA and Micronaut Data. *

@@ -69,7 +54,9 @@ public FontEntity() { * * @param id the unique identifier of the font * @param uiName the user interface name of the font - * @param variableName the variable name of the font + * @param key the local key of the font within the project's namespace + * (e.g. {@code default}, becomes {@code :default} + * via {@link #getNamespacedKey()}) * @param provider the provider of the font * @param texturePath the path to the texture of the font * @param comment a comment or description for the font @@ -81,7 +68,7 @@ public FontEntity() { public FontEntity( UUID id, String uiName, - String variableName, + String key, String provider, String texturePath, String comment, @@ -90,38 +77,19 @@ public FontEntity( List chars, ProjectEntity project ) { - this.id = id; + super(key, project); + this.setId(id); this.uiName = uiName; - this.variableName = variableName; this.provider = provider; this.texturePath = texturePath; this.comment = comment; this.height = height; this.ascent = ascent; this.chars = chars; - this.project = project; } // Getters and setters for each field - /** - * Returns the unique identifier of the font - * - * @return the unique identifier of the font - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the font - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - public void setUiName(String uiName) { this.uiName = uiName; } @@ -130,14 +98,6 @@ public String getUiName() { return uiName; } - public void setVariableName(String variableName) { - this.variableName = variableName; - } - - public String getVariableName() { - return variableName; - } - public void setMapper(String mapper) { this.mapper = mapper; } @@ -224,30 +184,12 @@ public void setChars(List chars) { this.chars = chars; } - /** - * Returns the project this font belongs to. - * - * @return the project of the font - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this font belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - @Override public String toString() { return "FontEntity{" + - "id=" + id + + "id=" + getId() + ", uiName='" + uiName + '\'' + - ", variableName='" + variableName + '\'' + + ", key='" + getKey() + '\'' + ", provider='" + provider + '\'' + ", mapper='" + mapper + '\'' + ", texturePath='" + texturePath + '\'' + @@ -255,7 +197,7 @@ public String toString() { ", height=" + height + ", ascent=" + ascent + ", chars=" + chars + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/IdentifiableEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/IdentifiableEntity.java new file mode 100644 index 0000000..17fa250 --- /dev/null +++ b/src/main/java/net/onelitefeather/vulpes/api/model/IdentifiableEntity.java @@ -0,0 +1,72 @@ +package net.onelitefeather.vulpes.api.model; + +import io.micronaut.data.annotation.DateCreated; +import io.micronaut.data.annotation.DateUpdated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import net.onelitefeather.vulpes.api.generator.VulpesGenerator; + +import java.time.Instant; +import java.util.UUID; + +/** + * Base class for all entities of the Vulpes model. Bundles the fields that are common to every + * entity: the generated identifier and the creation/modification timestamps, which are maintained + * automatically by Micronaut Data. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 2.2.0 + */ +@MappedSuperclass +public abstract class IdentifiableEntity implements VulpesModel { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @VulpesGenerator + private UUID id; + + @DateCreated + private Instant creationDate; + + @DateUpdated + private Instant modificationDate; + + /** + * Returns the unique identifier of the entity. + * + * @return the unique identifier + */ + public UUID getId() { + return id; + } + + /** + * Sets the unique identifier of the entity. + * + * @param id the unique identifier to set + */ + public void setId(UUID id) { + this.id = id; + } + + /** + * Returns the point in time at which the entity was created. + * + * @return the creation date + */ + public Instant getCreationDate() { + return creationDate; + } + + /** + * Returns the point in time at which the entity was last modified. + * + * @return the modification date + */ + public Instant getModificationDate() { + return modificationDate; + } +} diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java index a40efa5..5722fc1 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java @@ -2,21 +2,14 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import jakarta.persistence.UniqueConstraint; import net.onelitefeather.vulpes.api.model.item.ItemEnchantmentEntity; import net.onelitefeather.vulpes.api.model.item.ItemFlagEntity; import net.onelitefeather.vulpes.api.model.item.ItemLoreEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.List; import java.util.UUID; @@ -33,16 +26,12 @@ @Entity(name = "items") @Table(name = "items", indexes = { @Index(name = "idx_items_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_items_project_key", columnNames = {"project_id", "key"}) }) -public class ItemEntity implements VulpesModel { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public class ItemEntity extends AbstractEntity { private String uiName; - private String variableName; private String comment; private String displayName; private String material; @@ -56,11 +45,6 @@ public class ItemEntity implements VulpesModel { @OneToMany(mappedBy = "item", cascade = CascadeType.ALL) private List flags; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; - /** * Default constructor for JPA and Micronaut Data. *

@@ -76,7 +60,9 @@ public ItemEntity() { * * @param id the unique identifier of the item * @param uiName the model name associated with the item - * @param variableName the name of the item + * @param key the local key of the item within the project's namespace + * (e.g. {@code dirt}, becomes {@code :dirt} + * via {@link #getNamespacedKey()}) * @param comment a description of the item * @param displayName the display name of the item * @param material the material type associated with the item @@ -91,7 +77,7 @@ public ItemEntity() { public ItemEntity( UUID id, String uiName, - String variableName, + String key, String comment, String displayName, String material, @@ -103,9 +89,9 @@ public ItemEntity( List flags, ProjectEntity project ) { - this.id = id; + super(key, project); + this.setId(id); this.uiName = uiName; - this.variableName = variableName; this.comment = comment; this.displayName = displayName; this.material = material; @@ -115,29 +101,10 @@ public ItemEntity( this.enchantments = enchantments; this.lore = lore; this.flags = flags; - this.project = project; } // Getters and setters for each field - /** - * Returns the unique identifier of the item. - * - * @return the unique identifier of the item - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the item. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Sets the name representation for the ui * @@ -156,24 +123,6 @@ public String getUiName() { return uiName; } - /** - * Sets the variable name for the notification - * - * @param variableName the variable name to set - */ - public void setVariableName(String variableName) { - this.variableName = variableName; - } - - /** - * Returns the variable name for the notification - * - * @return the variable name of the notification - */ - public String getVariableName() { - return variableName; - } - /** * Returns the comment of the notification * @@ -336,24 +285,6 @@ public void setFlags(List flags) { this.flags = flags; } - /** - * Returns the project this item belongs to. - * - * @return the project of the item - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this item belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - /** * Provides a string representation of the ItemModel. * @@ -362,9 +293,9 @@ public void setProject(ProjectEntity project) { @Override public String toString() { return "ItemModel{" + - "id='" + id + '\'' + + "id='" + getId() + '\'' + ", modelName='" + uiName + '\'' + - ", name='" + variableName + '\'' + + ", key='" + getKey() + '\'' + ", comment='" + comment + '\'' + ", displayName='" + displayName + '\'' + ", material='" + material + '\'' + @@ -374,7 +305,7 @@ public String toString() { ", enchantments=" + enchantments + ", lore=" + lore + ", flags=" + flags + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java index 1fae6da..aaf9acc 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java @@ -1,17 +1,10 @@ package net.onelitefeather.vulpes.api.model; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import jakarta.persistence.UniqueConstraint; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.UUID; @@ -27,23 +20,16 @@ @Entity(name = "notifications") @Table(name = "notifications", indexes = { @Index(name = "idx_notifications_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_notifications_project_key", columnNames = {"project_id", "key"}) }) -public class NotificationEntity implements VulpesModel { +public class NotificationEntity extends AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String uiName; - private String variableName; private String comment; private String material; private String frameType; private String title; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; /** * Default constructor for JPA and Micronaut Data. @@ -60,40 +46,23 @@ public NotificationEntity() { * * @param id the unique identifier of the notification * @param uiName the user interface name of the notification - * @param variableName the variable name of the notification + * @param key the local key of the notification within the project's namespace + * (e.g. {@code achievement}, becomes {@code :achievement} + * via {@link #getNamespacedKey()}) * @param comment a comment for the description * @param material the material type associated with the notification * @param frameType the frame type associated with the notification * @param title the title of the notification * @param project the project this notification belongs to */ - public NotificationEntity(UUID id, String uiName, String variableName, String comment, String material, String frameType, String title, ProjectEntity project) { - this.id = id; + public NotificationEntity(UUID id, String uiName, String key, String comment, String material, String frameType, String title, ProjectEntity project) { + super(key, project); + this.setId(id); this.uiName = uiName; - this.variableName = variableName; this.comment = comment; this.material = material; this.frameType = frameType; this.title = title; - this.project = project; - } - - /** - * Returns the unique identifier of the notification - * - * @return the unique identifier of the notification - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the notification - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; } /** @@ -114,24 +83,6 @@ public String getUiName() { return uiName; } - /** - * Sets the variable name for the notification - * - * @param variableName the variable name to set - */ - public void setVariableName(String variableName) { - this.variableName = variableName; - } - - /** - * Returns the variable name for the notification - * - * @return the variable name of the notification - */ - public String getVariableName() { - return variableName; - } - /** * Returns the comment of the notification * @@ -204,24 +155,6 @@ public void setTitle(String title) { this.title = title; } - /** - * Returns the project this notification belongs to. - * - * @return the project of the notification - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this notification belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - /** * Provides a string representation of the NotificationModel * @@ -230,14 +163,14 @@ public void setProject(ProjectEntity project) { @Override public String toString() { return "NotificationModel{" + - "id='" + id + '\'' + + "id='" + getId() + '\'' + ", uiName='" + uiName + '\'' + - ", variableName='" + variableName + '\'' + + ", key='" + getKey() + '\'' + ", description='" + comment + '\'' + ", material='" + material + '\'' + ", frameType='" + frameType + '\'' + ", title='" + title + '\'' + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java index 2b324a7..07e35a6 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java @@ -3,15 +3,12 @@ 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 jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -37,12 +34,7 @@ @Table(name = "dimension_attributes", indexes = { @Index(name = "idx_dimension_attributes_type_key", columnList = "dimension_type_id, attribute_key", unique = true) }) -public final class DimensionAttributeEntity { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class DimensionAttributeEntity extends IdentifiableEntity { @NotNull @Enumerated(EnumType.STRING) @@ -81,30 +73,12 @@ public DimensionAttributeEntity( AttributeOperator operator, String attributeValue ) { - this.id = id; + this.setId(id); this.attributeKey = attributeKey; this.operator = operator; this.attributeValue = attributeValue; } - /** - * Sets the unique identifier of the attribute entry. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the attribute entry. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the key identifying the environment attribute. * @@ -182,7 +156,7 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (DimensionAttributeEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.attributeKey, that.attributeKey) && this.operator == that.operator && Objects.equals(this.attributeValue, that.attributeValue) && @@ -191,13 +165,13 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return Objects.hash(id, attributeKey, operator, attributeValue, dimensionType); + return Objects.hash(getId(), attributeKey, operator, attributeValue, dimensionType); } @Override public String toString() { return "DimensionAttributeEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "attributeKey=" + attributeKey + ", " + "operator=" + operator + ", " + "attributeValue=" + attributeValue + ", " + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java index 6338e05..cc2fc72 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java @@ -1,15 +1,12 @@ package net.onelitefeather.vulpes.api.model.dimension; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -33,12 +30,7 @@ @Table(name = "dimension_timelines", indexes = { @Index(name = "idx_dimension_timelines_type_key", columnList = "dimension_type_id, timeline_key", unique = true) }) -public final class DimensionTimelineEntity { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class DimensionTimelineEntity extends IdentifiableEntity { @NotNull private String timelineKey; @@ -65,28 +57,10 @@ public DimensionTimelineEntity( UUID id, String timelineKey ) { - this.id = id; + this.setId(id); this.timelineKey = timelineKey; } - /** - * Sets the unique identifier of the timeline reference. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the timeline reference. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the registry key of the referenced timeline. * @@ -128,20 +102,20 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (DimensionTimelineEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.timelineKey, that.timelineKey) && Objects.equals(this.dimensionType, that.dimensionType); } @Override public int hashCode() { - return Objects.hash(id, timelineKey, dimensionType); + return Objects.hash(getId(), timelineKey, dimensionType); } @Override public String toString() { return "DimensionTimelineEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "timelineKey=" + timelineKey + ", " + "dimensionType=" + dimensionType + ']'; } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java index 9475d67..da209a9 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java @@ -5,25 +5,18 @@ import jakarta.persistence.Entity; import jakarta.persistence.Enumerated; import jakarta.persistence.EnumType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import jakarta.validation.constraints.DecimalMax; import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; -import net.onelitefeather.vulpes.api.model.VulpesModel; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; import org.hibernate.annotations.ColumnDefault; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.List; import java.util.UUID; @@ -52,20 +45,14 @@ @Entity(name = "dimension_types") @Table(name = "dimension_types", indexes = { @Index(name = "idx_dimension_types_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_dimension_types_project_key", columnNames = {"project_id", "key"}) }) -public class DimensionTypeEntity implements VulpesModel { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public class DimensionTypeEntity extends AbstractEntity { @NotNull private String uiName; - @NotNull - private String variableName; - @ColumnDefault("false") private boolean hasFixedTime; @@ -121,11 +108,6 @@ public class DimensionTypeEntity implements VulpesModel { @OneToMany(mappedBy = "dimensionType", cascade = CascadeType.ALL) private List timelines; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; - /** * Default constructor for JPA and Micronaut Data. *

@@ -141,7 +123,9 @@ public DimensionTypeEntity() { * * @param id the unique identifier of the dimension type * @param uiName the user interface name of the dimension type - * @param variableName the variable name of the dimension type + * @param key the local key of the dimension type within the project's namespace + * (e.g. {@code overworld}, becomes {@code :overworld} + * via {@link #getNamespacedKey()}) * @param hasFixedTime whether the dimension type has a fixed time * @param hasSkylight whether the dimension type has skylight * @param hasCeiling whether the dimension type has a ceiling @@ -164,7 +148,7 @@ public DimensionTypeEntity() { public DimensionTypeEntity( UUID id, String uiName, - String variableName, + String key, boolean hasFixedTime, boolean hasSkylight, boolean hasCeiling, @@ -184,9 +168,9 @@ public DimensionTypeEntity( List timelines, ProjectEntity project ) { - this.id = id; + super(key, project); + this.setId(id); this.uiName = uiName; - this.variableName = variableName; this.hasFixedTime = hasFixedTime; this.hasSkylight = hasSkylight; this.hasCeiling = hasCeiling; @@ -204,29 +188,10 @@ public DimensionTypeEntity( this.defaultClock = defaultClock; this.attributes = attributes; this.timelines = timelines; - this.project = project; } // Getters and setters for each field - /** - * Returns the unique identifier of the dimension type. - * - * @return the unique identifier of the dimension type - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the dimension type. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Returns the user interface name of the dimension type. * @@ -245,23 +210,6 @@ public void setUiName(String uiName) { this.uiName = uiName; } - /** - * Returns the variable name of the dimension type. - * - * @return the variable name - */ - public String getVariableName() { - return variableName; - } - - /** - * Sets the variable name of the dimension type. - * - * @param variableName the variable name to set - */ - public void setVariableName(String variableName) { - this.variableName = variableName; - } /** * Returns whether the dimension type has a fixed time. @@ -570,30 +518,12 @@ public void setTimelines(List timelines) { this.timelines = timelines; } - /** - * Returns the project this dimension type belongs to. - * - * @return the project of the dimension type - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this dimension type belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - @Override public String toString() { return "DimensionTypeEntity{" + - "id=" + id + + "id=" + getId() + ", uiName='" + uiName + '\'' + - ", variableName='" + variableName + '\'' + + ", key='" + getKey() + '\'' + ", hasFixedTime=" + hasFixedTime + ", hasSkylight=" + hasSkylight + ", hasCeiling=" + hasCeiling + @@ -611,7 +541,7 @@ public String toString() { ", defaultClock='" + defaultClock + '\'' + ", attributes=" + attributes + ", timelines=" + timelines + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java index ecf9ce5..4dde75f 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java @@ -1,12 +1,9 @@ package net.onelitefeather.vulpes.api.model.font; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import net.onelitefeather.vulpes.api.model.FontEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -15,11 +12,7 @@ import java.util.UUID; @Entity(name = "font_string") -public final class FontStringEntity implements Comparable { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class FontStringEntity extends IdentifiableEntity implements Comparable { private String line; @ManyToOne @JoinColumn(name = "font_id", nullable = false) @@ -46,29 +39,11 @@ public FontStringEntity( String content, int orderIndex ) { - this.id = id; + this.setId(id); this.line = content; this.orderIndex = orderIndex; } - /** - * Sets the unique identifier of the font string. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the font string. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the content of the font string. * @@ -128,20 +103,20 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (FontStringEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.line, that.line) && Objects.equals(this.font, that.font); } @Override public int hashCode() { - return Objects.hash(id, line, font); + return Objects.hash(getId(), line, font); } @Override public String toString() { return "FontLoreEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "line=" + line + ", " + "font=" + font + ']'; } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java index 821bfae..914a7d9 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java @@ -1,12 +1,9 @@ package net.onelitefeather.vulpes.api.model.item; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import net.onelitefeather.vulpes.api.model.ItemEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -15,11 +12,7 @@ import java.util.UUID; @Entity(name = "item_enchantments") -public final class ItemEnchantmentEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class ItemEnchantmentEntity extends IdentifiableEntity { private String name; private short level; private boolean unsafe; @@ -49,30 +42,12 @@ public ItemEnchantmentEntity( short level, boolean unsafe ) { - this.id = id; + this.setId(id); this.name = name; this.level = level; this.unsafe = unsafe; } - /** - * Returns the unique identifier of the item enchantment. - * - * @return the id - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the item enchantment. - * - * @param id the id to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Returns the name of the enchantment. * @@ -150,7 +125,7 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (ItemEnchantmentEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.name, that.name) && this.level == that.level && this.unsafe == that.unsafe && @@ -159,13 +134,13 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return Objects.hash(id, name, level, unsafe, item); + return Objects.hash(getId(), name, level, unsafe, item); } @Override public String toString() { return "ItemEnchantmentEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "name=" + name + ", " + "level=" + level + ", " + "unsafe=" + unsafe + ", " + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java index 27df451..8125034 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java @@ -1,12 +1,9 @@ package net.onelitefeather.vulpes.api.model.item; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import net.onelitefeather.vulpes.api.model.ItemEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -22,11 +19,7 @@ * @since 1.6.0 */ @Entity(name = "item_flags") -public final class ItemFlagEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class ItemFlagEntity extends IdentifiableEntity { private String flag; @ManyToOne @JoinColumn(name = "item_id") @@ -50,28 +43,10 @@ public ItemFlagEntity( UUID id, String flag ) { - this.id = id; + this.setId(id); this.flag = flag; } - /** - * Sets the unique identifier of the item flag. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the item flag. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the flag associated with the item. * @@ -113,20 +88,20 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (ItemFlagEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.flag, that.flag) && Objects.equals(this.item, that.item); } @Override public int hashCode() { - return Objects.hash(id, flag, item); + return Objects.hash(getId(), flag, item); } @Override public String toString() { return "ItemFlagEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "text=" + flag + ", " + "item=" + item + ']'; } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java index e658300..3360d6e 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java @@ -1,12 +1,9 @@ package net.onelitefeather.vulpes.api.model.item; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import net.onelitefeather.vulpes.api.model.ItemEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -22,11 +19,7 @@ * @since 1.6.0 */ @Entity(name = "item_lore") -public final class ItemLoreEntity implements Comparable { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class ItemLoreEntity extends IdentifiableEntity implements Comparable { private String text; @ManyToOne @JoinColumn(name = "item_id", nullable = false) @@ -52,29 +45,11 @@ public ItemLoreEntity( String text, int orderIndex ) { - this.id = id; + this.setId(id); this.text = text; this.orderIndex = orderIndex; } - /** - * Sets the unique identifier of the lore entry. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the lore entry. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the item associated with this lore entry. * @@ -134,20 +109,20 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (ItemLoreEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.text, that.text) && Objects.equals(this.item, that.item); } @Override public int hashCode() { - return Objects.hash(id, text, item); + return Objects.hash(getId(), text, item); } @Override public String toString() { return "ItemLoreEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "text=" + text + ", " + "item=" + item + ']'; } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java index 01b6737..02b84ee 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java @@ -3,14 +3,10 @@ import jakarta.annotation.Nullable; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; -import net.onelitefeather.vulpes.api.model.VulpesModel; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import org.hibernate.annotations.ColumnDefault; import java.util.UUID; @@ -32,12 +28,7 @@ @Table(name = "projects", indexes = { @Index(name = "idx_projects_key", columnList = "project_key", unique = true) }) -public class ProjectEntity implements VulpesModel { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public class ProjectEntity extends IdentifiableEntity { @NotNull private String displayName; @@ -90,7 +81,7 @@ public ProjectEntity( @Nullable String description, boolean labor ) { - this.id = id; + this.setId(id); this.displayName = displayName; this.key = key; this.projectUrl = projectUrl; @@ -99,15 +90,6 @@ public ProjectEntity( this.labor = labor; } - /** - * Sets the unique identifier of the project. - * - * @param id of the project - */ - public void setId(UUID id) { - this.id = id; - } - /** * Sets the display name of the project. * @@ -162,15 +144,6 @@ public void setLabor(boolean labor) { this.labor = labor; } - /** - * Returns the unique identifier of the project. - * - * @return the unique identifier of the project - */ - public UUID getId() { - return id; - } - /** * Returns the display name of the project. * diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java index db62020..437f37d 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java @@ -2,20 +2,13 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; -import net.onelitefeather.vulpes.api.model.VulpesModel; +import jakarta.persistence.UniqueConstraint; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; import org.hibernate.annotations.ColumnDefault; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.List; import java.util.Objects; @@ -34,15 +27,12 @@ @Entity(name = "sounds") @Table(name = "sounds", indexes = { @Index(name = "idx_sounds_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_sounds_project_key", columnNames = {"project_id", "key"}) }) -public class SoundEventEntity implements VulpesModel { +public class SoundEventEntity extends AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String uiName; - private String variableName; private String keyName; @Column(name = "replace_flag") @ColumnDefault("false") @@ -57,11 +47,6 @@ public class SoundEventEntity implements VulpesModel { @OneToMany(mappedBy = "soundEvent") private List dataEntities; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; - /** * Default constructor for JPA and Micronaut Data. *

@@ -77,40 +62,23 @@ public SoundEventEntity() { * * @param id the unique identifier of the sound model * @param uiName the user interface name for the sound model - * @param variableName the variable name for the sound model + * @param key the local key of the sound model within the project's namespace + * (e.g. {@code ambient.cave}, becomes {@code :ambient.cave} + * via {@link #getNamespacedKey()}) * @param keyName the key name for the sound model * @param replace whether to replace an existing sound model * @param subTitle the subtitle for the sound model * @param dataEntities the list of sound data entities related to this sound model * @param project the project this sound event belongs to */ - public SoundEventEntity(UUID id, String uiName, String variableName, String keyName, boolean replace, String subTitle, List dataEntities, ProjectEntity project) { - this.id = id; + public SoundEventEntity(UUID id, String uiName, String key, String keyName, boolean replace, String subTitle, List dataEntities, ProjectEntity project) { + super(key, project); + this.setId(id); this.uiName = uiName; this.keyName = keyName; - this.variableName = variableName; this.replace = replace; this.subTitle = subTitle; this.dataEntities = dataEntities; - this.project = project; - } - - /** - * Returns the unique identifier of the sound model - * - * @return the unique identifier of the sound model - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the sound model - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; } /** @@ -149,23 +117,6 @@ public String getKeyName() { return keyName; } - /** - * Set the name for the variable associated with this sound model. - * - * @param variableName the name of the variable to set - */ - public void setVariableName(String variableName) { - this.variableName = variableName; - } - - /** - * Returns the name of the variable associated with this sound model. - * - * @return the name of the variable - */ - public String getVariableName() { - return variableName; - } /** * Sets the subtitle for the sound model. @@ -204,47 +155,29 @@ public void setSoundData(List soundDatumEntities) { this.dataEntities = soundDatumEntities; } - /** - * Returns the project this sound event belongs to. - * - * @return the project of the sound event - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this sound event belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - @Override public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; SoundEventEntity that = (SoundEventEntity) o; - return replace == that.replace && Objects.equals(id, that.id) && Objects.equals(uiName, that.uiName) && Objects.equals(variableName, that.variableName) && Objects.equals(keyName, that.keyName) && Objects.equals(subTitle, that.subTitle) && Objects.equals(dataEntities, that.dataEntities) && Objects.equals(project, that.project); + return replace == that.replace && Objects.equals(getId(), that.getId()) && Objects.equals(uiName, that.uiName) && Objects.equals(getKey(), that.getKey()) && Objects.equals(keyName, that.keyName) && Objects.equals(subTitle, that.subTitle) && Objects.equals(dataEntities, that.dataEntities) && Objects.equals(getProject(), that.getProject()); } @Override public int hashCode() { - return Objects.hash(id, uiName, variableName, keyName, replace, subTitle, dataEntities, project); + return Objects.hash(getId(), uiName, getKey(), keyName, replace, subTitle, dataEntities, getProject()); } @Override public String toString() { return "SoundEventEntity{" + - "id=" + id + + "id=" + getId() + ", uiName='" + uiName + '\'' + - ", variableName='" + variableName + '\'' + + ", key='" + getKey() + '\'' + ", keyName='" + keyName + '\'' + ", replace=" + replace + ", subTitle='" + subTitle + '\'' + ", dataEntities=" + dataEntities + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java index 2f4e3cd..09a1459 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java @@ -1,13 +1,9 @@ package net.onelitefeather.vulpes.api.model.sound; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; -import net.onelitefeather.vulpes.api.model.VulpesModel; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -24,12 +20,8 @@ * @since 0.1.0 */ @Entity(name = "sound_data") -public class SoundFileSource implements VulpesModel { +public class SoundFileSource extends IdentifiableEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String name; @ColumnDefault("1.0") private float volume; @@ -84,7 +76,7 @@ public SoundFileSource( boolean preload, String type ) { - this.id = id; + this.setId(id); this.name = name; this.volume = volume; this.pitch = pitch; @@ -97,24 +89,6 @@ public SoundFileSource( // Getters and setters for each field - /** - * Returns the unique identifier of the data. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the sound data. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Sets the name of the sound data * @@ -253,18 +227,18 @@ public void setSoundEvent(SoundEventEntity soundEvent) { public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; SoundFileSource that = (SoundFileSource) o; - return Float.compare(volume, that.volume) == 0 && Float.compare(pitch, that.pitch) == 0 && weight == that.weight && stream == that.stream && attenuationDistance == that.attenuationDistance && preload == that.preload && Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(type, that.type); + return Float.compare(volume, that.volume) == 0 && Float.compare(pitch, that.pitch) == 0 && weight == that.weight && stream == that.stream && attenuationDistance == that.attenuationDistance && preload == that.preload && Objects.equals(getId(), that.getId()) && Objects.equals(name, that.name) && Objects.equals(type, that.type); } @Override public int hashCode() { - return Objects.hash(id, name, volume, pitch, weight, stream, attenuationDistance, preload, type); + return Objects.hash(getId(), name, volume, pitch, weight, stream, attenuationDistance, preload, type); } @Override public String toString() { return "SoundDataEntity{" + - "id=" + id + + "id=" + getId() + ", name='" + name + '\'' + ", volume=" + volume + ", pitch=" + pitch +