Skip to content

Commit

Permalink
Add MapReviewsSummary and ModReviewsSummary
Browse files Browse the repository at this point in the history
Also remove deprecated attributes numberOfReviews and averageReviewScore
  • Loading branch information
Brutus5000 committed Nov 26, 2020
1 parent 310ab43 commit 5ceaa8c
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 33 deletions.
29 changes: 13 additions & 16 deletions src/main/java/com/faforever/api/data/domain/Map.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -101,16 +92,22 @@ 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)
public MapVersion getLatestVersion() {
return latestVersion;
}

@OneToOne(mappedBy = "map")
@UpdatePermission(expression = Prefab.ALL)
public MapReviewsSummary getReviewsSummary() {
return reviewsSummary;
}

@Transient
@Override
public Login getEntityOwner() {
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/com/faforever/api/data/domain/MapReviewsSummary.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -54,7 +56,8 @@ public int getReviews() {
}

@Column(name = "lower_bound")
public float getLowerBound() {
@Nullable
public Float getLowerBound() {
return lowerBound;
}

Expand Down
22 changes: 10 additions & 12 deletions src/main/java/com/faforever/api/data/domain/Mod.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -35,8 +38,7 @@ public class Mod extends AbstractEntity implements OwnableEntity {
private List<ModVersion> versions;
private ModVersion latestVersion;
private Player uploader;
private int numberOfReviews;
private float averageReviewScore;
private ModReviewsSummary reviewsSummary;

@Column(name = "display_name")
@Size(max = 100)
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/com/faforever/api/data/domain/ModReviewsSummary.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -54,6 +56,7 @@ public int getReviews() {
}

@Column(name = "lower_bound")
@Nullable
public float getLowerBound() {
return lowerBound;
}
Expand Down

0 comments on commit 5ceaa8c

Please sign in to comment.