2022-04-27 16:21:04 +02:00
|
|
|
package eu.eudat.migration.entities;
|
|
|
|
|
2022-05-11 10:29:26 +02:00
|
|
|
import eu.eudat.migration.utils.JsonTypeConverter;
|
2022-05-18 13:45:24 +02:00
|
|
|
import eu.eudat.models.data.admin.components.datasetprofile.Page;
|
|
|
|
import eu.eudat.models.data.admin.components.datasetprofile.Section;
|
|
|
|
import eu.eudat.models.data.admin.composite.DatasetProfile;
|
2022-05-03 14:56:04 +02:00
|
|
|
import org.hibernate.annotations.LazyCollection;
|
|
|
|
import org.hibernate.annotations.LazyCollectionOption;
|
|
|
|
|
|
|
|
import javax.persistence.*;
|
2022-05-11 10:29:26 +02:00
|
|
|
import java.util.*;
|
2022-04-27 16:21:04 +02:00
|
|
|
|
|
|
|
@Entity
|
|
|
|
@Table(name = "templates")
|
2022-05-11 10:29:26 +02:00
|
|
|
@SuppressWarnings("JpaAttributeTypeInspection")
|
2022-04-27 16:21:04 +02:00
|
|
|
public class Template {
|
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
@Id
|
|
|
|
private Long id;
|
|
|
|
private String title;
|
|
|
|
private String description;
|
|
|
|
private Boolean published;
|
|
|
|
@ManyToOne(fetch = FetchType.EAGER)
|
|
|
|
@JoinColumn(name = "org_id")
|
|
|
|
private Organization organization;
|
|
|
|
private String locale;
|
|
|
|
@Column(name = "is_default")
|
|
|
|
private Boolean isDefault;
|
|
|
|
@Column(name = "created_at")
|
|
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
|
|
private Date createdAt;
|
|
|
|
@Column(name = "updated_at")
|
|
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
|
|
private Date updatedAt;
|
2022-05-11 10:29:26 +02:00
|
|
|
private Short version;
|
2022-05-03 14:56:04 +02:00
|
|
|
private Visibility visibility;
|
|
|
|
@Column(name = "customization_of")
|
|
|
|
private Long customizationOf;
|
|
|
|
@Column(name = "family_id")
|
|
|
|
private Long familyId;
|
|
|
|
private Boolean archived;
|
2022-05-11 10:29:26 +02:00
|
|
|
@Convert(converter = JsonTypeConverter.class)
|
|
|
|
private Map<String, Object> links;
|
2022-05-03 14:56:04 +02:00
|
|
|
@OneToMany(cascade = CascadeType.ALL)
|
|
|
|
@JoinColumn(name = "template_id")
|
|
|
|
@OrderBy("number")
|
|
|
|
@LazyCollection(LazyCollectionOption.FALSE)
|
|
|
|
private List<Phase> phases = new ArrayList<>();
|
2022-05-11 10:29:26 +02:00
|
|
|
@OneToMany(cascade = CascadeType.ALL)
|
|
|
|
@JoinColumn(name = "template_id")
|
|
|
|
@LazyCollection(LazyCollectionOption.FALSE)
|
|
|
|
private Set<Plan> plans = new HashSet<>();
|
2022-05-03 14:56:04 +02:00
|
|
|
|
|
|
|
public enum Visibility {
|
|
|
|
ORGANIZATION,
|
|
|
|
PUBLIC
|
|
|
|
}
|
|
|
|
|
|
|
|
public Long getId() {
|
|
|
|
return id;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setId(Long id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public String getTitle() {
|
|
|
|
return title;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setTitle(String title) {
|
|
|
|
this.title = title;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setDescription(String description) {
|
|
|
|
this.description = description;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public Boolean getPublished() {
|
|
|
|
return published;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setPublished(Boolean published) {
|
|
|
|
this.published = published;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public Organization getOrganization() {
|
|
|
|
return organization;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setOrganization(Organization organization) {
|
|
|
|
this.organization = organization;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLocale() {
|
|
|
|
return locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLocale(String locale) {
|
|
|
|
this.locale = locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-05-11 10:29:26 +02:00
|
|
|
public Short getVersion() {
|
2022-05-03 14:56:04 +02:00
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2022-05-11 10:29:26 +02:00
|
|
|
public void setVersion(Short version) {
|
2022-05-03 14:56:04 +02:00
|
|
|
this.version = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Visibility getVisibility() {
|
|
|
|
return visibility;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVisibility(Visibility visibility) {
|
|
|
|
this.visibility = visibility;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public Long getCustomizationOf() {
|
|
|
|
return customizationOf;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setCustomizationOf(Long customizationOf) {
|
|
|
|
this.customizationOf = customizationOf;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public Long getFamilyId() {
|
|
|
|
return familyId;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setFamilyId(Long familyId) {
|
|
|
|
this.familyId = familyId;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public Boolean getArchived() {
|
|
|
|
return archived;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setArchived(Boolean archived) {
|
|
|
|
this.archived = archived;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
|
|
|
|
2022-05-11 10:29:26 +02:00
|
|
|
public Map<String, Object> getLinks() {
|
2022-05-03 14:56:04 +02:00
|
|
|
return links;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-11 10:29:26 +02:00
|
|
|
public void setLinks(Map<String, Object> links) {
|
2022-05-03 14:56:04 +02:00
|
|
|
this.links = links;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public Boolean getDefault() {
|
|
|
|
return isDefault;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setDefault(Boolean aDefault) {
|
|
|
|
isDefault = aDefault;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public List<Phase> getPhases() {
|
|
|
|
return phases;
|
|
|
|
}
|
2022-04-27 16:21:04 +02:00
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
public void setPhases(List<Phase> phases) {
|
|
|
|
this.phases = phases;
|
|
|
|
}
|
|
|
|
|
2022-05-11 10:29:26 +02:00
|
|
|
public Set<Plan> getPlans() {
|
|
|
|
return plans;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPlans(Set<Plan> plans) {
|
|
|
|
this.plans = plans;
|
|
|
|
}
|
|
|
|
|
2022-05-03 14:56:04 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "Template{" +
|
|
|
|
"id=" + id +
|
|
|
|
", title='" + title + '\'' +
|
|
|
|
", description='" + description + '\'' +
|
2022-05-11 10:29:26 +02:00
|
|
|
", published=" + published +
|
2022-05-03 14:56:04 +02:00
|
|
|
", organization=" + organization +
|
|
|
|
", locale='" + locale + '\'' +
|
2022-05-11 10:29:26 +02:00
|
|
|
", isDefault=" + isDefault +
|
2022-05-03 14:56:04 +02:00
|
|
|
", createdAt=" + createdAt +
|
|
|
|
", updatedAt=" + updatedAt +
|
|
|
|
", version=" + version +
|
|
|
|
", visibility=" + visibility +
|
|
|
|
", customizationOf=" + customizationOf +
|
|
|
|
", familyId=" + familyId +
|
2022-05-11 10:29:26 +02:00
|
|
|
", archived=" + archived +
|
|
|
|
", links=" + links +
|
|
|
|
", phases=" + phases +
|
|
|
|
", plans=" + plans +
|
2022-05-03 14:56:04 +02:00
|
|
|
'}';
|
|
|
|
}
|
2022-05-18 13:45:24 +02:00
|
|
|
|
|
|
|
public DatasetProfile buildDatasetProfile() {
|
|
|
|
DatasetProfile datasetProfile = new DatasetProfile();
|
|
|
|
datasetProfile.setLabel(this.getTitle());
|
|
|
|
datasetProfile.setDescription(this.getDescription());
|
|
|
|
datasetProfile.setLanguage(this.getLocale());
|
|
|
|
datasetProfile.setStatus((short) 1);
|
2022-05-20 23:30:56 +02:00
|
|
|
datasetProfile.setVersion(getVersion());
|
2022-05-18 13:45:24 +02:00
|
|
|
datasetProfile.setUsers(new ArrayList<>());
|
|
|
|
this.buildPages(datasetProfile);
|
|
|
|
return datasetProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void buildPages(DatasetProfile datasetProfile) {
|
|
|
|
List<Page> pages = new ArrayList<>();
|
|
|
|
List<Section> sections = new ArrayList<>();
|
|
|
|
this.getPhases().forEach(phase -> {
|
|
|
|
Page page = new Page();
|
|
|
|
page.setId(String.valueOf(UUID.randomUUID()));
|
|
|
|
page.setOrdinal(Math.toIntExact(phase.getNumber()) - 1);
|
|
|
|
page.setTitle(phase.getTitle());
|
|
|
|
pages.add(page);
|
|
|
|
sections.addAll(phase.buildSections(page.getId()));
|
|
|
|
});
|
|
|
|
datasetProfile.setPages(pages);
|
|
|
|
datasetProfile.setSections(sections);
|
|
|
|
}
|
|
|
|
|
2022-04-27 16:21:04 +02:00
|
|
|
}
|