149 lines
3.8 KiB
Java
149 lines
3.8 KiB
Java
package eu.eudat.migration.entities;
|
|
|
|
import eu.eudat.models.data.admin.components.datasetprofile.FieldSet;
|
|
import eu.eudat.models.data.components.commons.Multiplicity;
|
|
import org.hibernate.annotations.LazyCollection;
|
|
import org.hibernate.annotations.LazyCollectionOption;
|
|
|
|
import javax.persistence.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Entity
|
|
@Table(name = "sections")
|
|
public class RoadmapSection {
|
|
|
|
@Id
|
|
private Long id;
|
|
private String title;
|
|
private String description;
|
|
private Long number;
|
|
@Column(name = "created_at")
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
private Date createdAt;
|
|
@Column(name = "updated_at")
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
private Date updatedAt;
|
|
private Boolean modifiable;
|
|
@Column(name = "versionable_id")
|
|
private String versionableId;
|
|
@OneToMany(cascade = CascadeType.ALL)
|
|
@JoinColumn(name = "section_id")
|
|
@OrderBy("number")
|
|
@LazyCollection(LazyCollectionOption.FALSE)
|
|
private List<Question> questions = new ArrayList<>();
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "Section{" +
|
|
"id=" + id +
|
|
", title='" + title + '\'' +
|
|
", description='" + description + '\'' +
|
|
", number=" + number +
|
|
", createdAt=" + createdAt +
|
|
", updatedAt=" + updatedAt +
|
|
", modifiable=" + modifiable +
|
|
", versionableId='" + versionableId + '\'' +
|
|
", questions=" + questions +
|
|
'}';
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Long id) {
|
|
this.id = id;
|
|
}
|
|
|
|
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
public void setTitle(String title) {
|
|
this.title = title;
|
|
}
|
|
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
public void setDescription(String description) {
|
|
this.description = description;
|
|
}
|
|
|
|
|
|
public Long getNumber() {
|
|
return number;
|
|
}
|
|
|
|
public void setNumber(Long number) {
|
|
this.number = number;
|
|
}
|
|
|
|
|
|
public Date getCreatedAt() {
|
|
return createdAt;
|
|
}
|
|
|
|
public void setCreatedAt(Date createdAt) {
|
|
this.createdAt = createdAt;
|
|
}
|
|
|
|
|
|
public Date getUpdatedAt() {
|
|
return updatedAt;
|
|
}
|
|
|
|
public void setUpdatedAt(Date updatedAt) {
|
|
this.updatedAt = updatedAt;
|
|
}
|
|
|
|
public Boolean getModifiable() {
|
|
return modifiable;
|
|
}
|
|
|
|
public void setModifiable(Boolean modifiable) {
|
|
this.modifiable = modifiable;
|
|
}
|
|
|
|
public String getVersionableId() {
|
|
return versionableId;
|
|
}
|
|
|
|
public void setVersionableId(String versionableId) {
|
|
this.versionableId = versionableId;
|
|
}
|
|
|
|
|
|
public List<Question> getQuestions() {
|
|
return questions;
|
|
}
|
|
|
|
public void setQuestions(List<Question> questions) {
|
|
this.questions = questions;
|
|
}
|
|
|
|
public List<FieldSet> buildFieldSets(List<Question> questions) {
|
|
return questions.stream().map(question -> {
|
|
FieldSet fieldSet = new FieldSet();
|
|
fieldSet.setId(String.valueOf(UUID.randomUUID()));
|
|
fieldSet.setTitle(question.getText());
|
|
fieldSet.setDescription(question.buildDescription());
|
|
fieldSet.setOrdinal(Math.toIntExact(question.getNumber()) - 1);
|
|
fieldSet.setMultiplicity(this.buildMultiplicity());
|
|
fieldSet.setHasCommentField(question.getOptionCommentDisplay());
|
|
fieldSet.setFields(question.buildFields());
|
|
return fieldSet;
|
|
}).collect(Collectors.toList());
|
|
}
|
|
|
|
private Multiplicity buildMultiplicity() {
|
|
Multiplicity multiplicity = new Multiplicity();
|
|
multiplicity.setPlaceholder("");
|
|
return multiplicity;
|
|
}
|
|
}
|