Files
jhipster-question-bank/src/main/java/com/example/questionbank/domain/Question.java
T

177 lines
4.2 KiB
Java

package com.example.questionbank.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serial;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
/**
* A Question.
*/
@Entity
@Table(name = "question")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Question implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Size(min = 5, max = 2000)
@Column(name = "prompt", length = 2000, nullable = false)
private String prompt;
@Size(max = 2000)
@Column(name = "explanation", length = 2000)
private String explanation;
@NotNull
@Column(name = "active", nullable = false)
private Boolean active;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "question")
@JsonIgnoreProperties(value = { "question" }, allowSetters = true)
private Set<Choice> choices = new HashSet<>();
@ManyToOne(optional = false)
@NotNull
private Subject subject;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Question id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public String getPrompt() {
return this.prompt;
}
public Question prompt(String prompt) {
this.setPrompt(prompt);
return this;
}
public void setPrompt(String prompt) {
this.prompt = prompt;
}
public String getExplanation() {
return this.explanation;
}
public Question explanation(String explanation) {
this.setExplanation(explanation);
return this;
}
public void setExplanation(String explanation) {
this.explanation = explanation;
}
public Boolean getActive() {
return this.active;
}
public Question active(Boolean active) {
this.setActive(active);
return this;
}
public void setActive(Boolean active) {
this.active = active;
}
public Set<Choice> getChoices() {
return this.choices;
}
public void setChoices(Set<Choice> choices) {
if (this.choices != null) {
this.choices.forEach(i -> i.setQuestion(null));
}
if (choices != null) {
choices.forEach(i -> i.setQuestion(this));
}
this.choices = choices;
}
public Question choices(Set<Choice> choices) {
this.setChoices(choices);
return this;
}
public Question addChoice(Choice choice) {
this.choices.add(choice);
choice.setQuestion(this);
return this;
}
public Question removeChoice(Choice choice) {
this.choices.remove(choice);
choice.setQuestion(null);
return this;
}
public Subject getSubject() {
return this.subject;
}
public void setSubject(Subject subject) {
this.subject = subject;
}
public Question subject(Subject subject) {
this.setSubject(subject);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Question)) {
return false;
}
return getId() != null && getId().equals(((Question) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Question{" +
"id=" + getId() +
", prompt='" + getPrompt() + "'" +
", explanation='" + getExplanation() + "'" +
", active='" + getActive() + "'" +
"}";
}
}