-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #200
- Loading branch information
Showing
19 changed files
with
877 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.IsEntityOwner; | ||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import com.yahoo.elide.annotation.UpdatePermission; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
import javax.persistence.Transient; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "vote") | ||
@Include(type = Vote.TYPE_NAME, rootLevel = true) | ||
@ReadPermission(expression = IsEntityOwner.EXPRESSION) | ||
@UpdatePermission(expression = "Prefab.Role.None") | ||
@Setter | ||
public class Vote extends AbstractEntity implements OwnableEntity { | ||
public static final String TYPE_NAME = "vote"; | ||
|
||
private Player player; | ||
private VotingSubject votingSubject; | ||
private List<VotingAnswer> votingAnswers; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "player_id") | ||
public Player getPlayer() { | ||
return player; | ||
} | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "voting_subject_id") | ||
public VotingSubject getVotingSubject() { | ||
return votingSubject; | ||
} | ||
|
||
@OneToMany(mappedBy = "vote", cascade = CascadeType.ALL, orphanRemoval = true) | ||
public List<VotingAnswer> getVotingAnswers() { | ||
return votingAnswers; | ||
} | ||
|
||
@Transient | ||
@Override | ||
public Login getEntityOwner() { | ||
return getPlayer(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/faforever/api/data/domain/VotingAnswer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.IsEntityOwner; | ||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import com.yahoo.elide.annotation.UpdatePermission; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "voting_answer") | ||
@Include(type = VotingAnswer.TYPE_NAME) | ||
@ReadPermission(expression = IsEntityOwner.EXPRESSION) | ||
@UpdatePermission(expression = "Prefab.Role.None") | ||
@Setter | ||
public class VotingAnswer extends AbstractEntity { | ||
public static final String TYPE_NAME = "votingAnswer"; | ||
|
||
private Vote vote; | ||
private int alternativeOrdinal; | ||
private VotingChoice votingChoice; | ||
|
||
@Column(name = "alternative_ordinal") | ||
public int getAlternativeOrdinal() { | ||
return alternativeOrdinal; | ||
} | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "vote_id") | ||
public Vote getVote() { | ||
return vote; | ||
} | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "voting_choice_id") | ||
public VotingChoice getVotingChoice() { | ||
return votingChoice; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/com/faforever/api/data/domain/VotingChoice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.faforever.api.data.domain; | ||
|
||
import com.faforever.api.data.checks.permission.IsModerator; | ||
import com.faforever.api.data.listeners.VotingChoiceEnricher; | ||
import com.fasterxml.jackson.annotation.JsonBackReference; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.yahoo.elide.annotation.ComputedAttribute; | ||
import com.yahoo.elide.annotation.CreatePermission; | ||
import com.yahoo.elide.annotation.DeletePermission; | ||
import com.yahoo.elide.annotation.Exclude; | ||
import com.yahoo.elide.annotation.Include; | ||
import com.yahoo.elide.annotation.ReadPermission; | ||
import com.yahoo.elide.annotation.SharePermission; | ||
import com.yahoo.elide.annotation.UpdatePermission; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EntityListeners; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
import javax.persistence.Transient; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "voting_choice") | ||
@ReadPermission(expression = "Prefab.Role.All") | ||
@SharePermission(expression = IsModerator.EXPRESSION) | ||
@DeletePermission(expression = IsModerator.EXPRESSION) | ||
@UpdatePermission(expression = IsModerator.EXPRESSION) | ||
@CreatePermission(expression = IsModerator.EXPRESSION) | ||
@Include(rootLevel = true, type = VotingChoice.TYPE_NAME) | ||
@Setter | ||
@EntityListeners(VotingChoiceEnricher.class) | ||
public class VotingChoice extends AbstractEntity { | ||
public static final String TYPE_NAME = "votingChoice"; | ||
|
||
private String choiceTextKey; | ||
private String choiceText; | ||
private String descriptionKey; | ||
private String description; | ||
private int numberOfAnswers; | ||
private int ordinal; | ||
private VotingQuestion votingQuestion; | ||
private List<VotingAnswer> votingAnswers; | ||
|
||
@Column(name = "choice_text_key") | ||
@NotNull | ||
public String getChoiceTextKey() { | ||
return choiceTextKey; | ||
} | ||
|
||
@ComputedAttribute | ||
@Transient | ||
public String getChoiceText() { | ||
return choiceText; | ||
} | ||
|
||
@Column(name = "description_key") | ||
public String getDescriptionKey() { | ||
return descriptionKey; | ||
} | ||
|
||
@ComputedAttribute | ||
@Transient | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Column(name = "ordinal") | ||
@NotNull | ||
public int getOrdinal() { | ||
return ordinal; | ||
} | ||
|
||
@Transient | ||
@ComputedAttribute | ||
public int getNumberOfAnswers() { | ||
return numberOfAnswers; | ||
} | ||
|
||
@JsonBackReference | ||
@JoinColumn(name = "voting_question_id") | ||
@ManyToOne() | ||
public VotingQuestion getVotingQuestion() { | ||
return votingQuestion; | ||
} | ||
|
||
@JsonIgnore | ||
@Exclude | ||
@OneToMany(mappedBy = "votingChoice", cascade = CascadeType.ALL, orphanRemoval = true) | ||
public List<VotingAnswer> getVotingAnswers() { | ||
return votingAnswers; | ||
} | ||
} |
Oops, something went wrong.