From 5ceaa8ca39d0ac2a7416d28becf6c43ab84931a9 Mon Sep 17 00:00:00 2001 From: Brutus5000 Date: Thu, 26 Nov 2020 22:32:10 +0100 Subject: [PATCH] Add MapReviewsSummary and ModReviewsSummary Also remove deprecated attributes numberOfReviews and averageReviewScore --- .../com/faforever/api/data/domain/Map.java | 29 ++++---- .../api/data/domain/MapReviewsSummary.java | 70 +++++++++++++++++++ .../data/domain/MapVersionReviewsSummary.java | 9 ++- .../com/faforever/api/data/domain/Mod.java | 22 +++--- .../api/data/domain/ModReviewsSummary.java | 70 +++++++++++++++++++ .../data/domain/ModVersionReviewsSummary.java | 7 +- 6 files changed, 174 insertions(+), 33 deletions(-) create mode 100644 src/main/java/com/faforever/api/data/domain/MapReviewsSummary.java create mode 100644 src/main/java/com/faforever/api/data/domain/ModReviewsSummary.java diff --git a/src/main/java/com/faforever/api/data/domain/Map.java b/src/main/java/com/faforever/api/data/domain/Map.java index eb3b821d1..01d8183ab 100644 --- a/src/main/java/com/faforever/api/data/domain/Map.java +++ b/src/main/java/com/faforever/api/data/domain/Map.java @@ -1,14 +1,15 @@ package com.faforever.api.data.domain; +import com.faforever.api.data.checks.Prefab; import com.faforever.api.data.listeners.MapChangeListener; import com.yahoo.elide.annotation.Include; +import com.yahoo.elide.annotation.UpdatePermission; import lombok.Setter; import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Immutable; import org.hibernate.annotations.JoinColumnOrFormula; import org.hibernate.annotations.JoinColumnsOrFormulas; import org.hibernate.annotations.JoinFormula; -import org.hibernate.validator.constraints.NotEmpty; import org.jetbrains.annotations.Nullable; import javax.persistence.CascadeType; @@ -23,6 +24,7 @@ import javax.persistence.Table; import javax.persistence.Transient; import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.ArrayList; @@ -45,8 +47,7 @@ public class Map extends AbstractEntity implements OwnableEntity { private Player author; private MapStatistics statistics; private MapVersion latestVersion; - private int numberOfReviews; - private float averageReviewScore; + private MapReviewsSummary reviewsSummary; @Column(name = "display_name", unique = true) @Size(max = 100) @@ -67,16 +68,6 @@ public String getBattleType() { return battleType; } - @Column(name = "reviews") - public int getNumberOfReviews() { - return numberOfReviews; - } - - @Column(name = "average_review_score") - public float getAverageReviewScore() { - return averageReviewScore; - } - @OneToMany(mappedBy = "map", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) @NotEmpty @Valid @@ -101,9 +92,9 @@ public MapStatistics getStatistics() { @ManyToOne(fetch = FetchType.LAZY) @JoinColumnsOrFormulas({ @JoinColumnOrFormula( - formula = @JoinFormula( - value = "(SELECT map_version.id FROM map_version WHERE map_version.map_id = id ORDER BY map_version.version DESC LIMIT 1)", - referencedColumnName = "id") + formula = @JoinFormula( + value = "(SELECT map_version.id FROM map_version WHERE map_version.map_id = id ORDER BY map_version.version DESC LIMIT 1)", + referencedColumnName = "id") ) }) @BatchSize(size = 1000) @@ -111,6 +102,12 @@ public MapVersion getLatestVersion() { return latestVersion; } + @OneToOne(mappedBy = "map") + @UpdatePermission(expression = Prefab.ALL) + public MapReviewsSummary getReviewsSummary() { + return reviewsSummary; + } + @Transient @Override public Login getEntityOwner() { diff --git a/src/main/java/com/faforever/api/data/domain/MapReviewsSummary.java b/src/main/java/com/faforever/api/data/domain/MapReviewsSummary.java new file mode 100644 index 000000000..33d9a74cc --- /dev/null +++ b/src/main/java/com/faforever/api/data/domain/MapReviewsSummary.java @@ -0,0 +1,70 @@ +package com.faforever.api.data.domain; + +import com.yahoo.elide.annotation.Include; +import lombok.Setter; +import org.hibernate.annotations.BatchSize; +import org.hibernate.annotations.Immutable; + +import javax.annotation.Nullable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Setter +@Table(name = "map_reviews_summary") +@Include(type = "mapReviewsSummary") +@Immutable +public class MapReviewsSummary { + private int id; + private float positive; + private float negative; + private float score; + private int reviews; + @Nullable + private Float lowerBound; + private Map map; + + @Id + @Column(name = "id") + public int getId() { + return id; + } + + @Column(name = "positive") + public float getPositive() { + return positive; + } + + @Column(name = "negative") + public float getNegative() { + return negative; + } + + @Column(name = "score") + public float getScore() { + return score; + } + + @Column(name = "reviews") + public int getReviews() { + return reviews; + } + + @Column(name = "lower_bound") + @Nullable + public Float getLowerBound() { + return lowerBound; + } + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "map_id", insertable = false, updatable = false) + @BatchSize(size = 1000) + public Map getMap() { + return map; + } +} diff --git a/src/main/java/com/faforever/api/data/domain/MapVersionReviewsSummary.java b/src/main/java/com/faforever/api/data/domain/MapVersionReviewsSummary.java index 71e10e924..4e5674b9d 100644 --- a/src/main/java/com/faforever/api/data/domain/MapVersionReviewsSummary.java +++ b/src/main/java/com/faforever/api/data/domain/MapVersionReviewsSummary.java @@ -5,6 +5,7 @@ import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Immutable; +import javax.annotation.Nullable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -24,11 +25,12 @@ public class MapVersionReviewsSummary { private float negative; private float score; private int reviews; - private float lowerBound; + @Nullable + private Float lowerBound; private MapVersion mapVersion; @Id - @Column(name = "map_version_id") + @Column(name = "id") public int getId() { return id; } @@ -54,7 +56,8 @@ public int getReviews() { } @Column(name = "lower_bound") - public float getLowerBound() { + @Nullable + public Float getLowerBound() { return lowerBound; } diff --git a/src/main/java/com/faforever/api/data/domain/Mod.java b/src/main/java/com/faforever/api/data/domain/Mod.java index c287c194d..235de3b38 100644 --- a/src/main/java/com/faforever/api/data/domain/Mod.java +++ b/src/main/java/com/faforever/api/data/domain/Mod.java @@ -1,6 +1,8 @@ package com.faforever.api.data.domain; +import com.faforever.api.data.checks.Prefab; import com.yahoo.elide.annotation.Include; +import com.yahoo.elide.annotation.UpdatePermission; import lombok.Setter; import org.hibernate.annotations.Immutable; import org.hibernate.annotations.JoinColumnOrFormula; @@ -14,6 +16,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Transient; import javax.validation.Valid; @@ -35,8 +38,7 @@ public class Mod extends AbstractEntity implements OwnableEntity { private List versions; private ModVersion latestVersion; private Player uploader; - private int numberOfReviews; - private float averageReviewScore; + private ModReviewsSummary reviewsSummary; @Column(name = "display_name") @Size(max = 100) @@ -52,16 +54,6 @@ public String getAuthor() { return author; } - @Column(name = "reviews") - public int getNumberOfReviews() { - return numberOfReviews; - } - - @Column(name = "average_review_score") - public float getAverageReviewScore() { - return averageReviewScore; - } - @ManyToOne @JoinColumn(name = "uploader") public Player getUploader() { @@ -87,6 +79,12 @@ public ModVersion getLatestVersion() { return latestVersion; } + @OneToOne(mappedBy = "mod") + @UpdatePermission(expression = Prefab.ALL) + public ModReviewsSummary getReviewsSummary() { + return reviewsSummary; + } + @Transient @Override public Login getEntityOwner() { diff --git a/src/main/java/com/faforever/api/data/domain/ModReviewsSummary.java b/src/main/java/com/faforever/api/data/domain/ModReviewsSummary.java new file mode 100644 index 000000000..a2deae855 --- /dev/null +++ b/src/main/java/com/faforever/api/data/domain/ModReviewsSummary.java @@ -0,0 +1,70 @@ +package com.faforever.api.data.domain; + +import com.yahoo.elide.annotation.Include; +import lombok.Setter; +import org.hibernate.annotations.BatchSize; +import org.hibernate.annotations.Immutable; + +import javax.annotation.Nullable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Setter +@Table(name = "mod_reviews_summary") +@Include(type = "modReviewsSummary") +@Immutable +public class ModReviewsSummary { + private int id; + private float positive; + private float negative; + private float score; + private int reviews; + @Nullable + private Float lowerBound; + private Mod mod; + + @Id + @Column(name = "id") + public int getId() { + return id; + } + + @Column(name = "positive") + public float getPositive() { + return positive; + } + + @Column(name = "negative") + public float getNegative() { + return negative; + } + + @Column(name = "score") + public float getScore() { + return score; + } + + @Column(name = "reviews") + public int getReviews() { + return reviews; + } + + @Column(name = "lower_bound") + @Nullable + public Float getLowerBound() { + return lowerBound; + } + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mod_id", insertable = false, updatable = false) + @BatchSize(size = 1000) + public Mod getMod() { + return mod; + } +} diff --git a/src/main/java/com/faforever/api/data/domain/ModVersionReviewsSummary.java b/src/main/java/com/faforever/api/data/domain/ModVersionReviewsSummary.java index 9e0f08453..596b301e8 100644 --- a/src/main/java/com/faforever/api/data/domain/ModVersionReviewsSummary.java +++ b/src/main/java/com/faforever/api/data/domain/ModVersionReviewsSummary.java @@ -5,6 +5,7 @@ import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.Immutable; +import javax.annotation.Nullable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -24,11 +25,12 @@ public class ModVersionReviewsSummary { private float negative; private float score; private int reviews; - private float lowerBound; + @Nullable + private Float lowerBound; private ModVersion modVersion; @Id - @Column(name = "mod_version_id") + @Column(name = "id") public int getId() { return id; } @@ -54,6 +56,7 @@ public int getReviews() { } @Column(name = "lower_bound") + @Nullable public float getLowerBound() { return lowerBound; }