-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSurvey.java
More file actions
206 lines (166 loc) · 5.17 KB
/
Survey.java
File metadata and controls
206 lines (166 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package com.pwr.students.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
/**
* A Survey.
*/
@Entity
@Table(name = "survey")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Survey implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@NotNull
@Size(min = 3, max = 120)
@Column(name = "name", length = 120, nullable = false)
private String name;
@NotNull
@Size(min = 16, max = 255)
@Column(name = "description", length = 255, nullable = false)
private String description;
@Column(name = "deadline")
private LocalDate deadline;
@Column(name = "status")
@Enumerated(EnumType.STRING)
private SurveyStatus status;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "survey")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties(value = { "survey" }, allowSetters = true)
private Set<Question> questions = new HashSet<>();
@ManyToOne(fetch = FetchType.EAGER)
private User user;
@JsonIgnore
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "survey")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private Set<SurveyAssigment> SurveyAssigments = new HashSet<>();
@JsonIgnore
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "survey")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private Set<SurveyTargetGroups> SurveyTargetGroups = new HashSet<>();
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Survey id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public Survey name(String name) {
this.setName(name);
return this;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return this.description;
}
public Survey description(String description) {
this.setDescription(description);
return this;
}
public void setDescription(String description) {
this.description = description;
}
public LocalDate getDeadline() {
return this.deadline;
}
public Survey deadline(LocalDate deadline) {
this.setDeadline(deadline);
return this;
}
public void setDeadline(LocalDate deadline) {
this.deadline = deadline;
}
public SurveyStatus getStatus() {
return this.status;
}
public Survey status(SurveyStatus status) {
this.setStatus(status);
return this;
}
public void setStatus(SurveyStatus status) {
this.status = status;
}
public Set<Question> getQuestions() {
return this.questions;
}
public void setQuestions(Set<Question> questions) {
if (this.questions != null) {
this.questions.forEach(i -> i.setSurvey(null));
}
if (questions != null) {
questions.forEach(i -> i.setSurvey(this));
}
this.questions = questions;
}
public Survey questions(Set<Question> questions) {
this.setQuestions(questions);
return this;
}
public Survey addQuestion(Question question) {
this.questions.add(question);
question.setSurvey(this);
return this;
}
public Survey removeQuestion(Question question) {
this.questions.remove(question);
question.setSurvey(null);
return this;
}
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
public Survey user(User user) {
this.setUser(user);
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 Survey)) {
return false;
}
return id != null && id.equals(((Survey) o).id);
}
@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 "Survey{" +
"id=" + getId() +
", name='" + getName() + "'" +
", description='" + getDescription() + "'" +
", deadline='" + getDeadline() + "'" +
", status='" + getStatus() + "'" +
"}";
}
}